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