Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use .NOTPARALLEL in makefile only on specific targets?

Tags:

linux

makefile

I have 5 labels in Makefile:

all: label1 label2 label3 label4 last_label

I want last_label to be done last, and I want to use make -j. If I use .NOTPARALLEL, it will make all of them NOTPARALLEL, any suggestion on how to do that?

like image 323
shd Avatar asked May 30 '13 07:05

shd


People also ask

What is precious makefile?

PRECIOUS depends on are given the following special treatment: if make is killed or interrupted during the execution of their recipes, the target is not deleted. See Interrupting or Killing make . Also, if the target is an intermediate file, it will not be deleted after it is no longer needed, as is normally done.

What is the default make target?

By default, the goal is the first target in the makefile (not counting targets that start with a period). Therefore, makefiles are usually written so that the first target is for compiling the entire program or programs they describe.

What does all do in makefile?

This means that when you do a "make all", make always thinks that it needs to build it, and so executes all the commands for that target. Those commands will typically be ones that build all the end-products that the makefile knows about, but it could do anything.


2 Answers

If the reason last_label needs to run last is that it needs data from the other labels, the best approach would be to tell make about that dependency:

all: last_label

last_label: label1 label2 label3 label4

If there's not a true dependency (i.e., if you don't want last_label to be rebuilt if one of the others changes), and if you're using GNU Make, you can specify these as "order-only" dependencies--make will just make sure they exist before last_label is built:

all: last_label

last_label: | label1 label2 label3 label4
like image 164
laindir Avatar answered Oct 08 '22 12:10

laindir


Create a target specifying the four targets that can be executed in parallel & include this and last_label in the all target:

intermediate: label1 label2 label3 label4

all:
        $(MAKE) intermediate
        $(MAKE) last_label

This would execute the targets specified within intermediate in parallel, but intermediate and last_label would be forced consecutively.

(Note that the leading space before $(MAKE) is a TAB character.)

like image 28
devnull Avatar answered Oct 08 '22 13:10

devnull