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