]> git.sur5r.net Git - cc65/blob - samples/Makefile
samples zip and install targets moved into samples/Makefile as agreed
[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 # Determine the path to the executables and libraries. If the samples
11 # directory is part of a complete source tree, use the stuff from that
12 # source tree; otherwise, use the "install" directories.
13 ifeq "$(wildcard ../src)" ""
14 # No source tree
15 installdir = /usr/lib/cc65
16 ifneq "$(wildcard /usr/local/lib/cc65)" ""
17 installdir = /usr/local/lib/cc65
18 endif
19 ifneq "$(wildcard /opt/local/share/cc65)" ""
20 installdir = /opt/local/share/cc65
21 endif
22 ifdef CC65_HOME
23 installdir = $(CC65_HOME)
24 endif
25
26 MOUS = $(installdir)/target/$(SYS)/drv/mou/$(SYS)*.mou
27 TGI  = $(installdir)/target/$(SYS)/drv/tgi/$(SYS)*.tgi
28 CLIB = --lib $(SYS).lib
29 CL   = cl65
30 CC   = cc65
31 AS   = ca65
32 LD   = ld65
33
34 else
35 # "samples/" is a part of a complete source tree.
36 export CC65_HOME := $(abspath ..)
37 MOUS = ../target/$(SYS)/drv/mou/$(SYS)*.mou
38 TGI  = ../target/$(SYS)/drv/tgi/$(SYS)*.tgi
39 CLIB = ../lib/$(SYS).lib
40 CL   = ../bin/cl65
41 CC   = ../bin/cc65
42 AS   = ../bin/ca65
43 LD   = ../bin/ld65
44 endif
45
46 # This one comes with VICE
47 C1541   = c1541
48
49 # --------------------------------------------------------------------------
50 # System-dependent settings
51
52 # The Apple machines need the start address adjusted when using TGI
53 LDFLAGS_mandelbrot_apple2 = --start-addr 0x4000
54 LDFLAGS_tgidemo_apple2 = --start-addr 0x4000
55 LDFLAGS_mandelbrot_apple2enh = --start-addr 0x4000
56 LDFLAGS_tgidemo_apple2enh = --start-addr 0x4000
57
58 # The Apple ][ needs the start address adjusted for the mousetest
59 LDFLAGS_mousetest_apple2 = --start-addr 0x4000
60
61 # The atarixl target needs the start address adjusted when using TGI
62 LDFLAGS_mandelbrot_atarixl = --start-addr 0x4000
63 LDFLAGS_tgidemo_atarixl = --start-addr 0x4000
64
65 # The atari target needs to reserve some memory when using TGI
66 LDFLAGS_mandelbrot_atari = -D __RESERVED_MEMORY__=0x2000
67 LDFLAGS_tgidemo_atari = -D __RESERVED_MEMORY__=0x2000
68
69 # --------------------------------------------------------------------------
70 # Generic rules
71
72 %: %.c
73 %: %.s
74
75 .c.o:
76         @echo $<
77         @$(CC) $(CFLAGS) -Oirs --codesize 500 -T -g -t $(SYS) $<
78         @$(AS) $(<:.c=.s)
79
80 .s.o:
81         @echo $<
82         @$(AS) $(AFLAGS) -t $(SYS) $<
83
84 .PRECIOUS: %.o
85
86 .o:
87         @$(LD) $(LDFLAGS_$(@F)_$(SYS)) -o $@ -t $(SYS) -m $@.map $^ $(CLIB)
88
89 # --------------------------------------------------------------------------
90 # List of executables. This list could be made target-dependent by checking
91 # $(SYS).
92
93 EXELIST =       ascii           \
94                 diodemo         \
95                 enumdevdir      \
96                 fire            \
97                 gunzip65        \
98                 hello           \
99                 mandelbrot      \
100                 mousetest       \
101                 multdemo        \
102                 nachtm          \
103                 ovrldemo        \
104                 plasma          \
105                 sieve           \
106                 tgidemo
107
108 # --------------------------------------------------------------------------
109 # Rules to make the binaries
110
111 .PHONY: all samples
112 all:
113
114 samples:
115         $(EXELIST)
116
117 # --------------------------------------------------------------------------
118 # Overlay rules. Overlays need special ld65 configuration files.  Also, the
119 # overlay file-names are shortenned to fit the Atari's 8.3-character limit.
120
121 multdemo:       multidemo.o
122         @$(LD) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(CLIB)
123
124 ovrldemo:       overlaydemo.o
125         @$(LD) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(CLIB)
126
127 # --------------------------------------------------------------------------
128 # Rule to make a CBM disk with all samples. Needs the c1541 program that comes
129 # with the VICE emulator.
130
131 .PHONY: disk
132 disk:   samples.d64
133
134 samples.d64:    all
135         @$(C1541) -format samples,AA  d64 $@ > /dev/null
136         @for exe in $(EXELIST); do\
137             $(C1541) -attach $@ -write $$exe > /dev/null || exit $$?;\
138         done
139         @for mod in $(TGI) $(MOUS); do\
140             $(C1541) -attach $@ -write $$mod > /dev/null || exit $$?;\
141         done
142
143 # --------------------------------------------------------------------------
144 # Installation rules
145
146 INSTALL = install
147 samplesdir = $(prefix)/share/cc65
148 .PHONY: install
149 install:
150         $(if $(prefix),,$(error variable `prefix' must be set))
151         $(INSTALL) -d $(DESTDIR)$(samplesdir)
152         $(INSTALL) -d $(DESTDIR)$(samplesdir)/geos
153         $(INSTALL) -d $$(DESTDIR)$(samplesdir)/tutorial
154         $(INSTALL) -m0644 *.* $(DESTDIR)$(samplesdir)
155         $(INSTALL) -m0644 README $(DESTDIR)$(samplesdir)
156         $(INSTALL) -m0644 Makefile $(DESTDIR)$(samplesdir)
157         $(INSTALL) -m0644 geos/*.* $(DESTDIR)$(samplesdir)/geos
158         $(INSTALL) -m0644 tutorial/*.* $(DESTDIR)$(samplesdir)/tutorial
159
160 # --------------------------------------------------------------------------
161 # Packaging rules
162
163 .PHONY: zip
164 zip:
165         @cd .. && zip -r cc65 samples/
166
167 # --------------------------------------------------------------------------
168 # Clean-up rules
169
170 .PHONY: mostlyclean
171 mostlyclean:
172
173 .PHONY: clean
174 clean:
175         $(RM) *~ *.map *.o *.s *.lbl
176
177 .PHONY: zap
178 zap:    clean
179         $(RM) $(EXELIST) samples.d64
180         $(RM) multdemo.? ovrldemo.?