]> git.sur5r.net Git - cc65/blob - samples/Makefile
bbf69c8202cd8017de5f1545f5e861dc00156821
[cc65] / samples / Makefile
1 #
2 # Makefile for cc65 samples
3 #
4 # This Makefile requires GNU make
5 #
6
7 # Run 'make samples SYS=<target>' to build for another target system
8 SYS = c64
9
10 ifneq ($(shell echo),)
11   CMD_EXE = 1
12 endif
13
14 ifdef CMD_EXE
15   NULLDEV = nul:
16   DEL = -del /f
17   RMDIR = rmdir /s /q
18 else
19   NULLDEV = /dev/null
20   DEL = $(RM)
21   RMDIR = $(RM) -r
22 endif
23
24 ifdef CC65_HOME
25   AS = $(CC65_HOME)/bin/ca65
26   CC = $(CC65_HOME)/bin/cc65
27   CL = $(CC65_HOME)/bin/cl65
28   LD = $(CC65_HOME)/bin/ld65
29 else
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)
34 endif
35
36 TARGET_PATH := $(shell $(CL) --print-target-path)
37
38 EMD := $(wildcard $(TARGET_PATH)/$(SYS)/drv/emd/*)
39 MOU := $(wildcard $(TARGET_PATH)/$(SYS)/drv/mou/*)
40 TGI := $(wildcard $(TARGET_PATH)/$(SYS)/drv/tgi/*)
41
42 # This one comes with VICE
43 C1541 ?= c1541
44
45 # For this one see http://applecommander.sourceforge.net/
46 AC ?= ac.jar
47
48 # For this one see http://www.horus.com/~hias/atari/
49 DIR2ATR ?= dir2atr
50
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
56
57 # --------------------------------------------------------------------------
58 # System-dependent settings
59
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
65
66 # The Apple ][ needs the start address adjusted for the mousetest
67 LDFLAGS_mousetest_apple2 = --start-addr 0x4000
68
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
72
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
76
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
80
81 # --------------------------------------------------------------------------
82 # Generic rules
83
84 .PHONY: all mostlyclean clean install zip samples disk
85
86 %: %.c
87 %: %.s
88
89 .c.o:
90         $(CC) $(CFLAGS) -Oirs --codesize 500 -T -g -t $(SYS) $<
91         $(AS) $(<:.c=.s)
92
93 .s.o:
94         $(AS) $(AFLAGS) -t $(SYS) $<
95
96 .PRECIOUS: %.o
97
98 .o:
99         $(LD) $(LDFLAGS_$(@F)_$(SYS)) -o $@ -t $(SYS) -m $@.map $^ $(SYS).lib
100
101 # --------------------------------------------------------------------------
102 # List of executables
103
104 EXELIST_c64 =      \
105         ascii      \
106         enumdevdir \
107         fire       \
108         gunzip65   \
109         hello      \
110         mandelbrot \
111         mousetest  \
112         multdemo   \
113         nachtm     \
114         ovrldemo   \
115         plasma     \
116         sieve      \
117         tgidemo
118
119 EXELIST_apple2 =   \
120         ascii      \
121         diodemo    \
122         enumdevdir \
123         gunzip65   \
124         hello      \
125         mandelbrot \
126         mousetest  \
127         multdemo   \
128         ovrldemo   \
129         sieve      \
130         tgidemo
131
132 EXELIST_apple2enh = $(EXELIST_apple2)
133
134 EXELIST_atari =    \
135         ascii      \
136         gunzip65   \
137         hello      \
138         mandelbrot \
139         mousetest  \
140         multdemo   \
141         ovrldemo   \
142         sieve      \
143         tgidemo
144
145 EXELIST_atarixl = $(EXELIST_atari)
146
147 # --------------------------------------------------------------------------
148 # Rules to make the binaries and the disk
149
150 all:
151
152 samples: $(EXELIST_$(SYS))
153
154 disk: $(DISK_$(SYS))
155
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.
159
160 multdemo: multidemo.o
161         $(LD) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(SYS).lib
162
163 ovrldemo: overlaydemo.o
164         $(LD) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(SYS).lib
165
166 OVERLAYLIST := $(foreach I,1 2 3,multdemo.$I ovrldemo.$I)
167
168 # --------------------------------------------------------------------------
169 # Rule to make a CBM disk with all samples. Needs the c1541 program that comes
170 # with the VICE emulator.
171
172 define D64_WRITE_recipe
173
174 $(C1541) -attach $@ -write $(file) $(notdir $(file)) >$(NULLDEV)
175
176 endef # D64_WRITE_recipe
177
178 samples.d64: samples
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))
183
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'.
188
189 define DSK_WRITE_BIN_recipe
190
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)
194
195 endef # DSK_WRITE_BIN_recipe
196
197 define DSK_WRITE_REL_recipe
198
199 java -jar $(AC) -p $@ $(notdir $(file)) rel 0 <$(file)
200
201 endef # DSK_WRITE_REL_recipe
202
203 samples.dsk: samples
204         cp prodos.dsk $@
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))
208
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.
213
214 define ATR_WRITE_recipe
215
216 cp $(file) atr/$(notdir $(file))
217
218 endef # ATR_WRITE_recipe
219
220 samples.atr: samples
221         @mkdir atr
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
228         @$(RMDIR) atr
229
230 # --------------------------------------------------------------------------
231 # Installation rules
232
233 INSTALL = install
234 samplesdir = $(prefix)/share/cc65
235
236 install:
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
246
247 # --------------------------------------------------------------------------
248 # Packaging rules
249
250 zip:
251         @cd .. && zip -r cc65 samples/
252
253 # --------------------------------------------------------------------------
254 # Clean-up rules
255
256 mostlyclean:
257         @$(DEL) *.map *.o *.s 2>$(NULLDEV)
258
259 clean: mostlyclean
260         @$(DEL) $(EXELIST_$(SYS)) $(DISK_$(SYS)) 2>$(NULLDEV)
261         @$(DEL) multdemo.? ovrldemo.? 2>$(NULLDEV)