-
-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathmakefile.gen
More file actions
264 lines (213 loc) · 7.91 KB
/
makefile.gen
File metadata and controls
264 lines (213 loc) · 7.91 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# get makefile path in unix format
MAKEFILE_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
MAKEFILE_DIR := $(subst \,/,$(MAKEFILE_DIR))
# test if we have access to SGDK environment, if so we can override the GDK var
ifneq ($(wildcard $(MAKEFILE_DIR)bin/rescomp.jar),)
GDK := $(patsubst %/,%,$(MAKEFILE_DIR))
else
$(warning Cannot find SGDK environment ! Current folder = '${MAKEFILE_DIR}')
endif
include $(GDK)/common.mk
BUILD_TYPE := release
ifeq ($(MAKECMDGOALS),debug)
BUILD_TYPE := debug
else ifeq ($(MAKECMDGOALS),Debug)
BUILD_TYPE := debug
else ifeq ($(MAKECMDGOALS),clean-debug)
BUILD_TYPE := debug
else ifeq ($(MAKECMDGOALS),asm)
BUILD_TYPE := asm
else ifeq ($(MAKECMDGOALS),Asm)
BUILD_TYPE := asm
else ifeq ($(MAKECMDGOALS),clean-asm)
BUILD_TYPE := asm
endif
CLEAN := FALSE
ifeq ($(findstring clean,$(MAKECMDGOALS)),clean)
CLEAN := TRUE
endif
SRC_DIR := src
RES_DIR := res
INC_DIR := inc
OUT_DIR := out/$(BUILD_TYPE)
DEP_DIR = $(OUT_DIR)/_deps
OUT_DIR_LIB := $(GDK)/$(OUT_DIR)
SRC_C = $(wildcard *.c)
SRC_C += $(wildcard $(SRC_DIR)/*.c)
SRC_C += $(wildcard $(SRC_DIR)/*/*.c)
SRC_C += $(wildcard $(SRC_DIR)/*/*/*.c)
SRC_C += $(wildcard $(SRC_DIR)/*/*/*/*.c)
SRC_C += $(wildcard $(SRC_DIR)/*/*/*/*/*.c)
SRC_C := $(filter-out $(SRC_DIR)/rom_header.c,$(SRC_C))
SRC_S = $(wildcard *.s)
SRC_S += $(wildcard $(SRC_DIR)/*.s)
SRC_S += $(wildcard $(SRC_DIR)/*/*.s)
SRC_S += $(wildcard $(SRC_DIR)/*/*/*.s)
SRC_S += $(wildcard $(SRC_DIR)/*/*/*/*.s)
SRC_S += $(wildcard $(SRC_DIR)/*/*/*/*/*.s)
SRC_ASM = $(wildcard *.asm)
SRC_ASM += $(wildcard $(SRC_DIR)/*.asm)
SRC_ASM += $(wildcard $(SRC_DIR)/*/*.asm)
SRC_ASM += $(wildcard $(SRC_DIR)/*/*/*.asm)
SRC_ASM += $(wildcard $(SRC_DIR)/*/*/*/*.asm)
SRC_ASM += $(wildcard $(SRC_DIR)/*/*/*/*/*.asm)
SRC_ASM := $(SRC_ASM)
SRC_S80 = $(wildcard *.s80)
SRC_S80 += $(wildcard $(SRC_DIR)/*.s80)
SRC_S80 += $(wildcard $(SRC_DIR)/*/*.s80)
SRC_S80 += $(wildcard $(SRC_DIR)/*/*/*.s80)
SRC_S80 += $(wildcard $(SRC_DIR)/*/*/*/*.s80)
SRC_S80 += $(wildcard $(SRC_DIR)/*/*/*/*/*.s80)
SRC_S80 := $(SRC_S80)
RES_RES = $(wildcard *.res)
RES_RES += $(wildcard $(RES_DIR)/*.res)
RES_RES += $(wildcard $(RES_DIR)/*/*.res)
RES_RES += $(wildcard $(RES_DIR)/*/*/*.res)
RES_RES += $(wildcard $(RES_DIR)/*/*/*/*.res)
RES_RES += $(wildcard $(RES_DIR)/*/*/*/*/*.res)
RES_RES := $(RES_RES)
RES_O = $(RES_RES:.res=.o)
RES_O := $(addprefix $(OUT_DIR)/, $(RES_O))
OBJS = $(RES_RES:.res=.o)
OBJS += $(SRC_S80:.s80=.o)
OBJS += $(SRC_ASM:.asm=.o)
OBJS += $(SRC_S:.s=.o)
OBJS += $(SRC_C:.c=.o)
OBJS := $(addprefix $(OUT_DIR)/, $(OBJS))
LSTS := $(SRC_C:.c=.lst)
LSTS := $(addprefix $(OUT_DIR)/, $(LSTS))
DEPS = $(RES_RES:.res=.d)
DEPS += $(SRC_S:.s=.d)
DEPS += $(SRC_C:.c=.d)
DEPS := $(addprefix $(DEP_DIR)/, $(DEPS))
INCS := -I. -I$(INC_DIR) -I$(RES_DIR) -I$(OUT_DIR) -isystem$(INC_LIB) -isystem$(OUT_DIR_LIB)
DEFAULT_FLAGS := $(EXTRA_FLAGS) -DSGDK_GCC -m68000 -fdiagnostics-color=always -Wall -Wextra -Wno-shift-negative-value -Wno-main -Wno-unused-parameter -fno-builtin -ffunction-sections -fdata-sections -fms-extensions -B$(BIN)
Z80_FLAGS := -i. -i$(SRC_DIR) -i$(INC_DIR) -i$(RES_DIR) -i$(OUT_DIR) -i$(SRC_LIB) -i$(INC_LIB) -i$(INC_LIB)/snd -i$(OUT_DIR_LIB)
ifeq ($(BUILD_TYPE),debug)
# debug
FLAGS := $(INCS) $(DEFAULT_FLAGS) -O1 -DDEBUG=1
CFLAGS := $(FLAGS) -ggdb -g
AFLAGS := -x assembler-with-cpp -Wa,--register-prefix-optional,--bitwise-or $(FLAGS)
LIBMD := $(LIB)/libmd_debug.a
else ifeq ($(BUILD_TYPE),asm)
# asm
FLAGS := $(INCS) $(DEFAULT_FLAGS) -O3 -fuse-linker-plugin -fno-web -fno-gcse -fno-tree-loop-ivcanon -fomit-frame-pointer
CFLAGS := $(FLAGS)
AFLAGS := -x assembler-with-cpp -Wa,--register-prefix-optional,--bitwise-or $(FLAGS)
LIBMD := $(LIB)/libmd.a
else
# release
FLAGS := $(INCS) $(DEFAULT_FLAGS) -O3 -fuse-linker-plugin -fno-web -fno-gcse -fno-tree-loop-ivcanon -fomit-frame-pointer -flto -flto=auto -ffat-lto-objects
CFLAGS := $(FLAGS)
AFLAGS := -x assembler-with-cpp -Wa,--register-prefix-optional,--bitwise-or $(FLAGS)
LIBMD := $(LIB)/libmd.a
endif
.PHONY: default
.PHONY: all
.PHONY: release
.PHONY: Release
.PHONY: debug
.PHONY: Debug
.PHONY: asm
.PHONY: Asm
.PHONY: clean
.PHONY: clean-release
.PHONY: clean-debug
.PHONY: clean-asm
.PHONY: clean-all
default: release
all: release
# include ext.mk if it exists (better to do it after first / default definition)
ifneq ("$(wildcard $(GDK)/ext.mk)","")
include $(GDK)/ext.mk
endif
Release: release
Debug: debug
Asm: asm
clean: clean-all
release: $(OUT_DIR)/rom.bin $(OUT_DIR)/symbol.txt
release: padROM
.PHONY: padROM
debug: $(OUT_DIR)/rom.bin $(OUT_DIR)/symbol.txt
debug: injectSymbolsInROM
debug: padROM
.PHONY: injectSymbolsInROM
asm: $(OBJS) $(LSTS)
clean-all:
$(RM) -r -f out
clean-release: clean-task
clean-debug: clean-task
clean-asm: clean-task
clean-task:
$(RM) -r -f $(OUT_DIR)
.PHONY: clean-task
padROM: $(OUT_DIR)/rom.bin
$(SIZEBND) $(OUT_DIR)/rom.bin -sizealign 131072 -checksum
@$(CP) $(OUT_DIR)/rom.bin out/rom.bin
injectSymbolsInROM: $(OUT_DIR)/rom.bin $(OUT_DIR)/symbol.txt
$(CONVSYM) $(OUT_DIR)/symbol.txt $(OUT_DIR)/rom.bin -in txt -inopt " /fmt='%X %*[TtBbCcDd] %511s' /offsetFirst+" -range 0 FFFFFF -a -ref @MDDBG__SymbolDataPtr
$(OUT_DIR)/rom.bin: $(OUT_DIR)/rom.out $(OUT_DIR)/symbol.txt
$(OBJCPY) -O binary $(OUT_DIR)/rom.out $(OUT_DIR)/rom.bin
$(OUT_DIR)/symbol.txt: $(OUT_DIR)/rom.out
$(NM) $(LTO_PLUGIN) -n -l $(OUT_DIR)/rom.out > $(OUT_DIR)/symbol.txt
$(OUT_DIR)/rom.out: $(OUT_DIR)/sega.o $(OUT_DIR)/cmd_ $(LIBMD)
@$(MKDIR) -p $(dir $@)
$(CC) -m68000 -B$(BIN) -n -T $(GDK)/md.ld -nostdlib $(OUT_DIR)/sega.o @$(OUT_DIR)/cmd_ $(LIBMD) $(LIBGCC) -o $(OUT_DIR)/rom.out -Wl,--gc-sections -flto -flto=auto -ffat-lto-objects
@$(RM) $(OUT_DIR)/cmd_
$(OUT_DIR)/cmd_: $(OBJS)
@$(MKDIR) -p $(dir $@)
$(ECHO) "$(OBJS)" > $(OUT_DIR)/cmd_
# NOTE: sega.s references out/rom_header.bin internally
$(OUT_DIR)/sega.o: out/rom_header.bin
@$(MKDIR) -p $(dir $@)
$(CP) $(SRC_LIB)/boot/sega.s $(OUT_DIR)/sega.s
$(CC) $(AFLAGS) -c $(OUT_DIR)/sega.s -o $@
# NOTE: rom_head.bin need to be located in 'out' folder as it's referenced by boot/sega.s
out/rom_header.bin: $(OUT_DIR)/rom_header.o
$(OBJCPY) -O binary $< $@
$(OUT_DIR)/rom_header.o: $(SRC_DIR)/rom_header.c
@$(MKDIR) -p $(dir $@)
$(CC) $(INCS) $(DEFAULT_FLAGS) -c $< -o $@
# SRC_LIB files are "order-only" deps, right of the pipe. This means we will never overwrite the file in SRC_DIR, even if SRC_LIB is newer.
$(SRC_DIR)/rom_header.c: | $(SRC_LIB)/boot/rom_header.c
@$(MKDIR) -p $(dir $@)
$(CP) $| $@
# source / resource compilation
$(OUT_DIR)/%.o: %.c $(DEP_DIR)/%.d
@$(MKDIR) -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
$(OUT_DIR)/%.o: %.s $(DEP_DIR)/%.d
@$(MKDIR) -p $(dir $@)
$(CC) $(AFLAGS) -c $< -o $@
$(OUT_DIR)/%.o: %.asm
@$(MKDIR) -p $(dir $@)
$(MACCER) -o $(OUT_DIR)/$*.s $<
$(CC) $(AFLAGS) -c $(OUT_DIR)/$*.s -o $@
$(OUT_DIR)/%.o: %.s80
@$(MKDIR) -p $(dir $@)
$(ASMZ80) $(Z80_FLAGS) $< $(OUT_DIR)/$*.o80 $(OUT_DIR)/out.lst
$(BINTOS) $(OUT_DIR)/$*.o80 $(OUT_DIR)/$*.s
$(CC) $(AFLAGS) -c $(OUT_DIR)/$*.s -o $@
$(OUT_DIR)/%.o: %.res
@$(MKDIR) -p $(dir $@)
@$(MKDIR) -p $(dir $(DEP_DIR)/$*.d)
$(RESCOMP) $< $(OUT_DIR)/$*.s -dep $(OUT_DIR)/$*.o
@$(CP) $(OUT_DIR)/$*.d $(DEP_DIR)/$*.d
@$(RM) $(OUT_DIR)/$*.d
@$(CP) $(OUT_DIR)/$*.h $*.h
@$(RM) $(OUT_DIR)/$*.h
$(CC) $(AFLAGS) -c $(OUT_DIR)/$*.s -o $@
# listing files
$(OUT_DIR)/%.lst: %.c $(DEP_DIR)/%.d
@$(MKDIR) -p $(dir $@)
$(CC) $(CFLAGS) -S -c $< -o $@
# deps files (we want resource to be generated first)
$(DEP_DIR)/%.d: %.c $(RES_O)
@$(MKDIR) -p $(dir $@)
$(CC) $(CFLAGS) $< -E -MG -MM -MP -MT $(OUT_DIR)/$*.o -MF $(DEP_DIR)/$*.d
$(DEP_DIR)/%.d: %.s
@$(MKDIR) -p $(dir $@)
$(CC) $(AFLAGS) $< -E -MG -MM -MP -MT $(OUT_DIR)/$*.o -MF $(DEP_DIR)/$*.d
ifeq ($(CLEAN),FALSE)
-include $(DEPS)
endif