#!/bin/bash

if [ "$1" = "invoked from main makefile" ]; then
    MAKE_INVOKED=1
    shift
else
    MAKE_INVOKED=0
fi

CONFIG=${1:-config.in}

#
# do_readstring  - Ask for a string
#
# Inputs:
# 	PROMPT has the string to prompt the user with.
#	DEFAULT is the default response to use for empty input
# Outputs:
#	RESULT has the response from the user
#
do_readstring()
{
    while true; do
	echo -en "\n$PROMPT "
	if [ "$DEFAULT..." != "..." ]; then
	    echo -n "[default: $DEFAULT] "
	fi

	read RESULT

	if [ "$RESULT..." != "..." ]; then
	    return
	else
	    if [ "$DEFAULT..." != "..." ]; then
		RESULT=$DEFAULT
	        return
	    fi
	fi
    done
}

#
# Write a message to the user and get a CR to continue
#
do_confirm()
{
    PROMPT="$1"
    if [ "$1..." != "..." ]; then
	PROMPT="$PROMPT  "
    fi
    PROMPT="${PROMPT}Press Enter to continue... "
    echo -en "\n$PROMPT"
    read DISCARD
}

#
# do_read_dir  - Ask for name of an existing directory
#
# Inputs:
# 	PROMPT has the string to prompt the user with.
#	DEFAULT is the default response to use for empty input
# Outputs:
#	RESULT has the response from the user
#
do_read_dir()
{
    while :; do
	do_readstring
	if [ -d $RESULT ]; then
	    return
	fi
    done
}

#
# do_read_choice  - Ask for a choice
#
# Inputs:
# 	PROMPT has the string to prompt the user with.
#	RESPONSE has the responses that are valid
#	DEFAULT is the default response to use for empty input
# Outputs:
#	RESULT has the response from the user
#
do_read_choice()
{
    # Check that we have valid responses and default
    if [ "$RESPONSE..." = "..." ]; then
	echo "Internal error."
	exit 1;
    fi
    local VALID_DEFAULT=0
    for i in $RESPONSE; do
        if [ "$ALTERNATE_DEFAULT..." = "..." ]; then
	    local ALTERNATE_DEFAULT=$i
	fi
        if [ "$i" = "$DEFAULT" ]; then
    	    local VALID_DEFAULT=1
	    break
        fi
    done
    if [ "$VALID_DEFAULT" = "0" ]; then
	DEFAULT=
    fi
    if [ "$DEFAULT..." = "..." ]; then
	DEFAULT=$ALTERNATE_DEFAULT
    fi

    while :; do
	do_readstring
	for i in $RESPONSE; do
	    if [ "$i" = "$RESULT" ]; then
		return
	    fi
	done
	echo "Unexpected response"
    done
}

#
# Get config variable from autoconf.h
#
# $1 is the name of the variable to find.
#
# Return via stdout a "y" if defined or "" if not.
#
ac_get_config()
{
    x=`grep $1 $KSRC/include/linux/autoconf.h 2>&1`
    if [ $? -ne 0 ]; then
	return 1
    fi
    if expr "$x" : "#define" >/dev/null 2>/dev/null; then
	echo -n "y"
	return 0			# found
    fi
    return 1				# not found
}

