#!/bin/sh
#set -x

#  Dazuko configure. Configure Dazuko for easy compilation.
#  Written by John Ogness <jogness@antivir.de>
#
#  Copyright (c) 2003-2004 H+BEDV Datentechnik GmbH
#  All rights reserved.
#
#  Redistribution and use in source and binary forms, with or without
#  modification, are permitted provided that the following conditions
#  are met:
#
#  1. Redistributions of source code must retain the above copyright notice,
#  this list of conditions and the following disclaimer.
#
#  2. Redistributions in binary form must reproduce the above copyright notice,
#  this list of conditions and the following disclaimer in the documentation
#  and/or other materials provided with the distribution.
#
#  3. Neither the name of Dazuko nor the names of its contributors may be used
#  to endorse or promote products derived from this software without specific
#  prior written permission.
#
#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
#  POSSIBILITY OF SUCH DAMAGE.


print_help()
{
	echo "\`configure' configures dazuko to adapt to many kinds of systems."
	echo ""
	echo "Usage: ./configure [OPTION]..."
	echo ""
	echo "Configuration:"
	echo "  -h, --help   display this help and exit"
	echo ""
	echo "Fine tuning of the installation directories:"
	echo "  --kernelsrcdir=DIR   kernel source files (Linux only)"
	echo ""
	echo "For better control, use the options below."
	echo ""
	echo "Optional Features:"
	echo "  --disable-FEATURE               do not include FEATURE"
	echo "  --enable-FEATURE                include FEATURE"
	echo "  --disable-event-open            do not capture ON_OPEN events"
	echo "  --disable-event-close           do not capture ON_CLOSE events"
	echo "  --disable-event-exec            do not capture ON_EXEC events"
	echo "  --enable-event-unlink           capture ON_UNLINK events"
	echo "  --enable-event-rmdir            capture ON_RMDIR events"
	echo "  --enable-event-close-modified   capture ON_CLOSE_MODIFIED events"
	echo "  --enable-devfs                  support devfs (Linux only)"
	echo "  --enable-default-capabilities   support Default Capabilities (Linux 2.6 only)"
	echo "  --disable-compat1               disable 1.x compatibility (dazukoio only)"
	echo "  --enable-debug                  print extra debug information"
	echo ""
	echo "Optional Packages:"
	echo "  --with-PACKAGE                  use PACKAGE"
	echo "  --without-PACKAGE               do not use PACKAGE"
	echo "  --without-module                do not build kernel module"
	echo "  --without-library               do not build library"
	echo ""
	echo "Report bugs to <jogness@antivir.de>."
}

linux_check_srcdir()
{
	echo -n "kernel source in ${LINUX_SRC}... "

	if [ -f "${LINUX_SRC}/include/linux/version.h" ]
	then
		echo "yes"
		return 0
	else
		echo "no"
		return 1
	fi
}

do_lib_generic()
{
	echo "configure: creating library/Makefile"

	mkdir -p library

	echo "CC ?= gcc" > library/Makefile
	echo "RM ?= rm -f" >> library/Makefile
	echo "CFLAGS = -Wall -O" >> library/Makefile
	echo "CFLAGS += -I.." >> library/Makefile
	echo "OBJS = dazukoio.o" >> library/Makefile

	if [ $COMPAT12 -eq 0 ]
	then
		echo "CFLAGS += -DNO_COMPAT12" >> library/Makefile
	else
		echo "OBJS += dazukoio_compat12.o" >> library/Makefile
	fi

	echo "" >> library/Makefile
	echo "all: libdazuko.a" >> library/Makefile

	echo "" >> library/Makefile
	echo "libdazuko.a: \$(OBJS)" >> library/Makefile
	echo "	ar r libdazuko.a \$(OBJS)" >> library/Makefile
	echo "	ranlib libdazuko.a" >> library/Makefile

	echo "" >> library/Makefile
	echo "dazukoio.o: ../dazukoio.c ../dazukoio.h ../dazukoio_compat12.h" >> library/Makefile
	echo "	\$(CC) \$(CFLAGS) -c ../dazukoio.c -o dazukoio.o" >> library/Makefile

	echo "" >> library/Makefile
	echo "dazukoio_compat12.o: ../dazukoio_compat12.c ../dazukoio_compat12.h" >> library/Makefile
	echo "	\$(CC) \$(CFLAGS) -c ../dazukoio_compat12.c -o dazukoio_compat12.o" >> library/Makefile

	echo "" >> library/Makefile
	echo "clean:" >> library/Makefile
	echo "	\$(RM) -f *.o *.a" >> library/Makefile
}

