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