]> git.sur5r.net Git - cc65/blobdiff - samples/Makefile
Write overlays to d64 image.
[cc65] / samples / Makefile
index 78b4ca93a8d44f27e6af0d470dd6d087e8683598..c138c1c2e0b80bf3ed6a7f0e811657b7ab0ee414 100644 (file)
 #
 
 # Enter the target system here
-SYS    = c64
+SYS = c64
+
+ifneq ($(shell echo),)
+  CMD_EXE = 1
+endif
+
+ifdef CMD_EXE
+  NULLDEV = nul:
+  DEL = -del /f
+else
+  NULLDEV = /dev/null
+  DEL = $(RM)
+endif
 
 # Determine the path to the executables and libraries. If the samples
-# directory is part of a complete source tree, use the stuff from this
-# source tree, otherwise use the "official" directories.
+# directory is part of a complete source tree, use the stuff from that
+# source tree; otherwise, use the "install" directories.
 ifeq "$(wildcard ../src)" ""
 # No source tree
-CRT0 = $(SYS).o
-CLIB = $(SYS).lib
+installdir = /usr/lib/cc65
+ifneq "$(wildcard /usr/local/lib/cc65)" ""
+installdir = /usr/local/lib/cc65
+endif
+ifneq "$(wildcard /opt/local/share/cc65)" ""
+installdir = /opt/local/share/cc65
+endif
+ifdef CC65_HOME
+installdir = $(CC65_HOME)
+endif
+
+MOUS := $(wildcard $(installdir)/target/$(SYS)/drv/mou/$(SYS)*.mou)
+TGI  := $(wildcard $(installdir)/target/$(SYS)/drv/tgi/$(SYS)*.tgi)
+CLIB = --lib $(SYS).lib
 CL   = cl65
 CC   = cc65
 AS   = ca65
 LD   = ld65
 
 else
-# Samples is part of a complete source tree
-CRT0 = ../libsrc/$(SYS).o
-CLIB = ../libsrc/$(SYS).lib
-CL   = ../src/cl65/cl65
-CC   = ../src/cc65/cc65
-AS   = ../src/ca65/ca65
-LD   = ../src/ld65/ld65
-export CC65_INC = ../include
+# "samples/" is a part of a complete source tree.
+export CC65_HOME := $(abspath ..)
+MOUS := $(wildcard ../target/$(SYS)/drv/mou/$(SYS)*.mou)
+TGI  := $(wildcard ../target/$(SYS)/drv/tgi/$(SYS)*.tgi)
+CLIB = ../lib/$(SYS).lib
+CL   = ../bin/cl65
+CC   = ../bin/cc65
+AS   = ../bin/ca65
+LD   = ../bin/ld65
 endif
 
 # This one comes with VICE
-C1541          = c1541
+C1541 ?= c1541
 
+# --------------------------------------------------------------------------
+# System-dependent settings
+
+# The Apple machines need the start address adjusted when using TGI
+LDFLAGS_mandelbrot_apple2 = --start-addr 0x4000
+LDFLAGS_tgidemo_apple2 = --start-addr 0x4000
+LDFLAGS_mandelbrot_apple2enh = --start-addr 0x4000
+LDFLAGS_tgidemo_apple2enh = --start-addr 0x4000
+
+# The Apple ][ needs the start address adjusted for the mousetest
+LDFLAGS_mousetest_apple2 = --start-addr 0x4000
+
+# The atarixl target needs the start address adjusted when using TGI
+LDFLAGS_mandelbrot_atarixl = --start-addr 0x4000
+LDFLAGS_tgidemo_atarixl = --start-addr 0x4000
+
+# The atari target needs to reserve some memory when using TGI
+LDFLAGS_mandelbrot_atari = -D __RESERVED_MEMORY__=0x2000
+LDFLAGS_tgidemo_atari = -D __RESERVED_MEMORY__=0x2000
 
 # --------------------------------------------------------------------------
 # Generic rules
 
