]> git.sur5r.net Git - cc65/blob - libsrc/Makefile
Changed Makefile.inc handling.
[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         atarixl \
103         nes
104
105 TARGETUTIL = apple2    \
106              apple2enh \
107              atari     \
108              geos-apple
109
110 GEOSDIRS = common      \
111            conio       \
112            disk        \
113            dlgbox      \
114            file        \
115            graph       \
116            memory      \
117            menuicon    \
118            mousesprite \
119            process     \
120            runtime     \
121            system
122
123 ifeq ($(TARGET),apple2enh)
124   SRCDIR = apple2
125   OBJPFX = a2
126   DRVPFX = a2e
127 else ifeq ($(TARGET),atarixl)
128   SRCDIR = atari
129   OBJPFX = atr
130   DRVPFX = atrx
131 else ifeq ($(TARGET),sim65c02)
132   SRCDIR = sim6502
133 else
134   SRCDIR = $(TARGET)
135 endif
136
137 SRCDIRS = $(SRCDIR)
138
139 ifeq ($(TARGET),$(filter $(TARGET),$(CBMS)))
140   SRCDIRS += cbm
141 endif
142
143 ifeq ($(TARGET),$(filter $(TARGET),$(GEOS)))
144   SRCDIRS += $(addprefix $(TARGET)/,  $(GEOSDIRS))
145   SRCDIRS += $(addprefix geos-common/,$(GEOSDIRS))
146 endif
147
148 SRCDIRS += common   \
149            conio    \
150            dbg      \
151            em       \
152            joystick \
153            mouse    \
154            runtime  \
155            serial   \
156            tgi      \
157            zlib
158
159 vpath %.s $(SRCDIRS)
160 vpath %.c $(SRCDIRS)
161
162 OBJS := $(patsubst %.s,%.o,$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.s)))
163 OBJS += $(patsubst %.c,%.o,$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.c)))
164
165 OBJS := $(addprefix ../wrk/$(TARGET)/,$(sort $(notdir $(OBJS))))
166
167 DEPS = $(OBJS:.o=.d)
168
169 EXTRA_SRCPAT = $(SRCDIR)/extra/%.s
170 EXTRA_OBJPAT = ../lib/$(TARGET)-%.o
171 EXTRA_OBJS := $(patsubst $(EXTRA_SRCPAT),$(EXTRA_OBJPAT),$(wildcard $(SRCDIR)/extra/*.s))
172
173 ZPOBJ = ../wrk/$(TARGET)/zeropage.o
174 ifeq ($(TARGET),$(filter $(TARGET),$(EXTZP)))
175   ZPOBJ += ../wrk/$(TARGET)/extzp.o
176 endif
177
178 ifeq ($(TARGET),$(filter $(TARGET),$(MKINC)))
179   include $(SRCDIR)/Makefile.inc
180 endif
181
182 ifeq ($(TARGET),$(filter $(TARGET),$(TARGETUTIL)))
183   include $(SRCDIR)/targetutil/Makefile.inc
184 endif
185
186 ##########
187
188 define DRVTYPE_template
189
190 $1_SRCDIR = $$(SRCDIR)/$1
191 $1_OBJDIR = ../wrk/$$(TARGET)/$1
192 $1_DRVDIR = ../$1
193
194 $1_OBJPAT = $$($1_OBJDIR)/$$(OBJPFX)%.o
195 $1_DRVPAT = $$($1_DRVDIR)/$$(DRVPFX)%.$1
196 $1_STCPAT = ../wrk/$$(TARGET)/$$(DRVPFX)%-$1.o
197
198 $1_OBJS := $$(patsubst $$($1_SRCDIR)/%.s,$$($1_OBJDIR)/%.o,$$(wildcard $$($1_SRCDIR)/*.s))
199
200 $1_DRVS = $$(patsubst $$($1_OBJPAT),$$($1_DRVPAT),$$($1_OBJS))
201
202 $1_STCS = $$(patsubst $$($1_DRVPAT),$$($1_STCPAT),$$($1_DRVS))
203
204 $$($1_OBJS): | $$($1_OBJDIR)
205
206 $$($1_DRVPAT): $$($1_OBJPAT) $$(ZPOBJ) | $$($1_DRVDIR)
207         @echo $$(TARGET) - $$(<F)
208         @$$(LD65) -o $$@ -t module $$^
209
210 $$($1_OBJDIR) $$($1_DRVDIR):
211         @$$(call MKDIR,$$@)
212
213 $(TARGET): $$($1_DRVS)
214
215 $$($1_STCPAT): $$($1_DRVPAT)
216         @echo $$(TARGET) - $$(<F)
217         @$$(CO65) -o $$(@:.o=.s) --code-label _$$(subst -,_,$$(subst .,_,$$(<F))) $$<
218         @$$(CA65) -t $$(TARGET) -o $$@ $$(@:.o=.s)
219
220 OBJS += $$($1_STCS)
221
222 DEPS += $$($1_OBJS:.o=.d)
223
224 endef
225
226 ##########
227
228 $(foreach drvtype,$(DRVTYPES),$(eval $(call DRVTYPE_template,$(drvtype))))
229
230 AR65 := $(if $(wildcard ../bin/ar65*),../bin/ar65,ar65)
231 CA65 := $(if $(wildcard ../bin/ca65*),../bin/ca65,ca65)
232 CC65 := $(if $(wildcard ../bin/cc65*),../bin/cc65,cc65)
233 CO65 := $(if $(wildcard ../bin/co65*),../bin/co65,co65)
234 LD65 := $(if $(wildcard ../bin/ld65*),../bin/ld65,ld65)
235
236 export CC65_HOME := $(abspath ..)
237
238 ##########
239
240 define ASSEMBLE_recipe
241
242 $(if $(TRAVIS),,@echo $(TARGET) - $<)
243 @$(CA65) -t $(TARGET) $(CA65FLAGS) --create-dep $(@:.o=.d) -o $@ $<
244
245 endef
246
247 ##########
248
249 define COMPILE_recipe
250
251 $(if $(TRAVIS),,@echo $(TARGET) - $<)
252 @$(CC65) -t $(TARGET) $(CC65FLAGS) --create-dep $(@:.o=.d) --dep-target $@ -o $(@:.o=.s) $<
253 @$(CA65) -t $(TARGET) -o $@ $(@:.o=.s)
254
255 endef
256
257 ##########
258
259 ../wrk/$(TARGET)/%.o: %.s | ../wrk/$(TARGET)
260         $(ASSEMBLE_recipe)
261
262 ../wrk/$(TARGET)/%.o: %.c | ../wrk/$(TARGET)
263         $(COMPILE_recipe)
264
265 $(EXTRA_OBJPAT): $(EXTRA_SRCPAT) | ../lib
266         @echo $(TARGET) - $(<F)
267         @$(CA65) -t $(TARGET) $(CA65FLAGS) -o $@ $<
268
269 ../lib/$(TARGET).lib: $(OBJS) | ../lib
270         $(AR65) a $@ $?
271
272 ../wrk/$(TARGET) ../lib ../targetutil:
273         @$(call MKDIR,$@)
274
275 $(TARGET): $(EXTRA_OBJS) ../lib/$(TARGET).lib
276
277 -include $(DEPS)
278
279 endif # TARGET