Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ‘make again’ to clean and remake

Tags:

makefile

I want to have a phony target to ‘remake’ a project via make again instead of typing make clean && make or make clean all (which seems like I wanted to ‘clean all’) or making an alias/function/script to do this.

Is it safe to specify something like this:

again: clean all

in a sense that prerequisites are reliably updated from left to right? Or, maybe, is it better to do a recursive call like in

again:
    $(MAKE) clean   # maybe ‘&& \’ here
    $(MAKE) all

I mean, may there be any pitfalls or incompatibilities in either approach which could make creating e.g. a shell function or an alias to make clean && make safer?

Thank you.

like image 223
McSaks Avatar asked Dec 21 '25 18:12

McSaks


1 Answers

Is it safe to specify something like this:

again: clean all

in a sense that prerequisites are reliably updated from left to right?

That's not safe, because all does not depend on clean so if someone runs make -j2 again then the two targets can be run in parallel.

Your second approach will work better, because it ensures that $(MAKE) all cannot start before $(MAKE) clean has completed. It's not entirely safe though, because if someone does make -j2 clean again then those two targets could run in parallel, which would be roughly equivalent to make clean & make clean all, which would still allow the all step to run in parallel with the first clean.

A better option would be:

again: clean
    $(MAKE) all

This way if someone does make clean again then it only does the clean once, and if they do make -j2 clean again it still ensures that the clean target finishes before $(MAKE) all runs.

like image 151
Jonathan Wakely Avatar answered Dec 23 '25 20:12

Jonathan Wakely