]> git.sur5r.net Git - cc65/blob - samples/Makefile
8bb6d25ae1e77a346597607d233a549f2fa58544
[cc65] / samples / Makefile
1 #
2 # Makefile for cc65 samples
3 #
4 # This Makefile requires GNU make
5 #
6
7 # Run 'make SYS=<target>'; or, set a SYS env.
8 # var. to build for another target system.
9 SYS ?= c64
10
11 ifneq ($(shell echo),)
12   CMD_EXE = 1
13 endif
14
15 ifdef CMD_EXE
16   NULLDEV = nul:
17   DEL = -del /f
18   RMDIR = rmdir /s /q
19 else
20   NULLDEV = /dev/null
21   DEL = $(RM)
22   RMDIR = $(RM) -r
23 endif
24
25 ifdef CC65_HOME
26   AS = $(CC65_HOME)/bin/ca65
27   CC = $(CC65_HOME)/bin/cc65
28   CL = $(CC65_HOME)/bin/cl65
29   LD = $(CC65_HOME)/bin/ld65
30 else
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)
35 endif
36
37 ifneq ($(filter disk samples.%,$(MAKECMDGOALS)),)
38   TARGET_PATH := $(shell $(CL) --print-target-path)
39
40   EMD := $(wildcard $(TARGET_PATH)/$(SYS)/drv/emd/*)
41   MOU := $(wildcard $(TARGET_PATH)/$(SYS)/drv/mou/*)
42   TGI := $(wildcard $(TARGET_PATH)/$(SYS)/drv/tgi/*)
43
44   # This one comes with the VICE emulator.
45   # See http://vice-emu.sourceforge.net/
46   C1541 ?= c1541
47
48   # For this one, see https://applecommander.github.io/
49   AC ?= ac.jar
50
51   # For this one, see http://www.horus.com/~hias/atari/
52   DIR2ATR ?= dir2atr
53
54   DISK_c64       = samples.d64
55   DISK_apple2    = samples.dsk
56   DISK_apple2enh = samples.dsk
57   DISK_atari     = samples.atr
58   DISK_atarixl   = samples.atr
59 endif
60
61 # --------------------------------------------------------------------------
62 # System-dependent settings
63 # For convenience, these groups and lines are sorted alphabetically, first
64 # by target-machine group, then by mission, then by program and sub-target.
65
66 # The Apple machines need the start address adjusted when using TGI
67 LDFLAGS_mandelbrot_apple2    = --start-addr 0x4000
68 LDFLAGS_mandelbrot_apple2enh = --start-addr 0x4000
69 LDFLAGS_tgidemo_apple2       = --start-addr 0x4000
70 LDFLAGS_tgidemo_apple2enh    = --start-addr 0x4000
71
72 # The Apple ][ needs the start address adjusted for the mousedemo
73 LDFLAGS_mousedemo_apple2 = --start-addr 0x4000
74
75 # The Apple machines need the end address adjusted for large programs
76 LDFLAGS_gunzip65_apple2    = -D __HIMEM__=0xBF00
77 LDFLAGS_gunzip65_apple2enh = -D __HIMEM__=0xBF00
78
79 # The atari target needs to reserve some memory when using TGI
80 LDFLAGS_mandelbrot_atari = -D __RESERVED_MEMORY__=0x2000
81 LDFLAGS_tgidemo_atari    = -D __RESERVED_MEMORY__=0x2000
82
83 # The atarixl target needs the start address adjusted when using TGI
84 LDFLAGS_mandelbrot_atarixl = --start-addr 0x4000
85 LDFLAGS_tgidemo_atarixl    = --start-addr 0x4000
86
87 # --------------------------------------------------------------------------
88 # Generic rules
89
90 .PHONY: all mostlyclean clean install zip samples disk
91
92 %: %.c
93 %: %.s
94
95 .c.o:
96         $(CC) $(CFLAGS) -Ors --codesize 500 -T -g -t $(SYS) $<
97         $(AS) $(<:.c=.s)
98
99 .s.o:
100         $(AS) $(ASFLAGS) -t $(SYS) $<
101
102 .PRECIOUS: %.o
103
104 .o:
105 ifeq ($(SYS),vic20)
106         $(LD) $(LDFLAGS_$(@F)_$(SYS)) $(LDFLAGS) -o $@ -C vic20-32k.cfg -m $@.map $^ $(SYS).lib
107 else
108         $(LD) $(LDFLAGS_$(@F)_$(SYS)) $(LDFLAGS) -o $@ -t $(SYS) -m $@.map $^ $(SYS).lib
109 endif
110
111 # --------------------------------------------------------------------------
112 # Lists of executables
113
114 EXELIST_c64 =      \
115         ascii      \
116         enumdevdir \
117         fire       \
118         gunzip65   \
119         hello      \
120         mandelbrot \
121         mousedemo  \
122         multdemo   \
123         nachtm     \
124         ovrldemo   \
125         plasma     \
126         sieve      \
127         tgidemo
128
129 EXELIST_apple2 =   \
130         ascii      \
131         diodemo    \
132         enumdevdir \
133         gunzip65   \
134         hello      \
135         mandelbrot \
136         mousedemo  \
137         multdemo   \
138         ovrldemo   \
139         sieve      \
140         tgidemo
141
142 EXELIST_apple2enh = $(EXELIST_apple2)
143
144 EXELIST_atari =    \
145         ascii      \
146         gunzip65   \
147         hello      \
148         mandelbrot \
149         mousedemo  \
150         multdemo   \
151         ovrldemo   \
152         sieve      \
153         tgidemo
154
155 EXELIST_atarixl = $(EXELIST_atari)
156
157 EXELIST_atari2600 = \
158         atari2600hello
159
160 # Unlisted targets will try to build everything.
161 # That lets us learn what they cannot build, and what settings
162 # we need to use for programs that can be built and run.
163 ifndef EXELIST_$(SYS)
164 EXELIST_$(SYS) := ${patsubst %.c,%,$(wildcard *.c)}
165 endif
166
167 # --------------------------------------------------------------------------
168 # Rules to make the binaries and the disk
169
170 samples: $(EXELIST_$(SYS))
171
172 disk: $(DISK_$(SYS))
173
174 all:
175
176 # --------------------------------------------------------------------------
177 # Overlay rules. Overlays need special ld65 configuration files.  Also, the
178 # overlay file-names are shortenned to fit the Atari's 8.3-character limit.
179
180 multdemo: multidemo.o
181         $(LD) $(LDFLAGS) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(SYS).lib
182
183 ovrldemo: overlaydemo.o
184         $(LD) $(LDFLAGS) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(SYS).lib
185
186 OVERLAYLIST := $(foreach I,1 2 3,multdemo.$I ovrldemo.$I)
187
188 # --------------------------------------------------------------------------
189 # Rule to make a CBM disk with all samples. Needs the c1541 program that comes
190 # with the VICE emulator.
191
192 define D64_WRITE_recipe
193
194 $(C1541) -attach $@ -write $(file) $(notdir $(file)) >$(NULLDEV)
195
196 endef # D64_WRITE_recipe
197
198 samples.d64: samples
199         @$(C1541) -format samples,AA  d64 $@ >$(NULLDEV)
200         $(foreach file,$(EXELIST_$(SYS)),$(D64_WRITE_recipe))
201         $(foreach file,$(OVERLAYLIST),$(D64_WRITE_recipe))
202         $(foreach file,$(EMD) $(MOU) $(TGI),$(D64_WRITE_recipe))
203
204 # --------------------------------------------------------------------------
205 # Rule to make an Apple II disk with all samples. Needs the AppleCommander
206 # program, available at https://applecommander.github.io/, and a template disk
207 # named 'prodos.dsk'.
208
209 define DSK_WRITE_BIN_recipe
210
211 $(if $(findstring BF00,$(LDFLAGS_$(notdir $(file))_$(SYS))), \
212   java -jar $(AC) -p $@ $(notdir $(file)).system sys <$(TARGET_PATH)/$(SYS)/util/loader.system)
213 java -jar $(AC) -as $@ $(notdir $(file)) <$(file)
214
215 endef # DSK_WRITE_BIN_recipe
216
217 define DSK_WRITE_REL_recipe
218
219 java -jar $(AC) -p $@ $(notdir $(file)) rel 0 <$(file)
220
221 endef # DSK_WRITE_REL_recipe
222
223 samples.dsk: samples
224         cp prodos.dsk $@
225         $(foreach file,$(EXELIST_$(SYS)),$(DSK_WRITE_BIN_recipe))
226         $(foreach file,$(OVERLAYLIST),$(DSK_WRITE_REL_recipe))
227         $(foreach file,$(EMD) $(MOU) $(TGI),$(DSK_WRITE_REL_recipe))
228
229 # --------------------------------------------------------------------------
230 # Rule to make an Atari disk with all samples. Needs the dir2atr program
231 # available at http://www.horus.com/~hias/atari/ and the MyDos4534 variant
232 # of dos.sys and dup.sys.
233
234 define ATR_WRITE_recipe
235
236 cp $(file) atr/$(notdir $(file))
237
238 endef # ATR_WRITE_recipe
239
240 samples.atr: samples
241         @mkdir atr
242         cp dos.sys atr/dos.sys
243         cp dup.sys atr/dup.sys
244         @$(foreach file,$(EXELIST_$(SYS)),$(ATR_WRITE_recipe))
245         @$(foreach file,$(OVERLAYLIST),$(ATR_WRITE_recipe))
246         @$(foreach file,$(EMD) $(MOU) $(TGI),$(ATR_WRITE_recipe))
247         $(DIR2ATR) -d -b MyDos4534 3200 $@ atr
248         @$(RMDIR) atr
249
250 # --------------------------------------------------------------------------
251 # Installation rules
252
253 INSTALL = install
254 samplesdir = $(PREFIX)/share/cc65/samples
255
256 install:
257         $(if $(PREFIX),,$(error variable `PREFIX' must be set))
258         $(INSTALL) -d $(DESTDIR)$(samplesdir)
259         $(INSTALL) -d $(DESTDIR)$(samplesdir)/geos
260         $(INSTALL) -d $(DESTDIR)$(samplesdir)/tutorial
261         $(INSTALL) -m0644 *.* $(DESTDIR)$(samplesdir)
262         $(INSTALL) -m0644 README $(DESTDIR)$(samplesdir)
263         $(INSTALL) -m0644 Makefile $(DESTDIR)$(samplesdir)
264         $(INSTALL) -m0644 geos/*.* $(DESTDIR)$(samplesdir)/geos
265         $(INSTALL) -m0644 tutorial/*.* $(DESTDIR)$(samplesdir)/tutorial
266
267 # --------------------------------------------------------------------------
268 # Packaging rules
269
270 zip:
271         @cd .. && zip -r cc65 samples/
272
273 # --------------------------------------------------------------------------
274 # Clean-up rules
275
276 mostlyclean:
277         @$(DEL) *.lbl *.map *.o *.s 2>$(NULLDEV)
278
279 clean: mostlyclean
280         @$(DEL) $(EXELIST_$(SYS)) $(DISK_$(SYS)) 2>$(NULLDEV)
281         @$(DEL) multdemo.? ovrldemo.? 2>$(NULLDEV)