#!/bin/sh 
#
# Configure -- configure lsof
#
# See the LSOF_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 $LSOF_MK, that places its source modules in this
# directory.
#
# $Id: Configure,v 1.64 95/09/05 07:31:55 abe Exp $

#LSOF_DISTRIBKVM may be instroduced through the environment to specify the
#	    Sun4 kernel virtual memory type of distrib.cf

LSOF_F="ddev.c dfile.c dlsof.h dmnt.c dnode*.c dproc.c dproto.h dsock.c dstore.c kernelbase.h machine.h"
LSOF_HLP=/tmp/cfghlp.$$

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

LSOF_MK=Mksrc

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

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

if test "X$LSOF_MKFC" = "X"
then
  LSOF_MKFC=Makefile
fi

LSOF_MKF=Makefile

LSOF_VF=version

# Make sure no other variable important to Makefile construction is
# already set in the environment.
#
#	$LSOF_CC	    C compiler name (default = none)
#	$LSOF_CFGD	    depend options
#	$LSOF_CFGDN	    depend file name
#	$LSOF_CFGF	    C flags -- e.g., -D's
#	$LSOF_CFGL	    loader flags -- e.g., -l's
#	$LSOF_DEBUG	    Makefile's DEBUG string
#	$LSOF_DINC	    include flags -- -I's
#	$LSOF_DOC	    special document (man page) directory path
#	$LSOF_LOCALSUFFIX   local suffix for Makefile -- e.g., PUCC for
#			    Purdue University Computing Center's special
#			    Makefile

LSOF_CC=""
LSOF_CFGD=""
LSOF_CFGDN=""
LSOF_CFGF=""
LSOF_CFGL=""
LSOF_DEBUG=""
LSOF_DINC=""
LSOF_DOC=""

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

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

rm -f $LSOF_HLP
cat > $LSOF_HLP << LSOF_HLP
Usage: Configure <options> <target-dialect>
  <options> may be:
    -clean     : clean up previous configuration
    -h|-help   : display help information
  <target-dialect> may be:
    aix        : IBM AIX
    dcosx      : Pyramid DC/OSx 1.1 For ES, Nile, and S series
    decosf     : DEC OSF/1 1.x, 2.0, and 3.0
    dynix      : Purdue Dynix 3.0.12
    dynix3012  : Sequent Dynix 3.0.12
    dynix31    : Sequent Dynix 3.1
    epix211    : EP/IX 2.1.1 for the CDC 4680
    freebsd    : FreeBSD 1.1.5.1, 2.0, and 2.0.5
    hpux       : HP-UX 8, 9, or 10
    irix       : SGI Irix 4.0.5H, 5.2, 5.3, and 6.0
    linux      : Linux
    netbsd     : NetBSD 1.0 and 1.0A
    next3      : NEXTSTEP 3.[0123], all architectures
    ptx        : Sequent PTX 2.1.5, 2.1.6, and 4.0.[23]
    riscos     : RISCos 4.52 for RS2030
    sco        : SCO Open Desktop or Open Server 1.1 and 3.0
    solaris    : Solaris 2.[1234], using gcc
    solariscc  : Solaris 2.[1234], using Sun's cc
    sunos413   : SunOS 4.1.3, using gcc
    sunos413cc : SunOS 4.1.3, using Sun's cc
    ultrix22   : Purdue version of Ultrix 2.2
    ultrix     : Ultrix 4.2, 4.3, or 4.4
    uw11       : Novell UnixWare 1.1
    uw11nonet  : Novell UnixWare 1.1, no inet/nfs net packages
    v88        : Motorola V/88 Releases R32V3 and R40V4.2
LSOF_HLP

LSOF_TGT="no-target"

args=$#
while test $args -gt 0
do
  case $1 in
    -clean)
      if test -r $LSOF_MKFC
      then
	make -f $LSOF_MKFC clean
      fi
      rm -f $LSOF_F $LSOF_MKFC $LSOF_HLP version.h
      echo rm -f $LSOF_F $LSOF_MKFC version.h
      rm -f $LSOF_HLP
      exit 0
      ;;
 
    -h|-help) cat $LSOF_HLP
      rm -f $LSOF_HLP
      exit 0
      ;;

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

