This repository has been archived by the owner on Sep 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
171 lines (139 loc) · 4.43 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
ifneq ($(findstring MINGW,$(shell uname)),)
WINDOWS := 1
endif
ifneq ($(findstring MSYS,$(shell uname)),)
WINDOWS := 1
endif
#-------------------------------------------------------------------------------
# Files
#-------------------------------------------------------------------------------
# Used for elf2dol
TARGET_COL := wii
TARGET := smg1_us
BUILD_DIR := build/$(TARGET)
SRC_DIRS := src \
src/RVL/dvd src/runtime_libs/debugger/embedded/MetroTRK/Os/dolphin \
src/nw4r/ut \
src/Game/System
ASM_DIRS := asm \
asm/runtime_libs/debugger/embedded/MetroTRK/Portable \
asm/runtime_libs/debugger/embedded/MetroTRK/Export \
asm/runtime_libs/debugger/embedded/MetroTRK/Os/dolphin \
asm/runtime_libs/debugger/embedded/MetroTRK/Processor/ppc/Generic \
asm/runtime_libs/gamedev/cust_connection/cc/exi2/GCN/EXI2_GDEV_GCN \
asm/runtime_libs/gamedev/cust_connection/utils/common \
asm/runtime_libs/gamedev/cust_connection/utils/gc \
asm/ndev \
asm/MSL/MSL_C/MSL_Common_Embedded/Math/Double_precision \
asm/MSL/MSL_C/PPC_EABI/Runtime \
asm/MSL/MSL_C/PPC_EABI/SRC \
asm/MSL/MSL_C/PPC_EABI \
asm/RVL \
asm/RevoEx \
asm/Game/JAudio2 \
asm/nw4r \
asm/Game/J2D \
asm/Game/J3D \
asm/Game/JGadget \
asm/Game/JKernel \
asm/Game/JMath \
asm/Game/JParticle \
asm/Game/JSupport \
asm/Game/JUtility \
asm/Game/NWC24 \
asm/Game/Util \
asm/Game/Animation \
asm/Game/AreaObj \
asm/Game/AudioLib \
asm/Game/Boss \
asm/Game/Camera \
asm/Game/Demo \
asm/Game/Effect \
asm/Game/Enemy \
asm/Game/GameAudio \
asm/Game/Gravity \
asm/Game/LiveActor \
asm/Game/Map \
asm/Game/MapObj \
asm/Game/NameObj \
asm/Game/NPC \
asm/Game/Player \
asm/Game/RhythmLib \
asm/Game/Ride \
asm/Game/Scene \
asm/Game/Screen \
asm/Game/Speaker \
asm/Game/System \
asm/nw4r/ut
# Inputs
S_FILES := $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/*.s))
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
CPP_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
LDSCRIPT := $(BUILD_DIR)/ldscript.lcf
# Outputs
DOL := $(BUILD_DIR)/smg1_us.dol
ELF := $(DOL:.dol=.elf)
MAP := $(BUILD_DIR)/smg1_us.map
include obj_files.mk
O_FILES := $(INIT_O_FILES) $(EXTAB_O_FILES) $(EXTABINDEX_O_FILES) $(TEXT_O_FILES) \
$(CTORS_O_FILES) $(DTORS_O_FILES) $(RODATA_O_FILES) $(DATA_O_FILES) \
$(BSS_O_FILES) $(SDATA_O_FILES) $(SDATA2_O_FILES) $(SBSS2_O_FILES)
#-------------------------------------------------------------------------------
# Tools
#-------------------------------------------------------------------------------
# Programs
ifeq ($(WINDOWS),1)
WINE :=
else
WINE := wine
endif
AS := $(WINE) tools/powerpc-eabi-as.exe
OBJCOPY := $(WINE) tools/powerpc-eabi-objcopy.exe
CPP := cpp -P
CC := $(WINE) tools/mwcceppc.exe
LD := $(WINE) tools/mwldeppc.exe
ELF2DOL := tools/elf2dol
SHA1SUM := sha1sum
PYTHON := python3
#POSTPROC := tools/postprocess.py
# Options
INCLUDES := -i . -I- -i include
ASFLAGS := -mgekko -I include
LDFLAGS := -map $(MAP) -fp hard -nodefaults
CFLAGS := -Cpp_exceptions off -proc gekko -fp hard -O4,s -nodefaults -msgstyle gcc $(INCLUDES)
# for postprocess.py
PROCFLAGS := -fprologue-fixup=old_stack
# elf2dol needs to know these in order to calculate sbss correctly.
SDATA_PDHR := 9
SBSS_PDHR := 10
#-------------------------------------------------------------------------------
# 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 [email protected] -I include/ -I . -DBUILD_DIR=$(BUILD_DIR) -o $@ $<
$(DOL): $(ELF) | tools
$(ELF2DOL) $< $@ $(SDATA_PDHR) $(SBSS_PDHR) $(TARGET_COL)
$(SHA1SUM) -c $(TARGET).sha1
clean:
rm -f -d -r 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 $@ $<
$(BUILD_DIR)/%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
$(BUILD_DIR)/%.o: %.cpp
$(CC) $(CFLAGS) -c -o $@ $<
#$(PYTHON) $(POSTPROC) $(PROCFLAGS) $@