fixed linking, object filtering
authorken <ken@mihrtec.com>
Fri, 16 Dec 2016 20:26:30 +0000 (12:26 -0800)
committerken <ken@mihrtec.com>
Fri, 16 Dec 2016 20:26:30 +0000 (12:26 -0800)
Makefile

index e10f81c..2d713d3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -27,10 +27,10 @@ CCMD    = $(strip $(CC) $(CFLAGS) $(CPPFLAGS) -c $(if $2,-o $2) $1)
 # Linker
 LD        ?= ld
 LDFLAGS   ?= 
-LDLIBS    ?= -lunistring
+LDLIBS    ?= -lc -lunistring
 apcLIBS   ?= 
 apc-dLIBS ?= 
-LDCMD      = $(strip $(LD) $(LDFLAGS) $(LDLIBS) $($1LIBS) $(if $2,-o $2) $1)
+LDCMD      = $(strip $(LD) $(LDFLAGS) $(if $2,-o $2) $1) $(LDLIBS) $($1LIBS) 
 
 # APC is built from Ragel, Bison and C source code only.
 ySRC  := $(shell find ./src -type f -name '*.y')
@@ -42,9 +42,11 @@ hGEN  := $(ySRC:%.y=%.tab.h)
 cGEN  := $(strip $(ySRC:%.y=%.tab.c) $(rlSRC:%.rl=%.c))
 
 # Filter all other driver objects out of each driver's link commands.
+OBJ   := $(patsubst %.c,%.o,$(cSRC) $(cGEN))
 $(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))))
+$(eval OTHERS      := $(filter-out $(drv),$(DRIVERS)))\
+$(eval $(drv)SRC   := $(filter-out $(OTHERS:%=\%/%.o),$(OBJ)))\
+$(eval $(drv)-dSRC := $(filter-out $(OTHERS:%=\%/%-d.o),$(OBJ:%.o=%-d.o))))
 
 # Unless cleaning, deps should be generated for each source file
 ifeq (,$(filter clean,$(MAKECMDGOALS)))
@@ -72,5 +74,5 @@ $(DRIVERS:%=%-d) $(DRIVERS): $$($$@SRC) | $(hGEN)
 %.tab.c: %.y $$(call S2S,YCMD,%.y,$$@) ;
 %.c: %.rl $$(call S2S,RLCMD,%.rl,$$@) ;
 
-clean: $(wildcard $(cGEN) $(hGEN) $(apcSRC) $(apc-dSRC))
+clean: $(wildcard $(cGEN) $(hGEN) $(foreach drv,$(DRIVERS),$($(drv)SRC) $($(drv)-dSRC)))
        $(if $^,rm $^)