forked from d0k3/GodMode9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
265 lines (215 loc) · 9.64 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
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
265
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
# SPECS is the directory containing the important build and link files
#---------------------------------------------------------------------------------
export TARGET := EixMode9
ifeq ($(SAFEMODE),1)
export TARGET := WeakMode9
endif
BUILD := build
SOURCES := source source/common source/filesys source/crypto source/fatfs source/nand source/virtual source/game source/gamecart source/quicklz source/qrcodegen source/system source/utils
DATA := data
INCLUDES := common source source/common source/font source/filesys source/crypto source/fatfs source/nand source/virtual source/game source/gamecart source/quicklz source/qrcodegen source/system source/utils
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -DARM9 -march=armv5te -mthumb -mthumb-interwork
ASFLAGS := $(ARCH) -g -x assembler-with-cpp $(INCLUDE)
CFLAGS := $(ARCH) -g -Wall -Wextra -Wpedantic -Wcast-align -Wno-main -O2 \
-mtune=arm946e-s -fomit-frame-pointer -ffast-math -std=gnu11 \
$(INCLUDE) -Wno-unused-function
VERSION := $(shell git describe --tags --abbrev=8)
DBUILTS := $(shell date +'%Y%m%d%H%M%S')
DBUILTL := $(shell date +'%Y-%m-%d %H:%M:%S')
CFLAGS += -DDBUILTS="\"$(DBUILTS)\"" -DDBUILTL="\"$(DBUILTL)\"" -DVERSION="\"$(VERSION)\""
ifeq ($(FONT),ORIG)
CFLAGS += -DFONT_ORIGINAL
else ifeq ($(FONT),6X10)
CFLAGS += -DFONT_6X10
else ifeq ($(FONT),ACORN)
CFLAGS += -DFONT_ACORN
else ifeq ($(FONT),GB)
CFLAGS += -DFONT_GB
else
CFLAGS += -DFONT_6X10
endif
ifeq ($(SAFEMODE),1)
CFLAGS += -DSAFEMODE
endif
ifeq ($(AL3X10MODE),1)
CFLAGS += -DAL3X10MODE
endif
ifeq ($(EIXMODE),1)
CFLAGS += -DEIXMODE
endif
ifeq ($(SALTMODE),1)
CFLAGS += -DSALTMODE
endif
ifeq ($(SWITCH_SCREENS),1)
CFLAGS += -DSWITCH_SCREENS
endif
ifneq ("$(wildcard $(CURDIR)/../$(DATA)/README.md)","")
CFLAGS += -DHARDCODE_README
endif
ifneq ("$(wildcard $(CURDIR)/../$(DATA)/CHANGELOG.md)","")
CFLAGS += -DHARDCODE_CHANGELOG
endif
ifneq ("$(wildcard $(CURDIR)/../$(DATA)/INFOBOX.md)","")
CFLAGS += -DHARDCODE_INFOBOX
endif
ifneq ("$(wildcard $(CURDIR)/../$(DATA)/READMEE.md)","")
CFLAGS += -DHARDCODE_READMEE
endif
ifneq ("$(wildcard $(CURDIR)/../$(DATA)/aeskeydb.bin)","")
CFLAGS += -DHARDCODE_KEYS
endif
ifneq ("$(wildcard $(CURDIR)/../$(DATA)/autorun.gm9)","")
CFLAGS += -DAUTORUN_SCRIPT
endif
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
LDFLAGS = -T../link.ld -nostartfiles -g $(ARCH) -Wl,-Map,$(TARGET).map,-z,max-page-size=512
LIBS :=
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS :=
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT_D := $(CURDIR)/out
export OUTPUT := $(OUTPUT_D)/$(TARGET)
export RELEASE := $(CURDIR)/release
export EIXMODE := $(CURDIR)/eix
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/README.md))) \
$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/READMEE.md))) \
$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/CHANGELOG.md))) \
$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/INFOBOX.md))) \
$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/aeskeydb.bin))) \
$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/autorun.gm9)))
ifeq ($(SAFEMODE),1)
BINFILES += $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/sm9*.*)))
else
BINFILES += $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/gm9*.*)))
endif
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
ifeq ("$(wildcard $(CURDIR)/$(DATA)/vram0.img)","")
export FTCOMMON := -D $(OUTPUT).elf $(OUTPUT_D)/screeninit.elf -C NDMA XDMA
else
export FTCOMMON := -A 0x18000000 -D $(OUTPUT).elf $(OUTPUT_D)/screeninit.elf $(CURDIR)/$(DATA)/vram0.img -C NDMA XDMA memcpy
endif
.PHONY: common clean all firm binary screeninit release
#---------------------------------------------------------------------------------
all: firm ntrboot
common:
@[ -d $(OUTPUT_D) ] || mkdir -p $(OUTPUT_D)
@[ -d $(BUILD) ] || mkdir -p $(BUILD)
screeninit:
@$(MAKE) --no-print-directory dir_out=$(OUTPUT_D) -C screeninit
binary: common
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
firm: binary screeninit
firmtool build $(OUTPUT).firm $(FTCOMMON) -S nand-retail -g
firmtool build $(OUTPUT)_dev.firm $(FTCOMMON) -S nand-dev -g
ntrboot: binary screeninit
firmtool build $(OUTPUT)_ntr.firm $(FTCOMMON) -S spi-retail -g
firmtool build $(OUTPUT)_ntr_dev.firm $(FTCOMMON) -S spi-dev -g
release:
@-rm -fr $(BUILD) $(OUTPUT_D) $(RELEASE)
@$(MAKE) --no-print-directory firm
@$(MAKE) --no-print-directory ntrboot
@[ -d $(RELEASE) ] || mkdir -p $(RELEASE)
@[ -d $(RELEASE)/ntrboot ] || mkdir -p $(RELEASE)/ntrboot
@cp $(OUTPUT).firm $(RELEASE)
@cp $(CURDIR)/README.md $(RELEASE)
@cp $(CURDIR)/HelloScript.gm9 $(RELEASE)
@cp $(OUTPUT)_ntr.firm $(RELEASE)/ntrboot
@cp $(OUTPUT)_ntr.firm.sha $(RELEASE)/ntrboot
@cp $(OUTPUT)_ntr_dev.firm $(RELEASE)/ntrboot
@cp $(OUTPUT)_ntr_dev.firm.sha $(RELEASE)/ntrboot
@cp -R $(CURDIR)/resources/gm9 $(RELEASE)/gm9
@-7z a $(RELEASE)/$(TARGET)-$(VERSION)-$(DBUILTS).zip $(RELEASE)/*
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@-$(MAKE) clean --no-print-directory -C screeninit
@rm -fr $(BUILD) $(OUTPUT_D) $(RELEASE)
#---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).bin : $(OUTPUT).elf
$(OFILES_SOURCES) : $(HFILES)
$(OUTPUT).elf : $(OFILES)
#---------------------------------------------------------------------------------
%.bin: %.elf
@$(OBJCOPY) --set-section-flags .bss=alloc,load,contents -O binary $< $@
@echo built ... $(notdir $@)
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%_qlz.h %.qlz.o: %.qlz
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
#---------------------------------------------------------------------------------
%_bin.h %.bin.o: %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
#---------------------------------------------------------------------------------
%_gm9.h %.gm9.o: %.gm9
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
#---------------------------------------------------------------------------------
%_md.h %.md.o: %.md
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------