#!/bin/sh
# $Author: djh $ $Date: 1991/11/24 15:25:20 $
# $Header: /mac/src/cap60/RCS/Configure,v 2.31 1991/11/24 15:25:20 djh Rel djh $
# $Revision: 2.31 $
# CAP configuration shell script.  This ain't perfect, but it's a start.
# Execute with /bin/sh Configure if your system won't run it (ksh is okay too)
# 
# Usage: Configure [output file name]
#
fastether="define([fastether],1) # For papif and samples"
needselfdef="define([selfdefinetypes],1)"
ccompiler=cc
# ccompiler="define([thecompiler],[cc])"
# lpd system "bsd" or sys v "lp"
lpd="bsd"
mydir=`pwd`
PCAT=/bin/cat
PGREP=grep
if [ -f /bin/nm ]; then
  PNM=/bin/nm
else
  PNM=/usr/bin/nm
fi
# define to sh or /bin/sh if shell scripts can't be "executed" for some reason
USESH=""
export PGREP
os=""
ossecondary=""

echo 
echo "This is the CAP configuration script. It will attempt to help"
echo "you get the CAP libraries and component programs configured."
echo "Please refer to NOTES before you run if you haven't already."
echo
if [ -f /etc/atalk.local ]; then
  ${PGREP} _ /etc/atalk.local > /dev/null
  rc=$?
  if [ $rc -eq 0 ]; then
    echo "WARNING: Your /etc/atalk.local file MAY need to be edited."
    echo "Zone names must now be quoted to include spaces. The use"
    echo "of underscores to denote a space is no longer supported."
  fi
fi
echo 

echo
echo "MAJOR CONFIGURATION"

# Configure OS
echo "Checking for Ultrix 4.0 or later versions of Ultrix"
# Ultrix4.0
if [ -f /bin/uname ]; then
	case "`/bin/uname`" in
	"ULTRIX")
		if [ `/bin/uname -r` -ge 4 ]; then
			osdefault="ultrix40"
		fi
	;;
	esac
fi
# Ultrix2.0
if [ -z "${osdefault}" ]; then
	echo "Checking for Ultrix 2.0"
	if [ -f /vmb.exe ]; then
		if [ -d /var ]; then
			ossecondary="ultrix22"
			echo "Ultrix 2.2 or later version of Ultrix"
		else
			echo "Ultrix 2.0 or later version of Ultrix"
		fi
		osdefault="ultrix20"
	fi
fi
# sunos
if [ -z "${osdefault}" ]; then
	echo "Checking for SunOS"
	if [ -f /bin/sun ]; then
		/bin/sun 2>/dev/null >/dev/null
		if [ $? -eq 0 ]; then
			echo "SunOS"
			osdefault="sunos"
		fi
	fi
fi
# Encore Multimax
if [ -z "${osdefault}" ]; then
	echo "Checking for Encore MultiMax"
	if [ -f /Umax.image ]; then
		osdefault="encore"
	fi
fi
# IBM RT
if [ -z "${osdefault}" ]; then
	echo "Checking for IBM RT running ACIS 4.2/4.3"
	if [ -f /lib/ropt ]; then
	  if [ -d /usr/ibm ]; then
		osdefault="bsd"
		echo "IBM RT with ACIS 4.x"
		ossecondary="acis 4.x"
	   if [ -f /bin/pcc ]; then
echo "I see /bin/pcc - I will use this instead of cc in case"
echo "you have the MetaWare High C compiler set as default"
		ccompiler="pcc"
	   else
echo "WARNING: the MetaWare High C compiler and CAP are not compatible"
echo "modify the thecompiler define to point to the portable C compiler"
echo "if the default happens to be hc"
	   fi
	  fi
	fi
fi
# Pyramid
if [ -z "${osdefault}" ]; then
	echo "Checking for Pyramid"
	if [ -f /bin/pyr ]; then
		/bin/pyr
		rc=$?
		if [ $rc -eq 0 ]; then
			echo "Pyramid"
			osdefault="pyr"
		fi
	fi
fi
#Amdahl
if [ -z "${osdefault}" ]; then
	echo "Checking for UTS"
	if [ -f /bin/uts ]; then
		/bin/uts
		rc=$?
		if [ $rc -eq 0 ]; then
			echo "uts"
			osdefault="uts"
			lpd="lp"
		fi
	fi
fi
useauxappletalk=0
# A/UX, hpux, SCO Xenix System V
if [ -z "${osdefault}" ]; then
	echo "Checking for System V based machines"
	if [ -f /bin/uname ]; then
		case "`uname`" in
		"A/UX")
			echo "A/UX"
			osdefault="aux"
			if [ `uname -r` -ge 2 ]; then
			  echo "Release 2.0 or greater"
			  echo "(defaulting to native AppleTalk)"
			  useauxappletalk=1
			  lpd="lpr"
			else
			  echo "Release 1.1.1 or less"
			  lpd="lp"
			fi
			break
		;;
		"HP-UX")
			echo "HP-UX"
			osdefault="hpux"
			lpd="lp"
			if [ `uname -r` -ge 6 ]; then
				echo "Release 6.0 or later"
			else
echo "OLD hpux version: you will have to define NEEDMSGHDR in CAPOSDEFS"
echo "by hand (c.f. PORTING and NOTES)"
			fi
			break
		;;
		"XENIX")
			echo "SCO Xenix System V"
			osdefault="xenix5"
			lpd="lp"
			break
		;;
		"AIX")
			echo "IBM AIX System V"
			osdefault="aix"
			lpd="lp"
			break
		;;
		esac
	fi
fi
# Sequent Balance
if [ -z "${osdefault}" ]; then
	echo "Checking for Sequent Balance"
	if [ -f /dynix ]; then
		echo "Sequent Balance"
		osdefault="dynix"
	fi
fi
# Silicon Graphics
if [ -z "${osdefault}" ]; then
	echo "Checking for Silicon Graphics IRIS/IRIX"
	if [ -f /bin/4d ]; then
		/bin/4d
		rc=$?
		if [ $rc -eq 0 ]; then
			echo "Silicon Graphics IRIS/IRIX"
			osdefault="irix"
		fi
	fi
