forked from jkbenaim/cboy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
125 lines (104 loc) · 2.85 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
#
# Makefile for n64chain ROMs.
#
# n64chain: A (free) open-source N64 development toolchain.
# Copyright 2014-16 Tyler J. Stachecki <stachecki.tyler@gmail.com>
#
# This file is subject to the terms and conditions defined in
# 'LICENSE', which is part of this source code package.
#
ifdef SystemRoot
FIXPATH = $(subst /,\,$1)
RM = del /Q
else
FIXPATH = $1
RM = rm -f
endif
ROM_NAME = $(notdir $(CURDIR))
AS = $(call FIXPATH,$(CURDIR)/../tools/bin/mips64-elf-as)
AR = $(call FIXPATH,$(CURDIR)/../tools/bin/mips64-elf-gcc-ar)
CC = $(call FIXPATH,$(CURDIR)/../tools/bin/mips64-elf-gcc)
MAKE = $(call FIXPATH,$(CURDIR)/../tools/bin/make)
OBJCOPY = $(call FIXPATH,$(CURDIR)/../tools/bin/mips64-elf-objcopy)
CHECKSUM = $(call FIXPATH,$(CURDIR)/../tools/bin/checksum)
RSPASM = $(call FIXPATH,$(CURDIR)/../tools/bin/rspasm)
CFLAGS = -Wall -std=c99 -Wno-main -fno-strict-aliasing \
-I../libn64/include -I../libn64 -I.
OPTFLAGS = -O3 -march=vr4300 -mabi=eabi -mgp32 -mlong32 \
-flto -ffat-lto-objects -ffunction-sections -fdata-sections \
-G4 -mno-extern-sdata -mgpopt -fselective-scheduling \
-fsel-sched-pipelining -fsel-sched-pipelining-outer-loops
ASMFILES = $(call FIXPATH,\
)
CFILES = $(call FIXPATH,\
src/audio.c \
src/bootrom.c \
src/cart.c \
src/cartdesc.c \
src/cartrom.c \
src/cpu.c \
src/input.c \
src/main.c \
src/mbc_boot.c \
src/mbc.c \
src/mbc_cam.c \
src/mbc_huc1.c \
src/mbc_huc3.c \
src/mbc_mbc1.c \
src/mbc_mbc2.c \
src/mbc_mbc3.c \
src/mbc_mbc5.c \
src/mbc_mbc7.c \
src/mbc_none.c \
src/memory.c \
src/serial.c \
src/video.c \
)
UCODES = $(call FIXPATH,\
)
OBJFILES = \
$(ASMFILES:.S=.o) \
$(CFILES:.c=.o)
UCODEBINS = $(UCODES:.rsp=.bin)
DEPFILES = $(OBJFILES:.o=.d)
#
# Primary targets.
#
all: $(ROM_NAME).z64
$(ROM_NAME).z64: $(ROM_NAME).elf
@echo $(call FIXPATH,"Building: $(ROM_NAME)/$@")
@$(OBJCOPY) -O binary $< $@
@$(CHECKSUM) $(call FIXPATH,../libn64/header.bin) $@
$(ROM_NAME).elf: libn64 $(OBJFILES)
@echo $(call FIXPATH,"Building: $(ROM_NAME)/$@")
@$(CC) $(CFLAGS) $(OPTFLAGS) -Wl,-Map=$(ROM_NAME).map -nostdlib \
-T$(call FIXPATH,../libn64/rom.ld) -o $@ $(OBJFILES) \
-L$(call FIXPATH,../libn64) -ln64
#
# Generic compilation/assembly targets.
#
$(call FIXPATH,src/graphics.o): $(call FIXPATH,src/graphics.S) $(call FIXPATH,src/graphics.bin)
%.o: %.S
@echo $(call FIXPATH,"Assembling: $(ROM_NAME)/$<")
@$(CC) $(CFLAGS) $(OPTFLAGS) -MMD -c $< -o $@
%.o: %.c
@echo $(call FIXPATH,"Compiling: $(ROM_NAME)/$<")
@$(CC) $(CFLAGS) $(OPTFLAGS) -MMD -c $< -o $@
%.bin: %.rsp
@echo $(call FIXPATH,"Assembling: $(ROM_NAME)/$<")
@$(RSPASM) -o $@ $<
.PHONY: libn64
libn64:
@$(MAKE) -sC $(call FIXPATH,../libn64)
#
# Clean project target.
#
.PHONY: clean
clean:
@echo "Cleaning $(ROM_NAME)..."
@$(RM) $(ROM_NAME).map $(ROM_NAME).elf $(ROM_NAME).z64 \
$(DEPFILES) $(OBJFILES) $(UCODEBINS)
#
# Use computed dependencies.
#
-include $(DEPFILES)