Question

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?

Was it helpful?

Solution 2

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.

OTHER TIPS

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

?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top