Let\'s say you have a Makefile with two pseudo-targets, \'all\' and \'debug\'. The \'debug\' target is meant to build the same project as \'all\', except with some different
Keeping variant sets of object files (as in bobbogo's solution) is probably the best way, but if for some reason you don't want to do that, you can use empty files as markers, to indicate which way you last built the executable:
%-marker:
@rm -f $(OBJECTS) *-marker
@touch $@
debug: GCCFLAGS += -ggdb
debug: SOMEOTHERFLAG = WHATEVER
all debug: % : %-marker
@echo making $@
@$(MAKE) -S GCCFLAGS='$(GCCFLAGS)' SOMEOTHERFLAG='$(SOMEOTHERFLAG)' main
There are other variants on this idea; you could have a small file containing the flag settings, which the makefile would build and include
. That would be clever, but not really any cleaner than this.