From 35c8feef5ddc2be49091d83be6cff4621bbaa935 Mon Sep 17 00:00:00 2001 From: ken Date: Fri, 16 Dec 2016 12:26:30 -0800 Subject: [PATCH] fixed linking, object filtering --- Makefile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index e10f81c..2d713d3 100644 --- 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 $^) -- 2.18.0