]> git.sur5r.net Git - cc65/blob - libsrc/Makefile
99da96f1e809eca6cee7827d60e22178be56b007
[cc65] / libsrc / Makefile
1 CBMS = c128   \
2        c16    \
3        c64    \
4        cbm510 \
5        cbm610 \
6        pet    \
7        plus4  \
8        vic20
9
10 GEOS = geos-apple \
11        geos-cbm
12
13 TARGETS = apple2    \
14           apple2enh \
15           atari     \
16           atarixl   \
17           atmos     \
18           $(CBMS)   \
19           $(GEOS)   \
20           lynx      \
21           nes       \
22           sim6502   \
23           sim65c02  \
24           supervision
25
26 DRVTYPES = emd \
27            joy \
28            mou \
29            ser \
30            tgi
31
32 # Every target requires its individual vpath setting but the vpath directive
33 # acts globally. Therefore each target is built in a separate make instance.
34
35 ifeq ($(words $(MAKECMDGOALS)),1)
36   ifeq ($(MAKECMDGOALS),$(filter $(MAKECMDGOALS),$(TARGETS)))
37     TARGET = $(MAKECMDGOALS)
38   endif
39 endif
40
41 DIRLIST = $(strip $(foreach dir,$1,$(wildcard $(dir))))
42
43 ifeq ($(shell echo),)
44   MKDIR = mkdir -p $1
45   RMDIR = $(RM) -r $1
46 else
47   MKDIR = mkdir $(subst /,\,$1)
48   RMDIR = $(if $(DIRLIST),rmdir /s /q $(subst /,\,$(DIRLIST)))
49 endif
50
51 .SUFFIXES:
52
53 .PHONY: all lib $(TARGETS) mostlyclean clean install
54
55 ifndef TARGET
56
57 datadir = $(prefix)/share/cc65
58
59 INSTALLDIRS = ../asminc ../cfg ../include \
60               $(filter-out $(wildcard ../include/*.*),$(wildcard ../include/*)) \
61               ../lib ../targetutil $(addprefix ../,$(DRVTYPES))
62
63 INSTALL = install
64
65 all lib: $(TARGETS)
66
67 $(TARGETS):
68         @$(MAKE) --no-print-directory $@
69
70 mostlyclean:
71         $(call RMDIR,../wrk)
72
73 clean:
74         $(call RMDIR,../wrk ../lib ../targetutil $(addprefix ../,$(DRVTYPES)))
75
76 install:
77         $(foreach dir,$(INSTALLDIRS),$(INSTALL_recipe))
78
79 ##########
80
81 define INSTALL_recipe
82
83 $(if $(prefix),,$(error variable `prefix' must be set))
84 $(INSTALL) -d $(subst ..,$(DESTDIR)$(datadir),$(dir))
85 $(INSTALL) -m644 $(dir)/*.* $(subst ..,$(DESTDIR)$(datadir),$(dir))
86
87 endef
88
89 ##########
90
91 else # TARGET
92
93 CA65FLAGS =
94 CC65FLAGS = -Or -W error
95
96 EXTZP = cbm510 \
97         cbm610 \
98         lynx
99
100 MKINC = $(GEOS) \
101         atari   \
102         nes
103
104 TARGETUTIL = apple2 \
105              atari \
106              geos-apple
107
108 GEOSDIRS = common      \
109            conio       \
110            disk        \
111            dlgbox      \
112            file        \
113            graph       \
114            memory      \
115            menuicon    \
116            mousesprite \
117            process     \
118            runtime     \
119            system
120
121 ifeq ($(TARGET),apple2enh)
122   SRCDIR = apple2
123   OBJPFX = a2
124   DRVPFX = a2e
125 else ifeq ($(TARGET),atarixl)
126   SRCDIR = atari
127   OBJPFX = atr
128   DRVPFX = atrx
129 else ifeq ($(TARGET),sim65c02)
130   SRCDIR = sim6502
131 else
132   SRCDIR = $(TARGET)
133 endif
134
135 SRCDIRS = $(SRCDIR)
136
137 ifeq ($(TARGET),$(filter $(TARGET),$(CBMS)))
138   SRCDIRS += cbm
139 endif
140
141 ifeq ($(TARGET),$(filter $(TARGET),$(GEOS)))
142   SRCDIRS += $(addprefix $(TARGET)/,  $(GEOSDIRS))
143   SRCDIRS += $(addprefix geos-common/,$(GEOSDIRS))
144 endif
145
146 SRCDIRS += common   \
147            conio    \
148            dbg      \
149            em       \
150            joystick \
151            mouse    \
152            runtime  \
153            serial   \
154            tgi      \
155            zlib
156
157 vpath %.s $(SRCDIRS)
158 vpath %.c $(SRCDIRS)
159
160 OBJS := $(patsubst %.s,%.o,$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.s)))
161 OBJS += $(patsubst %.c,%.o,$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.c)))
162
163 OBJS := $(addprefix ../wrk/$(TARGET)/,$(sort $(notdir $(OBJS))))
164
165 DEPS = $(OBJS:.o=.d)
166
167 EXTRA_SRCPAT = $(SRCDIR)/extra/%.s
168 EXTRA_OBJPAT = ../lib/$(TARGET)-%.o
169 EXTRA_OBJS := $(patsubst $(EXTRA_SRCPAT),$(EXTRA_OBJPAT),$(wildcard $(SRCDIR)/extra/*.s))
170
171 ZPOBJ = ../wrk/$(TARGET)/zeropage.o
172 ifeq ($(TARGET),$(filter $(TARGET),$(EXTZP)))
173   ZPOBJ += ../wrk/$(TARGET)/extzp.o
174 endif
175
176 ifeq ($(SRCDIR),$(filter $(SRCDIR),$(MKINC)))
177   include $(SRCDIR)/Makefile.inc
178 endif
179
180 ifeq ($(SRCDIR),$(filter $(SRCDIR),$(TARGETUTIL)))
181   include $(SRCDIR)/targetutil/Makefile.inc
182 endif
183
184 ##########
185
186 define DRVTYPE_template
187
188 $1_SRCDIR = $$(SRCDIR)/$1
189 $1_OBJDIR = ../wrk/$$(TARGET)/$1
190 $1_DRVDIR = ../$1
191
192 $1_OBJPAT = $$($1_OBJDIR)/$$(OBJPFX)%.o
193 $1_DRVPAT = $$($1_DRVDIR)/$$(DRVPFX)%.$1
194 $1_STCPAT = ../wrk/$$(TARGET)/$$(DRVPFX)%-$1.o
195
196 $1_OBJS := $$(patsubst $$($1_SRCDIR)/%.s,$$($1_OBJDIR)/%.o,$$(wildcard $$($1_SRCDIR)/*.s))
197
198 $1_DRVS = $$(patsubst $$($1_OBJPAT),$$($1_DRVPAT),$$($1_OBJS))
199
200 $1_STCS = $$(patsubst $$($1_DRVPAT),$$($1_STCPAT),$$($1_DRVS))
201
202 $$($1_OBJS): | $$($1_OBJDIR)
203
204 $$($1_DRVPAT): $$($1_OBJPAT) $$(ZPOBJ) | $$($1_DRVDIR)
205         @echo $$(TARGET) - $$(<F)
206         @$$(LD65) -o $$@ -t module $$^
207
208 $$($1_OBJDIR) $$($1_DRVDIR):
209         @$$(call MKDIR,$$@)
210
211 $(TARGET): $$($1_DRVS)
212
213 $$($1_STCPAT): $$($1_DRVPAT)
214         @echo $$(TARGET) - $$(<F)
215         @$$(CO65) -o $$(@:.o=.s) --code-label _$$(subst -,_,$$(subst .,_,$$(<F))) $$<
216         @$$(CA65) -t $$(TARGET) -o $$@ $$(@:.o=.s)
217
218 OBJS += $$($1_STCS)
219
220 DEPS += $$($1_OBJS:.o=.d)
221
222 endef
223
224 ##########
225
226 $(foreach drvtype,$(DRVTYPES),$(eval $(call DRVTYPE_template,$(drvtype))))
227
228 AR65 := $(if $(wildcard ../bin/ar65*),../bin/ar65,ar65)
229 CA65 := $(if $(wildcard ../bin/ca65*),../bin/ca65,ca65)
230 CC65 := $(if $(wildcard ../bin/cc65*),../bin/cc65,cc65)
231 CO65 := $(if $(wildcard ../bin/co65*),../bin/co65,co65)
232 LD65 := $(if $(wildcard ../bin/ld65*),../bin/ld65,ld65)
233
234 export CC65_HOME := $(abspath ..)
235
236 ##########
237
238 define ASSEMBLE_recipe
239
240 $(if $(TRAVIS),,@echo $(TARGET) - $<)
241 @$(CA65) -t $(TARGET) $(CA65FLAGS) --create-dep $(@:.o=.d) -o $@ $<
242
243 endef
244
245 ##########
246
247 define COMPILE_recipe
248
249 $(if $(TRAVIS),,@echo $(TARGET) - $<)
250 @$(CC65) -t $(TARGET) $(CC65FLAGS) --create-dep $(@:.o=.d) --dep-target $@ -o $(@:.o=.s) $<
251 @$(CA65) -t $(TARGET) -o $@ $(@:.o=.s)
252
253 endef
254
255 ##########
256
257 ../wrk/$(TARGET)/%.o: %.s | ../wrk/$(TARGET)
258         $(ASSEMBLE_recipe)
259
260 ../wrk/$(TARGET)/%.o: %.c | ../wrk/$(TARGET)
261         $(COMPILE_recipe)
262
263 $(EXTRA_OBJPAT): $(EXTRA_SRCPAT) | ../lib
264         @echo $(TARGET) - $(<F)
265         @$(CA65) -t $(TARGET) $(CA65FLAGS) -o $@ $<
266
267 ../lib/$(TARGET).lib: $(OBJS) | ../lib
268         $(AR65) a $@ $?
269
270 ../wrk/$(TARGET) ../lib ../targetutil:
271         @$(call MKDIR,$@)
272
273 $(TARGET): $(EXTRA_OBJS) ../lib/$(TARGET).lib
274
275 -include $(DEPS)
276
277 endif # TARGET