I am trying to write a recursive clean target for GNU Makefile on OS X (GNU Make 3.81 - from XCode). Following GNU Make documentation, I came up with the following:
Main Makefile
ALLSUBMAKES=$(wildcard ./*/Makefile)
ALLSUBDIRS=$(patsubst %/Makefile,%,$(ALLSUBMAKES))
.PHONY: submakes clean $(ALLSUBDIRS)
submakes: $(ALLSUBDIRS)
clean: $(ALLSUBDIRS)
$(ALLSUBDIRS):
$(MAKE) -C $@
Submake Makefiles
mainTarget:
#do something here
clean:
#some clean operation
The problem:
I find that $(MAKE) passes only the make executable full path name ignoring targets and all other command line options (like -j5 for example). All submakes end up executing the mainTarget when I issue make clean on the top level.
What is the right way to implement such recursive clean targets? Or how to pass target along with all command line arguments to submakes?