#!/bin/sh 
#
# Configure -- configure lsof
#
# See the LSOF_HLP here document for usage.
#
# See the lsof distribution file 00XCONFIG for information on setting
# environment variables for cross-configuring lsof -- e.g., for configuring
# for Linux 2.1.42 on a machine running 2.0.30.  Marty Leisner
# <leisner@sdsp.mc.xerox.com> suggested this support and provided the Linux
# Configure stanza modifications.
#
# 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.37 97/12/15 07:44:43 abe Exp $

#LSOF_DISTRIBKVM may be introduced 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 machine.h.old new_machine.h __lseek.s"
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_LIB=lib
LSOF_MKF=Makefile
LSOF_LIBMKF=Makefile
LSOF_LIBMKFSKEL=Makefile.skel

LSOF_VF=version

# Make sure no other variable important to Makefile construction is
# already set in the environment.
#
#	$AFS_VICE	    locate of AFS VICE directory (default = /usr/vice)
#	$LSOF_AFS	    AFS temporary
#	$LSOF_AFSV	    AFS version
#	$LSOF_AR	    archive command for making the lsof library
#	$LSOF_CC	    C compiler name (default = none)
#	$LSOF_CCV	    C compiler version (default = none)
#	$LSOF_CDIR	    configuration directory
#	$LSOF_CFGD	    depend options
#	$LSOF_CFGDN	    depend file name
#	$LSOF_CFGF	    C flags -- e.g., -D's
#	$LSOF_CFGL	    last lsof library 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_ERR	    internal error flag
#	$LSOF_FCFGL	    first lsof library loader flags -- e.g., -l's
#			    that must precede $LSOF_LIB
#	$LSOF_HOST	    host name (e.g., from uname -n)
#	$LSOF_INCLUDE	    directory where header files are found
#			    (default = /usr/include)
#	$LSOF_LD	    loader name if not $LSOF_CC
#	$LSOF_LINUX_INCL    temporary variable for holding path to Linux
#			    include files
#	$LSOF_LOCALSUFFIX   local suffix for Makefile -- e.g., PUCC for
#			    Purdue University Computing Center's special
#			    Makefile
#	$LSOF_PL	    patch level
#	$LSOF_RANLIB	    randomizing command for the lsof library
#	$LSOF_SCRIPT_CALL   Customize and Inventory scripts call status
#	$LSOF_SPMKF	    Special Makefile name
#	$LSOF_TMP1	    internal temporary
#	$LSOF_TMP2	    internal temporary
#	$LSOF_TMPC_BASE	    base name for $LSOF_TMPC
#	$LSOF_TMPC	    /tmp temporary C source file base name
#	$LSOF_VERS	    Unix dialect version -- may be supplied
#			    externally

if test "X$AFS_VICE" = "X"
then
  AFS_VICE="/usr/vice"
fi
LSOF_AFS=""
LSOF_AFSV=""
LSOF_AR="ar cr \${LIB} \${OBJ}"
LSOF_CC=""
LSOF_CCV=""
LSOF_CDIR=""
LSOF_CFGD=""
LSOF_CFGDN=""
LSOF_CFGF=""
LSOF_CFGL=""
LSOF_DEBUG=""
LSOF_DOC=""
LSOF_ERR=""
LSOF_FCFGL=""
LSOF_HOST=""
if test "X$LSOF_INCLUDE" = "X"
then
  LSOF_DINC=""
  LSOF_INCLUDE="/usr/include"
else
  LSOF_DINC="-I$LSOF_INCLUDE"
fi
LSOF_LD=""
LSOF_LINUX_INCL=""
LSOF_PL=""
LSOF_RANLIB="ranlib \${LIB}"
LSOF_SCRIPT_CALL="yes"
LSOF_SPMKF=""
LSOF_TMP1=""
LSOF_TMP2=""
LSOF_TMPC_BASE=./lsof_Configure_tmp_
LSOF_TMPC=${LSOF_TMPC_BASE}$$
if test "X$LSOF_VERS" = "X"
then
  LSOF_VERS=""
fi

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

trap 'rm -f $LSOF_HLP ${LSOF_TMPC_BASE}*; exit 1' 1 2 3 15

rm -f $LSOF_HLP
cat > $LSOF_HLP << LSOF_HLP
Usage: Configure <options> <target-dialect>
  <options>:  -clean        : clean up previous configuration
              -d|-dialects  : display a list of supported dialect versions
              -h|-help      : display help information
              -n            : avoid AFS, customization, and inventory checks
  <target-dialect> (****USE -d TO GET TESTED DIALECT VERSION NUMBERS****):
    aix|aixgcc              : IBM AIX xlc (aix) or gcc (aixgcc)
    bsdi                    : BSDI BSD/OS
    digital_unix|du|decosf  : Digital UNIX (nee DEC OSF/1)
    freebsd                 : FreeBSD
    hpux|hpuxgcc            : HP-UX cc (hpux) or gcc (hpuxgcc)
    irix                    : SGI IRIX
    linux                   : Linux
    netbsd                  : NetBSD
    nextstep|next|ns|nxt    : NEXTSTEP
    openbsd                 : OpenBSD
    osr|sco                 : SCO OpenServer
    pyramid|pyr             : Pyramid DC/OSx and Reliant UNIX
    ptx                     : Sequent PTX
    riscos                  : MIPS RISCos
    solaris|solariscc       : Solaris gcc (solaris) or cc (solariscc)
    sunos|sunoscc           : SunOS gcc (sunos) or cc (sunoscc)
    ultrix                  : Ultrix
    unixware|uw             : SCO UnixWare
LSOF_HLP

LSOF_TGT="no-target"

args=$#
while test $args -gt 0
do
  case $1 in
    -clean)
      if test -r $LSOF_MKFC
      then
	echo "make -f $LSOF_MKFC clean"
	make -f $LSOF_MKFC clean
      else
	if test -r ${LSOF_LIB}/${LSOF_LIBMKF}
	then
	  echo "(cd ${LSOF_LIB}; make -f ${LSOF_LIBMKF} clean)"
	  (cd ${LSOF_LIB}; make -f ${LSOF_LIBMKF} clean)
	else
	  if test -r ${LSOF_LIB}/${LSOF_LIBMKF}.skel
	  then
	    echo "(cd ${LSOF_LIB}; make -f ${LSOF_LIBMKF}.skel clean)"
	    (cd ${LSOF_LIB}; make -f ${LSOF_LIBMKF}.skel clean)
	  fi
	fi
      fi
      rm -f $LSOF_F $LSOF_HLP $LSOF_MKFC ${LSOF_TMPC_BASE}*
      echo rm -f $LSOF_F $LSOF_HLP $LSOF_MKFC ${LSOF_TMPC_BASE}*
      rm -rf AFSHeaders AFSVersion version.h dialects/aix/aix41*
      echo rm -rf AFSHeaders AFSVersion version.h dialects/aix/aix41*
      rm -f cd9660_node.h dialects/uw/uw21/vm/swap.h
      echo "rm -f cd9660_node.h dialects/uw/uw21/vm/swap.h"
      rm -f ${LSOF_LIB}/${LSOF_LIBMKF}
      echo "rm -f ${LSOF_LIB}/${LSOF_LIBMKF}"
      exit 0
      ;;
 
    -d|-dialects)
      if test -r ./00DIALECTS -a -r ./version
      then
	V=`sed '/VN/s/.ds VN \(.*\)/\1/' version`
	echo "lsof $V has been *tested* on these UNIX dialect versions:"
	cat 00DIALECTS
	echo Although "$V hasn't been tested on other versions of these dialects,"
	echo "it may work.  Try \`Configure <dialect>\` and \`make\` to see."
	rm -f $LSOF_HLP
	exit 0
      else
	echo "Can't display UNIX dialect version information:"
	if test ! -r ./00DIALECTS
	then
	  echo "	./00DIALECTS is inaccessible."
	fi
	if test ! -r ./version
	then
	  echo "	./version is inaccessible."
	fi
	rm -f $LSOF_HLP
	exit 1
      fi
      ;;

    -h|-help) cat $LSOF_HLP
      rm -f $LSOF_HLP
      exit 0
      ;;

    -n*)
      LSOF_SCRIPT_CALL="no"
      ;;

    *)
      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
   ;;

