################################################################################ # Desc: APC make script # Author: kgr # Date: 2016 ################################################################################ # This makefile builds APC, the Asset Package Compiler for Henge, on the system. ################################################################################ # Directories (can override with env vars) APC_ROOTDIR := $(if $(APC_ROOTDIR),$(APC_ROOTDIR),.) APC_SRCDIR := $(if $(APC_SRCDIR),$(APC_SRCDIR),$(APC_ROOTDIR)/src) # APC is built from Ragel, Bison and C source code only. ySRC := $(shell find $(APC_SRCDIR) -type f -name '*.y') rlSRC := $(shell find $(APC_SRCDIR) -type f -name '*.rl') cSRC := $(shell find $(APC_SRCDIR) -type f -name '*.c') # Specify the linker (allow env var override) LD := $(if $(LD),$(LD),ld) # Generated files from Yacc/Bison and Ragel hGEN := $(ySRC:%.y=%.tab.h) cGEN := $(strip $(ySRC:%.y=%.tab.c) $(rlSRC:%.rl=%.c)) # Rules apc-d: $(patsubst %.c,%-d.o,$(cSRC) $(cGEN)) | $(hGEN) $(LD) $(LDFLAGS) $(LDLIBS) $< apc: $(patsubst %.c,%.o,$(cSRC) $(cGEN)) | $(hGEN) $(LD) $(LDFLAGS) $(LDLIBS) $< %.tab.h %.tab.c: %.y bison -d $(YFLAGS) $< cFLAGS = $(strip $(CFLAGS) $(CPPFLAGS) $1 $2 $3 $4 $5 $6 $7 $8 $9) GENDEP = $(filter-out $1 \ %:,$(shell $(CC) -MM -MG $1)) .SECONDEXPANSION: %.o: %.c $$(info $$(call GENDEP,$$(dir $$@)%.c)) $(CC) $(call cFLAGS,-c,-o $@) $< %-d.o: %.c $$(info $$@DEPS- $$(call GENDEP,$$(dir $$@)%.c)) $$(call GENDEP,$$(dir $$@)%.c) $(CC) $(call cFLAGS,-c,-Og,-ggdb,-o $@) $<