do_lib_freebsd()
{
	echo "configure: creating library/Makefile"

	mkdir -p library

	echo "LIB = dazuko" > library/Makefile
	echo "NOMAN =" >> library/Makefile
	echo "SRCS = ../dazukoio.c" >> library/Makefile
	echo "INCS = ../dazukoio_xp.h" >> library/Makefile
	echo "INCS += ../dazukoio.h" >> library/Makefile

	if [ $COMPAT12 -eq 0 ]
	then
		echo "CFLAGS += -DNO_COMPAT12" >> library/Makefile
	else
		echo "SRCS += ../dazukoio_compat12.c" >> library/Makefile
		echo "INCS += ../dazukoio_compat12.h" >> library/Makefile
	fi

	echo "" >> library/Makefile
	echo ".include <bsd.lib.mk>" >> library/Makefile
}

do_linux26()
{
	echo -n "checking if security module support is enabled... "
	grep -q "^#define CONFIG_SECURITY 1" "$LINUX_SRC/include/linux/autoconf.h"
	if [ $? -eq 0 ]
	then
		echo "yes"
	else
		echo "no"
		echo "error: security module support must be enabled in your kernel"
		exit 1
	fi

	if [ ${RSBAC} -eq 1 ]
	then
		VARIANT="rsbac"
	else
		VARIANT="linux26"
	fi

	if [ ${DEFAULT_CAPABILITIES} -eq 2 ]
	then
		echo -n "checking if default capabilities are needed... "
		grep -q "^#undef CONFIG_SECURITY_CAPABILITIES" "$LINUX_SRC/include/linux/autoconf.h"
		if [ $? -eq 0 ]
		then
			echo "no"
			DEFAULT_CAPABILITIES=0
		else
			echo "yes"
			DEFAULT_CAPABILITIES=1
		fi
	fi

	echo "#ifndef DAZUKO_OPS" > dazuko_ops_linux26.h
	echo "#define DAZUKO_OPS" >> dazuko_ops_linux26.h
	echo "" >> dazuko_ops_linux26.h
	echo "#include <linux/security.h>" >> dazuko_ops_linux26.h
	echo "" >> dazuko_ops_linux26.h
	echo "static inline int dazuko_inode_permission(struct inode *inode, int mask, struct nameidata *nd);" >> dazuko_ops_linux26.h
	echo "" >> dazuko_ops_linux26.h
	echo "static struct security_operations dazuko_ops = {" >> dazuko_ops_linux26.h
	echo ".inode_permission = dazuko_inode_permission," >> dazuko_ops_linux26.h

	if [ ${DEFAULT_CAPABILITIES} -eq 1 ]
	then
		echo -n "grabbing capabilitiy_ops... "

		if [ -f "$LINUX_SRC/security/capability.c" ]
		then
			STRING=""

			for item in `cat "$LINUX_SRC/security/capability.c"`
			do
        			STRING="$STRING $item"
			done

			echo "$STRING" | sed -e "s/.*static struct security_operations capability_ops = {//" -e "s/};.*//" >> dazuko_ops_linux26.h

			echo "ok"
		else
			echo "missing"
		fi
	fi

	echo "};" >> dazuko_ops_linux26.h
	echo "" >> dazuko_ops_linux26.h
	echo "#endif" >> dazuko_ops_linux26.h

	echo "configure: creating Makefile"

	echo "EXTRA_CFLAGS += -Wall -DLINUX26_SUPPORT" > Makefile

	if [ ${DEBUG} -eq 1 ]
	then
		echo "EXTRA_CFLAGS += -DDEBUG" >> Makefile
	fi

	if [ ${DEVFS} -eq 1 ]
	then
		echo "EXTRA_CFLAGS += -DDEVFS_SUPPORT" >> Makefile
	fi

	if [ ${ON_OPEN} -eq 1 ]
	then
		echo "EXTRA_CFLAGS += -DON_OPEN_SUPPORT" >> Makefile
	fi

	echo "RM ?= rm -f" >> Makefile

	echo "obj-m += dazuko.o" >> Makefile
	echo "dazuko-objs := dazuko_xp.o dazuko_${VARIANT}.o" >> Makefile

	echo "" >> Makefile
	echo "dummy_rule.o:" >> Makefile
        echo "	\$(MAKE) -C ${LINUX_SRC} SUBDIRS=`pwd` modules" >> Makefile
	echo "	touch dummy_rule.o" >> Makefile

	echo "" >> Makefile
	echo "test: dummy_rule.o" >> Makefile
	echo "	@test \`id -u\` -eq 0 || { echo \"!! you must be root !!\" ; false ; }" >> Makefile
	echo "	/sbin/insmod ./dazuko.ko" >> Makefile
	echo "	/sbin/rmmod dazuko" >> Makefile
	echo "	@echo \"--> test successful :)\"" >> Makefile

	echo "" >> Makefile
	echo "dazuko:" >> Makefile
	echo "	@echo Just type \\\"make\\\", not \\\"make dazuko\\\"" >> Makefile
	echo "" >> Makefile

	echo "" >> Makefile
	echo "dazuko-smp:" >> Makefile
	echo "	@echo Just type \\\"make\\\", not \\\"make dazuko-smp\\\"" >> Makefile

	echo "" >> Makefile
	echo "clean:" >> Makefile
	echo "	\$(RM) .*.cmd *.cmd *.o dazuko.ko dazuko.mod.c" >> Makefile
}

