From 9f5740dbdc3ebfd615f3cdc2a845c160eabcbfa6 Mon Sep 17 00:00:00 2001 From: ken Date: Thu, 15 Dec 2016 14:26:20 -0800 Subject: [PATCH] Makefile v0.1 --- Makefile | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..50fd45d --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ +################################################################################ +# Desc: APC make script +# Author: kgr +# Date: 2016 +################################################################################ +# 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) + +# 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) + +# Generated files from Yacc/Bison and Ragel +hGEN := $(ySRC:%.y=%.tab.h) +cGEN := $(strip $(ySRC:%.y=%.tab.c) $(rlSRC:%.rl=%.c)) + +# Rules +apc-d: $(patsubst %.c,%-d.o,$(cSRC) $(cGEN)) | $(hGEN) + $(LD) $(LDFLAGS) $(LDLIBS) $< + +apc: $(patsubst %.c,%.o,$(cSRC) $(cGEN)) | $(hGEN) + $(LD) $(LDFLAGS) $(LDLIBS) $< + +%.tab.h %.tab.c: %.y + bison -d $(YFLAGS) $< + +cFLAGS = $(strip $(CFLAGS) $(CPPFLAGS) $1 $2 $3 $4 $5 $6 $7 $8 $9) +GENDEP = $(filter-out $1 \ %:,$(shell $(CC) -MM -MG $1)) +.SECONDEXPANSION: +%.o: %.c $$(info $$(call GENDEP,$$(dir $$@)%.c)) + $(CC) $(call cFLAGS,-c,-o $@) $< + +%-d.o: %.c $$(info $$@DEPS- $$(call GENDEP,$$(dir $$@)%.c)) $$(call GENDEP,$$(dir $$@)%.c) + $(CC) $(call cFLAGS,-c,-Og,-ggdb,-o $@) $< -- 2.18.0