-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
136 lines (117 loc) · 4.17 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
# RB3Enhanced Makefile
# the source code files to compile from
SRC_DIR := source
SOURCES := $(wildcard $(SRC_DIR)/*.c)
INC_DIR := include
# output directory for final DLL/MOD files
OUTPUT := out
# output filename for final DLL/MOD files
OUTNAME := RB3Enhanced
# definitions for compilation
DEFINES := RB3E NDEBUG
# if DEBUG=1 then compile "debug" builds
ifeq ($(strip $(DEBUG)),1)
DEFINES += RB3EDEBUG
endif
# Wii variables
# =================
# build directory for Wii compilation
BUILD_W := build_wii
# .o object files for Wii compilation
OBJECTS_W :=$(subst $(SRC_DIR),$(BUILD_W),$(patsubst %.c,%.c.o,$(SOURCES)))
# BrainSlug library install directory
BSLUGDIR := $(DEVKITPRO)/bslug
# executable tool path
TOOLPATH_W := $(DEVKITPPC)/bin
COMPILER_W := $(TOOLPATH_W)/powerpc-eabi-gcc
LINKER_W := $(TOOLPATH_W)/powerpc-eabi-ld
# include directories
GCC_VER_W := 11.2.0
ifneq ($(strip $(DEVKITPPC)),)
GCC_VER_W := $(shell $(COMPILER_W) -dumpversion)
endif
INCLUDES_W := $(DEVKITPPC)/lib/gcc/powerpc-eabi/$(GCC_VER_W)/include \
$(DEVKITPPC)/lib/gcc/powerpc-eabi/$(GCC_VER_W)/include-fixed \
$(BSLUGDIR)/include $(INC_DIR)
# compiler flags
CFLAGS_W := -O2 -Wall -Wno-format-extra-args -x c -std=gnu99 -nostdinc -ffreestanding \
-DGEKKO -DHW_RVL -D__wii__ -DRB3E_WII $(patsubst %,-D%,$(DEFINES)) \
-mrvl -mcpu=750 -meabi -mhard-float -fshort-wchar -fno-common \
-msdata=none -memb -ffunction-sections -fdata-sections \
$(patsubst %,-I %,$(INCLUDES_W)) -iquote src
# linker flags for final compile
LFLAGS_W := --relocatable -s --gc-sections -u bslug_load -u bslug_meta \
-T $(BSLUGDIR)/bslug.ld
# linker flags for intermediate compile
LFLAG2_W := --relocatable -s -T $(BSLUGDIR)/bslug_elf.ld
# =================
# Xbox variables
# =================
# build directory for Xbox compilation
BUILD_X := build_xbox
# .obj object files for Xbox compilation
OBJECTS_X := $(subst $(SRC_DIR),$(BUILD_X),$(patsubst %.c,%.obj,$(SOURCES)))
# executable tool path
TOOLPATH_X := $(XEDK)/bin/win32
COMPILER_X := "$(TOOLPATH_X)/cl.exe"
LINKER_X := "$(TOOLPATH_X)/link.exe"
IMAGEXEX_X := "$(TOOLPATH_X)/imagexex.exe"
# include directories
INCLUDES_X := "$(XEDK)/include/xbox"
# library directories
LIBDIR_X := "$(XEDK)/lib/xbox"
# library includes
LIBS_X := xapilib.lib xboxkrnl.lib xnet.lib xonline.lib
ifeq ($(strip $(EMULATOR)),1) # for emulator builds we need xbdm
LIBS_X += xbdm.lib
endif
# compiler flags
CFLAGS_X := -c -Zi -nologo -W3 -WX- -Ox -Os -D _XBOX -D RB3E_XBOX $(patsubst %,-D %,$(DEFINES)) \
-GF -Gm- -MT -GS- -Gy -fp:fast -fp:except- -Zc:wchar_t -Zc:forScope \
-GR- -openmp- -FI"$(XEDK)/include/xbox/xbox_intellisense_platform.h" \
-Fd"$(BUILD_X)/" -I "$(INC_DIR)"
# linker flags
LFLAGS_X := -ERRORREPORT:PROMPT -INCREMENTAL:NO -NOLOGO $(LIBS_X) \
-MANIFESTUAC:"level='asInvoker' uiAccess='false'" -DEBUG \
-STACK:"262144","262144" -OPT:REF -OPT:ICF -TLBID:1 -RELEASE \
-dll -entry:"_DllMainCRTStartup" -XEX:NO
# xex generation flags
XEXFLAGS := -nologo -config:"xex.xml"
# =================
.PHONY: all
all: xbox wii
.PHONY: scripts
scripts:
@bash scripts/version.sh
.PHONY: clean
clean:
@rm -rf $(wildcard $(BUILD_W) $(BUILD_X) $(OUTPUT))
# Wii compilation, creates BrainSlug .MOD file
.PHONY: wii
wii: $(OUTPUT)/$(OUTNAME).mod
$(OUTPUT)/$(OUTNAME).mod: $(BUILD_W)/output.elf
@echo "Creating MOD..."
@mkdir -p $(@D)
@$(LINKER_W) $^ $(LFLAGS_W) -Map $(BUILD_W)/$(OUTNAME).map -o $@
$(BUILD_W)/output.elf: $(OBJECTS_W)
@echo "Linking ELF..."
@mkdir -p $(@D)
@$(LINKER_W) $^ $(LFLAG2_W) -o $@
$(BUILD_W)/%.c.o: $(SRC_DIR)/%.c | scripts
@echo $<
@mkdir -p $(@D)
@$(COMPILER_W) -c $(CFLAGS_W) $< -o $@
# Xbox compilation, creates .DLL file
.PHONY: xbox
xbox: $(OUTPUT)/$(OUTNAME).dll
$(OUTPUT)/$(OUTNAME).dll: $(BUILD_X)/$(OUTNAME).exe
@echo "Creating XEXDLL..."
@mkdir -p $(@D)
@$(WINDOWS_SHIM) $(IMAGEXEX_X) $(XEXFLAGS) -out:"$@" "$^"
$(BUILD_X)/$(OUTNAME).exe: $(OBJECTS_X)
@echo "Linking DLL..."
@mkdir -p $(@D)
@LIB=$(LIBDIR_X) $(WINDOWS_SHIM) $(LINKER_X) $(LFLAGS_X) -OUT:"$@" -PDB:"$(BUILD_X)/$(OUTNAME).pdb" -IMPLIB:"$(BUILD_X)/$(OUTNAME)" $^
$(BUILD_X)/%.obj: $(SRC_DIR)/%.c | scripts
@mkdir -p $(@D)
@INCLUDE=$(INCLUDES_X) $(WINDOWS_SHIM) $(COMPILER_X) $(CFLAGS_X) -Fo"$@" -TC $<