]> git.sur5r.net Git - cc65/blob - samples/Makefile
Improved Makefile by Greg King.
[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/mou/$(SYS)*.mou
16 TGI  = /usr/lib/cc65/tgi/$(SYS)*.tgi
17 ifneq "$(wildcard /usr/local/lib/cc65)" ""
18 MOUS = /usr/local/lib/cc65/mou/$(SYS)*.mou
19 TGI  = /usr/local/lib/cc65/tgi/$(SYS)*.tgi
20 endif
21 ifdef CC65_HOME
22 MOUS = $(CC65_HOME)/mou/$(SYS)*.mou
23 TGI  = $(CC65_HOME)/tgi/$(SYS)*.tgi
24 endif
25 CLIB = --lib $(SYS).lib
26 CL   = cl65
27 CC   = cc65
28 AS   = ca65
29 LD   = ld65
30
31 else
32 # "samples/" is a part of a complete source tree.
33 CA65_INC = ../asminc
34 CC65_INC = ../include
35 LD65_CFG = ../src/ld65/cfg
36 LD65_LIB = ../libsrc
37 LD65_OBJ = ../libsrc
38 MOUS = ../libsrc/$(SYS)*.mou
39 TGI  = ../libsrc/$(SYS)*.tgi
40 CLIB = ../libsrc/$(SYS).lib
41 CL   = ../src/cl65/cl65
42 CC   = ../src/cc65/cc65
43 AS   = ../src/ca65/ca65
44 LD   = ../src/ld65/ld65
45
46 MY_INC = --forget-inc-paths -I . -I $(CC65_INC)
47 MY_ASM = --forget-inc-paths -I . -I $(CA65_INC)
48 endif
49
50 # This one comes with VICE
51 C1541   = c1541
52
53
54 # --------------------------------------------------------------------------
55 # Generic rules
56
57 .c.o:
58         @echo $<
59         @$(CC) $(MY_INC) -Oirs --codesize 500 -T -g -t $(SYS) $<
60         @$(AS) $(basename $<).s
61
62 .s.o:
63         @echo $<
64         @$(AS) $(MY_ASM) -t $(SYS) $<
65
66 .o:
67         @$(LD) -t $(SYS) -m $(basename $@).map -o $@ $^ $(CLIB)
68
69
70 # --------------------------------------------------------------------------
71 # List of executables. This list could be made target dependent by checking
72 # $(SYS).
73
74 EXELIST =       ascii           \
75                 diodemo         \
76                 fire            \
77                 gunzip65        \
78                 hello           \
79                 mandelbrot      \
80                 mousedemo       \
81                 nachtm          \
82                 plasma          \
83                 sieve           \
84                 tgidemo
85
86 # --------------------------------------------------------------------------
87 # Rules how to make each one of the binaries
88
89 .PHONY: all
90 all:    $(EXELIST)
91
92 ascii:          ascii.o
93
94 diodemo:        diodemo.o
95
96 fire:           fire.o
97
98 gunzip65:       gunzip65.o
99
100 hello:          hello.o
101
102 # The Apple machines need the start address adjusted for the mandelbrot demo
103 ifeq "$(SYS)" "apple2"
104 mandelbrot:     mandelbrot.o
105         @$(LD) -t $(SYS) -m $(basename $@).map --start-addr 0x4000 -o $@ $^ $(CLIB)
106 else
107 ifeq "$(SYS)" "apple2enh"
108 mandelbrot:     mandelbrot.o
109         @$(LD) -t $(SYS) -m $(basename $@).map --start-addr 0x4000 -o $@ $^ $(CLIB)
110 else
111 mandelbrot:     mandelbrot.o
112 endif
113 endif
114
115 # The Apple ][ needs the start address adjusted for the mousedemo
116 ifeq "$(SYS)" "apple2"
117 mousedemo:      mousedemo.o
118         @$(LD) -t $(SYS) -m $(basename $@).map --start-addr 0x4000 -o $@ $^ $(CLIB)
119 else
120 mousedemo:      mousedemo.o
121 endif
122
123 nachtm:         nachtm.o
124
125 plasma:         plasma.o
126
127 sieve:          sieve.o
128
129 # The Apple machines need the start address adjusted for the tgidemo
130 ifeq "$(SYS)" "apple2"
131 tgidemo:        tgidemo.o
132         @$(LD) -t $(SYS) -m $(basename $@).map --start-addr 0x4000 -o $@ $^ $(CLIB)
133 else
134 ifeq "$(SYS)" "apple2enh"
135 tgidemo:        tgidemo.o
136         @$(LD) -t $(SYS) -m $(basename $@).map --start-addr 0x4000 -o $@ $^ $(CLIB)
137 else
138 tgidemo:        tgidemo.o
139 endif
140 endif
141
142 # --------------------------------------------------------------------------
143 # Rule to make a disk with all samples. Needs the c1541 program that comes
144 # with the VICE emulator.
145
146 .PHONY: disk
147 disk:   samples.d64
148
149 samples.d64:    all
150         @$(C1541) -format samples,AA  d64 $@ > /dev/null
151         @for exe in $(EXELIST); do\
152             $(C1541) -attach $@ -write $$exe > /dev/null || exit $$?;\
153         done
154         @for mod in $(TGI) $(MOUS); do\
155             $(C1541) -attach $@ -write $$mod > /dev/null || exit $$?;\
156         done
157
158 # --------------------------------------------------------------------------
159 # Cleanup rules
160
161 .PHONY: clean
162 clean:
163         $(RM) *~ *.map *.o *.s *.lbl
164
165 .PHONY: zap
166 zap:    clean
167         $(RM) $(EXELIST) samples.d64
168
169