#! /bin/sh
#
# Configuration script for ftape.
#
# This script will create the kernel-version.h file that contains
# kernel version dependent settings.
#
VERSION="/usr/include/linux/version.h"
CONFIG="/usr/include/linux/autoconf.h"
TARGET="kernel-version.h"

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

#
# Use the kernel source code for version information and configuration options.
#
	grep UTS_RELEASE $VERSION |
		sed s\\UTS_RELEASE\\KERNEL_VERSION\\ >$TARGET

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

else

#
# Use the running kernel for version and configuration information.
#
	echo "#define KERNEL_VERSION \"`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

fi

#
# See if we need to use the do_floppy hook
#
	grep KERNEL_VERSION $TARGET | cut -d" " -f3 | cut -d\" -f2 | \
	awk -F\. '{ if ($$1 < 1 || ($$1 == 1 && \
			($$2 < 1 || ($$2 == 1 && $$3 < 23)))) \
		print "#define FLOPPY_HACK" ; \
		else print "#undef FLOPPY_HACK" }' >>$TARGET
#
# See if we must use the old interrupt number acquisition code
#
	grep KERNEL_VERSION $TARGET | cut -d" " -f3 | cut -d\" -f2 | \
	awk -F\. '{ if ($$1 < 1 || ($$1 == 1 && \
			($$2 < 1 || ($$2 == 1 && $$3 < 43)))) \
		print "#define OLD_IRQ_REQUEST" ; \
		else print "#undef OLD_IRQ_REQUEST" }' >>$TARGET
#
# See if we must use the old dma channel acquisition code
#
	grep KERNEL_VERSION $TARGET | cut -d" " -f3 | cut -d\" -f2 | \
	awk -F\. '{ if ($$1 < 1 || ($$1 == 1 && \
			($$2 < 1 || ($$2 == 1 && $$3 < 48)))) \
		print "#define OLD_DMA_REQUEST" ; \
		else print "#undef OLD_DMA_REQUEST" }' >>$TARGET
#
# See if we must use the old interrupt service routine prototype
#
	grep KERNEL_VERSION $TARGET | cut -d" " -f3 | cut -d\" -f2 | \
	awk -F\. '{ if ($$1 < 1 || ($$1 == 1 && \
			($$2 < 1 || ($$2 == 1 && $$3 < 82)))) \
		print "#define OLD_IRQ_CALL" ; \
		else print "#undef OLD_IRQ_CALL" }' >>$TARGET

exit
#
