-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
212 lines (170 loc) · 5.56 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
ifneq ($(findstring MINGW,$(shell uname)),)
WINDOWS := 1
endif
ifneq ($(findstring MSYS,$(shell uname)),)
WINDOWS := 1
endif
# If 0, tells the console to chill out. (Quiets the make process.)
VERBOSE ?= 1
# If MAPGENFLAG set to 1, tells LDFLAGS to generate a mapfile, which makes linking take several minutes.
MAPGENFLAG ?= 1
ifeq ($(VERBOSE),0)
QUIET := @
endif
#-------------------------------------------------------------------------------
# Files
#-------------------------------------------------------------------------------
NAME := donut
VERSION ?= 0
# Overkill epilogue fixup strategy. Set to 1 if necessary.
EPILOGUE_PROCESS := 0
BUILD_DIR := build/$(NAME).$(VERSION)
ifeq ($(EPILOGUE_PROCESS),1)
EPILOGUE_DIR := epilogue/$(NAME).$(VERSION)
endif
# Inputs
S_FILES := $(wildcard asm/*.s)
C_FILES := $(wildcard src/*.c)
CPP_FILES := $(wildcard src/*.cpp)
CPP_FILES += $(wildcard src/*.cp)
LDSCRIPT := $(BUILD_DIR)/ldscript.lcf
# Outputs
DOL := $(BUILD_DIR)/main.dol
ELF := $(DOL:.dol=.elf)
MAP := $(BUILD_DIR)/donut.MAP
ifeq ($(MAPGENFLAG),1)
MAPGEN := -map $(MAP)
endif
include obj_files.mk
ifeq ($(EPILOGUE_PROCESS),1)
include e_files.mk
endif
ifeq ($(EPILOGUE_PROCESS),1)
E_FILES := $(EPILOGUE_UNSCHEDULED)
endif
#-------------------------------------------------------------------------------
# Tools
#-------------------------------------------------------------------------------
MWCC_VERSION := 1.7
ifeq ($(EPILOGUE_PROCESS),1)
MWCC_EPI_VERSION := 1.2.5
MWCC_EPI_EXE := mwcceppc.exe
endif
MWLD_VERSION := 1.7
# Programs
ifeq ($(WINDOWS),1)
WINE :=
AS := $(DEVKITPPC)/bin/powerpc-eabi-as.exe
CPP := $(DEVKITPPC)/bin/powerpc-eabi-cpp.exe -P
else
ifeq ($(NIX),1)
WINE := $(shell nix-build '<nixpkgs>' -A wine-staging --no-link)/bin/wine
AS := $(shell nix-build '<nixpkgs>' -A pkgsCross.ppc-embedded.gccCrossLibcStdenv.cc --no-link)/bin/powerpc-none-eabi-as
CPP := $(shell nix-build '<nixpkgs>' -A pkgsCross.ppc-embedded.gccCrossLibcStdenv.cc.cc --no-link)/bin/powerpc-none-eabi-cpp -P
else
WINE ?= wine
AS := $(DEVKITPPC)/bin/powerpc-eabi-as
CPP := $(DEVKITPPC)/bin/powerpc-eabi-cpp -P
endif
endif
CC = $(WINE) tools/mwcc_compiler/$(MWCC_VERSION)/mwcceppc.exe
ifeq ($(EPILOGUE_PROCESS),1)
CC_EPI = $(WINE) tools/mwcc_compiler/$(MWCC_EPI_VERSION)/$(MWCC_EPI_EXE)
endif
LD := $(WINE) tools/mwcc_compiler/$(MWLD_VERSION)/mwldeppc.exe
ELF2DOL := tools/elf2dol
SHA1SUM := sha1sum
PYTHON := python3
FRANK := tools/franklite.py
# Options
INCLUDES := -i- -i include/
ASM_INCLUDES := -I include/
ASFLAGS := -mbroadway $(ASM_INCLUDES) --defsym version=$(VERSION)
ifeq ($(VERBOSE),1)
# this set of LDFLAGS outputs warnings.
LDFLAGS := $(MAPGEN) -fp hard -nodefaults
endif
ifeq ($(VERBOSE),0)
# this set of LDFLAGS generates no warnings.
LDFLAGS := $(MAPGEN) -fp hard -nodefaults -w off -code_merging all
endif
CFLAGS = -DNDEBUG -Cpp_exceptions off -enum int -inline auto -proc gekko -RTTI off -fp hard -fp_contract on -O4,p -schedule on -sdata 8 -sdata2 8 -nodefaults $(INCLUDES)
ifeq ($(VERBOSE),0)
# this set of ASFLAGS generates no warnings.
ASFLAGS += -W
endif
$(BUILD_DIR)/src/os/__start.o: MWCC_VERSION := 1.2.5
#-------------------------------------------------------------------------------
# Recipes
#-------------------------------------------------------------------------------
### Default target ###
default: all
all: $(DOL)
ALL_DIRS := $(sort $(dir $(O_FILES)))
ifeq ($(EPILOGUE_PROCESS),1)
EPI_DIRS := $(sort $(dir $(E_FILES)))
endif
# Make sure build directory exists before compiling anything
DUMMY != mkdir -p $(ALL_DIRS)
# ifeq ($(EPILOGUE_PROCESS),1)
# Make sure profile directory exists before compiling anything
# DUMMY != mkdir -p $(EPI_DIRS)
# endif
.PHONY: tools
$(LDSCRIPT): ldscript.lcf
$(QUIET) $(CPP) -MMD -MP -MT $@ -MF [email protected] -I include/ -I . -DBUILD_DIR=$(BUILD_DIR) -o $@ $<
$(DOL): $(ELF) | tools
$(QUIET) $(ELF2DOL) $< $@
$(QUIET) $(SHA1SUM) -c sha1/$(NAME).$(VERSION).sha1
ifneq ($(findstring -map,$(LDFLAGS)),)
$(QUIET) $(PYTHON) tools/calcprogress/calcprogress.py --dol $(DOL) --map $(MAP)
endif
clean:
rm -f -d -r build
rm -f -d -r epilogue
find . -name '*.o' -exec rm {} +
find . -name 'ctx.c' -exec rm {} +
find ./include -name "*.s" -type f -delete
$(MAKE) -C tools clean
tools:
$(MAKE) -C tools
build/o_files: $(O_FILES)
$(file >$@) $(foreach V,$^,$(file >>$@,$V))
@true
# ELF creation makefile instructions
ifeq ($(EPILOGUE_PROCESS),1)
@echo Linking ELF $@
$(ELF): build/o_files $(E_FILES) $(LDSCRIPT)
$(QUIET) $(LD) $(LDFLAGS) -o $@ -lcf $(LDSCRIPT) @build/o_files
else
$(ELF): build/o_files $(LDSCRIPT)
@echo Linking ELF $@
$(QUIET) $(LD) $(LDFLAGS) -o $@ -lcf $(LDSCRIPT) @build/o_files
endif
$(BUILD_DIR)/%.o: %.s
@echo Assembling $<
$(QUIET) $(AS) $(ASFLAGS) -o $@ $<
$(BUILD_DIR)/%.o: %.c
@echo "Compiling " $<
$(QUIET) $(CC) $(CFLAGS) -c -o $@ $<
$(BUILD_DIR)/%.o: %.cp
@echo "Compiling " $<
$(QUIET) $(CC) $(CFLAGS) -c -o $@ $<
$(BUILD_DIR)/%.o: %.cpp
@echo "Compiling " $<
$(QUIET) $(CC) $(CFLAGS) -c -o $@ $<
ifeq ($(EPILOGUE_PROCESS),1)
$(EPILOGUE_DIR)/%.o: %.c $(BUILD_DIR)/%.o
@echo Frank is fixing $<
$(QUIET) $(PYTHON) $(FRANK) $(word 2,$^) $(word 2,$^)
$(EPILOGUE_DIR)/%.o: %.cp $(BUILD_DIR)/%.o
@echo Frank is fixing $<
$(QUIET) $(PYTHON) $(FRANK) $(word 2,$^) $(word 2,$^)
$(EPILOGUE_DIR)/%.o: %.cpp $(BUILD_DIR)/%.o
@echo Frank is fixing $<
$(QUIET) $(PYTHON) $(FRANK) $(word 2,$^) $(word 2,$^)
endif
# If we need Frank, add the following after the @echo
# $(QUIET) $(CC_EPI) $(CFLAGS) -c -o $@ $<
### Debug Print ###
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true