# Configure for AIX xlc and AIX gcc.

  aix|aixgcc)
    if test "X$LSOF_VERS" = "X"
    then

      # If the AIX version isn't pre-defined, determine it.

      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_VERS=`/usr/bin/oslevel | sed 's/[^0-9]*\(.*\)/\1/' | sed 's/\.//g'`
	echo "Oslevel reports the version is $LSOF_VERS."
      else
	LSOF_VERS=`uname -rv | awk '{printf "%d%d00\n",\$2,\$1}'`
	echo "WARNING: can't execute /usr/bin/oslevel; uname -rv reports the"
	echo "         version is $LSOF_VERS; edit CFGF in the Makefile to correct"
	echo "         the terminating 00; it should be 10 X the last AIX "
	echo "         version component -- e.g., 40 for AIX 3.2.4."
      fi
    fi
    if test "X$LSOF_TGT" = "Xaixgcc"
    then
      if test $LSOF_VERS -lt 4100
      then
	echo "*****************************************************************"
	echo "* Sorry, but gcc can't be used to compile lsof for AIX versions *"
	echo "* less than 4.1, because of possible kernel structure alignment *"
	echo "* differences between it and xlc.                               *"
	echo "*****************************************************************"
	exit 1
      fi
      LSOF_CC=gcc
      LSOF_TGT="aix"
    else
      LSOF_CC=cc
    fi
    LSOF_CFGF="-DAIXV=$LSOF_VERS"

    # Test for AFS.

    if test -r ${AFS_VICE}/etc/ThisCell
    then
      if test "X$LSOF_SCRIPT_CALL" = "Xno"
      then
	if test -r ./AFSHeaders -a -r ./AFSVersion
	then
	  LSOF_AFS="yes"
	fi
      else
	if test ! -x ./AFSConfig
	then
	  echo "Can't find or execute the AFSConfig script"
	  exit 1
	fi
	./AFSConfig
	if test $? -eq 0 -a -r ./AFSHeaders -a -r ./AFSVersion
	then
	    LSOF_AFS="yes"
	fi
      fi
      if test "X$LSOF_AFS" = "Xyes"
      then
	LSOF_AFSV=`cat ./AFSVersion | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1 \2/' | awk '{printf "%d%02d\n",\$1,\$2}'`
	LSOF_CFGF="$LSOF_CFGF -DHAS_AFS=$LSOF_AFSV"
	LSOF_DINC="$LSOF_DINC -I`cat ./AFSHeaders`"
      fi
    fi

    # Miscellaneous AIX tests

    if test -d ${LSOF_INCLUDE}/nfs
    then
      LSOF_CFGF="$LSOF_CFGF -DHAS_NFS"
    fi
    if test "X$LSOF_CC" = "Xcc" -a $LSOF_VERS -ge 4140
    then
      LSOF_CFGL="-bnolibpath"
    fi
    LSOF_DIALECT_DIR=aix
    if test "X$LSOF_CC" = "Xgcc"
    then
      if test $LSOF_VERS -ge 4100 -a $LSOF_VERS -lt 4200
      then
	if test "X$AIX_USHACK" = "X"
	then

	  # Compile and run a gcc test program to evaluate the user structure.

	  rm -f ${LSOF_TMPC}.*
	  echo "#include <stddef.h>" > ${LSOF_TMPC}.c
	  echo "#include <sys/user.h>" >> ${LSOF_TMPC}.c
	  echo "main(){exit((offsetof(struct user, U_irss) & 0x7) ? 1 : 0);}" >>${LSOF_TMPC}.c
	  echo "Testing user.h with $LSOF_CC"
	  $LSOF_CC ${LSOF_TMPC}.c -o ${LSOF_TMPC}.x
	  if ! ${LSOF_TMPX}.x
	  then
	    LSOF_TMP1=1
	  else
	    LSOF_TMP1=0
	  fi
	  rm -f ${LSOF_TMPC}.*
	else
	  if test "$AIX_USHACK" = "Y" -o "$AIX_USHACK" = "y"
	  then
	    LSOF_TMP1=1
	  else
	    LSOF_TMP1=0
	  fi
	fi
	if test ${LSOF_TMP1} -eq 1
	then
	  echo "Applying gcc AIX 4.1+ user struct alignment hack"
	  rm -rf ./dialects/aix/aix$LSOF_VERS
	  mkdir ./dialects/aix/aix$LSOF_VERS
	  mkdir ./dialects/aix/aix${LSOF_VERS}/sys
	    sed 's/U_irss\[/dummy_for_alignment, U_irss\[/' < ${LSOF_INCLUDE}/sys/user.h > ./dialects/aix/aix${LSOF_VERS}/sys/user.h
	    LSOF_CFGF="$LSOF_CFGF -U_LONG_LONG -I`pwd`/dialects/aix/aix$LSOF_VERS"
	fi
      fi
    else

      # Get xlc version number

      rm -f ${LSOF_TMPC}.*
      echo "main(){}" > ${LSOF_TMPC}.c
      echo "Getting version number of $LSOF_CC"
      cc -c ${LSOF_TMPC}.c -I${LSOF_INCLUDE} -o ${LSOF_TMPC}.o -qlist > /dev/null 2>&1
      LSOF_CCV=`head -1 ${LSOF_TMPC}.lst | sed 's/\(.**\) ---.*/\1/'`
      rm ${LSOF_TMPC}.*
    fi
    ;;

# Configure for BSDI BSD/OS.

  bsdi)
    LSOF_CC="gcc"
    LSOF_LD="shlicc2"
    if test "X$LSOF_VERS" = "X"
    then

      # If the BSDI version isn't predefined, determine it.

      case "`uname -r`" in
      2.0*)
	LSOF_VERS="20000"
	;;
      2.1*)
	LSOF_VERS="20100"
	;;
      3.0*)
	LSOF_VERS="30000"
	;;
      3.1*)
	LSOF_VERS="30100"
	;;
      4.0*)
	LSOF_VERS="40000"
	;;
      *)  
	echo Unknown BSDI release: `uname -r`
	echo Assuming BSDI 2.0
	LSOF_VERS="20000"
	;;
      esac
    fi

    # Test for a legal BSDI version.

    case $LSOF_VERS in
    20000|20100|30000|30100|40000)
      ;;
    *)
      echo "Illegal BSDI version: $LSOF_VERS"
      rm -f $LSOF_HLP
      exit 1
      ;;
    esac
    LSOF_CFGF="-DBSDIV=$LSOF_VERS"
    if test -r ${LSOF_INCLUDE}/miscfs/fdesc/fdesc.h
    then
	LSOF_CFGF="$LSOF_CFGF -DHASFDESCFS"
    fi
    grep -q nc_vpid ${LSOF_INCLUDE}/sys/namei.h
    if test $? -eq 0
    then
      LSOF_CFGF="$LSOF_CFGF -DHASNCVPID"
    fi
    LSOF_CFGL="-lrpc -lkvm"
    LSOF_DIALECT_DIR=bsdi
    ;;

# Configure for Digital UNIX.

  digital_unix|du|decosf)
    if test "X$LSOF_DINC" = "X"
    then
      LSOF_DINC="-I/usr/include"
    fi
    if test "X$LSOF_VERS" = "X"
    then

      # If the Digital UNIX version isn't predefined, determine it.

      case "`uname -r`" in
      V2.0)
	LSOF_VERS=20000
	;;
      V3.0)
	LSOF_VERS=30000
	;;
      V3.2)
	LSOF_VERS=30200
	;;
      ?4.0)
	LSOF_VERS=40000
	;;
      *)
	echo "WARNING: unknown Digital UNIX version; assuming version is 2.0"
	LSOF_VERS=20000
	;;
      esac
    fi

    # Do Digital UNIX version specific stuff.

    case $LSOF_VERS in
      20000)
	LSOF_TMP1="/sys"
	;;
      30000)
	LSOF_TMP1="/sys"
	LSOF_TMP2=-DUSELOCALREADDIR
	;;
      30200)
	LSOF_TMP1="/sys"
	LSOF_TMP2=-DUSELOCALREADDIR
	;;
      40000)
	LSOF_TMP1="/usr/sys"
	;;
      *)
	echo "WARNING: unknown Digital UNIX version: $LSOF_VERS"
	rm -f $LSOF_HLP
	exit 1
	;;
    esac
    if test "X$DU_SYSDIR" = "X"
    then
      DU_SYSDIR=$LSOF_TMP1
    fi
    LSOF_HOST=`uname -n`
    if test "X$DU_CDIR" = "X"
    then
      LSOF_CDIR=`expr $LSOF_HOST : '\([^\.]*\)\..*$'`
      if test "X$LSOF_CDIR" = "X"
      then
	LSOF_CDIR=$LSOF_HOST
      fi
      LSOF_CDIR=`echo $LSOF_CDIR | tr a-z A-Z`
    else
      LSOF_CDIR=$DU_CDIR
    fi
    LSOF_LOOP=1
    while test $LSOF_LOOP = 1
    do
      if test -d ${DU_SYSDIR}/$LSOF_CDIR
      then
	echo "Using header files in ${DU_SYSDIR}/$LSOF_CDIR"
	LSOF_LOOP=0
      else
	cat << .CAT_MARK

Please enter the name of the subdirectory in $DU_SYSDIR that contains the
configuration files for this host.  Usually its name would be $LSOF_CDIR, but
that subdirectory doesn't seem to exist.  The lsof compilation needs header
files specific to this machine's configuration found in that directory.

If you can't specify the appropriate configuration subdirectory, quit this
Configure step now and generate a proper configuration subdirectory with the
kernel generation process.

