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
60 @$(MAKE) --no-print-directory $@
66 $(call RMDIR,../wrk ../lib ../targetutil $(addprefix ../,$(DRVTYPES)))
71 CC65FLAGS = -Osir -W error
97 ifeq ($(TARGET),apple2enh)
101 else ifeq ($(TARGET),atarixl)
105 else ifeq ($(TARGET),sim65c02)
113 ifeq ($(TARGET),$(filter $(TARGET),$(CBMS)))
117 ifeq ($(TARGET),$(filter $(TARGET),$(GEOS)))
118 SRCDIRS += $(addprefix $(TARGET)/, $(GEOSDIRS))
119 SRCDIRS += $(addprefix geos-common/,$(GEOSDIRS))
136 OBJS := $(patsubst %.s,%.o,$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.s)))
137 OBJS += $(patsubst %.c,%.o,$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.c)))
139 OBJS := $(addprefix ../wrk/$(TARGET)/,$(sort $(notdir $(OBJS))))
143 EXTRA_SRCPAT = $(SRCDIR)/extra/%.s
144 EXTRA_OBJPAT = ../lib/$(TARGET)-%.o
145 EXTRA_OBJS := $(patsubst $(EXTRA_SRCPAT),$(EXTRA_OBJPAT),$(wildcard $(SRCDIR)/extra/*.s))
147 ZPOBJ = ../wrk/$(TARGET)/zeropage.o
148 ifeq ($(TARGET),$(filter $(TARGET),$(EXTZP)))
149 ZPOBJ += ../wrk/$(TARGET)/extzp.o
152 ifeq ($(SRCDIR),$(filter $(SRCDIR),$(MKINC)))
153 include $(SRCDIR)/Makefile.inc
156 ifeq ($(SRCDIR),$(filter $(SRCDIR),$(TARGETUTIL)))
157 include $(SRCDIR)/targetutil/Makefile.inc
162 define DRVTYPE_template
164 $1_SRCDIR = $$(SRCDIR)/$1
165 $1_OBJDIR = ../wrk/$$(TARGET)/$1
168 $1_OBJPAT = $$($1_OBJDIR)/$$(OBJPFX)%.o
169 $1_DRVPAT = $$($1_DRVDIR)/$$(DRVPFX)%.$1
170 $1_STCPAT = ../wrk/$$(TARGET)/$$(DRVPFX)%-$1.o
172 $1_OBJS := $$(patsubst $$($1_SRCDIR)/%.s,$$($1_OBJDIR)/%.o,$$(wildcard $$($1_SRCDIR)/*.s))
174 $1_DRVS = $$(patsubst $$($1_OBJPAT),$$($1_DRVPAT),$$($1_OBJS))
176 $1_STCS = $$(patsubst $$($1_DRVPAT),$$($1_STCPAT),$$($1_DRVS))
178 $$($1_OBJS): | $$($1_OBJDIR)
180 $$($1_DRVPAT): $$($1_OBJPAT) $$(ZPOBJ) | $$($1_DRVDIR)
181 @echo $$(TARGET) - $$(@F)
182 @$$(LD65) -o $$@ -t module $$^
184 $$($1_OBJDIR) $$($1_DRVDIR):
187 $(TARGET): $$($1_DRVS)
189 $$($1_STCPAT): $$($1_DRVPAT)
190 @echo $$(TARGET) - $$(<F)
191 @$$(CO65) -o $$(@:.o=.s) --code-label _$$(subst -,_,$$(subst .,_,$$(<F))) $$<
192 @$$(CA65) -t $$(TARGET) -o $$@ $$(@:.o=.s)
196 DEPS += $$($1_OBJS:.o=.d)
202 $(foreach drvtype,$(DRVTYPES),$(eval $(call DRVTYPE_template,$(drvtype))))
204 AR65 := $(if $(wildcard ../bin/ar65*),../bin/ar65,ar65)
205 CA65 := $(if $(wildcard ../bin/ca65*),../bin/ca65,ca65)
206 CC65 := $(if $(wildcard ../bin/cc65*),../bin/cc65,cc65)
207 CO65 := $(if $(wildcard ../bin/co65*),../bin/co65,co65)
208 LD65 := $(if $(wildcard ../bin/ld65*),../bin/ld65,ld65)
210 export CC65_HOME := $(abspath ..)
214 define ASSEMBLE_recipe
216 $(if $(TRAVIS),,@echo $(TARGET) - $<)
217 @$(CA65) -t $(TARGET) $(CA65FLAGS) --create-dep $(@:.o=.d) -o $@ $<
223 define COMPILE_recipe
225 $(if $(TRAVIS),,@echo $(TARGET) - $<)
226 @$(CC65) -t $(TARGET) $(CC65FLAGS) --create-dep $(@:.o=.d) --dep-target $@ -o $(@:.o=.s) $<
227 @$(CA65) -t $(TARGET) -o $@ $(@:.o=.s)
233 ../wrk/$(TARGET)/%.o: %.s | ../wrk/$(TARGET)
236 ../wrk/$(TARGET)/%.o: %.c | ../wrk/$(TARGET)
239 $(EXTRA_OBJPAT): $(EXTRA_SRCPAT) | ../lib
240 @echo $(TARGET) - $(@F)
241 @$(CA65) -t $(TARGET) $(CA65FLAGS) -o $@ $<
243 ../lib/$(TARGET).lib: $(OBJS) | ../lib
246 ../wrk/$(TARGET) ../lib ../targetutil:
249 $(TARGET): $(EXTRA_OBJS) ../lib/$(TARGET).lib