case $LSOF_TGT in
 no-target)
   echo "No target dialect was specified."
   cat $LSOF_HLP
   rm -f $LSOF_HLP
   exit 1
   ;;

  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."
      LSOF_CFGF=`/usr/bin/oslevel | sed 's/[^0-9]*\(.*\)/-D_AIXV=\1/' | sed 's/\.//g'`
    else
      echo "Can't execute /usr/bin/oslevel; assuming AIX version is 3.2.0."
      LSOF_CFGF="-D_AIXV=3200"
    fi
    LSOF_CFGL=""
    LSOF_DIALECT_DIR=aix
    ;;

  dcosx)
    LSOF_CFGL="-lc -lsocket -lnsl -lelf -L/usr/ucblib -lucb"
    LSOF_DIALECT_DIR=dcosx
    case "`uname -p`" in
      r3???)		# S and ES series machine.
	LSOF_CFGF=""
	;;
      r4???)    	# Nile Series machine.
	LSOF_CFGF="-DVIRTUAL_COLOR -DJOLT -DR4000"
	;;
      *)
	echo Unknown DC/OSx processor type: `uname -p`
	rm -f $LSOF_HLP
	exit 1
	;;
    esac
    if test -r /usr/include/sys/fs/vx_fs.h -a -r /usr/include/sys/fs/vx_inode.h
    then
      LSOF_CFGF="$LSOF_CFGF -DHASRXFS"
    fi
    ;;

  decosf)
    echo "Please enter the name of the subdirectory in /sys that contains"
    echo "the configuration files for this host.  Its name is usually an"
    echo "upper case derivative of the host name -- e.g., TOMIS from"
    echo "tomis.bio.purdue.edu.  If you don't have a subdirectory with a"
    echo "name like that, you may have one named BINARY, and you can try to"
    echo "use it.  The lsof compilation needs header files that are located"
    echo "in the subdirectory."
    LSOF_LOOP=1
    while test $LSOF_LOOP = 1
    do
	echo ""
	echo "/sys contains:"
	echo ""
	ls -CF /sys
	echo ""
        echo -n "Configuration subdirectory name? "
        read LSOF_CDIR LSOF_EXCESS
	if test -d /sys/$LSOF_CDIR -a "X$LSOF_CDIR" != "X"
	then
	    LSOF_LOOP=0
	else
	    echo ""
	    echo Cannot access directory /sys/$LSOF_CDIR.
	fi
    done
    case "`uname -r`" in
      V2.0)
	LSOF_OSF1V=20000
	LSOF_DEC_A=2
	;;
      V3.0)
	LSOF_OSF1V=30000
	LSOF_DEC_A=3
	;;
      V3.2)
	LSOF_OSF1V=30200
	LSOF_DEC_A=3.2
	;;
      *)
	echo "WARNING: unknown OSF/1 version; assuming version is 1.0"
	LSOF_OSF1V=10000
	LSOF_DEC_A=1
	;;
    esac
    echo "Determining the ADVFS version -- this will take a while."
    LSOF_ADVFSV=`/usr/sbin/setld -i | grep \^OSFADVFSBIN | sed 's/\([^ ]*\).*/\1/' | sort -u | tail -1 | sed 's/OSFADVFSBIN//'`
    case $LSOF_ADVFSV in
      1*)
	LSOF_ADVFSV=100
	echo "The ADVFS version is 1."
	;;
      2*)
	LSOF_ADVFSV=200
	echo "The ADVFS version is 2."
	;;
      3*)
	LSOF_ADVFSV=300
	echo "The ADVFS version is 3."
	;;
      *)
	echo "The ADVFS version is unknown; it will be assumed to be 1."
	LSOF_ADVFSV=100
	;;
    esac
    LSOF_CFGF="-D_OSF1V=$LSOF_OSF1V -D_ADVFSV=$LSOF_ADVFSV"
    LSOF_DINC="-I./dialects/osf/dec_a/$LSOF_DEC_A -I/usr/include -I/sys/$LSOF_CDIR"
    LSOF_CFGL="-lmld"
    LSOF_DIALECT_DIR=osf
    ;;

  dynix)
    LSOF_CFGF=""
    LSOF_CFGL=""
    LSOF_DIALECT_DIR=dynix
    ;;

  dynix3012)
    LSOF_CFGF="-DSEQUENT"
    LSOF_CFGL=""
    LSOF_DIALECT_DIR=dynix
    ;;

  dynix31)
    LSOF_CFGF="-DDYNIX31 -USEQUENT"
    LSOF_CFGL=""
    LSOF_DIALECT_DIR=dynix
    ;;

  epix211)
    LSOF_CFGF="-D_EPIXV=20101"
    LSOF_CFGL="-lmld -lsun"
    LSOF_DIALECT_DIR=epix
    ;;

  freebsd)
    case "`uname -r`" in
    1.*)
      LSOF_CFGF="-D_FREEBSDV=100"
      LSOF_CFGL="-lutil"
      LSOF_DINC="-I./dialects/freebsd/include/1"
      LSOF_N_UNIX=/386bsd
      ;;
    2.0-*)
      LSOF_CFGF="-D_FREEBSDV=200"
      LSOF_CFGL="-lkvm"
      LSOF_DINC="-I./dialects/freebsd/include/2"
      LSOF_N_UNIX=`/usr/sbin/sysctl -n kern.bootfile`
      if test "X$LSOF_N_UNIX" = "X"
      then
	LSOF_N_UNIX=/kernel
      fi
      ;;
    2.0.5-*)
      LSOF_CFGF="-D_FREEBSDV=205"
      LSOF_CFGL="-lkvm"
      LSOF_DINC="-I./dialects/freebsd/include/2"
      LSOF_N_UNIX=`/usr/sbin/sysctl -n kern.bootfile`
      if test "X$LSOF_N_UNIX" = "X"
      then
	LSOF_N_UNIX=/kernel
      fi
      ;;
    *)
      echo Unknown FreeBSD release: `uname -r`
      echo Assuming FreeBSD 1.x
      LSOF_CFGF="-D_FREEBSDV=100"
      LSOF_CFGL="-lutil"
      LSOF_DINC="-I./dialects/freebsd/include/1"
      LSOF_N_UNIX=/386bsd
      ;;
    esac
    if test ! -x $LSOF_N_UNIX
    then
      echo "Hmmm -- $LSOF_N_UNIX doesn't appear to be your kernel file."
      echo "Please enter the name of the file in / that contains"
      echo "the kernel for this host.  It must be a regular file,"
      echo "not a directory, and must be executable."
      LSOF_LOOP=1
      while test $LSOF_LOOP = 1
      do
	  echo ""
	  echo "/ contains:"
	  echo ""
	  ls -CF /
	  echo ""
          echo -n "Kernel file name? "
          read LSOF_N_UNIX LSOF_EXCESS
	  LSOF_N_UNIX="/$LSOF_N_UNIX"
	  if test ! -d $LSOF_N_UNIX -a -x $LSOF_N_UNIX
	  then
	    LSOF_LOOP=0
	  else
	    echo ""
	    echo $LSOF_N_UNIX is not a regular executable file.
	  fi
      done
    fi
    LSOF_N_UNIX=`echo $LSOF_N_UNIX | sed 's#^/*#/#'`
    LSOF_CFGF="$LSOF_CFGF -DN_UNIX=\\\"$LSOF_N_UNIX\\\""
    LSOF_DIALECT_DIR=freebsd
    ;;

  hpux)
    LSOF_CFGF=`uname -r | awk -F. '{printf "%d%02d",\$2,\$3}'`
    LSOF_CFGF="-D_HPUXV=$LSOF_CFGF"
    if test -d /etc/conf/x25
    then
      LSOF_CFGF="$LSOF_CFGF -DHPUX_CCITT"
      LSOF_DINC="-I/etc/conf"
    fi
    LSOF_CFGL=""
    LSOF_DIALECT_DIR=hpux
    ;;

  irix)
    case "`uname -r`" in
      4.0.5*)
	LSOF_CFGF="-D_IRIXV=40005"
	LSOF_CFGL="-lmld -lsun -lc_s"
	;;
      5.2*)
	LSOF_CFGF="-D_IRIXV=50200"
	LSOF_CFGL="-lmld"
	LSOF_DINC="-I./dialects/sgi/irix5hdr"
	;;
      5.3*)
	LSOF_CFGF="-D_IRIXV=50300"
	LSOF_CFGL="-lmld"
	LSOF_DINC="-I./dialects/sgi/irix5hdr"
	;;
      6.0*)
	LSOF_CFGF="-D_IRIXV=50200 -DIRIX64BITS -woff 1411,1174,1107"
	LSOF_CFGL="-lelf"
	LSOF_DINC="-I./dialects/sgi/irix6hdr"
	;;
      6.1*)
	LSOF_CFGF="-64 -D_IRIXV=50300 -DIRIX64BITS -D_HIBERNATORII -D_SHAREII"
	LSOF_CFGL="-lelf"
	LSOF_DINC="-I./dialects/sgi/irix61hdr -I/usr/include/sys/fs"
	;;
      *)
	echo Unknown Irix release: `uname -r`
	rm -f $LSOF_HLP
	exit 1
	;;
    esac
    LSOF_DIALECT_DIR=sgi
    ;;

  irix52)
    LSOF_CFGF="-D_IRIXV=050200"
    LSOF_CFGL="-lmld"
    LSOF_DINC="-I./dialects/sgi/irix5hdr"
    LSOF_DIALECT_DIR=sgi
    ;;

  linux)
    LSOF_CFGF=`uname -r|sed 's/\./ /g'|awk '{printf "%d%d%02d",\$1,\$2,\$3}'`
    LSOF_CFGF="-DLINUXV=$LSOF_CFGF"
    if test -r /usr/src/linux/net/inet/sock.h
    then
      LSOF_CFGL="net/inet/sock.h"
    else
      if test -r /usr/src/linux/include/net/sock.h
      then
        LSOF_CFGL="include/net/sock.h"
	LSOF_DINC="-I/usr/src/linux/include"
      else
	LSOF_CFGL=""
      fi
    fi
    if test "X$LSOF_CFGL" != "X"
    then
      grep protinfo /usr/src/linux/${LSOF_CFGL} > /dev/null 2>&1
      if test $? -eq 0
      then
	LSOF_CFGF="${LSOF_CFGF} -DHASUNMINSOCK"
      fi
    fi
    if test -r /usr/include/linux/netdevice.h
    then
      LSOF_CFGF="$LSOF_CFGF -DHASNETDEVICE_H"
    fi
    if test ! -r /zSystem.map
    then
      if test -r /System.map
      then
	LSOF_CFGF="$LSOF_CFGF -DN_UNIX=\\\"/System.map\\\""
      else
	echo "WARNING: can't find /zSystem.map or /System.map;"
	echo "         assuming /zSystem.map"
      fi
    fi
    LSOF_CFGL=""
    LSOF_DIALECT_DIR=linux
    ;;

  netbsd)
    case "`uname -r`" in
      1.0*)
	;;
      *)
	echo Unknown NetBSD release: `uname -r`
	echo Assuming NetBSD 1.0 or 1.0A
	;;
      esac
      LSOF_CFGF=""
      LSOF_CFGL="-lkvm"
      LSOF_DIALECT_DIR=netbsd
      ;;

  next3)
    LSOF_CFGF=""
    LSOF_CFGL=""
    LSOF_DIALECT_DIR=next
    ;;

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

    # PTS 4.x tests

      if test -r /usr/conf/uts/nfs/rnode.h
      then
	LSOF_CFGF="$LSOF_CFGF -DHAS_NFS"
      fi
      LSOF_CFGL="-lelf -linet -lnsl -lseq"
    else

    # PTX 2.x tests

      if test -r /usr/include/nfs/rnode.h
      then
	LSOF_CFGF="$LSOF_CFGF -DHAS_NFS"
      fi
      LSOF_CFGL="-linet -lnsl -lseq"
    fi
    LSOF_CFGF="-D_PTXV=$LSOF_CFGF"
    if test -r /usr/include/sys/cdfsinode.h
    then
	LSOF_CFGF="$LSOF_CFGF -DHAS_CDFS"
    fi
    LSOF_DIALECT_DIR=ptx
    ;;

  sco)
    case "`uname -X 2>/dev/null | grep Release | sed 's/Release = \(.*\)/\1/'`" in
      3.2v2.0)
	LSOF_CFGF="-D_SCOV=20"
	LSOF_CFGL="-lsocket -lc_s"
	LSOF_DEBUG="-Ox"
	LSOF_MKC="cp"
	;;
      3.2v2.1)
	LSOF_CFGF="-D_SCOV=21 -nointl"
	LSOF_CFGL="-lsocket -lc_s"
	LSOF_DEBUG="-Ox"
	LSOF_MKC="cp"
	;;
      3.2v4.0)
	LSOF_CFGF="-D_SCOV=40 -nointl"
	LSOF_CFGL="-lsocket -lc_s"
	LSOF_DEBUG="-Ox"
	;;
      3.2v4.1)
	LSOF_CFGF="-D_SCOV=41 -nointl"
	LSOF_CFGL="-lsocket -lc_s"
	LSOF_DEBUG="-Ox"
	;;
      3.2v4.2)
	LSOF_CFGF="-D_SCOV=42 -nointl"
	LSOF_CFGL="-lsocket -lc_s"
	LSOF_DEBUG="-Ox"
	;;
      3.2v5.0.0)
	LSOF_CFGF="-D_SCOV=500 -belf"
	LSOF_CFGL="-lsocket"
	LSOF_DEBUG="-O3 -Kspace"
	;;
      *)
	echo Unknown SCO Unix release: `uname -X | grep Release`
	echo Assuming 3.2.0 or 3.2.1
	LSOF_CFGF="-D_SCOV=0 -nointl"
	LSOF_CFGL="-lsocket -lc_s"
	LSOF_DEBUG="-Ox"
	LSOF_MKC="cp"
	;;
    esac
    nm /lib/libc.a | grep statlstat > /dev/null 2>&1
    if test $? -eq 0
    then
      LSOF_CFGF="$LSOF_CFGF -DHAS_STATLSTAT"
    fi
    if test ! -r /usr/include/netdb.h
    then
      LSOF_DINC="-I./dialects/sco/include"
    fi
    LSOF_DIALECT_DIR=sco
    ;;

  solaris*)
    if test "X$LSOF_TGT" = "Xsolariscc"
    then
      LSOF_CC=cc
      LSOF_TGT="solaris"
    else
      LSOF_CC=gcc
    fi