.CAT_MARK

	echo "$DU_SYSDIR contains:"
	echo ""
	ls -CF $DU_SYSDIR
	echo ""
	echo -n "Configuration subdirectory name? "
	read LSOF_CDIR LSOF_EXCESS
	if test "X$LSOF_CDIR" = "X" -o ! -d ${DU_SYSDIR}/$LSOF_CDIR
	then
	  echo ""
	  echo Cannot access directory ${DU_SYSDIR}/$LSOF_CDIR.
	fi
      fi
    done

    # Determine the ADVFS file system version.

    if test "X$DU_ADVFSV" = "X"
    then
      echo "Determining the ADVFS version -- this will take a while."
      LSOF_ADVFSV=`/usr/sbin/setld -i | grep "^OSFADVFSBIN[0-9]" | 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."
	;;
      4*)
	LSOF_ADVFSV=400
	echo "The ADVFS version is 4."
	;;
      *)
	echo "The ADVFS version is unknown; it will be assumed to be 1."
	LSOF_ADVFSV=100
	;;
      esac
    else
      LSOF_ADVFSV=$DU_ADVFSV
    fi
    LSOF_CFGF="-DDUV=$LSOF_VERS -DADVFSV=$LSOF_ADVFSV $LSOF_TMP2"
    if test "X$DU_SYSINC" = "X"
    then
      DU_SYSINC="/usr/sys/include"
    fi
    LSOF_DINC="$LSOF_DINC -I${DU_SYSDIR}/$LSOF_CDIR -I$DU_SYSINC"
    LSOF_CFGL="-lmld"
    if test "X${DU_SHLIB}" = "X"
    then
      DU_SHLIB=/usr/shlib
    fi
    if test -r ${DU_SHLIB}/libmsfs.so
    then
      nm ${DU_SHLIB}/libmsfs.so | grep tag_to_path > /dev/null 2>&1
      if test $? -eq 0
      then
	LSOF_CFGF="$LSOF_CFGF -DHASTAGTOPATH"
	LSOF_CFGL="$LSOF_CFGL -lmsfs"
      fi
    fi
    LSOF_DIALECT_DIR=du
    ;;

# Configure for FreeBSD.

  freebsd)
    LSOF_CC="gcc"
    if test "X$LSOF_VERS" = "X"
    then

      # If the FreeBSD version isn't pre-defined, determine it.

      case "`uname -r`" in
      1.*)
	LSOF_VERS=100
	;;
      2.0-*)
	LSOF_VERS=200
	;;
      2.0.5-*)
	LSOF_VERS=205
	;;
      2.1*)
	LSOF_VERS=210
	;;
      2.2*)
	LSOF_VERS=220
	;;
      3.0*)
	LSOF_VERS=300
	;;
      *)
	echo Unknown FreeBSD release: `uname -r`
	echo Assuming FreeBSD 2.x
	LSOF_CFGL="-lkvm"
	LSOF_VERS=200
	LSOF_N_UNIXV=`/usr/sbin/sysctl -n kern.bootfile`
	if test "X$LSOF_N_UNIXV" = "X"
	then
	  LSOF_N_UNIXV="/kernel"
	fi
	;;
      esac
    fi

    # Do FreeBSD version-specific stuff.

    case $LSOF_VERS in
    100)
      LSOF_CFGF="-DHASPROCFS=proc"
      LSOF_CFGL="-lutil"
      LSOF_DINC="$LSOF_DINC -I`pwd`/dialects/freebsd/include"
      if test "X$FREEBSD_KERNEL" = "X"
      then
	LSOF_N_UNIXV="/386bsd"
      else
	LSOF_N_UNIXV=$FREEBSD_KERNEL
      fi
      ;;
    200|205|210)
      LSOF_CFGL="-lkvm"
      ;;
    220)
      LSOF_CFGL="-lkvm"
      if test -r ${LSOF_INCLUDE}/vm/lock.h
      then
	LSOF_CFGF="-DHASVMLOCKH"
      fi
      ;;
    300)
      LSOF_CFGL="-lkvm"
      if test -r ${LSOF_INCLUDE}/nfs/rpcv2.h
      then
	LSOF_CFGF="-DHASRPCV2H"
      fi
      if test -r ${LSOF_INCLUDE}/vm/lock.h
      then
	LSOF_CFGF="$LSOF_CFGF -DHASVMLOCKH"
      fi
      ;;
    *)
      echo "Illegal FreeBSD version: $LSOF_VERS"
      rm -f $LSOF_HLP
      exit 1
      ;;
    esac
    LSOF_CFGF="-DFREEBSDV=$LSOF_VERS $LSOF_CFGF"
    if test $LSOF_VERS -lt 200 -a "X$FREEBSD_KERNEL" = "X"
    then
      if test ! -x $LSOF_N_UNIXV
      then
	echo "Hmmm -- $LSOF_N_UNIXV 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_UNIXV LSOF_EXCESS
	  LSOF_N_UNIXV="/$LSOF_N_UNIXV"
	  if test ! -d $LSOF_N_UNIXV -a -x $LSOF_N_UNIXV
	  then
	    LSOF_LOOP=0
	  else
	    echo ""
	    echo $LSOF_N_UNIXV is not a regular executable file.
	  fi
	done
      fi
      LSOF_N_UNIXV=`echo $LSOF_N_UNIXV | sed 's#^/*#/#'`
      LSOF_CFGF="$LSOF_CFGF -DN_UNIXV=$LSOF_N_UNIXV"
    fi
    LSOF_TMP1=0
    if test "X$FREEBSD_SYS" = "X"
    then
      FREEBSD_SYS="/sys"
    fi
    if test -d ${FREEBSD_SYS}/miscfs/fdesc
    then
      LSOF_CFGF="$LSOF_CFGF -DHASFDESCFS"
      LSOF_TMP1=1
    fi
    if test -d ${FREEBSD_SYS}/miscfs/procfs
    then
      LSOF_CFGF="$LSOF_CFGF -DHASPROCFS=proc"
      LSOF_TMP1=1
    fi
    if test -r ${FREEBSD_SYS}/isofs/cd9660/cd9660_node.h
    then
      rm -f cd9660_node.h
      sed -e '/^ \* Prototypes for ISOFS vnode operations/,$c\
      \ The ISOFS prototypes were removed by Configure. */' \
      < ${FREEBSD_SYS}/isofs/cd9660/cd9660_node.h > cd9660_node.h
      echo "" >> cd9660_node.h
      LSOF_CFGF="$LSOF_CFGF -DHAS9660FS"
    fi
    grep -q nc_vpid ${LSOF_INCLUDE}/sys/namei.h
    if test $? -eq 0
    then
      LSOF_CFGF="$LSOF_CFGF -DHASNCVPID"
    fi
    if test $LSOF_TMP1 -eq 1
    then
      LSOF_DINC="$LSOF_DINC -I$FREEBSD_SYS"
    fi
    LSOF_DIALECT_DIR=freebsd
    ;;

# Configure for HP-UX and HP-UX gcc.

  hpux|hpuxgcc)
    LSOF_RANLIB=""
    if test "X$LSOF_VERS" = "X"
    then

      # If the HP-UX version isn't pre-defined, determine it.

      LSOF_VERS=`uname -r | awk -F. '{printf "%d%02d",\$2,\$3}'`
    fi
    if test "X$LSOF_TGT" = "Xhpuxgcc"
    then
      LSOF_CC=gcc
      LSOF_CFGF="-DHAS_CONST"
      LSOF_DEBUG="-O"
      LSOF_TGT="hpux"
    else
      if test "X$HPUX_CCDIR1" = "X"
      then
	HPUX_CCDIR1="/bin"
      fi
      if test "X$HPUX_CCDIR2" = "X"
      then
	HPUX_CCDIR2="/usr/ccs/bin"
      fi
      if test -x ${HPUX_CCDIR1}/cc
      then
	LSOF_CC=${HPUX_CCDIR1}/cc
      else
	if test -x ${HPUX_CCDIR2}/cc
	then
	  LSOF_CC=${HPUX_CCDIR2}/cc
	else
	  echo "No executable cc in $HPUX_CCDIR1 or $HPUX_CCDIR2"
	  rm -f $LSOF_HLP
	  exit 1
	fi
      fi
      what $LSOF_CC | grep -q Bundled
      if test $? -eq 0
      then
	if test "X$HPUX_LIBC1" = "X"
	then
	  HPUX_LIBC1="/usr/lib"
	fi
	if test -r ${HPUX_LIBC1}/libc.sl
	then
	  LSOF_FCFGL="-L$HPUX_LIBC -lc"
	else
	  if test "X$HPUX_LIBC2" = "X"
	  then
	    HPUX_LIBC2="/usr/lib"
	  fi
	  if test -r ${HPUX_LIBC2}/libc.sl
	  then
	    LSOF_FCFGL="-L$HPUX_LIBC2 -lc"
	  fi
	fi
      else
	LSOF_DEBUG="-O"
      fi
    fi
    LSOF_CFGF="$LSOF_CFGF -DHPUXV=$LSOF_VERS"
    if test $LSOF_VERS -lt 1000
    then
      if test "X$HPUX_X25DIR" = "X"
      then
	HPUX_X25DIR="/etc/conf"
      else
	HPUX_X25DIR=$HPUX_X25DIR
      fi
      if test -r ${HPUX_X25DIR}/x25/x25addrstr.h
      then
	LSOF_CFGF="$LSOF_CFGF -DHPUX_CCITT"
	LSOF_DINC="$LSOF_DINC -I$HPUX_X25DIR"
      fi
    fi
    if test -r ${LSOF_INCLUDE}/sys/fs/vx_inode.h -a -r ${LSOF_INCLUDE}/sys/fs/vx_hpux.h
    then
      LSOF_CFGF="$LSOF_CFGF -DHASVXFS"
    fi

    # Test for AFS.

    if test -r ${AFS_VICE}/etc/ThisCell
    then
      if test "X$LSOF_SCRIPT_CALL" = "Xno"
      then
	if test -r ./AFSHeaders -a -r ./AFSVersion
	then
	  LSOF_AFS="yes"
	fi
      else
	if test ! -x ./AFSConfig
	then
	  echo "Can't find or execute the AFSConfig script"
	  rm -f $LSOF_HLP
	  exit 1
	fi
	./AFSConfig
	if test $? -eq 0 -a -r ./AFSHeaders -a -r ./AFSVersion
	then
	    LSOF_AFS="yes"
	fi
      fi
      if test "X$LSOF_AFS" = "Xyes"
      then
	LSOF_AFSV=`cat ./AFSVersion | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1 \2/' | awk '{printf "%d%02d\n",\$1,\$2}'`
	LSOF_CFGF="$LSOF_CFGF -DHAS_AFS=$LSOF_AFSV"
	LSOF_DINC="$LSOF_DINC -I`cat ./AFSHeaders`"
      fi
    fi
    LSOF_CFGL=""
    LSOF_DIALECT_DIR=hpux
    ;;

