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:
ALLSUBMAKES=$(wildcard ./*/Makefile) ALLSUBDIRS=$(patsubst %/Makefile,%,$(ALLSUBMAKES)) .PHONY: submakes clean $(ALLSUBDIRS) submakes: $(ALLSUBDIRS) clean: $(ALLSUBDIRS) $(ALLSUBDIRS): $(MAKE) -C $@
mainTarget: #do something here clean: #some clean operation
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?