#! /bin/sh
#
# Configuration script for ftape.
#
# This script will create the kernel-version.h file that contains
# kernel version dependent settings.
#
# $Id: Configure,v 1.4 1995/05/06 16:11:53 bas Beta $
#
# Make sure we're running bash
[ -z "$BASH" ] && { echo "Configure requires bash !" 1>&2; exit 1; }
#
#
VERSION="/usr/include/linux/version.h"
CONFIG="/usr/include/linux/autoconf.h"
TARGET="kernel-version.h"

cat >$TARGET <<HERE
/*  
 *  Kernel options for ftape device driver
 *
 *  created by: `pwd`/$0
 *          on: `date`
 *
HERE

if cat $VERSION 2>/dev/null >/dev/null ;
then

#
# Use the kernel source code for version information and configuration options.
#
	echo " *  Used "$VERSION >>$TARGET
        echo " */" >>$TARGET

	grep UTS_RELEASE $VERSION >> $TARGET

	grep CONFIG_MODVERSIONS $CONFIG |
		sed s\\CONFIG_MODVERSIONS\\MODULE\\ >>$TARGET

	HOST=`grep LINUX_COMPILE_HOST $VERSION | cut -d"\"" -f2`

# Use for testing:
#	echo " *  Used dummy" >>$TARGET
#	echo " */" >>$TARGET
#	echo "#define UTS_RELEASE \"1.1.90\"" >>$TARGET
#	echo "#define MODULE 1" >>$TARGET

else

#
# Use the running kernel for version and configuration information.
#
	echo " *  Used /proc/version" >>$TARGET
	echo " */" >>$TARGET

	echo "#define UTS_RELEASE \"`cat /proc/version | cut -d" " -f3`\"" \
		>$TARGET

        if grep _Using_Versions /proc/ksyms >/dev/null 2>/dev/null ;
        then
		echo "#define MODULE 1" >>$TARGET
        else
		echo "#undef MODULE" >>$TARGET
	fi

	HOST=`cat /proc/version | cut -d"@" -f2 | cut -d")" -f1`

fi

#
# Now extract the version numbers for comparisons
#
declare -i MAJOR=`grep UTS_RELEASE $TARGET | \
	cut -d" " -f3 | cut -d\" -f2 | cut -d\. -f1`
declare -i MINOR=`grep UTS_RELEASE $TARGET | \
	cut -d" " -f3 | cut -d\" -f2 | cut -d\. -f2`
declare -i REVISION=`grep UTS_RELEASE $TARGET | \
	cut -d" " -f3 | cut -d\" -f2 | cut -d\. -f3`
declare -i VERSION=$REVISION+1000*$MINOR+1000000*$MAJOR

echo Building ftape for kernel version $MAJOR.$MINOR.$REVISION \($VERSION\)

#
# Add integer coded kernel version number for conditional compilation
#
echo "#define KERNEL_VERSION $VERSION" >>$TARGET
echo "#define FLOPPY_HACK (KERNEL_VERSION < 1001023)" >>$TARGET

#
# Special test to set a flag on my ftape development system
#
if [ $HOST = "dodo" ] ;
then
	echo "#define DODO 1" >>$TARGET
else
	echo "#define DODO 0" >>$TARGET
fi

#
# Done
#
exit
#

