forked from bfbbdecomp/bfbb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
146 lines (117 loc) · 4.15 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
ifneq ($(findstring MINGW,$(shell uname)),)
WINDOWS := 1
endif
ifneq ($(findstring MSYS,$(shell uname)),)
WINDOWS := 1
endif
ifneq ($(findstring microsoft,$(shell uname -a)),)
WINDOWS := 1
endif
#-------------------------------------------------------------------------------
# Files
#-------------------------------------------------------------------------------
# Used for elf2dol
TARGET_COL := wii
OBJ_DIR := obj
SRC_DIRS := src \
src/Core/p2 \
src/Core/x \
src/Game
ASM_DIRS := asm \
asm/bink \
asm/CodeWarrior \
asm/Core/p2 \
asm/Core/x \
asm/dolphin \
asm/Game \
asm/ODEGdev \
asm/rwsdk
# 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 := ldscript.lcf
# Outputs
DOL := main.dol
ELF := $(DOL:.dol=.elf)
MAP := bfbb.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) $(SBSS_O_FILES) $(SDATA2_O_FILES) \
$(SBSS2_O_FILES)
#-------------------------------------------------------------------------------
# Tools
#-------------------------------------------------------------------------------
# Programs
ifeq ($(WINDOWS),1)
WINE :=
else
WINE := wine
endif
AS := $(DEVKITPPC)/bin/powerpc-eabi-as
OBJCOPY := $(DEVKITPPC)/bin/powerpc-eabi-objcopy
CC := $(WINE) tools/mwcc_compiler/2.0/mwcceppc.exe
LD := $(WINE) tools/mwcc_compiler/2.7/mwldeppc.exe
PPROC := python3 tools/postprocess.py
GLBLASM := python3 tools/inlineasm/globalasm.py
ELF2DOL := tools/elf2dol
SHA1SUM := sha1sum
ASMDIFF := ./asmdiff.sh
# Options
INCLUDES := -ir src -ir include -Iinclude -Iinclude/dolphin -Iinclude/CodeWarrior -Iinclude/rwsdk
ASFLAGS := -mgekko -I include
LDFLAGS := -map $(MAP) -w off -maxerrors 1 -nostdlib
CFLAGS := -g -DGAMECUBE -Cpp_exceptions off -proc gekko -fp hard -fp_contract on -O4,p -msgstyle gcc -maxerrors 1 \
-pragma "check_header_flags off" -RTTI off -pragma "force_active on" \
-str reuse,pool,readonly -char unsigned -enum int -use_lmw_stmw on -inline off -nostdinc -i- $(INCLUDES)
PPROCFLAGS := -fsymbol-fixup
# elf2dol needs to know these in order to calculate sbss correctly.
SDATA_PDHR := 9
SBSS_PDHR := 10
# Silences most build commands. Run make S= to show all commands being invoked.
S := @
#-------------------------------------------------------------------------------
# Recipes
#-------------------------------------------------------------------------------
default: all
all: $(DOL)
ALL_DIRS := $(OBJ_DIR) $(addprefix $(OBJ_DIR)/,$(SRC_DIRS) $(ASM_DIRS))
# Make sure build directory exists before compiling anything
DUMMY != mkdir -p $(ALL_DIRS)
.PHONY: tools
$(DOL): $(ELF) | tools
@echo " ELF2DOL "$@
$S$(ELF2DOL) $< $@ $(SDATA_PDHR) $(SBSS_PDHR) $(TARGET_COL)
$S$(SHA1SUM) -c bfbb.sha1 || ( rm -f main.dump; $(ASMDIFF) )
$Scp bfbb.map main.elf obj/ # needed for diff.py
clean:
rm -f $(DOL) $(ELF) $(MAP) baserom.dump main.dump
rm -rf .pragma obj
$(MAKE) -C tools clean
tools:
$(MAKE) -C tools
inspect:
ifeq ($(WINDOWS),1)
$(CC) $(CFLAGS) -o inspect.s -S $(subst \,/,$(subst C:\,/c/,$(INSPECT)))
else
$(CC) $(CFLAGS) -o inspect.s -S $(INSPECT)
endif
python3 tools/inspect_postprocess.py inspect.s
$(ELF): $(O_FILES) $(LDSCRIPT)
@echo " LINK "$@
$S$(LD) $(LDFLAGS) -o $@ -lcf $(LDSCRIPT) $(O_FILES) 1>&2
# The Metrowerks linker doesn't generate physical addresses in the ELF program headers. This fixes it somehow.
$S$(OBJCOPY) $@ $@
$(OBJ_DIR)/%.o: %.s
@echo " AS "$<
$S$(AS) $(ASFLAGS) -o $@ $<
$S$(PPROC) $(PPROCFLAGS) $@
$(OBJ_DIR)/%.o: %.c
@echo " CC "$<
$S$(CC) $(CFLAGS) -c -o $@ $< 1>&2
$(OBJ_DIR)/%.o: %.cpp
@echo " CXX "$<
$S$(GLBLASM) -s $< $(OBJ_DIR)/$*.cpp 1>&2
$S$(CC) $(CFLAGS) -c -o $@ $(OBJ_DIR)/$*.cpp 1>&2
$S$(PPROC) $(PPROCFLAGS) $@