SUBARCH_SUPPORTED = powerpc powerpc64 e500mc # apus prep

KERNELMAJOR = 2.6
BASEVERSION = 5.0.0-13

# create the kernels with builtin initrd.
builtin_initrd: $(TEMP_KERNEL) $(TEMP_INITRD)
	# temporary hack
	case $(KERNELMAJOR) in \
		2.6)	\
			for subarch in $(SUBARCHES); do	\
				rm -f $(DEST)/vmlinuz-$$subarch.initrd;	\
				mkvmlinuz -v				\
					-a $$subarch			\
					-r $(KERNELVERSION)		\
					-k $(TEMP_KERNEL)		\
					-z -i $(TEMP_INITRD)		\
					-o $(DEST)/vmlinuz-$$subarch.initrd;	\
			done	\
			;;	\
		*)	\
			echo "Kernel $(KERNELMAJOR) not supported"	\
			;;\
	esac

# cd content for powerpc, includes yaboot for booting 
# apple powerpc (newworld) computers
cd_content_common:
	mkdir -p $(TEMP_CD_TREE)/$(dir install/$(TYPE))

	cp $(TEMP_KERNEL) $(TEMP_CD_TREE)/install/$(TYPE)-linux
	ln -f $(TEMP_INITRD) $(TEMP_CD_TREE)/install/$(TYPE)-initrd.gz

	# New-world bootability
	bootvars-subst DISTRIBUTION_NAME "${DISTRIBUTION_NAME}" \
		< boot/powerpc/ofboot.b > $(TEMP_CD_TREE)/install/ofboot.b
	cp -f /usr/lib/yaboot/yaboot $(TEMP_CD_TREE)/install/
	bootvars-subst MEDIA_TYPE "${MEDIA_TYPE}" \
		DISTRIBUTION_NAME "${DISTRIBUTION_NAME}" \
		DEBIAN_VERSION "${DEBIAN_VERSION}" \
		BUILD_DATE "${BUILD_DATE}" \
		< boot/powerpc/boot.msg > $(TEMP_CD_TREE)/install/boot.msg
	ramdisk-size-subst $(TEMP_INITRD) \
		< boot/powerpc/yaboot.conf \
		| sed 's,\$${TYPE},$(TYPE),g' \
		| bootvars-subst DISTRIBUTION_NAME "${DISTRIBUTION_NAME}" \
			DEBIAN_VERSION "${DEBIAN_VERSION}" \
		> $(TEMP_CD_TREE)/install/yaboot.conf
	# CHRP bootability
	mkdir -p $(TEMP_CD_TREE)/etc
	mkdir -p $(TEMP_CD_TREE)/ppc/chrp
	cp -f $(TEMP_CD_TREE)/install/yaboot.conf $(TEMP_CD_TREE)/etc
	cp -f boot/powerpc/bootinfo.txt $(TEMP_CD_TREE)/ppc

# Adds yaboot to netboot dirs.
netboot_content_common:
	cp -f /usr/lib/yaboot/yaboot $(DEST)
	bootvars-subst MEDIA_TYPE "${MEDIA_TYPE}" \
		DISTRIBUTION_NAME "${DISTRIBUTION_NAME}" \
		DEBIAN_VERSION "${DEBIAN_VERSION}" \
		BUILD_DATE "${BUILD_DATE}" \
		< boot/powerpc/boot.msg > $(DEST)/boot.msg
	ramdisk-size-subst $(TEMP_INITRD) \
	< boot/powerpc/yaboot.conf.netboot \
	| sed 's,\$${TYPE},$(TYPE),g' \
	> $(DEST)/yaboot.conf

# creates a bootable cd image for powerpc
arch_miniiso_common: cd_content_common
	genisoimage -r -T --netatalk -chrp-boot -iso-level 4 -hfs -probe -map boot/powerpc/hfs.map -part -no-desktop -hfs-bless $(TEMP_CD_TREE)/install -hfs-volid Debian-Installer/PPC -o $(TEMP_MINIISO) $(TEMP_CD_TREE)

# creates a bootable HFS filesystem, used for USB sticks
hd_media_common: $(TEMP_KERNEL) $(TEMP_INITRD)
	mkdir -p $(dir $(TEMP_BOOT))
	: | dd of=$(TEMP_BOOT) bs=1024 seek=$(FLOPPY_SIZE)
	HOME=$(TEMP) hformat -l $(DISK_LABEL) $(TEMP_BOOT)
	HOME=$(TEMP) hmount $(TEMP_BOOT)
	HOME=$(TEMP) hcopy -r $(TEMP_KERNEL) :vmlinux
	HOME=$(TEMP) hcopy -r $(TEMP_INITRD) :initrd.gz
	cp -a /usr/lib/yaboot/yaboot $(TEMP)/yaboot # used later
	HOME=$(TEMP) hcopy -r $(TEMP)/yaboot :yaboot
	HOME=$(TEMP) hattrib -c UNIX -t tbxi :yaboot

	bootvars-subst MEDIA_TYPE "${MEDIA_TYPE}" \
		DISTRIBUTION_NAME "${DISTRIBUTION_NAME}" \
		DEBIAN_VERSION "${DEBIAN_VERSION}" \
		BUILD_DATE "${BUILD_DATE}" \
		< boot/powerpc/boot.msg > $(TEMP)/boot.msg
	ramdisk-size-subst $(TEMP_INITRD) \
		< boot/powerpc/yaboot.conf.hd-media \
		| bootvars-subst DISTRIBUTION_NAME "${DISTRIBUTION_NAME}" \
			DEBIAN_VERSION "${DEBIAN_VERSION}" \
		> $(TEMP)/yaboot.conf
	HOME=$(TEMP) hcopy -r $(TEMP)/boot.msg :boot.msg
	HOME=$(TEMP) hcopy -r $(TEMP)/yaboot.conf :yaboot.conf

	HOME=$(TEMP) hattrib -b :
	HOME=$(TEMP) humount
	rm -f $(TEMP)/.hcwd # clean up after hfsutils

	$(if $(GZIPPED),gzip -v9f $(TEMP_BOOT))


arch_tree:
