# This makefile builds APC, the Asset Package Compiler for Henge, on the system.
################################################################################
# Driver sources
-DRIVERS ?= apc testapc
+DRIVERS ?= apc testapc testston
# Debug Level
DEBUG ?= 1
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))
+ldDEP = $(filter %/$1.o,$(cTRG))
+ldDEP += $(if $(filter testston%,$1),,$(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))
+TSTAMP = $(if $(wildcard $1),$(shell stat -c %Y $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)
# 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 = $(if $(filter $2,$(call NEWER,$2,$3)),$(eval 4 := t),$(eval 4 :=))
S2S += $(if $4,$(info $(call $1,$2,$3)))
.SECONDEXPANSION:
$(ldTRG): $$(call ldDEP,$$@) | $(hGEN) ; $(call LDCMD,$^,$@)
%-d.o: CFLAGS+= -Og -ggdb -DDEBUG=$(DEBUG)
-%.o %-d.o: %.c $$(call cGENDEP,$$(dir $$@)%.c) ; $(call CCMD,$<,$@)
+%.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,$$@) ;