There's also the dedicated unix utility "tsort" (https://en.wikipedia.org/wiki/Tsort) although actually your makefile is more succinct.