fi
# Sony NEWS
if [ -z "${osdefault}" ]; then
	echo "Checking for Sony NEWS"
	if [ -d /usr/sony/bin ]; then
		echo "Sony NEWS"
		osdefault="newsos"
	fi
fi
# Default
if [ -z "${osdefault}" ]; then
  echo "Establishing default as BSD"
  echo "Warning: unable to guess unix variant, setting to bsd standard."
  echo "bsd should be good for the following:"
  echo "  IBM-RT (ACIS 4.2,4.3), Ultrix 1.0, Ultrix 1.1, BSD 4.2,"
  echo "  and BSD 4.3"
  osdefault="bsd"
fi
echo
valid=0
newl=""
echo -n test | ${PGREP} n > /dev/null
rc=$?
if [ $rc -ne 0 ]; then
  newl="-n"
fi
while [ ${valid} -eq 0 ];
do
  echo $newl "Operating System type? (default ${osdefault}, ? for valid items) "
  read os arg1
  if [ -z "${os}" ]; then
	os=${osdefault}
  fi
  case ${os} in
	"ultrix20") valid=1;;
	"ultrix40") valid=1;;
	"ultrix12") valid=1;;
	"bsd") valid=1;;
	"hpux") valid=1;;
	"aux") valid=1;;
	"xenix5") valid=1;;
	"aix") valid=1;;
	"uts") valid=1;;
	"pyr") valid=1;;
	"sunos") valid=1;;
	"encore") valid=1;;
	"next") valid=1;;
	"dynix") valid=1;;
	"irix") valid=1;;
	"newsos") valid=1;;
	"?"|*)
		if [ "${os}" != "?" ]; then
			echo "unknown type ${os}, valid are:"
		fi
		echo "	bsd - try if you aren't sure";
		echo "	ultrix12 - Ultrix 1.2";
		echo "	ultrix20 - Ultrix 2.0 or later";
		echo "	ultrix40 - Ultrix 4.0 or later";
		echo "	hpux - HP-UX for series 9000";
		echo "	aux - A/UX";
		echo "  uts - Amdahl UTS";
		echo "	xenix5 - SCO Xenix System V";
		echo " 	aix - IBM AIX System V";
		echo "	pyr - pyramid";
		echo "	sunos - suns";
		echo " 	encore - Encore MultiMax";
		echo " 	next - NeXT/MACH";
		echo " 	dynix - Sequent Balance"
		echo " 	irix - Silicon Graphics IRIS/IRIX"
		echo "  newsos - Sony NEWS"
	 ;;
  esac
done
echo "Will configure for ${os}"
echo
echo
uabprogs="define([uabprogs],[])"
uabplibs="define([uabplibs],[])"
uabpobjs="define([uabpobjs],[])"
etherprogs="define([etherprogs],[])"
etherpobjs="define([etherpobjs],[])"
lapobj="define([lapobj],[abkip.o abddp.o abnbp.o atalkdbm.o])"
usingphase2="# define([usephase2],1)"
singletree="# define([debug],1)"
result=0
usephase2=0
uabsupport=0
ethersupport=0
case ${os} in
	"sunos"|"ultrix40"|"ultrix20"|"ultrix12")
  		uabsupport=1
		ethersupport=1
		;;
	"pyr")
# later, someone should try this.
#  		uabsupport=1
		ethersupport=1
		;;
	"irix")
		uabsupport=1
		ethersupport=0
		;;
	"newsos")
		uabsupport=1
		ethersupport=0
		;;
	*)
  		uabsupport=0
		ethersupport=0
		;;
esac
if [ ${uabsupport} -eq 1 ]; then
  result=0
  while :
  do
    echo $newl "Do you wish to use UAB (Unix AppleTalk Bridge) (default no) ? "
    read ans
    if [ -z "${ans}" ]; then
	  ans="no"
    fi
    case ${ans} in
	  "yes"|"y") result=1; break;;
	  "no" |"n") result=0; break;;
	  *) echo "you must answer yes or no or carriage return for no." ;;
    esac
  done
  if [ $result -eq 0 ]; then
    echo "Not using UAB."
    uabprogs="define([uabprogs],[])"
    uabplibs="define([uabplibs],[])"
    uabpobjs="define([uabpobjs],[])"
    lapobj="define([lapobj],[abkip.o abddp.o abnbp.o atalkdbm.o])"
  else
    uabprogs="define([uabprogs],[uab])"
    uabplibs="define([uabplibs],[libuabcap.a])"
    lapobj="define([lapobj],[abmkip.o abddp.o abnbp.o atalkdbm.o])"
    case ${os} in
         "ultrix20"|"ultrix12")
      		  echo "OK, setting things up for UAB."
  		  uabpobjs="define([uabpobjs],[dlip.o])";;
	 "ultrix40")
      		  echo "OK, setting things up for UAB."
  		  uabpobjs="define([uabpobjs],[spfiltp.o])";;
	  "pyr")
      		  echo "OK, setting things up for UAB."
    		  uabpobjs="define([uabpobjs],[senetp.o])";;
	  "irix")
      		  echo "OK, setting things up for UAB."
    		  uabpobjs="define([uabpobjs],[snooppf.o])";;
	  "newsos")
      		  echo "OK, setting things up for UAB."
    		  uabpobjs="define([uabpobjs],[srawetherp.o])";;
	  "sunos")
  		  echo $newl "Have you installed the 'enet' driver (no) ? "
      		  read ans
      		  if [ -z "${ans}" ]; then
  	  		ans="no"
      		  fi
  		  case ${ans} in
  			"yes"|"y") aresult=1;;
  			*) aresult=0;;
  		  esac
  		  if [ $aresult -eq 0 ]; then
  			echo "OK, using the NIT ethernet interface."
    		  	uabpobjs="define([uabpobjs],[snitp.o])"
  		  else
  			echo "OK, using the 'enet' ethernet interface."
    		  	uabpobjs="define([uabpobjs],[senetp.o])"
  		  fi
    esac
  fi
