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