X-Git-Url: https://git.kengrimes.com/?p=henge%2Fapc.git;a=blobdiff_plain;f=Makefile;h=62bf1193ccb17282f4c383ae321a64a51ac9bfe6;hp=8cefc8edf9afdc19c8cc01a8847462809b138c3d;hb=3e4496a9ecca4b2e107f4473af2bdd062690ffc4;hpb=bbe164b7ec48bc9ae8b85469c0aa32c1ad28447c diff --git a/Makefile b/Makefile index 8cefc8e..62bf119 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,9 @@ # Driver sources DRIVERS ?= apc testapc +# Debug Level +DEBUG ?= 1 + # Yacc YACC := bison YFLAGS ?= -v -d -Wall @@ -16,7 +19,7 @@ YCMD += $(if $2,&& mv $(notdir $(1:%.y=%.tab.[ch])) $(dir $2)) # Ragel RLC ?= ragel -RLFALGS ?= -C +RLFLAGS ?= -C RLCMD = $(strip $(RLC) $(RLFLAGS) $(if $2,-o $2 $(dir $2))$1) # C @@ -33,13 +36,14 @@ apc-dLIBS ?= LDCMD = $(strip $(CC) $(LDFLAGS) $(if $2,-o $2) $1) $(LDLIBS) $($1LIBS) # APC is built from Ragel, Bison and C source code only. -ySRC := $(shell find ./src -type f -name '*.y') -rlSRC := $(shell find ./src -type f -name '*.rl') -cSRC := $(shell find ./src -type f -name '*.c') +ySRC := $(shell find src/ -type f -name '*.y') +rlSRC := $(shell find src/ -type f -name '*.rl') +cSRC := $(shell find src/ -type f -name '*.c') # Generated files from Yacc/Bison and Ragel hGEN := $(ySRC:%.y=%.tab.h) cGEN := $(strip $(ySRC:%.y=%.tab.c) $(rlSRC:%.rl=%.fsm.c)) +.SECONDARY: $(cGEN) # Determine binary/ir targets (object files and driver binaries) cTRG := $(patsubst %.c,%.o,$(cSRC) $(cGEN)) @@ -48,26 +52,36 @@ cTRG += $(cTRG:%.o=%-d.o) ldTRG := $(DRIVERS:%=%-d) $(DRIVERS) ldDEP = $(filter %/$1.o,$(cTRG)) $(if $(filter %-d,$1),$(ldSRC:%.o=%-d.o),$(ldSRC)) +# Determine if '1' is newer than '2' +TSTAMP = $(if $(wildcard $1),$(shell stat -c %Y $1),0$(info nots: $1)) +NEWER = $(eval 4 := $(call TSTAMP,$(dir $2)$1)) +NEWER += $(eval 5 := $(call TSTAMP,$2)) +NEWER += $(if $(filter $5,$(firstword $(sort $4 $5))),$1,$2) + ifeq (,$(filter clean,$(MAKECMDGOALS))) # Deps should be generated for each source file, when not cleaning cGENDEP = $(if $(wildcard $1),$(subst $(dir $1),,$(filter-out $1 \ %:,$(shell $(CC) -MM -MG $1))),\ $(info [<$1>: no deps - file not found])) +# Filter only missing deps +cMISDEP = $(strip $(foreach dep,$(call cGENDEP,$1),$(if $(wildcard src/$(dep)),,$(dep)))) # S2S will print the command necessary to create a file when called -S2S = $(info $(call $1,$2,$3)) +S2S = $(if $(filter $2,$(call NEWER,$2,$3)),$(eval 4 := t),$(eval 4 :=)) +S2S += $(if $4,$(info $(call $1,$2,$3))) ifeq (,$(filter n,$(MAKEFLAGS))) # Unless we're in -n mode, S2S should also invoke the command on the shell -S2S += $(shell $(call $1,$2,$3)) +S2S += $(if $4,$(shell $(call $1,$2,$3))) endif endif # Clean targets -cleanCMD = $(if $(wildcard $1),rm $(wildcard $1)) +cleanCMD = $(if $(wildcard $1),rm $(wildcard $(sort $1))) # Rules .SECONDEXPANSION: $(ldTRG): $$(call ldDEP,$$@) | $(hGEN) ; $(call LDCMD,$^,$@) -%-d.o: CFLAGS+= -Og -ggdb -%.o %-d.o: %.c $$(call cGENDEP,$$(dir $$@)%.c) ; $(call CCMD,$<,$@) +%-d.o: CFLAGS+= -Og -ggdb -DDEBUG=$(DEBUG) +%.o %-d.o: %.c $$(call cGENDEP,$$(dir $$@)%.c); $(call CCMD,$<,$@) +%.o %-d.o: %.c; $(error Missing dependencies for $<: $(call cMISDEP, $<)) %.tab.h: %.tab.c ; %.tab.c: %.y $$(call S2S,YCMD,%.y,$$@) ; %.fsm.c: %.rl $$(call S2S,RLCMD,%.rl,$$@) ;