#!/bin/sh
#
# configure [ --floppy <floppy location> ]
#
# No parameters for now.

# usage
#
# Prints usage.
#
usage()
{
	cat << EOF

Usage: $0 <options>
options:
  --floppy <floppy location>    Specifies the location of the floppy
                                (device or image).
  --bochs-debug                 Activates bochs serial debug emulation.
  --help                        Prints out this help.
EOF
}

# assertparam
#
# Checks whether at least one parameter is left.
#
assertparam()
{
	if [ $2 \< 2 ]; then
		echo $0: \`$1\': Parameter expected.
		exit 1
	fi
}

# default parameter values
#
platform=`uname`
floppy=
bochs_debug=0

# parse parameters
#
while [ $# \> 0 ] ; do
	case "$1" in
		--floppy)		assertparam "$1" $#; floppy=$2; shift 2;;
		--bochs-debug)	bochs_debug=1; shift 1;;
		--help | -h)	usage; exit 0;;
		*)				echo Invalid argument: \`$1\'; exit 1;;
	esac
done

# check parameters
#
if [ -n "$floppy" ]; then
	case "$floppy" in
		/*)	;;
		*)	echo "Warning: non-absolute floppy path. Parameter ignored.";
			floppy=;;
	esac
fi

# BeOS
if [ "${platform}" == "BeOS" ] ; then
	# GGC_PATH
	if [ "x${GCC_PATH}" == "x" ] ; then
		gcclib=`gcc -print-libgcc-file-name`
		GCC_PATH=`dirname ${gcclib}`
	fi

# Linux
else if [ "${platform}" == "Linux" ] ; then
	# GGC_PATH
	if [ "x${GCC_PATH}" == "x" ] ; then
		gcclib=`gcc -print-libgcc-file-name`
		GCC_PATH=`dirname ${gcclib}`
	fi

# Unknown platform
else
	echo Unsupported platform: ${platform}
	exit 1
fi; fi

# Generate BuildConfig
cat << EOF > build/BuildConfig
# BuildConfig
# Note: This file has been automatically generated by configure.

FLOPPY_PATH		?= "$floppy" ;
GCC_PATH		?= ${GCC_PATH} ;
BOCHS_DEBUG_HACK	?= $bochs_debug ;
EOF