do_linux()
{
	echo -n "checking if kernel is SMP... "

	uname -a | grep -q -w SMP
	if [ $? -eq 0 ]
	then
		SMP=1
		echo "yes"
	else
		SMP=0
		echo "no"
	fi

	if [ ${RSBAC} -eq 1 ]
	then
		VARIANT="rsbac"
	else
		VARIANT="linux"

		echo -n "checking whether sys_call_table is exported... "

		if [ -f "/proc/ksyms" ]
		then
			if [ -z "$(grep sys_call_table /proc/ksyms)" ]
			then
				HIDDEN_SCT=1
				echo "no"
			else
				HIDDEN_SCT=0
				echo "yes"
			fi
		else
			HIDDEN_SCT=0
			echo "unknown (assuming yes)"
		fi
	fi

	if [ ${HIDDEN_SCT} -eq 1 ]
	then
		echo -n "checking whether sys_close is exported... "

		if [ -z "$(grep sys_close /proc/ksyms)" ]
		then
			echo "no"
			echo "error: no usable exported symbols found"
			exit 1
		else
			echo "yes"
		fi
	fi

	echo "configure: creating Makefile"

	echo "CC ?= gcc" > Makefile
	echo "RM ?= rm -f" >> Makefile
	echo "CFLAGS += -Wall -O -DLINUX -Dlinux" >> Makefile

	if [ $COMPAT12 -eq 0 ]
	then
		echo "CFLAGS += -DNO_COMPAT12" >> Makefile
	fi

	echo "KFLAGS += \$(CFLAGS) -D__KERNEL__ -DMODULE -I${LINUX_SRC}/include" >> Makefile

	if [ ${SMP} -eq 1 ]
	then
		echo "KFLAGS += -D__SMP__" >> Makefile
	fi

	if [ ${DEBUG} -eq 1 ]
	then
		echo "KFLAGS += -DDEBUG" >> Makefile
	fi

	if [ ${DEVFS} -eq 1 ]
	then
		echo "KFLAGS += -DDEVFS_SUPPORT" >> Makefile
	fi

	if [ ${HIDDEN_SCT} -eq 1 ]
	then
		echo "KFLAGS += -DHIDDEN_SCT" >> Makefile
	fi

	if [ ${ON_OPEN} -eq 1 ]
	then
		echo "KFLAGS += -DON_OPEN_SUPPORT" >> Makefile
	fi

	if [ ${ON_CLOSE} -eq 1 ]
	then
		echo "KFLAGS += -DON_CLOSE_SUPPORT" >> Makefile
	fi

	if [ ${ON_EXEC} -eq 1 ]
	then
		echo "KFLAGS += -DON_EXEC_SUPPORT" >> Makefile
	fi

	if [ ${ON_UNLINK} -eq 1 ]
	then
		echo "KFLAGS += -DON_UNLINK_SUPPORT" >> Makefile
	fi

	if [ ${ON_RMDIR} -eq 1 ]
	then
		echo "KFLAGS += -DON_RMDIR_SUPPORT" >> Makefile
	fi

	if [ ${ON_CLOSE_MODIFIED} -eq 1 ]
	then
		echo "KFLAGS += -DON_CLOSE_MODIFIED_SUPPORT" >> Makefile
	fi

	echo "" >> Makefile
	echo "all: dazuko.o" >> Makefile

	echo "" >> Makefile
	echo "dazuko_xp.o: dazuko_xp.c dazuko_xp.h" >> Makefile
	echo "	\$(CC) \$(KFLAGS) -D__NO_VERSION__ -c dazuko_xp.c" >> Makefile

	echo "" >> Makefile
	echo "dazuko_${VARIANT}.o: dazuko_${VARIANT}.c dazuko_${VARIANT}.h" >> Makefile
	echo "	\$(CC) \$(KFLAGS) -c dazuko_${VARIANT}.c" >> Makefile

	echo "" >> Makefile
	echo "dazuko.o: dazuko_xp.o dazuko_${VARIANT}.o" >> Makefile
	echo "	ld -m elf_i386 -r -o dazuko.o dazuko_xp.o dazuko_${VARIANT}.o" >> Makefile

	echo "" >> Makefile
	echo "test: dazuko.o" >> Makefile
	echo "	@test \`id -u\` -eq 0 || { echo \"!! you must be root !!\" ; false ; }" >> Makefile
	echo "	/sbin/insmod ./dazuko.o" >> Makefile
	echo "	/sbin/rmmod dazuko" >> Makefile
	echo "	@echo \"--> test successful :)\"" >> Makefile

	echo "" >> Makefile
	echo "dazuko:" >> Makefile
	echo "	@echo Just type \\\"make\\\", not \\\"make dazuko\\\"" >> Makefile

	echo "" >> Makefile
	echo "dazuko-smp:" >> Makefile
	echo "	@echo Just type \\\"make\\\", not \\\"make dazuko-smp\\\"" >> Makefile

	echo "" >> Makefile
	echo "clean:" >> Makefile
	echo "	\$(RM) *.o" >> Makefile
}

