2 # Makefile for cc65 samples
4 # This Makefile requires GNU make
7 # Run 'make samples SYS=<target>' to build for another target system
10 ifneq ($(shell echo),)
25 AS = $(CC65_HOME)/bin/ca65
26 CC = $(CC65_HOME)/bin/cc65
27 CL = $(CC65_HOME)/bin/cl65
28 LD = $(CC65_HOME)/bin/ld65
30 AS := $(if $(wildcard ../bin/ca65*),../bin/ca65,ca65)
31 CC := $(if $(wildcard ../bin/cc65*),../bin/cc65,cc65)
32 CL := $(if $(wildcard ../bin/cl65*),../bin/cl65,cl65)
33 LD := $(if $(wildcard ../bin/ld65*),../bin/ld65,ld65)
36 TARGET_PATH := $(shell $(CL) --print-target-path)
38 EMD := $(wildcard $(TARGET_PATH)/$(SYS)/drv/emd/*)
39 MOU := $(wildcard $(TARGET_PATH)/$(SYS)/drv/mou/*)
40 TGI := $(wildcard $(TARGET_PATH)/$(SYS)/drv/tgi/*)
42 # This one comes with VICE
45 # For this one see http://applecommander.sourceforge.net/
48 # For this one see http://www.horus.com/~hias/atari/
51 DISK_c64 = samples.d64
52 DISK_apple2 = samples.dsk
53 DISK_apple2enh = samples.dsk
54 DISK_atari = samples.atr
55 DISK_atarixl = samples.atr
57 # --------------------------------------------------------------------------
58 # System-dependent settings
60 # The Apple machines need the start address adjusted when using TGI
61 LDFLAGS_mandelbrot_apple2 = --start-addr 0x4000
62 LDFLAGS_mandelbrot_apple2enh = --start-addr 0x4000
63 LDFLAGS_tgidemo_apple2 = --start-addr 0x4000
64 LDFLAGS_tgidemo_apple2enh = --start-addr 0x4000
66 # The Apple ][ needs the start address adjusted for the mousetest
67 LDFLAGS_mousetest_apple2 = --start-addr 0x4000
69 # The Apple machines need the end address adjusted for large programs
70 LDFLAGS_gunzip65_apple2 = -D __HIMEM__=0xBF00
71 LDFLAGS_gunzip65_apple2enh = -D __HIMEM__=0xBF00
73 # The atari target needs to reserve some memory when using TGI
74 LDFLAGS_mandelbrot_atari = -D __RESERVED_MEMORY__=0x2000
75 LDFLAGS_tgidemo_atari = -D __RESERVED_MEMORY__=0x2000
77 # The atarixl target needs the start address adjusted when using TGI
78 LDFLAGS_mandelbrot_atarixl = --start-addr 0x4000
79 LDFLAGS_tgidemo_atarixl = --start-addr 0x4000
81 # --------------------------------------------------------------------------
84 .PHONY: all mostlyclean clean install zip samples disk
90 $(CC) $(CFLAGS) -Oirs --codesize 500 -T -g -t $(SYS) $<
94 $(AS) $(AFLAGS) -t $(SYS) $<
99 $(LD) $(LDFLAGS_$(@F)_$(SYS)) -o $@ -t $(SYS) -m $@.map $^ $(SYS).lib
101 # --------------------------------------------------------------------------
102 # List of executables
132 EXELIST_apple2enh = $(EXELIST_apple2)
145 EXELIST_atarixl = $(EXELIST_atari)
147 # --------------------------------------------------------------------------
148 # Rules to make the binaries and the disk
152 samples: $(EXELIST_$(SYS))
156 # --------------------------------------------------------------------------
157 # Overlay rules. Overlays need special ld65 configuration files. Also, the
158 # overlay file-names are shortenned to fit the Atari's 8.3-character limit.
160 multdemo: multidemo.o
161 $(LD) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(SYS).lib
163 ovrldemo: overlaydemo.o
164 $(LD) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(SYS).lib
166 OVERLAYLIST := $(foreach I,1 2 3,multdemo.$I ovrldemo.$I)
168 # --------------------------------------------------------------------------
169 # Rule to make a CBM disk with all samples. Needs the c1541 program that comes
170 # with the VICE emulator.
172 define D64_WRITE_recipe
174 $(C1541) -attach $@ -write $(file) $(notdir $(file)) >$(NULLDEV)
176 endef # D64_WRITE_recipe
179 @$(C1541) -format samples,AA d64 $@ >$(NULLDEV)
180 $(foreach file,$(EXELIST_$(SYS)),$(D64_WRITE_recipe))
181 $(foreach file,$(OVERLAYLIST),$(D64_WRITE_recipe))
182 $(foreach file,$(EMD) $(MOU) $(TGI),$(D64_WRITE_recipe))
184 # --------------------------------------------------------------------------
185 # Rule to make an Apple II disk with all samples. Needs the Apple Commander
186 # program available at http://applecommander.sourceforge.net/ and a template
187 # disk named 'prodos.dsk'.
189 define DSK_WRITE_BIN_recipe
191 $(if $(findstring BF00,$(LDFLAGS_$(notdir $(file))_$(SYS))), \
192 java -jar $(AC) -p $@ $(notdir $(file)).system sys <$(TARGET_PATH)/$(SYS)/util/loader.system)
193 java -jar $(AC) -cc65 $@ $(notdir $(file)) bin <$(file)
195 endef # DSK_WRITE_BIN_recipe
197 define DSK_WRITE_REL_recipe
199 java -jar $(AC) -p $@ $(notdir $(file)) rel 0 <$(file)
201 endef # DSK_WRITE_REL_recipe
205 $(foreach file,$(EXELIST_$(SYS)),$(DSK_WRITE_BIN_recipe))
206 $(foreach file,$(OVERLAYLIST),$(DSK_WRITE_REL_recipe))
207 $(foreach file,$(EMD) $(MOU) $(TGI),$(DSK_WRITE_REL_recipe))
209 # --------------------------------------------------------------------------
210 # Rule to make an Atari disk with all samples. Needs the dir2atr program
211 # available at http://www.horus.com/~hias/atari/ and the MyDos4534 variant
212 # of dos.sys and dup.sys.
214 define ATR_WRITE_recipe
216 cp $(file) atr/$(notdir $(file))
218 endef # ATR_WRITE_recipe
222 cp dos.sys atr/dos.sys
223 cp dup.sys atr/dup.sys
224 @$(foreach file,$(EXELIST_$(SYS)),$(ATR_WRITE_recipe))
225 @$(foreach file,$(OVERLAYLIST),$(ATR_WRITE_recipe))
226 @$(foreach file,$(EMD) $(MOU) $(TGI),$(ATR_WRITE_recipe))
227 $(DIR2ATR) -d -b MyDos4534 3200 $@ atr
230 # --------------------------------------------------------------------------
234 samplesdir = $(prefix)/share/cc65
237 $(if $(prefix),,$(error variable `prefix' must be set))
238 $(INSTALL) -d $(DESTDIR)$(samplesdir)
239 $(INSTALL) -d $(DESTDIR)$(samplesdir)/geos
240 $(INSTALL) -d $$(DESTDIR)$(samplesdir)/tutorial
241 $(INSTALL) -m0644 *.* $(DESTDIR)$(samplesdir)
242 $(INSTALL) -m0644 README $(DESTDIR)$(samplesdir)
243 $(INSTALL) -m0644 Makefile $(DESTDIR)$(samplesdir)
244 $(INSTALL) -m0644 geos/*.* $(DESTDIR)$(samplesdir)/geos
245 $(INSTALL) -m0644 tutorial/*.* $(DESTDIR)$(samplesdir)/tutorial
247 # --------------------------------------------------------------------------
251 @cd .. && zip -r cc65 samples/
253 # --------------------------------------------------------------------------
257 @$(DEL) *.map *.o *.s 2>$(NULLDEV)
260 @$(DEL) $(EXELIST_$(SYS)) $(DISK_$(SYS)) 2>$(NULLDEV)
261 @$(DEL) multdemo.? ovrldemo.? 2>$(NULLDEV)