#
# Get System.map file name on a Red Hat system
# 5.2 has one of them in /boot, 6.0 has several with a symbolic
# link from System.map to the one that is in use.
#
# This is only meaningful if the user intends to run LiS on the
# machine on which he is installing it.  So ask first.
#
# Return 0 (true) if found
#
rh_get_system_map()
{
    if [ "$BEEN_HERE_DONE_THIS..." = "1..." ]; then
	if [ "$SMAP..." = "..." ]; then
	    return 1
	fi
	return 0
    fi

    SMAP=
    PROMPT="\
Is it your intent to run LiS on the same machine on which\n\
you are installing it?  Or are you intending to cross compile\n\
for another machine?\n\
    y = I am going to run it on this machine\n\
    n = I am not going to run it on this machine\n\
Please enter y or n"
    RESPONSE="y n"
    DEFAULT=y
    do_read_choice
    BEEN_HERE_DONE_THIS=1
    if [ "$RESULT..." = "n..." ]; then
	echo
	echo "You really should load your kernel source and build"
	echo "your kernel before installing LiS."
	echo
	do_confirm
	return 1
    fi

    if [ ! -d /boot ]; then
	return 1
    fi
    if [ ! -L /boot/System.map ]; then
	files=`ls /boot/System.map*`
	if [ $? -ne 0 ]; then
	    return 1
	fi
	nfiles=0
	for i in $files; do
	    nfiles=`expr $nfiles + 1`
	done
	if [ $nfiles -ne 1 ]; then	# need just one of them
	    return 1
	fi

	SMAP=$i				# save file name
    else				# it's a symbolic link
	SMAP=/boot/System.map
    fi
    return 0
}

#
# Figure out kernel version
# Return the version string in KVER (e.g. 2.2.6)
#
get_kver()
{
    if [ -f $KSRC/include/linux/version.h ]; then
	KVER=`grep UTS_RELEASE $KSRC/include/linux/version.h | \
	     sed -e 's/^.*UTS_RELEASE.//' -e's/"//g'`
    elif [ -f $KSRC/vmlinux ]; then
	KVDEC=`nm -g $KSRC/vmlinux | grep Version_ | sed -e 's/^.*_//'`
	KMAJ=`expr $KVDEC / 65536`
	KMIN=`expr $KVDEC / 256`
	KMIN=`expr $KMIN % 256`
	KPCH=`expr $KVDEC % 256`
	KVER="$KMAJ.$KMIN.$KPCH"
    elif grep -q "Red Hat" /etc/issue && rh_get_system_map; then
	KVDEC=`grep Version_ $SMAP | sed -e 's/^.*_//'`
	KMAJ=`expr $KVDEC / 65536`
	KMIN=`expr $KVDEC / 256`
	KMIN=`expr $KMIN % 256`
	KPCH=`expr $KVDEC % 256`
	KVER="$KMAJ.$KMIN.$KPCH"
    else
        echo "The file $KSRC/include/linux/version.h is not present."
        echo "LiS installation cannot proceed without it.  Please fix"
        echo "this problem and then try the installation again."
        exit 1
    fi
}

#
# Red Hat helper for getting SMP info
#
# Return 0 (true) if found, 1 (false) if not
#
rh_get_smp()
{
    if ! grep -q "Red Hat" /etc/issue || ! rh_get_system_map; then
	return 1
    fi

    if grep -w -q cpu_data $SMAP; then
	NEED_KSMP=0
	KSMP=y			# SMP kernel
    else
	KSMP=			# non-SMP kernel
    fi
    return 0			# got info
}

#
# Get SMP or not
# Return result in KSMP
#
get_smp()
{
    if [ -f $KSRC/vmlinux ]; then
	NEED_KSMP=0
	if nm -g $KSRC/vmlinux |grep -w -q cpu_data; then
	    KSMP=y			# SMP kernel
	else
	    KSMP=			# non-SMP kernel
	fi
    elif [ -f $KSRC/include/linux/autoconf.h ]; then
	NEED_KSMP=0
	KSMP=`ac_get_config CONFIG_SMP`
    else
	NEED_KSMP=1
	rh_get_smp			# try Red Hat style
    fi
}

#
# Helper routine for Red Hat systems.  This is invoked when there
# is no vmlinux available.  If the system is Red Hat we look at the
# System.map file in /boot for some of our information.
#
# Return 0 (true) if found, 1 (false) if not
#
rh_get_modules()
{
    if ! grep -q "Red Hat" /etc/issue || ! rh_get_system_map; then
	return 1
    fi

    if grep -q init_modules $SMAP; then
	NEED_KMODULES=0
	KMODULES=y			# Module support
	if grep -q unregister_chrdev_R /proc/ksyms; then
	    KMODVERS=y
	else
	    KMODVERS=
	fi
    else
	KMODULES=			# No module support
    fi
    return 0
}