# Configure for SGI IRIX.

  irix)
    LSOF_RANLIB=""
    if test ! -x dialects/irix/MkKernOpts
    then
      echo "Can't execute dialects/irix/MkKernOpts"
      rm -f $LSOF_HLP
      exit 1
    fi
    if test "X$LSOF_VERS" = "X"
    then

      # If the IRIX version isn't predefined, determine it.

      case "`uname -r`" in
      5.2*)
	LSOF_VERS="50200"
	;;
      5.3*)
	LSOF_VERS="50300"
	;;
      6.0)
	LSOF_VERS="60000"
	;;
      6.0.1)
	LSOF_VERS="60001"
	;;
      6.1*)
	LSOF_VERS="60100"
	;;
      6.2*)
	LSOF_VERS="60200"
	;;
      6.3*)
	LSOF_VERS="60300"
	;;
      6.4*)
	LSOF_VERS="60400"
	;;
      *)
	echo Unknown IRIX release: `uname -r`
	rm -f $LSOF_HLP
	exit 1
	;;
      esac
    fi

    # DO IRIX version-specific stuff.

    if test "X$IRIX_BITS" = "X"
    then
      IRIX_BITS=`uname -s`
    fi
    case $LSOF_VERS in
    50200)
      LSOF_CFGF="-DIRIXV=$LSOF_VERS"
      LSOF_CFGL="-lmld"
      LSOF_DINC="$LSOF_DINC -I`pwd`/dialects/irix/irix5hdr"
      ;;
    50300)
      LSOF_CFGF="-xansi -DIRIXV=$LSOF_VERS `dialects/irix/MkKernOpts $LSOF_VERS`"
      LSOF_CFGL="-lmld"
      LSOF_DINC="$LSOF_DINC -I`pwd`/dialects/irix/irix5hdr"
      if test "X$IRIX_53NFSROLLUP" = "X"
      then
	/usr/sbin/showprods | grep "NFS kernel rollup patch" > /dev/null
	if test $? -eq 0
	then
	  LSOF_CFGF="$LSOF_CFGF -DHAS53NFSROLLUP"
	fi
      else
	if test "X$IRIX_53NFSROLLUP" = "XY" -o "X$IRIX_53NFSROLLUP" = "Xy"
	then
	  LSOF_CFGF="$LSOF_CFGF -DHAS53NFSROLLUP"
	fi
      fi
      ;;
    60000)
      LSOF_CFGF="-DIRIXV=$LSOF_VERS -woff 1411,1174,1107"
      LSOF_CFGF="$LSOF_CFGF `dialects/irix/MkKernOpts $LSOF_VERS`"
      LSOF_CFGL="-lelf"
      LSOF_DINC="$LSOF_DINC -I`pwd`/dialects/irix/irix6hdr"
      ;;
    60001)
      LSOF_CFGF="-DIRIXV=$LSOF_VERS -woff 1411,1174,1107"
      LSOF_CFGF="$LSOF_CFGF `dialects/irix/MkKernOpts $LSOF_VERS`"
      LSOF_CFGL="-lelf"
      LSOF_DINC="$LSOF_DINC -I`pwd`/dialects/irix/irix6hdr"
      ;;
    60100)
      LSOF_CFGF="-DIRIXV=$LSOF_VERS"
      if test "X$IRIX_BITS" = "XIRIX64"
      then
	LSOF_CFGF="$LSOF_CFGF -mips3"
      fi
      LSOF_CFGF="$LSOF_CFGF `dialects/irix/MkKernOpts $LSOF_VERS`"
      LSOF_CFGL="-lelf"
      LSOF_DINC="$LSOF_DINC -I`pwd`/dialects/irix/irix61hdr -I${LSOF_INCLUDE}/sys/fs"
      ;;
    60200)
      LSOF_CFGF="-xansi -DIRIXV=$LSOF_VERS"
      if test "X$IRIX_BITS" = "XIRIX64"
      then
	LSOF_CFGF="$LSOF_CFGF -mips3"
      fi
      if test -r ${LSOF_INCLUDE}/cachefs/cachefs_fs.h
      then
	grep c_metadata ${LSOF_INCLUDE}/cachefs/cachefs_fs.h > /dev/null
	LSOF_CFGF="$LSOF_CFGF -DHASCACHEFS=$?"
      fi
      LSOF_CFGF="$LSOF_CFGF `dialects/irix/MkKernOpts $LSOF_VERS`"
      LSOF_CFGL="-lelf"
      if test "X$IRIX_XFSROLLUP" = "X"
      then
	/usr/sbin/showprods | grep "XFS rollup" > /dev/null
	if test $? -eq 0
	then
	  LSOF_CFGF="$LSOF_CFGF -DHASXFSROLLUP"
	fi
      else
	if test "X$IRIX_XFSROLLUP" = "XY" -o "X$IRIX_XFSROLLUP" = "Xy"
	then
	  LSOF_CFGF="$LSOF_CFGF -DHASXFSROLLUP"
	fi
      fi
      ;;
    60300)
      LSOF_CFGF="-xansi -DIRIXV=$LSOF_VERS"
      if test "X$IRIX_BITS" = "XIRIX64"
      then
	LSOF_CFGF="$LSOF_CFGF -mips3"
      fi
      if test -r ${LSOF_INCLUDE}/cachefs/cachefs_fs.h
      then
	LSOF_CFGF="$LSOF_CFGF -DHASCACHEFS"
      fi
      LSOF_CFGF="$LSOF_CFGF `dialects/irix/MkKernOpts $LSOF_VERS`"
      LSOF_CFGL="-lelf"
      ;;
    60400)
      LSOF_CFGF="-xansi -DIRIXV=$LSOF_VERS"
      if test "X$IRIX_BITS" = "XIRIX64"
      then
	LSOF_CFGF="$LSOF_CFGF -mips3"
      fi
      if test -r ${LSOF_INCLUDE}/cachefs/cachefs_fs.h
      then
	LSOF_CFGF="$LSOF_CFGF -DHASCACHEFS"
      fi
      LSOF_CFGF="$LSOF_CFGF `dialects/irix/MkKernOpts $LSOF_VERS`"
      LSOF_CFGL="-lelf"
      LSOF_DINC="$LSOF_DINC -I`pwd`/dialects/irix/irix64hdr"
      ;;
    *)
      echo "Illegal IRIX version: $LSOF_VERS"
      rm -f $LSOF_HLP
      exit 1
      ;;
    esac
    if test "X$IRIX_BITS" = "XIRIX64"
    then
      LSOF_CFGF="$LSOF_CFGF -64"
    else
      LSOF_CFGF="$LSOF_CFGF -DIRIX32BITS"
    fi
    if test "X$IRIX_HW" = "X"
    then
      if test -r /hw
      then
	LSOF_CFGF="$LSOF_CFGF -DUSE_STAT"
      fi
    else
      if test "X$IRIX_HW" = "XY" -o "X$IRIX_HW" = "Xy"
      then
	LSOF_CFGF="$LSOF_CFGF -DUSE_STAT"
      fi
    fi
    LSOF_DIALECT_DIR=irix
    ;;

# Configure for Linux.

  linux)
    LSOF_CC="gcc"
    if test "X$LSOF_VERS" = "X"
    then

      # If the Linux version isn't predefined, determine it.

      LSOF_VERS=`uname -r|sed 's/\./ /g'|awk '{printf "%d%d%02d",\$1,\$2,\$3}'`
    fi
    LSOF_CFGF="-DLINUXV=$LSOF_VERS"

    # If the Linux C library type isn't predefined, determine it.

    if test "X$LINUX_CLIB" = "X"
    then
      echo -n "Testing C library type with $LSOF_CC ... "
      rm -f ${LSOF_TMPC}.*
      echo "#include <features.h>" > $LSOF_TMPC.c
      echo "main(){" >> $LSOF_TMPC.c
      echo "#if defined(__GLIBC__)" >> $LSOF_TMPC.c
      echo "printf(\"-DGLIBCV=%d\\n\", __GLIBC__);" >> $LSOF_TMPC.c
      echo "#else" >> $LSOF_TMPC.c
      echo "printf(\"\\n\");" >> $LSOF_TMPC.c
      echo "#endif" >> $LSOF_TMPC.c
      echo "return(0); }" >> $LSOF_TMPC.c
      $LSOF_CC ${LSOF_TMPC}.c -I$LSOF_INCLUDE -o ${LSOF_TMPC}.x > /dev/null 2>&1
      if test -x ${LSOF_TMPC}.x
      then
        LINUX_CLIB=`${LSOF_TMPC}.x`
        LSOF_TMP=$?
      else
	LINUX_CLIB=""
        LSOF_TMP=1
      fi
      rm -f ${LSOF_TMPC}.*
      echo "done"
      if test $LSOF_TMP -ne 0
      then
	echo "Cannot determine C library type; assuming it is not glibc."
	LINUX_CLIB=""
      else
        if test "X$LINUX_CLIB" = "X"
        then
          echo "The C library type is not glibc."
        else
          echo "The C library type is glibc, version \"$LINUX_CLIB\"."
        fi
      fi
    fi
    if test "X$LINUX_CLIB" != "X"
    then
      LSOF_CFGF="$LSOF_CFGF $LINUX_CLIB"
    fi

    # If the Linux kernel directory isn't pre-defined, set its default.
    # If the Linux kernel include directory isn't pre-defined, set its default.

    if test "X$LINUX_KERNEL" = "X"
    then
      LINUX_KERNEL="/usr/src/linux"
    fi
    LSOF_LINUX_INCL=${LINUX_KERNEL}/include/linux
    if test -r ${LINUX_KERNEL}/net/inet/sock.h
    then
      LSOF_TMP1="net/inet/sock.h"
    else
      if test -r ${LINUX_KERNEL}/include/net/sock.h
      then
	LSOF_TMP1="include/net/sock.h"
	LSOF_DINC="$LSOF_DINC -I${LINUX_KERNEL}/include"
      else
	echo "WARNING: cannot find ${LINUX_KERNEL}/net/inet/sock.c or"
	echo "         ${LINUX_KERNEL}/include/net/sock.c.  Lsof may fail to"
	echo "         compile, or it it compiles, it may fail to identify"
	echo "         socket files correctly.  Does this machine have the"
	echo "         Linux kernel source and header files in ${LINUX_KERNEL}?"
	echo "         If it does not, you probably cannot build lsof."
	LSOF_TMP1=""
      fi
    fi
    if test "X$LSOF_TMP1" != "X"
    then
      grep protinfo ${LINUX_KERNEL}/$LSOF_TMP1 > /dev/null 2>&1
      if test $? -eq 0
      then
	grep unix_address ${LINUX_KERNEL}/$LSOF_TMP1 > /dev/null 2>&1
	if test $? -eq 0
	then
	  LSOF_CFGF="$LSOF_CFGF -DHASUNMINSOCK=1"
	else
	  LSOF_CFGF="$LSOF_CFGF -DHASUNMINSOCK=0"
	fi
      fi
    fi
    grep '*sk;' ${LSOF_LINUX_INCL}/net.h > /dev/null 2>&1
    if test $? -eq 0
    then
      LSOF_CFGF="$LSOF_CFGF -DHAS_SOCKET_SK"
    fi
    if test -r ${LSOF_LINUX_INCL}/netdevice.h
    then
      LSOF_CFGF="$LSOF_CFGF -DHASNETDEVICE_H"
    fi
    if test -r ${LSOF_LINUX_INCL}/autoconf.h
    then
      egrep "^#define[ 	]*CONFIG_KERNEL_ELF" ${LSOF_LINUX_INCL}/autoconf.h > /dev/null
      if test $? -eq 0
      then
	LSOF_CFGF="$LSOF_CFGF -DKERN_LD_ELF"
      fi
    fi
    if test -r ${LSOF_LINUX_INCL}/fs.h
    then
      grep fl_fd ${LSOF_LINUX_INCL}/fs.h > /dev/null
      if test $? -eq 0
      then
	LSOF_CFGF="$LSOF_CFGF -DHAS_FL_FD"
      fi
      grep fl_file ${LSOF_LINUX_INCL}/fs.h > /dev/null
      if test $? -eq 0
      then
	LSOF_CFGF="$LSOF_CFGF -DHAS_FL_FILE"
      fi
      grep fl_whence ${LSOF_LINUX_INCL}/fs.h > /dev/null
      if test $? -eq 0
      then
	LSOF_CFGF="$LSOF_CFGF -DHAS_FL_WHENCE"
      fi
    fi
    if test -r ${LINUX_KERNEL}/include/asm/atomic.h
    then
      grep "typedef struct .* atomic_t;" ${LINUX_KERNEL}/include/asm/atomic.h > /dev/null
      if test $? -eq 0
      then
	LSOF_CFGF="$LSOF_CFGF -DHAS_ATOMIC_T"
      fi
    fi
    if test -r ${LINUX_KERNEL}/include/asm/unistd.h
    then
      grep __NR_query_module ${LINUX_KERNEL}/include/asm/unistd.h > /dev/null
      if test $? -eq 0
      then
	LSOF_CFGF="$LSOF_CFGF -DHAS_QUERY_MODULE"
      fi
    fi
    if test $LSOF_VERS -ge 2100
    then
      if test "X$LINUX_LSEEK" = "X"
      then
	echo "Testing lseek() with $LSOF_CC"
	rm -f ${LSOF_TMPC}.*
	echo '#include <stdio.h>' > ${LSOF_TMPC}.c
	echo '#include <fcntl.h>' >> ${LSOF_TMPC}.c
	echo '#include <unistd.h>' >> ${LSOF_TMPC}.c
	echo 'main() { int f;' >> ${LSOF_TMPC}.c
	echo 'if((f=open("/dev/kmem",O_RDONLY,0600))<0)exit(1);' >> ${LSOF_TMPC}.c
	echo 'if(lseek(f,(off_t)-4097,SEEK_CUR)==-1)exit(2);' >> ${LSOF_TMPC}.c
	echo 'exit(0);}' >> ${LSOF_TMPC}.c
	$LSOF_CC ${LSOF_TMPC}.c -I$LSOF_INCLUDE -o ${LSOF_TMPC}.x
	${LSOF_TMPC}.x
	LSOF_TMP=$?
	case $LSOF_TMP in
	0)
	  echo "Lseek() is OK."
	  ;;
	1)
	  echo "Configure for Linux 2.1.x needs read permission to /dev/kmem"
	  echo "in order to test lseek() on it."
	  rm -f ${LSOF_TMPC}.* $LSOF_HLP
	  exit 1
	  ;;
	2)
	  echo "Lseek() is suspect; using private __lseek.s."
	  LSOF_SPMKF="Makefile.lseek"
	  ;;
	*)
	  echo "Unexpected return of $LSOF_TMP from lseek() test program, ${LSOF_TMPC}.c"
	  rm -f $LSOF_HLP
	  exit 1
	  ;;
	esac
	rm -f ${LSOF_TMPC}.*
      else
	if test "X$LINUX_LSEEK" = "XY" -o "X$LINUX_LSEEK" = "Xy"
	then
	  LSOF_SPMKF="Makefile.lseek"
	fi
      fi
    fi
    grep pidhash_next ${LSOF_LINUX_INCL}/sched.h > /dev/null
    if test $? -eq 0
    then
      LSOF_CFGF="$LSOF_CFGF -DHASHASHPID"
    fi
    if test -r ${LSOF_LINUX_INCL}/dcache.h
    then
      grep "^struct dentry {" ${LSOF_LINUX_INCL}/dcache.h > /dev/null
      if test $? -eq 0
      then
	LSOF_CFGF="$LSOF_CFGF -DHASDENTRY"
      fi
    fi
    grep __kernel_key_t ${LSOF_INCLUDE}/linux/types.h > /dev/null
    if test $? -eq 0
    then
      LSOF_CFGF="$LSOF_CFGF -DHASKERNELKEYT"
    fi
    LSOF_DIALECT_DIR=linux
    ;;

