# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../grub/grub.conf
# Copyright (C) 2006 - 2007 The OpenSDE Project
# Copyright (C) 2004 - 2006 The T2 SDE Project
# Copyright (C) 1998 - 2003 Clifford Wolf
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---

grub_postmake() {
	mkdir -p $root/boot/grub

	trg=${arch_target/-linux-*}
	trg=i386-${trg/i*-/}

	cp -v $root$libdir/grub/$trg/* $root/boot/grub/
	cp -v docs/menu.lst $root/boot/grub/menu.lst.example

	counter=1
	confopt="$confopt --enable-diskless"
	{	echo
		echo "Driver-map for PXE and Etherboot 2nd stage GRUB images:"
		echo "======================================================="
		echo
	} > $root/boot/grub/README.pxe_nb
	while read drivers
	do
		eval "./configure $confopt --enable-${drivers// / --enable-}"
		make -C netboot clean; make
		{	echo "pxegrub.$counter and nbgrub.$counter:"
			echo "	$drivers"; echo
		} >> $root/boot/grub/README.pxe_nb
		cp stage2/pxegrub $root/boot/grub/pxegrub.$counter
		cp stage2/nbgrub  $root/boot/grub/nbgrub.$counter
		(( counter++ ))
	done < <(
		./configure --help | grep ' driver$' |
		cut -f4- -d- | cut -f1 -d' ' | sort -u |
		paste -d' ' - - - - - - -
	)
}

hook_add preconf 3 "aclocal;automake;autoconf"
hook_add postmake 5 "grub_postmake"
hook_add postmake 6 "cp  -fv $confdir/opensde-grub-splash.xpm.gz $root/boot/"

# Every other optimization would cause build errors like
#
# pre_stage2_exec-builtins.o: In function `terminfo_func':
# pre_stage2_exec-builtins.o(.text+0x3b0e): undefined reference to `memcpy'
#
var_append GCC_WRAPPER_APPEND " " "-Os"

if [ $arch = x86-64 ] ; then
	libdir=\$root/\$prefix/lib
	var_insert GCC_WRAPPER_INSERT " " "-m32"
	arch_target="`echo $arch_target | sed -e 's/[-_]*64//' -e 's/x86/i386/'`"
	echo_status "Set arch_target to $arch_target"
	set_confopt
fi