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