# How big a floppy image should I make? (in kilobytes)
FLOPPY_SIZE = 18432

MEDIUM_SUPPORTED = cdrom netboot

# The version of the kernel to use.
KERNELMAJOR = 2.6
KERNELVERSION = 2.6.32-5-itanium
KERNEL_FLAVOUR = di
KERNELNAME = vmlinuz
KERNELIMAGEVERSION = $(KERNELVERSION)

INITRD_FS = initramfs

# The DOS volume id to use for DOS floppies. This is a 32 bit hexidecimal
# number.
DOS_VOLUME_ID = deb00001
# The DOS volume label to use for DOS floppies. This is a 11 character
# string.
DOS_VOLUME_LABEL = "$(shell echo "$(DISTRIBUTION_NAME) Inst" | cut -b1-11)"


arch_tree:

# Create a bootable floppy image.
# 1. make a dos filesystem image
# 2. copy over kernel, initrd
# 3. copy over elilo files
.PHONY: arch_boot
arch_boot:
	dd if=/dev/zero of=$@.new bs=1k count=$(FLOPPY_SIZE)
	mkfs.msdos -i $(DOS_VOLUME_ID) -n $(DOS_VOLUME_LABEL) -C $(TEMP_BOOT) $(FLOPPY_SIZE)

	mmd -i$(TEMP_BOOT) ::/efi
	mmd -i$(TEMP_BOOT) ::/efi/boot
	mcopy -i$(TEMP_BOOT) $(TEMP_KERNEL) ::/linux
	mcopy -i$(TEMP_BOOT) $(TEMP_INITRD) ::/initrd.gz
	mcopy -i$(TEMP_BOOT) /usr/lib/elilo/elilo.efi ::/efi/boot/bootia64.efi
	mcopy -i$(TEMP_BOOT) /usr/lib/elilo/elilo.efi ::/elilo.efi
	
	cat boot/ia64/elilo.conf \
	| ramdisk-size-subst $(TEMP_INITRD) \
	| bootvars-subst MEDIA_TYPE "$(MEDIA_TYPE)" \
		DISTRIBUTION_NAME "$(DISTRIBUTION_NAME)" \
		DEBIAN_VERSION "$(DEBIAN_VERSION)" \
		BUILD_DATE "$(BUILD_DATE)" \
		SYSDIR "/efi/boot/" \
		KERNEL /linux INITRD /initrd.gz \
	> $(TEMP)/elilo-cd.conf
	mcopy -i$(TEMP_BOOT) $(TEMP)/elilo-cd.conf ::/elilo.conf
	mcopy -i$(TEMP_BOOT) $(TEMP)/elilo-cd.conf ::/efi/boot/elilo.conf
	
	$(foreach file,$(wildcard $(TEMP_BOOT_SCREENS)/*.msg), \
		mcopy -i$(TEMP_BOOT) $(file) ::/efi/boot/`basename $(file)`; \
	)
	echo "elilo linux" | mcopy -i$(TEMP_BOOT) - ::/install.nsh

arch_boot_screens:
	-rm -f $(TEMP_BOOT_SCREENS)/*
	mkdir -p $(TEMP_BOOT_SCREENS)
	$(foreach SCREEN,$(wildcard boot/ia64/*.msg boot/ia64/*.msg.live), \
		bootvars-subst MEDIA_TYPE "$(MEDIA_TYPE)" \
			DISTRIBUTION_NAME "$(DISTRIBUTION_NAME)" \
			DEBIAN_VERSION "$(DEBIAN_VERSION)" \
			BUILD_DATE "$(BUILD_DATE)" \
		 < $(SCREEN) > $(TEMP_BOOT_SCREENS)/`basename $(SCREEN)`\
	;)

# elilo CD info directory, including help screens and an elilo.conf.
# Note that the paths in the elilo.conf must match the paths used on the
# CD by debian-cd.
.PHONY: arch_cd_info_dir
arch_cd_info_dir:
	-rm -f $(TEMP_CD_INFO_DIR)/*
	mkdir -p $(TEMP_CD_INFO_DIR)
	
	cp -a $(TEMP_BOOT_SCREENS)/* $(TEMP_CD_INFO_DIR)

	cat boot/ia64/elilo.conf \
	| ramdisk-size-subst $(TEMP_INITRD) \
	| bootvars-subst MEDIA_TYPE "$(MEDIA_TYPE)" \
		DISTRIBUTION_NAME "$(DISTRIBUTION_NAME)" \
		DEBIAN_VERSION "$(DEBIAN_VERSION)" \
		BUILD_DATE "$(BUILD_DATE)" \
		SYSDIR "/elilo/" \
		KERNEL /install/vmlinuz INITRD /install/initrd.gz \
	> $(TEMP_CD_INFO_DIR)/elilo.conf

.PHONY: arch_miniiso
arch_miniiso: $(TEMP_BOOT)
	-rm -rf $(TEMP_CD_TREE)/*
	install -m 644 -D $(TEMP_BOOT) $(TEMP_CD_TREE)/boot/boot.img

	genisoimage -no-emul-boot -J -o $(TEMP_MINIISO) -b boot/boot.img \
		-c boot/boot.catalog $(TEMP_CD_TREE)

.PHONY: arch_netboot_dir
arch_netboot_dir:
	-rm -f $(TEMP_NETBOOT_DIR)
	mkdir -p $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)
	cp $(TEMP_INITRD) $(TEMP_KERNEL) $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)
	
	cp /usr/lib/elilo/elilo.efi $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)
	cat boot/ia64/elilo.conf \
	| ramdisk-size-subst $(TEMP_INITRD) \
	| bootvars-subst MEDIA_TYPE "$(MEDIA_TYPE)" \
		DISTRIBUTION_NAME "$(DISTRIBUTION_NAME)" \
		DEBIAN_VERSION "$(DEBIAN_VERSION)" \
		BUILD_DATE "$(BUILD_DATE)" \
		SYSDIR "$(BOOT_SCREEN_DIR)" \
		KERNEL vmlinuz INITRD initrd.gz \
	> $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)/elilo.conf

	mkdir -p $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)/$(BOOT_SCREEN_DIR)
	set -e; \
	$(foreach file,$(wildcard $(TEMP_BOOT_SCREENS)/*.msg), \
		cp $(file) $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)/$(BOOT_SCREEN_DIR); \
	)
