2000-05-28 13:40:48 +00:00
|
|
|
#
|
|
|
|
# Makefile for cc65 samples
|
|
|
|
#
|
2000-06-06 17:45:06 +00:00
|
|
|
# This Makefile requires GNU make
|
|
|
|
#
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2018-04-14 22:09:13 +00:00
|
|
|
# Run 'make SYS=<target>'; or, set a SYS env.
|
|
|
|
# var. to build for another target system.
|
2016-06-19 16:55:00 +00:00
|
|
|
SYS ?= c64
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2018-06-10 16:12:09 +00:00
|
|
|
# Just the usual way to define a variable
|
|
|
|
# containing a single space character.
|
|
|
|
SPACE :=
|
|
|
|
SPACE +=
|
|
|
|
|
|
|
|
# Just the usual way to find out if we're
|
|
|
|
# using cmd.exe to execute make rules.
|
2016-06-01 20:14:30 +00:00
|
|
|
ifneq ($(shell echo),)
|
|
|
|
CMD_EXE = 1
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifdef CMD_EXE
|
|
|
|
NULLDEV = nul:
|
|
|
|
DEL = -del /f
|
2016-06-18 23:22:59 +00:00
|
|
|
RMDIR = rmdir /s /q
|
2016-06-01 20:14:30 +00:00
|
|
|
else
|
|
|
|
NULLDEV = /dev/null
|
|
|
|
DEL = $(RM)
|
2016-06-18 23:22:59 +00:00
|
|
|
RMDIR = $(RM) -r
|
2016-06-01 20:14:30 +00:00
|
|
|
endif
|
|
|
|
|
2009-09-28 19:22:02 +00:00
|
|
|
ifdef CC65_HOME
|
2016-06-18 23:22:59 +00:00
|
|
|
AS = $(CC65_HOME)/bin/ca65
|
|
|
|
CC = $(CC65_HOME)/bin/cc65
|
|
|
|
CL = $(CC65_HOME)/bin/cl65
|
|
|
|
LD = $(CC65_HOME)/bin/ld65
|
|
|
|
else
|
|
|
|
AS := $(if $(wildcard ../bin/ca65*),../bin/ca65,ca65)
|
|
|
|
CC := $(if $(wildcard ../bin/cc65*),../bin/cc65,cc65)
|
|
|
|
CL := $(if $(wildcard ../bin/cl65*),../bin/cl65,cl65)
|
|
|
|
LD := $(if $(wildcard ../bin/ld65*),../bin/ld65,ld65)
|
2009-09-28 19:22:02 +00:00
|
|
|
endif
|
2016-05-30 15:42:01 +00:00
|
|
|
|
2016-07-03 06:14:33 +00:00
|
|
|
ifneq ($(filter disk samples.%,$(MAKECMDGOALS)),)
|
2018-06-08 16:58:36 +00:00
|
|
|
ifdef CC65_HOME
|
|
|
|
TARGET_PATH = $(CC65_HOME)/target
|
|
|
|
else
|
|
|
|
TARGET_PATH := $(if $(wildcard ../target),../target,$(shell $(CL) --print-target-path))
|
|
|
|
endif
|
|
|
|
|
2018-06-10 16:12:09 +00:00
|
|
|
# If TARGET_PATH contains spaces then it is presumed to contain escaped spaces. GNU make
|
|
|
|
# has very limited support for paths containing spaces. $(wildcard) is the only function
|
|
|
|
# that is aware of escaped spaces. However, $(wildcard) never returns paths with escaped
|
2019-04-04 15:13:09 +00:00
|
|
|
# spaces !!! So if it e.g. finds 4 files in a path with 2 spaces then one ends up with a
|
|
|
|
# return value consisting of 12 plain words :-((
|
2018-06-10 16:12:09 +00:00
|
|
|
#
|
|
|
|
# Fortunately we can work around that behaviour here because we know that the files we
|
|
|
|
# are looking for have known extensions. So we can $(filter) the in our example above 12
|
|
|
|
# words for file extensions so we come up with 4 path fragments. Then we remove those
|
|
|
|
# path fragments with $(notdir) from the file names.
|
|
|
|
#
|
|
|
|
# So far so good. But here we want to process files from different paths in a single
|
|
|
|
# recipe further down below and therefore want to prepend the paths to the files with
|
|
|
|
# $(addprefix). However, $(foreach) isn't aware of escaped spaces (only $(wildcard) is).
|
|
|
|
# Therefore, we need to replace the spaces with some other character temporarily in order
|
|
|
|
# to have $(foreach) generate one invocation per file. We use the character '?' for that
|
|
|
|
# purpose here, just because it is known to not be part of file names.
|
|
|
|
#
|
|
|
|
# Inside the recipe generated per file we then replace the '?' again with a space. As we
|
|
|
|
# want to be compatible with cmd.exe for execution we're not using an escaped space but
|
|
|
|
# rather double-quote the whole path.
|
|
|
|
#
|
|
|
|
# Note: The "strange" $(wildcard) further down below just serves the purpose to unescape
|
|
|
|
# spaces for cmd.exe. This could have as well been done with another $(subst).
|
|
|
|
|
|
|
|
SUBST_TARGET_PATH := $(subst \$(SPACE),?,$(TARGET_PATH))
|
2004-11-07 11:33:30 +00:00
|
|
|
|
2016-08-10 09:38:11 +00:00
|
|
|
EMD := $(wildcard $(TARGET_PATH)/$(SYS)/drv/emd/*)
|
|
|
|
MOU := $(wildcard $(TARGET_PATH)/$(SYS)/drv/mou/*)
|
|
|
|
TGI := $(wildcard $(TARGET_PATH)/$(SYS)/drv/tgi/*)
|
2004-11-07 11:33:30 +00:00
|
|
|
|
2018-06-10 16:12:09 +00:00
|
|
|
EMD := $(addprefix $(SUBST_TARGET_PATH)/$(SYS)/drv/emd/,$(notdir $(filter %.emd,$(EMD))))
|
|
|
|
MOU := $(addprefix $(SUBST_TARGET_PATH)/$(SYS)/drv/mou/,$(notdir $(filter %.mou,$(MOU))))
|
|
|
|
TGI := $(addprefix $(SUBST_TARGET_PATH)/$(SYS)/drv/tgi/,$(notdir $(filter %.tgi,$(TGI))))
|
|
|
|
|
2018-04-14 22:09:13 +00:00
|
|
|
# This one comes with the VICE emulator.
|
|
|
|
# See http://vice-emu.sourceforge.net/
|
2016-08-10 09:38:11 +00:00
|
|
|
C1541 ?= c1541
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2018-04-14 22:09:13 +00:00
|
|
|
# For this one, see https://applecommander.github.io/
|
2016-08-10 09:38:11 +00:00
|
|
|
AC ?= ac.jar
|
2016-06-18 23:22:59 +00:00
|
|
|
|
2019-07-15 10:29:09 +00:00
|
|
|
# For this one, see https://www.horus.com/~hias/atari/
|
2016-08-10 09:38:11 +00:00
|
|
|
DIR2ATR ?= dir2atr
|
2016-06-18 23:22:59 +00:00
|
|
|
|
2016-08-10 09:38:11 +00:00
|
|
|
DISK_c64 = samples.d64
|
|
|
|
DISK_apple2 = samples.dsk
|
|
|
|
DISK_apple2enh = samples.dsk
|
|
|
|
DISK_atari = samples.atr
|
|
|
|
DISK_atarixl = samples.atr
|
2016-07-03 06:14:33 +00:00
|
|
|
endif
|
2016-06-18 23:22:59 +00:00
|
|
|
|
2014-03-22 11:04:16 +00:00
|
|
|
# --------------------------------------------------------------------------
|
2015-07-16 19:31:35 +00:00
|
|
|
# System-dependent settings
|
2018-04-14 22:09:13 +00:00
|
|
|
# For convenience, these groups and lines are sorted alphabetically, first
|
|
|
|
# by target-machine group, then by mission, then by program and sub-target.
|
2014-03-22 11:04:16 +00:00
|
|
|
|
|
|
|
# The Apple machines need the start address adjusted when using TGI
|
2016-06-18 23:22:59 +00:00
|
|
|
LDFLAGS_mandelbrot_apple2 = --start-addr 0x4000
|
2014-03-22 11:04:16 +00:00
|
|
|
LDFLAGS_mandelbrot_apple2enh = --start-addr 0x4000
|
2016-06-18 23:22:59 +00:00
|
|
|
LDFLAGS_tgidemo_apple2 = --start-addr 0x4000
|
|
|
|
LDFLAGS_tgidemo_apple2enh = --start-addr 0x4000
|
2014-03-22 11:04:16 +00:00
|
|
|
|
2017-02-13 21:43:26 +00:00
|
|
|
# The Apple ][ needs the start address adjusted for the mousedemo
|
|
|
|
LDFLAGS_mousedemo_apple2 = --start-addr 0x4000
|
2014-03-22 11:04:16 +00:00
|
|
|
|
2016-06-18 23:22:59 +00:00
|
|
|
# The Apple machines need the end address adjusted for large programs
|
|
|
|
LDFLAGS_gunzip65_apple2 = -D __HIMEM__=0xBF00
|
|
|
|
LDFLAGS_gunzip65_apple2enh = -D __HIMEM__=0xBF00
|
2014-03-22 11:04:16 +00:00
|
|
|
|
|
|
|
# The atari target needs to reserve some memory when using TGI
|
|
|
|
LDFLAGS_mandelbrot_atari = -D __RESERVED_MEMORY__=0x2000
|
2016-06-18 23:22:59 +00:00
|
|
|
LDFLAGS_tgidemo_atari = -D __RESERVED_MEMORY__=0x2000
|
|
|
|
|
|
|
|
# The atarixl target needs the start address adjusted when using TGI
|
|
|
|
LDFLAGS_mandelbrot_atarixl = --start-addr 0x4000
|
|
|
|
LDFLAGS_tgidemo_atarixl = --start-addr 0x4000
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2001-09-26 17:55:09 +00:00
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# Generic rules
|
|
|
|
|
2016-06-18 23:22:59 +00:00
|
|
|
.PHONY: all mostlyclean clean install zip samples disk
|
2016-06-01 19:08:47 +00:00
|
|
|
|
2013-06-27 14:01:47 +00:00
|
|
|
%: %.c
|
|
|
|
%: %.s
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
.c.o:
|
2017-03-10 13:47:48 +00:00
|
|
|
$(CC) $(CFLAGS) -Ors --codesize 500 -T -g -t $(SYS) $<
|
2016-06-01 21:00:37 +00:00
|
|
|
$(AS) $(<:.c=.s)
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
.s.o:
|
2018-04-14 22:09:13 +00:00
|
|
|
$(AS) $(ASFLAGS) -t $(SYS) $<
|
2009-09-28 19:22:02 +00:00
|
|
|
|
2014-03-22 11:04:16 +00:00
|
|
|
.PRECIOUS: %.o
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2014-03-22 11:04:16 +00:00
|
|
|
.o:
|
2018-04-14 22:09:13 +00:00
|
|
|
ifeq ($(SYS),vic20)
|
|
|
|
$(LD) $(LDFLAGS_$(@F)_$(SYS)) $(LDFLAGS) -o $@ -C vic20-32k.cfg -m $@.map $^ $(SYS).lib
|
|
|
|
else
|
|
|
|
$(LD) $(LDFLAGS_$(@F)_$(SYS)) $(LDFLAGS) -o $@ -t $(SYS) -m $@.map $^ $(SYS).lib
|
|
|
|
endif
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2001-09-26 17:55:09 +00:00
|
|
|
# --------------------------------------------------------------------------
|
2018-04-14 22:09:13 +00:00
|
|
|
# Lists of executables
|
2016-06-18 23:22:59 +00:00
|
|
|
|
|
|
|
EXELIST_c64 = \
|
|
|
|
ascii \
|
|
|
|
enumdevdir \
|
|
|
|
fire \
|
|
|
|
gunzip65 \
|
|
|
|
hello \
|
|
|
|
mandelbrot \
|
2017-02-13 21:43:26 +00:00
|
|
|
mousedemo \
|
2016-06-18 23:22:59 +00:00
|
|
|
multdemo \
|
|
|
|
nachtm \
|
|
|
|
ovrldemo \
|
|
|
|
plasma \
|
|
|
|
sieve \
|
|
|
|
tgidemo
|
|
|
|
|
|
|
|
EXELIST_apple2 = \
|
|
|
|
ascii \
|
|
|
|
diodemo \
|
|
|
|
enumdevdir \
|
|
|
|
gunzip65 \
|
|
|
|
hello \
|
|
|
|
mandelbrot \
|
2017-02-13 21:43:26 +00:00
|
|
|
mousedemo \
|
2016-06-18 23:22:59 +00:00
|
|
|
multdemo \
|
|
|
|
ovrldemo \
|
|
|
|
sieve \
|
|
|
|
tgidemo
|
|
|
|
|
|
|
|
EXELIST_apple2enh = $(EXELIST_apple2)
|
|
|
|
|
|
|
|
EXELIST_atari = \
|
|
|
|
ascii \
|
|
|
|
gunzip65 \
|
|
|
|
hello \
|
|
|
|
mandelbrot \
|
2017-02-13 21:43:26 +00:00
|
|
|
mousedemo \
|
2016-06-18 23:22:59 +00:00
|
|
|
multdemo \
|
|
|
|
ovrldemo \
|
|
|
|
sieve \
|
|
|
|
tgidemo
|
|
|
|
|
|
|
|
EXELIST_atarixl = $(EXELIST_atari)
|
2001-09-26 17:55:09 +00:00
|
|
|
|
2017-02-13 21:43:26 +00:00
|
|
|
EXELIST_atari2600 = \
|
2017-01-08 18:12:55 +00:00
|
|
|
atari2600hello
|
|
|
|
|
2018-04-14 22:09:13 +00:00
|
|
|
# Unlisted targets will try to build everything.
|
|
|
|
# That lets us learn what they cannot build, and what settings
|
|
|
|
# we need to use for programs that can be built and run.
|
|
|
|
ifndef EXELIST_$(SYS)
|
|
|
|
EXELIST_$(SYS) := ${patsubst %.c,%,$(wildcard *.c)}
|
|
|
|
endif
|
|
|
|
|
2005-03-31 07:28:14 +00:00
|
|
|
# --------------------------------------------------------------------------
|
2016-06-18 23:22:59 +00:00
|
|
|
# Rules to make the binaries and the disk
|
2001-09-26 17:55:09 +00:00
|
|
|
|
2016-06-18 23:22:59 +00:00
|
|
|
samples: $(EXELIST_$(SYS))
|
|
|
|
|
|
|
|
disk: $(DISK_$(SYS))
|
2001-09-26 17:55:09 +00:00
|
|
|
|
2016-06-19 16:55:00 +00:00
|
|
|
all:
|
|
|
|
|
2001-09-26 17:55:09 +00:00
|
|
|
# --------------------------------------------------------------------------
|
2015-07-16 19:31:35 +00:00
|
|
|
# Overlay rules. Overlays need special ld65 configuration files. Also, the
|
|
|
|
# overlay file-names are shortenned to fit the Atari's 8.3-character limit.
|
|
|
|
|
2016-06-01 18:59:33 +00:00
|
|
|
multdemo: multidemo.o
|
2018-04-14 22:09:13 +00:00
|
|
|
$(LD) $(LDFLAGS) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(SYS).lib
|
2015-07-16 19:31:35 +00:00
|
|
|
|
2016-06-01 18:59:33 +00:00
|
|
|
ovrldemo: overlaydemo.o
|
2018-04-14 22:09:13 +00:00
|
|
|
$(LD) $(LDFLAGS) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(SYS).lib
|
2015-07-16 19:31:35 +00:00
|
|
|
|
2016-06-02 18:49:10 +00:00
|
|
|
OVERLAYLIST := $(foreach I,1 2 3,multdemo.$I ovrldemo.$I)
|
|
|
|
|
2015-07-16 19:31:35 +00:00
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# Rule to make a CBM disk with all samples. Needs the c1541 program that comes
|
2001-09-26 17:55:09 +00:00
|
|
|
# with the VICE emulator.
|
2001-09-13 15:58:32 +00:00
|
|
|
|
2016-06-01 21:45:27 +00:00
|
|
|
define D64_WRITE_recipe
|
|
|
|
|
2018-06-10 16:12:09 +00:00
|
|
|
$(C1541) -attach $@ -write "$(subst ?,$(SPACE),$(file))" $(notdir $(file)) >$(NULLDEV)
|
2016-06-01 21:45:27 +00:00
|
|
|
|
|
|
|
endef # D64_WRITE_recipe
|
|
|
|
|
2016-06-01 18:59:33 +00:00
|
|
|
samples.d64: samples
|
2018-06-10 16:12:09 +00:00
|
|
|
@$(C1541) -format samples,AA d64 $@ >$(NULLDEV)
|
2016-06-18 23:22:59 +00:00
|
|
|
$(foreach file,$(EXELIST_$(SYS)),$(D64_WRITE_recipe))
|
2016-06-02 18:49:10 +00:00
|
|
|
$(foreach file,$(OVERLAYLIST),$(D64_WRITE_recipe))
|
2016-06-18 23:22:59 +00:00
|
|
|
$(foreach file,$(EMD) $(MOU) $(TGI),$(D64_WRITE_recipe))
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------------
|
2018-03-07 22:04:33 +00:00
|
|
|
# Rule to make an Apple II disk with all samples. Needs the AppleCommander
|
2018-04-14 22:09:13 +00:00
|
|
|
# program, available at https://applecommander.github.io/, and a template disk
|
2018-03-07 22:04:33 +00:00
|
|
|
# named 'prodos.dsk'.
|
2016-06-18 23:22:59 +00:00
|
|
|
|
|
|
|
define DSK_WRITE_BIN_recipe
|
|
|
|
|
|
|
|
$(if $(findstring BF00,$(LDFLAGS_$(notdir $(file))_$(SYS))), \
|
2018-06-10 16:12:09 +00:00
|
|
|
java -jar $(AC) -p $@ $(notdir $(file)).system sys <"$(wildcard $(TARGET_PATH)/$(SYS)/util/loader.system)")
|
|
|
|
java -jar $(AC) -as $@ $(notdir $(file)) <"$(file)"
|
2016-06-18 23:22:59 +00:00
|
|
|
|
|
|
|
endef # DSK_WRITE_BIN_recipe
|
|
|
|
|
|
|
|
define DSK_WRITE_REL_recipe
|
|
|
|
|
2018-06-10 16:12:09 +00:00
|
|
|
java -jar $(AC) -p $@ $(notdir $(file)) rel 0 <"$(subst ?,$(SPACE),$(file))"
|
2016-06-18 23:22:59 +00:00
|
|
|
|
|
|
|
endef # DSK_WRITE_REL_recipe
|
|
|
|
|
|
|
|
samples.dsk: samples
|
|
|
|
cp prodos.dsk $@
|
|
|
|
$(foreach file,$(EXELIST_$(SYS)),$(DSK_WRITE_BIN_recipe))
|
|
|
|
$(foreach file,$(OVERLAYLIST),$(DSK_WRITE_REL_recipe))
|
|
|
|
$(foreach file,$(EMD) $(MOU) $(TGI),$(DSK_WRITE_REL_recipe))
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# Rule to make an Atari disk with all samples. Needs the dir2atr program
|
|
|
|
# available at http://www.horus.com/~hias/atari/ and the MyDos4534 variant
|
|
|
|
# of dos.sys and dup.sys.
|
|
|
|
|
|
|
|
define ATR_WRITE_recipe
|
|
|
|
|
2018-06-10 16:12:09 +00:00
|
|
|
cp "$(subst ?,$(SPACE),$(file))" atr/$(notdir $(file))
|
2016-06-18 23:22:59 +00:00
|
|
|
|
|
|
|
endef # ATR_WRITE_recipe
|
|
|
|
|
|
|
|
samples.atr: samples
|
|
|
|
@mkdir atr
|
2018-06-10 16:12:09 +00:00
|
|
|
cp "dos.sys" atr/dos.sys
|
|
|
|
cp "dup.sys" atr/dup.sys
|
2016-06-18 23:22:59 +00:00
|
|
|
@$(foreach file,$(EXELIST_$(SYS)),$(ATR_WRITE_recipe))
|
|
|
|
@$(foreach file,$(OVERLAYLIST),$(ATR_WRITE_recipe))
|
|
|
|
@$(foreach file,$(EMD) $(MOU) $(TGI),$(ATR_WRITE_recipe))
|
|
|
|
$(DIR2ATR) -d -b MyDos4534 3200 $@ atr
|
|
|
|
@$(RMDIR) atr
|
2001-09-26 17:55:09 +00:00
|
|
|
|
2016-05-30 15:42:01 +00:00
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# Installation rules
|
|
|
|
|
|
|
|
INSTALL = install
|
2017-07-22 14:38:50 +00:00
|
|
|
samplesdir = $(PREFIX)/share/cc65/samples
|
2016-06-01 19:08:47 +00:00
|
|
|
|
2016-05-30 15:42:01 +00:00
|
|
|
install:
|
2019-01-05 19:57:12 +00:00
|
|
|
$(if $(PREFIX),,$(error variable "PREFIX" must be set))
|
2016-05-30 15:42:01 +00:00
|
|
|
$(INSTALL) -d $(DESTDIR)$(samplesdir)
|
|
|
|
$(INSTALL) -d $(DESTDIR)$(samplesdir)/geos
|
2016-06-23 12:41:03 +00:00
|
|
|
$(INSTALL) -d $(DESTDIR)$(samplesdir)/tutorial
|
2016-05-30 15:42:01 +00:00
|
|
|
$(INSTALL) -m0644 *.* $(DESTDIR)$(samplesdir)
|
|
|
|
$(INSTALL) -m0644 README $(DESTDIR)$(samplesdir)
|
|
|
|
$(INSTALL) -m0644 Makefile $(DESTDIR)$(samplesdir)
|
|
|
|
$(INSTALL) -m0644 geos/*.* $(DESTDIR)$(samplesdir)/geos
|
|
|
|
$(INSTALL) -m0644 tutorial/*.* $(DESTDIR)$(samplesdir)/tutorial
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# Packaging rules
|
|
|
|
|
|
|
|
zip:
|
|
|
|
@cd .. && zip -r cc65 samples/
|
|
|
|
|
2001-09-26 17:55:09 +00:00
|
|
|
# --------------------------------------------------------------------------
|
2015-07-16 19:31:35 +00:00
|
|
|
# Clean-up rules
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2016-05-30 15:42:01 +00:00
|
|
|
mostlyclean:
|
2018-04-14 22:09:13 +00:00
|
|
|
@$(DEL) *.lbl *.map *.o *.s 2>$(NULLDEV)
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2016-06-01 20:50:42 +00:00
|
|
|
clean: mostlyclean
|
2016-06-18 23:22:59 +00:00
|
|
|
@$(DEL) $(EXELIST_$(SYS)) $(DISK_$(SYS)) 2>$(NULLDEV)
|
2016-06-01 20:14:30 +00:00
|
|
|
@$(DEL) multdemo.? ovrldemo.? 2>$(NULLDEV)
|