fi
echo
if [ $result -eq 0 ]; then
  if [ ${ethersupport} -eq 1 ]; then
    result=0
    while :
    do
      echo $newl "Do you wish to use Native EtherTalk (default no) ? "
      read ans
      if [ -z "${ans}" ]; then
  	  ans="no"
      fi
      case ${ans} in
  	  "yes"|"y") result=1; break;;
  	  "no" |"n") result=0; break;;
  	  *) echo "you must answer yes or no or carriage return for no." ;;
      esac
    done
    if [ $result -eq 0 ]; then
      echo "Not using Native EtherTalk."
      etherprogs="define([etherprogs],[])"
      etherpobjs="define([etherpobjs],[])"
      lapobj="define([lapobj],[abkip.o abddp.o abnbp.o atalkdbm.o])"
    else
      etherprogs="define([etherprogs],[aarpd])"
      lapobj="define([lapobj],[abetalk.o abddp.o abnbp.o atalkdbm.o])"
      case ${os} in
         "ultrix20"|"ultrix12")
      		  echo "OK, setting things up for Native EtherTalk."
    		  etherpobjs="define([etherpobjs],[dlip.o])";;
  	 "ultrix40")
		  echo $newl "Do you want Phase 2 compatibility (no) ? "
		  read ans
		  if [ -z "${ans}" ]; then
			ans="no"
		  fi
		  case ${ans} in
		    "yes"|"y")
		      result=0
		      usephase2=1
      		      echo "OK, setting things up for Native EtherTalk, Phase 2"
                      ;;
                    *)
      		      echo "OK, setting things up for Native EtherTalk."
                      ;;
                  esac
    		  etherpobjs="define([etherpobjs],[spfiltp.o])";;
	  "pyr")
      		  echo "OK, setting things up for Native EtherTalk."
    		  etherpobjs="define([etherpobjs],[senetp.o])";;
  	  "sunos")
		  echo $newl "Do you want Phase 2 compatibility (no) ? "
		  read ans
		  if [ -z "${ans}" ]; then
			ans="no"
		  fi
		  case ${ans} in
		    "yes"|"y")
		      result=0
		      usephase2=1
		      ;;
		    *)
		      ;;
                  esac
		  echo $newl "Have you installed the 'enet' driver (no) ? "
      		  read ans
      		  if [ -z "${ans}" ]; then
  	  		ans="no"
      		  fi
  		  case ${ans} in
  			"yes"|"y") result=1;;
  			*) result=0;;
  		  esac
  		  if [ $result -eq 0 ]; then
  			echo $newl "OK, using the NIT ethernet interface"
    		  	etherpobjs="define([etherpobjs],[snitp.o])"
  		  else
  			echo $newl "OK, using the 'enet' ethernet interface"
    		  	etherpobjs="define([etherpobjs],[senetp.o])"
  		  fi
                  if [ $usephase2 -eq 1 ]; then
                  	echo " with Phase 2."
		  else
                  	echo "."
                  fi
		  ;;
      esac
    fi
  fi
fi
if [ $useauxappletalk -ne 0 ]; then
  lapobj="define([lapobj],[abauxddp.o abauxnbp.o])"
fi
if [ $usephase2 -ne 0 ]; then
  usingphase2="define([usephase2],1)"
fi
echo
echo "CAP can be setup to occupy a single directory tree (for testing)."
result=0
while :
do
  echo $newl "Do you wish to restrict CAP to this subdirectory (default no) ? "
  read ans
  if [ -z "${ans}" ]; then
    ans="no"
  fi
  case ${ans} in
    "yes"|"y") result=1; break;;
    "no" |"n") result=0; break;;
    *) echo "you must answer yes or no or carriage return for no." ;;
  esac
done
if [ $result -ne 0 ]; then
  echo "OK, using" ${mydir} "as the CAP root directory."
  singletree="define([debug],1)"