+.PHONY: all mostlyclean clean install zip samples d64
+
+%: %.c
+%: %.s
+
 .c.o:
-       @echo $<
-       @$(CC) -Oirs -T --forget-inc-paths --codesize 500 -g -t $(SYS) -I../include/ $<
-       @$(AS) $(basename $<).s
+       $(CC) $(CFLAGS) -Oirs --codesize 500 -T -g -t $(SYS) $<
+       $(AS) $(<:.c=.s)
 
 .s.o:
-       @echo $<
-       @$(AS) $(basename $<).s
+       $(AS) $(AFLAGS) -t $(SYS) $<
 
+.PRECIOUS: %.o
+
+.o:
+       $(LD) $(LDFLAGS_$(@F)_$(SYS)) -o $@ -t $(SYS) -m $@.map $^ $(CLIB)
 
 # --------------------------------------------------------------------------
-# List of executables. This list could be made target dependent by checking
+# List of executables. This list could be made target-dependent by checking
 # $(SYS).
 
-EXELIST        =       ascii           \
-               diodemo         \
-               fire            \
-               gunzip65        \
-               hello           \
-               mousedemo       \
-               nachtm          \
-               plasma          \
-               sieve           \
-               tgidemo
+EXELIST = ascii      \
+          diodemo    \
+          enumdevdir \
+          fire       \
+          gunzip65   \
+          hello      \
+          mandelbrot \
+          mousetest  \
+          multdemo   \
+          nachtm     \
+          ovrldemo   \
+          plasma     \
+          sieve      \
+          tgidemo
 
 # --------------------------------------------------------------------------
-# Rules how to make each one of the binaries
+# Rules to make the binaries
 
-.PHONY:        all
-all:           $(EXELIST)
+all:
 
-ascii:                 $(CRT0) ascii.o $(CLIB)
-       @$(LD) -t $(SYS) -m $(basename $@).map -o $@ $^
+samples: $(EXELIST)
 
-diodemo:        $(CRT0) diodemo.o $(CLIB)
-       @$(LD) -t $(SYS) -m $(basename $@).map -o $@ $^
+# --------------------------------------------------------------------------
+# Overlay rules. Overlays need special ld65 configuration files.  Also, the
+# overlay file-names are shortenned to fit the Atari's 8.3-character limit.
 
-fire:                  $(CRT0) fire.o $(CLIB)
-       @$(LD) -t $(SYS) -m $(basename $@).map -o $@ $^
+multdemo: multidemo.o
+       $(LD) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(CLIB)
 
-gunzip65:              $(CRT0) gunzip65.o $(CLIB)
-       @$(LD) -t $(SYS) -m $(basename $@).map -o $@ $^
+ovrldemo: overlaydemo.o
+       $(LD) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(CLIB)
 
-hello:                 $(CRT0) hello.o $(CLIB)
-       @$(LD) -t $(SYS) -m $(basename $@).map -o $@ $^
+OVERLAYLIST := $(foreach I,1 2 3,multdemo.$I ovrldemo.$I)
 
-# The apple machines need the start address adjusted for the mandelbrot demo
-ifeq "$(SYS)" "apple2"
-mandelbrot:     $(CRT0) mandelbrot.o $(CLIB)
-       @$(LD) -t $(SYS) -m $(basename $@).map --start-addr 0x4000 -o $@ $^
-else
-ifeq "$(SYS)" "apple2enh"
-mandelbrot:     $(CRT0) mandelbrot.o $(CLIB)
-       @$(LD) -t $(SYS) -m $(basename $@).map --start-addr 0x4000 -o $@ $^
-else
-mandelbrot:     $(CRT0) mandelbrot.o $(CLIB)
-       @$(LD) -t $(SYS) -m $(basename $@).map -o $@ $^
-endif
-endif
+# --------------------------------------------------------------------------
+# Rule to make a CBM disk with all samples. Needs the c1541 program that comes
+# with the VICE emulator.
 
-# The Apple ][ needs the start address adjusted for the mousedemo
-ifeq "$(SYS)" "apple2"
-mousedemo:             $(CRT0) mousedemo.o $(CLIB)
-       @$(LD) -t $(SYS) -m $(basename $@).map --start-addr 0x4000 -o $@ $^
-else
-mousedemo:             $(CRT0) mousedemo.o $(CLIB)
-       @$(LD) -t $(SYS) -m $(basename $@).map -o $@ $^
-endif
+d64: samples.d64
 
-nachtm:                $(CRT0) nachtm.o $(CLIB)
-       @$(LD) -t $(SYS) -m $(basename $@).map -Ln $(basename $@).lbl -o $@ $^
+define D64_WRITE_recipe
 
-plasma:                $(CRT0) plasma.o $(CLIB)
-       @$(LD) -t $(SYS) -m $(basename $@).map -o $@ $^
+$(C1541) -attach $@ -write $(file) $(notdir $(file)) >$(NULLDEV)
 
-sieve:                 $(CRT0) sieve.o $(CLIB)
-       @$(LD) -t $(SYS) -m $(basename $@).map -o $@ $^
+endef # D64_WRITE_recipe
 
-# The apple machines need the start address adjusted for the tgidemo
-ifeq "$(SYS)" "apple2"
-tgidemo:               $(CRT0) tgidemo.o $(CLIB)
-       @$(LD) -t $(SYS) -m $(basename $@).map --start-addr 0x4000 -o $@ $^
-else
-ifeq "$(SYS)" "apple2enh"
-tgidemo:               $(CRT0) tgidemo.o $(CLIB)
-       @$(LD) -t $(SYS) -m $(basename $@).map --start-addr 0x4000 -o $@ $^
-else
-tgidemo:               $(CRT0) tgidemo.o $(CLIB)
-       @$(LD) -t $(SYS) -m $(basename $@).map -o $@ $^
-endif
-endif
+samples.d64: samples
+       @$(C1541) -format samples,AA  d64 $@ >$(NULLDEV)
+       $(foreach file,$(EXELIST),$(D64_WRITE_recipe))
+       $(foreach file,$(OVERLAYLIST),$(D64_WRITE_recipe))
+       $(foreach file,$(TGI) $(MOUS),$(D64_WRITE_recipe))
 
 # --------------------------------------------------------------------------
-# Rule to make a disk with all samples. Needs the c1541 program that comes
-# with the VICE emulator.
-
-.PHONY:        disk
-disk:          samples.d64
-
-samples.d64:   all
-       @$(C1541) -format samples,AA  d64 $@ > /dev/null
-       @for exe in $(EXELIST); do\
-           $(C1541) -attach $@ -write $$exe > /dev/null;\
-       done;\
-       for tgi in ../libsrc/$(SYS)*.tgi; do\
-           $(C1541) -attach $@ -write $$tgi > /dev/null;\
-       done;
+# Installation rules
+
+INSTALL = install
+samplesdir = $(prefix)/share/cc65
+
+install:
+       $(if $(prefix),,$(error variable `prefix' must be set))
+       $(INSTALL) -d $(DESTDIR)$(samplesdir)
+       $(INSTALL) -d $(DESTDIR)$(samplesdir)/geos
+       $(INSTALL) -d $$(DESTDIR)$(samplesdir)/tutorial
+       $(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
 
 # --------------------------------------------------------------------------
-# Cleanup rules
-
-.PHONY:        clean
-clean:
-       $(RM) *~ *.map *.o *.s *.lbl
-
-.PHONY:        zap
-zap:   clean
-       $(RM) $(EXELIST) samples.d64
+# Packaging rules
 
+zip:
+       @cd .. && zip -r cc65 samples/
 
+# --------------------------------------------------------------------------
+# Clean-up rules
 
+mostlyclean:
+       @$(DEL) *.map *.o *.s 2>$(NULLDEV)
 
+clean: mostlyclean
+       @$(DEL) $(EXELIST) samples.d64 2>$(NULLDEV)
+       @$(DEL) multdemo.? ovrldemo.? 2>$(NULLDEV)