-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
131 lines (103 loc) · 3.64 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
include /usr/include/n64/make/PRdefs
#Project name
PROJECT = non_nusys_demo
#Libultra directories
LIB = $(ROOT)/usr/lib
LPR = $(LIB)/PR
INC = $(ROOT)/usr/include
#Audio Library
AUDIOLIB = -lmus
#Compiler/Linker settings
OPTIMIZER = -O1
LCDEFS = -DNDEBUG -D_FINALROM -DF3DEX_GBI_2
N64LIB = -lultra_rom
CFLAGS := $(CFLAGS) -DNDEBUG -D_FINALROM -DF3DEX_GBI_2 -G 0 -MMD -MP -Iinclude -I. -I$(NUSTDINCDIR) -I$(ROOT)/usr/include/PR -Wa,-Iinclude
CXXFLAGS := $(CXXFLAGS) -DNDEBUG -D_FINALROM -DF3DEX_GBI_2 -MMD -MP -G 0 -std=c++17 -fno-builtin -fno-exceptions -fno-rtti -fno-use-cxa-atexit -Iinclude -I$(NUSYSINCDIR) -I$(NUSTDINCDIR) -I$(ROOT)/usr/include/PR
#Linking outputs
ELF = ./build/$(PROJECT).elf
TARGETS = $(PROJECT).z64
MAP = ./build/$(PROJECT).map
#Linker requirements
LD_SCRIPT = $(PROJECT).ld
CP_LD_SCRIPT = ./build/$(PROJECT)_cp.ld
LD_DEPS = $(CP_LD_SCRIPT).d
#Header file list
HFILES := $(wildcard src/*.h) $(wildcard include/*.h)
#Code file list
ASMFILES := $(wildcard asm/*.s)
CODEFILES := $(wildcard src/*.c)
CXXFILES := $(wildcard src/*.cpp)
#Data file list
DATAFILES := $(wildcard data/*.c)
#Path for build artifacts
OBJPATH = ./build/obj
DEPPATH = ./build/dep
#Object definitions
CODEOBJECTS = $(CODEFILES:.c=.o) $(CXXFILES:.cpp=.o)
CODEOBJNAME = $(notdir $(CODEOBJECTS))
CODEOBJPATH = $(addprefix $(OBJPATH)/,$(CODEOBJNAME))
ASMOBJECTS = $(ASMFILES:.s=.o)
ASMOBJNAME = $(notdir $(ASMOBJECTS))
ASMOBJPATH = $(addprefix $(OBJPATH)/,$(ASMOBJNAME))
DATAOBJECTS = $(DATAFILES:.c=.o)
DATAOBJNAME = $(notdir $(DATAOBJECTS))
DATAOBJPATH = $(addprefix $(OBJPATH)/,$(DATAOBJNAME))
#Bootcode definitions
BOOT = /usr/lib/n64/PR/bootcode/boot.6102
BOOT_OBJ = ./build/obj/boot.6102.o
#Dependency list
DEPFILES = $(LD_DEPS) $(addprefix $(DEPPATH)/,$(CODEOBJNAME:%.o=%.d))
#Object for codesegment
CODESEGMENT = ./build/codesegment.o
#Required objects to link
OBJECTS = $(ASMOBJPATH) $(BOOT_OBJ) $(CODESEGMENT) $(DATAOBJPATH)
#Linker options
LCINCS = -I. -I$(ROOT)/usr/include/PR
LCOPTS = -G 0
LDIRT = $(APP) $(TARGETS)
LDFLAGS = -L$(LIB) $(AUDIOLIB) $(N64LIB) -L$(N64_LIBGCCDIR) -lgcc
#Default target
default: $(TARGETS)
#Clean target
clean:
@echo "\e[31mCleaning output...\e[0m"
@rm -rf ./build
#Include dependencies
-include $(DEPFILES)
#Compile rules
build/obj/%.o: */%.s | makeDirs
@echo "\e[35mCompiling $<...\e[0m"
@$(CC) -MF $(DEPPATH)/$*.d -o $@ $(CFLAGS) $<
build/obj/%.o: */%.c | makeDirs
@echo "\e[35mCompiling $<...\e[0m"
@$(CC) -MF $(DEPPATH)/$*.d -o $@ $(CFLAGS) $<
build/obj/%.o: */%.cpp | makeDirs
@echo "\e[35mCompiling $<...\e[0m"
@$(CC) -MF $(DEPPATH)/$*.d -o $@ $(CXXFLAGS) $<
#Code segment linking rule
$(CODESEGMENT): $(CODEOBJPATH)
@echo "\e[31mLinking codesegment...\e[0m"
$(LD) -o $(CODESEGMENT) -r $(CODEOBJPATH) $(LDFLAGS)
#Generate bootcode object
$(BOOT_OBJ): $(BOOT) | makeDirs
@echo "\e[35mLinking $<...\e[0m"
@$(OBJCOPY) -I binary -B mips -O elf32-bigmips $< $@
#Preprocess linker script
$(CP_LD_SCRIPT): $(LD_SCRIPT) | makeDirs
@echo "\e[35mPreprocessing linkerscript $<...\e[0m"
@cpp -MMD -MP -MF $(LD_DEPS) -MMD -MP -MT $@ -MF [email protected] -P -Wno-trigraphs -Iinclude -I. -o $@ $<
#Generate output ROM
$(TARGETS) $(APP): $(CP_LD_SCRIPT) $(OBJECTS)
@echo "\e[35mLinking ROM $<...\e[0m"
@$(LD) -L. -T $(CP_LD_SCRIPT) -Map $(MAP) -o $(ELF)
@echo "\e[35mConverting ROM $<...\e[0m"
@$(OBJCOPY) --gap-fill=0xFF $(ELF) $(TARGETS) -O binary
@makemask $(TARGETS)
@echo "\e[32mDone! ./build/$(PROJECT).z64\e[0m"
#Generate build directories
makeDirs:
@echo "\e[33mCreating build directories... $<\e[0m"
@mkdir -p "build/obj"
@mkdir -p "build/dep"
# Remove built-in rules, to improve performance
MAKEFLAGS += --no-builtin-rules