2 # Makefile for cc65 samples
4 # This Makefile requires GNU make
7 # Run 'make SYS=<target>'; or, set a SYS env.
8 # var. to build for another target system.
11 ifneq ($(shell echo),)
26 AS = $(CC65_HOME)/bin/ca65
27 CC = $(CC65_HOME)/bin/cc65
28 CL = $(CC65_HOME)/bin/cl65
29 LD = $(CC65_HOME)/bin/ld65
31 AS := $(if $(wildcard ../bin/ca65*),../bin/ca65,ca65)
32 CC := $(if $(wildcard ../bin/cc65*),../bin/cc65,cc65)
33 CL := $(if $(wildcard ../bin/cl65*),../bin/cl65,cl65)
34 LD := $(if $(wildcard ../bin/ld65*),../bin/ld65,ld65)
37 ifneq ($(filter disk samples.%,$(MAKECMDGOALS)),)
39 TARGET_PATH = $(CC65_HOME)/target
41 TARGET_PATH := $(if $(wildcard ../target),../target,$(shell $(CL) --print-target-path))
44 ifneq ($(words $(TARGET_PATH)),1)
45 $(error No space chars allowed in "$(TARGET_PATH)")
48 EMD := $(wildcard $(TARGET_PATH)/$(SYS)/drv/emd/*)
49 MOU := $(wildcard $(TARGET_PATH)/$(SYS)/drv/mou/*)
50 TGI := $(wildcard $(TARGET_PATH)/$(SYS)/drv/tgi/*)
52 # This one comes with the VICE emulator.
53 # See http://vice-emu.sourceforge.net/
56 # For this one, see https://applecommander.github.io/
59 # For this one, see http://www.horus.com/~hias/atari/
62 DISK_c64 = samples.d64
63 DISK_apple2 = samples.dsk
64 DISK_apple2enh = samples.dsk
65 DISK_atari = samples.atr
66 DISK_atarixl = samples.atr
69 # --------------------------------------------------------------------------
70 # System-dependent settings
71 # For convenience, these groups and lines are sorted alphabetically, first
72 # by target-machine group, then by mission, then by program and sub-target.
74 # The Apple machines need the start address adjusted when using TGI
75 LDFLAGS_mandelbrot_apple2 = --start-addr 0x4000
76 LDFLAGS_mandelbrot_apple2enh = --start-addr 0x4000
77 LDFLAGS_tgidemo_apple2 = --start-addr 0x4000
78 LDFLAGS_tgidemo_apple2enh = --start-addr 0x4000
80 # The Apple ][ needs the start address adjusted for the mousedemo
81 LDFLAGS_mousedemo_apple2 = --start-addr 0x4000
83 # The Apple machines need the end address adjusted for large programs
84 LDFLAGS_gunzip65_apple2 = -D __HIMEM__=0xBF00
85 LDFLAGS_gunzip65_apple2enh = -D __HIMEM__=0xBF00
87 # The atari target needs to reserve some memory when using TGI
88 LDFLAGS_mandelbrot_atari = -D __RESERVED_MEMORY__=0x2000
89 LDFLAGS_tgidemo_atari = -D __RESERVED_MEMORY__=0x2000
91 # The atarixl target needs the start address adjusted when using TGI
92 LDFLAGS_mandelbrot_atarixl = --start-addr 0x4000
93 LDFLAGS_tgidemo_atarixl = --start-addr 0x4000
95 # --------------------------------------------------------------------------
98 .PHONY: all mostlyclean clean install zip samples disk
104 $(CC) $(CFLAGS) -Ors --codesize 500 -T -g -t $(SYS) $<
108 $(AS) $(ASFLAGS) -t $(SYS) $<
114 $(LD) $(LDFLAGS_$(@F)_$(SYS)) $(LDFLAGS) -o $@ -C vic20-32k.cfg -m $@.map $^ $(SYS).lib
116 $(LD) $(LDFLAGS_$(@F)_$(SYS)) $(LDFLAGS) -o $@ -t $(SYS) -m $@.map $^ $(SYS).lib
119 # --------------------------------------------------------------------------
120 # Lists of executables
150 EXELIST_apple2enh = $(EXELIST_apple2)
163 EXELIST_atarixl = $(EXELIST_atari)
165 EXELIST_atari2600 = \
168 # Unlisted targets will try to build everything.
169 # That lets us learn what they cannot build, and what settings
170 # we need to use for programs that can be built and run.
171 ifndef EXELIST_$(SYS)
172 EXELIST_$(SYS) := ${patsubst %.c,%,$(wildcard *.c)}
175 # --------------------------------------------------------------------------
176 # Rules to make the binaries and the disk
178 samples: $(EXELIST_$(SYS))
184 # --------------------------------------------------------------------------
185 # Overlay rules. Overlays need special ld65 configuration files. Also, the
186 # overlay file-names are shortenned to fit the Atari's 8.3-character limit.
188 multdemo: multidemo.o
189 $(LD) $(LDFLAGS) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(SYS).lib
191 ovrldemo: overlaydemo.o
192 $(LD) $(LDFLAGS) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(SYS).lib
194 OVERLAYLIST := $(foreach I,1 2 3,multdemo.$I ovrldemo.$I)
196 # --------------------------------------------------------------------------
197 # Rule to make a CBM disk with all samples. Needs the c1541 program that comes
198 # with the VICE emulator.
200 define D64_WRITE_recipe
202 $(C1541) -attach $@ -write $(file) $(notdir $(file)) >$(NULLDEV)
204 endef # D64_WRITE_recipe
207 @$(C1541) -format samples,AA d64 $@ >$(NULLDEV)
208 $(foreach file,$(EXELIST_$(SYS)),$(D64_WRITE_recipe))
209 $(foreach file,$(OVERLAYLIST),$(D64_WRITE_recipe))
210 $(foreach file,$(EMD) $(MOU) $(TGI),$(D64_WRITE_recipe))
212 # --------------------------------------------------------------------------
213 # Rule to make an Apple II disk with all samples. Needs the AppleCommander
214 # program, available at https://applecommander.github.io/, and a template disk
215 # named 'prodos.dsk'.
217 define DSK_WRITE_BIN_recipe
219 $(if $(findstring BF00,$(LDFLAGS_$(notdir $(file))_$(SYS))), \
220 java -jar $(AC) -p $@ $(notdir $(file)).system sys <$(TARGET_PATH)/$(SYS)/util/loader.system)
221 java -jar $(AC) -as $@ $(notdir $(file)) <$(file)
223 endef # DSK_WRITE_BIN_recipe
225 define DSK_WRITE_REL_recipe
227 java -jar $(AC) -p $@ $(notdir $(file)) rel 0 <$(file)
229 endef # DSK_WRITE_REL_recipe
233 $(foreach file,$(EXELIST_$(SYS)),$(DSK_WRITE_BIN_recipe))
234 $(foreach file,$(OVERLAYLIST),$(DSK_WRITE_REL_recipe))
235 $(foreach file,$(EMD) $(MOU) $(TGI),$(DSK_WRITE_REL_recipe))
237 # --------------------------------------------------------------------------
238 # Rule to make an Atari disk with all samples. Needs the dir2atr program
239 # available at http://www.horus.com/~hias/atari/ and the MyDos4534 variant
240 # of dos.sys and dup.sys.
242 define ATR_WRITE_recipe
244 cp $(file) atr/$(notdir $(file))
246 endef # ATR_WRITE_recipe
250 cp dos.sys atr/dos.sys
251 cp dup.sys atr/dup.sys
252 @$(foreach file,$(EXELIST_$(SYS)),$(ATR_WRITE_recipe))
253 @$(foreach file,$(OVERLAYLIST),$(ATR_WRITE_recipe))
254 @$(foreach file,$(EMD) $(MOU) $(TGI),$(ATR_WRITE_recipe))
255 $(DIR2ATR) -d -b MyDos4534 3200 $@ atr
258 # --------------------------------------------------------------------------
262 samplesdir = $(PREFIX)/share/cc65/samples
265 $(if $(PREFIX),,$(error variable `PREFIX' must be set))
266 $(INSTALL) -d $(DESTDIR)$(samplesdir)
267 $(INSTALL) -d $(DESTDIR)$(samplesdir)/geos
268 $(INSTALL) -d $(DESTDIR)$(samplesdir)/tutorial
269 $(INSTALL) -m0644 *.* $(DESTDIR)$(samplesdir)
270 $(INSTALL) -m0644 README $(DESTDIR)$(samplesdir)
271 $(INSTALL) -m0644 Makefile $(DESTDIR)$(samplesdir)
272 $(INSTALL) -m0644 geos/*.* $(DESTDIR)$(samplesdir)/geos
273 $(INSTALL) -m0644 tutorial/*.* $(DESTDIR)$(samplesdir)/tutorial
275 # --------------------------------------------------------------------------
279 @cd .. && zip -r cc65 samples/
281 # --------------------------------------------------------------------------
285 @$(DEL) *.lbl *.map *.o *.s 2>$(NULLDEV)
288 @$(DEL) $(EXELIST_$(SYS)) $(DISK_$(SYS)) 2>$(NULLDEV)
289 @$(DEL) multdemo.? ovrldemo.? 2>$(NULLDEV)