perms
[henge/apc.git] / Makefile
1 ################################################################################
2 # Desc: APC make script
3 # Author: kgr
4 # Date: 2016
5 ################################################################################
6 # This makefile builds APC, the Asset Package Compiler for Henge, on the system.
7 ################################################################################
8 # Directories (can override with env vars)
9 APC_ROOTDIR := $(if $(APC_ROOTDIR),$(APC_ROOTDIR),.)
10 APC_SRCDIR := $(if $(APC_SRCDIR),$(APC_SRCDIR),$(APC_ROOTDIR)/src)
11
12 # APC is built from Ragel, Bison and C source code only.
13 ySRC := $(shell find $(APC_SRCDIR) -type f -name '*.y')
14 rlSRC := $(shell find $(APC_SRCDIR) -type f -name '*.rl')
15 cSRC := $(shell find $(APC_SRCDIR) -type f -name '*.c')
16
17 # Specify the linker (allow env var override)
18 LD := $(if $(LD),$(LD),ld)
19
20 # Generated files from Yacc/Bison and Ragel
21 hGEN := $(ySRC:%.y=%.tab.h)
22 cGEN := $(strip $(ySRC:%.y=%.tab.c) $(rlSRC:%.rl=%.c))
23
24 # Rules
25 apc-d: $(patsubst %.c,%-d.o,$(cSRC) $(cGEN)) | $(hGEN)
26 $(LD) $(LDFLAGS) $(LDLIBS) $<
27
28 apc: $(patsubst %.c,%.o,$(cSRC) $(cGEN)) | $(hGEN)
29 $(LD) $(LDFLAGS) $(LDLIBS) $<
30
31 %.tab.h %.tab.c: %.y
32 bison -d $(YFLAGS) $<
33
34 cFLAGS = $(strip $(CFLAGS) $(CPPFLAGS) $1 $2 $3 $4 $5 $6 $7 $8 $9)
35 GENDEP = $(filter-out \ %:,$(shell $(CC) -MM -MG $1))
36 .SECONDEXPANSION:
37 %.o: %.c $$(call GENDEP,$$(dir $$@)%.c)
38 $(CC) $(call cFLAGS,-c,-o $@) $<
39
40 %-d.o: $$(call GENDEP,$$(dir $$@)%.c) $$(info [DEPS|$$@] $$(call GENDEP,$$(dir $$@)%.c))
41 $(CC) $(call cFLAGS,-c,-Og,-ggdb,-o $@) $<