#!/bin/sh 
#
# Configure -- configure lslk
#
# See the LSLK_HLP here document for usage.
#
# When configuring for a particular dialect, <target-dialect>, this script
# requires that the subdirectory ./dialects/<target-dialect> contain a
# shell script, named $LSLK_MK, that places its source modules in this
# directory.
#
# $Id: Configure,v 1.22 2001/01/08 18:27:29 abe Exp $


LSLK_F="dmnt.c dlock.c dlock1.c dstore.c dlslk.h dproto.h kernelbase.h machine.h machine.h.old new_machine.h"
LSLK_HLP=/tmp/cfghlp.$$

#LSLK_LOCALSUFFIX may be introduced through the environment to select a local
#	          version of a Makefile.  It is used as a suffix to $LSLK_MKF.

LSLK_MK=Mksrc

#LSLK_MKC is the dialect's Mksrc create command -- default "ln -s".

# LSLK_MKFC may be introduced though the environment to change the name
# used for the created make file.

if test "X$LSLK_MKFC" = "X"	# {
then
  LSLK_MKFC=Makefile
fi	# }

LSLK_MKF=Makefile

LSLK_VF=version

# Make sure no other variable important to Makefile construction is
# already set in the environment.
#
#	$LSLK_CC	    C compiler name (default = none)
#	$LSLK_CCV	    C compiler version (default = none)
#	$LSLK_CFGD	    depend options
#	$LSLK_CFGDN	    depend file name
#	$LSLK_CFGF	    C flags -- e.g., -D's
#	$LSLK_CFGL	    loader flags -- e.g., -l's
#	$LSLK_DEBUG	    Makefile's DEBUG string
#	$LSLK_DINC	    include flags -- -I's
#	$LSLK_LOCALSUFFIX   local suffix for Makefile -- e.g., PUCC for
#			    Purdue University Computing Center's special
#			    Makefile
#	$LSLK_SCRIPT_CALL   Customize and Inventory scripts call status
#	$LSLK_TMP1	    internal temporary
#	$LSLK_TMPC	    /tmp temporary C source file name
#	$LSLK_VERS	    UNIX dialect version

LSLK_CC=""
LSLK_CCV=""
LSLK_CFGD=""
LSLK_CFGDN=""
LSLK_CFGF=""
LSLK_CFGL=""
LSLK_DEBUG=""
LSLK_DINC=""
LSLK_DOC=""
LSLK_SCRIPT_CALL="yes"
LSLK_TMP1=""
LSLK_TMPC=./lslk_Configure_tmp_$$
LSLK_VERS=""

# Make sure the help file is removed before an abnormal exit.

trap 'rm -f $LSLK_HLP; exit 1' 1 2 3 15

rm -f $LSLK_HLP
cat > $LSLK_HLP << LSLK_HLP
Usage: Configure <options> <target-dialect>
  <options> may be:
    -clean     : clean up previous configuration
    -h|-help   : display help information
    -n         : avoid customization and inventory check
  <target-dialect> may be:
    aix           : IBM AIX
    desosf        : DEC OSF/1, Digital UNIX, Tru64 UNIX 2.0, 3.0, 3.2, 4.0,
                    and 5.[01]
    digunix|du    : DEC OSF/1, Digital UNIX, Tru64 UNIX 2.0, 3.0, 3.2, 4.0,
                    and 5.[01]
    linux         : Linux
    ptx           : Sequent PTX 2.1.9, 4.2.1, 4.3, and 4.4
    osr|sco       : SCO Open Desktop or Open Server 3.0 and 5.0.[024]
    solaris       : Solaris 2.[12345], 2.5.1, and 2.[67] using gcc
    solariscc     : Solaris 2.[12345], 2.5.1, and 2.[67] using Sun's cc
    sunos         : SunOS 4.1.[34], using gcc
    sunoscc       : SunOS 4.1.[34], using Sun's cc
    tru64         : DEC OSF/1, Digital UNIX, Tru64 UNIX 2.0, 3.0, 3.2, 4.0,
                    and 5.[01]
LSLK_HLP

LSLK_TGT="no-target"

