-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
121 lines (96 loc) · 3.04 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
# -----------------------------------------------------------------------------
#
# Essential Configuration
#
# -----------------------------------------------------------------------------
# The base program name.
PROJECT_NAME = nes_template
# The mapper and linker script to be used (in `cfg/`)
LDSCRIPT := uorom.ld
# It is assumed that `fceux` is in the user's path.
EMULATOR := fceux
# -----------------------------------------------------------------------------
#
# Paths and tools
#
# -----------------------------------------------------------------------------
# Utilities used for the toolchain or otherwise in the build process.
TOOLS_DIR := tools
TOOLCHAIN := $(TOOLS_DIR)/cc65
BASH := bash
MKDIR := mkdir
MAKE := make
# The CA65 toolchain.
AR65 := $(TOOLCHAIN)/bin/ar65
CA65 := $(TOOLCHAIN)/bin/ca65
CC65 := $(TOOLCHAIN)/bin/cc65
CHRCVT65 := $(TOOLCHAIN)/bin/chrcvt65
CL65 := $(TOOLCHAIN)/bin/cl65
CO65 := $(TOOLCHAIN)/bin/co65
DA65 := $(TOOLCHAIN)/bin/da65
GRC65 := $(TOOLCHAIN)/bin/grc65
LD65 := $(TOOLCHAIN)/bin/ld65
OD65 := $(TOOLCHAIN)/bin/od65
SIM65 := $(TOOLCHAIN)/bin/sim65
sp65 := $(TOOLCHAIN)/bin/sp65
# Paths and files.
SRCDIR := src
OUTDIR := out
OBJDIR := $(OUTDIR)/obj
LDSDIR := cfg
MAPNAME := map.txt
LABELSNAME := labels.txt
LISTNAME := listing.txt
ROMNAME := $(PROJECT_NAME).nes
DBGNAME := $(PROJECT_NAME).dbg
# Toolchain configuration.
ASFLAGS := --include-dir $(SRCDIR) \
-g \
-U
CCFLAGS := -I $(SRCDIR) \
-Cl \
-O \
-Or \
LDFLAGS := -C $(LDSDIR)/$(LDSCRIPT) \
-m $(OUTDIR)/$(MAPNAME) \
-Ln $(OUTDIR)/$(LABELSNAME) \
--dbgfile $(OUTDIR)/$(DBGNAME)
# Sources. You may replace the wildcards with explicit files if desired.
SOURCES_H := $(shell find $(SRCDIR)/ -name '*.h' -print)
SOURCES_C := $(shell find $(SRCDIR)/ -name '*.c' -print)
SOURCES_ASM := $(shell find $(SRCDIR)/ -name '*.asm' -print)
OBJECTS_C := $(addprefix $(OBJDIR)/, $(SOURCES_C:.c=.o))
OBJECTS_ASM := $(addprefix $(OBJDIR)/, $(SOURCES_ASM:.asm=.o))
# -----------------------------------------------------------------------------
#
# Recipies
#
# -----------------------------------------------------------------------------
.PHONY: clean
all: $(OUTDIR)/$(ROMNAME)
# Directories and build dependencies.
$(TOOLS_DIR):
$(MKDIR) -p $@
$(OUTDIR):
$(MKDIR) -p $@
$(OBJDIR):
$(MKDIR) -p $@
$(TOOLCHAIN): $(TOOLS_DIR)
git clone [email protected]:cc65/cc65 $@
$(MAKE) -j$(nproc) -C $@
# The 2A03 software build.
$(OUTDIR)/$(ROMNAME): $(OBJECTS_ASM) $(OBJECTS_C) $(OUTDIR) $(TOOLCHAIN)
@$(BASH) -c 'printf "\t\e[94m[ LNK ]\e[0m $(OBJECTS_ASM) $(OBJECTS_C)\n"'
$(LD65) -o $@ $(LDFLAGS) $(OBJECTS_ASM) $(OBJECTS_C)
$(OBJDIR)/%.o: %.asm $(SOURCES_H) $(OBJDIR) $(TOOLCHAIN)
@$(BASH) -c 'printf "\t\e[96m[ ASM ]\e[0m $<\n"'
@$(MKDIR) -p $(OBJDIR)/$(<D)
$(CA65) $(ASFLAGS) $< -o $@
$(OBJDIR)/%.o: %.c $(SOURCES_H) $(OBJDIR) $(TOOLCHAIN)
@$(BASH) -c 'printf "\t\e[96m[ C ]\e[0m $<\n"'
@$(MKDIR) -p $(OBJDIR)/$(<D)
$(CC65) $(CFLAGS) $< -o $@
test: $(OUTDIR)/$(ROMNAME)
$(EMULATOR) $<
clean:
rm -rf $(OUTDIR)