do_freebsd()
{
	echo "configure: creating Makefile"

	echo -n "" > Makefile

	if [ ${FREEBSD_VERSION} -eq 5 ]
	then
		echo "CFLAGS += -DFREEBSD5_SUPPORT" >> Makefile
		DAZUKO_EXT_C="dazuko_freebsd5.c"
	else
		DAZUKO_EXT_C="dazuko_freebsd.c"
	fi

	if [ ${DEBUG} -eq 1 ]
	then
		echo "CFLAGS += -DDEBUG" >> Makefile
	fi

	if [ ${ON_OPEN} -eq 1 ]
	then
		echo "CFLAGS += -DON_OPEN_SUPPORT" >> Makefile
	fi

	if [ ${ON_CLOSE} -eq 1 ]
	then
		echo "CFLAGS += -DON_CLOSE_SUPPORT" >> Makefile
	fi

	if [ ${ON_EXEC} -eq 1 ]
	then
		echo "CFLAGS += -DON_EXEC_SUPPORT" >> Makefile
	fi

	if [ ${ON_UNLINK} -eq 1 ]
	then
		echo "CFLAGS += -DON_UNLINK_SUPPORT" >> Makefile
	fi

	if [ ${ON_RMDIR} -eq 1 ]
	then
		echo "CFLAGS += -DON_RMDIR_SUPPORT" >> Makefile
	fi

	if [ ${ON_CLOSE_MODIFIED} -eq 1 ]
	then
		echo "CFLAGS += -DON_CLOSE_MODIFIED_SUPPORT" >> Makefile
	fi

	echo "SRCS = dazuko_xp.c ${DAZUKO_EXT_C} vnode_if.h" >> Makefile
	echo "KMOD = dazuko" >> Makefile

	echo "" >> Makefile
	echo "all: dazuko.ko" >> Makefile

	if [ ${FREEBSD_VERSION} -ne 5 ]
	then
		echo "" >> Makefile
		echo "vnode_if.h: @" >> Makefile
		echo "	perl @/kern/vnode_if.pl -h @/kern/vnode_if.src" >> Makefile
	fi

	echo "" >> Makefile
	echo "test: dazuko.ko" >> Makefile
	echo "	@test \`id -u\` -eq 0 || { echo \"!! you must be root !!\" ; false ; }" >> Makefile
	echo "	/sbin/kldload ./dazuko.ko" >> Makefile
	echo "	/sbin/kldunload dazuko" >> Makefile
	echo "	@echo \"--> test successful :)\"" >> Makefile

	echo "" >> Makefile
	echo "dazuko:" >> Makefile
	echo "	@echo Just type \\\"make\\\", not \\\"make dazuko\\\"" >> Makefile

	echo "" >> Makefile
	echo "dazuko-smp:" >> Makefile
	echo "	@echo Just type \\\"make\\\", not \\\"make dazuko-smp\\\"" >> Makefile

	echo "" >> Makefile
	echo ".include <bsd.kmod.mk>" >> Makefile
}

