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 TARGET_PATH := $(shell $(CL) --print-target-path)
39 EMD := $(wildcard $(TARGET_PATH)/$(SYS)/drv/emd/*)
40 MOU := $(wildcard $(TARGET_PATH)/$(SYS)/drv/mou/*)
41 TGI := $(wildcard $(TARGET_PATH)/$(SYS)/drv/tgi/*)
43 # This one comes with VICE
46 # For this one see http://applecommander.sourceforge.net/
49 # For this one see http://www.horus.com/~hias/atari/
52 DISK_c64 = samples.d64
53 DISK_apple2 = samples.dsk
54 DISK_apple2enh = samples.dsk
55 DISK_atari = samples.atr
56 DISK_atarixl = samples.atr
58 # --------------------------------------------------------------------------
59 # System-dependent settings
61 # The Apple machines need the start address adjusted when using TGI
62 LDFLAGS_mandelbrot_apple2 = --start-addr 0x4000
63 LDFLAGS_mandelbrot_apple2enh = --start-addr 0x4000
64 LDFLAGS_tgidemo_apple2 = --start-addr 0x4000
65 LDFLAGS_tgidemo_apple2enh = --start-addr 0x4000
67 # The Apple ][ needs the start address adjusted for the mousetest
68 LDFLAGS_mousetest_apple2 = --start-addr 0x4000
70 # The Apple machines need the end address adjusted for large programs
71 LDFLAGS_gunzip65_apple2 = -D __HIMEM__=0xBF00
72 LDFLAGS_gunzip65_apple2enh = -D __HIMEM__=0xBF00
74 # The atari target needs to reserve some memory when using TGI
75 LDFLAGS_mandelbrot_atari = -D __RESERVED_MEMORY__=0x2000
76 LDFLAGS_tgidemo_atari = -D __RESERVED_MEMORY__=0x2000
78 # The atarixl target needs the start address adjusted when using TGI
79 LDFLAGS_mandelbrot_atarixl = --start-addr 0x4000
80 LDFLAGS_tgidemo_atarixl = --start-addr 0x4000
82 # --------------------------------------------------------------------------
85 .PHONY: all mostlyclean clean install zip samples disk
91 $(CC) $(CFLAGS) -Oirs --codesize 500 -T -g -t $(SYS) $<
95 $(AS) $(AFLAGS) -t $(SYS) $<
100 $(LD) $(LDFLAGS_$(@F)_$(SYS)) -o $@ -t $(SYS) -m $@.map $^ $(SYS).lib
102 # --------------------------------------------------------------------------
103 # List of executables
133 EXELIST_apple2enh = $(EXELIST_apple2)
146 EXELIST_atarixl = $(EXELIST_atari)
148 # --------------------------------------------------------------------------
149 # Rules to make the binaries and the disk
151 samples: $(EXELIST_$(SYS))
157 # --------------------------------------------------------------------------
158 # Overlay rules. Overlays need special ld65 configuration files. Also, the
159 # overlay file-names are shortenned to fit the Atari's 8.3-character limit.
161 multdemo: multidemo.o
162 $(LD) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(SYS).lib
164 ovrldemo: overlaydemo.o
165 $(LD) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(SYS).lib
167 OVERLAYLIST := $(foreach I,1 2 3,multdemo.$I ovrldemo.$I)
169 # --------------------------------------------------------------------------
170 # Rule to make a CBM disk with all samples. Needs the c1541 program that comes
171 # with the VICE emulator.
173 define D64_WRITE_recipe
175 $(C1541) -attach $@ -write $(file) $(notdir $(file)) >$(NULLDEV)
177 endef # D64_WRITE_recipe
180 @$(C1541) -format samples,AA d64 $@ >$(NULLDEV)
181 $(foreach file,$(EXELIST_$(SYS)),$(D64_WRITE_recipe))
182 $(foreach file,$(OVERLAYLIST),$(D64_WRITE_recipe))
183 $(foreach file,$(EMD) $(MOU) $(TGI),$(D64_WRITE_recipe))
185 # --------------------------------------------------------------------------
186 # Rule to make an Apple II disk with all samples. Needs the Apple Commander
187 # program available at http://applecommander.sourceforge.net/ and a template
188 # disk named 'prodos.dsk'.
190 define DSK_WRITE_BIN_recipe
192 $(if $(findstring BF00,$(LDFLAGS_$(notdir $(file))_$(SYS))), \
193 java -jar $(AC) -p $@ $(notdir $(file)).system sys <$(TARGET_PATH)/$(SYS)/util/loader.system)
194 java -jar $(AC) -cc65 $@ $(notdir $(file)) bin <$(file)
196 endef # DSK_WRITE_BIN_recipe
198 define DSK_WRITE_REL_recipe
200 java -jar $(AC) -p $@ $(notdir $(file)) rel 0 <$(file)
202 endef # DSK_WRITE_REL_recipe
206 $(foreach file,$(EXELIST_$(SYS)),$(DSK_WRITE_BIN_recipe))
207 $(foreach file,$(OVERLAYLIST),$(DSK_WRITE_REL_recipe))
208 $(foreach file,$(EMD) $(MOU) $(TGI),$(DSK_WRITE_REL_recipe))
210 # --------------------------------------------------------------------------
211 # Rule to make an Atari disk with all samples. Needs the dir2atr program
212 # available at http://www.horus.com/~hias/atari/ and the MyDos4534 variant
213 # of dos.sys and dup.sys.
215 define ATR_WRITE_recipe
217 cp $(file) atr/$(notdir $(file))
219 endef # ATR_WRITE_recipe
223 cp dos.sys atr/dos.sys
224 cp dup.sys atr/dup.sys
225 @$(foreach file,$(EXELIST_$(SYS)),$(ATR_WRITE_recipe))
226 @$(foreach file,$(OVERLAYLIST),$(ATR_WRITE_recipe))
227 @$(foreach file,$(EMD) $(MOU) $(TGI),$(ATR_WRITE_recipe))
228 $(DIR2ATR) -d -b MyDos4534 3200 $@ atr
231 # --------------------------------------------------------------------------
235 samplesdir = $(prefix)/share/cc65
238 $(if $(prefix),,$(error variable `prefix' must be set))
239 $(INSTALL) -d $(DESTDIR)$(samplesdir)
240 $(INSTALL) -d $(DESTDIR)$(samplesdir)/geos
241 $(INSTALL) -d $$(DESTDIR)$(samplesdir)/tutorial
242 $(INSTALL) -m0644 *.* $(DESTDIR)$(samplesdir)
243 $(INSTALL) -m0644 README $(DESTDIR)$(samplesdir)
244 $(INSTALL) -m0644 Makefile $(DESTDIR)$(samplesdir)
245 $(INSTALL) -m0644 geos/*.* $(DESTDIR)$(samplesdir)/geos
246 $(INSTALL) -m0644 tutorial/*.* $(DESTDIR)$(samplesdir)/tutorial
248 # --------------------------------------------------------------------------
252 @cd .. && zip -r cc65 samples/
254 # --------------------------------------------------------------------------
258 @$(DEL) *.map *.o *.s 2>$(NULLDEV)
261 @$(DEL) $(EXELIST_$(SYS)) $(DISK_$(SYS)) 2>$(NULLDEV)
262 @$(DEL) multdemo.? ovrldemo.? 2>$(NULLDEV)