-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
makefile.gen
228 lines (177 loc) · 5.98 KB
/
makefile.gen
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
MAKEFILE_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
MAKEFILE_DIR := $(subst \,/,$(MAKEFILE_DIR))
ifneq ("$(wildcard $(MAKEFILE_DIR)bin/rescomp.jar)","")
GDK := $(patsubst %/,%,$(MAKEFILE_DIR))
endif
include $(GDK)/common.mk
SRC := src
RES := res
INCLUDE := inc
OUT := out
SRC_C= $(wildcard *.c)
SRC_C+= $(wildcard $(SRC)/*.c)
SRC_C+= $(wildcard $(SRC)/*/*.c)
SRC_C+= $(wildcard $(SRC)/*/*/*.c)
SRC_C:= $(filter-out $(SRC)/boot/rom_head.c,$(SRC_C))
ifeq ($(SRC_C),)
SRC_C=$(SRC)/main.c
endif
SRC_S= $(wildcard *.s)
SRC_S+= $(wildcard $(SRC)/*.s)
SRC_S+= $(wildcard $(SRC)/*/*.s)
SRC_S+= $(wildcard $(SRC)/*/*/*.s)
SRC_S:= $(filter-out $(SRC)/boot/sega.s,$(SRC_S))
SRC_ASM= $(wildcard *.asm)
SRC_ASM+= $(wildcard $(SRC)/*.asm)
SRC_ASM+= $(wildcard $(SRC)/*/*.asm)
SRC_ASM+= $(wildcard $(SRC)/*/*/*.asm)
SRC_S80= $(wildcard *.s80)
SRC_S80+= $(wildcard $(SRC)/*.s80)
SRC_S80+= $(wildcard $(SRC)/*/*.s80)
SRC_S80+= $(wildcard $(SRC)/*/*/*.s80)
RES_C= $(wildcard $(RES)/*.c)
RES_S= $(wildcard $(RES)/*.s)
RES_RES= $(wildcard *.res)
RES_RES+= $(wildcard $(RES)/*.res)
RES_RS= $(RES_RES:.res=.rs)
RES_H= $(RES_RES:.res=.h)
RES_DEP= $(RES_RES:.res=.d)
RES_DEPS= $(addprefix $(OUT)/, $(RES_DEP))
OBJ= $(RES_RES:.res=.o)
OBJ+= $(RES_S:.s=.o)
OBJ+= $(RES_C:.c=.o)
OBJ+= $(SRC_S80:.s80=.o)
OBJ+= $(SRC_ASM:.asm=.o)
OBJ+= $(SRC_S:.s=.o)
OBJ+= $(SRC_C:.c=.o)
OBJS:= $(addprefix $(OUT)/, $(OBJ))
DEPS:= $(OBJS:.o=.d)
LST:= $(SRC_C:.c=.lst)
LSTS:= $(addprefix $(OUT)/, $(LST))
INCS:= -I$(INCLUDE) -I$(SRC) -I$(RES) -I$(INCLUDE_LIB) -I$(RES_LIB)
DEFAULT_FLAGS= $(EXTRA_FLAGS) -DSGDK_GCC -m68000 -Wall -Wextra -Wno-shift-negative-value -Wno-main -Wno-unused-parameter -fno-builtin -ffunction-sections -fdata-sections -fms-extensions $(INCS) -B$(BIN)
FLAGSZ80:= -i$(SRC) -i$(INCLUDE) -i$(RES) -i$(SRC_LIB) -i$(INCLUDE_LIB) -i$(INCLUDE_LIB)/snd
all: release
default: release
Default: release
Debug: debug
Release: release
Asm: asm
#release: FLAGS= $(DEFAULT_FLAGS) -Os -fomit-frame-pointer -fuse-linker-plugin -flto
release: FLAGS= $(DEFAULT_FLAGS) -O3 -fuse-linker-plugin -fno-web -fno-gcse -fomit-frame-pointer -flto -flto=auto -ffat-lto-objects
release: CFLAGS= $(FLAGS)
release: AFLAGS= $(FLAGS)
release: LIBMD= $(LIB)/libmd.a
release: $(OUT)/rom.bin $(OUT)/symbol.txt
.PHONY: release
#release: $(info $$var is [${SRC_C}])
debug: FLAGS= $(DEFAULT_FLAGS) -O1 -DDEBUG=1
debug: CFLAGS= $(FLAGS) -ggdb
debug: AFLAGS= $(FLAGS)
debug: LIBMD= $(LIB)/libmd_debug.a
debug: $(OUT)/rom.bin $(OUT)/rom.out $(OUT)/symbol.txt
.PHONY: debug
asm: FLAGS= $(DEFAULT_FLAGS) -O3 -fuse-linker-plugin -fno-web -fno-gcse -fomit-frame-pointer -S
asm: CFLAGS= $(FLAGS)
asm: AFLAGS= $(FLAGS)
asm: LIBMD= $(LIB)/libmd.a
asm: $(LSTS)
.PHONY: asm
-include $(DEPS)
define MAIN_C_CONTENT
#include "genesis.h"
int main(bool hardReset){
VDP_drawText("Hello SGDK!", 12, 12);
while(TRUE) { SYS_doVBlankProcess(); }
return 0;
}
endef
$(SRC)/main.c: export MAIN_C_CONTENT:=$(MAIN_C_CONTENT)
$(SRC)/main.c:
$(MKDIR) -p $(dir $@)
$(ECHO) "$${MAIN_C_CONTENT}" > $@
# include ext.mk if it exists (better to do it after release rule definition)
ifneq ("$(wildcard $(GDK)/ext.mk)","")
include $(GDK)/ext.mk
endif
cleantmp:
$(RM) -f $(RES_RS)
.PHONY: cleantmp
cleandep:
$(RM) -f $(DEPS)
.PHONY: cleandep
cleanlst:
$(RM) -f $(LSTS)
.PHONY: cleanlst
cleanres: cleantmp
$(RM) -f $(RES_H) $(RES_DEP) $(RES_DEPS)
.PHONY: cleanres
cleanobj:
$(RM) -f $(OBJS) $(OUT)/sega.o $(OUT)/rom_head.bin $(OUT)/rom_head.o $(OUT)/rom.out
.PHONY: cleanobj
clean: cleanobj cleanres cleanlst cleandep
$(RM) -f $(OUT)/out.lst $(OUT)/cmd_ $(OUT)/symbol.txt $(OUT)/rom.nm $(OUT)/rom.wch $(OUT)/rom.bin
.PHONY: clean
cleanrelease: clean
.PHONY: cleanrelease
cleandebug: clean
.PHONY: cleandebug
cleanasm: cleanlst
.PHONY: cleanasm
cleandefault: clean
cleanDefault: clean
.PHONY: cleandefault cleanDefault
cleanRelease: cleanrelease
cleanDebug: cleandebug
cleanAsm: cleanasm
.PHONY: cleanRelease cleanDebug cleanAsm
$(OUT)/rom.bin: $(OUT)/rom.out
$(OBJCPY) -O binary $(OUT)/rom.out $(OUT)/rom.bin
$(SIZEBND) $(OUT)/rom.bin -sizealign 131072 -checksum
$(OUT)/symbol.txt: $(OUT)/rom.out
$(NM) $(LTO_PLUGIN) -n $(OUT)/rom.out > $(OUT)/symbol.txt
$(OUT)/rom.out: $(OUT)/sega.o $(OUT)/cmd_ $(LIBMD)
$(MKDIR) -p $(dir $@)
$(CC) -m68000 -B$(BIN) -n -T $(GDK)/md.ld -nostdlib $(OUT)/sega.o @$(OUT)/cmd_ $(LIBMD) $(LIBGCC) -o $(OUT)/rom.out -Wl,--gc-sections -flto -flto=auto -ffat-lto-objects
$(RM) $(OUT)/cmd_
$(OUT)/cmd_: $(OBJS)
$(MKDIR) -p $(dir $@)
$(ECHO) "$(OBJS)" > $(OUT)/cmd_
# NOTE: sega.s references rom_head.bin internally.
$(OUT)/sega.o: $(SRC)/boot/sega.s $(OUT)/rom_head.bin
$(CC) -x assembler-with-cpp -Wa,--register-prefix-optional,--bitwise-or $(AFLAGS) -c $(SRC)/boot/sega.s -o $@
$(OUT)/rom_head.bin: $(OUT)/rom_head.o
$(OBJCPY) -O binary $< $@
$(OUT)/rom_head.o: $(SRC)/boot/rom_head.c
$(MKDIR) -p $(dir $@)
$(CC) $(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, even if SRC_LIB is newer.
$(SRC)/boot/sega.s: | $(SRC_LIB)/boot/sega.s
$(MKDIR) -p $(dir $@)
$(CP) $| $@
$(SRC)/boot/rom_head.c: | $(SRC_LIB)/boot/rom_head.c
$(MKDIR) -p $(dir $@)
$(CP) $| $@
$(OUT)/%.lst: %.c
$(MKDIR) -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
$(OUT)/%.o: %.c
$(MKDIR) -p $(dir $@)
$(CC) $(CFLAGS) -MMD -c $< -o $@
$(OUT)/%.o: %.s
$(MKDIR) -p $(dir $@)
$(CC) -x assembler-with-cpp -Wa,--register-prefix-optional,--bitwise-or $(AFLAGS) -MMD -c $< -o $@
$(OUT)/%.o: %.rs
$(MKDIR) -p $(dir $@)
$(CC) -x assembler-with-cpp -Wa,--register-prefix-optional,--bitwise-or $(AFLAGS) -c $*.rs -o $@
$(CP) $*.d $(OUT)/$*.d
$(RM) $*.d
%.rs: %.res
$(RESCOMP) $*.res $*.rs -dep $(OUT)/$*.o
%.s: %.asm
$(MACCER) -o $@ $<
%.o80: %.s80
$(ASMZ80) $(FLAGSZ80) $< $@ $(OUT)/out.lst
%.s: %.o80
$(BINTOS) $<