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.
35 ifeq ($(words $(MAKECMDGOALS)),1)
36 ifeq ($(MAKECMDGOALS),$(filter $(MAKECMDGOALS),$(TARGETS)))
37 TARGET = $(MAKECMDGOALS)
41 DIRLIST = $(strip $(foreach dir,$1,$(wildcard $(dir))))
47 MKDIR = mkdir $(subst /,\,$1)
48 RMDIR = $(if $(DIRLIST),rmdir /s /q $(subst /,\,$(DIRLIST)))
53 .PHONY: all lib $(TARGETS) mostlyclean clean install
57 datadir = $(prefix)/share/cc65
59 INSTALLDIRS = ../asminc ../cfg ../include \
60 $(filter-out $(wildcard ../include/*.*),$(wildcard ../include/*)) \
61 ../lib ../targetutil $(addprefix ../,$(DRVTYPES))
68 @$(MAKE) --no-print-directory $@
71 $(call RMDIR,../libwrk)
74 $(call RMDIR,../libwrk ../lib ../targetutil $(addprefix ../,$(DRVTYPES)))
77 $(foreach dir,$(INSTALLDIRS),$(INSTALL_recipe))
83 $(if $(prefix),,$(error variable `prefix' must be set))
84 $(INSTALL) -d $(subst ..,$(DESTDIR)$(datadir),$(dir))
85 $(INSTALL) -m644 $(dir)/*.* $(subst ..,$(DESTDIR)$(datadir),$(dir))
94 CC65FLAGS = -Or -W error
105 TARGETUTIL = apple2 \
123 ifeq ($(TARGET),apple2enh)
127 else ifeq ($(TARGET),atarixl)
131 else ifeq ($(TARGET),sim65c02)
139 ifeq ($(TARGET),$(filter $(TARGET),$(CBMS)))
143 ifeq ($(TARGET),$(filter $(TARGET),$(GEOS)))
144 SRCDIRS += $(addprefix $(TARGET)/, $(GEOSDIRS))
145 SRCDIRS += $(addprefix geos-common/,$(GEOSDIRS))
162 OBJS := $(patsubst %.s,%.o,$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.s)))
163 OBJS += $(patsubst %.c,%.o,$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.c)))
165 OBJS := $(addprefix ../libwrk/$(TARGET)/,$(sort $(notdir $(OBJS))))
169 EXTRA_SRCPAT = $(SRCDIR)/extra/%.s
170 EXTRA_OBJPAT = ../lib/$(TARGET)-%.o
171 EXTRA_OBJS := $(patsubst $(EXTRA_SRCPAT),$(EXTRA_OBJPAT),$(wildcard $(SRCDIR)/extra/*.s))
173 ZPOBJ = ../libwrk/$(TARGET)/zeropage.o
174 ifeq ($(TARGET),$(filter $(TARGET),$(EXTZP)))
175 ZPOBJ += ../libwrk/$(TARGET)/extzp.o
178 ifeq ($(TARGET),$(filter $(TARGET),$(MKINC)))
179 include $(SRCDIR)/Makefile.inc
182 ifeq ($(TARGET),$(filter $(TARGET),$(TARGETUTIL)))
183 include $(SRCDIR)/targetutil/Makefile.inc
188 define DRVTYPE_template
190 $1_SRCDIR = $$(SRCDIR)/$1
191 $1_OBJDIR = ../libwrk/$$(TARGET)/$1
194 $1_OBJPAT = $$($1_OBJDIR)/$$(OBJPFX)%.o
195 $1_DRVPAT = $$($1_DRVDIR)/$$(DRVPFX)%.$1
196 $1_STCPAT = ../libwrk/$$(TARGET)/$$(DRVPFX)%-$1.o
198 $1_OBJS := $$(patsubst $$($1_SRCDIR)/%.s,$$($1_OBJDIR)/%.o,$$(wildcard $$($1_SRCDIR)/*.s))
200 $1_DRVS = $$(patsubst $$($1_OBJPAT),$$($1_DRVPAT),$$($1_OBJS))
202 $1_STCS = $$(patsubst $$($1_DRVPAT),$$($1_STCPAT),$$($1_DRVS))
204 $$($1_OBJS): | $$($1_OBJDIR)
206 $$($1_DRVPAT): $$($1_OBJPAT) $$(ZPOBJ) | $$($1_DRVDIR)
207 @echo $$(TARGET) - $$(<F)
208 @$$(LD65) -o $$@ -t module $$^
210 $$($1_OBJDIR) $$($1_DRVDIR):
213 $(TARGET): $$($1_DRVS)
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)
222 DEPS += $$($1_OBJS:.o=.d)
228 $(foreach drvtype,$(DRVTYPES),$(eval $(call DRVTYPE_template,$(drvtype))))
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)
236 export CC65_HOME := $(abspath ..)
240 define ASSEMBLE_recipe
242 $(if $(TRAVIS),,@echo $(TARGET) - $<)
243 @$(CA65) -t $(TARGET) $(CA65FLAGS) --create-dep $(@:.o=.d) -o $@ $<
249 define COMPILE_recipe
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)
259 ../libwrk/$(TARGET)/%.o: %.s | ../libwrk/$(TARGET)
262 ../libwrk/$(TARGET)/%.o: %.c | ../libwrk/$(TARGET)
265 $(EXTRA_OBJPAT): $(EXTRA_SRCPAT) | ../lib
266 @echo $(TARGET) - $(<F)
267 @$(CA65) -t $(TARGET) $(CA65FLAGS) -o $@ $<
269 ../lib/$(TARGET).lib: $(OBJS) | ../lib
272 ../libwrk/$(TARGET) ../lib ../targetutil:
275 $(TARGET): $(EXTRA_OBJS) ../lib/$(TARGET).lib