# Solaris patch 101318-32 creates a longer kernel tcp_s structure.
# If it appears the patch is installed, define PATCH_101318_32 so
# dsock.c can adjust its local definition of tcp_s.

    case "`uname -r`" in
      5.3)
	LSOF_PL=`grep -h SUNW_PATCHID=101318 /var/sadm/pkg/SUNWcar*/pkginfo | sed 's/.*-//' | sort -u | tail -1`
	: ${LSOF_PL:=0}
	if test $LSOF_PL -lt 32
	then
	  LSOF_CFGF="-Dsolaris=20300"
	  echo "Kernel patch 101318-32 (or above) is probably not installed."
	else
	  LSOF_CFGF="-Dsolaris=20300 -DPATCH_101318_32"
	  echo "Kernel patch 101318-32 (or above) may be installed."
	fi;;
      5.[0-2])
	  LSOF_CFGF="-Dsolaris=20300";;
      5.4)
	  LSOF_CFGF="-Dsolaris=20400";;
      5.5)
	  LSOF_CFGF="-Dsolaris=20500";;
      *)
	  echo Unknown Solaris version: `uname -r`
	  rm -f $LSOF_HLP
	  exit 1
    esac
    LSOF_CFGL="-lkvm -lelf -lsocket -lnsl"
    LSOF_DIALECT_DIR=sun
    if test "X$LSOF_LOCALSUFFIX" = "XPUCC"
    then
      LSOF_DOC="\${DESTDIR}/usr/local/man"
    fi
    ;;

  sunos413*)
    if test "X$LSOF_TGT" = "Xsunos413"
    then
      LSOF_CC=gcc
      LSOF_CFGF="-ansi"
    else
      LSOF_CC=cc
      LSOF_CFGF="-DNOCONST"
    fi
    LSOF_CFGF="$LSOF_CFGF -DSUNOSV=40103"
    LSOF_CFGL="-lkvm"
    LSOF_DIALECT_DIR=sun
    if test "X$LSOF_LOCALSUFFIX" = "XPUCC"
    then
      LSOF_DOC="\${DESTDIR}/usr/man"
    fi
    ;;

  ultrix22)
    LSOF_CFGF="-DULTRIXV=20200 -DHASPWSTAYOPEN"
    LSOF_CFGL=""
    LSOF_DIALECT_DIR=ultrix
    ;;

  ultrix)
    case "`uname -r`" in
      4.2)
	LSOF_CFGF="-DULTRIXV=40200"
	;;
      4.3)
	LSOF_CFGF="-DULTRIXV=40300"
	;;
      4.4)
	LSOF_CFGF="-DULTRIXV=40400"
	;;
      *)
	echo Unknown Ultrix release: `uname -r`
	rm -f $LSOF_HLP
	exit 1
	;;
    esac
    case "`uname -m`" in
      RISC)
	;;
      VAX)
	LSOF_CFGF="$LSOF_CFGF -DVAXULTRIX"
	;;
      *)
	echo Unknown machine hardware name: `uname -m`
	rm -f $LSOF_HLP
	exit 1
	;;
    esac
    if test -r /usr/lib/libdnet.a -a -r /usr/include/netdnet/dn.h
    then
      LSOF_CFGL="-ldnet"
      LSOF_CFGF="$LSOF_CFGF -DDECnet"
    else
      LSOF_CFGL=""
    fi
    LSOF_DIALECT_DIR=ultrix
    ;;

  riscos)
    case "`uname -r`" in
      4_52)
	LSOF_RISCOSV=452
	;;
      *)
	echo Unknown RISCos version: `uname -r`
	echo Assuming version is 4_52.
	LSOF_RISCOSV=452
	;;
    esac
    LSOF_CFGF="-D_RISCOSV=$LSOF_RISCOSV"
    LSOF_CFGL="-lmld -lsun"
    LSOF_DIALECT_DIR=riscos
    ;;

  uw11)
    LSOF_CFGF="-DUWV=010100"
    LSOF_CFGL="-lc -lsocket -lnsl -lelf -L/usr/ucblib -lucb"
    LSOF_DIALECT_DIR=novell
    ;;

  uw11nonet)
    LSOF_CFGF="-DUWV=010100"
    LSOF_CFGL="-lc -lsocket -lnsl -lelf -L/usr/ucblib -lucb"
    LSOF_DIALECT_DIR=novell
    LSOF_DINC="-I./dialects/novell/uw11"
    ;;

  v88)
    case "`uname -r`" in
      R32V3)
	LSOF_CFGF="-DV88=30203"
	LSOF_CFGL=""
	;;
      4.0)
	LSOF_CFGL="-lsocket -lnsl -lelf"
	case "`uname -v`" in
	  R40V4.2)
	    LSOF_CFGF="-DV88=40402"
	    ;;
	  R40V4.3)
	    LSOF_CFGF="-DV88=40403"
	    ;;
	  *)
	    echo Unknown 4.0 version: `uname -v`
	    rm -f $LSOF_HLP
	    exit 1
	    ;;
	esac
	;;
      *)
	echo Unknown release: `uname -r`
	rm -f $LSOF_HLP
	exit 1
	;;
    esac
    LSOF_DIALECT_DIR=motorola
    ;;

  *) 
    echo "Can't configure for $LSOF_TGT."
    cat $LSOF_HLP
    rm -f $LSOF_HLP
    exit 1
    ;;
