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