X-Git-Url: https://www.kengrimes.com/gitweb/?p=henge%2Fapc.git;a=blobdiff_plain;f=Makefile;fp=Makefile;h=1bc47b85301e95d305fed50933dcd6aff5ca0e64;hp=d6689db596e7ce86fca439a10236e170afdaef10;hb=9f1d945585172b03bc9e5dca7048302a29239e0c;hpb=dbce0e5aa9599ae86cb1aa33966b09b9dad3e810 diff --git a/Makefile b/Makefile index d6689db..1bc47b8 100644 --- a/Makefile +++ b/Makefile @@ -5,37 +5,55 @@ ################################################################################ # 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) +# 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 $(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) +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 fnf $1)) +ldFLAGS = $(strip $(LDFLAGS) $(LDLIBS) $(VA_ARGS)) + # Rules -apc-d: $(patsubst %.c,%-d.o,$(cSRC) $(cGEN)) | $(hGEN) - $(LD) $(LDFLAGS) $(LDLIBS) $< +apcSRC := $(patsubst %.c,%.o,$(cSRC) $(cGEN)) +apc-dSRC := $(patsubst %.o,%-d.o,$(apcSRC)) + +.SECONDEXPANSION: +apc-d apc: $$($$@SRC) | $(hGEN) + $(strip $(LDCMD)) -apc: $(patsubst %.c,%.o,$(cSRC) $(cGEN)) | $(hGEN) - $(LD) $(LDFLAGS) $(LDLIBS) $< +%-d.o: CFLAGS+= -Og -ggdb +%.o %-d.o: %.c $$(call cGENDEP,$$(dir $$@)%.c) + $(strip $(CCMD)) %.tab.h %.tab.c: %.y - bison -d $(YFLAGS) $< - -cFLAGS = $(strip $(CFLAGS) $(CPPFLAGS) $1 $2 $3 $4 $5 $6 $7 $8 $9) -GENDEP = $(filter-out \ %:,$(shell $(CC) -MM -MG $1)) -.SECONDEXPANSION: -%.o: %.c $$(call GENDEP,$$(dir $$@)%.c) - $(CC) $(call cFLAGS,-c,-o $@) $< + $(strip $(YCMD)) + mv $(notdir $(<:%.y=%.tab.[ch])) $(dir $@) -%-d.o: $$(call GENDEP,$$(dir $$@)%.c) $$(info [DEPS|$$@] $$(call GENDEP,$$(dir $$@)%.c)) - $(CC) $(call cFLAGS,-c,-Og,-ggdb,-o $@) $< +%.c: %.rl + $(strip $(RLCMD))