esac

# Make sure target directory exists.

if test ! -d ./dialects/$LSOF_DIALECT_DIR
then
  echo "Can't configure for $LSOF_TGT -- ./dialects/$LSOF_DIALECT_DIR doesn't exist."
  rm -f $LSOF_HLP
  exit 1
fi

# Make sure $LSOF_MK exists in the target directory.

if test ! -r ./dialects/$LSOF_DIALECT_DIR/$LSOF_MK
then
  echo "Can't configure for $LSOF_TGT -- ./dialects/$LSOF_DIALECT_DIR/$LSOF_MK doesn't exist."
  rm -f $LSOF_HLP
  exit 1
fi

# Make sure $LSOF_MKF (or $LSOF_MKF.$LSOF_LOCALSUFFIX) exists in the
# target directory.

if test "X$LSOF_LOCALSUFFIX" != "X"
then
  LSOF_REST=$LSOF_MKF.$LSOF_LOCALSUFFIX
else
  LSOF_REST=$LSOF_MKF
fi
if test ! -r ./dialects/$LSOF_DIALECT_DIR/$LSOF_REST
then
  echo "Can't configure for $LSOF_TGT -- ./dialects/$LSOF_DIALECT_DIR/$LSOF_REST doesn't exist."
  rm -f $LSOF_HLP
  exit 1
