Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop compilation immediately with parallel make

Is there any way to make parallel invocations of GNU make (ie. make -jN) cease ALL compilation immediately whenever it encounters an error?

Currently I see a "Waiting for unfinished jobs" message & then many lines of output whilst existing make processes finish.

like image 654
Scott Smedley Avatar asked Jan 24 '12 02:01

Scott Smedley


People also ask

How does make J work?

-j [jobs], --jobs[=jobs] Specifies the number of jobs (commands) to run simultaneously. If there is more than one -j option, the last one is effective. If the -j option is given without an argument, make will not limit the number of jobs that can run simultaneously.


2 Answers

I see this is an old thread, but the answer isn't definitive. This has always worked well for me:

#!/usr/bin/make -f

MAKEPID:= $(shell echo $$PPID)

$(mytargets):
    @script_that_runs_in_parallel.sh $@ || kill -TERM $(MAKEPID)

It's pretty brutal, but it does the job.

like image 179
Craig Avatar answered Oct 07 '22 20:10

Craig


There is no way to do this (in GNU make). The only possible way would be to add a boilerplate stanza to all of your recipes such that if they failed, you would catch the failure and use killall or something similar to kill all instances of make. Tricky and dangerous for sure.

Of course you can always hit CTRL-C yourself to stop make.

like image 36
MadScientist Avatar answered Oct 07 '22 21:10

MadScientist