vmrob
vmrob

Reputation: 3046

How can I prevent race conditions in make?

As the title suggests, how can I prevent race conditions in make?

My specific use case is where I want clean and then build the all target:

make -j 4 clean all

Should I give up and settle for make clean && make -j 4 all?

Upvotes: 1

Views: 559

Answers (2)

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136286

You cannot really execute in parallel a recipe that builds a target and another one that destroys it.

What a use case do you have in mind that would not be satisfied with:

make clean && make -j4

?

Upvotes: 2

Aaron Digulla
Aaron Digulla

Reputation: 328614

I think the only way to make this work is to put this in the Makefile:

all : clean

which you don't want (obviously). My next idea would be:

clean_all: clean
    $(MAKE) all

That would allow you to write make -j clean_all but I'm not happy with it, either.

Upvotes: 1

Related Questions