fi

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

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

# Clean up in advance.

rm -f $LSOF_F $LSOF_MKFC
echo rm -f $LSOF_F $LSOF_MKFC

# Make the dialect sources.

if test "X$LSOF_MKC" = "X"
then
  LSOF_MKC="ln -s"
fi
LSOF_MKC=$LSOF_MKC ./dialects/$LSOF_DIALECT_DIR/$LSOF_MK $LSOF_TGT

# Make $LSOF_MKFC.

echo "# $LSOF_TGT Makefile for lsof version $LSOF_VN" > $LSOF_MKFC
echo "" >> $LSOF_MKFC
if test "X$LSOF_CC" != "X"
then
  echo "CC=	$LSOF_CC" >> $LSOF_MKFC
else
  echo "CC=	cc" >> $LSOF_MKFC
fi
echo "" >> $LSOF_MKFC
if test "X$LSOF_CFGD" != "X"
then
  echo "CFGD=	$LSOF_CFGD" >> $LSOF_MKFC
fi
if test "X$LSOF_CFGDN" != "X"
then
  echo "CFGDN=	$LSOF_CFGDN" >> $LSOF_MKFC
fi
echo "CFGF=	$LSOF_CFGF" >> $LSOF_MKFC
echo "CFGL=	$LSOF_CFGL" >> $LSOF_MKFC
if test "X$LSOF_DEBUG" != "X"
then
  echo "DEBUG=	$LSOF_DEBUG" >> $LSOF_MKFC
fi
echo "" >> $LSOF_MKFC
if test "X$LSOF_DINC" != "X"
then
  echo "DINC=	$LSOF_DINC" >> $LSOF_MKFC
  echo "" >> $LSOF_MKFC
fi
if test "X$LSOF_DOC" != "X"
then
  echo "DOC=$LSOF_DOC" >> $LSOF_MKFC
fi
echo "" >> $LSOF_MKFC
if test "X$LSOF_DISTRIBKVM" != "X" -a "X$LSOF_DISTRIBKVM" != "XKVM"
then
  echo "KVM=	$LSOF_DISTRIBKVM" >> $LSOF_MKFC
  echo "" >> $LSOF_MKFC
fi
cat ./dialects/$LSOF_DIALECT_DIR/$LSOF_REST >> $LSOF_MKFC
echo $LSOF_MKFC created.
rm -f $LSOF_HLP
exit 0