args=$#
while test $args -gt 0
do
  case $1 in	# {
    -clean)
      if test -r $LSLK_MKFC	# {
      then
	make -f $LSLK_MKFC clean
      fi	# }
      rm -f $LSLK_F $LSLK_MKFC $LSLK_HLP version.h dialects/osr/osr_*
      echo rm -f $LSLK_F $LSLK_MKFC version.h
      rm -f dialects/du/du5_sys_malloc.h
      echo "rm -f dialects.du.du5_sys_malloc.h"
      rm -f $LSLK_HLP
      exit 0
      ;;
 
    -h|-help) cat $LSLK_HLP
      rm -f $LSLK_HLP
      exit 0
      ;;

    -n*)
      LSLK_SCRIPT_CALL="no"
      ;;

    *)
      if test $LSLK_TGT != no-target	# {
      then
	echo "Only one dialect may be configured at a time."
	echo 'Both "$LSLK_TGT" and "$1" were specified.'
	cat $LSLK_HLP
	rm -f $LSLK_HLP
	exit 1
      else	# }{
	LSLK_TGT=$1
      fi	# }
      ;;
  esac	# }
  shift
  args=`expr $args - 1`
done

case $LSLK_TGT in	# {
  no-target)
    echo "No target dialect was specified."
    cat $LSLK_HLP
    rm -f $LSLK_HLP
    exit 1
    ;;

# Configure for IBM AIX.

  aix)
    if test -x /usr/bin/oslevel	# {
    then
      echo "Determining AIX version with /usr/bin/oslevel."
      echo "This may take a while, depending on your maintenance level."
      LSLK_CFGF=`/usr/bin/oslevel | sed 's/[^0-9]*\(.*\)/\1/' | sed 's/\.//g'`
      echo "Oslevel reports the version is $LSLK_CFGF."
    else	# }{
      LSLK_CFGF=`uname -rv | awk '{printf "%d%d00\n",\$2,\$1}'`
      echo "WARNING: can't execute /usr/bin/oslevel; uname -rv reports the"
      echo "         version is $LSLK_CFGF; edit CFGF in the Makefile to correct"
      echo "         the terminating 00; it should be 10 X the last AIX "
      echo "         version component -- e.g., 50 for AIX 3.2.5."
    fi	# }
    LSLK_CFGF="-DAIXV=$LSLK_CFGF"
    LSLK_CFGL=""
    LSLK_DIALECT_DIR=aix
    rm -f ${LSLK_TMPC}.*
    echo "main(){}" > ${LSLK_TMPC}.c
    cc -c ${LSLK_TMPC}.c -o ${LSLK_TMPC}.o -qlist > /dev/null 2>&1
    LSLK_CCV=`head -1 ${LSLK_TMPC}.lst | sed 's/\(.**\) ---.*/\1/'`
    rm ${LSLK_TMPC}.*
    ;;

# Configure for DEC OSF/1, Digital UNIX, and Tru64 UNIX.

  decosf|digunix|du|tru64)
    LSLK_CC=cc
    case `uname -r` in	# {
    V2.0)
      LSLK_DUV=20000
      ;;
    V3.0)
      LSLK_DUV=30000
      ;;
    V3.2)
      LSLK_DUV=30200
      ;;
    ?4.0)
      LSLK_DUV=40000
      ;;
    ?5.0)
      LSLK_DUV=50000
      ;;
    ?5.1)
      LSLK_DUV=50100
      ;;
    *)
      echo "WARNING: unknown version; assuming version is 2.0"
      LSLK_DUV=20000
      ;;
    esac	# }
    echo "Determining the ADVFS version -- this may take a while."
    LSLK_ADVFSV=`/usr/sbin/setld -i | grep "^OSFADVFSBIN[0-9]" | sed 's/\([^ ]*\).*/\1/' | sort -u | tail -1 | sed 's/OSFADVFSBIN//'`
    case $LSLK_ADVFSV in	# {
      1*)
	LSLK_ADVFSV=100
	echo "The ADVFS version is 1."
	;;
      2*)
	LSLK_ADVFSV=200
	echo "The ADVFS version is 2."
	;;
      3*)
	LSLK_ADVFSV=300
	echo "The ADVFS version is 3."
	;;
      4*)
	LSLK_ADVFSV=400
	echo "The ADVFS version is 4."
	;;
      5*)
	LSLK_ADVFSV=500
	echo "The ADVFS version is 5."
	;;
      *)
	echo "The ADVFS version is unknown; it will be assumed to be 1."
	LSLK_ADVFSV=100
	;;
    esac	# }
    LSLK_CFGF="-DDUV=${LSLK_DUV} -DADVFSV=${LSLK_ADVFSV}"
    LSLK_CFGL="-lmld"
    LSLK_HOST=`uname -n`
    if test  "${LSLK_DUV}" -lt 40000	# {
    then
	LSLK_SYSDIR=/sys
    else	# }{
	LSLK_SYSDIR=/usr/sys
    fi	# }
    LSLK_CDIR=`expr $LSLK_HOST : '\([^\.]*\)\..*$'`
    if test "X$LSLK_CDIR" = "X"	# {
    then
	LSLK_CDIR=$LSLK_HOST
    fi	# }
    LSLK_CDIR=`echo $LSLK_CDIR | tr a-z A-Z`
    LSLK_LOOP=1
    while test $LSLK_LOOP = 1
    do
	if test -d ${LSLK_SYSDIR}/$LSLK_CDIR	# {
	then
	    echo "Using header files in ${LSLK_SYSDIR}/$LSLK_CDIR"
	    LSLK_LOOP=0
	else	# }{
	    cat << .CAT_MARK

