forked from doldecomp/sms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
197 lines (155 loc) · 5.63 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
# If defined, wine is not used.
NOWINE ?= 0
ifneq ($(findstring MINGW,$(shell uname)),)
WINDOWS := 1
endif
ifneq ($(findstring MSYS,$(shell uname)),)
WINDOWS := 1
endif
#-------------------------------------------------------------------------------
# Gamecube SDK and Codewarrior Includes
#-------------------------------------------------------------------------------
# Import the SDK path variable and set the paths.
SDK_BASE_PATH := $(SDK_BASE_PATH)
SDK_LIB_PATH := $(SDK_BASE_PATH)/HW2/lib
# The Dec 2001 SDK is required for this, which doesn't use /include.
SDK_INC_PATH := $(SDK_BASE_PATH)
# Check if SDK is not defined, error if not defined.
ifeq ($(SDK_BASE_PATH),)
$(error You have not defined SDK_BASE_PATH. Please ensure the Gamecube SDK is installed and point SDK_BASE_PATH as an environment variable to its location.)
endif
# Import the Codewarrior GC 1.1 path variable and set the include path as well.
CW_BASE_PATH := $(CW_BASE_PATH)
CW_INC_PATH := $(CW_BASE_PATH)/PowerPC_EABI_Support
# Check if CW is not defined, error if not defined.
ifeq ($(CW_BASE_PATH),)
$(error You have not defined CW_BASE_PATH. Please ensure Codewarrior for Gamecube is installed and point CW_BASE_PATH as an environment variable to its location.)
endif
#-------------------------------------------------------------------------------
# Files
#-------------------------------------------------------------------------------
# Used for elf2dol
USES_SBSS2 := yes
TARGET := sms_jp_r0
BUILD_DIR := build/$(TARGET)
SRC_DIRS := src \
src/NPC \
src/MarioUtil \
src/JSystem \
src/System \
src/MSL_C.PPCEABI.bare.H \
ASM_DIRS := asm \
asm/JSystem \
asm/Runtime.PPCEABI.H \
asm/MSL_C.PPCEABI.bare.H \
asm/TRK_MINNOW_DOLPHIN \
asm/base \
asm/db \
asm/os \
asm/mtx \
asm/dvd \
asm/vi \
asm/pad \
asm/ai \
asm/ar \
asm/dsp \
asm/card \
asm/gx \
asm/OdemuExi2 \
asm/amcstubs \
asm/odenotstub \
asm/gd \
asm/si \
asm/exi \
asm/thp \
asm/THPPlayer \
asm/MarioUtil \
asm/M3DUtil \
asm/System \
asm/Strategic \
asm/Player \
asm/NPC \
asm/MSound \
asm/MoveBG \
asm/Map \
asm/GC2D \
asm/Enemy \
asm/Camera \
asm/Animal \
# Inputs
S_FILES := $(wildcard asm/*.s)
C_FILES := $(wildcard src/*.c)
CPP_FILES := $(wildcard src/*.cpp)
LDSCRIPT := $(BUILD_DIR)/ldscript.lcf
# Outputs
DOL := $(BUILD_DIR)/main.dol
ELF := $(DOL:.dol=.elf)
MAP := $(BUILD_DIR)/$(TARGET).map
include obj_files.mk
#-------------------------------------------------------------------------------
# Tools
#-------------------------------------------------------------------------------
MWCC_VERSION := GC/1.2.5
# Programs
ifeq ($(WINDOWS),1)
WINE :=
else
WINE := wine
endif
ifeq ($(NOWINE),1)
WINE :=
endif
AS := $(DEVKITPPC)/bin/powerpc-eabi-as
OBJCOPY := $(DEVKITPPC)/bin/powerpc-eabi-objcopy
CPP := $(DEVKITPPC)/bin/powerpc-eabi-cpp -P
CC := $(WINE) tools/mwcc_compiler/$(MWCC_VERSION)/mwcceppc.exe
LD := $(WINE) tools/mwcc_compiler/$(MWCC_VERSION)/mwldeppc.exe
ELF2DOL := tools/elf2dol
SHA1SUM := sha1sum
PYTHON := python
POSTPROC := tools/postprocess.py
# Options
INCLUDES := -i . -I- -i include -i src -ir "$(SDK_INC_PATH)" -ir "$(CW_INC_PATH)"
ASFLAGS := -m750cl -I include
LDFLAGS := -map $(MAP) -fp hard -nodefaults
CFLAGS := -Cpp_exceptions off -proc gekko -fp hard -O4 -nodefaults -msgstyle gcc $(INCLUDES) -enum int -rostr
# for postprocess.py
PROCFLAGS := -fsymbol-fixup -fprologue-fixup=old_stack
# elf2dol needs to know these in order to calculate sbss correctly.
SDATA_PDHR := 9
SBSS_PDHR := 10
# hardcoded flags
$(BUILD_DIR)/src/System/FlagManager.o: FILE_UNIQUE_CFLAGS = -opt all,nostrength -inline all,level=1,deferred
$(BUILD_DIR)/src/System/ParamInst.o: FILE_UNIQUE_CFLAGS = -use_lmw_stmw=off
#-------------------------------------------------------------------------------
# Recipes
#-------------------------------------------------------------------------------
### Default target ###
default: all
all: $(DOL)
ALL_DIRS := build $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(SRC_DIRS) $(ASM_DIRS))
# Make sure build directory exists before compiling anything
DUMMY != mkdir -p $(ALL_DIRS)
.PHONY: tools
$(LDSCRIPT): ldscript.lcf
$(CPP) -MMD -MP -MT $@ -MF $@.d -I include/ -I . -DBUILD_DIR=$(BUILD_DIR) -o $@ $<
$(DOL): $(ELF) | tools
$(ELF2DOL) $< $@ $(SDATA_PDHR) $(SBSS_PDHR) $(USES_SBSS2)
$(SHA1SUM) -c $(TARGET).sha1
clean:
rm -fdr build
$(MAKE) -C tools clean
tools:
$(MAKE) -C tools
$(ELF): $(O_FILES) $(LDSCRIPT)
$(LD) $(LDFLAGS) -o $@ -lcf $(LDSCRIPT) $(O_FILES)
# The Metrowerks linker doesn't generate physical addresses in the ELF program headers. This fixes it somehow.
$(OBJCOPY) $@ $@
$(BUILD_DIR)/%.o: %.s
$(AS) $(ASFLAGS) -o $@ $<
# $(PYTHON) $(POSTPROC) $(PROCFLAGS) $@
$(BUILD_DIR)/%.o: %.cpp
$(CC) $(CFLAGS) $(FILE_UNIQUE_CFLAGS) -c -o $@ $<
$(BUILD_DIR)/%.o: %.c
$(CC) $(CFLAGS) $(FILE_UNIQUE_CFLAGS) -c -o $@ $<
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true