n=bootcd
m=/mnt/1
m2=/mnt/2

all: mksquashfs mkisofs
mkisofs: isoroot/live/filesystem.squashfs
	cd isoroot ; mkisofs -R -D -V $n -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table . > ../$n.iso

mksquashfs: rootfs
	rm -f isoroot/live/filesystem.squashfs
	time mksquashfs rootfs/ isoroot/live/filesystem.squashfs -comp gzip
	du -m isoroot/live/filesystem.squashfs

isoroot:
	wget -nc http://cdimage.debian.org/debian-cd/current-live/i386/iso-hybrid/debian-live-6.0.6-i386-standard.iso
	mkdir -p $m ${m2}
	mount -o loop debian-live-6.0.6-i386-standard.iso $m
	rsync -aSH $m/ isoroot/
	umount $m
	cd isoroot ; rm -rf pool install doc dists debian css README*

rootfs: isoroot
	wget -nc http://download.opensuse.org/distribution/11.4/iso/openSUSE-11.4-GNOME-LiveCD-i686.iso
	mount -o loop openSUSE-11.4-GNOME-LiveCD-i686.iso $m
	clicfs $m/openSUSE-gnome-11.4-livecd-gnome-read-only.i686-2.8.0 ${m2}
	mount -o loop ${m2}/fsdata.ext3 $m
	rsync -aSH $m/ rootfs/
	umount $m
	umount ${m2} ; sleep 3
	umount $m
	mount -o loop isoroot/live/filesystem.squashfs $m
	rsync -a $m/lib/modules/2.6.32-5-486 rootfs/lib/modules/
	umount $m
	rm -rf rootfs/lib/modules/2.6.37*
	touch $@
	# optional: remove some packages to fit on a CD inspite of gzip compression
	chroot rootfs bin/sh -c "rpm -qa | grep -e libreoffice -e orca -e icewm -e banshee | xargs rpm -e"
	chroot rootfs bin/sh -c "rpm -q --requires gnome-games-recommended | head -9 | xargs rpm -e gnome-games-recommended"

test:
	qemu-kvm -m 1000 -monitor stdio -cdrom $n.iso

