]> git.sur5r.net Git - cc65/blobdiff - samples/Makefile
Merge pull request #283 from polluks/sp65
[cc65] / samples / Makefile
index 7df3d004f7d1caca84ad27a43cd410dbb5da1574..951706ce6a50c674e1f670b2ae8b7f5065886149 100644 (file)
 # Enter the target system here
 SYS    = c64
 
-CRT0           = ../libsrc/$(SYS).o
-CLIB   = ../libsrc/$(SYS).lib
-CC     = ../src/cc65/cc65
-CL     = ../src/cl65/cl65
-AS     = ../src/ca65/ca65
-LD     = ../src/ld65/ld65
-C1541          = c1541
+# Determine the path to the executables and libraries. If the samples
+# 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
+MOUS = /usr/lib/cc65/mou/$(SYS)*.mou
+TGI  = /usr/lib/cc65/tgi/$(SYS)*.tgi
+ifneq "$(wildcard /usr/local/lib/cc65)" ""
+MOUS = /usr/local/lib/cc65/mou/$(SYS)*.mou
+TGI  = /usr/local/lib/cc65/tgi/$(SYS)*.tgi
+endif
+ifdef CC65_HOME
+MOUS = $(CC65_HOME)/mou/$(SYS)*.mou
+TGI  = $(CC65_HOME)/tgi/$(SYS)*.tgi
+endif
+CLIB = --lib $(SYS).lib
+CL   = cl65
+CC   = cc65
+AS   = ca65
+LD   = ld65
+
+else
+# "samples/" is a part of a complete source tree.
+export CC65_HOME := $(abspath ..)
+MOUS = ../mou/$(SYS)*.mou
+TGI  = ../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
 
+# --------------------------------------------------------------------------
+# 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
 
+%: %.c
+%: %.s
+
 .c.o:
        @echo $<
-       @$(CC) -Oirs -T --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)
 
 # --------------------------------------------------------------------------
-# Rules how to make each one of the binaries
+# List of executables. This list could be made target-dependent by checking
+# $(SYS).
+
+EXELIST        =       ascii           \
+               diodemo         \
+               enumdevdir      \
+               fire            \
+               gunzip65        \
+               hello           \
+               mandelbrot      \
+               mousetest       \
+               multdemo        \
+               nachtm          \
+               ovrldemo        \
+               plasma          \
+               sieve           \
+               tgidemo
 
-EXELIST=fire hello mousedemo nachtm plasma sieve tgidemo
+# --------------------------------------------------------------------------
+# Rules to make the binaries
 
 .PHONY:        all
-all:           $(EXELIST)
-
-fire:          $(CRT0) fire.o $(CLIB)
-       @$(LD) -t $(SYS) -m fire.map -Ln fire.lbl -o $@ $^
+all:   $(EXELIST)
 
-hello:                 $(CRT0) hello.o $(CLIB)
-       @$(LD) -t $(SYS) -m hello.map -Ln hello.lbl -o $@ $^
-
-mousedemo:             $(CRT0) mousedemo.o $(CLIB)
-       @$(LD) -t $(SYS) -m mousedemo.map -Ln mousedemo.lbl -o $@ $^
-
-nachtm:                $(CRT0) nachtm.o $(CLIB)
-       @$(LD) -t $(SYS) -vm -m nachtm.map -Ln nachtm.lbl -o $@ $^
-
-plasma:                $(CRT0) plasma.o $(CLIB)
-       @$(LD) -t $(SYS) -m plasma.map -Ln nachtm.lbl -o $@ $^
-
-sieve:                 $(CRT0) sieve.o $(CLIB)
-       @$(LD) -t $(SYS) -m sieve.map -Ln sieve.lbl -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.
 
-tgidemo:       $(CRT0) tgidemo.o $(CLIB)
-       @$(LD) -t $(SYS) -m tgidemo.map -Ln tgidemo.lbl -o $@ $^
+multdemo:      multidemo.o
+       @$(LD) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(CLIB)
 
+ovrldemo:      overlaydemo.o
+       @$(LD) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(CLIB)
 
 # --------------------------------------------------------------------------
-# Rule to make a disk with all samples. Needs the c1541 program that comes
+# Rule to make a CBM disk with all samples. Needs the c1541 program that comes
 # with the VICE emulator.
 
 .PHONY:        disk
-disk:          samples.d64
+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;
+           $(C1541) -attach $@ -write $$exe > /dev/null || exit $$?;\
+       done
+       @for mod in $(TGI) $(MOUS); do\
+           $(C1541) -attach $@ -write $$mod > /dev/null || exit $$?;\
+       done
 
 # --------------------------------------------------------------------------
-# Cleanup rules
+# Clean-up rules
 
 .PHONY:        clean
 clean:
-       rm -f *~ *.map *.o *.s *.lbl
+       $(RM) *~ *.map *.o *.s *.lbl
 
 .PHONY:        zap
 zap:   clean
-       rm -f $(EXELIST) samples.d64
-
-
-
-
+       $(RM) $(EXELIST) samples.d64
+       $(RM) multdemo.? ovrldemo.?