Search code examples
linuxmakefilebuild

Makefile .NOTPARALLEL: target, make the whole makefile not parallel, instead of just the specified target


According to Disabling Parallel Execution adding .NOTPARALLEL: target with prerequisites, makes the prerequisites run serially.

If the .NOTPARALLEL special target with no prerequisites is specified anywhere then the entire instance of make will be run serially, regardless of the parallel setting.

If the .NOTPARALLEL special target has prerequisites, then each of those prerequisites will be considered a target and all prerequisites of these targets will be run serially. Note that only when building this target will the prerequisites be run serially: if some other target lists the same prerequisites and is not in .NOTPARALLEL then these prerequisites may be run in parallel.

Unfortunately it doesn't work in my case. makefile:

t%:
        @ echo "$@..."
        @ sleep 0.0$*
        @ echo "$@ - done"

notpara: t4 t3 t2 t1
        @ echo "Done!"

para: t4 t3 t2 t1
        @ echo "Done!"


.NOTPARALLEL: notpara

When running the notpara target I really get them run in sync:

$ make -j notpara
t4...
t4 - done
t3...
t3 - done
t2...
t2 - done
t1...
t1 - done
Done!

But I also get it when I run the para target, which should run in parallel:

$ make -j para
t4...
t4 - done
t3...
t3 - done
t2...
t2 - done
t1...
t1 - done
Done!

When removing .NOTPARALLEL:, all goes to be not parallel:

$ make -j notpara
t4...
t3...
t2...
t1...
t1 - done
t2 - done
t3 - done
t4 - done
Done!
$ make -v
GNU Make 4.3

Please help


Solution

  • You need a newer version of GNU Make. From the NEWS file:

    Version 4.4 (31 Oct 2022)

    ...

    • New feature: .NOTPARALLEL accepts prerequisites If the .NOTPARALLEL special target has prerequisites then all prerequisites of those targets will be run serially (as if .WAIT was specified between each prerequisite).

    The documentation on the web site is from the latest published release. If you are using an older version of GNU Make, you should use the documentation provided with that version (the entire GNU Make manual is provided with each release, as an info file for example).