# Configure for NetBSD.

  netbsd)
    LSOF_CC="gcc"
    if test "X$LSOF_VERS" = "X"
    then
      
      # If the NetBSD version isn't pre-defined, determine it.

      case "`uname -r`" in
      1.0*)
	LSOF_VERS="1000"
	;;
      1.1*)
	LSOF_VERS="1010"
	;;
      1.2*)
	LSOF_VERS="1020"
	;;
      1.3*)
	LSOF_VERS="1030"
	;;
      *)
	echo Unknown NetBSD release: `uname -r`
	echo Assuming NetBSD 1.0
	LSOF_VERS="1000"
	;;
      esac
    fi

    # Test for legal NetBSD version.

    case $LSOF_VERS in
    1000|1010|1020|1030)
      ;;
    *)
      echo "Illegal NetBSD version: $LSOF_VERS"
      rm -f $LSOF_HLP
      exit 1
      ;;
    esac
    LSOF_CFGF="-DNETBSDV=$LSOF_VERS"
    if test -r ${LSOF_INCLUDE}/nfs/nfsproto.h
    then
	LSOF_CFGF="$LSOF_CFGF -DHASNFSPROTO"
    fi
    LSOF_TMP1=0
    if test "X$NETBSD_SYS" = "X"
    then
      NETBSD_SYS="/sys"
    fi
    if test -d ${NETBSD_SYS}/miscfs/fdesc
    then
      LSOF_CFGF="$LSOF_CFGF -DHASFDESCFS"
      LSOF_TMP1=1
    fi
    if test -d ${NETBSD_SYS}/miscfs/procfs
    then
      LSOF_CFGF="$LSOF_CFGF -DHASPROCFS=proc"
      LSOF_TMP1=1
    fi
    if test -d ${NETBSD_SYS}/isofs/cd9660
    then
      LSOF_CFGF="$LSOF_CFGF -DHAS9660FS"
      LSOF_TMP1=1
    fi
    if test -r ${NETBSD_SYS}/miscfs/kernfs/kernfs.h
    then
      grep -q "kt_name;" ${NETBSD_SYS}/miscfs/kernfs/kernfs.h
      if test $? -eq 0
	then
 	  LSOF_CFGF="$LSOF_CFGF -DHASKERNFS"
	  LSOF_TMP1=1
      fi
    fi
    if test $LSOF_TMP1 -eq 1
    then
      LSOF_DINC="-I$LSOF_INCLUDE -I$NETBSD_SYS"
    fi
    grep -q nc_vpid ${LSOF_INCLUDE}/sys/namei.h
    if test $? -eq 0
    then
      LSOF_CFGF="$LSOF_CFGF -DHASNCVPID"
    fi
    grep -q i_ffs_size ${LSOF_INCLUDE}/ufs/ufs/inode.h
    if test $? -eq 0
    then
      LSOF_CFGF="$LSOF_CFGF -DHASI_FFS"
    fi
    grep -q VT_EXT2FS ${LSOF_INCLUDE}/sys/vnode.h
    if test $? -eq 0
    then
      LSOF_CFGF="$LSOF_CFGF -DHASEXT2FS"
      grep -q i_e2fs_size ${LSOF_INCLUDE}/ufs/ufs/inode.h
      if test $? -eq 0
      then
	LSOF_CFGF="$LSOF_CFGF -DHASI_E2FS"
      fi
    fi
    LSOF_CFGF="$LSOF_CFGF -DN_UNIXV=/netbsd"
    LSOF_CFGL="-lkvm"
    LSOF_DIALECT_DIR=n+obsd
    ;;

# Configure for NeXTSTEP.

  nextstep|next|ns|nxt)
    if test "X$LSOF_VERS" = "X"
    then

      # If the NeXSTEP version isn't predefined, determine it.

      LSOF_VERS=`hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\)\.\([0-9]*\).*/\1\2/p'`
    fi
    LSOF_CCV=`cc -v 2>&1 | sed -n 's/.*version \(.*\)/\1/p'`
    LSOF_CFGF="-DNEXTSTEPV=$LSOF_VERS"
    LSOF_CFGL=""
    LSOF_DIALECT_DIR=ns

    # Test for AFS.

    if test -r ${AFS_VICE}/etc/ThisCell
    then
      if test "X$LSOF_SCRIPT_CALL" = "Xno"
      then
	if test -r ./AFSHeaders -a -r ./AFSVersion
	then
	  LSOF_AFS="yes"
	fi
      else
	if test ! -x ./AFSConfig
	then
	  echo "Can't find or execute the AFSConfig script"
	  rm -f $LSOF_HLP
	  exit 1
	fi
	./AFSConfig
	if test $? -eq 0 -a -r ./AFSHeaders -a -r ./AFSVersion
	then
	    LSOF_AFS="yes"
	fi
      fi
      if test "X$LSOF_AFS" = "Xyes"
      then
	LSOF_AFSV=`cat ./AFSVersion | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1 \2/' | awk '{printf "%d%02d\n",\$1,\$2}'`
	LSOF_CFGF="$LSOF_CFGF -DHAS_AFS=$LSOF_AFSV"
	LSOF_DINC="$LSOF_DINC -I`cat ./AFSHeaders`"
      fi
    fi
    ;;

# Configure for OpenBSD.  (OpenBSD uses NetBSD dialect sources and version
# numbering.

  openbsd)
    LSOF_CC="gcc"
    if test "X$LSOF_VERS" = "X"
    then

      # If the OpenBSD version isn't pre-defined, determine it.

      case "`uname -r`" in
      1.2*)
	LSOF_VERS=1020
	;;
      2.0*)
	LSOF_VERS=2000
	;;
      2.1*)
	LSOF_VERS=2010
	;;
      2.2*)
	LSOF_VERS=2020
	;;
      *)
	echo Unknown OpenBSD release: `uname -r`
	echo Assuming OpenBSD 1.2
	LSOF_VERS=1020
	;;
      esac
    fi

    # Test for legal OpenBSD version.

    case $LSOF_VERS in
    1020|2000|2010|2020)
      ;;
    *)
      echo "Illegal OpenBSD version: $LSOF_VERS"
      rm -f $LSOF_HLP
      exit 1
      ;;
    esac
    LSOF_CFGF="-DOPENBSDV=$LSOF_VERS -DN_UNIXV=/bsd"
    if test -r ${LSOF_INCLUDE}/nfs/nfsproto.h
    then
      LSOF_CFGF="$LSOF_CFGF -DHASNFSPROTO"
    fi
    LSOF_TMP1=0
    if test "X$OPENBSD_SYS" = "X"
    then
      OPENBSD_SYS="/sys"
    fi
    if test -d ${OPENBSD_SYS}/miscfs/fdesc
    then
      LSOF_CFGF="$LSOF_CFGF -DHASFDESCFS"
      LSOF_TMP1=1
    fi
    if test -d ${OPENBSD_SYS}/miscfs/procfs
    then
      LSOF_CFGF="$LSOF_CFGF -DHASPROCFS=proc"
      LSOF_TMP1=1
    fi
    if test -d ${OPENBSD_SYS}/isofs/cd9660
    then
      LSOF_CFGF="$LSOF_CFGF -DHAS9660FS"
      LSOF_TMP1=1
    fi
    if test -r ${OPENBSD_SYS}/miscfs/kernfs/kernfs.h
    then
      grep -q "kt_name;" ${OPENBSD_SYS}/miscfs/kernfs/kernfs.h
      if test $? -eq 0
	then
 	  LSOF_CFGF="$LSOF_CFGF -DHASKERNFS"
	  LSOF_TMP1=1
      fi
    fi
    if test $LSOF_TMP1 -eq 1
    then
      LSOF_DINC="-I$LSOF_INCLUDE -I$OPENBSD_SYS"
    fi
    grep -q VT_EXT2FS ${LSOF_INCLUDE}/sys/vnode.h
    if test $? -eq 0
    then
      LSOF_CFGF="$LSOF_CFGF -DHASEXT2FS"
    fi
    grep -q nc_vpid ${LSOF_INCLUDE}/sys/namei.h
    if test $? -eq 0
    then
      LSOF_CFGF="$LSOF_CFGF -DHASNCVPID"
    fi
    LSOF_CFGL="-lkvm"
    LSOF_DIALECT_DIR=n+obsd
    ;;

