
TMPDIR_BOOT = $(TMPDIR)/boot
TMPDIR_MAIN = $(TMPDIR)/main

# Generate a .mkisofs file with info strings
.mkisofsrc:
	echo ABST="$(ABST)" >  $@
	echo APPI="$(APPI)" >> $@
	echo BIBL="$(BIBL)" >> $@
	echo COPY="$(COPY)" >> $@
	echo PREP="$(PREP)" >> $@
	echo PUBL="$(PUBL)" >> $@
	echo SYSI="$(SYSI)" >> $@
	echo VOLS="$(VOLS)" >> $@

# Create the tmpdir (remove it, if it did exist before)
define init-tmpdir
	rm -rf $(TMPDIR)
	mkdir -p $(TMPDIR_MAIN)/debian
endef

# Create a dists/ subdir in debian/ subdir of the tmpdir.
define init-dists
	# Hack for frozen
	(cd $(ARCHIVE); cp -dpRPl dists/$(STATUS) $(TMPDIR_MAIN)/debian)
	-ln -s $(STATUS) $(TMPDIR_MAIN)/debian/dists/stable
	-ln -s ../hamm $(TMPDIR_MAIN)/debian/dists/hamm
endef

# Install doc files
define install-doc
	(cd $(ARCHIVE); cp -dpRPl \
		doc README* \
		$(TMPDIR_MAIN)/debian );
endef

# Install architecture independent main/ binaries
define install-main-all
	(cd $(ARCHIVE); cp -dpRPl \
		hamm/hamm/binary-all\
		$(TMPDIR_MAIN)/debian );
endef

# Install binaries for main/i386
define install-main-arch
	(cd $(ARCHIVE); cp -dpRPl \
		hamm/hamm/binary-$(subst binary-,,$@)\
		hamm/hamm/disks-$(subst binary-,,$@)\
		hamm/Contents-$(subst binary-,,$@).gz\
		$(TMPDIR_MAIN)/debian );
	ln -s hamm $(TMPDIR_MAIN)/debian/hamm/main
endef

define install-tools-i386
	(cd $(ARCHIVE); cp -dpRPl \
		tools \
		$(TMPDIR_MAIN)/debian );
endef

define install-source
	(cd $(ARCHIVE); cp -dpRPl \
		hamm/hamm/source\
		$(TMPDIR_MAIN)/debian);
	ln -s hamm $(TMPDIR_MAIN)/debian/hamm/main
	rm -rf $(TMPDIR_MAIN)/debian/hamm/hamm/source/x11
	echo "x11/ was move to the contrib cdrom, the whole source did not fit." | todos > $(TMPDIR_MAIN)/debian/hamm/hamm/source/x11.note
endef

define install-source-x11
	mkdir $(TMPDIR_MAIN)/debian/hamm
	# did not fit on the source cdrom
	(cd $(ARCHIVE); cp -dpRPl \
		hamm/hamm/source/x11 $(TMPDIR_MAIN)/debian)
endef

define install-contrib
	(cd $(ARCHIVE); cp -dpRPl \
		hamm/contrib/source \
		hamm/contrib/binary-all \
		hamm/contrib/binary-i386 \
		hamm/contrib/binary-m68k \
		$(TMPDIR_MAIN)/debian)
endef

define install-non-US
	mkdir -p $(TMPDIR_MAIN)/debian/hamm/non-US 
	(cd $(NON-US);  cp -dpRl source \
		binary-i386 binary-m68k binary-all \
		$(TMPDIR_MAIN)/debian/hamm/non-US)
endef

define boot-i386
	mkdir -p -m 755 $(TMPDIR_BOOT)/boot
	cp $(RELEASE)/hamm/disks-i386/current/resc1440.bin \
		$(TMPDIR_BOOT)/boot
endef

define boot-i386-tecra
	mkdir -p -m 755 $(TMPDIR_BOOT)/boot
	cp $(RELEASE)/hamm/disks-i386/current/resc1440tecra.bin \
		$(TMPDIR_BOOT)/boot
endef

define mkisofs-main-i386
	(cat README.cdrom; echo "This is the binary i386 cdrom" ) \
		|todos > $(TMPDIR_MAIN)/README

	$(MKISOFS) -V "$(VOLI) : binary i386 cdrom" \
 	-b boot/resc1440.bin -c boot/boot.catalog \
 	-o $(IMAGEPATH)/.binary-i386.tmp $(TMPDIR_BOOT) $(TMPDIR_MAIN)
	mv $(IMAGEPATH)/.binary-i386.tmp $(IMAGEPATH)/binary-i386.raw
endef

define mkisofs-main-arch
	(cat README.cdrom; echo "This is the binary $(subst binary-,,$@) cdrom" ) \
		|todos > $(TMPDIR_MAIN)/README

	$(MKISOFS) -V "$(VOLI) : binary $(subst binary-,,$@) cdrom" \
 	-o $(IMAGEPATH)/.binary-$(subst binary-,,$@).tmp $(TMPDIR_MAIN)
	mv $(IMAGEPATH)/.binary-$(subst binary-,,$@).tmp $(IMAGEPATH)/binary-$(subst binary-,,$@).raw
endef