fi
echo
echo "CAP can be configured for various optional features."
echo "For more information, refer to the file 'CAP60.README'."
echo
echo "Checking for special feature customisation ..."
${PCAT} <<\EOT0 > /tmp/m4.f.$$
# m4.features
#
# This file is used to determine the default set of additional features
# that will be incorporated into CAP. These features have been contributed
# by many people throughout the network community.
#
# Necessary preamble - please don't alter
define(`concat',$1$2$3$4$5$6$7$8$9)
define(`specialcflags',`')
define(`aufsosflags',`')
define(`simpleflags',`')
define(`lwflags',`')
#
# To change the feature set, simply uncomment the wanted defines().
# The Configure file will then use the customised version.
# For more details, refer to the file 'CAP60.README'
#
# + SHORT_NAMES adds short name support to AUFS for AppleShare PC.
# define(`specialcflags',concat(specialcflags,` -DSHORT_NAMES'))
#
# + NOCASEMATCH removes UNIX case sensitivity in AUFS (like Macs).
# define(`specialcflags',concat(specialcflags,` -DNOCASEMATCH'))
#
# + SIZESERVER adds a daemon per AUFS server process for volume size info.
# define(`specialcflags',concat(specialcflags,` -DSIZESERVER'))
#
# + LWSRV_AUFS_SECURITY provides printer security based on AUFS connection.
# define(`specialcflags',concat(specialcflags,` -DLWSRV_AUFS_SECURITY'))
#
# + LWSRV_LPR_LOG causes stdout/stderr lpr output to be included in lwsrv log
# define(`specialcflags',concat(specialcflags,` -DLWSRV_LPR_LOG'))
#
# + AUTHENTICATE turn on alternate AUFS/LWSRV authentication method
# define(`specialcflags',concat(specialcflags,` -DAUTHENTICATE'))
#
# + STAT_CACHE causes critical AUFS stat() calls to be cached.
# define(`specialcflags',concat(specialcflags,` -DSTAT_CACHE'))
#
# + TREL_TIMEOUT causes an extra TREL timeout listener to run to avoid timeouts
# define(`specialcflags',concat(specialcflags,` -DTREL_TIMEOUT'))
#
# + RUTGERS includes local modifications for Rutgers University
# define(`specialcflags',concat(specialcflags,` -DRUTGERS'))
#
# + MELBOURNE includes local modifications for Melbourne University
# define(`specialcflags',concat(specialcflags,` -DMELBOURNE'))
#
# + USE_HOST_ICON provides automatic aufs ICON selection on supported hosts
# define(`specialcflags',concat(specialcflags,` -DUSE_HOST_ICON'))
#
# + PERMISSIVE_USER_NAME allows AUFS users to have their real name in Chooser
# define(`specialcflags',concat(specialcflags,` -DPERMISSIVE_USER_NAME'))
#
# + ULTRIX_SECURITY adds ULTRIX enhanced security to aufs
# define(`specialcflags',concat(specialcflags,` -DULTRIX_SECURITY'))
#
# + USE_MAC_DATES maintains Mac Create/Modify dates on file copy
# define(`specialcflags',concat(specialcflags,` -DUSE_MAC_DATES'))
#
# + DEV_NIT specifies alternate NIT device name (default "/dev/nit")
# define(`specialcflags',concat(specialcflags,` -DDEV_NIT=\"/dev/nit\"'))
#
# + APPLICATION_MANAGER control the use of designated applications
# define(`specialcflags',concat(specialcflags,` -DAPPLICATION_MANAGER'))
#
# + AUFS_README links readme file into new user's top level
# define(`specialcflags',concat(specialcflags,` -DAUFS_README'))
#
# + ULT42PFBUG unpatched ULTRIX 4.2 packet filter workaround (also need COPYALL)
# define(`specialcflags',concat(specialcflags,` -DULT42PFBUG'))
#
#
#
# AUFS definable options (previously required editing m4.setup)
#
# + NONLXLATE for aufs
# define(`aufsosflags',concat(aufsosflags,` -DNONLXLATE'))
#
# + FULL_NCS_SUPPORT (National Character Support) for aufs
# define(`aufsosflags',concat(aufsosflags,` -DFULL_NCS_SUPPORT'))
#
# + GGTYPE="gid_t" (group ID type) for AUFS
# define(`aufsosflags',concat(aufsosflags,` -DGGTYPE="gid_t"'))
#
# + NOCHGRPEXEC don't exec chgrp, just use chown(2) 3rd arg. [Not for Sys V]
# define(`aufsosflags',concat(aufsosflags,` -DNOCHGRPEXEC'))
#
# + USEDIRSETGID set group ID bit on non-primary group dirs [SunOS/Sys V]
# define(`aufsosflags',concat(aufsosflags,` -DUSEDIRSETGID'))
#
# + NETWORKTRASH fix permissions on network trash stuff
# define(`aufsosflags',concat(aufsosflags,` -DNETWORKTRASH'))
#
#
#
# LWSRV definable options (previously required editing m4.setup)
#
# + LPRARGS passes arguments on lwsrv command line directly to lpr
# define(`lwflags',concat(lwflags,` -DLPRARGS'))
#
# + DOCNAME adds document name as a part of job name to lpr
# define(`lwflags',concat(lwflags,` -DDOCNAME'))
#
# + PAGECOUNT adds page count to job name (value is internal buffer size)
# define(`lwflags',concat(lwflags,` -DPAGECOUNT=512'))
# define(`simpleflags',concat(simpleflags,` -DPAGECOUNT=512'))
#
# + ADOBE_DSC2_CONFORMANT forces Adobe DSC2 conformance
# define(`simpleflags',concat(simpleflags,` -DADOBE_DSC2_CONFORMANT'))
#
EOT0
result=0
if [ -f m4.features ]; then
  diff m4.features /tmp/m4.f.$$ > /dev/null 2>/dev/null
  rc=$?
  if [ $rc -ne 0 ]; then
    echo
    echo "You appear to have a locally customised version of m4.features."
    while :
    do
    echo $newl "I assume that you want to use it rather than the default (y) ? "
      read ans
      if [ -z "${ans}" ]; then
	    ans="yes"
      fi
      case ${ans} in
	    "y"|"ye"|"yes") result=1; break;;
	    "no"|"n") result=0; break;;
	    *) echo "you must answer yes or no or carriage return for yes." ;;
      esac
    done
    if [ $result -eq 0 ]; then
      echo "OK, copying m4.features to /tmp and replacing with the default."
      ${PCAT} m4.features > /tmp/m4.features
      ${PCAT} /tmp/m4.f.$$ > m4.features
    else
      echo "Using the locally customised version of m4.features."
    fi
  else
    echo "Using the default feature list."
  fi
else
  echo "Using the default feature list."
  ${PCAT} /tmp/m4.f.$$ > m4.features
fi
rm -f /tmp/m4.f.$$
echo
echo
result=0
while :
do
  echo $newl "Do you wish to customise the feature list (default no) ? "
  read ans
  if [ -z "${ans}" ]; then
    ans="no"
  fi
  case ${ans} in
    "y"|"yes")	result=1; break;;
    "n"|"no")	result=0; break;;
    *) echo "you must answer yes or no or carriage return for no." ;;
  esac
done
if [ $result -ne 0 ]; then
    case ${os} in
    "ultrix40"|"ultrix20"|"ultrix12"|"bsd"|"encore"|"newsos")
        ${EDITOR-vi} m4.features
    ;;
    *)
        ${EDITOR:-vi} m4.features
    ;;
    esac
fi
echo
echo
echo "Some machines send packets fast enough to overrun a Kinetics box"
echo "running KIP.  You should answer yes if you know this is the case."
echo "If you aren't sure, answer no.  You can go back and recompile the"
echo "relevant programs later.  Generally, the programs affected are the"
echo "LaserWriter printing programs."
echo
echo "Systems affected are generally those whose network interfaces are faster"
echo "than the DEQNA (DEC Q-Bus Network Adapter).  Machines at risk may"
echo "include, but are not limited to, Sun 3's and 4's and DEC VAX 8xxx class"
echo "machines with DEBNT/DEBNA's"
echo
result=0
while :
do
  echo $newl "Do you want to throttle output for a Kinetics box (default no)? "
  read ans
  if [ -z "${ans}" ]; then
	ans="no"
  fi
  case ${ans} in
	"y"|"ye"|"yes") result=1; break;;
	"no"|"n") fastether="# $fastether"; result=0; break;;
	*) echo "you must answer yes or no or carriage return for no" ;;
  esac
done
if [ $result -eq 0 ]; then
  echo "We won't slow down printing code."
else
  echo "We will slow down printing code."
fi
# check for byte swapping
echo
echo "Checking the byte ordering on your machine ..."
${PCAT} <<\EOTF > /tmp/bs$$.c
#include <stdio.h>

main()
{
  unsigned short aword, result;
  char *pchar = (char *) &aword;

  *pchar++ = 0x42;
  *pchar   = 0x53;

  result = (aword != 0x4253);
  printf("This appears to be a '%s-endian' machine.\n",(result)?"little":"big");
  exit(result);
}
EOTF
byteswapping="# define([usebyteswap],1)"
${ccompiler} -o /tmp/bs$$ /tmp/bs$$.c > /dev/null 2>/dev/null
rc=$?
if [ $rc -eq 0 ]; then
	/tmp/bs$$
	rc=$?
	if [ $rc -ne 0 ]; then
		byteswapping="define([usebyteswap],1)"
		echo "Defining BYTESWAPPED for correct operation."
	fi
else
	echo "Hmmm, can't get sensible results, assuming non-byteswapped"
	echo "Uncomment the 'usebyteswap' line in m4.setup if incorrect."
fi
rm -f /tmp/bs$$ /tmp/bs$$.c
# check types.h
echo
echo "Checking to see if the sequence"
echo "	#include <sys/param.h>"
echo "	#include <sys/types.h>"
echo "causes a problem at your site."
echo "Assuming that your C compiler returns error codes."
echo " Temporary files: /tmp/cx$$.c, cx$$.o"
echo
echo $newl "[Hit carriage return to continue] "
read ans
trap "
echo Exiting... Wait...
if [ -f /tmp/cx$$.c ]; then rm -f /tmp/cx$$.c; fi; 
if [ -f cx$$.o ]; then rm -f cx$$.o fi
exit 255" 2
echo "#include <sys/param.h>" > /tmp/cx$$.c
echo "#ifndef _TYPES" >> /tmp/cx$$.c
echo "# include <sys/types.h>" >> /tmp/cx$$.c
echo "#endif" >> /tmp/cx$$.c
${ccompiler} -c /tmp/cx$$.c > /dev/null 2>/dev/null
rc=$?
if [ $rc -ne 0 ]; then
  echo
  echo "The sequence does cause a problem, checking to see if the"
  echo "actual sequence:"
  echo "	#include <sys/param.h>"
  echo "	#ifndef _TYPES"
  echo "	# include <sys/types.h>"
  echo "	#endif"
  echo "can be made to work by define _TYPES everywhere"
  echo
  echo $newl "[Hit carriage return to continue] "
  read ans
  ${ccompiler} -c -D_TYPES /tmp/cx$$.c > /dev/null 2>/dev/null
  rc=$?
  if [ $rc -ne 0 ]; then
    echo
    echo "This failed, continuing configuration, but you probably won't be"
    echo "able to compile because sys/param.h or sys/types are probably not"
    echo "there and even if they are, CAP sources make invalid assumptions"
    echo "about them"
  fi
else
  echo
  echo "No problems here"
  needselfdef="# ${needselfdef}"
fi
rm -f /tmp/cx$$.c
if [ -f cx$$.o ]; then
  rm -f cx$$.o
fi
trap 2
echo
echo "Checking for various system calls.  (But not the list of system"
echo "call for system V compatibility). Temp files: m4.tmp, /tmp/cx$$"
echo
echo $newl "[Hit carriage return to continue] "
read ans
echo
trap "
echo Exiting... Wait...
if [ -f /tmp/cx$$ ]; then rm -f /tmp/cx$$; fi; exit 255" 2
case "${osdefault}" in
"xenix5")
	echo "Getting name list from /lib/386/Slib{[cx],socket}.a..."
	${PNM} /lib/386/Slibc.a		> /tmp/cx$$
	${PNM} /lib/386/Slibx.a		>> /tmp/cx$$
	${PNM} /lib/386/Slibsocket.a	>> /tmp/cx$$
	;;
*)
	if [ -f /lib/libc.a ]; then
	  echo "Getting name list from /lib/libc.a..."
	  ${PNM} /lib/libc.a > /tmp/cx$$
	else
	  if [ -f /usr/lib/libc.a ]; then
	    echo "Getting name list from /usr/lib/libc.a..."
	    ${PNM} /usr/lib/libc.a > /tmp/cx$$
	  else
	    if [ -f /lib/libsys_s.a ]; then
	      echo "Getting NeXT 2.0 name list from /lib/libsys_s.a..."
	      ${PNM} /lib/libsys_s.a > /tmp/cx$$
	    else
	      echo "Cannot get the namelist ... HELP"
	    fi
	  fi
	fi
	;;
esac
names=$?
if [ $names -ne 0 ]; then
 echo "Couldn't get the name list!"
else
 echo "Done, running function configuration"
 ${USESH} ./conf.func.sh /tmp/cx$$ conf.func.lst m4 m4.tmp
 rc=$?
 if [ $rc -eq 1 ]; then
   if [ -z "${USESH}" ]; then
     sh conf.func.sh /tmp/cx$$ conf.func.lst m4 m4.tmp
   fi
 fi
 echo "Done."
fi
rm -f /tmp/cx$$
trap 2
# now setup
if [ -z "$1" ]; then
 of=m4.setup
else
 of=$1
fi
echo
echo $newl "[Hit carriage return to continue] "
read ans
echo
if [ -f ${of} ]; then
  echo "Getting ready to overwrite existing ${of}"
else
  echo "Getting ready to create ${of}"
