From: ken Date: Fri, 16 Dec 2016 05:36:19 +0000 (-0800) Subject: Makefile v0.2 X-Git-Url: https://www.kengrimes.com/gitweb/?p=henge%2Fapc.git;a=commitdiff_plain;h=9f1d945585172b03bc9e5dca7048302a29239e0c Makefile v0.2 --- 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)) diff --git a/src/lexer.c b/src/lexer.c index b2bb535..1550db9 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -28,7 +28,7 @@ #include /* Local */ -#include "src/parser.tab.h" +#include "parser.tab.h" #ifndef DE_STACKSIZE #define DE_STACKSIZE 1024 #endif diff --git a/src/main.o b/src/main.o deleted file mode 100644 index db32a98..0000000 Binary files a/src/main.o and /dev/null differ