Please enter the name of the subdirectory in $LSLK_SYSDIR that contains the
configuration files for this host.  Usually its name would be $LSLK_CDIR, but
that subdirectory doesn't seem to exist.  The lslk compilation needs header
files specific to this machine's configuration found in that directory.  Lslk
may be able to use the BINARY subdirectory, if it exists. you can tell lslk
to use BINARY if you can't find anything else appropriate.

.CAT_MARK

	    echo "$LSLK_SYSDIR contains:"
	    echo ""
	    ls -CF $LSLK_SYSDIR
	    echo ""
	    echo -n "Configuration subdirectory name? "
	    read LSLK_CDIR LSLK_EXCESS
	    if test "X$LSLK_CDIR" = "X" -o ! -d ${LSLK_SYSDIR}/$LSLK_CDIR  # {
	    then
		echo ""
		echo Cannot access directory ${LSLK_SYSDIR}/$LSLK_CDIR.
	    fi	# }

	fi	# }
    done
    LSLK_DINC="-I/usr/sys/include -I${LSLK_SYSDIR}/$LSLK_CDIR"
    if test $LSLK_DUV -ge 50000	# {
    then

    # Make du5_sys_malloc.h for Tru64 UNIX and above.  Disable some compiler
    # warning messages to compensate for errors in Tru64 UNIX 5 RPC and XDR
    # header files.

      LSLK_TMP1=/usr/include/sys/malloc.h
      if test -r $LSLK_TMP1	# {
      then
        LSLK_TMP2=dialects/du/du5_sys_malloc.h
        rm -f $LSLK_TMP2
        echo "#if !defined(MANUFACTURED_DU5_SYS_MALLOC_H)" > $LSLK_TMP2
        echo "/* By lsof Configure:" `date` " */" >> $LSLK_TMP2
        echo "#define MANUFACTURED_DU5_SYS_MALLOC_H" >> $LSLK_TMP2
        grep "^#define[ 	]MALLOC_NUM_BUCKETS" $LSLK_TMP1 >> $LSLK_TMP2
        echo "struct percpukmembuckets {" >> $LSLK_TMP2
        sed '1,/^struct percpukmembuckets/d' $LSLK_TMP1 | sed -n '1,/^};/p' >> $LSLK_TMP2
        echo "#endif" >> $LSLK_TMP2
        LSLK_CFGF="$LSLK_CFGF -I`pwd`/dialects/du"
      fi	# }
    fi	# }
    LSLK_DIALECT_DIR=du
    ;;

# Configure for Linux.

  linux)
    LSLK_CC=gcc
    LSLK_CFGF=`uname -r|sed 's/\./ /g'|awk '{printf "%d%d%02d",\$1,\$2,\$3}'`
    LSLK_CFGF="-DLINUXV=$LSLK_CFGF"
    cat /proc/locks > /dev/null 2>&1
    LSLK_CFGL=""
    if test -r /proc/locks	# {
    then

    # Configure for /proc-based Linux lslk.

      LSLK_DIALECT_DIR=linux/proc

    else	# }{

    # Configure for /dev/kmem-based Linux lslk.

      if test -r /usr/src/linux/include/linux/autoconf.h	# {
      then
        egrep "^#define[  ]*CONFIG_KERNEL_ELF" /usr/src/linux/include/linux/autoconf.h > /dev/null
        if test $? -eq 0	# {
        then
          LSLK_CFGF="$LSLK_CFGF -DKERN_LD_ELF"
        fi	# }
      fi	# }
      LSLK_DIALECT_DIR=linux/kmem
    fi	# }
    ;;

# Configure for Sequent PTX 4.x.

  ptx)
    LSLK_VERS=`uname -v|awk -F. '{printf "%d%d%d",substr($1,2), $2, $3}'`
    if test $LSLK_VERS -ge 400	# {
    then

    # PTX 4.x tests

      if test $LSLK_VERS -lt 410	# {
      then
        LSLK_CFGL="-lelf -linet -lnsl -lseq"
      else	# }{
        LSLK_CFGL="-lelf -lnsl -lseq -lsocket"
      fi	# }
    else	# }{

    # PTX 2.x

      LSLK_CFGL="-linet -lnsl -lseq"
    fi	# }
    LSLK_CFGF="-DPTXV=$LSLK_VERS $LSLK_CFGF"
    if test -r /usr/include/sys/vx_inode.h	# {
    then
      LSLK_CFGF="$LSLK_CFGF -DHASVXFS"
    fi	# }
    LSLK_DIALECT_DIR=ptx
    ;;

# Configure for SCO OpenServer.

  osr|sco)
    case "`LANG=C_C.C uname -X 2>/dev/null | grep Release | sed 's/Release = \(.*\)/\1/'`" in	# {
      3.2v4.2)
	LSLK_CFGF="-nointl"
	LSLK_CFGL="-lsocket -lc_s"
	LSLK_DEBUG="-Ox"
	LSLK_VERS="42"
	;;
      3.2v5.0.*)
	LSLK_CFGF="-belf"
	LSLK_CFGL="-lsocket"
	LSLK_DEBUG="-O3 -Kspace"
	LSLK_VERS="500"
	;;
      *)
	echo Unknown SCO Unix release: `uname -X | grep Release`
	echo Assuming 3.2v4.2
	LSLK_CFGF="-nointl"
	LSLK_CFGL="-lsocket -lc_s"
	LSLK_DEBUG="-Ox"
	LSLK_MKC="cp"
	LSLK_VERS="42"
	;;
    esac	# }
    LSLK_CFGF="-DOSRV=${LSLK_VERS} $LSLK_CFGF"
    /bin/nm /lib/libc.a | grep statlstat > /dev/null 2>&1
    if test $? -eq 0	# {
    then
      LSLK_CFGF="$LSLK_CFGF -DHAS_STATLSTAT"
    fi	# }
    if test -r /usr/include/sys/fs/nfs/rnode.h	# {
    then
      LSLK_CFGF="$LSLK_CFGF -DHAS_NFS"
    fi	# }
    if test ! -r /usr/include/netdb.h	# {
    then
      LSLK_DINC="-I./dialects/osr/include"
    fi	# }
    if test $LSLK_VERS -eq 500	# {
    then
      grep "^#if !defined(INKERNEL) && !defined(_KERNEL) && defined(__STAT_TYPES__)$" /usr/include/sys/net/memory.h >> /dev/null
      if test $? -ne 0	# {
        then
          echo "Applying __STAT_TYPES__  patch to <sys/net/memory.h>"
          rm -rf ./dialects/osr/osr_${LSLK_VERS}
          mkdir ./dialects/osr/osr_${LSLK_VERS}
          mkdir ./dialects/osr/osr_${LSLK_VERS}/sys
          mkdir ./dialects/osr/osr_${LSLK_VERS}/sys/net
          sed '/^#if !defined(INKERNEL) && !defined(_KERNEL)$/s/$/ \&\& defined(__STAT_TYPES__)/' < /usr/include/sys/net/memory.h > ./dialects/osr/osr_${LSLK_VERS}/sys/net/memory.h
      LSLK_DINC="$LSLK_DINC -I./dialects/osr/osr_${LSLK_VERS}"
      fi	# }
    fi	# }
    LSLK_DIALECT_DIR=osr
    ;;

