ARCHIVE=grub-0.97.tar.gz
DIR=grub-0.97
URL=ftp://alpha.gnu.org/gnu/grub/$(ARCHIVE)

GRUB_CFLAGS= -Os -fno-strict-aliasing -Wall -Werror -Wno-shadow -Wno-unused -Wno-pointer-sign

OUTPUT = sbootmgr.dsk memdisk.bin boot
all: $(OUTPUT)


boot: build sbootmgr.dsk memdisk.bin menu.lst splash.xpm.gz
	mkdir -p boot
	mkdir -p boot/grub
	cp $(DIR)/stage1/stage1		boot/grub/
	cp $(DIR)/stage2/stage2		boot/grub/
	cp $(DIR)/stage2/e2fs_stage1_5		boot/grub/
	cp $(DIR)/stage2/fat_stage1_5		boot/grub/
	#cp $(DIR)/stage2/ffs_stage1_5		boot/grub/
	#cp $(DIR)/stage2/iso9660_stage1_5	boot/grub/
	cp $(DIR)/stage2/jfs_stage1_5		boot/grub/
	#cp $(DIR)/stage2/minix_stage1_5	boot/grub/
	cp $(DIR)/stage2/reiserfs_stage1_5	boot/grub/
	#cp $(DIR)/stage2/ufs2_stage1_5		boot/grub/
	#cp $(DIR)/stage2/vstafs_stage1_5	boot/grub/
	cp $(DIR)/stage2/xfs_stage1_5		boot/grub/
	cp etherboot/*.zlilo		boot/
	cp memdisk.bin			boot/
	cp sbootmgr.dsk			boot/
	cp menu.lst				boot/grub/
	cp splash.xpm.gz			boot/grub/


sbootmgr.dsk:
	$(MAKE) -C sbm
	cp sbm/sbootmgr.dsk ./$@

memdisk.bin: ../syslinux
	cp ../syslinux/memdisk.bin ./$@

etherboot:
	$(MAKE) -C etherboot



build: $(DIR) grub-0.97-RHEL5.patch
	cd $(DIR) && patch -p1 < ../grub-0.97-RHEL5.patch
	cd $(DIR) && autoreconf --install --force
	CFLAGS="$(GRUB_CFLAGS)" cd $(DIR) && ./configure --disable-auto-linux-mem-opt
	CFLAGS="$(GRUB_CFLAGS)" $(MAKE) -C $(DIR)
	echo ok > $@

$(DIR): $(ARCHIVE)
	tar zxvf $(ARCHIVE)

$(ARCHIVE):
	wget $(URL)

.PHONY: clean distclean
clean:
	rm -f build
	$(MAKE) -C sbm clean
	$(MAKE) -C etherboot clean
	rm -f memdisk.bin
	rm -rf $(DIR)
	rm -rf $(OUTPUT)

distclean: clean
	rm -f $(ARCHIVE)
	$(MAKE) -C sbm distclean
	$(MAKE) -C etherboot distclean

