]> git.sur5r.net Git - cc65/blob - samples/Makefile
Removed shell for-loop.
[cc65] / samples / Makefile
1 #
2 # Makefile for cc65 samples
3 #
4 # This Makefile requires GNU make
5 #
6
7 # Enter the target system here
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 else
18   NULLDEV = /dev/null
19   DEL = $(RM)
20 endif
21
22 # Determine the path to the executables and libraries. If the samples
23 # directory is part of a complete source tree, use the stuff from that
24 # source tree; otherwise, use the "install" directories.
25 ifeq "$(wildcard ../src)" ""
26 # No source tree
27 installdir = /usr/lib/cc65
28 ifneq "$(wildcard /usr/local/lib/cc65)" ""
29 installdir = /usr/local/lib/cc65
30 endif
31 ifneq "$(wildcard /opt/local/share/cc65)" ""
32 installdir = /opt/local/share/cc65
33 endif
34 ifdef CC65_HOME
35 installdir = $(CC65_HOME)
36 endif
37
38 MOUS := $(wildcard $(installdir)/target/$(SYS)/drv/mou/$(SYS)*.mou)
39 TGI  := $(wildcard $(installdir)/target/$(SYS)/drv/tgi/$(SYS)*.tgi)
40 CLIB = --lib $(SYS).lib
41 CL   = cl65
42 CC   = cc65
43 AS   = ca65
44 LD   = ld65
45
46 else
47 # "samples/" is a part of a complete source tree.
48 export CC65_HOME := $(abspath ..)
49 MOUS := $(wildcard ../target/$(SYS)/drv/mou/$(SYS)*.mou)
50 TGI  := $(wildcard ../target/$(SYS)/drv/tgi/$(SYS)*.tgi)
51 CLIB = ../lib/$(SYS).lib
52 CL   = ../bin/cl65
53 CC   = ../bin/cc65
54 AS   = ../bin/ca65
55 LD   = ../bin/ld65
56 endif
57
58 # This one comes with VICE
59 C1541 = c1541
60
61 # --------------------------------------------------------------------------
62 # System-dependent settings
63
64 # The Apple machines need the start address adjusted when using TGI
65 LDFLAGS_mandelbrot_apple2 = --start-addr 0x4000
66 LDFLAGS_tgidemo_apple2 = --start-addr 0x4000
67 LDFLAGS_mandelbrot_apple2enh = --start-addr 0x4000
68 LDFLAGS_tgidemo_apple2enh = --start-addr 0x4000
69
70 # The Apple ][ needs the start address adjusted for the mousetest
71 LDFLAGS_mousetest_apple2 = --start-addr 0x4000
72
73 # The atarixl target needs the start address adjusted when using TGI
74 LDFLAGS_mandelbrot_atarixl = --start-addr 0x4000
75 LDFLAGS_tgidemo_atarixl = --start-addr 0x4000
76
77 # The atari target needs to reserve some memory when using TGI
78 LDFLAGS_mandelbrot_atari = -D __RESERVED_MEMORY__=0x2000
79 LDFLAGS_tgidemo_atari = -D __RESERVED_MEMORY__=0x2000
80
81 # --------------------------------------------------------------------------
82 # Generic rules
83
84 .PHONY: all mostlyclean clean install zip samples d64
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 $^ $(CLIB)
100
101 # --------------------------------------------------------------------------
102 # List of executables. This list could be made target-dependent by checking
103 # $(SYS).
104
105 EXELIST = ascii      \
106           diodemo    \
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 # --------------------------------------------------------------------------
121 # Rules to make the binaries
122
123 all:
124
125 samples: $(EXELIST)
126
127 # --------------------------------------------------------------------------
128 # Overlay rules. Overlays need special ld65 configuration files.  Also, the
129 # overlay file-names are shortenned to fit the Atari's 8.3-character limit.
130
131 multdemo: multidemo.o
132         $(LD) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(CLIB)
133
134 ovrldemo: overlaydemo.o
135         $(LD) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(CLIB)
136
137 # --------------------------------------------------------------------------
138 # Rule to make a CBM disk with all samples. Needs the c1541 program that comes
139 # with the VICE emulator.
140
141 d64: samples.d64
142
143 define D64_WRITE_recipe
144
145 $(C1541) -attach $@ -write $(file) $(notdir $(file)) >$(NULLDEV)
146
147 endef # D64_WRITE_recipe
148
149 samples.d64: samples
150         @$(C1541) -format samples,AA  d64 $@ >$(NULLDEV)
151         $(foreach file,$(EXELIST),$(D64_WRITE_recipe))
152         $(foreach file,$(TGI) $(MOUS),$(D64_WRITE_recipe))
153
154 # --------------------------------------------------------------------------
155 # Installation rules
156
157 INSTALL = install
158 samplesdir = $(prefix)/share/cc65
159
160 install:
161         $(if $(prefix),,$(error variable `prefix' must be set))
162         $(INSTALL) -d $(DESTDIR)$(samplesdir)
163         $(INSTALL) -d $(DESTDIR)$(samplesdir)/geos
164         $(INSTALL) -d $$(DESTDIR)$(samplesdir)/tutorial
165         $(INSTALL) -m0644 *.* $(DESTDIR)$(samplesdir)
166         $(INSTALL) -m0644 README $(DESTDIR)$(samplesdir)
167         $(INSTALL) -m0644 Makefile $(DESTDIR)$(samplesdir)
168         $(INSTALL) -m0644 geos/*.* $(DESTDIR)$(samplesdir)/geos
169         $(INSTALL) -m0644 tutorial/*.* $(DESTDIR)$(samplesdir)/tutorial
170
171 # --------------------------------------------------------------------------
172 # Packaging rules
173
174 zip:
175         @cd .. && zip -r cc65 samples/
176
177 # --------------------------------------------------------------------------
178 # Clean-up rules
179
180 mostlyclean:
181         @$(DEL) *.map *.o *.s 2>$(NULLDEV)
182
183 clean: mostlyclean
184         @$(DEL) $(EXELIST) samples.d64 2>$(NULLDEV)
185         @$(DEL) multdemo.? ovrldemo.? 2>$(NULLDEV)