I have a makefile structured something like this:
all :
compile executable
clean :
rm -f *.o $(EXEC)
I realized that I was consistently running “make clean” followed by “clear” in my terminal before running “make all”. I like to have a clean terminal before I try and sift through nasty C++ compilation errors. So I tried to add a 3rd target:
fresh :
rm -f *.o $(EXEC)
clear
make all
This works, however this runs a second instance of make (I believe). Is there a right way to get the same functionality without running a 2nd instance of make?
Actually you are right: it runs another instance of make.
A possible solution would be:
By calling
make freshyou get first thecleantarget, then theclearscreenwhich runsclearand finallyallwhich does the job.EDIT Aug 4
What happens in the case of parallel builds with make’s
-joption?There’s a way of fixing the order. From the make manual, section 4.2:
Hence the makefile becomes
EDIT Dec 5
It is not a big deal to run more than one makefile instance since each command inside the task will be a sub-shell anyways. But you can have reusable methods using the call function.