do_summary()
{
	echo ""
	echo "$0 successful"
	echo ""
	echo "======================="
	echo " Configuration summary"
	echo "======================="
	echo ""

	if [ ${WITH_MODULE} -eq 0 ]
	then
		echo "build module = no"
	else
		echo -n "module events ="
		if [ ${ON_OPEN} -eq 1 ]
		then
			echo -n " ON_OPEN"
		fi

		if [ ${ON_CLOSE} -eq 1 ]
		then
			echo -n " ON_CLOSE"
		fi

		if [ ${ON_EXEC} -eq 1 ]
		then
			echo -n " ON_EXEC"
		fi

		if [ ${ON_UNLINK} -eq 1 ]
		then
			echo -n " ON_UNLINK"
		fi

		if [ ${ON_RMDIR} -eq 1 ]
		then
			echo -n " ON_RMDIR"
		fi

		if [ ${ON_CLOSE_MODIFIED} -eq 1 ]
		then
			echo -n " ON_CLOSE_MODIFIED"
		fi

		echo ""

		if [ "${OS}" = "Linux" ]
		then
			echo -n "devfs support = "
			if [ ${DEVFS} -eq 1 ]
			then
				echo "yes"
			else
				echo "no"
			fi

			echo -n "rsbac support = "
			if [ ${RSBAC} -eq 1 ]
			then
				echo "yes"
			else
				echo "no"
			fi

			if [ ${LINUX_VERSION} -eq 26 ]
			then
				echo -n "default capabilities = "
				if [ ${DEFAULT_CAPABILITIES} -eq 1 ]
				then
					echo "yes"
				else
					echo "no"
				fi
			fi
		fi

		echo -n "module debug = "
		if [ ${DEBUG} -eq 1 ]
		then
			echo "yes"
		else
			echo "no"
		fi
	fi

	echo -n "library 1.x compatibility = "
	if [ ${COMPAT12} -eq 1 ]
	then
		echo "yes"
	else
		echo "no"
	fi

	echo ""
}

inc_library()
{
	WITH_LIBRARY=$(($WITH_LIBRARY + 1))
}

dec_library()
{
	if [ $WITH_LIBRARY -gt 0 ]
	then
		WITH_LIBRARY=$(($WITH_LIBRARY - 1))
	fi
}

#main()
ON_OPEN=1
ON_CLOSE=1
ON_EXEC=1
ON_UNLINK=0
ON_RMDIR=0
ON_CLOSE_MODIFIED=0
COMPAT12=1
# DEVFS=2 => uninitialized
DEVFS=2
RSBAC=0
# DEFAULT_CAPABILITES=2 => uninitialized
DEFAULT_CAPABILITIES=2
DEBUG=0
WITH_MODULE=1
WITH_LIBRARY=2
WITH_EXAMPLE_C=1
WITH_EXAMPLE_JAVA=0
WITH_EXAMPLE_PERL=0
WITH_EXAMPLE_PYTHON=0
SMP=0
HIDDEN_SCT=0
LINUX_SRC=""
LINUX_VERSION=0
FREEBSD_VERSION=0

