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