1 ################################################################################
2 # Desc: APC make script
5 ################################################################################
6 # This makefile builds APC, the Asset Package Compiler for Henge, on the system.
7 ################################################################################
17 YCMD
= $(strip $(YACC
) $(YFLAGS
) $(if
$2,$(dir $2))$1)
18 YCMD
+= $(if
$2,&& mv
$(notdir $(1:%.y
=%.tab.
[ch
])) $(dir $2))
23 RLCMD
= $(strip $(RLC
) $(RLFLAGS
) $(if
$2,-o
$2 $(dir $2))$1)
28 CCMD
= $(strip $(CC
) $(CFLAGS
) $(CPPFLAGS
) -c
$(if
$2,-o
$2) $1)
36 LDCMD
= $(strip $(CC
) $(LDFLAGS
) $(if
$2,-o
$2) $1) $(LDLIBS
) $($1LIBS)
38 # APC is built from Ragel, Bison and C source code only.
39 ySRC
:= $(shell find src
/ -type f
-name
'*.y')
40 rlSRC
:= $(shell find src
/ -type f
-name
'*.rl')
41 cSRC
:= $(shell find src
/ -type f
-name
'*.c')
43 # Generated files from Yacc/Bison and Ragel
44 hGEN
:= $(ySRC
:%.y
=%.tab.h
)
45 cGEN
:= $(strip $(ySRC
:%.y
=%.tab.c
) $(rlSRC
:%.rl
=%.fsm.c
))
48 # Determine binary/ir targets (object files and driver binaries)
49 cTRG
:= $(patsubst %.c
,%.o
,$(cSRC
) $(cGEN
))
50 ldSRC
:= $(filter-out $(DRIVERS
:%=\
%/%.o
),$(cTRG
))
51 cTRG
+= $(cTRG
:%.o
=%-d.o
)
52 ldTRG
:= $(DRIVERS
:%=%-d
) $(DRIVERS
)
53 ldDEP
= $(filter %/$1.o
,$(cTRG
)) $(if
$(filter %-d
,$1),$(ldSRC
:%.o
=%-d.o
),$(ldSRC
))
55 # Determine if '1' is newer than '2'
56 TSTAMP
= $(if
$(wildcard $1),$(shell stat
-c
%Y
$1),0$(info nots
: $1))
57 NEWER
= $(eval
4 := $(call TSTAMP
,$(dir $2)$1))
58 NEWER
+= $(eval
5 := $(call TSTAMP
,$2))
59 NEWER
+= $(if
$(filter $5,$(firstword $(sort $4 $5))),$1,$2)
61 ifeq (,$(filter clean,$(MAKECMDGOALS
)))
62 # Deps should be generated for each source file, when not cleaning
63 cGENDEP
= $(if
$(wildcard $1),$(subst $(dir $1),,$(filter-out $1 \
%:,$(shell $(CC
) -MM
-MG
$1))),\
64 $(info [<$1>: no deps
- file not found
]))
65 # S2S will print the command necessary to create a file when called
66 S2S
= $(if
$(filter $2,$(call NEWER
,$2,$3)),$(eval
4 := t
),$(eval
4 :=))
67 S2S
+= $(if
$4,$(info $(call
$1,$2,$3)))
68 ifeq (,$(filter n
,$(MAKEFLAGS
)))
69 # Unless we're in -n mode, S2S should also invoke the command on the shell
70 S2S
+= $(if
$4,$(shell $(call
$1,$2,$3)))
75 cleanCMD
= $(if
$(wildcard $1),rm $(wildcard $(sort $1)))
79 $(ldTRG
): $$(call ldDEP
,$$@
) |
$(hGEN
) ; $(call LDCMD
,$^
,$@
)
80 %-d.o
: CFLAGS
+= -Og
-ggdb
-DDEBUG
=$(DEBUG
)
81 %.o
%-d.o
: %.c
$$(call cGENDEP
,$$(dir $$@
)%.c
) ; $(call CCMD
,$<,$@
)
83 %.tab.c
: %.y
$$(call S2S
,YCMD
,%.y
,$$@
) ;
84 %.fsm.c
: %.rl
$$(call S2S
,RLCMD
,%.rl
,$$@
) ;
85 clean: ; $(call cleanCMD
,$(cGEN
) $(hGEN
) $(cTRG
))
86 distclean: clean ; $(call cleanCMD
,$(ldTRG
))