-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
179 lines (141 loc) · 5.44 KB
/
Makefile
File metadata and controls
179 lines (141 loc) · 5.44 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# GNU Makefile for template nesdev project.
# Project title, basename of final iNES container file.
PROJECT = template
# Location of the base directory of the cc65 distribution or repository; must
# contain a bin/ subdirectory where ca65 and ld65 are located.
CC65DIR = ../../../tools/cc65
# Project source/object tree
INCDIR = inc
ASMDIR = asm
CHRDIR = chr
# Required linker configuration file, which controls the layout of code/data
# segments in the iNES container as well as the runtime address ranges of
# memory segments (code, data, RAM). Goes hand-in-hand with the cartridge
# hardware targeted (i.e., mapper). You'll need to change this if targeting
# anything other than NROM.
LDCFG = ldcfg/nrom.cfg
# Output dirs (created by make, deleted by make clean):
OBJDIR = obj
DISTDIR = dist
DEPDIR = dep
# Target iNES container file to create (within $DISTDIR)
NESFILE = $(PROJECT).nes
# Which object files should get linked together into the final iNES container.
# Each one of these will be created in $OBJDIR, assembled from the corresponding
# .s file in $ASMDIR, and will depend on that .s file and any other files
# included by it, e.g. by `.include` and `.incbin` directives.
#
# This is the main definition that the developer changes to add or remove
# modules (i.e. code and data) to or from the final iNES container.
OBJECTS = locals.o main.o ppu.o joy.o random.o
# Alternatively, for zero Makefile-editing as you write new modules, you could
# link together every object for which there is a source file:
# SOURCES = $(wildcard $(ASMDIR)/*.s)
# OBJECTS = $(notdir $(SOURCES:.s=.o))
# Emulator locations
# `make mesen`
MESENDIR = ../../emu/mesen-x
# `make nintendulator`
NINTENDULATORDIR= ../../emu/ndx/nintendulatordx-v36
# `make fceux`
FCEUXDIR = ../../emu/fceux/fceux-2.2.2-win32
# `make nestopia`
NESTOPIADIR = ../../emu/nestopia/nestopia-1.46.2
# Tool locations
CC65BINDIR = $(CC65DIR)/bin
AS = $(CC65BINDIR)/ca65
LD65 = $(CC65BINDIR)/ld65
# Default target
all: $(NESFILE)
.PHONY: all
# NESFILE depends on OBJECTS and should be created after DISTDIR
$(NESFILE): $(OBJECTS) | $(DISTDIR)
# Object files should be created after OBJDIR and DISTDIR (but they don't depend
# on them)
$(OBJECTS): | $(OBJDIR) $(DEPDIR)
# The list of dependency files (.d files), one for each object
DEPS = $(addprefix $(DEPDIR)/,$(OBJECTS:.o=.d))
# Dependency files should be create after DEPDIR and OBJDIR
$(DEPS): | $(DEPDIR) $(OBJDIR)
# How to create the output dirs
$(OBJDIR) $(DEPDIR) $(DISTDIR):
mkdir $@
# Assembler (ca65) flags
ASFLAGS = -g --include-dir $(INCDIR) --bin-include-dir $(CHRDIR)
# Linker (ld65) flags
LDFLAGS = --obj-path $(OBJDIR)
# clean: remove all generated files
RMDIRFLAGS=--ignore-fail-on-non-empty
clean:
rm -f \
$(OBJDIR)/* \
$(DEPDIR)/* \
$(CHRDIR)/*.png $(CHRDIR)/*.chr \
$(DISTDIR)/*
test -d $(OBJDIR) && rmdir $(RMDIRFLAGS) $(OBJDIR) || true
test -d $(DEPDIR) && rmdir $(RMDIRFLAGS) $(DEPDIR) || true
test -d $(DISTDIR) && rmdir $(RMDIRFLAGS) $(DISTDIR) || true
.PHONY: clean
#
# Print a table of how memory segments are laid out
#
summary: $(NESFILE)
@cat $(<:.nes=.map.txt) | grep -A 9 "^Name"
.PHONY: summary
#
# Convenience targets to launch the game in emulators for testing
#
nestopia: $(NESFILE)
$(NESTOPIADIR)/nestopia $< 2> /dev/null > /dev/null
nintendulator: $(NESFILE)
$(NINTENDULATORDIR)/Nintendulator.exe $< 2> /dev/null
fceux: $(NESFILE)
$(FCEUXDIR)/fceux.exe $< 2> /dev/null
mesen: $(NESFILE)
$(MESENDIR)/Mesen.exe $< 2> /dev/null
.PHONY: nestopia nintendulator fceux mesen
# Pattern rule for generating the .d file of dependencies for each .s source
# file, using the bin/autodep tool. The .d files will be included to establish
# the dependencies of each object file. Note that each .o file implicitly
# depends on its corresponding .s file; the .d file only needs to mention any
# dependencies in addition to this.
# The sed just patches up the output of autodep to give the .d file the same
# prerequisites as the .o file, so that make knows to recompute the module's
# dependencies whenever the module source or its dependencies change.
# See:
# https://www.gnu.org/software/make/manual/html_node/Automatic-Prerequisites.html
$(DEPDIR)/%.d: %.s bin/autodep
@set -e; rm -f $@; \
bin/autodep --include-dir $(INCDIR) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
# include the automatic dependencies
include $(DEPS)
# Pattern rules on how to build PNGs from XCFs, and CHRs from PNGs. A code
# module that .incbin's a CHR bank need only mention the CHR file in its
# dependencies (automatically generated by bin/autodep), and make will figure
# out how to generate it through the XCF -> PNG -> CHR pipeline.
%.chr: $(CHRDIR)/%.png bin/bmp2nes
bin/bmp2nes -i $< -o $(CHRDIR)/$@
%.png: %.xcf bin/xcf2png
bin/xcf2png $< $@
# Don't delete the intermediate PNGs created by chaining the above implicit
# rules.
.PRECIOUS: %.png
# Below: the main pattern rules for building object and nes files with the
# assembler and linker, respectively.
%.o: %.s
$(AS) $(ASFLAGS) -o $(OBJDIR)/$@ $<
%.nes: $(LDCFG)
$(LD65) $(LDFLAGS) -o $(DISTDIR)/$@ -C $(LDCFG) -m $(DISTDIR)/$*.map.txt \
-Ln $(DISTDIR)/$*.labels.txt --dbgfile $(DISTDIR)/$*.dbg \
$(wordlist 2, $(words $^), $^)
# where to look for files with various suffixes
vpath %.o $(OBJDIR)
vpath %.s $(ASMDIR)
vpath %.inc $(INCDIR)
vpath %.chr $(CHRDIR)
vpath %.xcf $(CHRDIR)
vpath %.png $(CHRDIR)
vpath %.nes $(DISTDIR)
vpath %.d $(DEPDIR)