Published on

Forcing Makefile Targets to Run Sequentially and in Order

Authors

With makefiles you can specify a target that is made up of other targets:

sometarget: a b c

In the above sometarget uses targets with the name a, b and c. You may expect that these run one after another blocking each other until the previous target is complete. But this is not the case. By default make will run all targets using maximum parallelism meaning it can run a, b and c at the same time. In my case I needed these targets to run one after another.

After a bit of searching I found that there is a flag to make -j n which lets you specify how many jobs can be run at once.

--jobs -j -- allow N jobs at once; infinite jobs

n must be a positive integer and by default this is set to infinite jobs which I assume scales based on how many cores you have. Using this I managed to easily force a given multi-target target to be run in sequence:

make -j 1 sometarget