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 $@
74 $(call RMDIR,../wrk ../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 = -Osir -W error
104 TARGETUTIL = apple2 \
120 ifeq ($(TARGET),apple2enh)
124 else ifeq ($(TARGET),atarixl)
128 else ifeq ($(TARGET),sim65c02)
136 ifeq ($(TARGET),$(filter $(TARGET),$(CBMS)))
140 ifeq ($(TARGET),$(filter $(TARGET),$(GEOS)))
141 SRCDIRS += $(addprefix $(TARGET)/, $(GEOSDIRS))
142 SRCDIRS += $(addprefix geos-common/,$(GEOSDIRS))
159 OBJS := $(patsubst %.s,%.o,$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.s)))
160 OBJS += $(patsubst %.c,%.o,$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.c)))
162 OBJS := $(addprefix ../wrk/$(TARGET)/,$(sort $(notdir $(OBJS))))
166 EXTRA_SRCPAT = $(SRCDIR)/extra/%.s
167 EXTRA_OBJPAT = ../lib/$(TARGET)-%.o
168 EXTRA_OBJS := $(patsubst $(EXTRA_SRCPAT),$(EXTRA_OBJPAT),$(wildcard $(SRCDIR)/extra/*.s))
170 ZPOBJ = ../wrk/$(TARGET)/zeropage.o
171 ifeq ($(TARGET),$(filter $(TARGET),$(EXTZP)))
172 ZPOBJ += ../wrk/$(TARGET)/extzp.o
175 ifeq ($(SRCDIR),$(filter $(SRCDIR),$(MKINC)))
176 include $(SRCDIR)/Makefile.inc
179 ifeq ($(SRCDIR),$(filter $(SRCDIR),$(TARGETUTIL)))
180 include $(SRCDIR)/targetutil/Makefile.inc
185 define DRVTYPE_template
187 $1_SRCDIR = $$(SRCDIR)/$1
188 $1_OBJDIR = ../wrk/$$(TARGET)/$1
191 $1_OBJPAT = $$($1_OBJDIR)/$$(OBJPFX)%.o
192 $1_DRVPAT = $$($1_DRVDIR)/$$(DRVPFX)%.$1
193 $1_STCPAT = ../wrk/$$(TARGET)/$$(DRVPFX)%-$1.o
195 $1_OBJS := $$(patsubst $$($1_SRCDIR)/%.s,$$($1_OBJDIR)/%.o,$$(wildcard $$($1_SRCDIR)/*.s))
197 $1_DRVS = $$(patsubst $$($1_OBJPAT),$$($1_DRVPAT),$$($1_OBJS))
199 $1_STCS = $$(patsubst $$($1_DRVPAT),$$($1_STCPAT),$$($1_DRVS))
201 $$($1_OBJS): | $$($1_OBJDIR)
203 $$($1_DRVPAT): $$($1_OBJPAT) $$(ZPOBJ) | $$($1_DRVDIR)
204 @echo $$(TARGET) - $$(<F)
205 @$$(LD65) -o $$@ -t module $$^
207 $$($1_OBJDIR) $$($1_DRVDIR):
210 $(TARGET): $$($1_DRVS)
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)
219 DEPS += $$($1_OBJS:.o=.d)
225 $(foreach drvtype,$(DRVTYPES),$(eval $(call DRVTYPE_template,$(drvtype))))
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)
233 export CC65_HOME := $(abspath ..)
237 define ASSEMBLE_recipe
239 $(if $(TRAVIS),,@echo $(TARGET) - $<)
240 @$(CA65) -t $(TARGET) $(CA65FLAGS) --create-dep $(@:.o=.d) -o $@ $<
246 define COMPILE_recipe
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)
256 ../wrk/$(TARGET)/%.o: %.s | ../wrk/$(TARGET)
259 ../wrk/$(TARGET)/%.o: %.c | ../wrk/$(TARGET)
262 $(EXTRA_OBJPAT): $(EXTRA_SRCPAT) | ../lib
263 @echo $(TARGET) - $(<F)
264 @$(CA65) -t $(TARGET) $(CA65FLAGS) -o $@ $<
266 ../lib/$(TARGET).lib: $(OBJS) | ../lib
269 ../wrk/$(TARGET) ../lib ../targetutil:
272 $(TARGET): $(EXTRA_OBJS) ../lib/$(TARGET).lib