#!/bin/sh
#
# Shell script to generate netboot distribution

# We need the bash because of some shell variable substitutions
if [ -z $BASH_VERSION ]; then
	echo "$0 requires the GNU bash"
	exit 1
fi

# Determine the netboot base directory
case "$0" in
  */misc/makedist)	ROOTDIR="${0%/misc/makedist}"
			;;
  */makedist)		ROOTDIR="${0%/makedist}/.."
			;;
  *)			ROOTDIR=".."
			;;
esac
if [ ! -d $ROOTDIR -o ! -d $ROOTDIR/misc/config ]; then
	echo "$0: unable to determine netboot base directory"
	exit 1
fi
cd $ROOTDIR
ROOTDIR=`pwd`

# Determine current configuration and cleanup 
./configure --sysconfdir= --enable-bootrom
trap 'rm -f config.tmp' 0
cp config.cache config.tmp
make realclean

# Restore configuration information
cd $ROOTDIR/misc/config
make all
cd $ROOTDIR
mv config.tmp config.cache

# Make everything
./configure --sysconfdir= --enable-bootrom
make distrib

# Cleanup at the end
make distclean

# Create the distribution archive
. $ROOTDIR/version
if [ -n "$PATCHLEVEL" -a "$PATCHLEVEL" -gt 0 ]; then
	VERSION="$VER_MAJOR.$VER_MINOR.$PATCHLEVEL"
else
	VERSION="$VER_MAJOR.$VER_MINOR"
fi
if [ -r $ROOTDIR/bootrom/headers/general.h ]; then
	cd $ROOTDIR/..
	tar czf netboot-$VERSION.tar.gz netboot
fi

