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