#
# Get Modules or not
# Return result in KMODULES
#
get_modules()
{
    if [ -f $KSRC/vmlinux ]; then
	NEED_KMODULES=0
	if nm -g $KSRC/vmlinux |grep -w -q init_modules; then
	    KMODULES=y			# Module support
	    if strings $KSRC/vmlinux |grep -q Using_Versions; then
		KMODVERS=y
	    else
		KMODVERS=
	    fi
	else
	    KMODULES=			# No module support
	fi
    elif [ -f $KSRC/include/linux/autoconf.h ]; then
	NEED_KMODULES=0
	KMODULES=`ac_get_config CONFIG_MODULES`
	if [ "$KMODULES..." = "y..." ]; then
	    KMODVERS=`ac_get_config CONFIG_MODVERSIONS`
	fi
    else
	NEED_KMODULES=1
	rh_get_modules			# try Red Hat style
    fi
}

#
# Establish defaults
#
if [ -f $CONFIG ]; then
. $CONFIG
    if [ "$KERN_TARGET..." = "..." ]; then
	KERN_TARGET=bzImage
    fi
else
    CONFIG_STREAMS=m
    MOD_INSTALL=y
    KSRC=/usr/src/linux
    CONFIG_MK_KERNEL=n
    KERN_TARGET=bzImage
    STRMS_QUEUES=t
    DBG_OPT=n
    LIS_SHLIB=y
fi

case $KERN_TARGET in
    zImage)	KTARG=1;;
    zlilo)	KTARG=2;;
    bzImage)	KTARG=3;;
    bzlilo)	KTARG=4;;
    *)		KTARG=3;;
esac

#
# LIS_HOME
#
# Plant a symbolic link from /usr/src/LiS to whereever this directory is.
# Remember our directory name as either its real name or as /usr/src/LiS
# if /usr/src/LiS is symbolically linked to this directory.
#
LIS_HOME=`pwd`

if [ -L /usr/src/LiS ]; then
    usr_src_lis=`ls -l /usr/src/LiS | sed -e 's/^.* //' | sed -e 's/\/$//'`
else
    usr_src_lis=
fi
if [ "$LIS_HOME" = "$usr_src_lis" ]; then
    LIS_HOME="/usr/src/LiS"
elif [ `id -u` -eq 0 ]; then
    if [ -L /usr/src/LiS ]; then
	rm /usr/src/LiS
	if [ $? -ne 0 ]; then
	    echo "Error removing symbolic link /usr/src/LiS"
	fi
    fi
    ln -s $LIS_HOME /usr/src/LiS
    if [ $? -ne 0 ]; then
	echo "Error making symbolic link from /usr/src/LiS to $LIS_HOME."
	echo "Please fix this problem and try again."
	exit 1
    fi
    LIS_HOME="/usr/src/LiS"
fi

#
# TARGET
#
PROMPT="\
How do you want to configure STREAMS?\n\
    l = to run in the Linux kernel\n\
    u = to run in user level\n\
    q = to run under QNX (may not work)\n\
Please enter your choice"
RESPONSE="l u q"
DEFAULT="$CONFIG_STREAMS"
do_read_choice
TARGET=$RESULT

