-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
138 lines (108 loc) · 3.61 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
default: all
include config.mk
include rules.mk
# File containing main must be the first in the list
SRC := \
src/main.c \
src/script_disass.c \
src/crc32.c \
src/script_handlers.c \
src/strtab.c \
src/branch.c \
src/script_as.c \
src/script_parse_ctx.c \
src/embed.c \
src/search.c \
src/glyph.c
SRC_TEST := \
test/make_strtab.c \
test/script_as.c \
test/mk_strtab_str.c \
test/embed_strtab.c \
test/hard_wrap.c \
test/break_frame.c
SRC_LEX := src/script_lex.yy.c
SRC_YACC := src/script_gram.tab.c
SRC_PARSER := $(SRC_LEX) $(SRC_YACC)
SRC += $(OBJ_LEX)
SRC += $(OBJ_YACC)
OBJ := $(SRC:src/%.c=build/%.o)
OBJ += $(SRC_PARSER:src/%.c=build/%.o)
OBJ += build/glyph_margins.o
DEP := $(OBJ:%.o=%.d)
# all but main.o
OBJ_TEST := $(wordlist 2,$(words $(OBJ)),$(OBJ))
DEP_TEST := $(OBJ_TEST:%.o=%.d)
TARGET := build/shpn_tool
TARGETS_TEST := $(SRC_TEST:test/%.c=build/test/%.sym)
include scripts/scripts.mk
include agb/patch.mk
IPS_TARGETS = $(foreach script,$(SCRIPTS),$(script:%=build/%.ips))
BPS_TARGETS = $(foreach script,$(SCRIPTS),$(script:%=build/%.bps))
$(foreach script,$(SCRIPTS),$(eval $(call MAKE_BUILD_TAG,$(script))))
$(foreach script,$(SCRIPTS),$(eval $(call MAKE_ROM,$(script))))
$(foreach script,$(SCRIPTS),$(eval $(call MAKE_IPS,$(script))))
$(foreach script,$(SCRIPTS),$(eval $(call MAKE_BPS,$(script))))
all: $(TARGET) agb $(IPS_TARGETS) $(BPS_TARGETS) | build
.PHONY: clean all test help distclean yyclean agb
.SUFFIXES:
-include $(DEP) $(DEP_TEST)
build:
@mkdir -p build
src/%.tab.c src/%.tab.h: src/%.y
@echo yacc $(notdir $<)
$(VERBOSE) $(ENV) $(YACC) $(YACC_FLAGS) -o $(@:%.h=%.c) $<
src/%.yy.c src/%.yy.h: src/%.l $(SRC_YACC)
@echo lex $(notdir $<)
$(VERBOSE) $(ENV) $(LEX) $(LEX_FLAGS) -o $(@:%.h=%.c) $<
$(eval $(call COMPILE_C,build,src))
$(eval $(call COMPILE_C,build,agb))
$(eval $(call COMPILE_C,build/test,test))
build/script_parse_ctx.o: $(SRC_PARSER)
$(eval $(call LINK_TARGET,$(TARGET).sym,$(OBJ)))
# For each test target, link the objects from src/ (but main.o) and only the test .o we need
$(foreach test,$(TARGETS_TEST),$(eval $(call LINK_TARGET,$(test),$(OBJ_TEST) $(test:%.sym=%.o))))
agb:
@echo make agb
$(VERBOSE) $(MAKE) -C agb
$(TARGET): $(TARGET).sym
@echo strip $(notdir $@)
$(VERBOSE) $(ENV) $(STRIP) $(TARGET).sym -o $@
clean:
@rm -rf build
yyclean:
@rm -f $(SRC_PARSER) $(SRC_PARSER:src/%.c=src/%.h)
distclean: clean yyclean
make -C agb clean
testdir:
@mkdir -p build/test
test: $(TARGETS_TEST) | testdir
-$(foreach tgt,$(TARGETS_TEST),$(tgt)$(\n))
help:
$(info Supported targets:)
$(info all$(\t)$(\t)$(\t)compile everything but tests)
$(info $(TARGET)$(\t)$(\t)compile $(TARGET))
$(info $(TARGET).sym$(\t)compile symbolised $(TARGET))
$(info agb$(\t)$(\t)$(\t)ROM code patches)
$(info build/LANG.rom$(\t)$(\t)translated rom for LANG)
$(info build/LANG.ips$(\t)$(\t)IPS patch for the translation)
$(info build/LANG.bps$(\t)$(\t)BPS patch for the translation)
$(info test$(\t)$(\t)$(\t)run unit tests)
$(info clean$(\t)$(\t)$(\t)remove build artefacts)
$(info yyclean$(\t)$(\t)$(\t)remove $(SRC_PARSER))
$(info distclean$(\t)$(\t)same as clean and yyclean)
$(info help$(\t)$(\t)$(\t)show this message)
$(info Supported LANG values:)
$(info $(SCRIPTS))
$(info Supported environment variables:)
$(info CC)
$(info STRIP)
$(info FLIPS)
$(info YACC)
$(info LEX)
$(info SHPN_ROM$(\t)$(\t)ROM path)
$(info DEBUG$(\t)$(\t)$(\t)compile code with debug info, without optimisations)
$(info ICONV$(\t)$(\t)$(\t)iconv installation prefix)
$(info SANITIZE$(\t)$(\t)build with specified sanitizer (e.g. address))
$(info VERBOSE$(\t)$(\t)$(\t)verbose build command logging)
@: