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)),)
38 TARGET_PATH := $(shell $(CL) --print-target-path)
40 EMD := $(wildcard $(TARGET_PATH)/$(SYS)/drv/emd/*)
41 MOU := $(wildcard $(TARGET_PATH)/$(SYS)/drv/mou/*)
42 TGI := $(wildcard $(TARGET_PATH)/$(SYS)/drv/tgi/*)
44 # This one comes with VICE
47 # For this one see http://applecommander.sourceforge.net/
50 # For this one see http://www.horus.com/~hias/atari/
53 DISK_c64 = samples.d64
54 DISK_apple2 = samples.dsk
55 DISK_apple2enh = samples.dsk
56 DISK_atari = samples.atr
57 DISK_atarixl = samples.atr
60 # --------------------------------------------------------------------------
61 # System-dependent settings
63 # The Apple machines need the start address adjusted when using TGI
64 LDFLAGS_mandelbrot_apple2 = --start-addr 0x4000
65 LDFLAGS_mandelbrot_apple2enh = --start-addr 0x4000
66 LDFLAGS_tgidemo_apple2 = --start-addr 0x4000
67 LDFLAGS_tgidemo_apple2enh = --start-addr 0x4000
69 # The Apple ][ needs the start address adjusted for the mousetest
70 LDFLAGS_mousetest_apple2 = --start-addr 0x4000
72 # The Apple machines need the end address adjusted for large programs
73 LDFLAGS_gunzip65_apple2 = -D __HIMEM__=0xBF00
74 LDFLAGS_gunzip65_apple2enh = -D __HIMEM__=0xBF00
76 # The atari target needs to reserve some memory when using TGI
77 LDFLAGS_mandelbrot_atari = -D __RESERVED_MEMORY__=0x2000
78 LDFLAGS_tgidemo_atari = -D __RESERVED_MEMORY__=0x2000
80 # The atarixl target needs the start address adjusted when using TGI
81 LDFLAGS_mandelbrot_atarixl = --start-addr 0x4000
82 LDFLAGS_tgidemo_atarixl = --start-addr 0x4000
84 # --------------------------------------------------------------------------
87 .PHONY: all mostlyclean clean install zip samples disk
93 $(CC) $(CFLAGS) -Oirs --codesize 500 -T -g -t $(SYS) $<
97 $(AS) $(AFLAGS) -t $(SYS) $<
102 $(LD) $(LDFLAGS_$(@F)_$(SYS)) -o $@ -t $(SYS) -m $@.map $^ $(SYS).lib
104 # --------------------------------------------------------------------------
105 # List of executables
135 EXELIST_apple2enh = $(EXELIST_apple2)
148 EXELIST_atarixl = $(EXELIST_atari)
150 # --------------------------------------------------------------------------
151 # Rules to make the binaries and the disk
153 samples: $(EXELIST_$(SYS))
159 # --------------------------------------------------------------------------
160 # Overlay rules. Overlays need special ld65 configuration files. Also, the
161 # overlay file-names are shortenned to fit the Atari's 8.3-character limit.
163 multdemo: multidemo.o
164 $(LD) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(SYS).lib
166 ovrldemo: overlaydemo.o
167 $(LD) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(SYS).lib
169 OVERLAYLIST := $(foreach I,1 2 3,multdemo.$I ovrldemo.$I)
171 # --------------------------------------------------------------------------
172 # Rule to make a CBM disk with all samples. Needs the c1541 program that comes
173 # with the VICE emulator.
175 define D64_WRITE_recipe
177 $(C1541) -attach $@ -write $(file) $(notdir $(file)) >$(NULLDEV)
179 endef # D64_WRITE_recipe
182 @$(C1541) -format samples,AA d64 $@ >$(NULLDEV)
183 $(foreach file,$(EXELIST_$(SYS)),$(D64_WRITE_recipe))
184 $(foreach file,$(OVERLAYLIST),$(D64_WRITE_recipe))
185 $(foreach file,$(EMD) $(MOU) $(TGI),$(D64_WRITE_recipe))
187 # --------------------------------------------------------------------------
188 # Rule to make an Apple II disk with all samples. Needs the Apple Commander
189 # program available at http://applecommander.sourceforge.net/ and a template
190 # disk named 'prodos.dsk'.
192 define DSK_WRITE_BIN_recipe
194 $(if $(findstring BF00,$(LDFLAGS_$(notdir $(file))_$(SYS))), \
195 java -jar $(AC) -p $@ $(notdir $(file)).system sys <$(TARGET_PATH)/$(SYS)/util/loader.system)
196 java -jar $(AC) -cc65 $@ $(notdir $(file)) bin <$(file)
198 endef # DSK_WRITE_BIN_recipe
200 define DSK_WRITE_REL_recipe
202 java -jar $(AC) -p $@ $(notdir $(file)) rel 0 <$(file)
204 endef # DSK_WRITE_REL_recipe
208 $(foreach file,$(EXELIST_$(SYS)),$(DSK_WRITE_BIN_recipe))
209 $(foreach file,$(OVERLAYLIST),$(DSK_WRITE_REL_recipe))
210 $(foreach file,$(EMD) $(MOU) $(TGI),$(DSK_WRITE_REL_recipe))
212 # --------------------------------------------------------------------------
213 # Rule to make an Atari disk with all samples. Needs the dir2atr program
214 # available at http://www.horus.com/~hias/atari/ and the MyDos4534 variant
215 # of dos.sys and dup.sys.
217 define ATR_WRITE_recipe
219 cp $(file) atr/$(notdir $(file))
221 endef # ATR_WRITE_recipe
225 cp dos.sys atr/dos.sys
226 cp dup.sys atr/dup.sys
227 @$(foreach file,$(EXELIST_$(SYS)),$(ATR_WRITE_recipe))
228 @$(foreach file,$(OVERLAYLIST),$(ATR_WRITE_recipe))
229 @$(foreach file,$(EMD) $(MOU) $(TGI),$(ATR_WRITE_recipe))
230 $(DIR2ATR) -d -b MyDos4534 3200 $@ atr
233 # --------------------------------------------------------------------------
237 samplesdir = $(prefix)/share/cc65
240 $(if $(prefix),,$(error variable `prefix' must be set))
241 $(INSTALL) -d $(DESTDIR)$(samplesdir)
242 $(INSTALL) -d $(DESTDIR)$(samplesdir)/geos
243 $(INSTALL) -d $(DESTDIR)$(samplesdir)/tutorial
244 $(INSTALL) -m0644 *.* $(DESTDIR)$(samplesdir)
245 $(INSTALL) -m0644 README $(DESTDIR)$(samplesdir)
246 $(INSTALL) -m0644 Makefile $(DESTDIR)$(samplesdir)
247 $(INSTALL) -m0644 geos/*.* $(DESTDIR)$(samplesdir)/geos
248 $(INSTALL) -m0644 tutorial/*.* $(DESTDIR)$(samplesdir)/tutorial
250 # --------------------------------------------------------------------------
254 @cd .. && zip -r cc65 samples/
256 # --------------------------------------------------------------------------
260 @$(DEL) *.map *.o *.s 2>$(NULLDEV)
263 @$(DEL) $(EXELIST_$(SYS)) $(DISK_$(SYS)) 2>$(NULLDEV)
264 @$(DEL) multdemo.? ovrldemo.? 2>$(NULLDEV)