X-Git-Url: https://www.kengrimes.com/gitweb/?p=henge%2Fapc.git;a=blobdiff_plain;f=Makefile;fp=Makefile;h=7968b668a13834e2d6a8a2a66d8ba5ff4a0a6d16;hp=d37a162f58e6358ffa1f1a30584e226d147d9b08;hb=44adcae5601d919ab63f8241ebac4ddfc0bc69f5;hpb=5e1b8a97f8f2252768d4b905be9e5d2e35e0d1e4 diff --git a/Makefile b/Makefile index d37a162..7968b66 100644 --- a/Makefile +++ b/Makefile @@ -21,10 +21,12 @@ CFLAGS ?= -Wall CCMD = $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< # Linker -LD ?= ld -LDFLAGS ?= -LDLIBS ?= -lunistring -LDCMD = $(LD) $(LDFLAGS) $(LDLIBS) -o $@ $^ +LD ?= ld +LDFLAGS ?= +LDLIBS ?= -lunistring +apcLIBS ?= +apc-dLIBS ?= +LDCMD = $(LD) $(LDFLAGS) $(LDLIBS) $($1LIBS) -o $@ $^ # APC is built from Ragel, Bison and C source code only. ySRC := $(shell find ./src -type f -name '*.y') @@ -35,17 +37,19 @@ cSRC := $(shell find ./src -type f -name '*.c') 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)) +# Deps generation function +cGENDEP = $(if $(wildcard $1),$(subst $(dir $1),,$(filter-out $1 \ %:,$(shell $(CC) -MM -MG $1))),$(info <$1>)) -# Rules -apcSRC := $(patsubst %.c,%.o,$(cSRC) $(cGEN)) -apc-dSRC := $(patsubst %.o,%-d.o,$(apcSRC)) +# Driver sources +DRIVERS := apc testapc +$(foreach drv,$(DRIVERS),\ +$(eval $(drv)SRC := $(patsubst %.c,%.o,$(filter-out $(patsubst %,src/%.c,$(filter-out $(drv),$(DRIVERS))),$(cSRC) $(cGEN))))\ +$(eval $(drv)-dSRC := $(patsubst %.o,%-d.o,$($(drv)SRC)))) +# Rules .SECONDEXPANSION: -apc-d apc: $$($$@SRC) | $(hGEN) - $(strip $(LDCMD)) +$(DRIVERS:%=%-d) $(DRIVERS): $$($$@SRC) | $(hGEN) + $(strip $(call LDCMD,$@)) %-d.o: CFLAGS+= -Og -ggdb %.o %-d.o: %.c $$(call cGENDEP,$$(dir $$@)%.c) @@ -59,4 +63,4 @@ apc-d apc: $$($$@SRC) | $(hGEN) $(strip $(RLCMD)) clean: $(wildcard $(cGEN) $(hGEN) $(apcSRC) $(apc-dSRC)) - rm $^ + $(if $^,rm $^)