# Configure for Pyramid DC/OSx and Reliant UNIX.

  pyramid|pyr)
    LSOF_CC=/usr/ccs/bin/cc
    LSOF_RANLIB=""
    if /bin/test ! -x dialects/pyramid/MkKernOpts
    then
      /bin/echo "Can't execute dialects/pyramid/MkKernOpts"
      rm -f $LSOF_HLP
      exit 1
    fi
    LSOF_CFGF="`dialects/pyramid/MkKernOpts`"
    if /bin/test -r ${LSOF_INCLUDE}/sys/fs/vx_fs.h -a -r ${LSOF_INCLUDE}/sys/fs/vx_inode.h
    then
      LSOF_CFGF="$LSOF_CFGF -DHASVXFS"
    fi
    if /bin/test -r ${LSOF_INCLUDE}/sys/fs/tfs.h
    then
      LSOF_CFGF="$LSOF_CFGF -DHASTFS"
    fi
    if /bin/test -r ${LSOF_INCLUDE}/fs/objfs/obj_fs.h
    then
      LSOF_CFGF="$LSOF_CFGF -DHASOBJFS"
    fi
    if /bin/test -r ${LSOF_INCLUDE}/sys/dnlc.h
    then
      /bin/grep "name;" ${LSOF_INCLUDE}/sys/dnlc.h > /dev/null
      if /bin/test $? -eq 0
      then
	LSOF_CFGF="$LSOF_CFGF -DHASDNLCPTR"
      fi
    fi
    LSOF_CFGF="$LSOF_CFGF -Xa"
    LSOF_CFGL="-lsocket -lnsl -lelf"
    LSOF_CCV="`$LSOF_CC -V 2>&1`"
    LSOF_DIALECT_DIR=pyramid
  ;;

# Configure for Sequent PTX.

  ptx)
    LSOF_RANLIB=""
    if test "X$LSOF_VERS" = "X"
    then

      # If the PTX version isn't predefined, determine it.

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

    # PTX 4.x tests

      if test "X$PTX_CONF" = "X"
      then
	PTX_CONF="/usr/conf/uts"
      fi
      if test $LSOF_VERS -lt 410
      then
	LSOF_CFGL="-lrpc -lelf -linet -lnsl -lseq"
      else
	LSOF_CFGL="-lrpc -lelf -lnsl -lseq -lsocket"
      fi
      if test -r ${PTX_CONF}/nfs/rnode.h
      then
	LSOF_CFGF="-DHAS_NFS"
      fi
    else

    # PTX 2.x tests

      if test -r ${LSOF_INCLUDE}/nfs/rnode.h
      then
	LSOF_CFGF="-DHAS_NFS"
      fi
      LSOF_CFGL="-lrpc -linet -lnsl -lseq"
    fi
    LSOF_CFGF="-DPTXV=$LSOF_VERS $LSOF_CFGF"
    if test -r ${LSOF_INCLUDE}/sys/cdfsinode.h
    then
	LSOF_CFGF="$LSOF_CFGF -DHAS_CDFS"
    fi
    if test -r ${LSOF_INCLUDE}/netinet/in_pcb.h
    then
      grep "inp_laddr;" ${LSOF_INCLUDE}/netinet/in_pcb.h | grep struct > /dev/null
      if test $? -eq 0
      then
	LSOF_CFGF="$LSOF_CFGF -DHASINADDRSTR"
      fi
    fi
    if test -r ${LSOF_INCLUDE}/sys/vx_inode.h
    then
      LSOF_CFGF="$LSOF_CFGF -DHASVXFS"
      if test -r ${LSOF_INCLUDE}/sys/vx_dnlc.h
      then
	LSOF_CFGF="$LSOF_CFGF -DHASVXFSDNLC"
      fi
    fi
    LSOF_DIALECT_DIR=ptx
    ;;

# Configure for MIPS RISCos.

  riscos)
    if test "X$LSOF_VERS" = "X"
    then

      # If the RISCos version isn't pre-defined, determine it.

      case "`uname -r`" in
      4_52)
	LSOF_VERS=452
	;;
      *)
	echo Unknown RISCos version: `uname -r`
	echo Assuming version is 4_52.
	LSOF_VERS=452
	;;
      esac
    fi

    # Test for a legal RISCos version.

    case $LSOF_VERS in
    452)
      ;;
    *)
      echo "Illegal RISCos version: $LSOF_VERS"
      rm -f $LSOF_HLP
      exit 1
      ;;
    esac
    LSOF_CFGF="-DRISCOSV=$LSOF_VERS"
    LSOF_CFGL="-lmld -lsun"
    LSOF_DIALECT_DIR=riscos
    ;;

# Configure for SCO OpenServer.

  osr|sco)
    LSOF_RANLIB=""
    if test "X$LSOF_VERS" = "X"
    then

      # If the SCO OpenServer release version isn't predefined, determine it.

      LSOF_TMP1="`LANG=C_C.C uname -X 2>/dev/null | grep Release | sed 's/Release = \(.*\)/\1/'`"
      case $LSOF_TMP1 in
      3.2v2.0)
	LSOF_VERS="20"
	;;
      3.2v2.1)
	LSOF_VERS="21"
	;;
      3.2v4.0)
	LSOF_VERS="40"
	;;
      3.2v4.1)
	LSOF_VERS="41"
	;;
      3.2v4.2)
	LSOF_VERS="42"
	;;
      3.2v5.0.*)
	LSOF_VERS="`echo $LSOF_TMP1 | sed 's/3\.2v//; s/\.//g'`"
	;;
      *)
	echo Unknown SCO OpenServer release: `uname -X | grep Release`
	echo Assuming 3.2.0 or 3.2.1
	LSOF_VERS="0"
	;;
      esac
    fi

    # Do SCO OpenServer specific stuff.

    case $LSOF_VERS in
    0)
      LSOF_CFGF="-nointl"
      LSOF_CFGL="-lrpc -lsocket -lc_s"
      LSOF_DEBUG="-Ox"
      LSOF_MKC="cp"
      ;;
    20)
      LSOF_CFGL="-lrpc -lsocket -lc_s"
      LSOF_DEBUG="-Ox"
      LSOF_MKC="cp"
      ;;
    21)
      LSOF_CFGF="-nointl"
      LSOF_CFGL="-lrpc -lsocket -lc_s"
      LSOF_DEBUG="-Ox"
      LSOF_MKC="cp"
      ;;
    40)
      LSOF_CFGF="-nointl"
      LSOF_CFGL="-lrpc -lsocket -lc_s"
      LSOF_DEBUG="-Ox"
      ;;
    41)
      LSOF_CFGF="-nointl"
      LSOF_CFGL="-lrpc -lsocket -lc_s"
      LSOF_DEBUG="-Ox"
      ;;
    42)
      LSOF_CFGF="-nointl"
      LSOF_CFGL="-lrpc -lsocket -lc_s"
      LSOF_DEBUG="-Ox"
      ;;
    5*)
      LSOF_CFGF="-belf"
      LSOF_CFGL="-lsocket"
      LSOF_DEBUG="-O3 -Kspace"
      ;;
    *)
      echo "Illegal SCO OpenServer release: $LSOF_VERS"
      rm -f $LSOF_HLP
      exit 1
      ;;
    esac
    LSOF_CFGF="-DOSRV=$LSOF_VERS $LSOF_CFGF"
    if test "X$OSR_STATLSTAT" = "X"
    then
      echo "Testing libc.a for statlstat"
      /bin/nm /lib/libc.a | grep statlstat > /dev/null 2>&1
      if test $? -eq 0
      then
	LSOF_CFGF="$LSOF_CFGF -DHAS_STATLSTAT"
      fi
    else
      if test "X$OSR_STATLSTAT" = "XY" -o "X$OSR_STATLSTAT" = "Xy"
      then
	LSOF_CFGF="$LSOF_CFGF -DHAS_STATLSTAT"
      fi
    fi
    if test -r ${LSOF_INCLUDE}/sys/fs/nfs/rnode.h
    then
      LSOF_CFGF="$LSOF_CFGF -DHAS_NFS"
    fi
    if test ! -r ${LSOF_INCLUDE}/netdb.h
    then
      LSOF_DINC="$LSOF_DINC -I`pwd`/dialects/osr/include"
    fi
    LSOF_DIALECT_DIR=osr
    ;;

