33 # Every target requires its individual vpath setting but the vpath directive
34 # acts globally. Therefore each target is built in a separate make instance.
36 ifeq ($(words $(MAKECMDGOALS)),1)
37 ifeq ($(MAKECMDGOALS),$(filter $(MAKECMDGOALS),$(TARGETS)))
38 TARGET = $(MAKECMDGOALS)
42 DIRLIST = $(strip $(foreach dir,$1,$(wildcard $(dir))))
48 MKDIR = mkdir $(subst /,\,$1)
49 RMDIR = $(if $(DIRLIST),rmdir /s /q $(subst /,\,$(DIRLIST)))
54 .PHONY: all lib $(TARGETS) mostlyclean clean install
58 datadir = $(prefix)/share/cc65
60 INSTALLDIRS = ../asminc ../cfg ../include \
61 $(filter-out $(wildcard ../include/*.*),$(wildcard ../include/*)) \
62 ../lib ../targetutil $(addprefix ../,$(DRVTYPES))
69 @$(MAKE) --no-print-directory $@
75 $(call RMDIR,../wrk ../lib ../targetutil $(addprefix ../,$(DRVTYPES)))
78 $(foreach dir,$(INSTALLDIRS),$(INSTALL_recipe))
84 $(if $(prefix),,$(error variable `prefix' must be set))
85 $(INSTALL) -d $(subst ..,$(DESTDIR)$(datadir),$(dir))
86 $(INSTALL) -m644 $(dir)/*.* $(subst ..,$(DESTDIR)$(datadir),$(dir))
95 CC65FLAGS = -Osir -W error
105 TARGETUTIL = apple2 \
121 ifeq ($(TARGET),apple2enh)
125 else ifeq ($(TARGET),atarixl)
129 else ifeq ($(TARGET),sim65c02)
137 ifeq ($(TARGET),$(filter $(TARGET),$(CBMS)))
141 ifeq ($(TARGET),$(filter $(TARGET),$(GEOS)))
142 SRCDIRS += $(addprefix $(TARGET)/, $(GEOSDIRS))
143 SRCDIRS += $(addprefix geos-common/,$(GEOSDIRS))
160 OBJS := $(patsubst %.s,%.o,$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.s)))
161 OBJS += $(patsubst %.c,%.o,$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.c)))
163 OBJS := $(addprefix ../wrk/$(TARGET)/,$(sort $(notdir $(OBJS))))
167 EXTRA_SRCPAT = $(SRCDIR)/extra/%.s
168 EXTRA_OBJPAT = ../lib/$(TARGET)-%.o
169 EXTRA_OBJS := $(patsubst $(EXTRA_SRCPAT),$(EXTRA_OBJPAT),$(wildcard $(SRCDIR)/extra/*.s))
171 ZPOBJ = ../wrk/$(TARGET)/zeropage.o
172 ifeq ($(TARGET),$(filter $(TARGET),$(EXTZP)))
173 ZPOBJ += ../wrk/$(TARGET)/extzp.o
176 ifeq ($(SRCDIR),$(filter $(SRCDIR),$(MKINC)))
177 include $(SRCDIR)/Makefile.inc
180 ifeq ($(SRCDIR),$(filter $(SRCDIR),$(TARGETUTIL)))
181 include $(SRCDIR)/targetutil/Makefile.inc
186 define DRVTYPE_template
188 $1_SRCDIR = $$(SRCDIR)/$1
189 $1_OBJDIR = ../wrk/$$(TARGET)/$1
192 $1_OBJPAT = $$($1_OBJDIR)/$$(OBJPFX)%.o
193 $1_DRVPAT = $$($1_DRVDIR)/$$(DRVPFX)%.$1
194 $1_STCPAT = ../wrk/$$(TARGET)/$$(DRVPFX)%-$1.o
196 $1_OBJS := $$(patsubst $$($1_SRCDIR)/%.s,$$($1_OBJDIR)/%.o,$$(wildcard $$($1_SRCDIR)/*.s))
198 $1_DRVS = $$(patsubst $$($1_OBJPAT),$$($1_DRVPAT),$$($1_OBJS))
200 $1_STCS = $$(patsubst $$($1_DRVPAT),$$($1_STCPAT),$$($1_DRVS))
202 $$($1_OBJS): | $$($1_OBJDIR)
204 $$($1_DRVPAT): $$($1_OBJPAT) $$(ZPOBJ) | $$($1_DRVDIR)
205 @echo $$(TARGET) - $$(<F)
206 @$$(LD65) -o $$@ -t module $$^
208 $$($1_OBJDIR) $$($1_DRVDIR):
211 $(TARGET): $$($1_DRVS)
213 $$($1_STCPAT): $$($1_DRVPAT)
214 @echo $$(TARGET) - $$(<F)
215 @$$(CO65) -o $$(@:.o=.s) --code-label _$$(subst -,_,$$(subst .,_,$$(<F))) $$<
216 @$$(CA65) -t $$(TARGET) -o $$@ $$(@:.o=.s)
220 DEPS += $$($1_OBJS:.o=.d)
226 $(foreach drvtype,$(DRVTYPES),$(eval $(call DRVTYPE_template,$(drvtype))))
228 AR65 := $(if $(wildcard ../bin/ar65*),../bin/ar65,ar65)
229 CA65 := $(if $(wildcard ../bin/ca65*),../bin/ca65,ca65)
230 CC65 := $(if $(wildcard ../bin/cc65*),../bin/cc65,cc65)
231 CO65 := $(if $(wildcard ../bin/co65*),../bin/co65,co65)
232 LD65 := $(if $(wildcard ../bin/ld65*),../bin/ld65,ld65)
234 export CC65_HOME := $(abspath ..)
238 define ASSEMBLE_recipe
240 $(if $(TRAVIS),,@echo $(TARGET) - $<)
241 @$(CA65) -t $(TARGET) $(CA65FLAGS) --create-dep $(@:.o=.d) -o $@ $<
247 define COMPILE_recipe
249 $(if $(TRAVIS),,@echo $(TARGET) - $<)
250 @$(CC65) -t $(TARGET) $(CC65FLAGS) --create-dep $(@:.o=.d) --dep-target $@ -o $(@:.o=.s) $<
251 @$(CA65) -t $(TARGET) -o $@ $(@:.o=.s)
257 ../wrk/$(TARGET)/%.o: %.s | ../wrk/$(TARGET)
260 ../wrk/$(TARGET)/%.o: %.c | ../wrk/$(TARGET)
263 $(EXTRA_OBJPAT): $(EXTRA_SRCPAT) | ../lib
264 @echo $(TARGET) - $(<F)
265 @$(CA65) -t $(TARGET) $(CA65FLAGS) -o $@ $<
267 ../lib/$(TARGET).lib: $(OBJS) | ../lib
270 ../wrk/$(TARGET) ../lib ../targetutil:
273 $(TARGET): $(EXTRA_OBJS) ../lib/$(TARGET).lib