for option in $@
do
	case ${option} in
		--disable-event-open)
			ON_OPEN=0
			;;
		--enable-event-open)
			ON_OPEN=1
			;;
		--disable-event-close)
			ON_CLOSE=0
			;;
		--enable-event-close)
			ON_CLOSE=1
			;;
		--disable-event-exec)
			ON_EXEC=0
			;;
		--enable-event-exec)
			ON_EXEC=1
			;;
		--disable-event-close-modified)
			ON_CLOSE_MODIFIED=0
			;;
		--enable-event-unlink)
			ON_UNLINK=1
			;;
		--enable-event-rmdir)
			ON_RMDIR=1
			;;
		--enable-event-close-modified)
			ON_CLOSE_MODIFIED=1
			;;
		--disable-devfs)
			DEVFS=0
			;;
		--enable-devfs)
			DEVFS=1
			;;
		--disable-default-capabilities)
			DEFAULT_CAPABILITIES=0
			;;
		--enable-default-capabilities)
			DEFAULT_CAPABILITIES=1
			;;
		--disable-debug)
			DEBUG=0
			;;
		--enable-debug)
			DEBUG=1
			;;
		--enable-compat1)
			COMPAT12=1
			;;
		--disable-compat1)
			COMPAT12=0
			;;
		--enable-compat12)
			COMPAT12=1
			;;
		--disable-compat12)
			COMPAT12=0
			;;
		--with-module)
			WITH_MODULE=1
			;;
		--without-module)
			WITH_MODULE=0
			;;
		--with-library)
			inc_library
			;;
		--without-library)
			dec_library
			;;
		--kernelsrcdir=*)
			LINUX_SRC="${option#--kernelsrcdir=}"
			LINUX_SRC="${LINUX_SRC%/}"
			;;
		--help|-h)
			print_help
			exit 0
			;;
		*)
			echo "configure: error: unrecognized option: ${option}"
			echo "Try \`./configure --help' for more information."
			exit 1
			;;
	esac
done

echo -n "checking host system type... "

OS="$(uname)"

echo "${OS}"

case ${OS} in
	Linux)
		if [ $WITH_MODULE -eq 1 ]
		then
			if [ -z "${LINUX_SRC}" ]
			then
				LINUX_SRC="/lib/modules/$(uname -r)/build"
				linux_check_srcdir
				if [ $? -ne 0 ]
				then
					LINUX_SRC="/usr/src/linux"
					linux_check_srcdir

					if [ $? -ne 0 ]
					then
						echo "error: kernel source files not found"
						exit 1
					fi
				fi
			fi

			echo -n "checking if Linux is RSBAC patched... "
			if [ -f "$LINUX_SRC/include/rsbac/types.h" ]
			then
				echo "yes"
				RSBAC=1
			else
				echo "no"
			fi

			if [ $DEVFS -eq 2 ]
			then
				echo -n "checking if devfs is enabled... "

				grep -q "^#define CONFIG_DEVFS_FS 1" "$LINUX_SRC/include/linux/autoconf.h"
				if [ $? -eq 0 ]
				then
					DEVFS=1
					echo "yes"
				else
					DEVFS=0
					echo "no"
				fi
			fi

			echo -n "checking if Linux version is 2.6... "
			TEMPVERSION=""
			if [ ! -z "$LINUX_SRC" ]
			then
				MKVER="$(grep VERSION.*= ${LINUX_SRC}/Makefile | head -n 1)"
				MKPLVL="$(grep PATCHLEVEL.*= ${LINUX_SRC}/Makefile | head -n 1)"
				if [ ! -z "${MKVER}" -a ! -z "${MKPLVL}" ]
				then
					TEMPVERSION="${MKVER##* }.${MKPLVL##* }.x"
				fi
			fi

			if [ -z "${TEMPVERSION}" ]
			then
				TEMPVERSION="$(uname -r)"
			fi

			if [ "${TEMPVERSION#2.6.}" = "${TEMPVERSION}" ]
			then
				echo "no"
				LINUX_VERSION=24
				do_linux
			else
				echo "yes"
				LINUX_VERSION=26
				do_linux26
			fi
		fi
		;;
	FreeBSD)
		COMPAT12=0
		SMP=0

		if [ $WITH_MODULE -eq 1 ]
		then
			TEMPVERSION="$(uname -r)"

			if [ "${TEMPVERSION#5.}" = "${TEMPVERSION}" ]
			then
				FREEBSD_VERSION=4
				DEVFS=0
			else
				FREEBSD_VERSION=5
				DEVFS=1
			fi

			do_freebsd
		fi
		;;
	*)
		echo "error: unknown host system type"
		;;
esac

if [ $WITH_LIBRARY -ge 1 ]
then
	case ${OS} in
		FreeBSD)
			do_lib_freebsd
			;;
		*)
			do_lib_generic
			;;
	esac
fi

do_summary