# Configure for Sun Solaris, SunPro C and gcc.

  solaris|solariscc)
    if test "X$LSOF_TGT" = "Xsolariscc"
    then
      if test "X$SOLARIS_CCDIR" = "X"
      then
	SOLARIS_CCDIR="/opt/SUNWspro"
      fi
      if test -x ${SOLARIS_CCDIR}/bin/cc
      then
	LSOF_CC=${SOLARIS_CCDIR}/bin/cc
      else
	echo "WARNING: can't find cc in ${LSOF_CCDIR}/bin"
	LSOF_CC=cc
      fi
      LSOF_TGT="solaris"
      LSOF_CCV=`$LSOF_CC -V 2>&1 | sed -n 's/^cc: \(.*\)/\1/p'`
    else
      LSOF_CC=gcc
    fi
    if test "X$LSOF_VERS" = "X"
    then

      # If the Solaris version isn't predefined, determine it.

      case "`uname -r`" in
      5.[0-2])
	LSOF_VERS="20300"
	;;
      5.3)
	LSOF_VERS="20300"
	;;
      5.4)
	LSOF_VERS="20400"
	;;
      5.5)
	LSOF_VERS="20500"
	;;
      5.5.1)
	LSOF_VERS="20501"
	;;
      5.6*)
	LSOF_VERS="20600"
	;;
      *)
	echo Unknown Solaris version: `uname -r`
	rm -f $LSOF_HLP
	exit 1
      esac
    fi

    # Do Solaris version-specific stuff.

    case $LSOF_VERS in
    20300)
      LSOF_RANLIB=""

      # Solaris patch 101318-32 creates a longer kernel tcp_s structure,
      # and 101318-45 changes the way the vnode's v_filocks member is
      # handled.  The following code creates a symbol definition for
      # patch 101318 whose value is the patch level.  No symbol is defined
      # if the patch level is not greater than zero.

      if test "X$SOLARIS_23P101318" = "X"
      then
	LSOF_PL=`grep -h SUNW_PATCHID=101318 /var/sadm/pkg/SUNWcar*/pkginfo | sed 's/.*-//' | sort -u | tail -1`
	if test "X$LSOF_PL" = "X"
	then
	  LSOF_PL=0
	fi
      else
	LSOF_PL=$SOLARIS_23P101318
      fi
      if test $LSOF_PL -gt 0
      then
	LSOF_CFGF="-DP101318=$LSOF_PL"
      fi
      ;;
    20400)
      LSOF_RANLIB=""
      if test "X$SOLARIS_24P101945" = "X"
      then
	LSOF_PL=`grep -h SUNW_PATCHID=101945 /var/sadm/pkg/SUNWcar*/pkginfo | sed 's/.*-//' | sort -u | tail -1`
	if test "X$LSOF_PL" = "X"
	then
	  LSOF_PL=0
	fi
      else
	LSOF_PL=$SOLARIS_24P101945
      fi
      if test $LSOF_PL -ge 32
      then
	if test "X$SOLARIS_24P102303" = "X"
	then
	  LSOF_PL=`grep -h SUNW_PATCHID=102303 /var/sadm/pkg/SUNWhea*/pkginfo | sed 's/.*-//' | sort -u | tail -1`
	  if test "X$LSOF_PL" = "X"
	  then
	    LSOF_PL=0
	  fi
	else
	  LSOF_PL=$SOLARIS_24P102303
	fi
	if test $LSOF_PL -ge 2
	then
	  echo "WARNING: your Solaris 2.4 system appears to have patches 101945-32 and 102303-2"
	  echo "         installed.  This probably means the NUM_*_VECTORS definitions in"
	  echo "         <sys/auxv.h> don't match the ones used to build your kernel.  Consult"
	  echo "         the Sun Problems section of the 00FAQ file of the lsof distribution"
	  echo "         for an explanation of the work-around being supplied by including"
	  echo "         the header file ./dialects/sun/include/sys/auxv.h."
	  LSOF_DINC="$LSOF_DINC -I`pwd`/dialects/sun/include"
	fi
      fi
      ;;
    20500|20501)
      ;;
    20600)
      if test "X$SOLARIS_26PR_GWINDOWS" = "X"
      then
	rm -f ${LSOF_TMPC}.*
	echo "#define _KMEMUSER" > ${LSOF_TMPC}.c
	echo "#include <sys/proc/prdata.h>" >> ${LSOF_TMPC}.c
	echo "main(){" >> ${LSOF_TMPC}.c
	echo "enum prnodetype p=PR_GWINDOWS;}" >> ${LSOF_TMPC}.c
	echo "Testing prdata.h for PR_GWINDOWS, using $LSOF_CC"
	if test "X$LSOF_CC" = "Xgcc"
	then
	  $LSOF_CC ${LSOF_TMPC}.c -o ${LSOF_TMPC}.x  > /dev/null 2>&1
	else
	  $LSOF_CC ${LSOF_TMPC}.c -I$LSOF_INCLUDE -o ${LSOF_TMPC}.x  > /dev/null 2>&1
	fi
	if test $? -eq 0
	then
	  LSOF_CFGF="$LSOF_CFGF -DHASPR_GWINDOWS"
	fi
      else
	if test "X$SOLARIS_26PR_GWINDOWS" = "XY" -o "X$SOLARIS_26PR_GWINDOWS" = "Xy"
	then
	  LSOF_CFGF="$LSOF_CFGF -DHASPR_GWINDOWS"
	fi
      fi
      if test "X$SOLARIS_26PR_LDT" = "X"
      then
	rm -f ${LSOF_TMPC}.*
	echo "#define _KMEMUSER" > ${LSOF_TMPC}.c
	echo "#include <sys/proc/prdata.h>" >> ${LSOF_TMPC}.c
	echo "main(){" >> ${LSOF_TMPC}.c
	echo "enum prnodetype p=PR_LDT;}" >> ${LSOF_TMPC}.c
	echo "Testing prdata.h for PR_LDT, using $LSOF_CC"
	if test "X$LSOF_CC" = "Xgcc"
	then
	  $LSOF_CC ${LSOF_TMPC}.c -o ${LSOF_TMPC}.x > /dev/null 2>&1
	else
	  $LSOF_CC ${LSOF_TMPC}.c -I$LSOF_INCLUDE -o ${LSOF_TMPC}.x > /dev/null 2>&1
	fi
	if test $? -eq 0
	then
	  LSOF_CFGF="$LSOF_CFGF -DHASPR_LDT"
	fi
	rm -f ${LSOF_TMPC}.*
      else
	if test "X$SOLARIS_26PR_LDT" = "XY" -o "X$SOLARIS_26PR_LDT" = "Xy"
	then
	  LSOF_CFGF="$LSOF_CFGF -DHASPR_LDT"
	fi
      fi
      ;;
    *)
      echo "Illegal Solaris version: $LSOF_VERS"
      rm -f $LSOF_HLP
      exit 1
      ;;
    esac
    LSOF_CFGF="-Dsolaris=$LSOF_VERS $LSOF_CFGF"

    # Test for VSOCK.

    if test "X$SOLARIS_VSOCK" = "X"
    then
      rm -f ${LSOF_TMPC}.*
      echo "#include <sys/vnode.h>" > ${LSOF_TMPC}.c
      echo "main(){" >> ${LSOF_TMPC}.c
      echo "enum vtype p=VSOCK;}" >> ${LSOF_TMPC}.c
      echo "Testing vnode.h for VSOCK, using $LSOF_CC"
      if test "X$LSOF_CC" = "Xgcc"
      then
	$LSOF_CC ${LSOF_TMPC}.c -o ${LSOF_TMPC}.x > /dev/null 2>&1
      else
	$LSOF_CC ${LSOF_TMPC}.c -I$LSOF_INCLUDE -o ${LSOF_TMPC}.x > /dev/null 2>&1
      fi
      if test $? -eq 0
      then
	LSOF_CFGF="$LSOF_CFGF -DHAS_VSOCK"
      fi
      rm -f ${LSOF_TMPC}.*
    else
      if test "X$SOLARIS_VSOCK" = "XY" -o "X$SOLARIS_VSOCK" = "Xy"
      then
	LSOF_CFGF="$LSOF_CFGF -DHAS_VSOCK"
      fi
    fi

    # Test for AFS.

    if test -r ${AFS_VICE}/etc/ThisCell
    then
      if test "X$LSOF_SCRIPT_CALL" = "Xno"
      then
	if test -r ./AFSHeaders -a -r ./AFSVersion
	then
	  LSOF_AFS="yes"
	fi
      else
	if test ! -x ./AFSConfig
	then
	  echo "Can't find or execute the AFSConfig script"
	  rm -f $LSOF_HLP
	  exit 1
	fi
	./AFSConfig
	if test $? -eq 0 -a -r ./AFSHeaders -a -r ./AFSVersion
	then
	    LSOF_AFS="yes"
	fi
      fi
      if test "X$LSOF_AFS" = "Xyes"
      then
	LSOF_AFSV=`cat ./AFSVersion | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1 \2/' | awk '{printf "%d%02d\n",\$1,\$2}'`
	LSOF_CFGF="$LSOF_CFGF -DHAS_AFS=$LSOF_AFSV"
	LSOF_DINC="$LSOF_DINC -I`cat ./AFSHeaders`"
      fi
    fi

    # Test for VxFS.

    if test -r ${LSOF_INCLUDE}/sys/fs/vx_inode.h
    then
      LSOF_CFGF="$LSOF_CFGF -DHASVXFS"
      if test -r ${LSOF_INCLUDE}/sys/fs/vx_fs.h
      then
	LSOF_CFGF="$LSOF_CFGF -DHASVXFS_FS_H"
      fi
      if test -r ${LSOF_INCLUDE}/sys/fs/vx_sol.h
      then
	LSOF_CFGF="$LSOF_CFGF -DHASVXFS_SOL_H"
      fi
      egrep "struct[ 	]vx_inode[ 	]{" ${LSOF_INCLUDE}/sys/fs/vx_inode.h > /dev/null
      if test $? -eq 0
      then
	LSOF_CFGF="$LSOF_CFGF -DHASVXFS_VX_INODE"
      fi
    fi

    # Set libraries and dialect subdirectory.

    LSOF_CFGL="-lkvm -lelf -lsocket -lnsl"
    LSOF_DIALECT_DIR=sun

    # Set PUCC-specific stuff.

    if test "X$LSOF_LOCALSUFFIX" = "XPUCC"
    then
      LSOF_DOC="\${DESTDIR}/usr/local/man"
    fi
    ;;

