+define D64_WRITE_recipe
+
+$(C1541) -attach $@ -write "$(subst ?,$(SPACE),$(file))" $(notdir $(file)) >$(NULLDEV)
+
+endef # D64_WRITE_recipe
+
+samples.d64: samples
+ @$(C1541) -format samples,AA d64 $@ >$(NULLDEV)
+ $(foreach file,$(EXELIST_$(SYS)),$(D64_WRITE_recipe))
+ $(foreach file,$(OVERLAYLIST),$(D64_WRITE_recipe))
+ $(foreach file,$(EMD) $(MOU) $(TGI),$(D64_WRITE_recipe))
+
+# --------------------------------------------------------------------------
+# 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 <"$(wildcard $(TARGET_PATH)/$(SYS)/util/loader.system)")
+java -jar $(AC) -as $@ $(notdir $(file)) <"$(file)"
+
+endef # DSK_WRITE_BIN_recipe
+
+define DSK_WRITE_REL_recipe
+
+java -jar $(AC) -p $@ $(notdir $(file)) rel 0 <"$(subst ?,$(SPACE),$(file))"
+
+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
+
+cp "$(subst ?,$(SPACE),$(file))" atr/$(notdir $(file))
+
+endef # ATR_WRITE_recipe
+
+samples.atr: samples
+ @mkdir atr
+ cp "dos.sys" atr/dos.sys
+ cp "dup.sys" atr/dup.sys
+ @$(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
+
+# --------------------------------------------------------------------------
+# Installation rules
+
+INSTALL = install
+samplesdir = $(PREFIX)/share/cc65/samples
+
+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
+
+# --------------------------------------------------------------------------
+# Packaging rules