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?
The POSIX description of
make
includes a rationale which says:(I believe the
t.tab.o
in the$(CC)
line is a typo fory.tab.o
, but that is what the rationale actually says.)Thus, the observed behaviour that pre-requisites are processed from left to right has validation here, though it is only in the Rationale section, not in the main description. The Rationale also mentions issues with parallel
make
etc.By default, the order of execution is the same as specified in the prerequisites list, unless there are any dependencies defined between these prerequisites.
The order is
x 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 afterz
, there must be ay : z
dependence.And keep in mind that GNU Make can execute some recipes in parallel, see Mat's answer.
From https://stackoverflow.com/a/22638294/636849, you can add the pipe symbol:
You really shouldn't depend on the order in which they are executed - all else being equal, all three recipes for those prerequisites could run in parallel.
The only hard rule is that all prerequisites must be met before the target recipe is run.
If there are no dependencies between
x
,y
andz
, and no parallel execution, GNU make appears to run them in the order you specified them, but this is not guaranteed in the docs.