-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
140 lines (111 loc) · 3.87 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
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
#-------------------------------------------------------------------------------
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/fmod \
asm/GAME \
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 := in.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
#-------------------------------------------------------------------------------
MWCC_VERSION := 2.7
# Programs
ifeq ($(WINDOWS),1)
WINE :=
else
WINE := wine
endif
AS := $(DEVKITPPC)/bin/powerpc-eabi-as
CC := $(WINE) tools/mwcc_compiler/$(MWCC_VERSION)/mwcceppc.exe
LD := $(WINE) tools/mwcc_compiler/$(MWCC_VERSION)/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/CodeWarrior -Iinclude/rwsdk
ASFLAGS := -W -mgekko -I include
LDFLAGS := -map $(MAP) -w off -maxerrors 1 -nostdlib
CFLAGS := -g -O4,s -DGAMECUBE -DGEKKO -Cpp_exceptions off -proc gekko -fp hard -fp_contract on -RTTI off \
-str reuse,pool,readonly -enum int -use_lmw_stmw on -inline off -sdata 64 -sdata2 64 \
-pragma "check_header_flags off" -pragma "force_active on" -pragma "cpp_extensions on" \
-msgstyle gcc -maxerrors 1 -nostdinc -i- $(INCLUDES)
PPROCFLAGS := -fsymbol-fixup
# Silences most build commands. Run make S= to show all commands being invoked.
S := @
#-------------------------------------------------------------------------------
# Recipes
#-------------------------------------------------------------------------------
### Default target ###
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) $< $@
$S$(SHA1SUM) -c in.sha1 || ( test -f baserom.dol && ( rm -f main.dump; $(ASMDIFF) ) || echo "Cannot display diff, baserom.dol not found." )
clean:
rm -f $(DOL) $(ELF) $(MAP) baserom.dump main.dump
rm -rf .pragma obj
$(MAKE) -C tools clean
tools:
$(MAKE) -C tools
$(ELF): $(O_FILES) $(LDSCRIPT)
@echo " LINK "$@
$S$(LD) $(LDFLAGS) -o $@ -lcf $(LDSCRIPT) $(O_FILES) 1>&2
$(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) $@
$(PREPROCESS_O_FILES): $(OBJ_DIR)/%.o: %.cpp
@echo " CXX "$<
$S$(GLBLASM) -s $< $(OBJ_DIR)/$*.cp 1>&2
$S$(CC) $(CFLAGS) -E -o $(OBJ_DIR)/$*.cpp $(OBJ_DIR)/$*.cp 1>&2
$S$(CC) $(CFLAGS) -c -o $@ $(OBJ_DIR)/$*.cpp 1>&2
$S$(PPROC) $(PPROCFLAGS) $@
@rm -f $(OBJ_DIR)/$*.cp