if [ "$TARGET" = "l" ]; then
    #
    # The linux target needs some special handling
    #

    #
    # Kernel source location
    #
    PROMPT="Enter directory location of your kernel source"
    DEFAULT=$KSRC
    if [ "$KSRC..." = "..." ]; then
        DEFAULT="/usr/src/linux"
    fi
    if [ ! -d $KSRC ]; then
        DEFAULT="/usr/src/linux"
    fi
    do_read_dir
    KSRC=$RESULT

    #
    # Try to dig some info out of the kernel binary "vmlinux".  If we
    # can find out this stuff from the binary then we don't need the
    # .config file
    #
    get_kver
    get_smp
    get_modules
    if [ $NEED_KSMP -eq 1 -o $NEED_KMODULES -eq 1 ]; then
	NEED_KCONFIG=1		# couldn't access kernel binary
    else
	NEED_KCONFIG=0		# have info from kernel binary
    fi

    #
    # See if the kernel's .config file is there.  If not then the user
    # has not done a "make menuconfig" yet.
    #
    if [ $NEED_KCONFIG -eq 1 -a ! -f $KSRC/.config ]; then
        PROMPT="\
It appears that you have not done a 'make menuconfig' on \
your kernel in $KSRC yet. \
You should do that now to avoid problems with the installation. \
Do you want to do that now?"
        RESPONSE="y n"
        do_read_choice
        case $RESULT in
	    y)
		    if ! make -C $KSRC menuconfig; then
		        echo "Menuconfig failed.  LiS installation aborted."
		        exit 1
		    fi
		    echo "Make menuconfig was successful."
		    echo "Continuing with LiS installation."
		    ;;
	    n)
		    echo "OK, but this may cause problems with the installation."
		    ;;
        esac
    fi

    #
    # If we have a kernel configuration now, source it.
    #
    if [ -f $KSRC/.config ]; then
        . $KSRC/.config
    fi

    #
    # See if version.h is there.  It may not be if the user just unpacked
    # a fresh version of Linux and has not done a "make dep" yet.
    #
    if [ $NEED_KCONFIG -eq 1 -a ! -f $KSRC/include/linux/version.h ]; then
        PROMPT="\
It appears that you have not done a 'make dep' on your kernel yet.\n\
You will have to do this to proceed.\n\
Do you want to do that now?"
        RESPONSE="y n"
        do_read_choice
        case $RESULT in
	    y)
	        if ! make -C $KSRC dep; then
	            echo "Make dep failed.  LiS installation aborted."
	            exit 1
	        fi
	        echo "Make dep was successful."
		echo "Continuing with LiS installation."
	        ;;
	    n)
		echo "LiS installation cannot proceed until this is done."
		echo "Please fix the problem and then try again."
		exit 1
		;;
        esac
    fi

    #
    # Kernel version
    #
    DEFAULT=$KVER
    PROMPT="Which version of the kernel are you building for?"
    do_readstring
    KVER=$RESULT
    
    KVER_PATCH=`echo ${KVER}|sed -e "s/[^\.]\.[^\.]\.//"`
    KVER_PATCHNO=`echo $KVER_PATCH | sed -e 's/-.*//'`
    KVER_MAJORMINOR=`echo ${KVER}|sed -e "s/\.${KVER_PATCH}//"`
    if [ "${KVER_MAJORMINOR}" != "2.0" -a	\
         "${KVER_MAJORMINOR}" != "2.1" -a	\
         "${KVER_MAJORMINOR}" != "2.2" ]; then
        echo Sorry, LiS does not compile Linux version $KVER_MAJORMINOR.x
        exit 1
    fi
    KVER_MINOR=`echo ${KVER_MAJORMINOR}|sed -e "s/[^\.]\.//"`
    KVER_MAJOR=`echo ${KVER}|sed -e "s/\.${KVER_MINOR}\.${KVER_PATCH}//"`
    if [ "$KVER_MAJORMINOR" = "2.0" -a $KVER_PATCHNO -lt 36 ]; then
	echo
	echo "The assigned system call numbers used by LiS in kernel"
	echo "version prior to 2.0.36 are not official numbers assigned"
	echo "by Linus.  From kernel version 2.0.36 onward these syscall"
	echo "numbers have been assigned to LiS by Linus.  It would be"
	echo "a good idea from an application compatibility standpoint"
	echo "to install LiS on a more recent kernel.  This is just an"
	echo "informational message and will not prevent LiS from installing."
	echo
	do_confirm
    fi
    
    #
    # CONFIG_STREAMS
    #
    if [ "$KMODULES" = "y" ]; then
        PROMPT="\
How do you want to build STREAMS for the Linux kernel?\n\
    k = link with the linux kernel\n\
    m = create a kernel loadable module\n\
Please enter your choice"
        RESPONSE="m k"
        DEFAULT="$CONFIG_STREAMS"
        do_read_choice
        CONFIG_STREAMS=$RESULT
    else
        CONFIG_STREAMS="k"
    fi

    #
    # CONFIG_MK_KERNEL
    #
    if [ $CONFIG_STREAMS = "k" ]; then
	# no module versioning if linking directly into the kernel
	KMODVERS=
        PROMPT="\
When you make STREAMS, do you want to also build the kernel automatically?\n\
    y = make kernel\n\
    n = just make LiS and leave streams.o in this directory\n\
Please enter y or n"
        RESPONSE="y n"
        DEFAULT="$CONFIG_MK_KERNEL"
        do_read_choice
        CONFIG_MK_KERNEL=$RESULT
    else
        CONFIG_MK_KERNEL="n"
    fi
    
    #
    # KERN_TARGET
    #
    if [ $CONFIG_STREAMS = "k" -a $CONFIG_MK_KERNEL = "y" ]; then
	PROMPT="The target to make when building a kernel."
	PROMPT="$PROMPT  Possibilities are:\n"
	PROMPT="${PROMPT}    1 = zImage\n"
	PROMPT="${PROMPT}    2 = zlilo\n"
	PROMPT="${PROMPT}    3 = bzImage\n"
	PROMPT="${PROMPT}    4 = bzlilo\n"
	PROMPT="${PROMPT}Please enter a number from 1-4 [default: $KTARG] \c"
	RESPONSE="1 2 3 4"
	DEFAULT="$KTARG"
	do_read_choice

	case $RESULT in
	    1) RESULT=zImage;;
	    2) RESULT=zlilo;;
	    3) RESULT=bzImage;;
	    4) RESULT=bzlilo;;
	esac
	KERN_TARGET=$RESULT
	echo "KERN_TARGET=$RESULT" >>$CONFIG
    else
	echo "# KERN_TARGET not set" >>$CONFIG
    fi

    #
    # See if the user wants STREAMS kernel loadable modules installed for
    # easy running.
    #
    if [ "$CONFIG_STREAMS" = "m" -a "$KMODULES" = "y" ]; then
        PROMPT="\
After building STREAMS, do you want kernel loadable modules installed?\n\
This allows you to load it by typing in \"insmod streams\".\n\
    y = install it for module loading\n\
    n = just leave modules for later \"make modules_install\"\n\
Please enter y or n "
        RESPONSE="y n"
        DEFAULT="$MOD_INSTALL"
        do_read_choice
        MOD_INSTALL=$RESULT
    else
        MOD_INSTALL="n"
    fi

    #
    # MOD_INST_DIR
    #
    if [ "$CONFIG_STREAMS" = "m" -a "$KMODULES" = "y" ]; then
        PROMPT="Enter location of your kernel module directory\n"
	PROMPT="$PROMPT              "
	if [ "$MOD_INST_DIR..." = "..." ]; then
            DEFAULT=/lib/modules/$KVER/misc
            if [ ! -d $DEFAULT ]; then
                DEFAULT=/lib/modules/preferred/misc
                if [ ! -d $DEFAULT ]; then
		    if [ `id -u` -eq 0 ]; then
			DEFAULT=/lib/modules/$KVER/misc
			if ! mkdir $DEFAULT 2>/dev/null; then
			    DEFAULT=/lib/modules/preferred/misc
			    if ! mkdir $DEFAULT 2>/dev/null; then
				DEFAULT=
			    fi
			fi
		    else
		    DEFAULT=
		    fi
                fi
            fi
	else
	    DEFAULT=$MOD_INST_DIR
        fi
        do_read_dir
        MOD_INST_DIR=$RESULT
    fi

    #
    # STRMS_QUEUES
    #
    # Cannot run as kernel thread on 2.0.x kernels unless LiS
    # is linked directly into the kernel or unless we can apply
    # the ksyms patch.
    #
    choose_runqueues=0
    if [ "$CONFIG_STREAMS" = "m" -a "$KVER_MAJORMINOR" = "2.0" ]; then
        if [ $KVER_PATCHNO -ge 35 -a ! -f $KSRC/kernel/ksyms.c ]; then
	    echo
	    echo "In order to be able to run STREAMS queues as a kernel thread"
	    echo "on a 2.0.x kernel we need to apply a patch to the file"
	    echo "$KSRC/kernel/ksyms.c.  But that file is missing --"
	    echo "perhaps your kernel source is not present.  This is"
	    echo "nothing to be concerned about.  However, we will configure"
	    echo "LiS to run the STREAMS queues as a \"bottom half\""
	    echo "process with no ability to choose the \"kernel thread\""
	    echo "method."
	    echo
	    do_confirm
	    STRMS_QUEUES=b		# use bottom half by default
        elif [ $KVER_PATCHNO -ge 35 -a -f $KSRC/kernel/ksyms.c ]; then
	    echo
	    echo "Because this is a 2.0.35/36 kernel we are going to set"
	    echo "the default option for running STREAMS queues to"
	    echo "use the \"bottom half\" method.  You can choose"
	    echo "another method in the next menu, but the default"
	    echo "choice will be best if you don't wish to rebuild"
	    echo "your kernel."
	    echo
	    do_confirm
	    STRMS_QUEUES=b		# use bottom half by default
	    choose_runqueues=1		# allow user to choose
	fi
    else			# not installing as module, or later kernel
	choose_runqueues=1
    fi
    if [ "$KVER_MAJORMINOR" = "2.0" -a $KVER_PATCHNO -lt 35 ]; then
	echo
	echo "You may experience some difficulty with kernel versions"
	echo "earlier than 2.0.35.  If you see syntax errors when compiling"
	echo "LiS or unresolved externals when loading it as a module"
	echo "you may consider ugrading to at least 2.0.36 or configuring"
	echo "LiS to link directly into the kernel.  If you elect to"
	echo "link LiS directly into the kernel and you still get"
	echo "syntax errors then you will need to upgrade your kernel"
	echo "to at least 2.0.36."
	echo
	do_confirm
    fi
    if [ $choose_runqueues -eq 0 ]; then
	echo
	echo "We will configure LiS to use \"bottom half\" processing"
	echo "for STREAMS queues.  If you want to use the kernel thread"
	echo "technique, load your kernel source, come back to the"
	echo "/usr/src/LiS directory and do 'make realclean; make'."
	echo "If you don't care, just ignore this message and proceed."
	echo
	do_confirm
	STRMS_QUEUES=b
    else
	PROMPT="\
The STREAMS queues can be run either as a bottom half task (faster\n\
but with restrictions on kernel constructs) or as a kernel thread\n\
(slower but no restrictions on kernel routines used from STREAMS\n\
service procedures).\n\
    t = use kernel thread\n\
    b = use bottom half processing\n\
Please enter t or b"
	RESPONSE="t b"
	DEFAULT="$STRMS_QUEUES"
	do_read_choice
	STRMS_QUEUES=$RESULT
    fi

    if [ "$STRMS_QUEUES" = "t" -a "$CONFIG_STREAMS" = "m" -a \
	 "$KVER_MAJORMINOR" = "2.0" ]; then
	echo
	echo "               PLEASE NOTE"
	echo "The LiS 'make' procedure will install a patch in"
	echo "your kernel source that will allow you to run"
	echo "the STREAMS queues as a kernel thread.  Be sure"
	echo "to remake your kernel, run lilo, and reboot before"
	echo "attempting to run streams.  If you get an unresolved"
	echo "external on \"exit_files\" when you attempt to run"
	echo "streams via \"insmod streams\" this is a sign that you"
	echo "need to perform this procedure."
	echo
	echo "If you do not wish to rebuild your kernel, reconfigure"
	echo "LiS and select 'b' for \"bottom half\" for STREAMS"
	echo "queue processing."
	echo
	do_confirm
    fi