# Configure for SunOS 4.1.x, Sun C and gcc.

  sunos|sunoscc)
    if test "X$LSOF_TGT" = "Xsunos"
    then
      LSOF_CC=gcc
      LSOF_CFGF="-ansi"
    else
      LSOF_TGT="sunos"
      if test "X$SUNOS_ACC" = "X"
      then
	SUNOS_ACC="/usr/lang"
      fi
      if test -x ${SUNOS_ACC}/acc
      then
	LSOF_CC=${SUNOS_ACC}/acc
      else
	LSOF_CC=cc
      fi

      # See if C compiler supports the const keyword.

      if test "X$SUNOS_NOCONST" = "X"
      then
	rm -f ${LSOF_TMPC}.*
	echo "main() { const x; }" > ${LSOF_TMPC}.c
	echo "Testing $LSOF_CC for const support"
	if test "X$LSOF_CC" = "Xgcc"
	then
	  $LSOF_CC -c ${LSOF_TMPC}.c -o ${LSOF_TMPC}.o > /dev/null 2>&1
	else
	  $LSOF_CC -c ${LSOF_TMPC}.c -I$LSOF_INCLUDE -o ${LSOF_TMPC}.o > /dev/null 2>&1
	fi
	if test $? -ne 0
	then
	  LSOF_CFGF="-DNOCONST"
	fi
	rm -f ${LSOF_TMPC}.*
      else
	if test "X$SUNOS_NOCONST" = "XY" -o "X$SUNOS_NOCONST" = "Xy"
	then
	  LSOF_CFGF="-DNOCONST"
	fi
      fi
    fi
    if test "X$LSOF_VERS" = "X"
    then

      # If SunOS version isn't pre-defined, determine it.

      LSOF_VERS=`uname -r | sed 's/\([0-9\.]*\).*/\1/' | awk -F. '{printf "%d%02d%02d", $1, $2, $3}'`
    fi
    LSOF_CFGF="$LSOF_CFGF -DSUNOSV=$LSOF_VERS"
    LSOF_CFGL="-lkvm"
    LSOF_DIALECT_DIR=sun
    if test "X$LSOF_LOCALSUFFIX" = "XPUCC"
    then
      LSOF_DOC="\${DESTDIR}/usr/man"
    fi

    # Test for VSOCK.

    if test "X$SUNOS_VSOCK" = "X"
    then
      rm -f ${LSOF_TMPC}.*
      echo "#include <sys/types.h>" > ${LSOF_TMPC}.c
      echo "#include <sys/time.h>" >> ${LSOF_TMPC}.c
      echo "#include <sys/vnode.h>" >> ${LSOF_TMPC}.c
      echo "main(){" >> ${LSOF_TMPC}.c
      echo "enum vtype p=VSOCK;}" >> ${LSOF_TMPC}.c
      echo "Testing vnode.h for VSOCK, using $LSOF_CC"
      if test "X$LSOF_CC" = "Xgcc"
      then
	$LSOF_CC ${LSOF_TMPC}.c -o ${LSOF_TMPC}.x > /dev/null 2>&1
      else
	$LSOF_CC ${LSOF_TMPC}.c -I$LSOF_INCLUDE -o ${LSOF_TMPC}.x > /dev/null 2>&1
      fi
      if test $? -eq 0
      then
	LSOF_CFGF="$LSOF_CFGF -DHAS_VSOCK"
      fi
      rm -f ${LSOF_TMPC}.*
    else
      if test "X$SUNOS_VSOCK" = "XY" -o "X$SUNOS_VSOCK" = "Xy"
      then
	LSOF_CFGF="$LSOF_CFGF -DHAS_VSOCK"
      fi
    fi

    # Test for AFS.

    if test -r ${AFS_VICE}/etc/ThisCell
    then
      if test "X$LSOF_SCRIPT_CALL" = "Xno"
      then
	if test -r ./AFSHeaders -a -r ./AFSVersion
	then
	  LSOF_AFS="yes"
	fi
      else
	if test ! -x ./AFSConfig
	then
	  echo "Can't find or execute the AFSConfig script"
	  rm -f $LSOF_HLP
	  exit 1
	fi
	./AFSConfig
	if test $? -eq 0 -a -r ./AFSHeaders -a -r ./AFSVersion
	then
	    LSOF_AFS="yes"
	fi
      fi
      if test "X$LSOF_AFS" = "Xyes"
      then
	LSOF_AFSV=`cat ./AFSVersion | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1 \2/' | awk '{printf "%d%02d\n",\$1,\$2}'`
	LSOF_CFGF="$LSOF_CFGF -DHAS_AFS=$LSOF_AFSV"
	LSOF_DINC="$LSOF_DINC -I`cat ./AFSHeaders`"
      fi
    fi
    ;;

# Configure for DEC Ultrix.

  ultrix)
    if test "X$LSOF_VERS" = "X"
    then

      # If the Ultrix version isn't pre-defined, determine it.

      case "`uname -r`" in
      4.2)
	LSOF_VERS="40200"
	;;
      4.3)
	LSOF_VERS="40300"
	;;
      4.4)
	LSOF_VERS="40400"
	;;
      4.5)
	LSOF_VERS="40500"
	;;
      *)
	echo Unknown Ultrix release: `uname -r`
	rm -f $LSOF_HLP
	exit 1
	;;
      esac
    fi
    
    # Test for a legal Ultrix version.

    case $LSOF_VERS in
    40200|40300|40400|40500)
      ;;
    *)
      echo "Illegal Ultrix version: $LSOF_VERS"
      rm -f $LSOF_HLP
      exit 1
      ;;
    esac
    LSOF_CFGF="-DULTRIXV=$LSOF_VERS $LSOF_CFGF"
    if test "X$ULTRIX_HWNM" = "X"
    then
      ULTRIX_HWNM=`uname -m`
    fi
    case $ULTRIX_HWNM in
    RISC)
      ;;
    VAX)
      LSOF_CFGF="$LSOF_CFGF -DVAXULTRIX"
      ;;
    *)
      echo Unknown machine hardware name: `uname -m`
      rm -f $LSOF_HLP
      exit 1
      ;;
    esac

    # Test for DECnet

    if test "X$ULTRIX_DECNET" = "X"
    then
      if test "X$ULTRIX_USRLIB" = "X"
      then
	ULTRIX_USRLIB="/usr/lib"
      fi
      if test -r ${ULTRIX_USRLIB}/libdnet.a -a -r ${LSOF_INCLUDE}netdnet/dn.h
      then
	LSOF_TMP1=1
      else
       LSOF_TMP1=0
      fi
    else
      if test "X$ULTRIX_DECNET" = "XY" -o "X$ULTRIX_DECNET" = "Xy"
      then
	LSOF_TMP1=1
      else
	LSOF_TMP1=0
      fi
    fi
    if test $LSOF_TMP1 -eq 1
    then
      LSOF_CFGL="-ldnet"
      LSOF_CFGF="$LSOF_CFGF -DDECnet"
    else
      LSOF_CFGL=""
    fi
    LSOF_DIALECT_DIR=ultrix
    ;;

# Configure for SCO UnixWare.

  unixware|uw)
    LSOF_RANLIB=""
    if test "X$LSOF_VERS" = "X"
    then

      # If the UnixWare version isn't pre-defined, determine it.

      LSOF_VERS=`uname -v | sed 's/\([0-9\.]*\).*/\1/; s/\./ /g' | awk '{printf "%d%02d%02d\n", $1, $2, $3;}'`
    fi
    LSOF_CFGF="-DUNIXWAREV=$LSOF_VERS"

    # Do UnixWare version-specific stuff.

    case $LSOF_VERS in
    20100|20101|20102)
      LSOF_DINC="$LSOF_DINC -I`pwd`/dialects/uw/uw21"
      if test ! -r ${LSOF_INCLUDE}/vm/swap.h -a -r ${LSOF_INCLUDE}/sys/swap.h
      then
	(cd ./dialects/uw/uw21/vm; rm -f swap.h; ln -s ${LSOF_INCLUDE}/sys/swap.h swap.h)
      fi
      if test -r ${LSOF_INCLUDE}/sys/fs/vx_inode.h
      then
	LSOF_CFGF="$LSOF_CFGF -DHASVXFS"
      fi
      LSOF_CFGL="-lsocket -lnsl -lelf -lgen"
      ;;
    *)
      echo Unsupported UnixWare version: `uname -v`
      rm -f $LSOF_HLP
      exit 1
      ;;
    esac
    LSOF_DIALECT_DIR=uw
    ;;

# Handle unknown abbreviation.

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

# End of LSOF_TGT cases

esac

# Do an inventory of the distribution, as required.

if test "X$LSOF_SCRIPT_CALL" = "Xyes" -a ! -r ./.neverInv
then
  if test ! -f ./Inventory	# Want -x, but Ultrix doesn't grok it.
  then
    echo "Can't find Inventory script."
    rm -f $LSOF_HLP
    exit 1
  fi
  ./Inventory
fi

# 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, $LSOF_SPMKF, or $LSOF_MKF.$LSOF_LOCALSUFFIX) exists
# in the target directory.

if test "X$LSOF_SPMKF" != "X"
then
  LSOF_TMP1=$LSOF_SPMKF
else
  LSOF_TMP1=$LSOF_MKF
fi
if test "X$LSOF_LOCALSUFFIX" != "X"
then
  LSOF_REST=$LSOF_TMP1.$LSOF_LOCALSUFFIX
else
  LSOF_REST=$LSOF_TMP1
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 $LSOF_VERS

# Make $LSOF_MKFC and ${LSOF_LIB}/$LSOF_LIBMKF.

echo "# $LSOF_TGT Makefile for lsof version $LSOF_VN" > $LSOF_MKFC
echo "" >> $LSOF_MKFC
if test "X$LSOF_CC" = "X"
then
  LSOF_CC=cc
fi
echo "CC=	$LSOF_CC" >> $LSOF_MKFC
if test "X$LSOF_CCV" != "X"
then
  echo "CCV=	$LSOF_CCV" >> $LSOF_MKFC
else
  if test "X$LSOF_CC" = "Xgcc"
  then
    LSOF_CCV=`gcc -v 2>&1 | sed -n 's/.*version \(.*\)/\1/p'`
    echo "CCV=	$LSOF_CCV" >> $LSOF_MKFC
  fi
fi
echo "LIB=	${LSOF_LIB}/liblsof.a" >> $LSOF_MKFC
echo "" >> $LSOF_MKFC
if test "X$LSOF_LD" != "X"
then
  echo "LD=	$LSOF_LD" >> $LSOF_MKFC
  echo "" >> $LSOF_MKFC
fi
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_FCFGL -L./$LSOF_LIB -llsof $LSOF_CFGL" >> $LSOF_MKFC
if test "X$LSOF_DEBUG" != "X"
then
  echo "" >> $LSOF_MKFC
  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
rm -f ${LSOF_LIB}/$LSOF_LIBMKF
cp $LSOF_MKFC ${LSOF_LIB}/$LSOF_LIBMKF
cat ./dialects/$LSOF_DIALECT_DIR/$LSOF_REST >> $LSOF_MKFC

# Put optional archiver and randomizing strings in ${LSOF_LIB}/$LSOF_LIBMKF.
# Add its skeleton section.

echo "" >> ${LSOF_LIB}/$LSOF_LIBMKF
if test "X$LSOF_AR" != "X"
then
  echo "AR=	$LSOF_AR" >> ${LSOF_LIB}/$LSOF_LIBMKF
fi
if test "X$LSOF_RANLIB" != "X"
then
  echo "RANLIB=	$LSOF_RANLIB" >> ${LSOF_LIB}/$LSOF_LIBMKF
fi
echo "" >> ${LSOF_LIB}/$LSOF_LIBMKF
cat ${LSOF_LIB}/$LSOF_LIBMKFSKEL >> ${LSOF_LIB}/$LSOF_LIBMKF
echo $LSOF_MKFC and ${LSOF_LIB}/$LSOF_LIBMKF created.
rm -f $LSOF_HLP

# Call Customize, as required.

if test "X$LSOF_SCRIPT_CALL" = "Xyes" -a ! -r ./.neverCust
then
  if test ! -f ./Customize	# Want -x, but Ultrix doesn't grok it.
  then
    echo "Can't find Customize script."
    exit 1
  fi
  ./Customize
fi
exit 0
