#!/bin/sh
# $Id: 4.kernel.sh,v 1.14 2004/10/15 20:45:19 saturnero Exp $

set -e -u

. ./config.sh
. ./.common.sh

if [ "x$MINIMAL" = "xYES" ]; then
    export __MAKE_CONF=$LOCALDIR/files/make.conf.minimal # Redefine make.conf path
else
    export __MAKE_CONF=$LOCALDIR/files/make.conf # Redefine make.conf path
fi

echo "Copying FreeSBIE configuration file in /usr/src/sys/i386/conf"

cp $LOCALDIR/files/FREESBIE.5 /usr/src/sys/i386/conf/FREESBIE || print_error
cp /usr/src/sys/i386/conf/GENERIC.hints $FREESBIEBASEDIR/boot/device.hints || print_error

if [ "x$MINIMAL" = "xYES" ]; then
    echo -n "Do you want to edit the kernel file? [N/y]: "
    read ANSWER
    if [ "${ANSWER}" = "Y" -o "${ANSWER}" = "y" ]; then
	if [ "x${EDITOR}" = "x" ]; then
	    EDITOR=/usr/bin/ee
	fi
        ${EDITOR} /usr/src/sys/i386/conf/FREESBIE
    fi
fi

echo "Building FreeSBIE kernel..."
sleep 1

cd /usr/src || print_error
$MAKE kernel DESTDIR=$FREESBIEBASEDIR $MAKEOPT || print_error

rm -f /usr/src/sys/i386/conf/FREESBIE

echo hint.psm.0.flags=\"0x100\" >> $FREESBIEBASEDIR/boot/device.hints || print_error
if [ "x$MINIMAL" = "xYES" ]; then
	echo "Compiling acpi"
	cd /usr/src/sys/modules/acpi
	$MAKE depend DESTDIR=$FREESBIEBASEDIR $MAKEOPT && \
	$MAKE DESTDIR=$FREESBIEBASEDIR $MAKEOPT && \
	$MAKE install DESTDIR=$FREESBIEBASEDIR $MAKEOPT
fi
    cd $FREESBIEBASEDIR/boot/kernel || print_error
    strip kernel || print_error
    gzip -f9 kernel || print_error

