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