# Configure for Sun Solaris 2.x.

  solaris*)
    if test "X$LSLK_TGT" = "Xsolariscc"	# {
    then
      LSLK_CC=cc
      LSLK_TGT="solaris"
    else	# }{
      LSLK_CC=gcc
    fi	# }
    case "`uname -r`" in	# {
      5.[0-2])
	echo "Lslk is untested for Solaris versions below 2.3, so Configure"
	echo "is assuming this is Solaris 2.3."
	LSLK_VERS="20300"
	;;
      5.3)
	LSLK_VERS="20300"
	;;
      5.4)
	LSLK_VERS="20400"
	;;
      5.5)
	LSLK_VERS="20500"
	;;
      5.5.1)
	LSLK_VERS="20501"
	;;
      5.6)
	LSLK_VERS="20600"
	;;
      5.7)
	LSLK_VERS="70000"
	;;
      5.8)
	LSLK_VERS="80000"
	;;
      *)
	echo Unknown Solaris version: `uname -r`
	echo "Configure is assuming this is Solaris 2.6."
	LSLK_VERS="20600"
	;;
    esac	# }
    LSLK_CFGF="-Dsolaris=$LSLK_VERS"

# Determine kernel bit size for Solaris 7 and 8.
    
    if test $LSLK_VERS -ge 70000	# {
    then
	/bin/isainfo -kv | grep 64 > /dev/null
	if test $? -eq 0	# {
	then
	  echo $LSLK_CC | grep gcc > /dev/null
	  if test $? -eq 0	# {
	  then

	# Test gcc for 64 bit support.

	    echo "Testing $LSLK_CC for 64 bit support"
	    rm -f ${LSLK_TMPC}.*
	    echo "main(){}" > ${LSLK_TMPC}.c
	    LSLK_TMP1=""

	# First try gcc's -m64 option -- it's the most current possibility.

	    $LSLK_CC ${LSLK_TMPC}.c -m64 -o ${LSLK_TMPC}.x > /dev/null 2>&1
	    if test $? -eq 0	# {
	    then
	      /bin/file ${LSLK_TMPC}.x | /bin/grep 64 > /dev/null 
	      if test $? -eq 0	# {
	      then
		LSLK_TMP1="-m64"
	      fi	# }
	    fi	# }
	    rm -f ${LSLK_TMPC}.*
	    if test "X$LSLK_TMP1" = "X"	# {
	    then

	    # Try using the older -mcpu=v9 option with gcc instead of -m64.

	      echo "main(){}" > ${LSLK_TMPC}.c
	      $LSLK_CC ${LSLK_TMPC}.c -mcpu=v9 -o ${LSLK_TMPC}.x > /dev/null 2>&1
	      if test $? -eq 0	# {
	      then
		/bin/file ${LSLK_TMPC}.x | /bin/grep 64 > /dev/null 
		if test $? -eq 0	# {
		then
		  LSLK_TMP1="-mcpu=v9"
		fi	# }
	      fi	# }
	      rm -f ${LSLK_TMPC}.*
	    fi	# }
	    if test "X$LSLK_TMP1" = "X"	# {
	    then
	      echo ""
	      echo "!!!WARNING!!!=========!!!WARNING!!!=========!!!WARNING!!!"
	      echo "!                                                       !"
	      echo "! LSLK NEEDS TO BE CONFIGURED FOR A 64 BIT KERNEL, BUT  !"
	      echo "! THIS GCC DOESN'T SUPPORT THE BUILDING OF 64 BIT       !"
	      echo "! SOLARIS EXECUTABLES.  LSLK WILL BE CONFIGURED FOR A   !"
	      echo "! 32 BIT echo KERNEL.                                   !"
	      echo "!                                                       !"
	      echo "!!!WARNING!!!=========!!!WARNING!!!=========!!!WARNING!!!"
	      echo ""
	    else
	     echo ""
	     echo "*********************************"
	     echo "* Configuring for 64 bit kernel *"
	     echo "*********************************"
	     echo ""
	     LSLK_CFGF="$LSLK_CFGF $LSLK_TMP1"
	     LSLK_CINFO="64 bit kernel"
	   fi	# }
	  else

	  # Test Sun compiler for 64 bit support.

	    echo "Testing $LSLK_CC for 64 bit support"
	    rm -f ${LSLK_TMPC}.*
	    echo "main(){}" > ${LSLK_TMPC}.c
	    LSLK_TMP1=0
	    $LSLK_CC ${LSLK_TMPC}.c -xarch=v9 -o ${LSLK_TMPC}.x > /dev/null 2>&1
	    if test $? -eq 0	# {
	    then
	      /bin/file ${LSLK_TMPC}.x | /bin/grep 64 > /dev/null 
	      if test $? -eq 0	# {
	      then
		LSLK_TMP1=1
	      fi	# }
	    fi	# }
	    rm -f ${LSLK_TMPC}.*
	    if test $LSLK_TMP1 -eq 1	# {
	    then
	      LSLK_CFGF="$LSLK_CFGF -xarch=v9"
	      echo ""
	      echo "*********************************"
	      echo "* Configuring for 64 bit kernel *"
	      echo "*********************************"
	      echo ""
	      LSLK_CINFO="64 bit kernel"
	    else
	      echo ""
	      echo "!!!WARNING!!!==========!!!WARNING!!!==========!!!WARNING!!!"
	      echo "!                                                         !"
	      echo "! LSLK NEEDS TO BE CONFIGURED FOR A 64 BIT KERNEL, BUT    |"
	      echo "! THE VERSION OF SUN C AVAILABLE DOESN'T SUPPORT THE      !"
	      echo "! -xarch=v9 FLAG.  LSLK WILL BE CONFIGURED FOR A 32 BIT   !"
	      echo "! KERNEL.                                                 !"
	      echo "!                                                         !"
	      echo "!!!WARNING!!!==========!!!WARNING!!!==========!!!WARNING!!!"
	      echo ""
	    fi	# }
	  fi	# }
	else
	  echo ""
	  echo "*********************************"
	  echo "* Configuring for 32 bit kernel *"
	  echo "*********************************"
	  echo ""
	  LSLK_CINFO="32 bit kernel"
	fi	# }
    fi # }
    LSLK_CFGL="-lkvm -lelf -lnsl"
    LSLK_DIALECT_DIR=solaris
    if test "X$LSLK_LOCALSUFFIX" = "XPUCC"	# {
    then
      LSLK_DOC="\${DESTDIR}/usr/local/man"
    fi	# }
    ;;

