Order of processing components in makefile


In a makefile, the dependency line is of the form –

abc: x y z

All three of the components (x,y,z) are themselves targets in dependency lines further down in the makefile.

If make abc is invoked, in what order will the three targets x,y,z be executed?

Best Solution

By default, the order of execution is the same as specified in the prerequisites list, unless there are any dependencies defined between these prerequisites.

abc: x y z

The order is x y z.

abc: x y z
y : z

The order would be x z y.

But ideally, you should design your Makefiles so that it wouldn't rely on the order in which prerequisites are specified. That is, if y should be executed after z, there must be a y : z dependence.

And keep in mind that GNU Make can execute some recipes in parallel, see Mat's answer.