40 DRVOUTPUTDIRS := $(foreach drvtype,$(DRVTYPES),goodies/drivers/$(drvtype))
49 $(subst ../,,$(filter-out $(wildcard ../include/*.*),$(wildcard ../include/*)))
51 .PHONY: all mostlyclean clean install zip lib $(TARGETS)
56 DIRLIST = $(strip $(foreach dir,$1,$(wildcard $(dir))))
57 MKDIR = mkdir $(subst /,\,$1)
58 RMDIR = $(if $(DIRLIST),rmdir /s /q $(subst /,\,$(DIRLIST)))
64 # Every target requires its individual vpath setting but the vpath directive
65 # acts globally. Therefore each target is built in a separate make instance.
67 ifeq ($(words $(MAKECMDGOALS)),1)
68 ifeq ($(MAKECMDGOALS),$(filter $(MAKECMDGOALS),$(TARGETS)))
69 TARGET = $(MAKECMDGOALS)
75 datadir = $(prefix)/share/cc65
80 $(call RMDIR,../libwrk)
82 # Transitional line active. Final line commented out below in order to
83 # allow some time for transition between the directory structures
85 $(call RMDIR,../libwrk ../lib ../targetutil ../goodies $(addprefix ../,$(DRVTYPES)))
86 # $(call RMDIR,../libwrk ../lib ../goodies)
98 $(if $(prefix),,$(error variable `prefix' must be set))
99 $(INSTALL) -d $(DESTDIR)$(datadir)/$(dir)
100 $(INSTALL) -m644 ../$(dir)/*.* $(DESTDIR)$(datadir)/$(dir)
102 endef # INSTALL_recipe
105 $(foreach dir,$(OUTPUTDIRS),$(INSTALL_recipe))
111 @cd .. && zip cc65 $(dir)/*.*
116 $(foreach dir,$(OUTPUTDIRS),$(ZIP_recipe))
119 @$(MAKE) --no-print-directory $@
124 CC65FLAGS = -Or -W error
135 TARGETUTIL = apple2 \
153 ifeq ($(TARGET),apple2enh)
157 else ifeq ($(TARGET),atarixl)
161 else ifeq ($(TARGET),sim65c02)
169 ifeq ($(TARGET),$(filter $(TARGET),$(CBMS)))
173 ifeq ($(TARGET),$(filter $(TARGET),$(GEOS)))
174 SRCDIRS += $(addprefix $(TARGET)/, $(GEOSDIRS))
175 SRCDIRS += $(addprefix geos-common/,$(GEOSDIRS))
192 OBJS := $(patsubst %.s,%.o,$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.s)))
193 OBJS += $(patsubst %.c,%.o,$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.c)))
195 OBJS := $(addprefix ../libwrk/$(TARGET)/,$(sort $(notdir $(OBJS))))
199 EXTRA_SRCPAT = $(SRCDIR)/extra/%.s
200 EXTRA_OBJPAT = ../lib/$(TARGET)-%.o
201 EXTRA_OBJS := $(patsubst $(EXTRA_SRCPAT),$(EXTRA_OBJPAT),$(wildcard $(SRCDIR)/extra/*.s))
203 ZPOBJ = ../libwrk/$(TARGET)/zeropage.o
204 ifeq ($(TARGET),$(filter $(TARGET),$(EXTZP)))
205 ZPOBJ += ../libwrk/$(TARGET)/extzp.o
208 ifeq ($(TARGET),$(filter $(TARGET),$(MKINC)))
209 include $(SRCDIR)/Makefile.inc
212 ifeq ($(TARGET),$(filter $(TARGET),$(TARGETUTIL)))
213 include $(SRCDIR)/targetutil/Makefile.inc
216 define DRVTYPE_template
218 $1_SRCDIR = $$(SRCDIR)/$1
219 $1_STCDIR = ../libwrk/$$(TARGET)
220 $1_DYNDIR = ../libwrk/$$(TARGET)/$1
221 $1_DRVDIR = ../goodies/drivers/$1
223 $1_SRCPAT = $$($1_SRCDIR)/$$(OBJPFX)%.s
224 $1_STCPAT = $$($1_STCDIR)/$$(OBJPFX)%-$1.o
225 $1_DYNPAT = $$($1_DYNDIR)/$$(OBJPFX)%.o
226 $1_DRVPAT = $$($1_DRVDIR)/$$(DRVPFX)%.$1
228 $1_SRCS := $$(wildcard $$($1_SRCDIR)/*.s)
229 $1_STCS = $$(patsubst $$($1_SRCPAT),$$($1_STCPAT),$$($1_SRCS))
230 $1_DYNS = $$(patsubst $$($1_SRCPAT),$$($1_DYNPAT),$$($1_SRCS))
231 $1_DRVS = $$(patsubst $$($1_DYNPAT),$$($1_DRVPAT),$$($1_DYNS))
233 $$($1_STCPAT): $$($1_SRCPAT)
234 @echo $$(TARGET) - $$< - static
235 @$$(CA65) -t $$(TARGET) -D DYN_DRV=0 $$(CA65FLAGS) --create-dep $$(@:.o=.d) -o $$@ $$<
238 DEPS += $$($1_STCS:.o=.d)
240 $$($1_DYNS): | $$($1_DYNDIR)
242 $$($1_DRVPAT): $$($1_DYNPAT) $$(ZPOBJ) | $$($1_DRVDIR)
243 @echo $$(TARGET) - $$(<F)
244 @$$(LD65) -o $$@ -t module $$^
246 $$($1_DYNDIR) $$($1_DRVDIR):
249 $(TARGET): $$($1_DRVS)
251 DEPS += $$($1_DYNS:.o=.d)
253 endef # DRVTYPE_template
255 $(foreach drvtype,$(DRVTYPES),$(eval $(call DRVTYPE_template,$(drvtype))))
257 AR65 := $(if $(wildcard ../bin/ar65*),../bin/ar65,ar65)
258 CA65 := $(if $(wildcard ../bin/ca65*),../bin/ca65,ca65)
259 CC65 := $(if $(wildcard ../bin/cc65*),../bin/cc65,cc65)
260 LD65 := $(if $(wildcard ../bin/ld65*),../bin/ld65,ld65)
262 export CC65_HOME := $(abspath ..)
264 define ASSEMBLE_recipe
266 $(if $(QUIET),,@echo $(TARGET) - $<)
267 @$(CA65) -t $(TARGET) $(CA65FLAGS) --create-dep $(@:.o=.d) -o $@ $<
269 endef # ASSEMBLE_recipe
271 define COMPILE_recipe
273 $(if $(QUIET),,@echo $(TARGET) - $<)
274 @$(CC65) -t $(TARGET) $(CC65FLAGS) --create-dep $(@:.o=.d) --dep-target $@ -o $(@:.o=.s) $<
275 @$(CA65) -t $(TARGET) -o $@ $(@:.o=.s)
277 endef # COMPILE_recipe
279 ../libwrk/$(TARGET)/%.o: %.s | ../libwrk/$(TARGET)
282 ../libwrk/$(TARGET)/%.o: %.c | ../libwrk/$(TARGET)
285 $(EXTRA_OBJPAT): $(EXTRA_SRCPAT) | ../lib
286 @echo $(TARGET) - $(<F)
287 @$(CA65) -t $(TARGET) $(CA65FLAGS) -o $@ $<
289 ../lib/$(TARGET).lib: $(OBJS) | ../lib
292 ../libwrk/$(TARGET) ../lib ../goodies/targetutil:
295 $(TARGET): $(EXTRA_OBJS) ../lib/$(TARGET).lib