define mkisofs-source
	(cat README.cdrom; echo "This is the source cdrom" ) \
		|todos > $(TMPDIR_MAIN)/README

	$(MKISOFS) -V "$(VOLI) : source cdrom" \
 	-b boot/resc1440tecra.bin -c boot/boot.catalog \
 	-o $(IMAGEPATH)/.source.tmp $(TMPDIR_BOOT) $(TMPDIR_MAIN)
	mv $(IMAGEPATH)/.source.tmp $(IMAGEPATH)/source.raw
endef

define mkisofs-contrib
	(cat README.cdrom; echo "This is the contrib cdrom (without non-US)" ) \
		|todos > $(TMPDIR_MAIN)/README

	$(MKISOFS) -V "$(VOLI) : contrib cdrom" \
 	-o $(IMAGEPATH)/.contrib.tmp $(TMPDIR_MAIN)
	mv $(IMAGEPATH)/.contrib.tmp $(IMAGEPATH)/contrib.raw
endef

define mkisofs-contrib-non-US
	(cat README.cdrom; echo "This is the contrib cdrom (with non-US)" ) \
		|todos > $(TMPDIR_MAIN)/README

	$(MKISOFS) -V "$(VOLI) : contrib cdrom" \
 	-o $(IMAGEPATH)/.contrib-non-US.tmp $(TMPDIR_MAIN)
	mv $(IMAGEPATH)/.contrib-non-US.tmp $(IMAGEPATH)/contrib-non-US.raw
endef

define rm-tmpdir
	rm -rf $(TMPDIR)
endef

define install-i386
	mkdir -m 755 $(TMPDIR_MAIN)/install
	(cd $(RELEASE)/hamm/disks-i386/current/ ; \
		cp resc1440*.bin linux root.bin\
			install.txt install.html $(TMPDIR_MAIN)/install )

	cp $(TMPDIR_MAIN)/tools/lodlin16/*.exe $(TMPDIR_MAIN)/install
	cp $(TMPDIR_MAIN)/tools/rawrite1/rawrite3.com $(TMPDIR_MAIN)/install/rw1_3.com
	cp $(TMPDIR_MAIN)/tools/rawrite2/rawrite2.exe $(TMPDIR_MAIN)/install/rw2_0.exe
	cp $(TMPDIR_MAIN)/tools/fips15c/*.exe $(TMPDIR_MAIN)/install

	(echo "@ echo off" ; \
	echo "rem Flush any write-cached disk blocks before we leave DOS. " ; \
	echo "smartdrv /c" ; \
	echo "loadlin.exe linux root=/dev/ram ro initrd=root.bin" ; \
	) |todos > $(TMPDIR_MAIN)/install/boot.bat
endef

define tools-i386
	mkdir $(TMPDIR_MAIN)/tools
	mkdir $(TMPDIR_MAIN)/tools/fips15
	(cd $(TMPDIR_MAIN)/tools/fips15; \
		unzip -Lq $(ARCHIVE)/tools/fips15.zip; \
		rm restorrb source -rf)

	(cd $(TMPDIR_MAIN)/tools/; \
		unzip -Lq $(ARCHIVE)/tools/fips15c.zip; \
		cd fips15c ; \
		rm restorrb source -rf)

	(cd $(TMPDIR_MAIN)/tools; \
		unzip -Lq $(ARCHIVE)/tools/lodlin16.zip; \
		rm lodlin16/src lodlin16/initrd loadlin16/debian -rf)

	mkdir $(TMPDIR_MAIN)/tools/rawrite1
	(cd $(TMPDIR_MAIN)/tools/rawrite1; \
		unzip -Lq $(ARCHIVE)/tools/rawrite1.zip )

	mkdir $(TMPDIR_MAIN)/tools/rawrite2
	(cd $(TMPDIR_MAIN)/tools/rawrite2; \
		unzip -Lq $(ARCHIVE)/tools/rawrite2.zip; \
		rm rawrite2.c )
	(echo "Tools for DOS :" ; \
echo "fips15/         non-destructively shorten a FAT partition" ; \
echo "fips15c/        An update to fips to support FAT32" ; \
echo "lodlin16/       load Linux kernel from DOS" ;\
echo "rawrite1/       rawrite 1.3 : create disks from disk images (*.bin)"; \
echo "rawrite2/       rawrite 2.0 : create disks from disk images (*.bin)"; \
echo "         rawrite 2.0 is much faster, but it locks up on some machines";\
) |todos > $(TMPDIR_MAIN)/tools/README
endef

define upgrade-i386
	cp -dpRl $(ARCHIVE)/hamm/hamm/upgrade-$(subst binary-,,$@)\
		$(TMPDIR_MAIN)/upgrade
	# HACK to get apt onto the CD somewhere
	cp -dl $(ARCHIVE)/dists/slink/main/binary-i386/admin/apt_*.deb \
		$(TMPDIR_MAIN)/install
endef

image-md5sum:
	cd $(IMAGEPATH) ; md5sum *.raw > MD5SUMS
	
image-date:
	rm -f $(IMAGEPATH)/Debian-2.0-Beta*
	touch `TZ=GMT date +$(IMAGEPATH)/Debian-2.0-Beta-CD-Images-%d-%b-%Y-%H:%M-GMT`

image-readme:
	cp README.images $(IMAGEPATH)
	cp README.official $(IMAGEPATH)
	cp README.cdwrite $(IMAGEPATH)
	cp README.get $(IMAGEPATH)
	cp README.contrib $(IMAGEPATH)
