46 $(subst ../,,$(filter-out $(wildcard ../include/*.*),$(wildcard ../include/*)))\
47 $(subst ../,,$(wildcard ../target/*/drv/*))\
48 $(subst ../,,$(wildcard ../target/*/util))\
50 .PHONY: all mostlyclean clean install zip lib $(TARGETS)
55 DIRLIST = $(strip $(foreach dir,$1,$(wildcard $(dir))))
56 MKDIR = mkdir $(subst /,\,$1)
57 RMDIR = $(if $(DIRLIST),rmdir /s /q $(subst /,\,$(DIRLIST)))
63 # Every target requires its individual vpath setting but the vpath directive
64 # acts globally. Therefore each target is built in a separate make instance.
66 ifeq ($(words $(MAKECMDGOALS)),1)
67 ifeq ($(MAKECMDGOALS),$(filter $(MAKECMDGOALS),$(TARGETS)))
68 TARGET = $(MAKECMDGOALS)
74 datadir = $(prefix)/share/cc65
79 $(call RMDIR,../libwrk)
82 $(call RMDIR,../libwrk ../lib ../target)
94 $(if $(prefix),,$(error variable `prefix' must be set))
95 $(INSTALL) -d $(DESTDIR)$(datadir)/$(dir)
96 $(INSTALL) -m0644 ../$(dir)/*.* $(DESTDIR)$(datadir)/$(dir)
98 endef # INSTALL_recipe
101 $(foreach dir,$(OUTPUTDIRS),$(INSTALL_recipe))
107 @cd .. && zip cc65 $(dir)/*.*
112 $(foreach dir,$(OUTPUTDIRS),$(ZIP_recipe))
115 @$(MAKE) --no-print-directory $@
120 CC65FLAGS = -Or -W error
131 TARGETUTIL = apple2 \
149 ifeq ($(TARGET),apple2enh)
153 else ifeq ($(TARGET),atarixl)
157 else ifeq ($(TARGET),sim65c02)
165 ifeq ($(TARGET),$(filter $(TARGET),$(CBMS)))
169 ifeq ($(TARGET),$(filter $(TARGET),$(GEOS)))
170 SRCDIRS += $(addprefix $(TARGET)/, $(GEOSDIRS))
171 SRCDIRS += $(addprefix geos-common/,$(GEOSDIRS))
188 OBJS := $(patsubst %.s,%.o,$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.s)))
189 OBJS += $(patsubst %.c,%.o,$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.c)))
191 OBJS := $(addprefix ../libwrk/$(TARGET)/,$(sort $(notdir $(OBJS))))
195 EXTRA_SRCPAT = $(SRCDIR)/extra/%.s
196 EXTRA_OBJPAT = ../lib/$(TARGET)-%.o
197 EXTRA_OBJS := $(patsubst $(EXTRA_SRCPAT),$(EXTRA_OBJPAT),$(wildcard $(SRCDIR)/extra/*.s))
199 ZPOBJ = ../libwrk/$(TARGET)/zeropage.o
200 ifeq ($(TARGET),$(filter $(TARGET),$(EXTZP)))
201 ZPOBJ += ../libwrk/$(TARGET)/extzp.o
204 ifeq ($(TARGET),$(filter $(TARGET),$(MKINC)))
205 include $(SRCDIR)/Makefile.inc
208 ifeq ($(TARGET),$(filter $(TARGET),$(TARGETUTIL)))
209 include $(SRCDIR)/targetutil/Makefile.inc
212 define DRVTYPE_template
214 $1_SRCDIR = $$(SRCDIR)/$1
215 $1_STCDIR = ../libwrk/$$(TARGET)
216 $1_DYNDIR = ../libwrk/$$(TARGET)/$1
217 $1_DRVDIR = ../target/$$(TARGET)/drv/$1
219 $1_SRCPAT = $$($1_SRCDIR)/$$(OBJPFX)%.s
220 $1_STCPAT = $$($1_STCDIR)/$$(OBJPFX)%-$1.o
221 $1_DYNPAT = $$($1_DYNDIR)/$$(OBJPFX)%.o
222 $1_DRVPAT = $$($1_DRVDIR)/$$(DRVPFX)%.$1
224 $1_SRCS := $$(wildcard $$($1_SRCDIR)/*.s)
225 $1_STCS = $$(patsubst $$($1_SRCPAT),$$($1_STCPAT),$$($1_SRCS))
226 $1_DYNS = $$(patsubst $$($1_SRCPAT),$$($1_DYNPAT),$$($1_SRCS))
227 $1_DRVS = $$(patsubst $$($1_DYNPAT),$$($1_DRVPAT),$$($1_DYNS))
229 $$($1_STCPAT): $$($1_SRCPAT)
230 @echo $$(TARGET) - $$< - static
231 @$$(CA65) -t $$(TARGET) -D DYN_DRV=0 $$(CA65FLAGS) --create-dep $$(@:.o=.d) -o $$@ $$<
234 DEPS += $$($1_STCS:.o=.d)
236 $$($1_DYNS): | $$($1_DYNDIR)
238 $$($1_DRVPAT): $$($1_DYNPAT) $$(ZPOBJ) | $$($1_DRVDIR)
239 @echo $$(TARGET) - $$(<F)
240 @$$(LD65) -o $$@ -t module $$^
242 $$($1_DYNDIR) $$($1_DRVDIR):
245 $(TARGET): $$($1_DRVS)
247 DEPS += $$($1_DYNS:.o=.d)
249 endef # DRVTYPE_template
251 $(foreach drvtype,$(DRVTYPES),$(eval $(call DRVTYPE_template,$(drvtype))))
253 AR65 := $(if $(wildcard ../bin/ar65*),../bin/ar65,ar65)
254 CA65 := $(if $(wildcard ../bin/ca65*),../bin/ca65,ca65)
255 CC65 := $(if $(wildcard ../bin/cc65*),../bin/cc65,cc65)
256 LD65 := $(if $(wildcard ../bin/ld65*),../bin/ld65,ld65)
258 export CC65_HOME := $(abspath ..)
260 define ASSEMBLE_recipe
262 $(if $(QUIET),,@echo $(TARGET) - $<)
263 @$(CA65) -t $(TARGET) $(CA65FLAGS) --create-dep $(@:.o=.d) -o $@ $<
265 endef # ASSEMBLE_recipe
267 define COMPILE_recipe
269 $(if $(QUIET),,@echo $(TARGET) - $<)
270 @$(CC65) -t $(TARGET) $(CC65FLAGS) --create-dep $(@:.o=.d) --dep-target $@ -o $(@:.o=.s) $<
271 @$(CA65) -t $(TARGET) -o $@ $(@:.o=.s)
273 endef # COMPILE_recipe
275 ../libwrk/$(TARGET)/%.o: %.s | ../libwrk/$(TARGET)
278 ../libwrk/$(TARGET)/%.o: %.c | ../libwrk/$(TARGET)
281 $(EXTRA_OBJPAT): $(EXTRA_SRCPAT) | ../lib
282 @echo $(TARGET) - $(<F)
283 @$(CA65) -t $(TARGET) $(CA65FLAGS) -o $@ $<
285 ../lib/$(TARGET).lib: $(OBJS) | ../lib
288 ../libwrk/$(TARGET) ../lib ../target/$(TARGET)/util:
291 $(TARGET): $(EXTRA_OBJS) ../lib/$(TARGET).lib