# Configure for Sun SunOS (Solaris 1.x).

  sunos*)
    if test "X$LSLK_TGT" = "Xsunos"	# {
    then
      LSLK_CC=gcc
      LSLK_CFGF="-ansi"
    else	# }{
      LSLK_CC=cc
      rm -f ${LSLK_TMPC}.*
      echo "main() { const x; }" > ${LSLK_TMPC}.c
      cc -c ${LSLK_TMPC}.c -o ${LSLK_TMPC}.o > /dev/null 2>&1
      if test $? -ne 0	# {
      then
        LSLK_CFGF="-DNOCONST"
      fi	# }
      rm -f ${LSLK_TMPC}.*
    fi	# }
    LSLK_CFGL="-lkvm"
    LSLK_DIALECT_DIR=sunos
    if test "X$LSLK_LOCALSUFFIX" = "XPUCC"	# {
    then
      LSLK_DOC="\${DESTDIR}/usr/man"
    fi	# }
    ;;

  *) 
    echo "Can't configure for $LSLK_TGT."
    cat $LSLK_HLP
    rm -f $LSLK_HLP
    exit 1
    ;;
esac	# }

# Do an inventory of the distribution, as required.

if test "X$LSLK_SCRIPT_CALL" = "Xyes" -a ! -r ./.neverInv	# {
then
  if test ! -x ./Inventory	# {
  then
    echo "Can't find or execute Inventory script."
    rm -f $LSLK_HLP
    exit 1
  fi	# }
  ./Inventory
fi	# }

# Make sure target directory exists.

if test ! -d ./dialects/$LSLK_DIALECT_DIR	# {
then
  echo "Can't configure for $LSLK_TGT -- ./dialects/$LSLK_DIALECT_DIR doesn't exist."
  rm -f $LSLK_HLP
  exit 1