else # Not a Linux kernel target
    # These configuration items only make sense in the Linux kernel
    KSRC=
    KVER=
    CONFIG_MK_KERNEL=
    KERN_TARGET=
    STRMS_QUEUES=
    MOD_INST_DIR=
    MOD_INSTALL=
    KSMP=
    KMODULES=

    CONFIG_STREAMS=$TARGET
fi # Not a Linux kernel target

#
# DBG_OPT
#
PROMPT="\
When you make STREAMS, do you want to compile for source level debugging?\n\
This is most useful when STREAMS is linked into the kernel and the\n\
gdbstub patch is installed in the kernel for kernel source level debugging.\n\
    y = set up for source level debugging\n\
    n = no source level debugging\n\
Please enter y or n"
RESPONSE="y n"
DEFAULT=$DBG_OPT
do_read_choice
DBG_OPT=$RESULT


#
# LIS_SHLIB
#
PROMPT="\
Do you want to use shared libraries?
If you select static linking, you will get larger binaries that run by
themselves. If you select dynamic linking, the binaries will be smaller but
you will have to install the shared libraries in a directory that is in your
LD_LIBRARY_PATH environment variable.
    y = use dynamic linking with shared libraries\n\
    n = use static linking\n\
Please enter y or n"
RESPONSE="y n"
DEFAULT=$LIS_SHLIB
do_read_choice
LIS_SHLIB=$RESULT


