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