-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
105 lines (75 loc) · 2.63 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
# Makefile to rebuild MK64 split image
################ Target Executable and Sources ###############
# BUILD_DIR is location where all build artifacts are placed
BUILD_DIR = build
# Directories containing source files
SRC_DIRS := src src/libultra
ASM_DIRS := asm data bin
# If COMPARE is 1, check the output sha1sum when building 'all'
COMPARE = 1
TARGET = mk64.u
LD_SCRIPT = $(TARGET).ld
MIO0_DIR = bin
TEXTURE_DIR = textures
# Source code files
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
S_FILES := $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/*.s))
# Object files
O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) \
$(foreach file,$(S_FILES),$(BUILD_DIR)/$(file:.s=.o))
##################### Compiler Options #######################
CROSS = mips-linux-gnu-
AS = $(CROSS)as
CC = $(CROSS)gcc
LD = $(CROSS)ld
OBJDUMP = $(CROSS)objdump
OBJCOPY = $(CROSS)objcopy
ASFLAGS = -march=vr4300 -mabi=32 -I include -I $(BUILD_DIR)
OBJCOPYFLAGS = --pad-to=0xC00000 --gap-fill=0xFF
CFLAGS = -O2 -march=vr4300 -G 0 -c
LDFLAGS = -T undefined_syms.txt -T $(LD_SCRIPT) -Map $(BUILD_DIR)/mk64.u.map --no-check-sections
####################### Other Tools #########################
# N64 tools
TOOLS_DIR = tools
MIO0TOOL = $(TOOLS_DIR)/mio0
N64CKSUM = $(TOOLS_DIR)/n64cksum
N64GRAPHICS = $(TOOLS_DIR)/n64graphics
EMULATOR = mupen64plus
EMU_FLAGS = --noosd
LOADER = loader64
LOADER_FLAGS = -vwf
SHA1SUM = sha1sum
######################## Targets #############################
default: all
# file dependencies generated by splitter
MAKEFILE_SPLIT = Makefile.split
include $(MAKEFILE_SPLIT)
all: $(BUILD_DIR)/$(TARGET).z64
ifeq ($(COMPARE),1)
@$(SHA1SUM) -c $(TARGET).sha1
endif
clean:
$(RM) -r $(BUILD_DIR)
$(BUILD_DIR)/$(MIO0_DIR)/%.mio0: $(MIO0_DIR)/%.bin
$(MIO0TOOL) $< $@
$(BUILD_DIR):
mkdir $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(SRC_DIRS) $(ASM_DIRS))
$(BUILD_DIR)/data/game_data.o: $(TEXTURE_DATA_MIO0_FILES) $(LEVEL_DATA_MIO0_FILES)
$(BUILD_DIR)/%.o: %.s $(BUILD_DIR) $(MIO0_FILES)
$(AS) $(ASFLAGS) -o $@ $<
$(BUILD_DIR)/$(TARGET).elf: $(O_FILES) $(LD_SCRIPT)
$(LD) $(LDFLAGS) -o $@ $(O_FILES)
$(BUILD_DIR)/$(TARGET).z64: $(BUILD_DIR)/$(TARGET).elf
$(OBJCOPY) $(OBJCOPYFLAGS) $< $(@:.z64=.bin) -O binary
$(N64CKSUM) $(@:.z64=.bin) $@
$(BUILD_DIR)/$(TARGET).hex: $(TARGET).z64
xxd $< > $@
$(BUILD_DIR)/$(TARGET).objdump: $(BUILD_DIR)/$(TARGET).elf
$(OBJDUMP) -D $< > $@
test: $(TARGET).z64
$(EMULATOR) $(EMU_FLAGS) $<
load: $(TARGET).z64
$(LOADER) $(LOADER_FLAGS) $<
.PHONY: all clean default diff test load
.PRECIOUS: $(BUILD_DIR)/bin/%.mio0
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true