From: ken Date: Sat, 17 Dec 2016 04:49:13 +0000 (-0800) Subject: added distclean, simplified some rules X-Git-Url: https://www.kengrimes.com/gitweb/?p=henge%2Fapc.git;a=commitdiff_plain;h=bbe164b7ec48bc9ae8b85469c0aa32c1ad28447c added distclean, simplified some rules --- diff --git a/Makefile b/Makefile index 2d928e6..8cefc8e 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # This makefile builds APC, the Asset Package Compiler for Henge, on the system. ################################################################################ # Driver sources -DRIVERS := apc testapc +DRIVERS ?= apc testapc # Yacc YACC := bison @@ -41,12 +41,12 @@ cSRC := $(shell find ./src -type f -name '*.c') hGEN := $(ySRC:%.y=%.tab.h) cGEN := $(strip $(ySRC:%.y=%.tab.c) $(rlSRC:%.rl=%.fsm.c)) -# Filter all other driver objects out of each driver's link commands. -OBJ := $(patsubst %.c,%.o,$(cSRC) $(cGEN)) -$(foreach drv,$(DRIVERS),\ -$(eval OTHERS := $(filter-out $(drv),$(DRIVERS)))\ -$(eval $(drv)SRC := $(filter-out $(OTHERS:%=\%/%.o),$(OBJ)))\ -$(eval $(drv)-dSRC := $($(drv)SRC:%.o=%-d.o))) +# Determine binary/ir targets (object files and driver binaries) +cTRG := $(patsubst %.c,%.o,$(cSRC) $(cGEN)) +ldSRC := $(filter-out $(DRIVERS:%=\%/%.o),$(cTRG)) +cTRG += $(cTRG:%.o=%-d.o) +ldTRG := $(DRIVERS:%=%-d) $(DRIVERS) +ldDEP = $(filter %/$1.o,$(cTRG)) $(if $(filter %-d,$1),$(ldSRC:%.o=%-d.o),$(ldSRC)) ifeq (,$(filter clean,$(MAKECMDGOALS))) # Deps should be generated for each source file, when not cleaning @@ -60,18 +60,16 @@ S2S += $(shell $(call $1,$2,$3)) endif endif +# Clean targets +cleanCMD = $(if $(wildcard $1),rm $(wildcard $1)) + # Rules .SECONDEXPANSION: -$(DRIVERS:%=%-d) $(DRIVERS): $$($$@SRC) | $(hGEN) - $(call LDCMD,$^,$@) - +$(ldTRG): $$(call ldDEP,$$@) | $(hGEN) ; $(call LDCMD,$^,$@) %-d.o: CFLAGS+= -Og -ggdb -%.o %-d.o: %.c $$(call cGENDEP,$$(dir $$@)%.c) - $(call CCMD,$<,$@) - +%.o %-d.o: %.c $$(call cGENDEP,$$(dir $$@)%.c) ; $(call CCMD,$<,$@) %.tab.h: %.tab.c ; %.tab.c: %.y $$(call S2S,YCMD,%.y,$$@) ; %.fsm.c: %.rl $$(call S2S,RLCMD,%.rl,$$@) ; - -clean: $(wildcard $(cGEN) $(hGEN) $(foreach drv,$(DRIVERS),$($(drv)SRC) $($(drv)-dSRC))) - $(if $^,rm $^) +clean: ; $(call cleanCMD,$(cGEN) $(hGEN) $(cTRG)) +distclean: clean ; $(call cleanCMD,$(ldTRG))