fi	# }

# Make sure $LSLK_MK exists in the target directory.

if test ! -r ./dialects/$LSLK_DIALECT_DIR/$LSLK_MK	# {
then
  echo "Can't configure for $LSLK_TGT -- ./dialects/$LSLK_DIALECT_DIR/$LSLK_MK doesn't exist."
  rm -f $LSLK_HLP
  exit 1
fi	# }

# Make sure $LSLK_MKF (or $LSLK_MKF.$LSLK_LOCALSUFFIX) exists in the
# target directory.

if test "X$LSLK_LOCALSUFFIX" != "X"	# {
then
  LSLK_REST=$LSLK_MKF.$LSLK_LOCALSUFFIX
else	# }{
  LSLK_REST=$LSLK_MKF
fi	# }
if test ! -r ./dialects/$LSLK_DIALECT_DIR/$LSLK_REST	# {
then
  echo "Can't configure for $LSLK_TGT -- ./dialects/$LSLK_DIALECT_DIR/$LSLK_REST doesn't exist."
  rm -f $LSLK_HLP
  exit 1
fi	# }

# Make sure $LSLK_VF exists.  Extract the version number from it.

if test ! -r $LSLK_VF	# {
then
  echo "Version number file, ./$LSLK_VF, does not exist."
  rm -f $LSLK_HLP
  exit 1
else	# }{
  LSLK_VN=`sed "s/.ds VN \(.*\)/\1/" < version`
fi	# }

# Clean up in advance.

rm -f $LSLK_F $LSLK_MKFC
echo rm -f $LSLK_F $LSLK_MKFC

# Make the dialect sources.

if test "X$LSLK_MKC" = "X"	# {
then
  LSLK_MKC="ln -s"
fi	# }
LSLK_MKC=$LSLK_MKC ./dialects/$LSLK_DIALECT_DIR/$LSLK_MK $LSLK_TGT

# Make $LSLK_MKFC.

echo "# $LSLK_TGT Makefile for lslk version $LSLK_VN" > $LSLK_MKFC
echo "" >> $LSLK_MKFC
if test "X$LSLK_CC" != "X"	# {
then
  echo "CC=	$LSLK_CC" >> $LSLK_MKFC
else	# }{
  echo "CC=	cc" >> $LSLK_MKFC
fi	# }
if test "X$LSLK_CCV" != "X"	# {
then
  echo "CCV=	$LSLK_CCV" >> $LSLK_MKFC
else	# }{
  if test "X$LSLK_CC" = "Xgcc"	# {
  then
    LSLK_CCV=`gcc -v 2>&1 | sed -n 's/.*version \(.*\)/\1/p'`
    echo "CCV=	$LSLK_CCV" >> $LSLK_MKFC
  fi	# }
fi	# }
echo "" >> $LSLK_MKFC
if test "X$LSLK_CFGD" != "X"	# {
then
  echo "CFGD=	$LSLK_CFGD" >> $LSLK_MKFC
fi	# }
if test "X$LSLK_CFGDN" != "X"	# {
then
  echo "CFGDN=	$LSLK_CFGDN" >> $LSLK_MKFC
fi	# }
echo "CFGF=	$LSLK_CFGF" >> $LSLK_MKFC
echo "CFGL=	$LSLK_CFGL" >> $LSLK_MKFC
if test "X$LSLK_DEBUG" != "X"	# {
then
  echo "DEBUG=	$LSLK_DEBUG" >> $LSLK_MKFC
fi	# }
echo "" >> $LSLK_MKFC
if test "X$LSLK_DINC" != "X"	# {
then
  echo "DINC=	$LSLK_DINC" >> $LSLK_MKFC
  echo "" >> $LSLK_MKFC
fi	# }
if test "X$LSLK_DOC" != "X"	# {
then
  echo "DOC=$LSLK_DOC" >> $LSLK_MKFC
fi	# }
echo "" >> $LSLK_MKFC
cat ./dialects/$LSLK_DIALECT_DIR/$LSLK_REST >> $LSLK_MKFC
echo $LSLK_MKFC created.
rm -f $LSLK_HLP
exit 0
