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