#
# Finally output configuration file
#

cfg_out()
{
    if [ $# = 2 ]; then
        echo "$1=$2" >>$CONFIG
    else
        echo "# $1 is not set" >>$CONFIG
    fi
}

echo "" >$CONFIG
echo "# This file is generated from the Configure script" >>$CONFIG
echo "# Do not edit manually." >>$CONFIG
echo "" >>$CONFIG
cfg_out LIS_HOME $LIS_HOME
cfg_out CONFIG_STREAMS $CONFIG_STREAMS
if [ "$TARGET" = "l" ]; then
    cfg_out KSRC $KSRC
    cfg_out KVER $KVER
    cfg_out KVER_MAJOR $KVER_MAJOR
    cfg_out KVER_MINOR $KVER_MINOR
    cfg_out KVER_PATCH $KVER_PATCH
    cfg_out KVER_MAJORMINOR $KVER_MAJORMINOR
    cfg_out KSMP $KSMP
    cfg_out KMODULES $KMODULES
    cfg_out KMODVERS $KMODVERS
    cfg_out CONFIG_MK_KERNEL $CONFIG_MK_KERNEL 
    cfg_out KERN_TARGET $KERN_TARGET
    cfg_out STRMS_QUEUES $STRMS_QUEUES
    cfg_out MOD_INST_DIR $MOD_INST_DIR
    cfg_out MOD_INSTALL $MOD_INSTALL
fi
cfg_out DBG_OPT $DBG_OPT
cfg_out LIS_SHLIB $LIS_SHLIB

if [ "$MAKE_INVOKED" != "1" ]; then
    echo
    echo "Warning:"
    echo "You did not use \"make configure\" to run this configuration."
    echo "Please do \"make clean && make dep\" first to get a clean build."
fi
