-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathMakefile
More file actions
268 lines (227 loc) · 8.29 KB
/
Makefile
File metadata and controls
268 lines (227 loc) · 8.29 KB
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
266
267
268
###############################################################################
# makefile
# by Alex Chadwick
#
# A makefile script for generation of the brainslug project
###############################################################################
###############################################################################
# helper variables
C := ,
###############################################################################
# devkitpro settings
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
endif
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitPRO")
endif
ifeq ($(OS),Windows_NT)
$(info Compiling from $(OS))
PORTLIBS := $(DEVKITPRO)/portlibs/ppc
PATH := $(DEVKITPPC)/bin:$(PORTLIBS)/bin:$(PATH)
ifeq ($(DEVKITPRO),$(subst :, ,$(DEVKITPRO)))
DEVKITPRO := $(patsubst /$(firstword $(subst /, ,$(DEVKITPRO)))/%,$(firstword $(subst /, ,$(DEVKITPRO))):/%,$(DEVKITPRO))
$(info DEVKITPRO corrected to $(DEVKITPRO))
else
$(info DEVKITPRO is $(DEVKITPRO))
endif
PORTLIBS := $(DEVKITPRO)/portlibs/ppc
ifeq ($(DEVKITPPC),$(subst :, ,$(DEVKITPPC)))
DEVKITPPC := $(patsubst /$(firstword $(subst /, ,$(DEVKITPPC)))/%,$(firstword $(subst /, ,$(DEVKITPPC))):/%,$(DEVKITPPC))
$(info DEVKITPPC corrected to $(DEVKITPPC))
else
$(info DEVKITPPC is $(DEVKITPPC))
endif
else
$(info Compiling from Unix)
PORTLIBS := $(DEVKITPRO)/portlibs/ppc
$(info DEVKITPRO is $(DEVKITPRO))
$(info DEVKITPPC is $(DEVKITPPC))
endif
###############################################################################
# Compiler settings
# The toolchain to use.
PREFIX ?= powerpc-eabi-
# Tools to use
AS := $(PREFIX)as
LD := $(PREFIX)g++
CC := $(PREFIX)g++
OBJDUMP := $(PREFIX)objdump
OBJCOPY := $(PREFIX)objcopy
ELF2DOL ?= elf2dol
# -O2: optimise lots
# -Wl$C--gc-sections: remove unneeded symbols
# -mrvl: enable wii/gamecube compilation
# -mcpu=750: enable processor specific compilation
# -meabi: enable eabi specific compilation
# -Wl$C--section-start$C.init=0x80a00000:
# start the executable after 0x80a00000 so we don't have to move in order to
# load a dol file from a disk.
# -Wl$C-Map$C: generate a map file
LDFLAGS += -O2 -Wl$C--gc-sections \
-mrvl -mcpu=750 -meabi \
-Wl$C--section-start$C.init=0x80a00000 \
$(patsubst %,-Wl$C-Map$C%,$(strip $(MAP)))
# -O2: optimise lots
# -Wall: generate lots of warnings
# -x c: compile as C code
# -std=gnu99: use the C99 standard with GNU extensions
# -DGEKKO: define the symbol GEKKO (used in some libogc headers)
# -DHW_RVL: define the symbol HW_RVL (used in some libogc headers)
# -D__wii__: define the symbol __wii__ (used in some libogc headers)
# -mrvl: enable wii/gamecube compilation
# -mcpu=750: enable processor specific compilation
# -meabi: enable eabi specific compilation
# -mhard-float: enable hardware floating point instructions
# -msdata=eabi: use r2 and r13 as small data areas
# -memb: enable embedded application specific compilation
# -ffunction-sections: split up functions so linker can garbage collect
# -fdata-sections: split up data so linker can garbage collect
CFLAGS += -O2 -Wall -x c -std=gnu99 \
-DGEKKO -DHW_RVL -D__wii__ \
-mrvl -mcpu=750 -meabi -mhard-float \
-msdata=eabi -memb -ffunction-sections -fdata-sections
ifdef DEBUG
else
CFLAGS += -DNDEBUG
endif
###############################################################################
# Parameters
# Used to suppress command echo.
Q ?= @
LOG ?= @echo $@
# The intermediate directory for compiled object files.
BUILD ?= build
# The output directory for compiled results.
BIN ?= bin
# The output directory for releases.
RELEASE?= release
# The name of the output file to generate.
TARGET ?= $(BIN)/boot.dol
# The name of the assembler listing file to generate.
LIST ?= $(BIN)/boot.list
# The name of the map file to generate.
MAP ?= $(BIN)/boot.map
###############################################################################
# Variable init
# The names of libraries to use.
LIBS := ogc mxml fat
# The source files to compile.
SRC :=
# Phony targets
PHONY :=
# Include directories
INC_DIRS := .
# Library directories
LIB_DIRS := $(DEVKITPPC) $(DEVKITPPC)/powerpc-eabi \
$(DEVKITPRO)/libogc $(DEVKITPRO)/libogc/lib/wii \
$(wildcard $(DEVKITPPC)/lib/gcc/powerpc-eabi/*) \
$(PORTLIBS) $(PORTLIBS)/wii
###############################################################################
# Rule to make everything.
PHONY += all
all : $(TARGET) $(BIN)/boot.elf
###############################################################################
# Install rule
BSLUGDIR := $(DEVKITPRO)/bslug
# Rule to install bslug.
PHONY += install
install : bslug_include modules symbols bslug.ld bslug_elf.ld
$(LOG)
$(addprefix $Qrm -rf ,$(wildcard $(BSLUGDIR)))
$Qmkdir $(BSLUGDIR)
$Qcp -r bslug_include $(BSLUGDIR)/include
$Q$(MAKE) -C modules install BSLUGDIR=$(BSLUGDIR)
$Qcp -r symbols $(BSLUGDIR)
$Qcp -r bslug.ld $(BSLUGDIR)
$Qcp -r bslug_elf.ld $(BSLUGDIR)
# Rule to install bslug.
PHONY += uninstall
uninstall :
$(LOG)
$(addprefix $Qrm -rf ,$(wildcard $(BSLUGDIR)))
###############################################################################
# Release rules
PHONY += release
release: $(TARGET) meta.xml icon.png
$(LOG)
$(addprefix $Qrm -rf ,$(wildcard $(RELEASE)))
$Qmkdir $(RELEASE)
$Qmkdir $(RELEASE)/apps
$Qmkdir $(RELEASE)/apps/brainslug
$Qcp -r $(TARGET) $(RELEASE)/apps/brainslug
$Qcp -r meta.xml $(RELEASE)/apps/brainslug
$Qcp -r icon.png $(RELEASE)/apps/brainslug
$Qmkdir $(RELEASE)/bslug
$Qcp -r symbols $(RELEASE)/bslug
$Qmkdir $(RELEASE)/bslug/modules
$Qcp -r USAGE $(RELEASE)/readme.txt
###############################################################################
# Recursive rules
include src/makefile.mk
LDFLAGS += $(patsubst %,-l %,$(LIBS)) $(patsubst %,-l %,$(LIBS)) \
$(patsubst %,-L %,$(LIB_DIRS)) $(patsubst %,-L %/lib,$(LIB_DIRS))
CFLAGS += $(patsubst %,-I %,$(INC_DIRS)) \
$(patsubst %,-I %/include,$(LIB_DIRS)) -iquote src
OBJECTS := $(patsubst %.c,$(BUILD)/%.c.o,$(filter %.c,$(SRC)))
ifeq ($(words $(filter clean%,$(MAKECMDGOALS))),0)
ifeq ($(words $(filter install%,$(MAKECMDGOALS))),0)
ifeq ($(words $(filter uninstall%,$(MAKECMDGOALS))),0)
include $(patsubst %.c,$(BUILD)/%.c.d,$(filter %.c,$(SRC)))
endif
endif
endif
###############################################################################
# Special build rules
# Rule to make the image file.
$(TARGET) : $(BUILD)/output.elf | $(BIN)
$(LOG)
-$Qmkdir -p $(dir $@)
$Q$(ELF2DOL) $(BUILD)/output.elf $(TARGET)
$(BIN)/boot.elf : $(BUILD)/output.elf | $(BIN)
$(LOG)
$Qcp $< $@
$Q$(PREFIX)strip $@
$Q$(PREFIX)strip -g $@
# Rule to make the elf file.
$(BUILD)/output.elf : $(OBJECTS) $(LINKER) | $(BIN) $(BUILD)
$(LOG)
$Q$(LD) $(OBJECTS) $(LDFLAGS) -o $@
# Rule to make intermediate directory
$(BUILD) :
$Qmkdir $@
# Rule to make output directory
$(BIN) :
$Qmkdir $@
###############################################################################
# Standard build rules
$(BUILD)/%.c.o: %.c | $(BUILD)
$(LOG)
-$Qmkdir -p $(dir $@)
$Q$(CC) -c $(CFLAGS) $< -o $@
$(BUILD)/%.c.d: %.c | $(BUILD)
$(LOG)
-$Qmkdir -p $(dir $@)
$Q$(RM) $(wildcard $@)
$Q{ $(CC) -MP -MM -MT $(@:.d=.o) $(CFLAGS) $< > $@ \
&& $(RM) $@.tmp; } \
|| { $(RM) $@.tmp && false; }
###############################################################################
# Assembly listing rules
# Rule to make assembly listing.
PHONY += list
list : $(LIST)
# Rule to make the listing file.
%.list : $(BUILD)/output.elf $(BUILD)
$(LOG)
-$Qmkdir -p $(dir $@)
$Q$(OBJDUMP) -d $(BUILD)/output.elf > $@
###############################################################################
# Clean rule
# Rule to clean files.
PHONY += clean
clean :
$Qrm -rf $(wildcard $(BUILD) $(BIN) $(RELEASE))
###############################################################################
# Phony targets
.PHONY : $(PHONY)