################################################################################ # Desc: APC make script # Author: kgr # Date: 2016 ################################################################################ # This makefile builds APC, the Asset Package Compiler for Henge, on the system. ################################################################################ # Yacc YACC := bison YFLAGS ?= -v -d -Wall YCMD = $(YACC) $(YFLAGS) $< # Ragel RLC ?= ragel RLFALGS ?= -C RLCMD = $(RLC) $(RLFLAGS) -o $@ $< # C CC ?= gcc CFLAGS ?= -Wall -Werror CCMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $< # Linker LD ?= ld LDFLAGS ?= LDLIBS ?= LDCMD = $(LD) $(LDFLAGS) $(LDLIBS) -o $@ $^ # 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') # Generated files from Yacc/Bison and Ragel hGEN := $(ySRC:%.y=%.tab.h) cGEN := $(strip $(ySRC:%.y=%.tab.c) $(rlSRC:%.rl=%.c)) # Functions cGENDEP = $(if $(wildcard $1),$(subst src/,,$(filter-out $1 \ %:,$(shell $(CC) -MM -MG $1))),$(info <$1>)) ldFLAGS = $(strip $(LDFLAGS) $(LDLIBS) $(VA_ARGS)) # Rules apcSRC := $(patsubst %.c,%.o,$(cSRC) $(cGEN)) apc-dSRC := $(patsubst %.o,%-d.o,$(apcSRC)) .SECONDEXPANSION: apc-d apc: $$($$@SRC) | $(hGEN) $(strip $(LDCMD)) %-d.o: CFLAGS+= -Og -ggdb %.o %-d.o: %.c $$(call cGENDEP,$$(dir $$@)%.c) $(strip $(CCMD)) %.tab.h %.tab.c: %.y $(strip $(YCMD)) mv $(notdir $(<:%.y=%.tab.[ch])) $(dir $@) %.c: %.rl $(strip $(RLCMD)) clean: $(wildcard $(cGEN) $(hGEN) $(apcSRC) $(apc-dSRC)) rm $^