]> git.sur5r.net Git - cc65/blobdiff - samples/Makefile
Made the samples Makefile be able to build the samples for targets other than the...
[cc65] / samples / Makefile
index bbf69c8202cd8017de5f1545f5e861dc00156821..8bb6d25ae1e77a346597607d233a549f2fa58544 100644 (file)
@@ -4,8 +4,9 @@
 # This Makefile requires GNU make
 #
 
-# Run 'make samples SYS=<target>' to build for another target system
-SYS = c64
+# Run 'make SYS=<target>'; or, set a SYS env.
+# var. to build for another target system.
+SYS ?= c64
 
 ifneq ($(shell echo),)
   CMD_EXE = 1
@@ -33,29 +34,34 @@ else
   LD := $(if $(wildcard ../bin/ld65*),../bin/ld65,ld65)
 endif
 
-TARGET_PATH := $(shell $(CL) --print-target-path)
+ifneq ($(filter disk samples.%,$(MAKECMDGOALS)),)
+  TARGET_PATH := $(shell $(CL) --print-target-path)
 
-EMD := $(wildcard $(TARGET_PATH)/$(SYS)/drv/emd/*)
-MOU := $(wildcard $(TARGET_PATH)/$(SYS)/drv/mou/*)
-TGI := $(wildcard $(TARGET_PATH)/$(SYS)/drv/tgi/*)
+  EMD := $(wildcard $(TARGET_PATH)/$(SYS)/drv/emd/*)
+  MOU := $(wildcard $(TARGET_PATH)/$(SYS)/drv/mou/*)
+  TGI := $(wildcard $(TARGET_PATH)/$(SYS)/drv/tgi/*)
 
-# This one comes with VICE
-C1541 ?= c1541
+  # This one comes with the VICE emulator.
+  # See http://vice-emu.sourceforge.net/
+  C1541 ?= c1541
 
-# For this one see http://applecommander.sourceforge.net/
-AC ?= ac.jar
+  # For this one, see https://applecommander.github.io/
+  AC ?= ac.jar
 
-# For this one see http://www.horus.com/~hias/atari/
-DIR2ATR ?= dir2atr
+  # For this one, see http://www.horus.com/~hias/atari/
+  DIR2ATR ?= dir2atr
 
-DISK_c64       = samples.d64
-DISK_apple2    = samples.dsk
-DISK_apple2enh = samples.dsk
-DISK_atari     = samples.atr
-DISK_atarixl   = samples.atr
+  DISK_c64       = samples.d64
+  DISK_apple2    = samples.dsk
+  DISK_apple2enh = samples.dsk
+  DISK_atari     = samples.atr
+  DISK_atarixl   = samples.atr
+endif
 
 # --------------------------------------------------------------------------
 # System-dependent settings
+# For convenience, these groups and lines are sorted alphabetically, first
+# by target-machine group, then by mission, then by program and sub-target.
 
 # The Apple machines need the start address adjusted when using TGI
 LDFLAGS_mandelbrot_apple2    = --start-addr 0x4000
@@ -63,8 +69,8 @@ LDFLAGS_mandelbrot_apple2enh = --start-addr 0x4000
 LDFLAGS_tgidemo_apple2       = --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 Apple ][ needs the start address adjusted for the mousedemo
+LDFLAGS_mousedemo_apple2 = --start-addr 0x4000
 
 # The Apple machines need the end address adjusted for large programs
 LDFLAGS_gunzip65_apple2    = -D __HIMEM__=0xBF00
@@ -87,19 +93,23 @@ LDFLAGS_tgidemo_atarixl    = --start-addr 0x4000
 %: %.s
 
 .c.o:
-       $(CC) $(CFLAGS) -Oirs --codesize 500 -T -g -t $(SYS) $<
+       $(CC) $(CFLAGS) -Ors --codesize 500 -T -g -t $(SYS) $<
        $(AS) $(<:.c=.s)
 
 .s.o:
-       $(AS) $(AFLAGS) -t $(SYS) $<
+       $(AS) $(ASFLAGS) -t $(SYS) $<
 
 .PRECIOUS: %.o
 
 .o:
-       $(LD) $(LDFLAGS_$(@F)_$(SYS)) -o $@ -t $(SYS) -m $@.map $^ $(SYS).lib
+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
 
 # --------------------------------------------------------------------------
-# List of executables
+# Lists of executables
 
 EXELIST_c64 =      \
         ascii      \
@@ -108,7 +118,7 @@ EXELIST_c64 =      \
         gunzip65   \
         hello      \
         mandelbrot \
-        mousetest  \
+        mousedemo  \
         multdemo   \
         nachtm     \
         ovrldemo   \
@@ -123,7 +133,7 @@ EXELIST_apple2 =   \
         gunzip65   \
         hello      \
         mandelbrot \
-        mousetest  \
+        mousedemo  \
         multdemo   \
         ovrldemo   \
         sieve      \
@@ -136,7 +146,7 @@ EXELIST_atari =    \
         gunzip65   \
         hello      \
         mandelbrot \
-        mousetest  \
+        mousedemo  \
         multdemo   \
         ovrldemo   \
         sieve      \
@@ -144,24 +154,34 @@ EXELIST_atari =    \
 
 EXELIST_atarixl = $(EXELIST_atari)
 
+EXELIST_atari2600 = \
+        atari2600hello
+
+# 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
+
 # --------------------------------------------------------------------------
 # Rules to make the binaries and the disk
 
-all:
-
 samples: $(EXELIST_$(SYS))
 
 disk: $(DISK_$(SYS))
 
+all:
+
 # --------------------------------------------------------------------------
 # Overlay rules. Overlays need special ld65 configuration files.  Also, the
 # overlay file-names are shortenned to fit the Atari's 8.3-character limit.
 
 multdemo: multidemo.o
-       $(LD) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(SYS).lib
+       $(LD) $(LDFLAGS) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(SYS).lib
 
 ovrldemo: overlaydemo.o
-       $(LD) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(SYS).lib
+       $(LD) $(LDFLAGS) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(SYS).lib
 
 OVERLAYLIST := $(foreach I,1 2 3,multdemo.$I ovrldemo.$I)
 
@@ -182,15 +202,15 @@ samples.d64: samples
        $(foreach file,$(EMD) $(MOU) $(TGI),$(D64_WRITE_recipe))
 
 # --------------------------------------------------------------------------
-# Rule to make an Apple II disk with all samples. Needs the Apple Commander
-# program available at http://applecommander.sourceforge.net/ and a template
-# disk named 'prodos.dsk'.
+# Rule to make an Apple II disk with all samples. Needs the AppleCommander
+# program, available at https://applecommander.github.io/, and a template disk
+# named 'prodos.dsk'.
 
 define DSK_WRITE_BIN_recipe
 
 $(if $(findstring BF00,$(LDFLAGS_$(notdir $(file))_$(SYS))), \
   java -jar $(AC) -p $@ $(notdir $(file)).system sys <$(TARGET_PATH)/$(SYS)/util/loader.system)
-java -jar $(AC) -cc65 $@ $(notdir $(file)) bin <$(file)
+java -jar $(AC) -as $@ $(notdir $(file)) <$(file)
 
 endef # DSK_WRITE_BIN_recipe
 
@@ -231,13 +251,13 @@ samples.atr: samples
 # Installation rules
 
 INSTALL = install
-samplesdir = $(prefix)/share/cc65
+samplesdir = $(PREFIX)/share/cc65/samples
 
 install:
-       $(if $(prefix),,$(error variable `prefix' must be set))
+       $(if $(PREFIX),,$(error variable `PREFIX' must be set))
        $(INSTALL) -d $(DESTDIR)$(samplesdir)
        $(INSTALL) -d $(DESTDIR)$(samplesdir)/geos
-       $(INSTALL) -d $$(DESTDIR)$(samplesdir)/tutorial
+       $(INSTALL) -d $(DESTDIR)$(samplesdir)/tutorial
        $(INSTALL) -m0644 *.* $(DESTDIR)$(samplesdir)
        $(INSTALL) -m0644 README $(DESTDIR)$(samplesdir)
        $(INSTALL) -m0644 Makefile $(DESTDIR)$(samplesdir)
@@ -254,7 +274,7 @@ zip:
 # Clean-up rules
 
 mostlyclean:
-       @$(DEL) *.map *.o *.s 2>$(NULLDEV)
+       @$(DEL) *.lbl *.map *.o *.s 2>$(NULLDEV)
 
 clean: mostlyclean
        @$(DEL) $(EXELIST_$(SYS)) $(DISK_$(SYS)) 2>$(NULLDEV)