# $Progeny: Makefile,v 1.3 2002/04/22 21:18:44 branden Exp $

SHELL=	/bin/sh -e

# XXX: put ISOLINUX support here

# initrd we're using, created by stage0
INITRD = $(TDIR)/initrd.installer.gz

# list of files to be placed on the boot media
INSTALLER_FILES = $(TDIR)/install $(TDIR)/boot.msg

# directory containing $(INSTALLER_FILES) and the live filesystem
INSTALLER_FILES_FS = $(TDIR)/installer-files.fs

# size (in kB) of the filesystem we will create to house yaboot, the kernel, etc.
IMAGE_SIZE = 10000

# What we build in this Makefile depends on our final product.
# If it's an installer-only ISO, we'll have everything we need,
# and can produce one here.  Otherwise, we'll merely generate
# files for the ISO that the archive/ directory will produce, and
# calculate the space these files will occupy, since that space
# will be unavailable for a package archive on the ISO.

ifdef INSTALLER_ONLY
MKISOFS=/usr/bin/mkisofs
MKISOFS_OPTS=-l
ISO=$(OUT)/$(CODENAME)-installer-$(ARCH).iso
else
# file containing calculated size of $(INSTALLER_FILES_FS) (see archive/Makefile)
INSTALLER_FILES_FS_SIZE = $(TDIR)/installer-files.fs.size
endif

all: $(INSTALLER_FILES_FS_SIZE) $(ISO)

# Create a banner message for yaboot.
$(TDIR)/boot.msg:
	echo "PGI $(PGI_VERSION)" > $@

# Create directory that contains yaboot, the kernel, and the
# initrd; everything we need to boot.
$(TDIR)/install: $(INITRD) $(TDIR)/boot.msg
	@echo Creating $$(basename $@)...
	mkdir $@.tmp
	install /boot/vmlinuz-$(KERNEL_VERSION) $@.tmp/linux || (rm -rf $@.tmp; exit 1)
	install $(INITRD) $@.tmp/initrd || (rm -rf $@.tmp; exit 1)
	install /usr/lib/yaboot/yaboot $@.tmp || (rm -rf $@.tmp; exit 1)
	install /usr/lib/yaboot/ofboot $@.tmp/ofboot.b || (rm -rf $@.tmp; exit 1)
	install yaboot.conf $@.tmp || (rm -rf $@.tmp; exit 1)
	install boot.msg $@.tmp || (rm -rf $@.tmp; exit 1)
	install ofboot.b $@.tmp || (rm -rf $@.tmp; exit 1)
	mv $@.tmp $@

# Create a directory tree containing everything that will be
# placed on the ISO (not including package archives, which are
# generated in archive/ if required).
$(INSTALLER_FILES_FS): $(INSTALLER_FILES)
	-rm -r $@.tmp $@
	mkdir $@.tmp
	cp -a $(INSTALLER_FILES) $@.tmp
	cp -a $(TDIR)/live/* $@.tmp
	mv $@.tmp $@

# Calculate the disk consumption of the files to be placed on the
# ISO, so we know how much less room will be available on the
# (first) ISO for use by a package archive.
$(INSTALLER_FILES_FS_SIZE): $(INSTALLER_FILES_FS)
	du -bs $(INSTALLER_FILES_FS) | awk '{print $$1}' > $@.tmp
	mv $@.tmp $@

# If we're building an installer-only ISO, create it now.
$(ISO): $(INSTALLER_FILES_FS)
	@echo "Generating the installer ISO image..."
	$(MKISOFS) $(MKISOFS_OPTS) -V "$(CODENAME) Installer" \
		--netatalk -hfs -probe -part -no-desktop -map hfs.map \
		-hfs-bless $(INSTALLER_FILES_FS)/install -o $@.tmp \
		$(INSTALLER_FILES_FS)
	mv --backup=numbered $@.tmp $@

clean:
	rm -rf \
	    $(INSTALLER_FILES) \
	    $(INSTALLER_FILES_FS) \
	    $(INSTALLER_FILES_FS_SIZE) \
	    $(TDIR)/install.empty \
	    $(TDIR)/install.image \
	    $(TDIR)/install.mnt \

distclean: clean

.PHONY: all clean distclean

# vim:set ai noet sw=8 sts=8 ts=8 tw=0:
