forked from zeldaret/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
259 lines (198 loc) · 7.27 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
WINDOWS := $(shell which wine ; echo $$?)
UNAME_S := $(shell uname -s)
#-------------------------------------------------------------------------------
# Options
#-------------------------------------------------------------------------------
DEBUG ?= 0
ifeq ($(DEBUG), 1)
CFLAGS += -g
else
CFLAGS +=
endif
#-------------------------------------------------------------------------------
# Files
#-------------------------------------------------------------------------------
TARGET_COL := wii
TARGET := dolzel2
BUILD_PATH := build
BUILD_DIR := $(BUILD_PATH)/$(TARGET)
TARGET_ISO := $(BUILD_DIR)/dolzel2.iso
SRC_DIRS := $(shell find src/ libs/ -type f -name '*.cpp')
ASM_DIRS := $(shell find asm/ -type f -name '*.s')
# Inputs
LDSCRIPT := $(BUILD_DIR)/ldscript.lcf
# Outputs
DOL := $(BUILD_DIR)/main.dol
DOL_SHIFT := $(BUILD_DIR)/main_shift.dol
ELF := $(DOL:.dol=.elf)
ELF_SHIFT := $(DOL_SHIFT:.dol=.elf)
MAP := $(BUILD_DIR)/dolzel2.map
# include list of object files
include obj_files.mk
#-------------------------------------------------------------------------------
# Tools
#-------------------------------------------------------------------------------
MWCC_VERSION := 2.7
# Programs
ifeq ($(WINE),) #if WINE varible is unset (wine can be replaced with a less bloated translation layer such as wibo if needed)
ifeq ($(WINDOWS),1)
WINE :=
else
WINE := wine
endif
endif
ifeq ($(WINE_LD),)
WINE_LD := $(WINE)
endif
# Hack for OSX
ifeq ($(UNAME_S),Darwin)
CPP := cpp-10 -P
SHA1SUM := shasum -a 1
else
CPP := cpp -P
SHA1SUM := sha1sum
endif
AS := $(DEVKITPPC)/bin/powerpc-eabi-as
OBJCOPY := $(DEVKITPPC)/bin/powerpc-eabi-objcopy
STRIP := $(DEVKITPPC)/bin/powerpc-eabi-strip
CC := $(WINE) tools/mwcc_compiler/$(MWCC_VERSION)/mwcceppc_modded.exe
DOLPHIN_LIB_CC := $(WINE) tools/mwcc_compiler/1.2.5n/mwcceppc.exe
LD := $(WINE_LD) tools/mwcc_compiler/$(MWCC_VERSION)/mwldeppc.exe
ELF2DOL := $(BUILD_PATH)/elf2dol
YAZ0 := $(BUILD_PATH)/yaz0.so
PYTHON := python3
ICONV := iconv
DOXYGEN := doxygen
MAKEREL := tools/makerel.py
IMAGENAME := gz2e01.iso
# Options
INCLUDES := -i include -i include/dolphin/ -i src
# Assembler flags
ASFLAGS := -mgekko -I include
# Linker flags
LDFLAGS := -unused -map $(MAP) -fp hard -nodefaults -w off
# Compiler flags
CFLAGS += -Cpp_exceptions off -proc gekko -fp hard -O3 -nodefaults -str pool,readonly,reuse -RTTI off -maxerrors 5 -enum int $(INCLUDES)
DEPFLAGS := $(if $(DISABLE_DEPS),,-MD)
# O4,p for init.c
$(BUILD_DIR)/src/init.o: CFLAGS := -Cpp_exceptions off -proc gekko -fp hard -O4,p -nodefaults -str pool,readonly,reuse -RTTI off -maxerrors 5 -enum int $(INCLUDES)
# __start.c needs mwcc 1.2.5 and O4,p
$(BUILD_DIR)/src/__start.o: CFLAGS := -Cpp_exceptions off -proc gekko -fp hard -O4,p -nodefaults -str pool,readonly,reuse -RTTI off -maxerrors 5 -enum int $(INCLUDES)
$(BUILD_DIR)/src/__start.o: MWCC_VERSION := 1.2.5
$(BUILD_DIR)/src/__start.o: CC := $(WINE) tools/mwcc_compiler/$(MWCC_VERSION)/mwcceppc.exe
# elf2dol needs to know these in order to calculate sbss correctly.
SDATA_PDHR := 9
SBSS_PDHR := 10
#-------------------------------------------------------------------------------
# Recipes
#-------------------------------------------------------------------------------
### Default target ###
default: all
dol: $(DOL)
$(SHA1SUM) -c $(TARGET).sha1
all: dirs dol
# Make sure build directory exists before compiling anything
dirs:
@mkdir -p build
@mkdir -p $(BUILD_DIR)
$(DOL): $(ELF) | tools
$(ELF2DOL) $< $@ $(SDATA_PDHR) $(SBSS_PDHR) $(TARGET_COL)
clean:
rm -f -d -r $(BUILD_DIR)/libs
rm -f -d -r $(BUILD_DIR)/src
rm -f $(ELF)
rm -f $(DOL)
rm -f $(ELF_SHIFT)
rm -f $(DOL_SHIFT)
rm -f $(BUILD_DIR)/*.a
clean_game:
rm -r -f -d $(TARGET)/game
rm -r -f -d $(TARGET_ISO)
clean_assets:
rm -r -f -d game
clean_all:
rm -f -d -r build
clean_rels:
rm -f -d -r $(BUILD_DIR)/rel
rm -f $(BUILD_PATH)/*.rel
tools: dirs $(ELF2DOL) $(YAZ0)
assets:
@mkdir -p game
$(PYTHON) tools/extract_game_assets.py $(IMAGENAME) game
docs:
$(DOXYGEN) Doxyfile
rels: $(ELF) $(RELS)
@echo generating RELs from .plf
@echo $(RELS) > build/plf_files
$(PYTHON) $(MAKEREL) build --string-table $(BUILD_DIR)/frameworkF.str @build/plf_files $(ELF)
./tp check --rels
$(ELF): $(LIBS) $(O_FILES)
@echo $(O_FILES) > build/o_files
@$(PYTHON) tools/lcf.py dol --output $(LDSCRIPT)
$(LD) -application $(LDFLAGS) -o $@ -lcf $(LDSCRIPT) @build/o_files $(LIBS)
$(ELF_SHIFT): $(DOL)
@echo $(O_FILES) > build/o_files
@$(PYTHON) tools/lcf.py dol_shift --output $(LDSCRIPT)
$(LD) -application $(LDFLAGS) -o $@ -lcf $(LDSCRIPT) @build/o_files $(LIBS)
$(DOL_SHIFT): $(ELF_SHIFT) | tools
$(ELF2DOL) $< $@ $(SDATA_PDHR) $(SBSS_PDHR) $(TARGET_COL)
shift: dirs $(DOL_SHIFT)
shiftedrels: shift $(RELS)
@echo generating shifted RELs from .plf
@echo $(RELS) > build/plf_files
$(PYTHON) $(MAKEREL) build --string-table $(BUILD_DIR)/frameworkF.str @build/plf_files $(ELF_SHIFT)
game: shiftedrels
@mkdir -p game
@$(PYTHON) tools/package_game_assets.py ./game $(BUILD_PATH) copyCode native
game-fast: shiftedrels
@mkdir -p game
@$(PYTHON) tools/package_game_assets.py ./game $(BUILD_PATH) copyCode oead
game-nocompile:
@mkdir -p game
@$(PYTHON) tools/package_game_assets.py ./game $(BUILD_PATH) noCopyCode native
game-nocompile-fast:
@mkdir -p game
@$(PYTHON) tools/package_game_assets.py ./game $(BUILD_PATH) noCopyCode oead
rungame-nocompile: game-nocompile
@echo If you are playing on a shifted game make sure Hyrule Field Speed hack is disabled in dolphin!
dolphin-emu $(BUILD_DIR)/game/sys/main.dol
rungame-nocompile-fast: game-nocompile-fast
@echo If you are playing on a shifted game make sure Hyrule Field Speed hack is disabled in dolphin!
dolphin-emu $(BUILD_DIR)/game/sys/main.dol
rungame-fast: game-fast
@echo If you are playing on a shifted game make sure Hyrule Field Speed hack is disabled in dolphin!
dolphin-emu $(BUILD_DIR)/game/sys/main.dol
rungame: game
@echo If you are playing on a shifted game make sure Hyrule Field Speed hack is disabled in dolphin!
dolphin-emu $(BUILD_DIR)/game/sys/main.dol
iso: game
@$(PYTHON) tools/packageISO.py $(BUILD_DIR)/game/ $(TARGET_ISO)
$(BUILD_DIR)/%.o: %.c $(BUILD_DIR)/%.d
@mkdir -p $(@D)
@echo building... $<
@$(ICONV) -f UTF-8 -t CP932 < $< > $(basename $@).c
@$(CC) $(CFLAGS) $(DEPFLAGS) -c -o $(dir $@) $(basename $@).c
@if [ -z '$(DISABLE_DEPS)' ]; then tools/transform-dep.py '$(basename $@).d' '$(basename $@).d'; touch -c $@; fi
$(BUILD_DIR)/%.o: %.cpp $(BUILD_DIR)/%.d
@mkdir -p $(@D)
@echo building... $<
@$(ICONV) -f UTF-8 -t CP932 < $< > $(basename $@).cpp
@$(CC) $(CFLAGS) $(DEPFLAGS) -c -o $(dir $@) $(basename $@).cpp
@if [ -z '$(DISABLE_DEPS)' ]; then tools/transform-dep.py '$(basename $@).d' '$(basename $@).d'; touch -c $@; fi
ifndef DISABLE_DEPS
D_FILES := $(O_FILES:.o=.d)
$(D_FILES):
include $(wildcard $(D_FILES))
endif
# shared cpp files for RELs
$(BUILD_DIR)/rel/%.o: rel/%.cpp
@mkdir -p $(@D)
$(CC) $(CFLAGS) -sdata 0 -sdata2 0 -c -o $@ $<
# include library and rel makefiles
-include include_link.mk
# tools
include tools/elf2dol/Makefile
include tools/yaz0/Makefile
### Debug Print ###
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true
.PHONY: default all dirs clean tools docs shift game rungame iso print-%