fi
echo
echo $newl "[Hit carriage return to continue] "
read ans
echo "Creating ${of}"
exec > ${of}
${PCAT} <<\EOT
define(`concat',$1$2$3$4$5$6$7$8$9)
changequote([,])

# os - one of:
#   "bsd" - bsd 4.2, bsd 4.3, ultrix 1.1, acis 4.2,4.3 other
#       "standard" bsd systems without nfs
#   "ultrix12" - Ultrix 1.2
#   "ultrix20" - Ultrix 2.0 or greater
#   "ultrix40" - Ultrix 4.0 or greater
#   "hpux" - HP/UX
#   "aux" - A/UX
#   "uts" - Amdahl UTS
#   "xenix5" - SCO Xenix System V
#   "aix" - IBM AIX System V
#   "pyr" - pyramid (in BSD universe)
#   "sunos" - SunOS
#   "encore" - Encore MultiMax
#   "next" - NeXT/MACH
#   "dynix" - Sequent Balance
#   "irix" - Silicon Graphics IRIS-4D/IRIX
#   "newsos" - Sony NEWS
# Warning: hpux, pyr are hardcoded in some of the makefiles (sorry)

# MAJOR CONFIGURATION
# set to one of the above (or configure your own below)
EOT
echo "define([os],[$os])"
echo
echo "# System call configuration (not for system v compatibilty)"
echo "# known: X_GETOPT, X_VPRINTF, X_GETMNT, X_STATFS, X_QUOTA,"
echo "# X_SUNQUOTA, X_FLOCK, X_LOCKF, X_FCNTLLOCKF"
${PCAT} m4.tmp
echo
echo "# GETOPT support"
if [ "${os}" = "dynix" ]; then
  echo "# Dynix provides getopt in -lseq"
else
  echo "ifdef([X_GETOPT],[],[define([needgetopt],[att_getopt.o])])"
fi
echo "# VPRINTF support"
echo "ifdef([X_VPRINTF],[define([usevprintf], 1)],[])"
echo
echo "# Path to cap sources: useful for testing"
echo "define([cwd],[${mydir}])" 
echo "# turn on if your system sends packets very quickly"
echo "# (see applications/aufs/INSTALLATION)"
echo "${fastether}"
echo
echo "# The following selects the correct lap delivery objects"
echo "${lapobj}"
echo
echo "# This determines what happens to UAB"
echo "${uabprogs}"
echo "${uabplibs}"
echo "${uabpobjs}"
echo
echo "# This sets up Native EtherTalk support"
echo "${etherprogs}"
echo "${etherpobjs}"
echo
echo "# And this determines if Phase 2 packets are used"
echo "${usingphase2}"
echo
echo "# The following selects byteswapping or otherwise"
echo "${byteswapping}"
echo
echo "# We use the debug flag to restrict CAP to a single directory tree"
echo "${singletree}"
echo
echo "# uncomment if your param.h includes types.h and types.h doesn't"
echo "# prevent itself from being included twice"
echo "# define _TYPES"
echo "${needselfdef}"
${PCAT} <<\EOT1
# MINOR CONFIGURATION: configure various programs

#define([columbia],1) # so columbia can do things quickly
#define([rutgers],1) # so rutgers can do things quickly

# location of include files
define([includedir],[[/usr/include]])
# location of des subroutine source (see lib/afp/README)
define([desloc],[[../../extras]])
# location of atalk.local, etc.
define([etcdest],[[/etc]])
ifdef([columbia],[define([etcdest],[[/usr/local/lib/cap]])])
# location of user cap programs
define([capdestdir],[[/usr/local/cap]])
# location of cap "server" programs (aufs, lwsrv, papif, uab etc.)
define([capsrvrdestdir],[[/usr/local/cap]])
# location of some cap data files
define([caplibdestdir],[[/usr/local/lib/cap]])
ifdef([rutgers],[define([caplibdestdir],[[/usr/local/cap/lib]])])
# location of cap libraries
define([libdestdir],[[/usr/local/lib]])
# override for aux (doesn't search /usr/local/lib)
ifelse(os,[aux],[define([libdestdir],[[/usr/lib]])])
# cap library names
define([caplib],[[libcap.a]])
define([afplib],[[libafp.a]])
define([afpclib],[[libafpc.a]])
# names to load cap libraries with
define([libcap],[[-lcap]])
define([libafp],[[-lafp]])
define([libafpc],[[-lafpc]])
ifelse(os,[encore],
	[define([libcap],concat([-L],libdestdir,[ ],libcap))])
ifelse(os,[encore],
	[define([libafp],concat([-L],libdestdir,[ ],libafp))])
ifelse(os,[encore],
	[define([libafpc],concat([-L],libdestdir,[ ],libafpc))])
ifelse(os,[aix],
	[define([libcap],concat([-L],libdestdir,[ ],libcap))])
ifelse(os,[aix],
	[define([libafp],concat([-L],libdestdir,[ ],libafp))])
ifelse(os,[aix],
	[define([libafpc],concat([-L],libdestdir,[ ],libafpc))])
# any special libraries
define([libspecial],[])
ifelse(os,[ultrix40],[
	define([libspecial],concat(libspecial,[ -lauth]))])
ifelse(os,[xenix5],[
	define([libspecial],concat(libspecial,[ -lsocket]))])
ifelse(os,[uts],[
	define([libspecial],concat(libspecial,[ -lsocket -lbsd -la]))])
ifelse(os,[dynix],[
	define([libspecial],concat(libspecial,[ -lseq]))])
ifelse(os,[irix],[
	define([libspecial],concat(libspecial,[ -lbsd]))])
ifelse(os,[aix],[
	define([libspecial],concat(libspecial,[ -lbsd]))])
ifelse(os,[aux],[
	define([libspecial],concat(libspecial,[ -lat]))])
ifelse(os,[hpux],[
	define([libspecial],concat(libspecial,[ -lBSD]))])

#
# special configurations for individual source files
#

#
# Aufs: see applications/aufs/INSTALLATION
#
# WARNING: OS DEPENDENT
# define([smartunixfinderinfo],1)
#
# Set -DNONLXLATE, -DFULL_NCS_SUPPORT, -DGGTYPE="gid_t" or -DNOCHGRPEXEC
#  in m4.features
# Others: USESTATFS, USEGETMNT, USECHOWN, USEQUOTA, USESUNQUOTA
#  are autoconfigured
define([aufsosdefs],[aufsosflags()])

#
# lib/cap/authenticate.c: configuration file
#
define([authconfig],[[\"/etc/cap.auth\"]])

#
# lwsrv: see applications/lwsrv/README
#
# lwflags and simpleflags are now defined in m4.features

#
# lwrename: set name of file containing list of printers to be renamed
#
define([lwrenamefile],concat([\"],caplibdestdir,[/lwrename.list\"]))

#
# papif: see applications/papif/README
#
# uncomment and set to right location to turn on printing "plain text files"
# define([pstextloc],[[\"/usr/local/lib/ps/pstext\"]])
#
# uncomment and set to right location to turn on page reversal
# define([psrevloc],[[\"/usr/local/lib/ps/psrev\"]])
#
# Valid are:
#  -DVERBOSELOG - default (set =0 to turn off)
#  -DNO_STRUCT - default is on (structured)
#  -DNOACCT - default is on (accounting)
#  -DIDLESTUFF - default is off
#  -DSFLOWQ - default is 8 (min 1, max 8)
#  -DRFLOWQ - default is 8 (min 1, max 8)
#  -DATPRESPONSETIMEOUT - default is 120 (2 minutes) - in seconds
#  -DWATCHTIME - default is 10 seconds (in seconds)
#  -DDEBUG - default is off
#  -DSTRIPCONTROLD - default is off
#  -DMAPCRTOLF - default is off
#  -DMACUSER - default is off (need LPD_JOB environment variable in lpd)
#  -DPLP - Use with PLP rather than Berkeley lpd
#  see papif README file for explanations of the above
# The following defines are recommended for System V lp printers (vs. bsd lpd)
#  -DWATCHTIME=0 (no status) -DNOACCT
define([papflags],[-DMACUSER])
EOT1
if [ "${lpd}" = "lp" ]; then
	echo "define([papflags],concat(papflags,[ -DWATCHTIME=0 -DNOACCT]))"
else
	echo "define([papflags],concat(papflags,[ -DIDLESTUFF]))"
fi
echo
echo "# Set -DBANNERFIRST if you want the banner page to come out as the"
echo "#  first page instead of the last page "
echo "# Set -DBANNERLAST if want it last"
echo "# Set -DPSBANNER if you want a custom PostScipt Banner (must specify"
echo "#  short banners in printcap). This still defaults to regular banners"
echo "# Add -DCHARGEBANNER if you want to charge the banner page to the user"
echo "#  on system V - there is no accounting, so leave blank"
if [ "${lpd}" = "lp" ]; then
	echo "define([papbanner],[])"
else
	echo "define([papbanner],[-DCHARGEBANNER])"
fi
${PCAT} <<\EOT3

# for cap.printers - uncomment and change the following line to point
# papif, et. al. to a location other than /etc/cap.printers.  (Note:
# line below would set it to $etcdest/cap.printers)
# define([capprinters],concat([\"],etcdest,[/],[cap.printers],[\"]))
ifdef([columbia],
       [define([capprinters],concat([\"],etcdest,[/],[cap.printers],[\"]))])
# for atalkdbm - allows change following line(s) to modify atalk.local
# (probably shouldn't).  Remember that atalk.local is expected to
# be in etcdest
define([atalklocal],concat([\"],etcdest,[/],[atalk.local],[\"]))
define([etalklocal],concat([\"],etcdest,[/],[etalk.local],[\"]))
define([configdir],concat([\"],etcdest,[\"]))
define([uabpidfile],concat([\"],caplibdestdir,[/],[uab.pid],[\"]))
define([uabbrdescr],concat([\"],caplibdestdir,[/],[bridge_desc],[\"]))

# in case you want to globally change the c compiler
EOT3
echo "define([thecompiler],[${ccompiler}])"
${PCAT} <<\EOT4
define([theloader],[ld])
define([theinstaller],[cp])

#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#		      END OF CONFIGABLE OPTIONS                            #
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# You should only edit past here if you are "porting"
# Automatics
define([osname],[Unknown])
ifelse(os,[ultrix12],[define([osname],[Ultrix 1.2])])
ifelse(os,[ultrix20],[define([osname],[Ultrix 2.0])])
ifelse(os,[ultrix40],[define([osname],[Ultrix 4.0])])
ifelse(os,[aux],[define([osname],[A/UX])])
ifelse(os,[sunos],[define([osname],[SunOS])])
ifelse(os,[encore],[define([osname],[Encore Umax])])
ifelse(os,[hpux],[define([osname],[HP-UX (for 9000 series)])])
ifelse(os,[uts],[define([osname],[Amdahl UTS])])
ifelse(os,[bsd],[define([osname],[Standard BSD])])
ifelse(os,[pyr],[define([osname],[Pyramid in BSD universe])])
ifelse(os,[xenix5],[define([osname],[SCO Xenix System V])])
ifelse(os,[aix],[define([osname],[IBM AIX System V])])
ifelse(os,[next],[define([osname],[NeXT/MACH])])
ifelse(os,[dynix],[define([osname],[Sequent Balance])])
ifelse(os,[irix],[define([osname],[Silicon Graphics IRIS/IRIX])])
ifelse(os,[newsos],[define([osname],[Sony NEWS])])
#
define([cflags],ifdef([selfdefinetypes],[-D_TYPES],[]))
define([cflags],concat(cflags,ifdef([usebyteswap],[ -DBYTESWAPPED],[])))
define([cflags],concat(cflags,ifdef([usephase2],[ -DPHASE2],[])))
define([bigcflags],ifelse(os,[hpux],[]))
# The encore optimiser is slightly over zealous
ifelse(os,[encore],[define([cflags],concat(cflags,[ -Dencore]))],[
    define([cflags],concat(cflags,[ -O]))])
ifelse(os,[pyr],[
    define([cflags],concat(cflags,[ -q]))])
ifelse(os,[next],[
    define([cflags],concat(cflags,[ -DNeXT -DADDRINPACK]))])
ifelse(os,[xenix5],[
    define([cflags],concat(cflags,[ -Dxenix5 -I$I -DLAI_TCP -Di386]))])
ifelse(os,[aix],[
    define([cflags],concat(cflags,[ -DAIX -DUSETIMES -DNOWAIT3 -DUSEDIRENT]))])
ifelse(os,[uts],[
    define([cflags],concat(cflags,[ -eft ]))])
ifelse(os,[irix],[
    define([cflags],concat(cflags,[ -D_BSD_COMPAT]))])

# was used for nbp, but found we needed more... leave in case
define([nbpflags],[])
define([lflags],[])
define([mflags],[])

# aux's c compiler isn't nice - it doesn't have a preprocessor
# definition for aux.  So, let's invent one.  Also turn on -n
# for shared code.
ifelse(os,[aux],[
	define([cflags],concat(cflags,[ -n -Daux]))
	define([lflags],concat(lflags,[ -n]))])

# check to see if we need sysvinstall usage
ifelse(os,[hpux],[define([sysvinstall],[yes])],
       os,[irix],[define([sysvinstall],[yes])])

# or if we really want to use install
# ifelse(os,[someOS], [define([theinstaller],[install])])

# for cap library
# Valid are:
#  NOFFS - no ffs function defined, fake it out
#  LOCALTIME_GTOD - uses pd localtime, but gettimeofday always reads
#   disk based time of day.  Always defined for AUX for now.  Probably
#   needs to be changed for versions of Aux after 1.0
#  NORECVMSG - no recvmsg in system (fake it out)
#  NOSENDMSG - no recvmsg in system (fake it out)
define([caposdefs],
	concat( ifdef([X_NOFFS],[ -DNOFFS],[]),
		ifelse(os,[aux],[ -DLOCALTIME_GTOD],[]),
		ifdef([X_NORECVMSG], [ -DNORECVMSG],[]),
		ifdef([X_NOSENDMSG], [ -DNOSENDMSG],[])))
# for afp library
# two cases for X_LOCKF - if lockf isn't defined
# first: X_FCNTLLOCKF is defined, so just note that lockf uses fcntl.h
# second: "         " isn't defined so define no lockf
# we "know" that flock() was hiding in libbsd.a under aix
define([afposdefs],
	concat(	ifdef([X_FLOCK],[], ifelse(os,[aix],[],[ -DNOFLOCK])),
		ifdef([X_LOCKF],[],
		   [ifdef([X_FCNTLLOCKF],[ -DLOCKFUSESFCNTL],[ -DNOLOCKF])])))
# for aufs
define([aufsosdefs],
    concat(aufsosdefs,
	ifdef([X_STATFS],[ -DUSESTATFS],[]),
	ifdef([X_GETMNT],[ -DUSEGETMNT],[]),
	ifdef([X_QUOTA],[ -DUSEQUOTA],[]),
	ifdef([X_SUNQUOTA],[ -DUSESUNQUOTA],[]),
	ifelse(os,[irix],[ -DNOVFORK]),
	ifelse(os,[aix],[ -DNOVFORK -DUSECHOWN],[])))

# if no ranlib (or fakeout like hpux) and need to order libaries
ifelse(os,[dummy],[define(uselordertsort,[1])],
       os,[aux],  [define(uselordertsort,[1])],
       os,[uts],  [define(uselordertsort,[1])],
       os,[irix], [define(uselordertsort,[1])])

# lw config
define([lwflags],
    concat(lwflags,
	ifdef([fastether],[ -DSFLOWQ=1],[]),
	ifelse(os,[aix],[],[])))

# more papif config
define([papflags],
    concat(papflags,
	ifelse(os,[irix],[ -DNOVFORK]),
	ifelse(os,[aix],[ -DNOVFORK],[])))

#NBPFLAGS = nbpflags()
#SPECCFLAGS = specialcflags()
#BIGCFLAGS = bigcflags()
#CFLAGS = cflags()
#LFLAGS = lflags()
#AFPOSDEFS = afposdefs()
#AUFSOSDEFS = aufsosdefs()

ifdef([debug],[
# location of include files
 define([includedir],[cwd])
# location of des subroutine source (see lib/afp/README)
 define([desloc],[[../../extras]])
# location of atalk.local, etc.
 define([etcdest],concat(cwd,[[[/etc]]]))
# location of user cap programs
 define([capdestdir],concat(cwd,[[[/bin]]]))
# location of cap "server" programs (aufs, lwsrv, papif, uab etc.)
 define([capsrvrdestdir],concat(cwd,[[[/bin]]]))
# location of some cap data files
 define([caplibdestdir],concat(cwd,[[[/bin]]]))
# location of cap libraries
 define([libdestdir],concat(cwd,[[[/lib]]]))
# cap library names
 define([caplib],[[libcap.a]])
 define([afplib],[[libafp.a]])
 define([afpclib],[[libafpc.a]])
# names to load cap libraries with
 define([libcap],concat(cwd,[[[/lib/libcap.a]]]))
 define([libafp],concat(cwd,[[[/lib/libafp.a]]]))
 define([libafpc],concat(cwd,[[[/lib/libafpc.a]]]))
 define([capprinters],concat([\"],etcdest,[/],[cap.printers],[\"]))
 define([cflags],concat(cflags,[ -I],includedir))
 define([atalklocal],concat([\"],etcdest,[/],[atalk.local],[\"]))
 define([etalklocal],concat([\"],etcdest,[/],[etalk.local],[\"]))
 define([configdir],concat([\"],etcdest,[\"]))
])

define([datestring],maketemp(/tmp/capcXXXXXX))
syscmd(date > datestring())
##########MARKER##########
# Makefile autoconfigured for ...
[#] osname() system on include(datestring())
syscmd(rm datestring())

MFLAGS=mflags()
LFLAGS=lflags()
CC=thecompiler()
LD=theloader()
SHELL=/bin/sh
INSTALLER=theinstaller()
EOT4
exec > /dev/tty
echo "${of} configured"
echo "Generate makefiles by typing: gen.makes (or sh gen.makes) from"
echo "the top level directory"
echo
echo "MAKE SURE YOU HAVE READ NOTES.  There are machine dependencies"
echo "that are not handled by Configure!!!!!"
echo
echo "Program configuration can be done by modifying ${of}"
echo "under the minor configuration parameters"
