forked from untoxa/gbvm
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile.common
179 lines (138 loc) · 4.55 KB
/
Makefile.common
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
TOP := $(dir $(lastword $(MAKEFILE_LIST)))
GBDK = $(TOP)../gbdk
CC = $(GBDK)/bin/lcc
TEST_DIR = $(TOP)test
TEST_FW = $(TEST_DIR)/framework
EXAMPLES_DIR = ./examples
EMU = $(TOP)../bgb/bgb
GBSPACK = $(TOP)../gbspack/gbspack
TEST_CHK = python $(CURDIR)/$(TEST_FW)/unit_checker.py
GBS_CLI = node $(TOP)../gb-studio/out/cli/gb-studio-cli.js
PLATFORM =
ROMTITLE = "GBSTUDIO"
ROM_BUILD_DIR = build
OBJDIR = obj
REL_OBJDIR = obj/_rel
CFLAGS = $(PLATFORM) -I$(TOP)include -Wa-I$(TOP)include
LFLAGS_NBANKS += -Wm-yoA -Wm-ya4
LFLAGS_SYMBOLS = -Wl-j -Wl-m -Wl-w -Wm-yS
LFLAGS = $(PLATFORM) -Wm-yt$(CART_MBC) $(LFLAGS_NBANKS) $(LFLAGS_SYMBOLS) -Wl-klib -Wl-g.STACK=0xDF00 -Wi-e
PACKFLAGS = -b 1 -f 255 -e rel -c
EMUFLAGS = \
-set "Color0=E8E8E8" \
-set "Color1=A0A0A0" \
-set "Color2=585858" \
-set "Color3=101010" \
-set "DebugWRAMbreak=0" \
-set "DebugSrcBrk=1" \
-hf -stateonexit \
-screenonexit ./capture.bmp
EMU_FORCE_DMG = -set "SystemMode=0"
EMU_FORCE_CGB = -set "SystemMode=1"
EMU_FORCE_SGB = -set "SystemMode=2"
TARGET = $(ROM_BUILD_DIR)/rom.gb
ASRC = $(foreach dir,$(TOP)src,$(notdir $(wildcard $(dir)/*.s)))
CSRC = $(foreach dir,$(TOP)src,$(notdir $(wildcard $(dir)/*.c)))
ACORE = $(foreach dir,$(TOP)src/core,$(notdir $(wildcard $(dir)/*.s)))
CCORE = $(foreach dir,$(TOP)src/core,$(notdir $(wildcard $(dir)/*.c)))
CSTATES = $(foreach dir,$(TOP)src/states,$(notdir $(wildcard $(dir)/*.c)))
ASTATES = $(foreach dir,$(TOP)src/states,$(notdir $(wildcard $(dir)/*.s)))
ENGINE_OBJS = $(CSRC:%.c=$(TOP)$(OBJDIR)/%.o) \
$(ASRC:%.s=$(TOP)$(OBJDIR)/%.o) \
$(ACORE:%.s=$(TOP)$(OBJDIR)/%.o) \
$(CCORE:%.c=$(TOP)$(OBJDIR)/%.o) \
$(CSTATES:%.c=$(TOP)$(OBJDIR)/%.o) \
$(ASTATES:%.s=$(TOP)$(OBJDIR)/%.o)
OBJS = $(ENGINE_OBJS)
REL_OBJS = $(OBJS:$(OBJDIR)/%.o=$(REL_OBJDIR)/%.rel)
all: settings directories BUILD
.PHONY: directories clean release debug profile AP DMG CGB SGB MBC3 MBC5 hUGE GBT test rom BUILD
.SECONDARY: $(OBJS)
AP:
$(eval PLATFORM = -msm83:ap)
$(eval TARGET = $(patsubst %.gb,%.pocket,$(TARGET)))
@echo "Analogue pocket build"
release:
$(eval CFLAGS += -Wf'--max-allocs-per-node 50000')
@echo "RELEASE mode ON"
debug:
$(eval CFLAGS += -Wf--fverbose-asm -Wf--debug -Wl-m -Wl-w -Wl-y -DVM_DEBUG_OUTPUT)
$(eval CFLAGS += -Wf--nolospre -Wf--nogcse)
$(eval LFLAGS += -Wf--debug -Wl-m -Wl-w -Wl-y)
@echo "DEBUG mode ON"
profile:
$(eval CFLAGS += -Wf--profile)
@echo "PROFILE mode ON"
DMG:
@echo "DMG mode ON"
$(eval EMUFLAGS += $(EMU_FORCE_DMG))
CGB:
$(eval CFLAGS += -DCGB)
$(eval LFLAGS += -Wm-yC)
$(eval EMUFLAGS += $(EMU_FORCE_CGB))
@echo "CGB mode ON"
SGB:
$(eval CFLAGS += -DSGB)
$(eval LFLAGS += -Wm-ys)
$(eval EMUFLAGS += $(EMU_FORCE_SGB))
@echo "SGB mode ON"
batteryless:
$(eval PACKFLAGS += -a 4)
$(eval BATTERYLESS = 1)
$(eval CFLAGS += -DBATTERYLESS)
@echo "BETTERYLESS SAVE ON"
MBC3:
$(eval CART_MBC = 0x10)
@echo "Using MBC3"
MBC5:
$(eval CART_MBC = 0x1B)
@echo "Using MBC5"
hUGE:
$(eval CFLAGS += -DHUGE_TRACKER)
$(eval LFLAGS += -Wl-l$(TOP)lib/hUGEDriver.lib)
@echo "Enable hUGETracker"
GBT:
$(eval CFLAGS += -DGBT_PLAYER)
$(eval LFLAGS += -Wl-l$(TOP)lib/gbt_player.lib)
$(eval PACKFLAGS += -s 1:800)
@echo "Enable GBTPlayer"
directories: $(ROM_BUILD_DIR) $(OBJDIR) $(REL_OBJDIR)
$(ROM_BUILD_DIR):
mkdir -p $(ROM_BUILD_DIR)
$(OBJDIR):
mkdir -p $(OBJDIR)
mkdir -p $(TOP)$(OBJDIR)
$(REL_OBJDIR):
mkdir -p $(REL_OBJDIR)
$(TOP)$(OBJDIR)/%.o: $(TOP)src/core/%.c
$(CC) $(CFLAGS) -Wf-MMD $(filter -Wf-ba%, $(subst .d,-Wf-ba,$(suffix $(<:%.c=%)))) -c -o $@ $<
$(TOP)$(OBJDIR)/%.o: $(TOP)src/core/%.s
$(CC) $(CFLAGS) -c -o $@ $<
$(TOP)$(OBJDIR)/%.o: $(TOP)src/states/%.c
$(CC) $(CFLAGS) -Wf-MMD -c -o $@ $<
$(TOP)$(OBJDIR)/%.o: $(TOP)src/states/%.s
$(CC) $(CFLAGS) -c -o $@ $<
$(TOP)$(OBJDIR)/%.o: $(TOP)src/%.c
$(CC) $(CFLAGS) -Wf-MMD -c -o $@ $<
$(TOP)$(OBJDIR)/%.o: $(TOP)src/%.s
$(CC) $(CFLAGS) -c -o $@ $<
$(REL_OBJDIR)/linkfile.lk: $(OBJS)
mkdir -p $(REL_OBJDIR)
$(shell rm -f $(REL_OBJDIR)/packfile.pk)
$(foreach O,$(OBJS),$(shell echo $O >>$(REL_OBJDIR)/packfile.pk))
$(eval CART_SIZE=$(shell $(GBSPACK) $(PACKFLAGS) -o $(REL_OBJDIR) -i $(REL_OBJDIR)/packfile.pk))
$(shell echo -g __start_save=$(shell expr $(CART_SIZE) - 4 ) >$@)
$(foreach O,$(REL_OBJS),$(shell echo $O >>$@))
BUILD: $(REL_OBJDIR)/linkfile.lk
$(CC) $(LFLAGS) -Wm-yn$(ROMTITLE) -o $(TARGET) -Wl-f$<
clean:
@echo "CLEANUP..."
rm -rf $(TOP)$(OBJDIR)
rm -rf $(OBJDIR)
rm -rf $(ROM_BUILD_DIR)
rm -f $(TEST_DIR)/*/capture.bmp
rm -rf $(TEST_DIR)/*/obj
rm -rf $(TEST_DIR)/*/build
rm -rf $(EXAMPLES_DIR)/*/obj
rm -rf $(EXAMPLES_DIR)/*/build
rom: directories BUILD