#! /bin/sh
#
# If these # comments don't work, trim them.  Don't worry about any other
# shell scripts, Configure will trim # comments from them for you.
#
# (If you are trying to port this packasge to a machine without sh, I would
# suggest you cut out the prototypical config.h from the end of Configure
# and edit it to reflect your system.  Some packages may include samples
# of config.h for certain machines, so you might look for one of those.)
#
# $Header: /home/users/hurtta/cvsroot/mail/elmme+/Configure,v 2.102 2025/07/04 17:28:29 hurtta Exp $
#

: sanity checks
ORIG_PATH="$PATH"
PATH=".:$PATH:/bin:/usr/bin:/usr/sbin:/usr/sfw/bin:/usr/ccs/bin:/usr/local/bin:/usr/ucb:/usr/local:/usr/lbin:/etc:/usr/new:/usr/new/bin:/usr/nbin"
export PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh $0; kill $$)

start_dir="`pwd`"

X="`dirname $0`"
case "$X" in
    '')
    ;;
    .)
    ;;
    *)
    echo "Changing directory to $X ..."
    cd $X || exit 1
    ;;
esac
source_dir="`pwd`"
echo "Source directory: $source_dir"
build_dir="$start_dir"
 
fastread=''
extractsh=''
prefix=''
libsuffix=''
extradefs=''
batchmode=''
config=''
addg=''
fastextractsh=''

while test $# -gt 0; do
	case "$1" in
		-d) shift; fastread='yes';;
		-b) shift; batchmode='yes'
			   fastread='yes';;
		-S) shift; extractsh=true;;
		-SS) shift; extractsh=true
                            fastextractsh='exit 0';;
		-M) shift; extractsh=map;;
		-h) shift; error=true;;
	        -g) shift; addg=-g;;
		-D*)
		    if test "$extradefs" = "" ; then
			extradefs="$1"
		    else
			extradefs="$extradefs $1"
		    fi
		    shift
		    ;;
		-P*)
		    prefix="`expr \"$1\" : '-P\(.*\)'`"
		    shift
		    case "$prefix" in
			"")
			prefix="$1"
			shift
			;;
		    esac
       		    echo "Prefix: $prefix"
		;;
		-s*)
		    libsuffix="`expr \"$1\" : '-s\(.*\)'`"
		    shift
		    case "$libsuffix" in
			"")
			libsuffix="$1"
			shift
			;;
		    esac
       		    echo "Extra library suffix: $libsuffix"
		;;
		-c*)
		    config="`expr \"$1\" : '-c\(.*\)'`"
		    shift
		    case "$config" in
			"")
			config="$1"
			shift
			;;
		    esac
		;;
	        -O-)
		   A="`uname -sn`" || exit 1
		   test "$A" = "" && exit 1
                   A="`echo \"$A\" | sed 's/ /-/;'`" || exit 1
		   test "$A" = "" && exit 1
		   build_dir="BUILD-$A"
		   shift
		   ;;
		-O*)
		    build_dir="`expr \"$1\" : '-O\(.*\)'`"
		    shift
		    case "$build_dir" in
			"")
			build_dir="$1"
			shift
			;;
		    esac
		;;


		-*) echo "Configure: unknown option $1" >&2; shift; error=true;;
		*) break;;
	esac
done

case "$batchmode" in
    yes)
    ;;
    *)
    if test ! -t 0; then
	echo "Say 'sh Configure', not 'sh <Configure'" >&2
	exit 1
    fi
    ;;
esac

if test "$config" != "" ; then
    case "$config" in
	/*)
	    if test ! -f "$config" ; then
	       echo "File $config is not readable" >&2
	       error=true       
	    fi

	    ;;
	*)
	    A="$start_dir/$config"

	    if test ! -f "$A" ; then
	       echo "File $config ($A) is not readable" >&2
	       error=true
	    else
	       config="$A"
	    fi
	    ;;
     esac	
fi

case "$error" in
true)
    cat >&2 << EOM
Usage: Configure [-dSbhSMN] [-P'prefix'] [-s'suffix'] [-c'config'] [-DDEBUG] [-O'object_dir']
  -d : use defaults for all answers.
  -b : batchmode -- do not prompt user (implies -d)
  -h : print this help message and exit (with an error status).
  -S : perform variable substitutions on all .SH files and
       generate bin/elm.mimecharsets, bin/elm.terminalinfo,
       bin/elm.mimetypes, bin/elm.mailinglists,
       bin/elm.aliases, bin/elm.mailservices, bin/elm.iso2022sets,
       bin/elm.tagfilter.entities
  -M : generate bin/elm.mimecharsets, bin/elm.terminalinfo,
       bin/elm.mimetypes, bin/elm.mailinglists,
       bin/elm.aliases, bin/elm.mailservices, bin/elm.iso2022sets,
       bin/elm.tagfilter.entities
  -O'object_dir' : use as build directory 
  -P'prefix' : use as installation prefix (for example /usr/local)
  -s'suffix' : use as extra version suffix for shared libraries
  -c'config' : Read file 'config' instead of config.sh (NOTE: config.sh is still written)
  -DDEBUG : Compile with debugging
  -g : Compile with debugging symbols
EOM

   A="`uname -sn`" || exit 1
   test "$A" = "" && exit 1
   A="`echo \"$A\" | sed 's/ /-/;'`" || exit 1
   test "$A" = "" && exit 1
   XXX="BUILD-$A"

    cat >&2 << EOM
  -O- : use $XXX as build directory 
EOM

    exit 1
    ;;
esac

case "$build_dir" in
    /*)
	;;
    *)
	build_dir="$start_dir/$build_dir"
	;;
esac
echo "Build directory: $build_dir"

if test ! -d "$build_dir" ; then
        echo "Making $build_dir directory"
	mkdir "$build_dir" || exit 1
fi

if test ! -d "$build_dir/UU"; then
   mkdir "$build_dir/UU" || exit 1
fi
cd "$build_dir/UU" || exit 1
UU="`pwd`"

: check for out bin directory
if test ! -d "$build_dir/bin"; then
    echo "Making $build_dir/bin directory"
    mkdir "$build_dir/bin" || exit 1
else
    echo "Found $build_dir/bin directory"
fi

if test ! -d "$build_dir/libs"; then
    echo "Making $build_dir/libs directory"
    mkdir "$build_dir/libs" || exit 1
else
    echo "Found $build_dir/libs directory"
fi


case "$extractsh" in
true)

    cd "$build_dir"  || exit 1;

    if test "$config" != "" ; then
	echo "Copying file $config to config.sh"
	cp $config config.sh || exit 1
    fi


    d_sharedtag="`grep SHAREDTAG: $source_dir/hdrs/patchlevel.h | cut -d' ' -f2`"
    cat >>config.sh <<EOT
d_sharedtag='$d_sharedtag'
EOT
        echo "Changing version tag to $d_sharedtag"
   
    if test "$libsuffix" != "" ; then
	case "$libsuffix" in
	    .*)
	    d_shared_rev="$d_sharedtag$libsuffix"
	    ;;
	    *)
	    d_shared_rev="$d_sharedtag.$libsuffix"
	    ;;
        esac
	
	cat >>config.sh <<EOT
d_shared_rev='$d_shared_rev'
EOT
	echo "Changing shared library name to libelmme-base.so$d_shared_rev"
    fi
   
    if test "$extradefs" != "" ; then
	. config.sh

	ccflags="$ccflags $extradefs"
	cppflags="$cppflags $extradefs"
	
	cat >>config.sh <<EOT
ccflags='$ccflags'
cppflags='$cppflags'
EOT
	echo "Setting ccflags to $ccflags"
	echo "Setting cppflags to $cppflags"
    fi

    if test "$addg" != "" ; then
	. config.sh

	optimize="$optimize $addg"
	ldflags="$ldflags $addg"

	cat >>config.sh <<EOT
optimize='$optimize'
ldflags='$ldflags'
EOT

	echo "Setting optimize to $optimize"
	echo "Setting ldflags to $ldflags"
    fi

    . "$source_dir/ConfTool/Substitute"

    $fastextractsh

    if $test "$d_shared" = "$define" ; then
	if test ! -d shlib; then
	    echo "Making shlib directory"
	    mkdir shlib
	else
	    echo "Found shlib directory"
	fi
    fi

    nomap=
    if [ "$have_codeset" = "$define" ] ; then
	$cat <<EOF
Because nl_langinfo(CODESET) is supported,
$lib/elm.mimecharsets need not include mapping
definations from locale to charset. 

EOF
	nomap=y
    fi

    . "$source_dir/ConfTool/GenCharmap"

    . "$source_dir/ConfTool/GenIso2022sets"

    . "$source_dir/ConfTool/GenTerminalinfo"

    . "$source_dir/ConfTool/GenMimetypes"

    . "$source_dir/ConfTool/GenMailinglists"
 
    . "$source_dir/ConfTool/GenAliases"

    . "$source_dir/ConfTool/GenMailServices"

    . "$source_dir/ConfTool/GenHashMarks"

    . "$source_dir/ConfTool/GenEntities"

    
    exit 0
    ;;
map)
    cd "$build_dir"  || exit 1;

    if test "$config" != "" ; then
        echo "WARNING:  Combination -M -c config is not supported" >&2
	echo "Reading $config instead of config.sh"
	. "$config"
    else
	. ./config.sh
    fi

    nomap=
    if [ "$have_codeset" = "$define" ] ; then
	$cat <<EOF
Because nl_langinfo(CODESET) is supported,
$lib/elm.mimecharsets need not include mapping
definations from locale to charset. 

EOF
	nomap=y
    fi
    . "$source_dir/ConfTool/GenCharmap"

    . "$source_dir/ConfTool/GenIso2022sets"

    . "$source_dir/ConfTool/GenTerminalinfo"

    . "$source_dir/ConfTool/GenMimetypes"

    . "$source_dir/ConfTool/GenMailinglists"

    . "$source_dir/ConfTool/GenAliases"

    . "$source_dir/ConfTool/GenMailServices"
 
    . "$source_dir/ConfTool/GenHashMarks"

    . "$source_dir/ConfTool/GenEntities"

    exit 0
    ;;
esac

Log=''
Header=''
bin=''
contains=''
cppstdin=''
cppminus=''
diff=''
ascii_codeset=''
d_getopt=''
d_getopt_type=''
d_memcpy=''
d_symlink=''
d_whoami=''
d_poll=''
i_sys_select=''
i_sysexits=''
i_stdint=''
d_select=''
d_mmap=''
d_have_int128=''
d_have_socket=''
d_have_soerror=''
d_have_getsockname=''
getsockname_socklen=''
i_netinet_in=''
d_have_in6=''
d_have_scope=''
d_ipv6_scope_id=''
scope_id_default=''
d_ifaddrs=''
d_usegetifaddrs=''
i_arpa_inet=''
i_net_if=''
d_nameindex=''
d_use_aton=''
d_use_xtox_pn=''
i_netdb=''
d_addrinfo=''
d_addrconfig=''
d_getnameinfo=''
d_directory=''
d_directyry_type=''
i_inttypes=''
d_nointtypes=''
d_setlinebuf=''
d_shared=''
d_shared_rev=''
d_dlopen_libs=''
shared_list=''
shared_register=''
dlopen_lib=''
rpath_opt=''
rpath_ok=''
soname_opt=''
soname_include_path=''
soname_ok=''
dynamic_opt=''
d_dynamic_main=''
have_codeset=''
install_prefix=''
n=''
c=''
orderlib=''
ranlib=''
ar=''
nm=''
package=''
pager=''
use_builtin_pager=''
startsh=''
define=''
loclist=''
expr=''
sed=''
echo=''
cat=''
rm=''
mv=''
cp=''
tail=''
tr=''
sort=''
uniq=''
grep=''
fgrep=''
head=''
trylist=''
test=''
inews=''
ispell=''
egrep=''
more=''
pg=''
Mcc=''
vi=''
cpp=''
perl=''
emacs=''
ls=''
rmail=''
sendmail=''
shar=''
smail=''
submit=''
tbl=''
troff=''
gtroff=''
nroff=''
uname=''
uuname=''
line=''
chgrp=''
chmod=''
lint=''
sleep=''
pr=''
tar=''
ln=''
lpr=''
lp=''
touch=''
make=''
date=''
csh=''
pmake=''
mips=''
col=''
pack=''
compress=''
execmail=''
libswanted=''
c_date=''
d_ascii=''
d_backtrace=''
backtrace_opt=''
d_broke_ctype=''
d_calendar=''
calendar=''
d_chown_neg1=''
d_content=''
d_crypt=''
i_crypt=''
cryptlib=''
d_disphost=''
d_domname=''
d_usegetdom=''
d_errlst=''
d_flock=''
d_dotlock=''
d_fcntlock=''
has_flock=''
has_fcntl=''
d_compile_flock=''
d_compile_fcntl=''
d_ftruncate=''
d_gethname=''
d_douname=''
ign_hname=''
d_havetlib=''
termlib=''
i_curses=''
i_term=''
d_index=''
d_ispell=''
ispell_path=''
ispell_options=''
i_locale=''
i_nl_types=''
d_mailname=''
mailname_file=''
d_usemailname=''
d_msgcat=''
d_mallocvoid=''
d_mboxedit=''
metamail_path=''
metamail=''
d_8bitmime=''
d_binarymime=''
d_dsn=''
defsystemcharset=''
d_mmdf=''
d_newauto=''
d_noaddfrom=''
d_usedomain=''
d_noxheader=''
d_pidcheck=''
d_ptem=''
d_putenv=''
maxattempts=''
d_setgid=''
mailermode=''
d_sigvec=''
d_sigvectr=''
d_sigset=''
d_sighold=''
d_sigprocmask=''
d_sigblock=''
d_sigaction=''
d_strcspn=''
d_strspn=''
d_strpbrk=''
d_strerror=''
d_strftime=''
d_mktime=''
d_getusershell=''
d_strings=''
d_pwdinsys=''
d_waitpid=''
strings=''
includepath=''
d_strstr=''
d_strtok=''
d_subshell=''
d_tempnam=''
tempnamo=''
tempnamc=''
d_termio=''
d_termios=''
d_utimbuf=''
d_vfork=''
defbatsub=''
defeditor=''
editoropts=''
phostname=''
mydomain=''
d_dummydomain=''
dummydomain=''
autohostname=''
fmsgiddomain=''
d_msgiddomain=''
i_memory=''
i_time=''
i_systime=''
s_timeval=''
d_systimekernel=''
d_gettimeofday=''
suseconds=''
d_suseconds=''
d_clock_gettime=''
i_unistd=''
i_utime=''
i_sysutime=''
lib=''
etc=''
stage_dir=''
build_package=''
libdirname=''
shlib=''
libc=''
linepr=''
maildir=''
mailer=''
mailer_bv_ok=''
mailgrp=''
mansrc=''
catmansrc=''
manext=''
manext_choice=''
catmanext=''
catmanext_choice=''
packed=''
manroff=''
manroffopts=''
suffix=''
packer=''
optimize=''
ccflags=''
picflag=''
nopic=''
cppflags=''
ldflags=''
cc=''
libs=''
noaddlib=''
nametype=''
d_passnames=''
d_berknames=''
d_usgnames=''
rmttape=''
sigtype=''
spitshell=''
shsharp=''
sharpbang=''
tmpdir=''
tzname_handling=''
use_pmake=''
make_sets_make=''
xencf=''
xenlf=''
d_xenix=''
d_bsd=''
locale=''
d_pgp=''
pgp=''
gpg=''
pgp2_path=''
pgp5_dir=''
gpg_path=''
special_path=''
special_path2=''
dirname=''
locale_dir=''
d_wchar=''
d_wcwidth=''
CONFIG=''
: set package name
package=elmme+2.5

echo " "
echo "Beginning of configuration questions for $package kit."
echo " "

define='define'
undef='undef'
: change the next line if compiling for Xenix/286 on Xenix/386
xlibpth='/usr/lib/386 /lib/386 /lib'
libpth='/usr/lib /usr/ccs/lib /usr/local/lib /usr/lib/large /lib '$xlibpth' /lib/large /usr/lib/small /lib/small'
smallmach='pdp11 i8086 z8000 i80286 iAPX286'
rmlist='kit[1-9]isdone kit[1-9][0-9]isdone'
trap 'echo " "; rm -f $rmlist; exit 1' 1 2 3

: Now test for existence of everything in MANIFEST

if test ! -f "$source_dir/MANIFEST" ; then
    echo "$source_dir/MANIFEST not found ..."
    exit 1
fi

echo "First let's make sure your kit is complete.  Checking..."
if awk '$1 !~ /PACKINGLIST/ {print $1}' "$source_dir/MANIFEST" | split -100
then
   
    rm -f $UU/missing
    for filelist in x??; do
	(cd "$source_dir"; ls `cat "$UU/$filelist"` >/dev/null 2>>$UU/missing)
    done
    if test -s $UU/missing; then
	cat $UU/missing
	kill $$
    fi
    echo "Looks good..."
else
    echo "Failed to process $source_dir/MANIFEST"
    exit 1
fi

: Do one time items.....

for file in OneTime.PL* ; do
	if test -f "$file" ; then
		echo "Executing patch cleanup script $file . . ."
		. ./$file
	fi
done

attrlist="mc68000 sun gcos unix ibm gimpel interdata tss os mert pyr"
attrlist="$attrlist vax pdp11 i8086 z8000 u3b2 u3b5 u3b20 u3b200"
attrlist="$attrlist hpux hp9000s300 hp9000s500 hp9000s800"
attrlist="$attrlist ns32000 ns16000 iAPX286 mc300 mc500 mc700 sparc"
attrlist="$attrlist nsc32000 sinix xenix venix posix ansi M_XENIX"
attrlist="$attrlist $mc68k __STDC__ UTS M_I8086 M_I186 M_I286 M_I386"
attrlist="$attrlist i186 __m88k__ m88k DGUX __DGUX__ NeXT _AIX ultrix"
attrlist="$attrlist sgi linux"
pth="/bin /usr/bin /usr/ucb /sbin /usr/sbin /usr/local /usr/local/bin /usr/lbin"
pth="$pth /usr/5bin /vol/local/bin /etc /usr/bsd /usr/lib /usr/ccs/lib /usr/ccs/bin /lib"
pth="$pth /usr/local/lib /sys5.3/bin /sys5.3/usr/bin /bsd4.3/bin /bsd4.3/usr/bin /bsd4.3/usr/ucb"
pth="$pth /usr/convex /usr/mmdf/bin /usr/mmdf/lib /usr/lib/mail"
pth="$pth ${BSDBASE-/bsd}/usr/ucb ${BSDBASE-/bsd}/bin ${BSDBASE-/bsd}/usr/bin"


: some greps do not return status, grrr.
echo "grimblepritz" >grimble
if grep blurfldyick grimble >/dev/null 2>&1 ; then
    contains=contains
elif grep grimblepritz grimble >/dev/null 2>&1 ; then
    contains=grep
else
    contains=contains
fi
rm -f grimble
: the following should work in any shell
case "$contains" in
contains*)
    echo " "
    echo "AGH!  Grep doesn't return a status.  Attempting remedial action."
    cat >contains <<'EOSS'
grep "$1" "$2" >.greptmp && cat .greptmp && test -s .greptmp
EOSS
chmod +x contains
esac

: see if sh knows # comments
echo " "
echo "Checking your sh to see if it knows about # comments..."
if sh -c '#' >/dev/null 2>&1 ; then
    echo "Your sh handles # comments correctly."
    shsharp=true
    spitshell=cat
    echo " "
    echo "Okay, let's see if #! works on this system..."
    e=/bin/echo; test -f $e || e=/usr/bin/echo
    echo "#!$e hi" > try
    chmod +x try
    ./try > today
    if $contains hi today >/dev/null 2>&1; then
	echo "It does."
	sharpbang='#!'
    else
	echo "#! $e hi" > try
	chmod +x try
	./try > today
	if test -s today; then
	    echo "It does."
	    sharpbang='#! '
	else
	    echo "It doesn't."
	    sharpbang=': use '
	fi
    fi
else
    echo "Your sh doesn't grok # comments--I will strip them later on."
    shsharp=false
    echo "exec grep -v '^#'" >spitshell
    chmod +x spitshell
    spitshell=`pwd`/spitshell
    echo "I presume that if # doesn't work, #! won't work either!"
    sharpbang=': use '
fi

: figure out how to guarantee sh startup
echo " "
echo "Checking out how to guarantee sh startup..."
startsh=$sharpbang'/bin/sh'
echo "Let's see if '$startsh' works..."
cat >try <<EOSS
$startsh
set abc
test "$?abc" != 1
EOSS

chmod +x try
if ./try; then
    echo "Yup, it does."
else
    echo "Nope.  You may have to fix up the shell scripts to make sure sh runs them."
fi
rm -f try today

: first determine how to suppress newline on echo command
echo "Checking echo to see how to suppress newlines..."
(echo "hi there\c" ; echo " ") >.echotmp
if $contains c .echotmp >/dev/null 2>&1 ; then
    echo "...using -n."
    n='-n'
    c=''
else
    cat <<'EOM'
...using \c
EOM
    n=''
    c='\c'
fi

case "$batchmode" in
    yes)
    ;;
    *)
    echo $n "Type carriage return to continue.  Your cursor should be here-->$c"
    read ans
    ;;
esac
rm -f .echotmp

: now set up to do reads with possible shell escape and default assignment
cat <<EOSC >myread
case "\$fastread" in
yes) ans=''; echo " " ;;
*) ans='!';;
esac
while expr "X\$ans" : "X!" >/dev/null; do
    read ans
    case "\$ans" in
    !)
	sh
	echo " "
	echo $n "\$rp $c"
	;;
    !*)
	set \`expr "X\$ans" : "X!\(.*\)\$"\`
	sh -c "\$*"
	echo " "
	echo $n "\$rp $c"
	;;
    esac
done
rp='Your answer:'
case "\$ans" in
'') ans="\$dflt";;
esac
EOSC

: general instructions
cat <<EOH
 
This installation shell script will examine your system and ask you questions
to determine how the $package package should be installed.  If you get stuck
on a question, you may use a ! shell escape to start a subshell or execute
a command.  Many of the questions will have default answers in square
brackets--typing carriage return will give you the default.

On some of the questions which ask for file or directory names you are
allowed to use the ~name construct to specify the login directory belonging
to "name", even if you don't have a shell which knows about that.  Questions
where this is allowed will be marked "(~name ok)".

EOH
rp="[Type carriage return to continue]"
echo $n "$rp $c"
. myread
cat <<EOH

Much effort has been expended to ensure that this shell script will run
on any Unix system.  If despite that it blows up on you, your best bet is
to edit Configure and run it again. 

This installation script affects things in two ways: 1) it may do direct
variable substitutions on some of the files included in this kit, and
2) it builds a config.h file for inclusion in C programs.  You may edit
any of these files as the need arises after running this script.

If you make a mistake on a question, there is no easy way to back up to it
currently.  The easiest thing to do is to edit config.sh and rerun all the
SH files.  Configure will offer to let you do this before it runs the SH files.

EOH
rp="[Type carriage return to continue]"
echo $n "$rp $c"
. myread

save_package="$package"
if test "$config" != "" ; then
    echo "Fetching default answers from your old $config file..."
    . "$config"

: get old answers, if there is a config file out there
elif test -f "$build_dir/config.sh"; then
    echo " "
    dflt=y
    rp="I see a config.sh file.  Did Configure make it on THIS system? [$dflt]"
    echo $n "$rp $c"
    . myread
    case "$ans" in
    n*) echo "OK, I'll ignore it.";;
    *)  echo "Fetching default answers from your old config.sh file..."
	tmp="$n"
	ans="$c"
        . "$build_dir/config.sh"
	n="$tmp"
	c="$ans"
	;;
    esac
fi

if test "$save_package" != "$package" ; then

	echo
	echo "WARNING!  Saved configuration is for $package and not for $save_package"
	echo
	sleep 5

	: FIX paths
	stage_dir="`echo \"$stage_dir\" | sed \"s/$package/$save_package/\"`"

	package="$save_package"
fi

cat <<EOH
 
If you want Configure to search programs from some unusual directory first, 
you can give it on here. Give "none" if no any special directory exists or
if do want search special path as last resort. If you want specify several 
directories, seperate them with space.

EOH

case "$special_path" in
    '') 	
     saved="$IFS"
     dflt='none'
     IFS=":$IFS"
     for zz in $PATH; do
	case "$zz" in
	    $HOME*)	    
	    ;;
	    ''|.)
	    ;;
	    /*)
	    dflt="$zz"	    
	    break
	    ;;
	esac
    done

    IFS="$saved"
    ;;
    *) dflt="$special_path"
    ;;
esac

rp="Special directory from where search programs first? [$dflt]"

echo $n "$rp $c"
. myread

special_path="$ans"
case "$special_path" in
    none)
	echo
	;;
    *)
        pth="$special_path $pth"
	;;
esac

cat <<EOH
 
If you want Configure to search programs from some unusual directory as last 
resort. If you want specify several directories, seperate them with space.
Give "none" if no any special directory exists.

EOH



case "$special_path2" in
    '') 	
     dflt=none
     saved="$IFS"
     IFS=":$IFS"
     for zz in $ORIG_PATH; do
	case "$zz" in
	    $HOME*)	    
	    ;;
	    ''|.)
	    ;;
	    /*)
	    dflt="$zz"
	    ;;
	esac
    done

    IFS="$saved"
    ;;
    *) dflt="$special_path2"
    ;;
esac


rp="Special directory from where search programs last? [$dflt]"

echo $n "$rp $c"
. myread

special_path2="$ans"
case "$special_path2" in
    none)
	echo
	;;
    *)
        pth="$pth $special_path2"
	;;
esac

: find out where common programs are
echo " "
echo "Locating common programs..."
cat <<EOSC >loc
$startsh
case \$# in
0) exit 1;;
esac
thing=\$1
shift
dflt=\$1
shift
for dir in \$*; do
    case "\$thing" in
    .)
	if test -d \$dir/\$thing; then
	    echo \$dir
	    exit 0
	fi
	;;
    *)
	if test -f \$dir/\$thing; then
	    echo \$dir/\$thing
	    exit 0
	fi
	;;
    esac
done
echo \$dflt
exit 1
EOSC
chmod +x loc
loclist="
basename
cat
chgrp
chmod
cp
dirname
echo
expr
egrep
grep
fgrep
head
ln
ls
make
mv
rm
sed
sleep
sort
diff
touch
tr
uniq
cut
ar
"
trylist="
Mcc
compress
cpp
date
diff
emacs
execmail
gencat
gpg
ispell
line
lint
lp
locale
lpr
metamail
mips
more
nroff
pack
pg
pgp
pmake
pr
rmail
sendmail
shar
smail
submit
tar
tbl
test
troff
gtroff
uname
uuname
vi
nm
"
for file in $loclist; do
    xxx=`loc $file $file $pth`
    eval $file=$xxx
    eval _$file=$xxx
    case "$xxx" in
    /*)
	echo $file is in $xxx.
	;;
    *)
	echo "I don't know where $file is.  I hope it's in everyone's PATH."
	;;
    esac
done
echo " "
echo "Don't worry if any of the following aren't found..."
ans=offhand
for file in $trylist; do
    xxx=`loc $file $file $pth`
    eval $file=$xxx
    eval _$file=$xxx
    case "$xxx" in
    /*)
	echo $file is in $xxx.
	;;
    *)
	echo "I don't see $file out there, $ans."
	ans=either
	;;
    esac
done
case "$egrep" in
egrep)
    echo "Substituting grep for egrep."
    egrep=$grep
    ;;
esac
case "$test" in
test)
    echo "Hopefully test is built into your sh."
    ;;
/bin/test)
    if sh -c "PATH= test true" >/dev/null 2>&1; then
	echo "Using the test built into your sh."
	test=test
    fi
    ;;
*)
    test=test
    ;;
esac
case "$echo" in
echo)
    echo "Hopefully echo is built into your sh."
    ;;
/bin/echo)
    echo " "
    echo "Checking compatibility between /bin/echo and builtin echo (if any)..."
    $echo $n "hi there$c" >foo1
    echo $n "hi there$c" >foo2
    if cmp foo1 foo2 >/dev/null 2>&1; then
	echo "They are compatible.  In fact, they may be identical."
    else
	case "$n" in
	'-n') n='' c='\c' ans='\c' ;;
	*) n='-n' c='' ans='-n' ;;
	esac
	cat <<FOO
They are not compatible!  You are probably running ksh on a non-USG system.
I'll have to use /bin/echo instead of the builtin, since Bourne shell doesn't
have echo built in and we may have to run some Bourne shell scripts.  That
means I'll have to use $ans to suppress newlines now.  Life is ridiculous.

FOO
	rp="Your cursor should be here-->"
	$echo $n "$rp$c"
	. myread
    fi
    $rm -f foo1 foo2
    ;;
*)
    : cross your fingers
    echo=echo
    ;;
esac
rmlist="$rmlist loc"

: see if date exists, if so, init c_date
if $test ! "x$date" = "x" ; then
    c_date=`LANG= LC_TIME= $date`
else
    c_date='date was unavailable at configuration'
fi

if $test -n "$prefix"; then
    if $test ! -d "$prefix" ; then
	echo "Installation prefix directory $prefix does not exist"
	exit 1
    fi
    case "$prefix" in
	/*)
	    echo "Installation prefix directory is $prefix"
	;;
	*)
	    echo "Installation prefix directory $prefix is not absolute"
	    exit 1
	;;
    esac
fi

: get calendar mode and default calendar file name
$cat <<EOM

There is a neat feature that enables scanning of the message body for
entries to add to the users ".calendar" (or whatever) file.  These
entries are then processed by the system program calendar.  To use
this feature it needs to be enabled.  The name of the per user calendar
file used by your system's calendar program is also required.
EOM

case "$d_calendar" in
"$define") dflt=y;;
"$undef")  dflt=n;;
*)	   dflt=y;;
esac

rp="Enable calendar feature [$dflt]"
$echo $n "$rp $c"
. myread
case "$ans" in
y*) d_calendar="$define";;
*)  d_calendar="$undef";;
esac

case "$calendar" in
    '') dflt='calendar';;
    *)  dflt=$calendar;;
esac

if $test "$d_calendar" = "$define"; then
	echo " "
	rp="Default calendar file: [$dflt]"
	$echo $n "$rp $c"
	. myread
	calendar="$ans"
fi

: make some quick guesses about what we are up against
echo " "
$echo $n "Hmm...  $c"
if $test -f "$uname"; then
    uname_os=`$uname -s`
    uname_rel=`$uname -r`
    uname_rel=`expr "$uname_rel" : "\(...\).*"`
else
    uname_os=unknown
    uname_rel=unknown
fi
echo " $uname_os $uname_rel."
case "$uname_os" in
  Linux)
    libswanted=""
  ;;

  SunOS)
    case "$uname_rel" in
      5.*)
        libswanted="sun intl socket nsl c_s"
        ;;
      *)
        libswanted="sun intl nls c_s"
        ;;
     esac
     ;;
  FreeBSD)
     libswanted="sun nls c_s"
    ;;
  IRIX*)
	case "$uname_rel" in
	6*)
		libswanted=""
		;;
	*)
		libswanted="sun intl nls c_s"
		;;
	esac
	;;
  *)
     libswanted="sun intl nls c_s"
     ;;
esac

cat /usr/include/signal.h /usr/include/sys/signal.h >foo 2>/dev/null
if test `echo abc | tr a-z A-Z` = Abc ; then
    echo "Looks kind of like a USG system, but we'll see..."
    echo exit 1 >bsd
    echo exit 0 >usg
    echo exit 1 >v7
elif $contains SIGTSTP foo >/dev/null 2>&1 ; then
    if $test "(" "$uname_os" = "SunOS" -a "$uname_rel" = "4.1" ")" ; then
	echo "Looks like SunOs 4.1, a USG system"
	echo exit 1 >bsd
	echo exit 0 >usg
	echo exit 1 >v7
    elif $test "$uname_os" = "OSF1" ; then
	echo "Looks like an OSF/1 system"
	echo exit 1 >bsd
	echo exit 1 >usg
	echo exit 1 >v7
    elif $test "$uname_os" = "HP-UX" ; then
	echo "Looks like an HP-UX system"
	echo exit 1 >bsd
	echo exit 0 >usg
	echo exit 1 >v7
    elif $test "$uname_os" = "IRIX" -o "$uname_os" = "IRIX64" ; then
    : test `echo abc | tr a-z A-Z` = Abc does not work in IRIX 6.2
	echo "Looks like an IRIX system"
	echo exit 1 >bsd
	echo exit 1 >usg
	echo exit 1 >v7
    else
	echo "Looks kind of like a BSD system"
	echo exit 0 >bsd
	echo exit 1 >usg
	echo exit 1 >v7
    fi
else
    echo "Looks kind of like a version 7 system, but we'll see..."
    echo exit 1 >bsd
    echo exit 1 >usg
    echo exit 0 >v7
fi

if test -f /xenix; then
    echo "Actually, this looks more like a XENIX system..."
    echo "exit 0" >xenix
else
    echo " "
    echo "It's not Xenix..."
    echo "exit 1" >xenix
fi
chmod +x xenix
if test -f /venix; then
    echo "Actually, this looks more like a VENIX system..."
    echo "exit 0" >venix
else
    echo " "
    if xenix; then
	: null
    else
	echo "Nor is it Venix..."
    fi
    echo "exit 1" >venix
fi
chmod +x bsd usg v7 venix
rm -rf foo
rmlist="$rmlist bsd usg v7 venix xenix"

: find out how to find out full name
echo " "
case "$d_berknames" in
"$define")
    dflt=y;;
"$undef")
    dflt=n;;
*)
    if bsd; then
	dflt=y
    elif xenix; then
	dflt=y
    elif $test "$uname_os" = "IRIX" -o "$uname_os" = "IRIX64"; then
        dflt=y
    elif $test "$uname_os" = "SunOS"; then
        dflt=y
    elif $test "$uname_os" = "Linux"; then
        dflt=y
    elif $test "$uname_os" = "OSF1"; then
        dflt=y
    else
	dflt=n
    fi
    ;;
esac
echo "Does your /etc/passwd file keep full names in Berkeley/V7 format (name first"
$echo $n "thing after ':' in GCOS field)? [$dflt] $c"
rp="Berkeley/V7 format full name? [$dflt]"
. myread
case "$ans" in
  y*)
    d_passnames="$define"
    d_berknames="$define"
    d_usgnames="$undef"
    nametype=bsd
    ;;
  *)
    echo " "
    case "$d_usgnames" in
    "$define")
	dflt=y;;
    "$undef")
	dflt=n;;
    *)
	if usg; then
	    dflt=y
	else
	    dflt=n
	fi
	;;
    esac
    echo "Does your passwd file keep full names in USG format (name sandwiched"
    $echo $n "between a '-' and a '(')? [$dflt] $c"
    rp="USG format full name? [$dflt]"
    . myread
    case "$ans" in
      n*)
	echo "Full name will be taken from ~/.fullname"
	d_passnames="$undef"
	d_berknames="$undef"
	d_usgnames="$undef"
	nametype=other
	;;
      *)
	d_passnames="$define"
	d_berknames="$undef"
	d_usgnames="$define"
	nametype=usg
	;;
    esac
    ;;
esac

: set up shell script to do ~ expansion
cat >filexp <<EOSS
$startsh
: expand filename
case "\$1" in
 ~/*|~)
    echo \$1 | $sed "s|~|\${HOME-\$LOGDIR}|"
    ;;
 ~*)
    if $test -f /bin/csh; then
	/bin/csh -f -c "glob \$1"
	echo ""
    else
	name=\`$expr x\$1 : '..\([^/]*\)'\`
	dir=\`$sed -n -e "/^\${name}:/{s/^[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\).*"'\$'"/\1/" -e p -e q -e '}' </etc/passwd\`
	if $test ! -d "\$dir"; then
	    me=\`basename \$0\`
	    echo "\$me: can't locate home directory for: \$name" >&2
	    exit 1
	fi
	case "\$1" in
	*/*)
	    echo \$dir/\`$expr x\$1 : '..[^/]*/\(.*\)'\`
	    ;;
	*)
	    echo \$dir
	    ;;
	esac
    fi
    ;;
*)
    echo \$1
    ;;
esac
EOSS
chmod +x filexp

: default clear to no extra flags
xencf=
xenlf=
d_xenix="$undef"
d_bsd="$undef"
: see if we are xenix 
if xenix; then
    d_xenix="$define"
:	now are we a 286
    case "`$uname -p`" in
	i80286) 
		xencf="-LARGE -Ml2et32"
		xenlf="-Ml2t32 -F 5600 -SEG 512"
      esac
fi
if bsd; then
    d_bsd="$define"
fi

: see if we need a special compiler
case "$cc" in
    '') dflt=cc;;
    *) dflt="$cc";;
    esac
    rp="Use which C compiler? [$dflt]"
    $echo $n "$rp $c"
    . myread
    cc="$ans"
case "$cc" in
gcc*) cpp=`loc gcc-cpp $cpp $pth`;;
esac

: determine optimize, if desired, or use for debug flag also
case "$optimize" in
' ') case "$addg" in
       '') dflt="none"
       ;;
       *) dflt="$addg"
       ;;
     esac
     ;;
'') dflt="-O $addg";
    ;;
*$addg*)
    dflt="$optimize"
    ;;
*)  dflt="$optimize $addg"
    ;;
esac
cat <<EOH

Some C compilers have problems with their optimizers, by default, $package
compiles with the -O flag to use the optimizer.  Alternately, you might
want to use the symbolic debugger, which uses the -g flag (on traditional
UNIX systems).  Either flag can be specified here.  To use neither flag,
specify the word "none".
  
The -O flag is disabled if that interferences with backtrace() function

EOH
rp="What optimizer/debugger flag should be used? [$dflt]"
$echo $n "$rp $c"
. myread
optimize="$ans"
case "$optimize" in
'none') optimize=" "
     ;;
esac

case "$ccflags" in
    '') case "$cc" in
	*gcc*) 
	    dflt='-fpcc-struct-return'
	    ;;
	*) 
	    dflt=''
	    if test "$uname_os" = "OSF1"; then
		dflt='-std'
	    fi
	    ;;
	esac
	if $test "$uname_os" = "Linux" -a -d /usr/i386-glibc20-linux/include 
	then
	    dflt="-I/usr/include -I/usr/i386-glibc20-linux/include $dflt"
	fi
	;;
	*) 
	    dflt="$ccflags"
	;;
esac

case "$dflt" in
    *$extradefs*)
	;;
    *)
	dflt="$dflt $extradefs"
	;;
esac

for thisincl in $inclwanted; do
    if test -d $thisincl; then
	case "$dflt" in
	*$thisincl*);;
	*) dflt="$dflt -I$thisincl";;
	esac
    fi
done
case "$optimize" in
-g*)
    case "$dflt" in
    *DEBUG*);;
    *) dflt="$dflt -DDEBUG";;
    esac
    ;;
esac
case "$dflt" in
'') dflt=none;;
esac
if $test -n "$xencf" ; then
    $echo "Xenix 286 system, using compiler flags $xencf"
    $echo "do not respecify these flags below."
    $echo ""
fi
cat <<EOH

Your C compiler may want other flags.  For this question you should
include -I/whatever and -DWHATEVER flags and any other flags used by
the C compiler, but you should NOT include libraries or ld flags like
-lwhatever.  To use no flags, specify the word "none".
  
EOH
rp="Any additional cc flags? [$dflt]"
$echo $n "$rp $c"
. myread
case "$ans" in
none) ans='';
esac
ccflags="$ans"

: the following weeds options from ccflags that are of no interest to cpp
cppflags="$ccflags"
case "$cc" in
*gcc*) cppflags="$cppflags -D__GNUC__";;
esac
case "$cppflags" in
'');;
*)  set X $cppflags
    cppflags=''
    for flag
    do
	case $flag in
	-D*|-I*|-U*) cppflags="$cppflags $flag";;
	esac
    done
    case "$cppflags" in
    *-*)  echo "(C preprocessor flags: $cppflags)";;
    esac
    ;;
esac

if $test -n "$xenlf" ; then
    $echo "Xenix 286 system, using linker flags $xenlf"
    $echo "do not respecify these flags below"
    $echo ""
fi
case "$ldflags" in
'') case "$addg" in
    '') 
      if venix; then
	  dflt='-i -z'
      else
	  dflt='none'
      fi
      ;;
    *)
      dflt="$addg"
      ;;
    esac
    ;;
*$addg*) dflt="$ldflags";;
*)     dflt="$ldflags $addg";;
esac
cat <<EOH

Your linker/loader may want other flags.  For example, you might
want to enable support for the symbolic debugger (-g on traditional
UNIX systems).  For this question you should specify those flags.
Do NOT specify libraries (-lwhatever) here.  Most systems will not
need any special flags, in which case specify "none".

EOH
rp="Any additional ld flags (NOT including libraries)? [$dflt]"
$echo $n "$rp $c"
. myread
case "$ans" in
none) ans='';
esac
ldflags="$ans"
rmlist="$rmlist pdp11"

$echo $n "Testing if $cc $ccflags works ... $c"
$cat > trivial.c <<EOF
#include <stdio.h>

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{
	return 0;
}
EOF
found_libcso=

if $cc $ccflags -o trivial trivial.c && ./trivial ; then
    echo "Yes, it does."
else
    echo "NO!"
    echo " "
    echo "You compiler seems not work..."
    exit 1
fi

case "$uname_os" in
    IRIX*)
	case "`file trivial`" in
	    *N32*)
		libdirname=lib32
		;;
	    *64*)
		libdirname=lib64
		;;
	    *)
		libdirname=lib
		;;
	esac
	;;
    Linux)
	case "`file trivial`" in
	    *64-bit*)
		if test -d /usr/lib64
		then
		    libdirname=lib64
		else
		    libdirname=lib
		fi
		;;
	    *)
		libdirname=lib
		;;
	esac
	if test -x /usr/bin/ldd && /usr/bin/ldd trivial > lddoutput 2> /dev/null
	then
	    A="`awk '/libc.so.[0-9] =>/ { print $3; }' lddoutput`"
	    if test "$A" != "" -a -f "$A" 
            then
		found_libcso="$A"
            fi
	fi 
	;;
    *)
	libdirname=lib
	;;
esac
echo "Library directory name is $libdirname"
if test "$found_libcso" != "" ; then
    echo "Compiler used $found_libcso for C library"
fi

$rm -f trivial trivial.c lddoutput

XXXlib=/usr/$libdirname
if test "$XXXlib" != /usr/lib -a -d "$XXXlib"
then
    echo "Adding $XXXlib /$libdirname to library search path"
    libpth="$XXXlib /$libdirname $libpth"
fi

echo " "
echo "Checking for optional libraries..."
dflt=''

case "$libswanted" in
'') libswanted='c_s';;
esac
if [ "$noaddlib" != yes ]; then

	$cat > trivial.c <<EOF
#include <stdio.h>

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{
	return 0;
}
EOF

    reverse=
    for thislib in $libswanted $libs; do
        case "$thislib" in
		-l*)	thislib=`expr X$thislib : 'X-l\(.*\)'`
	esac
        case "$reverse" in
		*$thislib*);;		
		*) reverse="$thislib $reverse" ;;
	esac
    done

    for thislib in $reverse; do
	case "$thislib" in
	dbm) thatlib=ndbm;;
	*_s) thatlib=NONE;;
	*) thatlib="${thislib}_s";;
	*) thatlib=NONE;;
	esac
		
	echo $n "Testing -l$thislib $dflt ... $c"
	if $cc $ccflags -o trivial trivial.c -l$thislib $dflt 2> /dev/null && ./trivial 
	then
	   echo "It works."
           case "$dflt" in
		*-l$thislib*|*-l$thatlib*);;
		*) dflt="-l$thislib $dflt";;
	   esac
	elif $cc $ccflags -o trivial trivial.c -l$thislib 2> /dev/null && ./trivial
	then
		echo "... -l$thislib alone (without $dflt) works."
	else
		echo "No -l$thislib."
	fi
    done
    $rm -f trivial trivial.c
else
    echo "You told last time that additional libraries are not needed!"
fi
set X $dflt
shift
dflt="$*"
case "$dflt" in
'') dflt='none';;
esac

$cat <<EOM
 
Some versions of UNIX support shared libraries, which make
executables smaller but make load time slightly longer.

On some systems, mostly newer UNIX System V's, the shared library
is included by putting the option "-lc_s" as the last thing on the
cc command line when linking.  Other systems use shared libraries
by default.  There may be other libraries needed to compile $package
on your machine as well.  If your system needs the "-lc_s" option,
include it here.  Include any other special libraries here as well.
Say "none" for none.
EOM

echo " "
rp="Any additional libraries? [$dflt]"
$echo $n "$rp $c"
. myread
case "$ans" in
none|'') ans='';
    noaddlib='yes';
    ;;
*)
    noaddlib='no'
    ;;
esac
libs="$ans"

case "$libs" in
	'')
	:
	;;
	*)
	$echo $n "Testing given libraries ... $c"
	$cat > trivial.c <<EOF
#include <stdio.h>

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{
	return 0;
}
EOF
	if $cc $ccflags -o trivial trivial.c $libs && ./trivial ; then
    		echo "Yes, it works"
	else
    		echo "NO!"
    		echo " "
    		echo "You libraries ($libs) seems not work."
    		exit 1
	fi
	$rm -f trivial trivial.c
	;;
esac

: get list of predefined functions in a handy place
echo " "
case "$libc" in
'') if test -d /usr/apollo; then
	libc=/lib/libc
    else
	libc=unknown
    fi
    ;;
'/lib/libc /lib/clib')
    libc=/lib/libc
    ;;
esac
case "$mips" in
'') mips=false;;
'mips') mips=false;;
esac
case "$nm_opts" in
'') if test -f /mach_boot; then
	nm_opts=''
    elif test "$uname_os" = "OSF1"; then
 	nm_opts=''
    elif test -d /usr/ccs/lib; then
	nm_opts='-p'
    elif "$mips"; then
	nm_opts='-B'
    elif test "$uname_os" = "Darwin"; then
	nm_opts='-p'
    elif test "$uname_os" = "Linux"; then
	nm_opts='-D -f sysv'
    else
	nm_opts=''
    fi
    ;;
esac
: on mips, we DO NOT want /lib, and we want inclPath/usr/lib
case "$libpth" in
'') if "$mips"; then
	libpth='$inclPath/usr/lib /usr/local/lib'
	nm_opts='-B'
    else
	libpth='/usr/ccs/lib /lib /usr/lib /usr/ucblib /usr/local/lib'
    fi
    ;;
esac
case "$libs" in
*-lc_s*) libc=`./loc libc_s.a $libc $libpth`
esac
libnames='';
case "$libs" in
'') ;;
*)  for thislib in $libs; do
	case "$thislib" in
	-l*) thislib=`expr X$thislib : 'X-l\(.*\)'`
	    try=`./loc lib$thislib.a blurfl/dyick $libpth`
	    if test ! -f $try; then
		try=`./loc lib$thislib blurfl/dyick $libpth`
		if test ! -f $try; then
		    try=`./loc $thislib blurfl/dyick $libpth`
		    if test ! -f $try; then
			try=`./loc Slib$thislib.a blurfl/dyick $xlibpth`
			if test ! -f $try; then
			    try=''
			fi
		    fi
		fi
	    fi
	    libnames="$libnames $try"
	    ;;
	*) libnames="$libnames $thislib" ;;
	esac
    done
    ;;
esac
set /usr/ccs/lib/libc.so
test -f $1 || set /usr/$libdirname/libc.so
test -f $1 || set /usr/$libdirname/libc.so.[0-9]*
test -f $1 || set /usr/lib/libc.so
test -f $1 || set /usr/lib/libc.so.[0-9]*
test -f $1 || set /usr/lib/system/libsystem_c.dylib
test -f $1 || set /usr/lib/libc.dylib
test -f $1 || set /lib/libsys_s.a
eval set \$$#
if test -f "$1"; then
    echo "Your shared C library is in $1."
    libc="$1"
elif test "$found_libcso" != "" -a -f "$found_libcso" ; then
    echo "Your shared C library is in $found_libcso."
    libc="$found_libcso"
elif test -f "$libc"; then
    echo "Your C library is in $libc."
elif test -f /lib/libc.a; then
    echo "Your C library is in /lib/libc.a.  You're normal."
    libc=/lib/libc.a
else
    if   ans=`./loc libc.a  blurfl/dyick $libpth`; test -f "$ans"; then
	:
    elif ans=`./loc libc    blurfl/dyick $libpth`; test -f "$ans"; then
	    libnames="$libnames "`./loc clib blurfl/dyick $libpth`
    elif ans=`./loc clib    blurfl/dyick $libpth`; test -f "$ans"; then
	:
    elif ans=`./loc Slibc.a blurfl/dyick $xlibpth`; test -f "$ans"; then
	:
    elif ans=`./loc Mlibc.a blurfl/dyick $xlibpth`; test -f "$ans"; then
	:
    elif ans=`./loc Llibc.a blurfl/dyick $xlibpth`; test -f "$ans"; then
	:
    fi
    if test -f "$ans"; then
	echo "Your C library is in $ans, of all places."
	libc=$ans
    else
	cat <<EOM
 
I can't seem to find your C library.  I've looked in the following places:

	$libpth

None of these seems to contain your C library.  What is the full name
EOM
	dflt=None
	$echo $n "of your C library? $c"
	rp='C library full name?'
	. myread
	libc="$ans"
    fi
fi
echo " "
if test $libc = "/lib/libc"; then
    libc="$libc /lib/clib"
fi 

set `echo $libc $libnames | tr ' ' '\012' | $sort | $uniq`
$echo $n "Checking $* for GNU ld scripts...$c"
echo >libgroup.list
for i in $* ; do
    if $grep '^GROUP' $i > libgroup.tmp; then
        a="`$sed 's/^GROUP *(//; s/)//;' <libgroup.tmp`"
	if $test "$a" != "" ; then
	    b=
	    for j in $a ; do
		if $test -f $j ; then
		    case "$b" in
			'')  b="$j" ;;
			*)   b="$b $j";
		    esac
		fi
	    done

	    echo "$b" >> libgroup.list
	    echo $n " $i ($b)$c" 
	else
	    echo $i >> libgroup.list
	fi
    else
	echo $i >> libgroup.list
    fi
done
$echo " OK."
set `tr ' ' '\012' < libgroup.list | $sort | $uniq`
$echo $n "Extracting names from $* for later perusal ($nm $nm_opts) ...$c"
if $nm $nm_opts $* 2>/dev/null >libc.tmp; then
    :
else
    $echo $n " (failed: $nm $nm_opts) $c" 

    case "x$nm_opts" in
	"x-D -f sysv")
	    try_opts="-D"
	    echo " Trying $nm $try_opts instead.";
	    $echo $n "Extracting names from $* for later perusal ($nm $try_opts) ...$c"
	    if $nm $try_opts $* 2>/dev/null >libc.tmp; then
		 $echo $n " (OK) $c"
		 nm_opts="$try_opts"
	    else
		$echo $n " (failed: $nm $try_opts) $c" 
	    fi
	    ;;	
    esac
fi

if $test "$uname_os" = "AIX" 
then
    case "`$uname -v`" in
	3*)
	    $sed -n -e 's/^.* [ATDSUW]  *[_.]*//p' -e 's/^.* [ATDSUW] //p' <libc.tmp >libc.list
	    ;;
	*)
	    cat libc.tmp |egrep '^\..* *T'|egrep -v '^\._|Srestf|Ssavef|^\.\$'|\
		$sed -e 's/\.\(.* \)T.*/\1/' -e 's/ *//g' >libc.list
	;;
   esac

   if $test -f /lib/syscalls.exp; then
      echo " "
      echo "Also extracting names from /lib/syscalls.exp for good ole AIX..." 
      $sed -n 's/^\([^  ]*\)[    ]*syscall$/\1/p' /lib/syscalls.exp >>libc.list
   fi
else
   $sed -n -e 's/^.* [ATDSUW]  *[_.]*//p' -e 's/^.* [iATDSUW] //p' <libc.tmp >libc.list
fi

if $contains '^printf$' libc.list >/dev/null 2>&1; then
    echo done
elif $sed -n -e 's/^__*//' -e 's/^\([a-zA-Z_0-9$]*\).*xtern.*/\1/p' \
	<libc.tmp >libc.list; \
  $contains '^printf$' libc.list >/dev/null 2>&1; then
    echo done
elif $sed -n -e '/|UNDEF/d' -e '/FUNC..GL/s/^.*|__*//p' <libc.tmp >libc.list; \
  $contains '^printf$' libc.list >/dev/null 2>&1; then
    echo done
elif $sed -n -e 's/^.* D __*//p' -e 's/^.* D //p' <libc.tmp >libc.list; \
  $contains '^printf$' libc.list >/dev/null 2>&1; then
    echo done
elif $sed -n -e 's/^_//' -e 's/^\([a-zA-Z_0-9]*\).*xtern.*text.*/\1/p' \
		<libc.tmp >libc.list; \
  $contains '^printf$' libc.list >/dev/null 2>&1; then
    echo done
elif $grep '|' <libc.tmp | $sed -n -e '/|COMMON/d' -e '/|DATA/d' \
                                   -e 's/^\([^     ]*\).*/\1/p' >libc.list
  $contains '^printf$' libc.list >/dev/null 2>&1; then
    echo done
elif $sed -n -e 's/^.*|FUNC |GLOB .*|//p' -e 's/^.*|FUNC |WEAK .*|//p' \
	   <libc.tmp >libc.list; \
  $contains '^printf$' libc.list >/dev/null 2>&1; then
    echo done
elif $sed -n -e 's/^.* [ATDSUW]  *//p' -e 's/^.* [ATDSUW] //p' \
	<libc.tmp >libc.list; \
  $contains '^printf$' libc.list >/dev/null 2>&1; then
    echo done
else
    $nm -p $* 2>/dev/null >libc.tmp
    $sed -n -e 's/^.* [ATDSUW]  *[_.]*//p' -e 's/^.* [iATDSUW] //p' <libc.tmp >libc.list
    if $contains '^printf$' libc.list >/dev/null 2>&1; then
	nm_opts='-p'
	echo " (succeed: $nm $nm_opts) done"
    else
	echo " "
	echo "$nm didn't seem to work right."
	echo "Trying $ar instead..."
	if $ar t $libc > libc.tmp; then
	    for thisname in $libnames; do
		$ar t $thisname >>libc.tmp
	    done
	    $sed -e 's/\.o$//' < libc.tmp > libc.list
	    echo "Ok."
	else
	    echo "$ar didn't seem to work right."
	    echo "Maybe this is a Cray...trying bld instead..."
	    if bld t $libc | $sed -e 's/.*\///' -e 's/\.o:.*$//' > libc.list; then
		for thisname in $libnames; do
		    bld t $libnames | \
			$sed -e 's/.*\///' -e 's/\.o:.*$//' >>libc.list
		    $ar t $thisname >>libc.tmp
		done
		echo "Ok."
	    else
		echo "That didn't work either.  Giving up."
		exit 1
	    fi
	fi
    fi
fi

: old version

inlibc='echo " ";
if $contains "^$1\$" libc.list >/dev/null 2>&1;
then echo "$1() found"; eval "$2=$define";
else echo "$1() not found"; eval "$2=$undef"; fi'

: : new version
: 
: inlibc='echo " "; td=$define; tu=$undef;
: if $contains "^$1\$" libc.list >/dev/null 2>&1;
: then echo "$1() found";
:   eval "case \"\$$2\" in undef) . whoa; esac"; eval "$2=\$td";
: else echo "$1() not found";
:   eval "case \"\$$2\" in define) . whoa; esac"; eval "$2=\$tu"; fi'
: 
: rmlist="$rmlist libc.tmp libc.list"
: 
: see how we invoke the C preprocessor
echo " "
echo "Now, how can we feed standard input to your C preprocessor..."
cat <<'EOT' >testcpp.c
#define ABC abc
#define XYZ xyz
ABC.XYZ
EOT
echo 'Maybe "'"$cc"' -E" will work...'
$cc -E <testcpp.c >testcpp.out 2>&1
: try to force gcc preprocessor if that is the compiler they are using
case $? in
0) cppstdin="$cc -E";;
*) case "$cc" in
    *gcc*)
	cd "$build_dir"
	echo 'Trying (cat >/tmp/$$.c; '"$cc"' -E /tmp/$$.c; rm /tmp/$$.c)'
	echo 'cat >/tmp/$$.c; '"$cc"' -E /tmp/$$.c; rm /tmp/$$.c' >cppstdin
	chmod 755 cppstdin
	cppstdin=`pwd`/cppstdin
	cppminus='';
	cd $UU
	$cppstdin <testcpp.c >testcpp.out 2>&1
	;;
    esac
    ;;
esac
if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
    echo "Yup, it does."
    cppstdin="$cc -E"
    cppminus='';
else
    echo 'Nope, maybe "'$cpp'" will work...'
    $cpp <testcpp.c >testcpp.out 2>&1
    if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
	echo "Yup, it does."
	cppstdin="$cpp"
	cppminus='';
    else
	echo 'No such luck...maybe "'$cpp' -" will work...'
	$cpp - <testcpp.c >testcpp.out 2>&1
	if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
	    echo "It works!"
	    cppstdin="$cpp"
	    cppminus='-';
	else
	    echo 'Nixed again...maybe "'"$cc"' -E -" will work...'
	    $cc -E - <testcpp.c >testcpp.out 2>&1
	    if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
		echo "Hooray, it works!  I was beginning to wonder."
		cppstdin="$cc -E"
		cppminus='-';
	    else
		echo 'Nope...maybe "'"$cc"' -P" will work...'
		
		$cc -P <testcpp.c >testcpp.out 2>&1
		if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
		    echo "Yup, that does."
		    cppstdin="$cc -P"
		    cppminus='';
		else
		    echo 'Nope...maybe "'"$cc"' -P -" will work...'
		    $cc -P - <testcpp.c >testcpp.out 2>&1
		    if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
			echo "Yup, that does."
			cppstdin="$cc -P"
			cppminus='-';
		    else
			echo 'Hmm...perhaps you already told me...'
			case "$cppstdin" in
			'') ;;
			*) $cppstdin $cppminus <testcpp.c >testcpp.out 2>&1;;
			esac
			if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
			    echo "Hooray, you did!  I was beginning to wonder."
			else
			    echo 'Uh-uh.  Time to get fancy...'
			    cd "$build_dir"
			    echo 'Trying (cat >/tmp/$$.c; '"$cc"' -E /tmp/$$.c; rm /tmp/$$.c)'
			    echo 'cat >/tmp/$$.c; '"$cc"' -E /tmp/$$.c; rm /tmp/$$.c' >cppstdin
			    chmod 755 cppstdin
			    cppstdin=`pwd`/cppstdin
			    cppminus='';
			    cd $UU
			    $cppstdin <testcpp.c >testcpp.out 2>&1
			    if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
				echo "Eureka!."
			    else
				dflt=blurfl
				$echo $n "No dice.  I can't find a C preprocessor.  Name one: $c"
				rp='Name a C preprocessor:'
				. myread
				cppstdin="$ans"
				$cppstdin <testcpp.c >testcpp.out 2>&1
				if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
				    echo "OK, that will do."
				else
				    echo "Sorry, I can't get that to work.  Go find one."
				    exit 1
				fi
			    fi
			fi
		    fi
		fi
	    fi
	fi
    fi
fi
$rm -f testcpp.c testcpp.out

: get C preprocessor symbols handy
echo " "
echo $attrlist | $tr ' ' '\012' >Cppsym.know
$cat <<EOSS >Cppsym
$startsh
case "\$1" in
-l) list=true
    shift
    ;;
esac
unknown=''
case "\$list\$#" in
1|2)
    for sym 
    do
	if $contains "^\$1$" Cppsym.true >/dev/null 2>&1; then
	    exit 0
	elif $contains "^\$1$" Cppsym.know >/dev/null 2>&1; then
		:
	else
	    unknown="\$unknown \$sym"
	fi
    done
    set X \$unknown
    shift
    ;;
esac
case \$# in
0) exit 1;;
esac
echo \$* | $tr ' ' '\012' | $sed -e 's/\(.*\)/\\
#ifdef \1\\
exit 0; _ _ _ _\1\\	 \1\\
#endif\\
/' >/tmp/Cppsym\$\$
echo exit 1 >>/tmp/Cppsym\$\$
$cppstdin $cppminus </tmp/Cppsym\$\$ >/tmp/Cppsym2\$\$
case "\$list" in
true) awk 'NF > 5 {print substr(\$6,2,100)}' </tmp/Cppsym2\$\$ ;;
*)
    sh /tmp/Cppsym2\$\$
    status=\$?
    ;;
esac
$rm -f /tmp/Cppsym\$\$ /tmp/Cppsym2\$\$
exit \$status
EOSS
chmod +x Cppsym

echo "Your C preprocessor defines the following symbols:"
Cppsym -l $attrlist >Cppsym.true
cat Cppsym.true
rmlist="$rmlist Cppsym Cppsym.know Cppsym.true"



: see if strings.h is in /usr/include or /usr/include/sys
echo " "

if $test "$uname_os" = "OSF1"; then
    strings=`loc strings.h "" /usr/include $includepath`
    if $test -z "$strings"; then
	    strings=`loc string.h "" /usr/include $includepath`
    fi
else
    strings=`loc string.h "" /usr/include $includepath`
    if $test -z "$strings"; then
	    strings=`loc strings.h "" /usr/include $includepath`
    fi
fi
while $test -z "$strings"; do
	echo " "
	dflt=''
	rp="What is the full path name of the include file directory? []"
	$echo $n "$rp $c"
	. myread
	includepath=`filexp $ans`
	if $test -d "$includepath"; then
		strings=`loc string.h "" /usr/include $includepath`
		if $test -z "$strings"; then
			strings=`loc strings.h "" /usr/include $includepath`
		fi
		if $test -z "$strings"; then
			$cat <<EOM

Include file string.h or strings.h not found in $includepath.
Elm requires string.h on USG type systems or strings.h on BSD type
systems.  Please specify the directory where one of these files can
be found.
EOM
		fi
	else
		echo "Directory $includepath not found"
	fi
done

strings_f=`$expr "$strings" : ".*/\(.*\)"`
if $test "$strings_f" = "string.h"; then
	d_strings="$undef"
	echo "Using string.h instead of strings.h"
else
	d_strings="$define"
	echo "Using strings.h instead of string.h"
fi


: see if there is dlfcn.h file
echo " "
if $test -r /usr/include/dlfcn.h ; then
    echo "dlfcn.h found (trying shared libraries)"

    $cat > try.c <<'EOF'

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{

    return 0;
}
EOF

    $cat <<'EOF'

Some machines requires special options for generate position indepedent code 
for shared libraries. Other machines produce position indepedent code always 
(if "noshared" options are not used).
EOF

    res=''
    old="$picflag"
    
    for A in "$old" '-KPIC' '-fPIC'; do
	case "$res" in
	    '')
		case "$A" in
		    '')
			: Skipped
		    ;;
		    *)
		    echo "  Trying compiling with $A"
		    if $cc $ccflags $A -o try try.c > try.log 2>&1 &&
			./try ; then

			: gcc retuns 0 although unknown -Kxxx option is given !!!
			if $grep "unrecognized option" try.log ||
			   $grep "unrecognised option" try.log; then
			    echo "Ignoring $A option although compilation succeed"
			else
			    res="$A"
			    echo "Succeed with $A flag" 
			fi
		    fi
		    ;;
		esac
	    ;;
	esac
    done

    if $test "$nopic" = y ; then
	    dflt=none
    else 
	case "$res" in
	    '')
	    dflt=none
	    ;;
	    *)
	    dflt="$res"
	    ;;
	esac
    fi

    echo "Give \"none\" if any extra flags should not be used."
    rp="What flag should be used? [$dflt]"
    $echo $n "$rp $c"
    . myread
    case "$ans" in
	none)
	    nopic=y
	    picflag=
	    ;;
	*)
	    nopic=
	    picflag="$ans"
	    echo "  Trying compiling with $picflag"
	    if $cc $ccflags $picflag -o try try.c > try.log 2>&1 &&
		    ./try ; then
	       echo "Succeed with $picflag flag" 
	    else
		echo "COMPILATION FAILED -- ignoring $picflag"
		picflag=
	    fi

	    ;;
    esac
      
    if test ! -d "$build_dir/shlib"; then
	echo "Making shlib directory"
	mkdir "$build_dir/shlib"
    else
	echo "Found shlib directory"
    fi

    $echo "Trying create shared library"

    LibLoc=`cd "$build_dir"; pwd`/shlib
    
    $cat > try_sh.c <<'EOF'

char * myfunc()
{
    return "succeed";
}
EOF

    $cat > try.c <<EOF
#$d_strings STRINGS

#ifdef STRINGS
#include <strings.h>
#else
#include <string.h>
#endif

extern char * myfunc();

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{
    char * C;

    C = myfunc();

    if (C &&
        0 == strcmp(C,"succeed"))
	return 0;

   return 1;
}
EOF

    soname_opt=''
    for A in '-shared -soname ' '-shared -Xlinker -soname=' '-Wl,-dy,-G,-h' \
		'-shared -soname='; do
	case "$soname_opt" in
	'')
	    echo "  Trying creation with ${A}name.so"
	    if $cc $ccflags $picflag ${A}testshared.so -o "$build_dir/shlib/testshared-dummy.so" try_sh.c > try.log 2>&1
	    then
		soname_opt="$A"
		echo "Succeed with ${soname_opt}name.so"
		mv "$build_dir/shlib/testshared-dummy.so" "$build_dir/shlib/testshared.so"  || exit 1
	    fi
	;;
        esac
    done
    
    if $test "X$soname_opt" != X
    then

	echo
	echo "1)   Testing shared library usage with RPATH ... "

	rpath_ok=''
	rpath_opt=''

	XX=testshared-$$.so
	cp "$build_dir/shlib/testshared.so" $XX   || exit 1


	for A in '-rpath ' '-Xlinker -rpath -Xlinker ' '-R'; do
	    case "$rpath_opt" in
	    '')
		echo "  Trying link with ${A}DIR" 
		if $cc $ccflags $picflag -o try $A$LibLoc try.c $XX $libs > try.log 2>&1
		then
		    rpath_opt="$A"
		    echo "Succeed with ${rpath_opt}directory"
		fi
	    ;;
            esac
	done
	rm $XX


	if $test "X$rpath_opt" != X
	then
	    
	    if ./try ; then
		echo "Shared libraries (with RPATH) seems work"
		rpath_ok='OK'
	    else
		echo "Runtime linking with test shared library failed  (RPATH)"
	    fi

	else
	    echo "Compiling or linking with test shared library failed (RPATH)"
	fi
	rm -f try

	echo
	echo "2)   Testing shared library usage with absolute SONAME ... "
	
	soname_ok=''

	echo "Creating library with ${soname_opt}dirname/name.so"

	if $cc $ccflags $picflag ${soname_opt}$LibLoc/testshared-ab.so -o "$build_dir/shlib/testshared-dummy2.so" try_sh.c > try.log 2>&1
	then	    
	    mv "$build_dir/shlib/testshared-dummy2.so" "$build_dir/shlib/testshared-ab.so"  || exit 1


	    XX=testshared-$$.so
	    cp "$build_dir/shlib/testshared-ab.so" $XX   || exit 1

	    echo "Linking with created library"
	    if $cc $ccflags $picflag -o try try.c $XX $libs > try.log 2>&1
	    then
		rm $XX

		
		if ./try ; then
		    echo "Shared libraries (with absolute SONAME) seems work"
		    soname_ok='OK'

		else
		    echo "Runtime linking with test shared library failed  (with absolute SONAME)"
		fi

	    else
		echo "linking with test shared library failed (with absolute SONAME)"
	    fi
	    rm -f $XX     
	fi


	echo
	case "$rpath_ok$soname_ok" in
	    OKOK)
		echo "Shared libraries seems work (both methods works)"
		d_shared="$define"
		;;

	    *OK*)
		echo "Shared libraries seems work (one method works)"
		d_shared="$define"
		;;
	    *)
		echo "Shared libraries seems NOT work"
		d_shared="$undef"
		;;
	esac

	

	if $test "$d_shared" = "$define" ; then
	    $cat > dltry.c <<EOF
#$d_strings STRINGS

#ifdef STRINGS
#include <strings.h>
#else
#include <string.h>
#endif

#if defined(__STDC__)
#include <stdlib.h>

int main (int argc, char * argv[]);
#else

#ifndef const
#define const
#endif
#endif

#include <dlfcn.h>

int main (argc,argv)
   int argc;
   char * argv[];
{
    char * C;
    void * handle = dlopen(LIBNAME,RTLD_NOW);
    typedef char * myfunc();
    myfunc * f_handle;

    if (!handle)
       return 1;

    f_handle = dlsym(handle,"myfunc");
    if (!f_handle)
       return 1;

    C = f_handle();

    if (C &&
        0 == strcmp(C,"succeed"))
	return 0;

   dlclose(handle);

   return 1;
}
EOF

	    dlopen_lib=BAD
	    echo > failed.log
	    
	    for A in '' '-ldl'; do
		case "$dlopen_lib" in
		BAD)		
		    echo "  Trying dlopen() with ${A:-(none)}" 
		    if $cc $ccflags $picflag -o dltry -DLIBNAME=\"$LibLoc/testshared.so\" dltry.c $A $libs > dltry.log 2>&1 
		    then
			echo "Found dlopen() from ${A:-system}"
			dlopen_lib="$A"
		    else
			echo "* Test dlopen() with ${A:-(none)} failed " >> failed.log
			$cat dltry.log >> failed.log
			
		    fi
		;;
                esac
            done
		
	    if $test "X$dlopen_lib" != XBAD &&
		./dltry
	    then
		echo "Succeed with dlopen()"
                d_dlopen_libs="$define"
	    else
		echo "Failed to use dlopen()"
		$cat failed.log
		
		d_dlopen_libs="$undef"
		dlopen_lib=
		d_dynamic_main="$undef"
		dynamic_opt=
	    fi

	else
	    d_dlopen_libs="$undef"
	    dlopen_lib=
	    d_dynamic_main="$undef"
	    dynamic_opt=

	fi

    else
	echo "Creating of test shared library failed"
	d_shared="$undef"
	d_dlopen_libs="$undef"
	dlopen_lib=
	d_dynamic_main="$undef"
        dynamic_opt=
    fi

    if $test "$d_dlopen_libs" = "$define" ; then

	$cat > try_dyn.c <<'EOF'

char * in_main;

#ifdef __STDC__
char * myfunc(void);
#endif

char * myfunc()
{
    return in_main;
}
EOF
	: This should succeed
	$echo $n "Compiling testdynshared.so ... $c"
	$cc $ccflags $picflag ${soname_opt}$LibLoc/testdynshared.so -o "$build_dir/shlib/testdynshared.so" try_dyn.c && echo " OK"


       $cat > dltry2.c <<EOF
#$d_strings STRINGS

#ifdef STRINGS
#include <strings.h>
#else
#include <string.h>
#endif

#include <dlfcn.h>

char * in_main = "succeed";

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{
    char * C;
    void * handle = dlopen(LIBNAME,RTLD_NOW);
    typedef char * myfunc();
    myfunc * f_handle;

    if (!handle)
       return 1;

    f_handle = dlsym(handle,"myfunc");
    if (!f_handle)
	    return 1;

    C = f_handle();

    if (C &&
        0 == strcmp(C,"succeed")) {
	printf("%s\n",C);
	return 0;
   }
   dlclose(handle);

   return 1;
}
EOF

	dynamic_opt=BAD
	for A in '' '-rdynamic' ; do
	    case "$dynamic_opt" in
	    BAD)
		echo "  Trying resolving with option ${A:-(none)}"
		if $cc $ccflags $picflag -o dltry2 -DLIBNAME=\"$LibLoc/testdynshared.so\" dltry2.c $dlopen_lib $A $libs > dltry.log 2>&1 &&
		    ./dltry2 ; then
			echo "Resolves ok with option ${A:-(none)}"
			dynamic_opt="$A"
		fi		   
	    ;;
	    esac
	done

	if $test "X$dynamic_opt" != XBAD ; then
	    d_dynamic_main="$define"
	else
	    echo "Unable to found how resolve mail program symbols from dynamic libary"
	    dynamic_opt=
	    d_dynamic_main="$undef"
	fi

    fi

    $rm -f try_sh.c try.c dltry.c ./try try.log dltry.log "$build_dir/shlib/testshared.so" "$build_dir/shlib/testshared-ab.so" dltry try_dyn.c "$build_dir/shlib/testdynshared.so" dltry2.c dltry2 failed.log

else
    echo "dlfcn.h not found (no shared librariers)"
    d_shared="$undef"
fi

: Testing gcc __int128

$echo $n "Testing __int128 type...  $c"

$cat > test_int128.c <<EOF
#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{
     __int128 x;

     x = 0;

     return 0;
}
EOF
if $cc $ccflags -o test_int128 test_int128.c > try.log 2>&1
then
    if ./test_int128
    then
	echo "OK"
	d_have_int128="$define"
    else
	echo "Run failed?"
	d_have_int128="$undef"
    fi
else
    echo " DO not have __int128 type"
    d_have_int128="$undef"

    # cat try.log
fi

rmlist="$rmlist  test_int128 test_int128.c try.log"

: see if chown can take -1 for mantaining the user/group unchanged
echo " "
 
case "$d_chown_neg1" in
undef)  dflt=n;;
*)  dflt=y;;
esac

$cat <<EOM

Does your system allow chown(-1, group) and chown(user, -1) to
not change the user or group respectively.  This is usually documented
in the chown manual page (man 2 chown). (Most POSIX and BSD systems can,
Xenix cannot)

EOM
rp="Does this system allow -1 as chown argument? [$dflt]"
$echo $n "$rp $c"
. myread
case "$ans" in
y*) d_chown_neg1="$define";;
*)  d_chown_neg1="$undef";;
esac

case "$d_content" in
"$define") dflt=y;;
"$undef")  dflt=n;;
*)	   dflt=n;;
esac

$cat << EOM

Some Local Delivery Agents (mailers) support the Content-Length: header. In 
doing so, they do not wish to have messages escaped to protect 'From ' lines
in the body of the message, among other strings.  Does the Local Delivery Agent
in use on this system use the Content-Length: header when writing mails to
(incoming) mailbox?
EOM

echo " "
rp="Honors Content-Length: header? [$dflt]"
$echo $n "$rp $c"
. myread
case "$ans" in
y*) d_content="$define";;
*)  d_content="$undef";;
esac

: see if crypt exists
echo " "
if $contains '^crypt$' libc.list >/dev/null 2>&1; then
    echo 'crypt() found.'
    d_crypt="$define"
    cryptlib=''
else
    cryptlib=`loc Slibcrypt.a "" $xlibpth`
    if $test -z "$cryptlib"; then
	cryptlib=`loc Mlibcrypt.a "" $xlibpth`
    else
	cryptlib=-lcrypt
    fi
    if $test -z "$cryptlib"; then
	cryptlib=`loc Llibcrypt.a "" $xlibpth`
    else
	cryptlib=-lcrypt
    fi
    if $test -z "$cryptlib"; then
	cryptlib=`loc libcrypt.a "" $libpth`
    else
	cryptlib=-lcrypt
    fi
:
:	now try for international versions?
:
    if $test -z "$cryptlib"; then
	cryptlib=`loc Slibcrypt_i.a "" $libpth`
	if $test -z "$cryptlib"; then
	    cryptlib=`loc Mlibcrypt_i.a "" $libpth`
	else
	    cryptlib=-lcrypt_i
	fi
	if $test -z "$cryptlib"; then
	    cryptlib=`loc Llibcrypt_i.a "" $libpth`
	else
	    cryptlib=-lcrypt_i
	fi
	if $test -z "$cryptlib"; then
	    cryptlib=`loc libcrypt_i.a "" $libpth`
	else
	    cryptlib=-lcrypt_i
	fi
    fi
    if $test -z "$cryptlib"; then
	i_crypt=`loc crypt.h "" /usr/include $includepath`

	if $test -n "$i_crypt"; then
	    echo "Can't locate crypt() but found <crypt.h>. Trying compile testing."
	
	    $cat > try_crypt.c <<'EOF'

#include <crypt.h>

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{
    char * C;

    C = crypt("aa","aa");

    if (C)
         return 0;
    

    return 0;
}
EOF

	    rmlist="$rmlist  try_crypt try_crypt.c try.log try2.log"

	    d_crypt=
	    i_crypt="$undef"

	    for A in '' '-lcrypt' '-lcrypt_i' ; do
		case "$d_crypt" in
		    '')
			echo "  Trying ${A:-system} library"

			if $cc $ccflags -o try_crypt try_crypt.c $A $libs >  try.log 2>&1 &&
			    ./try_crypt > try2.log 2>&1
			then
			    echo "Found crypt() from ${A:-system} library"
			    d_crypt="$define"
			    i_crypt="$define"
			    cryptlib="$A"
			fi

			;;
		esac
	    done

	    case "$d_crypt" in
		'')
		    echo 'crypt() not found.'
		    d_crypt="$undef"
		    ;;
	    esac

	else

	    echo 'crypt() not found.'
	    d_crypt="$undef"
	fi
    else
	echo "Found library $cryptlib for crypt()."
	d_crypt="$define"
    fi
fi

if $test "$i_crypt" = "";  then 
    if $test "$d_crypt" = "$define";  then
	: see if crypt.h is in includepath
	echo " "
	i_crypt=`loc crypt.h "" /usr/include $includepath`
	if $test -n "$i_crypt"; then
	    echo "Found <crypt.h>"
	    i_crypt="$define"
	else
	    echo "Did not find <crypt.h>"
	    i_crypt="$undef"
	fi
    else
	i_crypt="$undef"
    fi
fi

: determine if the host name should be displayed on the index page

case "$d_disphost" in
"$define") dflt=y;;
"$undef")  dflt=n;;
*)	dflt=n;;
esac
$cat <<EOM

Elm can either display the hostname on the index page, or just
the folder name.  If the hostname is displayed, the folder name
will read hostname:folder.  If not it will just read folder.

This can be changed also on global elm.rc or on per user elmrc 
(variable menu-display-host).

EOM
rp="Should Elm display the hostname as part of the folder name? [$dflt]"
$echo $n "$rp $c"
. myread
case "$ans" in
y*) d_disphost="$define";;
*)  d_disphost="$undef";;
esac


echo " "
if $contains flock libc.list >/dev/null 2>&1; then
    echo 'flock() found.'
    if $contains EWOULDBLOCK /usr/include/errno.h > /dev/null 2>&1; then
        has_flock="$define"
        echo 'flock locking available.'
    elif $contains EWOULDBLOCK /usr/include/sys/errno.h > /dev/null 2>&1; then
        has_flock="$define"
        echo 'flock locking available.'
    elif $test "$uname_os" = "Linux" && 
	$contains EWOULDBLOCK /usr/include/asm/errno.h > /dev/null 2>&1; then
        has_flock="$define"
        echo 'flock locking available.'
    elif $test "$uname_os" = "Linux" && 
	$contains EWOULDBLOCK /usr/include/linux/errno.h > /dev/null 2>&1; then
        has_flock="$define"
        echo 'flock locking available.'
    elif $test "$uname_os" = "Linux" && 
	$contains EWOULDBLOCK /usr/include/asm-generic/errno.h > /dev/null 2>&1
    then
        has_flock="$define"
        echo 'flock locking available.'
    else       
	has_flock="$undef"
        echo 'flock locking not available.'
	d_flock="$undef"
    fi
else
    has_flock="$undef"
    d_flock="$undef"
fi

if $contains F_SETLK /usr/include/sys/fcntl.h >/dev/null 2>&1; then
    echo 'F_SETLK found, fcntl locking available'
    has_fcntl="$define"
elif $contains F_SETLK /usr/include/sys/fcntlcom.h >/dev/null 2>&1; then
    echo 'F_SETLK found, fcntl locking available'
    has_fcntl="$define"
elif $contains F_SETLK /usr/include/sys/file.h >/dev/null 2>&1; then
    echo 'F_SETLK found, fcntl locking available'
    has_fcntl="$define"
elif $contains F_SETLK /usr/include/fcntl.h >/dev/null 2>&1; then
    echo 'F_SETLK found, fcntl locking available'
    has_fcntl="$define"
elif $test "$uname_os" = "Linux" ; then
    : I give up, use compiler instead for testing F_SETLK
    $echo $n "Testing if F_SETLK can be used ... $c"
    $cat > try.c <<'EOF'
#include <unistd.h>
#include <fcntl.h>

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{
    struct flock lock_info;

    int fd = open("try.c",O_RDONLY);
  
    lock_info.l_type = F_RDLCK;
    lock_info.l_whence = 0;
    lock_info.l_start = 0;
    lock_info.l_len = 0;
    
    if (fcntl(fd, F_SETLK, &lock_info) != 0) {
         return 1;      /* failure */
    }
    return 0;      /* OK */
}
EOF

    rmlist="$rmlist try.c try"

   if $cc $ccflags -o try try.c >/dev/null 2>&1 &&  ./try ; then
       echo " OK, fcntl locking available"
        has_fcntl="$define"
   else
        echo " No, fcntl locking not available"
        has_fcntl="$undef"
        d_fcntlock="$undef" 
   fi

else
    echo 'F_SETLK not found, fcntl locking not available'
    has_fcntl="$undef"
    d_fcntlock="$undef"
fi

may_flock=n
may_fcntl=n

if $test "$has_flock" = "$define" -o "$has_fcntl" = "$define"; then
    $cat <<EOF

Used mail spool locking is asked later. Which syscall locking methods
should be supported (and compiled) ?

EOF

   echo "Test file" > test-file.xx
   rmlist="$rmlist test-file.xx"

   if $test "$has_flock" = "$define"; then

       $echo $n "Testing flock()...  $c"

       $cat > try_flock.c <<'EOF'
#include <sys/file.h>
#include <unistd.h>

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{

      int fd = open("test-file.xx",O_RDWR);

      if (flock (fd, LOCK_NB | LOCK_EX)) {

           return 1;      /* failure */

      }

      return 0;
}
EOF

       case "$d_compile_flock" in
	   "$define")	dflt=y;;
	   "$undef")    dflt=n;;
	   *)           
	       if $test "$d_flock" = "$define"; then
		   dflt=y
	       else
		   dflt=n
	       fi
	       ;;
       esac
       if $cc $ccflags -o try_flock  try_flock.c
       then
	   if ./try_flock 
	   then
	       echo "OK"
	       dflt=y
               may_flock=y
	   else
	       echo "flock() does not work?"
	   fi
       else
	   echo "OOPS ... compile test for flock() failed"
	   dflt=n
       fi
       
       rp="Support flock() style locking? [$dflt]"
       $echo $n "$rp $c"
       . myread
       case "$ans" in
	   y*)   d_compile_flock="$define";;
	   *)    d_compile_flock="$undef";;
       esac
       
       rmlist="$rmlist try_flock.c try_flock"
       
   else
       d_compile_flock="$undef"
   fi
    
   if $test "$has_fcntl" = "$define"; then

       $echo $n "Testing fcntl()...  $c"

       $cat > try_fcntl.c <<'EOF'
#include <unistd.h>
#include <fcntl.h>

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{
    struct flock lock_info;

    int fd = open("test-file.xx",O_RDWR);

    lock_info.l_type = F_WRLCK;
    lock_info.l_whence = 0;
    lock_info.l_start = 0;
    lock_info.l_len = 0;

    if (fcntl(fd, F_SETLK, &lock_info) != 0) {
          return 1;      /* failure */
    }
    return 0;      /* OK */
}

EOF
       rmlist="$rmlist try_fcntl.c try_fcntl"
       
       case "$d_compile_fcntl" in
	   "$define")	dflt=y;;
	   "$undef")    dflt=n;;
	   *)           
	       if $test "$d_fcntlock" = "$define"; then
		   dflt=y
	       else
		   dflt=n
	       fi
	       ;;
       esac
       if $cc $ccflags -o try_fcntl try_fcntl.c
       then
	   if ./try_fcntl 
	   then
	       echo "OK"
	       dflt=y
               may_fcntl=y
	   else
	       echo "fcntl() does not work?"
	   fi
       else
	   echo "OOPS ... compile test for fcntl() failed"
	   dflt=n
       fi

       rp="Support fcntl() style locking? [$dflt]"
       $echo $n "$rp $c"
       . myread
       case "$ans" in
	   y*)   d_compile_fcntl="$define";;
	   *)    d_compile_fcntl="$undef";;
       esac



   else
       d_compile_fcntl="$undef"
   fi

else
    d_compile_flock="$undef"
    d_compile_fcntl="$undef"
fi

if $test "$has_flock" = "$define" -o "$has_fcntl" = "$define"; then
    $cat <<EOF

Mail Transport Agents (sendmail, etc.) and Mail User Agents (Elm) can
use a variety of file locking protocols.  Based on your system type,
usage of a network, and MTA/MUAs in use, you may want to configure more
than one of the following Mail Locking Protocols.  It is recommended
that you use as many as are possible on your system to avoid problems.
All systems can support the dot locking method (.lock files).

You can also use global elm.rc variables mailhome-locking and 
mailbox-locking for changing this.

Available locking protocols:
	dot locking (.lock)
EOF

    if $test "$has_flock" = "$define"; then
	echo '	flock style locking'
    fi

    if $test "$has_fcntl" = "$define"; then
	echo '	fcntl style locking'
    fi

    if $test "$has_flock" = "$define" -a "$has_fcntl" = "$define"; then
	$cat <<EOF

EOF
	rp="[Type carriage return to continue]"
	$echo $n "$rp $c"
	. myread

	$cat <<EOM

On some systems, flock style locking and fcntl style locking use the
same underlying calls so both are not only not necessary, but may
interfere with each other.  On other systems they are distinct and both
should be used.  You will have to consult the documentation for your
operating system to determine in which class your system resides.

Usually flock style locking is emulated using fcntl style locking
on these systems (for example on IRIX).

This can be changed also on global elm.rc (variables mailhome-locking
and mailbox-locking).

EOM
	if $test "$uname_os" = "Linux"; then
	    $cat <<EOF

How locking is done depends kernel and libc versions on Linux.
In some versions of Linux both fcntl and flock style locking 
can be used and some versions of Linux they conflicts. Please
consult /usr/src/linux/Documentation/locks.txt for details.

EOF
	fi
    fi

    case "$d_dotlock" in
    "$define")	dflt=y;;
    "$undef")	dflt=n;;
    *)		dflt=y;;
    esac

    rp="Would you like to use dot lock style mail spool locking? [$dflt]"
    $echo $n "$rp $c"
    . myread
    case "$ans" in
    y*) d_dotlock="$define";;
    *)  d_dotlock="$undef";;
    esac

    if $test "$has_flock" = "$define"; then
	case "$d_flock" in
	"$define")	dflt=y;;
	"$undef")	dflt=n;;
	*)
	    if $test "$uname_os" = "Linux"; then
		case "$uname_rel" in
		    2.*)
			dflt=$may_flock;;
		    3.*)
			dflt=$may_flock;;
		    [4-9].*)	
			dflt=$may_flock;;
		    *)
			dflt=n;;
		 esac
	    elif bsd || $test "$has_fcntl" != "$define"; then
		dflt=$may_flock
	    else
		dflt=n
	    fi
	    ;;
	esac

	rp="Would you like to use flock style mail spool locking? [$dflt]"
	$echo $n "$rp $c"
	. myread
	case "$ans" in
	y*) d_flock="$define";;
	*)  d_flock="$undef";;
	esac
    fi

    if $test "$has_fcntl" = "$define"; then
	case "$d_fcntlock" in
	"$define")	dflt=y;;
	"$undef")	dflt=n;;
	*)		
	    if $test "$uname_os" = "Linux" -a "$d_flock" = "$define"; then
		case "$uname_rel" in
		    2.[1-9]*)
			dflt=$may_fcntl;;
		    3.*)
			dflt=$may_fcntl;;
		    [4-9].*)
			dflt=$may_fcntl;;
		    *)
			dflt=n;;
		 esac
            else
		dflt=$may_fcntl
	    fi
	    ;;
	esac

    if $test "$uname_os" = "Darwin"; then
        echo "Macs don't have a working fcntl, disabling fcntl locking."
        d_fcntlock="$undef"
    else
	    rp="Would you like to use fcntl style mail spool locking? [$dflt]"
	    $echo $n "$rp $c"
	    . myread
	    case "$ans" in
	    y*) d_fcntlock="$define";;
	    *)  d_fcntlock="$undef";;
	    esac
	fi
	
    fi
else
    d_dotlock="$define"
    echo 'Dot lock style locking will be used'
fi

: now get the host name
if $test "$autohostname" != "$undef" -o "$hostname" = "" ; then
    autohostname="$define"
    echo " "
    echo "Figuring out host name..."
    echo 'Maybe "hostname" will work...'
    if ans=`sh -c hostname 2>&1` ; then
	hostname=$ans
	phostname=hostname
    else
	echo 'No, maybe "uuname -l" will work...'
	if $test -n "$uuname" && ans=`sh -c "$uuname -l" 2>&1` ; then
	    hostname=$ans
	    phostname="$uuname -l"
	else
	    echo 'Strange.  Maybe "uname -n" will work...'
	    if $test -n "$uname" && ans=`sh -c "$uname -n" 2>&1` ; then
		hostname=$ans
		phostname="$uname -n"
	    else
	        if ans=`cat /etc/systemid 2>&1` ; then
		    hostname=$ans
		    phostname='cat /etc/systemid'
		    echo "Well, I'll use the systemid file anyway..."
		else
		    case "$hostname" in
		      '') echo "Does this machine have an identity crisis or something?"
			  phostname=''
		      ;;
		      *)  echo "Well, you said $hostname before...";;
		    esac
	        fi
	    fi
	fi
    fi
else
    echo "Last time you said the hostname was $hostname"
fi
: you do not want to know about this
set $hostname
hostname=$1

: translate upper to lower if necessary
case "$hostname" in
    *[A-Z]*)
	hostname=`echo $hostname | tr '[A-Z]' '[a-z]'`
	echo "(Normalizing case in your host name)"
	;;
esac

: verify guess
if $test "$hostname" ; then
    dflt=y
    echo 'Your host name appears to be "'$hostname'".'
    $echo $n "Is this correct? [$dflt] $c"
    rp="Sitename is $hostname? [$dflt]"
    . myread
    case "$ans" in
      y*)  ;;
      *)      hostname='' ;;
    esac
fi

: bad guess or no guess
while $test "X$hostname" = X ; do
    dflt=''
    rp="Please type the (one word) name of your host:"
    $echo $n "$rp $c"
    . myread
    hostname="$ans"
    autohostname="$undef"
done

echo " "
case "$hostname" in
*.*)
    hostdom=`$expr "X$hostname" : "X[^.]*\(\..*\)"`
    case "$mydomain" in
	'')
	    dflt="$hostdom"

	    : default is not dummydomain
	    d_dummydomain="$undef"
	    ;;
	*)  dflt="$mydomain"

	: perhaps $dummydomain ?
	    
	if $test "$dflt" != "$hostdom" ; then
	    cat <<EOF
You told last time that your domain name is "$dflt", using this.
Hostname "$hostname" gives "$hostdom" as domain name (ignoring).
EOF
	fi
	
	;;
    esac
	
    hostname=`$expr "X$hostname" : "X\([^.]*\)\."`
    echo "(Trimming domain name from host name--host name is now $hostname)"
    ;;
*)  case "$mydomain" in
	'') 
	    if ans=`sh -c dnsdomainname 2>&1` ; then
		if $test "X$ans" = X ; then
		    echo "(dnsdomainname -command returned empty domain name)"
		    dflt='.localdomain'
		    
		    d_dummydomain="$define"
		    dummydomain="$dflt"
		    
		else
		    echo "(Got domainname with dnsdomainname -command: $ans)"
		    dflt=".$ans"

		    : default is not dummydomain
		    d_dummydomain="$undef"
		fi
	    else
		dflt='.localdomain'
		d_dummydomain="$define"
		dummydomain="$dflt"		
	    fi
	    ;;
    '.localdomain')
	dflt="$mydomain"
	case "$d_dummydomain" in
	    '')
		d_dummydomain="$define"
		dummydomain="$dflt"
		;;
	esac
	
	;;
	*) dflt="$mydomain"
	   
	   : default is not dummydomain
	   d_dummydomain="$undef"
	   ;;
    esac
    ;;
esac

case "$d_dummydomain" in
    '')
	d_dummydomain="$undef"
	dummydomain=""
	;;
esac

rp="What is your domain name? [$dflt]"
$echo $n "$rp $c"
. myread
case "$ans" in
'') ;;
.*) ;;
*) ans=".$ans";;
esac
mydomain="$ans"

: a little sanity check here
case "$phostname" in
'') ;;
*)  case `$phostname` in
    $hostname$mydomain|$hostname) ;;
    *)
	case "$phostname" in
	sed*)
	    echo "(That doesn't agree with your whoami.h file, by the way.)"
	    ;;
	*)
	    echo "(That doesn't agree with your $phostname command, by the way.)"
	    ;;
	esac
	phostname=''
	;;
    esac
    ;;
esac

: see if there is a whoami file
echo " "
if $test -r /usr/include/whoami.h ; then
    d_whoami="$define"
    echo "whoami.h found."
else
    d_whoami="$undef"
fi

: see if there is a sysexits.h file
echo " "
if $test -r /usr/include/sysexits.h ; then
    i_sysexits="$define"
    echo "sysexits.h found."
else
    i_sysexits="$undef"
fi

: see if there is a stdint.h file
echo " "
if $test -r /usr/include/stdint.h ; then
    i_stdint="$define"
    echo "stdint.h found."
else
    i_stdint="$undef"
fi

: see if there is a poll.h file
echo " "
if $test -r /usr/include/poll.h ; then
    d_poll="$define"
    echo "poll.h found."
else
    d_poll="$undef"
fi

: see if there is sys/select.h file
echo " "
i_sys_select=`loc sys/select.h "" /usr/include $includepath`
if $test -n "$i_sys_select" ; then
    i_sys_select="$define"
    echo "<sys/select.h> found."
else
    i_sys_select="$undef"
fi

: see if select exists
set select d_select
eval $inlibc

case "$i_sys_select$d_select" in
    "$define$define")
	echo "Both select() and <sys/select.h> found. Good."	
	;;
    *define*)
	$echo $n "Either select() and <sys/select.h> found. Testing ... $c"

	$cat > try_select.c <<'EOF'
#include <sys/select.h>	

int main (argc,argv)
   int argc;
   char * argv[];
{
    fd_set write_set;
    int r;

    FD_ZERO(&write_set);
    FD_SET(1,&write_set);   /* stdout writable */

    r = select(2,0,& write_set,0,0);
    if (-1 == r)
         return 1;
	
     return 0;      /* OK */
}
EOF
	rmlist="$rmlist  try_select.c try_select try.log";
	if $cc $ccflags -o try_select  try_select.c  >try.log 2>&1
	then
	    $echo $n "compilation succeed ... $c"
	    if ./try_select
	    then
		echo "Both select() and <sys/select.h> available. Good."
		i_sys_select="$define"
		d_select="$define"
	    else
		echo "No both select() and <sys/select.h> available. Test failed"
	    fi	    
	else
	    echo "No both select() and <sys/select.h> available. Compilation failed"
	fi
	;;
esac

: see if there is a mman file
echo " "
X1=0
if $test -r /usr/include/sys/mman.h ; then
    echo "Found <sys/mman.h>"
    echo " "
    X1=t
elif $test "$uname_os" = "Linux" ; then
    X1=t
    echo "Assuming <sys/mman.h>"
    : I give up, use compiler testing
fi
 if [ "$X1" = t ] ; then
    $echo $n "Testing if mmap() works ... $c"
$cat > mmap.c <<EOF
#include <stdio.h>
#include <stdlib.h>

#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/mman.h>

#ifndef MAP_FAILED
#define MAP_FAILED    (void *)(-1)
#endif

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif 

int main (argc,argv)
   int argc;
   char * argv[];
{
   int s = getpagesize();
   int fd = open("Testfile",O_RDONLY);

   void * result = mmap(0,s,PROT_READ,MAP_SHARED,fd,0);

   if (result == MAP_FAILED) {
       return 1;
   } 
   return 0;
}
EOF

    cp mmap.c Testfile
    if $cc $ccflags -o mmap mmap.c && ./mmap ; then
       echo "Yes, it does."
       d_mmap="$define"
   else
       echo "NO -- mmap seems not work."
       d_mmap="$undef"
   fi
   rmlist="$rmlist mmap.c Testfile mmap"
else
    d_mmap="$undef"
fi

: see if there is a socket and detdb file
echo " "
X1=0
if $test -r /usr/include/sys/socket.h ; then
    echo "sys/socket.h found"
    X1=t
elif $test "$uname_os" = "Linux" ; then
    X1=t
    echo "Assuming <sys/socket.h>"
    : I give up, use compiler testing
fi
if [ "$X1" = t ] ; then
    $echo $n "Testing if socket() works ... $c"
    $cat > socket.c <<EOF
#include <stdio.h>
#include <stdlib.h>

#include <sys/socket.h>
#include <sys/un.h>

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif 

int main (argc,argv)
   int argc;
   char * argv[];
{
     int fd = socket(AF_UNIX, SOCK_STREAM, 0);
    
      if (-1 == fd) {
       return 1;
   } 
   return 0;
}
EOF
    if $cc $ccflags -o socket socket.c && ./socket ; then
       echo "Yes, unix socket does."
       d_have_socket="$define"
   else
       echo "NO -- unix socket seems not work."
       d_have_socket="$undef"
   fi
   rmlist="$rmlist socket socket.c"
else
    d_have_socket="$undef"
fi

if $test "$d_have_socket" = "$define" ; then
    $echo $n "Testing if getsockopt(...,SOL_SOCKET,SO_ERROR,...,...)  works ... $c"

    $cat > so_error.c <<EOF
#include <stdio.h>
#include <stdlib.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif 

int main (argc,argv)
   int argc;
   char * argv[];
{
     int fd = socket(AF_UNIX, SOCK_STREAM, 0);
     int error = 0;
     socklen_t len = sizeof (error);    

     if (-1 == fd) {
        return 1;
     }

     if (-1 == getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len)) {
        return 1;
     }

     return 0;
}
EOF
    if $cc $ccflags -o so_error so_error.c && ./so_error ; then
       echo "Yes, getsockopt(...SO_ERROR...) probably does."
       d_have_soerror="$define"
     else
       echo "NO -- getsockopt(...SO_ERROR...) seems not work."
       d_have_soerror="$undef"
    fi
    rmlist="$rmlist  so_error so_error.c"
else
    d_have_soerror="$undef"
fi

if $test "$d_have_socket" = "$define" ; then
    $echo $n "Testing if getsockname() compiles ... $c"
    $cat > getsockname.c <<EOF
#include <stdio.h>
#include <stdlib.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif 

int main (argc,argv)
   int argc;
   char * argv[];
{
     int fd = socket(AF_UNIX, SOCK_STREAM, 0);
 
     union {
       struct sockaddr s;
       struct sockaddr_un sun;
       char path[256];          
     } addr;
     SOCKLEN addrlen = sizeof addr;

     if (-1 == fd) {
        return 1;
     }
    
      if (-1 ==  getsockname(fd,&(addr.s),&addrlen)) {
         perror("getsockname fails");
         return 1;
      }

      return 0;
}
EOF
    getsockname_socklen=none
    
    for socklen in socklen_t int; do
	if [ "$getsockname_socklen" = none ] ; then
	    $echo $n " ($socklen) $c" 
	    if $cc $ccflags -DSOCKLEN=$socklen -o getsockname getsockname.c 2> getsockname.err ; then
		if ./getsockname ; then
		    getsockname_socklen=$socklen
		    $echo $n " OK $c"
		else 
		    $echo $n " (compiles, test FAIL) $c"
		fi
	    fi
	fi
    done

    if [ "$getsockname_socklen" != none ] ; then
	echo "Yes, getsockname() with $getsockname_socklen as length type probably does."
	d_have_getsockname="$define"
    else
	echo "NO --  getsockname()  seems not work."
	d_have_getsockname="$undef"
	cat  getsockname.err
    fi
    rmlist="$rmlist  getsockname getsockname.c getsockname.err"
else
    d_have_getsockname="$undef"
fi
    
if $test -r /usr/include/netdb.h; then
    i_netdb="$define"
    echo "netdb.h found"

    : see if getaddrinfo exists
    set getaddrinfo d_addrinfo 
    eval $inlibc

    if $test "$d_addrinfo" = "$define" ; then
	$echo $n "Testing getaddrinfo() with AI_ADDRCONFIG ... $c"

	$cat > try_addrinfo.c <<EOF
#$d_strings STRINGS

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>

#ifdef STRINGS
#include <strings.h>
#else
#include <string.h>
#endif

#include <netinet/in.h>

#if defined(__STDC__)
int main (int argc, char * argv[]);
#else

#ifndef const
#define const
#endif
#endif

int main (argc,argv)
    int argc;
   char * argv[];
{
    struct addrinfo * ai = NULL;
    struct addrinfo hints;
    int status;
    int R = 0;
    
    if (argc != 2) {
	fprintf(stderr, "Usage: %s <domain>\n",argv[0]);
	return 2;
    }

    memset(&hints, 0, sizeof(hints));
		    
#ifdef AI_ADDRCONFIG
   hints.ai_flags      = AI_ADDRCONFIG;
#else
   hints.ai_flags      = 0;
   printf(" no AI_ADDRCONFIG ");
   fflush(stdout);

    R=3;  /* failure */
#endif


    hints.ai_family     = AF_UNSPEC    /* Allow IPv4 or IPv6 */;
    hints.ai_socktype   = SOCK_STREAM;    
    hints.ai_protocol   = IPPROTO_TCP;
    hints.ai_flags	= AI_CANONNAME;
    hints.ai_addr       = NULL;
    hints.ai_next       = NULL;

    status =  getaddrinfo(argv[1],"0",&hints,&ai);

    if (0 != status || !ai) {
	printf(" %s failed: %s ",argv[1],gai_strerror(status));
	fflush(stdout);

	return 1;  /* failure */
    } 

   
    return R; /* succeed? */

}
EOF

	if $cc $ccflags -o try_addrinfo try_addrinfo.c > try_addrinfo.log 2>&1 
	then
	    $echo $n " compilation succeed ... $c"

	    if ./try_addrinfo localhost
	    then
	        echo "OK."
		d_addrconfig="$define"
	    else
		echo " ... Failed."
		d_addrconfig="$undef"	       
	    fi

	else
	    echo " compilation failed!"

	    cat try_addrinfo.log
	    d_addrconfig="$undef"
	    : getaddrinfo is still assumed to be available
	fi

	rmlist="$rmlist try_addrinfo try_addrinfo.c  try_addrinfo.log"

    fi

    : see if getnameinfo exists
    set getnameinfo d_getnameinfo 
    eval $inlibc

    

else
    i_netdb="$undef"
    d_addrinfo="$undef"
    d_getnameinfo="$undef"
    d_addrconfig="$undef"
fi
if $test -r /usr/include/netinet/in.h; then
    i_netinet_in="$define"
    echo "netinet/in.h found"

    $echo $n "Testing if netinet/in.h includes sockaddr_in6 ... $c"

       $cat > try_in6.c <<EOF

#include <netinet/in.h>
#if defined(__STDC__)
int main (int argc, char * argv[]);
#else

#ifndef const
#define const
#endif
#endif

struct in6_addr zero_sin6_addr;

int main (argc,argv)
   int argc;
   char * argv[];
{
     struct sockaddr_in6  sin6;

     sin6.sin6_family    = AF_INET6;
     sin6.sin6_port      = 0;
     sin6.sin6_flowinfo  = 0;
     sin6.sin6_addr      = zero_sin6_addr;
     
     return 0; /* succeed */
}
EOF
       if $cc $ccflags -o try_in6 try_in6.c > try6.log 2>&1 &&  ./try_in6 ; then
	   echo " OK"
	   d_have_in6="$define"
       else
	   echo " not available"  
	   d_have_in6="$undef"
       fi

       rmlist="$rmlist try_in6.c try_in6 try6.log"
	   
else
    i_netinet_in="$undef"
    d_have_in6="$undef"
fi
if  $test "$d_have_in6" = "$define" ; then
     $echo $n "Testing if struct sockaddr_in6 includes sin6_scope_id ... $c"

       $cat > try_scope.c <<EOF

#include <netinet/in.h>
#if defined(__STDC__)
int main (int argc, char * argv[]);
#else

#ifndef const
#define const
#endif
#endif
int main (argc,argv)
   int argc;
   char * argv[];
{
     struct sockaddr_in6  sin6;

     sin6.sin6_scope_id   = 0;
     
     return 0; /* succeed */
}
EOF

       if $cc $ccflags -o try_scope try_scope.c > try6s.log 2>&1 &&  ./try_scope ; then
	   echo " OK"
	   d_have_scope="$define"
       else
	   echo " not available"  
	   d_have_scope="$undef"
       fi

       rmlist="$rmlist try_scope.c try_scope try6s.log"

else
    d_have_scope="$undef"
fi

if $test -r /usr/include/ifaddrs.h; then
    echo "ifaddrs.h found"

    : see if getifaddrs exists
    set  getifaddrs d_ifaddrs
    eval $inlibc

    : On Solaris getifaddrs exists on libsocket,
    : this is not currently tested 


    case "$d_ifaddrs" in
	"$define")  cat <<EOM

The  getifaddrs() function lists the network interfaces of system. Should
interface addresses added to "mailname" global elm.rc variable?

You can use global elm.rc variable 
    name-resolution = +getifaddrs
or  name-resolution = -getifaddrs

EOM
	    case "$d_usegetifaddrs" in
	    "$define")  dflt=y;;
	    "$undef")   dflt=n;;
		*)      dflt=y;;
	    esac

	    rp="Should getifaddrs() used to populate \"mailname\" global elm.rc variable? [$dflt]"
	    echo $n "$rp $c"
	    . myread

	    case "$ans" in
		y*) d_usegetifaddrs="$define";;
		*) d_usegetifaddrs="$undef" ;;
	    esac
	    ;;

	*) d_usegetifaddrs="$undef" ;;
    esac

   
else
    d_ifaddrs="$undef"
    d_usegetifaddrs="$undef"
fi

if $test -r /usr/include/net/if.h; then
    echo "net/if.h found"
    i_net_if="$define"

    : see if if_nameindex exists
    set  if_nameindex d_nameindex
    eval $inlibc

    if $test "$d_have_scope" = "$define" -a \
	"$d_nameindex" = "$define"
    then
	 cat <<EOM
The sin6_scope_id on struct sockaddr_in6 gives scope
id for IPv6 address. That is used on link local addresses.
Some systems scope id for link local address is interface
index as used on if_nameindex, if_indextoname and if_nametoindex.

You can use elm.rc variable 
    ipv6-scope-id = -link-local-if-index
or  ipv6-scope-id = +link-local-if-index
or  ipv6-scope-id = -auto
or  ipv6-scope-id = +auto

Do sin6_scope_id contain interface index for link
local addresses ? You can use "auto" as answer.

EOM
	 case "$scope_id_default" in
	     "0L")                                      dflt=n;;
	     "FLAGVAL(scope_auto_flag)")                dflt=a;;
	     "FLAGVAL(scope_link_local_if_index_flag)") dflt=y;;
	     *)
		 if $test "$uname_os" = "Linux"; then
		     dflt=y
		 elif $test "$d_ifaddrs" = "$define"; then
		     dflt=a
		 else
		     dflt=n
		 fi
		 ;;
	 esac

	 d_ipv6_scope_id="$define"	 
	 rp="IPv6 scope id is interface index on link local addresses (yes/no/auto) ? [$dflt]"
	 $echo $n "$rp $c"
	 . myread

	 case "$ans" in
	     n*)   scope_id_default="0L";;
	     a*)   scope_id_default="FLAGVAL(scope_auto_flag)";;
	     y*)   scope_id_default="FLAGVAL(scope_link_local_if_index_flag)";;
	     *) 
		 echo "Default value for ipv6-scope-id is not set"
		 d_ipv6_scope_id="$undef"
		 scope_id_default=''
		 ;;
	 esac

	 if $test "$d_ifaddrs" = "$undef" -a \
	     "$scope_id_default" = "FLAGVAL(scope_auto_flag)"
	 then
	     echo "ipv6-scope-id = auto is not supported"
	     d_ipv6_scope_id="$undef"
	 fi


    else
	d_ipv6_scope_id="$undef"
    fi

else
    i_net_if="$undef"
    d_nameindex="$undef"
    d_ipv6_scope_id="$undef"
fi

if $test -r /usr/include/arpa/inet.h; then
    i_arpa_inet="$define"
    echo "arpa/inet.h found"
else
    i_arpa_inet="$undef"
fi

if  $test "$d_have_socket" = "$define" \
  -a "$i_arpa_inet" = "$define"; then
     $echo $n "Testing if inet_ntop and inet_pton can be used ... $c"

    $cat > inet_try.c <<EOF
#$d_strings STRINGS

#ifdef STRINGS
#include <strings.h>
#else
#include <string.h>
#endif

#include <sys/socket.h>
#include <arpa/inet.h>

#if defined(__STDC__)
int main (int argc, char * argv[]);
#else

#ifndef const
#define const
#endif

#endif

int main (argc,argv)
   int argc;
   char * argv[];
{
    struct in_addr X;
    char source[] = "1.2.3.4";
    const char * res;
    char target[INET_ADDRSTRLEN];

    /* Return 1 on succeed */

    if (inet_pton(AF_INET,source,&X) < 1) {
        /* -1 --- errno set */
        /*  0 --- string not valid network address */

        return 1;      /* failure */
    }

    res = inet_ntop(AF_INET,&X,target,sizeof target);
    if (!res) {
        return 1;      /* failure */
    }

    if (0 == strcmp(res,source)) {
        return 0; /* succeed */
    }

    return 1;      /* failure */

}
EOF
    
    if $cc $ccflags -o inet_try inet_try.c >/dev/null 2>&1 &&  ./inet_try ; then
	echo " OK"
	d_use_xtox_pn="$define"
    else
	echo " not available"  
	d_use_xtox_pn="$undef"
    fi
   
    rmlist="$rmlist inet_try.c inet_try"

else
    d_use_xtox_pn="$undef"
fi


if $test "$d_have_socket" = "$define" -a "$i_netinet_in" = "$define" \
 -a "$i_arpa_inet" = "$define"; then

    $echo $n "Testing if inet_aton can be used ... $c"
    $cat > try.c <<'EOF'
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{
    struct in_addr X;

    if (inet_aton("1.2.3.4",&X)) {
	return 0; /* succeed */
    }
    return 1;      /* failure */
}
EOF
	rmlist="$rmlist try.c try"

    if $cc $ccflags -o try try.c >/dev/null 2>&1 &&  ./try ; then
	echo " OK"
	d_use_aton="$define"
    else
	echo " not available"  
	d_use_aton="$undef"
    fi
   
else
   d_use_aton="$undef"
fi

if $test -r /usr/include/dirent.h; then
    d_directory="$define"
    d_directyry_type="USE_DIRENT"
    echo "dirent.h found"
elif $test -r /usr/include/sys/dir.h; then
    d_directory="$define"    
    d_directyry_type="USE_SYSDIR"
    echo "sys/dir.h found"
else
    d_directory="$undef"
    d_directyry_type=""
    echo "Neither dirent.h or sys/dir.h found"
fi

: see if there is a inttypes file
echo " "
if $test -r /usr/include/inttypes.h ; then
    i_inttypes="$define"
    echo "inttypes.h found."

	case "$d_nointtypes" in
		"$define") dflt=y;;
		"$undef")  dflt=n;;
		*)         dflt=n;;
	esac

    echo "In some systems (such as IRIX 5.3, but not in IRIX 6.2) "
    echo "including of inttypes.h causes error (types defined also "
    echo "in sys/types.h)"
    echo " "

    rp="Avoid including inttypes.h [$dflt]"
    $echo $n "$rp $c"
    . myread

    case "$ans" in
	[Yy]*)	
		d_nointtypes="$define"
		;;
	*)
		d_nointtypes="$undef"
    esac

else
    i_inttypes="$undef"
    d_nointtypes="$undef"
fi


: see how we will look up host name
echo " "
d_douname="$undef"
d_gethname="$undef"

if $contains '^gethostname$' libc.list >/dev/null 2>&1 ; then
    echo "gethostname() found."
    d_gethname="$define"

    $cat <<EOF

You can use global elm.rc variable 
    name-resolution = +gethostname
or  name-resolution = -gethostname

EOF
fi

if $contains '^uname$' libc.list >/dev/null 2>&1 ; then
    echo "uname() found."
    d_douname="$define"

    $cat <<EOF

You can use global elm.rc variable 
    name-resolution = +uname
or  name-resolution = -uname
EOF
fi

case "$d_douname$d_gethname" in
*define*)
    ;;
*)
    $cat <<EOT
 
There is no gethostname() or uname() on this system.  
You must define it in the global elm.rc file in the library directory 
to specify hostname, hostfullname and hostdomain.

EOT
    rp="[Type carriage return to continue]"
    echo $n "$rp $c"
    . myread
    ;;
esac

: /etc/mailname is Debian specific
:     http://www.debian.org/doc/manuals/debian-reference/ch06.en.html#_the_mail_address_configuration
echo " "
if $test "$mailname_file" = "" ; then
    mailname_file=/etc/mailname
fi
case "$d_mailname"  in
    "$define") ;;
    "$undef")  ;;
    *) 
	if $test -f /etc/debian_version -o -f "$mailname_file" ; then
	    d_mailname="$define"
	else
	    d_mailname="$undef"
	fi
	;;
esac
case "$d_mailname"  in
    "$define")
	$cat <<EOF

The $mailname_file gives the visible mail name of the system. The file 
contains only one line describing the fully qualified domain name that 
the program wishing to get the mail name should use (that is, everything 
after the @).

The file /etc/mailname is Debian specific. 

Should $mailname_file be used for the first value of "mailname" global elm.rc 
variable?

You can use global elm.rc variable 
    name-resolution = +mailname-file
or  name-resolution = -mailname-file

EOF
	case "$d_usemailname" in
	    "$define")  dflt=y;;
	    "$undef")   dflt=n;;
	    *) 
		if $test -f /etc/debian_version ; then
		    dflt=y
		else
		    dflt=n
		fi
		;;
	esac

	rp="Should $mailname_file be used? [$dflt]"
	$echo $n "$rp $c"
	. myread
	case "$ans" in
	    y*) d_usemailname="$define";;
	    *)  d_usemailname="$undef" ;;
	esac

	;;
    *)
	d_usemailname="$undef"
esac

: see if there is a strerror
set strerror d_strerror
eval $inlibc

if $test "$d_strerror" = "$define" ; then	

    cat <<EOM

Elm would like to use the systems strerror() for error messages.

EOM
    d_errlst="$undef"

else

: see if errlst.o is in the lib.
echo " "
case "$d_errlst" in
"$define") dflt=y;;
"$undef")  dflt=n;;
*)	   if $contains '^errlst$' libc.list >/dev/null 2>&1 ; then
		echo "errlst object found, will attempt to use systems"
		echo "sys_nerr and sys_errlist"
		dflt=y
	    elif $contains '^sys_errlist$' libc.list >/dev/null 2>&1 ; then
		echo "sys_errlist found, will attempt to use systems"
		echo "sys_nerr and sys_errlist"
		dflt=y
	    else
		echo "neither errlst object nor sys_errlist found, $package will use its own"
		dflt=n
	    fi;;
esac

cat <<EOM

Elm would like to use the systems definitions of the error messages for system
errors.  These are usually contained in the global variables sys_errlist[] and
sys_nerr.  If these do not exist, there is a standard list built into Elm.

EOM

rp="Does the system support the sys_errlist[] global variable? [$dflt]"
$echo $n "$rp $c"
. myread
case "$ans" in
    y*) d_errlst="$define";;
    *)  d_errlst="$undef" ;;
esac

fi

: see if fstruncate exists
set ftruncate d_ftruncate
eval $inlibc

: see if getopt exists
set getopt d_getopt
eval $inlibc

if [ "$d_getopt" = "$define" ] 
then
    $echo ' '

    : Can getopt used ?
    case "$d_getopt_type" in
	GETOPT_BROKEN)
	    dflt=n;
	    d_getopt_type=
	    ;;

	GETOPT_OK) 
            dflt=y
	    d_getopt_type=
	    ;;
	*)

	    $echo $n "Testing your getopt routines ... $c"
	    d_getopt_type=n
	    dflt=GETOPT_BROKEN
	    $cat > try.c <<'EOF'
#include <unistd.h>
#include <stdio.h>

char OPTION_LETTERS[] = "Gd:w:I:S:Mcr:";

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{
    int c;

     while ((c = getopt(argc, argv, OPTION_LETTERS)) != EOF) {
	 /* xxx */
     }
     
     optind = 1;     /* Reset scanning */
     
     while ((c = getopt(argc, argv, OPTION_LETTERS)) != EOF) {
	switch(c) {
           case 'I' :
	   puts(optarg);
        }
     }
    
     return 0;      /* OK */
}
EOF
    rmlist="$rmlist try.c try"

	    if $cc $ccflags -o try try.c >/dev/null &&  
		result=`./try -G -I UGH -w aaa -S zzz -S yyy -S bbb fail`
	    then
		case "$result" in
		    UGH)
			echo "Scanning can perhaps be restarted."
			dflt=y
			;;
		    *)
			echo "Thest gives bad result: $result"
			;;
		esac
	    else
		echo " Compile or run failed"
	    fi

	    
	    ;;
    esac

    case "$d_getopt_type" in
	GETOPT_BROKEN|GETOPT_OK) 
	    ;;
	*)

	    cat <<EOH

Some libraries does not allow resetting scanning of argument vector 
with getopt() be setting optind = 1. In that case using of system
version of getopt() causes that installation fails.

EOH
	    rp="Can system version of getopt() scan argument vector twice? [$dflt]"

	    $echo $n "$rp $c"
	    . myread
	    case "$ans" in
		y*) d_getopt_type=GETOPT_OK;;
		*)  d_getopt_type=GETOPT_BROKEN;;
	    esac
	    ;;
    esac

else
   d_getopt_type=""
fi


pwdinsys=`loc pwd.h "" /usr/include $includepath`
if $test -z "$pwdinsys"; then
	d_pwdinsys="$define"
else
	d_pwdinsys="$undef"
fi

: index or strcpy
echo " "
case "$d_index" in
"$define") dflt=n;;
*) 
	: strchr is on ANSI C
	if $contains __STDC__ Cppsym.true libc.list >/dev/null 2>&1; then
	     dflt=n
	else
	     dflt=y
	fi
;;
esac
if $contains '^index$' libc.list >/dev/null 2>&1 ; then
    if $contains '^strchr$' libc.list >/dev/null 2>&1 ; then
	if $contains strchr "$strings" >/dev/null 2>&1 ; then
	    if $contains index "$strings" >/dev/null 2>&1 ; then
		
		:  has index, strchr, and index and strchr in strings.h
		
		echo "Your system has both index() and strchr().  Shall I use"
		rp="index() rather than strchr()? [$dflt]"
		$echo $n "$rp $c"
		. myread
		case "$ans" in
		    n*) d_index="$define" ;;
		    *)  d_index="$undef" ;;
		esac
	    else
		
		:  has index, strchr, and strchr in strings.h
		
		d_index="$define"
	        echo "strchr() found."
	    fi
	else
	    
	    :  has index, strchr, and no strchr in strings.h
	    d_index="$undef"
	    echo "index() found."
	fi
    else
	:     has only index, no strchr, strings.h is a moot point
	d_index="$undef"
	echo "index() found."
    fi
else
    if $contains '^strchr$' libc.list >/dev/null 2>&1 ; then
	d_index="$define"
	echo "strchr() found."
    else
	echo "No index() or strchr() found!"
	d_index="$undef"
    fi
fi



case "$d_mmdf" in
"$define") dflt=y;;
"$undef")  dflt=n;;
*)	if $test -f "$submit"; then
	    dflt=y
	else
	    dflt=n
	fi
	;;
esac
$cat <<EOM
 
Some systems run MMDF as their Mail Transport Agent.  MMDF uses a
different way of delimiting messages in the mailbox files.  Other
systems don't run MMDF but use the MMDF separator in their mailbox
files.  The MMDF separator is usually a series of four Control A's.
$package needs to know if this system uses the MMDF style message
separator in its mailbox files.

EOM
rp="Does this system use MMDF style message separator? [$dflt]"
$echo $n "$rp $c"
. myread
case "$ans" in
y*) d_mmdf="$define";;
*)  d_mmdf="$undef";;
esac

: BSD Sendmail installs itself either /usr/sbin/sendmail, /usr/lib/sendmail
: or /usr/ucblib/sendmail, prefer that over other locations
if [ -x /usr/sbin/sendmail ] ; then
	sendmail=/usr/sbin/sendmail
	echo "BSD(?) sendmail is on $sendmail"
elif [ -x  /usr/lib/sendmail ] ; then
	sendmail=/usr/lib/sendmail
	echo "BSD(?) sendmail is on $sendmail"
elif [ -x /usr/ucblib/sendmail ] ; then
	sendmail=/usr/ucblib/sendmail
	echo "BSD(?) sendmail is on $sendmail"
fi 
: determine mail delivery agent for Elm to use
case "$mailer" in
'')
    if $test "$d_mmdf" = "$define" -a -f "$execmail"; then
 	dflt="$execmail"
    elif $test "$d_mmdf" = "$define" -a -f "$submit"; then
	dflt="$submit"
    elif $test -f "$sendmail"; then
	dflt="$sendmail"
    else
	echo
	echo "WARNING: Unable to found mailer (normally sendmail)."
	echo 	
	dflt=none
    fi
    ;;
*)  dflt="$mailer";;
esac
cont=true
while $test "$cont" ; do
    $cat <<EOM

Give the full path name of the program used to deliver mail on your
system. Give value "none" if that mailer should be given on run 
time on global elm.rc (variable mailer) instead. 

EOM
    rp="Preferred mail delivery agent: [$dflt]"

    $echo $n "$rp $c"
    . myread
    mailer="$ans"
    if $test "$mailer" = none; then
	echo
	echo "OK. Specify mailer on global elm.rc instead. For example: "
	echo "mailer = sendmail; path=/usr/sbin/sendmail"
	echo
	cont=''
    elif $test -f "$ans"; then
	cont=''
    else
	if $test "$fastread" = yes; then
	    dflt=y
	else
	    dflt=n
	fi
	echo "Mail delivery agent $ans doesn't exist."
	rp="Use that name anyway? [$dflt]"
	$echo $n "$rp $c"
	. myread
	dflt=''
	case "$ans" in
	y*) cont='';;
	esac
    fi
done

sendmail_version=''

case "$mailer" in
    */sendmail)
        $echo $n "Testing Sendmail version for $mailer... $c"
	sendmail_version="`$mailer < /dev/null -d0 -bv root | $grep '^Version'| $sed 's/Version //;'`"
	if $test "$sendmail_version" != "" ; then
	    $echo "OK (Sendmail $sendmail_version)"
	    sendmail="$mailer"
	else
	    $echo "NOT Sendmail"
        fi
	;;
esac

mailer_test_pattern="-bv root"
mailer_bv_ok="$undef"
     
case "$sendmail_version" in
    [1-9]*)
    $echo $n "Testing if $mailer -bv root works... $c"
    if $mailer -bv root < /dev/null >/dev/null; then
	echo "Good"
        mailer_bv_ok="$define"
    else
	echo "Nope -- will use sending of mail to $USER instead on tests!"
	mailer_test_pattern="$USER"
    fi
    ;;
esac

if $test "$sendmail" != "" ; then
    echo "Default path for mailer=sendmail is $sendmail (selected mailer is $mailer)"
fi

: check for ispell spelling checker
case "$d_ispell" in
"$define")	dflt=y
		dflt_path=$ispell_path
		dflt_options=$ispell_options
		;;
"$undef")	dflt=n
		dflt_path=
		dflt_options=
		;;
*)	if $test -n "$ispell" -a "$ispell" != "ispell"; then
	    dflt=y
	    dflt_path=$ispell
	    dflt_options='-x'
	else
	    dflt=n
	    dflt_path=
	    dflt_options=
	fi
	;;
esac
$cat <<EOM
 
Elm has the ability to place a call to the ispell spelling checker
on its post-message-entry/pre-message-send menu.
EOM
if $test -n "$dflt_path"; then
	$echo "Configure has found ispell as $dflt_path"
else
	$echo "Configure was unable to find ispell"
fi

$echo $n "Should Elm add the ispell option to the pre-send menu? [$dflt] $c"
rp="Should Elm add the ispell option to the pre-send menu? [$dflt]"
. myread
case "$ans" in
y*) d_ispell="$define";;
*)  d_ispell="$undef";;
esac

case "$d_ispell" in
"$undef")	ispell_path=
		;;
"$define")	cont=true
		dflt=$dflt_path
		while $test "$cont" ; do
		    echo " "
		    echo "Give the name of the ispell program on your"
		    $echo $n "system: [$dflt] $c"
		    rp="Ispell path name: [$dflt]"
		    . myread
		    ispell_path=$ans;
		    if $test "$ans" = none; then
			echo
			echo "Canceling adding of ispell option to the pre-send menu"
			ispell_path=
			d_ispell="$undef"
			cont=''
		    elif $test -f "$ans"; then
			cont=''
		    else
			lookup=`loc "$ans" "" . $pth`
			if $test -f "$lookup"; then
			    cont=''
			    ispell_path=$lookup
			else
			    if $test "$fastread" = yes; then
				dflt=y
			    else
				dflt=n
			    fi
			    echo "spelling program $ans doesn't exist."
			    rp="Use that name anyway? [$dflt]"
			    $echo $n "$rp $c"
			    . myread
			    dflt=''
			    case "$ans" in
				y*) cont='';;
			    esac
			fi
		    fi
		done
esac

case "$d_ispell" in
"$define")	dflt=$dflt_options
		$echo $n "What options should Elm use with $ispell_path: [$dflt] $c"
		rp="$ispell_path options: [$dflt]"
		. myread
		ispell_options=$ans;
		case "$ispell_options" in
		'none') ispell_options=''
		     ;;
		esac
		;;
esac

: see if locale.h is in /usr/include
echo " "
dflt=`loc locale.h "" /usr/include $includepath`
if $test -z "$dflt"; then
	echo "locale.h not found, $package will not call setlocale"
	i_locale=$undef

else
	echo "locale.h found, $package will call setlocale"
	i_locale=$define
fi

if [ "$i_locale" = "$define" ] ; then

    $cat <<EOF

Assuming that isprint() works for non-ASCII characters 
because locale support (setlocale()) exists.

Skipping test of "ctype" conversion routines and 
using standard system "ctype" conversions because
Elm's replacement routines are US-ASCII only and
there was locale() support provided by system.

EOF

    d_ascii="$undef"
    d_broke_ctype="$undef"

    rp="[Type carriage return to continue]"
    $echo $n "$rp $c"
    . myread
    echo " "

    dflt=`loc langinfo.h "" /usr/include $includepath`
    if $test -z "$dflt"; then
	echo "langinfo.h not found, no nl_langinfo(CODESET) support"
	have_codeset="$undef"
    else
	echo "langinfo.h found, testing nl_langinfo(CODESET) support ..."

	$cat > try_langinfo.c <<'EOF'

#include <stdio.h>
#include <langinfo.h>

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{
    char * c = nl_langinfo(CODESET);

    if (!c) 
	return 1;
  
    printf("%s\n",c);
    return 0;
}

EOF

	rmlist="$rmlist try_langinfo try_langinfo.c  try.log  result_charset try2.log"

	if $cc $ccflags -o try_langinfo try_langinfo.c $libs > try.log 2>&1 &&
	    ./try_langinfo > result_charset 2> try2.log 
	then
	    cs="`cat result_charset`"
	    if [ "$cs" != "" ] ; then

		echo "nl_langinfo(CODESET) seems work, charset for C locale is $cs"
		have_codeset="$define"
		
		case "$cs" in
		    646)      : SunOS
			ascii_codeset="$cs"
			echo "Setting ASCII_CODESET to $ascii_codeset"
			;;
		    ANSI_X3.4-1968)
			ascii_codeset="$cs"
			echo "Setting ASCII_CODESET to $ascii_codeset"
			;;
                    US-ASCII)
                        ascii_codeset=""
                        ;;
                    ISO*)
                        ascii_codeset=""
                        ;;
                    *)
                        echo "WARNING: Unexpected charset for C locale"
                        sleep 5
                        ;;
                  esac
	    else

		echo "nl_langinfo(CODESET) seems exists, but did not return charset for default locale"
		have_codeset="$undef"
	    fi
	else
	    echo "nl_langinfo(CODESET) failed"
	    have_codeset="$undef"
	fi

   fi

    dflt=`loc wchar.h "" /usr/include $includepath`
    if $test -z "$dflt"; then
	echo "wchar.h not found, no native wide char support"
       d_wchar="$undef"

    else
	echo "wchar.h found"

       dflt=`loc wctype.h "" /usr/include $includepath`
       if $test -z "$dflt"; then
	   echo "wctype.h not found, no native wide char support"
           d_wchar="$undef"

       else
	   echo "wctype.h found, testing wide char support ..."

	$cat > try_wchar.c <<'EOF'

#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <wctype.h>

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{
     int i;
     mbstate_t a;

     wchar_t   c;
     size_t    r;

     wchar_t   buffer1[10];
     const char *ptr;

     char      buffer2[10];
     const wchar_t *ptr2;


     i = iswprint(L'a');
     if (!i) {
          fprintf (stderr, "iswprint(L'a') returned 0\n");
          return 1;
     }
     i = iswprint(L' ');
     if (!i) {
          fprintf (stderr, "iswprint(L' ') returned 0\n");
          return 1;
     }

     i = iswprint(L'\n');
     if (i) {
          fprintf (stderr, "iswprint(L'\\n') returned %d\n",i);
          return 1;
     }

     i = iswcntrl(L'\n');
     if (!i) {
          fprintf (stderr, "iswcntrl(L'\\n') returned 0\n");
          return 1;
     }

     memset(&a, 0, sizeof(a));

     r = mbrtowc(&c,"E", 1, &a);

     if (1 != r) {
          fprintf (stderr, "mbrtowc(&c,\"E\", 1, &A); returned %d\n",r);
          return 1;
     }
     if (c != L'E') {
         fprintf (stderr, "mbrtowc(&c,\"E\", 1, &A); converted to %lc\n",c);
         return 1;
     }


     memset(&a, 0, sizeof(a));

     ptr = "ELM";
     r = mbsrtowcs(buffer1,&ptr,10,&a);
     if (r != 3) {
          fprintf (stderr, "mbsrtowcs(buffer1,&ptr,10,&a) returned %d\n",r);
          return 1;
     }
     if (ptr != NULL) {
          fprintf (stderr, "mbsrtowcs(buffer1,&ptr,10,&a) did not set ptr to NULL\n");
          return 1;
     }

     i = wcscmp(buffer1,L"ELM");
     if (0 != i) {
          fprintf (stderr, "wcscmp(buffer1,L\"ELM\") returned %d\n",i);
          return 1;
     }

     memset(&a, 0, sizeof(a));
     ptr2  = L"ELM";

     r = wcsrtombs(buffer2,&ptr2,sizeof buffer2,&a);
     if (r != 3) {
          fprintf (stderr, "wcsrtombs(buffer2,&ptr2,sizeof buffer2,&a) returned %d\n",r);
          return 1;
     }
     if (ptr2 != NULL) {
          fprintf (stderr, "wcsrtombs(buffer2,&ptr2,sizeof buffer2,&a) did not set ptr2 to NULL\n");
          return 1;
     }

     i = strcmp(buffer2,"ELM");
     if (0 != i) {
          fprintf (stderr, "strcmp(buffer2,\"ELM\") returned %d\n",i);
          return 1;
     }

     printf("Wide character support tests succeed.\n");
     return 0;
}

EOF

	rmlist="$rmlist  try_wchar try_whcar.c  try.log try2.log"

	if $cc $ccflags -o try_wchar try_wchar.c $libs > try.log 2>&1 &&
	    ./try_wchar 2> try2.log 
	then
           echo "System supports native wide characters."
           d_wchar="$define"
        else
	   echo "System seems not support native wide characters"
	   d_wchar="$undef"	 
        fi

      fi
   fi

   if $test "$d_wchar" = "$define" ; then

	echo "wide char support available, testing wcwidth() support"

	$cat > try_wcwidth.c <<'EOF'

#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <wctype.h>

int wcwidth(wchar_t c);

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{
   int i;

     i = wcwidth(L'\0');

     if (0 != i) {
          fprintf (stderr, "wcwidth(L'\\0') returned %d  (0 expected)\n",
                   i);
          return 1;
     }

     i = wcwidth(L'a');

     if (1 != i) {
          fprintf (stderr, "wcwidth(L'a') returned %d  (1 expected)\n",
                   i);
          return 1;
     }


     printf("wcwidth() support tests succeed.\n");
     return 0;
}
EOF

	rmlist="$rmlist try_wcwidth try_wcwidth.c try.log try2.log"

     if $cc $ccflags -o try_wcwidth try_wcwidth.c $libs > try.log 2>&1 &&
	    ./try_wcwidth 2> try2.log 
     then
           echo "System supports wcwidth()."
           d_wcwidth="$define"
     else
	   echo "System seems not support wcwidth()"
	   d_wcwidth="$undef"	 
     fi

   else
      d_wcwidth="$undef"
   fi


else

    # If we do not have local support, we can not have nl_langinfo(CODESET) support
    have_codeset="$undef"

    : If we do not have local support, we can not have wchar support
    d_wchar="$undef"
    d_wcwidth="$undef"

    : check to see if the macros are 8-bit clean, ask the user
    $cat <<EOM

Not all environments are restricted to the ASCII 7-bit character set.
For example, the ISO 8859/1 (Latin alphabet no. 1) character set,
consisting of 8 bits and 191 printable characters, is becoming
more and more common, especially in non-English speaking countries.

Unfortunately, not all isprint() functions or macros, which ELM
uses to determine whether a character is printable or not, will
handle non-ASCII (8-bit) characters properly.  It is suggested that you
start with this value configured to handle 8-bit characters correctly
and if there are problems with Elm aborting while displaying messages
that use extended character sets to reconfigure Elm to only display
7-bit characters.

EOM

    case "$d_ascii" in
	"$define")   dflt='n';;
	*)  dflt='y';;
    esac

    echo "  "
    rp="Should Elm assume that isprint() won't break on non-ASCII characters? [$dflt]"
    $echo $n "$rp $c"
    . myread
    case "$ans" in
	y*) d_ascii="$undef";;
	*) d_ascii="$define";;
    esac

    : check for broken toupper/tolower
    $echo ' '
    case "$d_broke_ctype" in
    "$define") ;;
    "$undef") ;;
    *)
	$echo "Testing your \"ctype\" conversion routines..."
	d_broke_ctype="$define"
	$cat >try.c <<'EOF'
#include <stdio.h>
#include <ctype.h>
#define my_tolower(c)	(isupper(c) ? (c) - 'A' + 'a' : (c))
#define my_toupper(c)	(islower(c) ? (c) - 'a' + 'A' : (c))

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{
    int i;
    for (i = 1 ; i <= 0x7F ; ++i) {
	if (my_tolower(i) != tolower(i) || my_toupper(i) != toupper(i))
		return 1;
    }
    return 0;
}
EOF
	rmlist="$rmlist try try.c core"

	$cc $ccflags -o try try.c >/dev/null 2>&1 \
	    && ./try >/dev/null 2>&1 && d_broke_ctype="$undef"

	;;
    esac
    case "$d_broke_ctype" in
    "$define")	$echo "Using our own \"ctype\" conversions." ;;
    "$undef")	$echo "Using standard system \"ctype\" conversions." ;;
    esac

fi

: see if catgets is in the libraries
set catgets d_msgcat
eval $inlibc

: also catgets needs nl_types.h
dflt=`loc nl_types.h "" /usr/include $includepath`

if $test "$d_msgcat" = "$define" -a ! -z "$dflt" ; then
	echo "Message catalog routines and nl_types.h found"
	i_nl_types="$define"

	if $test -f "$gencat" ; then 
	    echo "System gencat command $gencat found"
	else
	    echo "WARNING: System gencat command not found!"
	    echo
	    sleep 1
	fi

else
	echo "Message catalog routines or nl_types.h not found, $package will use its own"
	d_msgcat="$undef"
	i_nl_types="$undef"
fi

: see if malloc is void * or char *
echo " "
case "$d_mallocvoid" in
"$define") dflt=y;;
"$undef")  dflt=n;;
*)	
	    cat >usemymalloc.c <<'END'

#if defined(__STDC__) || defined(_AIX)
# define ANSI_C 1
#endif

#ifdef ANSI_C
# include <stdlib.h>
#else
#include <malloc.h>
#endif
#include <stdlib.h>
void *malloc();
END

	if $cc $ccflags -c usemymalloc.c >/dev/null 2>&1; then
	    d_mallocvoid=$define
	    echo "Your system wants malloc to return void *, it would seem."
	else
	    d_mallocvoid=$undef
	    echo "Your system wants malloc to return char *, it would seem."
	fi
	;;
esac
echo " "

case "$d_mboxedit" in
"$define") dflt=y;;
"$undef")  dflt=n;;
*)	dflt=n;;
esac
$cat <<EOM
 
A lot of sites that install the Elm Mail System find that the function
e)dit mailbox from within Elm is dangerous and confusing.  If you choose,
you can instead disable that function, with the program being slightly
smaller and presenting an appropriate error message to the user if they
try to e)dit their mailbox.

EOM
rp="Would you like to enable the e)dit mailbox function? [$dflt]"
$echo $n "$rp $c"
. myread
case "$ans" in
y*) d_mboxedit="$define";;
*)  d_mboxedit="$undef";;
esac

: see if memcpy exists
set memcpy d_memcpy
eval $inlibc

$cat <<EOM

MIME allows for sending and receiving of Messages compliant to the
Multipurpose Internet Mail Extension (RFC 1341). MIME provides a way to
attach binary, graphic, audio, video, postscript and other files. MIME
doesn't necessarily need graphics capabilities on your display, but its
useful.

Elm ME+'s MIME support may use internal parser to read mailcap files. 
Mailcap files tells how certain MIME types are handled. Also Nathaniel 
Borenstein's  metamail package uses mailcap files for same purpose.

Elm ME+'s MIME support  would not depend on the Nathaniel Borenstein's metamail 
package, but you would not be able to use some MIME features as long as you 
don't have metamail installed.  

Elm ME+ ask user before calling metamail, when  global elm.rc or per 
user elmrc variable prompt-metamail is set. That is default.

If you don't have metamail, you can tell that metamail should not be used. 
This is configuration option.

This can be changed also on global elm.rc or on per user elmrc 
(variable metamail).

EOM

rp="[Type carriage return to continue]"
$echo $n "$rp $c"
. myread

case "$defsystemcharset" in
'') defsystemcharset="US-ASCII";;
*) defsystemcharset="$defsystemcharset";;
esac

case "$metamail_path" in
'') if test -f "$metamail" ; then
	dflt="$metamail"
	echo
        echo "Metamail program found from $metamail"
    else
        dflt='none'
    fi
   ;;
*) dflt="$metamail_path"
   ;;
esac


cat <<EOM

If you have installed Nathaniel Borenstein's metamail package for
displaying MIME messages, Elm ME+ can make use of it.  Alternatively
Elm ME+ can consult mailcap -files directly. If you didn't
have metamail installed you might obtain a copy of it.  

This version (Elm ME+) does not use Metamail's companion programs 
(such as mmencode) directly, but metamail package supposes that
companion programs are installed to search path.
  
What is the compile time default path for metamail?
Possible values include:
	none		Don't call metamail
	metamail	Call metamail if environment variable \$NOMETAMAIL
			is not set.
	/path		Call metamail via that path, if it is executable
  
EOM
cont=true
while $test "$cont" ; do
	rp="Default path for metamail? [$dflt]"
	$echo $n "$rp $c"
	. myread
	case "$ans" in
		none|metamail)
			metamail_path="$ans"
	    		cont=''
		;;
		/*)
			if $test -f "$ans"; then
		                metamail_path="$ans"	
	    			cont=''
			else
	    			if $test "$fastread" = yes; then
					dflt=y
	    			else
					dflt=n
	    			fi
	    			rp="File $ans doesn't exist.  Use that name anyway? [$dflt]"
	    			$echo $n "$rp $c"
				savedAns="$ans"
	    			. myread
	    			case "$ans" in
	    				y*) 
					metamail_path="$savedAns"
					cont='';;
	    			esac
			fi
		;;
		*)
			metamail_path="$ans"
		;;
	esac
done

if $test d_ascii = "$define" ; then
    $cat <<EOF

System have ASCII only "ctype" routines. Will set
US-ASCII as System Character Set for MIME routines.

EOF
	defsystemcharset="US-ASCII"
else
    if [ "$i_locale" = "$define" ] ; then
	$cat <<EOF

System supports multiple character sets or languages. 
Name of character set used by "ctype" ruotines is
determined from locale's LC_CTYPE via elm.mimecharsets 
file on elm's library directory. 
EOF

    if [ "$have_codeset" = "$define" ] ; then
		$cat <<EOF
Also codeset name returned by nl_langinfo(CODESET)
is used to determine (MIME) name of character set.
EOF
    fi

	$cat <<EOF

In case of that locale name does not found from 
elm.mimecharsets file, what is used as Default System Character Set? 

However instead of Default System Character Set environment 
variable \$MM_CHARSET is tried first if it is set (and 
\$NOMETAMAIL is not set) in case of that locale name does not 
found from elm.mimecharsets file.

Normally Default System Character Set should be US-ASCII.
EOF

	dflt="$defsystemcharset"
	rp="Default System Character Set? [$dflt]"
    else
	$cat <<EOF

System does not support multiple character sets or languages.
What is name of System Character Set used by "ctype" routines?

System Character Set is overriden by environment variable
\$MM_CHARSET if it is set (and \$NOMETAMAIL is not set.)
 
That also can be changed by setting character set name on 
elm.mimecharsets file for locale "NONE".

EOF

	dflt="$defsystemcharset"
	rp="System Character Set [$dflt]"
    fi

	$echo $n "$rp $c"
	. myread
	defsystemcharset="$ans"

fi

test_it=n
if $test "$mailer" != none; then
    case "$d_8bitmime" in
	"$define") dflt=y
	   test_it=y
	   ;;
	"$undef") dflt=n;;
	*)  
	    case "$sendmail_version" in
	    8.*|9.*|10.*)
		test_it=y
		;;
	    *)
		dflt=n
		rp="Can I test if your mailer supports -B8BITMIME -option? [$dflt]"
		$echo $n "$rp $c"
		. myread
		case "$ans" in
		    y*) 
		    test_it=y
		    ;;
		esac
		;;
	    esac

	    if $test $test_it = y ; then
		echo "Testing if your mailer supports -B8BITMIME ..."

		$cat >test.mailer <<EOF
Subject: Testing $mailer

Running $mailer -B8BITMIME $mailer_test_pattern 
EOF

		if $mailer -B8BITMIME $mailer_test_pattern >/dev/null < test.mailer
		then
		    echo "Yup. Option -B8BITMIME perhaps works."
		    echo "(Sendmail 8.6 will accept but ignore that option.)"
		    case "$sendmail_version" in
			8.6*)
			    dflt=n
			    ;;

			*)
			    dflt=y
			    ;;
		    esac
		else
		    echo "Seems that option -B8BITMIME does not work."
		    dflt=n
		fi
		rm test.mailer
	    fi
	    ;;
       esac
fi

if $test $test_it = y ; then
    cat <<EOM

If your MTA (Mail transport Agent) supports 8BITMIME ESMTP -extension
and accepts also option -B8BITMIME (that is BODYTYPE=8BITMIME), Elm
can left doing encoding from 8bit to quoted_printable to MTA. Otherwise
Elm does encoding of 8bit data itself. Sendmail version 8.7 supports
8BITMIME -extension.

EOM
    rp="MTA supports -B8BITMIME -option? [$dflt]"
    $echo $n "$rp $c"
    . myread
    case "$ans" in
	y*) d_8bitmime="$define";;
    *)  d_8bitmime="$undef";;
    esac
else
    d_8bitmime="$undef"
fi

: If mailer don't support 8BITMIME it also don't support BINARYMIME
case "$d_8bitmime" in
"$define")

case "$d_binarymime" in
"$define") dflt=y;;
"$undef") dflt=n;;
*)  
if $test "$sendmail_version" != "" ; then
	echo " "
	echo "Testing if your mailer supports -BBINARYMIME ..."

		$cat >test.mailer <<EOF
Subject: Testing $mailer

Running $mailer -BBINARYMIME $mailer_test_pattern
EOF

	if $mailer -BBINARYMIME $mailer_test_pattern >/dev/null <test.mailer
        then
		echo "Yup. Option -BBINARYMIME perhaps works."
		echo "(Is there really MTA what supports BINARYMIME?)"
		dflt=y
	else
		echo "Seems that option -BBINARYMIME does not work."
		dflt=n
	fi
        rm test.mailer

else
	echo "Can't figure how to test if your mailer supports -BBINARYMIME ..."
	dflt=n
fi
;;
esac

cat <<EOM

If your MTA (Mail transport Agent) supports BINARYMIME ESMTP -extension
and accepts also option -BBINARYMIME (that is BODYTYPE=BINARYMIME), Elm
can left doing encoding from BINARY to base64 or quoted-printabe to MTA. 
Otherwise Elm does encoding of binary data itself. Passing of binary data
requires that all text data lines are terminated with CRLF -- Unix's
LF is NOT sufficient. Currently ELM don't use CRLF as line terminator
in every places when using -BBINARYMIME option (so that option is only
partially implemented by Elm). Notice also that isn't known any MTA (mailer)
what implements BINARYMIME or accepts -BBINARYMIME option. Notice also
that BINARYMIME is Experimental Protocol (as stated in RFC1830).

EOM
rp="MTA supports -BBINARYMIME -option? [$dflt]"
$echo $n "$rp $c"
. myread
case "$ans" in
y*) d_binarymime="$define";;
*)  d_binarymime="$undef";;
esac

;;
*) d_binarymime="$undef";;
esac

test_it=n
if $test "$mailer" != none; then
    case "$d_dsn" in
	"$define") dflt=y
		   test_it=y
		   ;;
	"$undef") dflt=n;;
	*)  
	    case "$sendmail_version" in
		8.*|9.*|10.*)
		    test_it=y
		    ;;
		*)
		    dflt=n
		    rp="Can I test if your mailer supports DSN options: -N -R -V? [$dflt]"
		    $echo $n "$rp $c"
		    . myread
		    case "$ans" in
			y*) 
			    test_it=y
			    ;;
		    esac
		    ;;
	    esac

	    if $test $test_it = y ; then
		echo " "
		echo "Testing if your mailer supports DSN options: -N -R -V ..."

		$cat >test.mailer <<EOF
Subject: Testing $mailer

Running $mailer -N success -R hdrs -V zzz $mailer_test_pattern 
EOF

		if $mailer -N success -R hdrs -V zzz $mailer_test_pattern  >/dev/null <test.mailer
		then
		    echo "Yup. Options -N succees -R hdrs -V zzz perhaps works."
		    dflt=y
		else
		    echo "Seems that options -N succees -R hdrs -V zzz does not work."
		    dflt=n
		fi
		rm test.mailer
	    fi
	    ;;
    esac
fi

if $test $test_it = y ; then
    cat <<EOF
If your MTA (Mail transport Agent) supports DSN ESMTP -extension
(Delivery Status Notification) and accepts also options:
	-N success,failure,delay/never        
	-R hdrs/full                              for RET= -paramater
	-V ...                                    for ENVID= -paramater
Elm can use them. Sendmail 8.8 supports this (sendmail 8.7 supports
ESMTP DSN, but it is not available via command line options).
EOF
    rp="MTA supports DSN via options -N -R -V ? [$dflt]"
    $echo $n "$rp $c"
    . myread
    case "$ans" in
    y*) d_dsn="$define";;
    *)  d_dsn="$undef";;
    esac
else
    d_dsn="$undef"
fi

: ask about PGP support
case "$d_pgp" in
"$define")
	dflt=y
	;;
"$undef")
    	dflt=n
	;;
*)
    if $test "$pgp" != pgp ; then
	dflt=y
    elif $test "$gpg" != gpg ; then
        dflt=y
    else
	dflt=n
    fi
    ;;
esac
if $test "$pgp2_path" = "" -o "$pgp5_dir" = ""; then
	case "$pgp" in
	    /*)
		case "`$pgp -h 2>/dev/null|$head -1`" in
		    *"PGP 2."*)
			pgp2_path="$pgp"
                        pgp5_dir=none
			;;
		    *)
		        pgp2_path=none
			pgp5_dir="`$dirname $pgp`"
			;;
	        esac
	    ;;
	    *)
		pgp2_path="none"
		pgp5_dir="none"
	    ;;
       esac
fi
if $test "$gpg_path" = "" ; then
    case "$gpg" in
	/*)
	    gpg_path="$gpg"
	;;
	*)
	    gpg_path=none
	;;
    esac
fi	    
echo ''
echo <<EOF
Elm can use pgp (Pretty Good Privacy encryption system) or
gpg (GnuPG - The GNU Privacy Guard) for processing PGP mails.

EOF
rp="Should PGP support be compiled in? [$dflt]"
$echo $n "$rp $c"
. myread
if test "$ans" = "y"; then
	d_pgp="$define"
	cat <<EOM

What is the compile time default path for pgp 2?
Possible values include:
	none		Don't call pgp 2
	/path		Call pgp 2 via that path, if it is executable
If you use pgp 5 or gpg instead, answer "none" to this question.
EOM
	cont=true
	dflt="$pgp2_path"
	while $test "$cont"; do
                rp="Where is the pgp 2.6 binary located? [$dflt]"
		echo $n "$rp $c"
		. myread
		pgp2_path="$ans"
		case "$ans" in
		none)
			pgp2_path=none
			cont=''
			;;
		/*)
			if $test -f $ans; then
				cont=''
			else
				if $test "$fastread" = yes; then
					dflt=y
				else
					dflt=n
				fi
				rp="File $ans doesn't exist.  Use that name anyway? [$dflt]"
				echo $n "$rp $c"
				. myread
				case "$ans" in
				y*) cont='';;
				esac
			fi
			;;
		*)
			echo "Please give the full pathname."
			;;
		esac
	done
	cat <<EOM

What is the compile time default directory for pgp 5 binaries?
Possible values include:
	none		Don't call pgp 5
	/path		Call pgp 5 binaries from that directory
If you use pgp 2 or gpg instead, answer "none" to this question.
EOM
	cont=true
	dflt="$pgp5_dir"
	while $test "$cont"; do
                rp="Where is the pgp 5 binaries located? [$dflt]"
		echo $n "$rp $c"
		. myread
		pgp5_dir="$ans"
		case "$ans" in
		none)
			pgp5_dir=none
			cont=''
			;;
		/*)
			if $test -d $ans; then
				cont=''
			else
				if $test "$fastread" = yes; then
					dflt=y
				else
					dflt=n
				fi
				rp="Directory $ans doesn't exist.  Use that name anyway? [$dflt]"
				echo $n "$rp $c"
				. myread
				case "$ans" in
				y*) cont='';;
				esac
			fi
			;;
		*)
			echo "Please give the full directory name."
			;;
		esac
	done
	cat <<EOM

What is the compile time default path for gpg?
Possible values include:
	none		Don't call gpg
	/path		Call gpg via that path, if it is executable
If you use pgp 2 or pgp 5 instead, answer "none" to this question.
EOM
	cont=true
	dflt="$gpg_path"
	while $test "$cont"; do
                rp="Where is the gpg 1.0 binary located? [$dflt]"
		echo $n "$rp $c"
		. myread
		gpg_path="$ans"
		case "$ans" in
		none)
			gpg_path=none
			cont=''
			;;
		/*)
			if $test -f $ans; then
				cont=''
			else
				if $test "$fastread" = yes; then
					dflt=y
				else
					dflt=n
				fi
				rp="File $ans doesn't exist.  Use that name anyway? [$dflt]"
				echo $n "$rp $c"
				. myread
				case "$ans" in
				y*) cont='';;
				esac
			fi
			;;
		*)
			echo "Please give the full pathname."
			;;
		esac
	done
else
	d_pgp="$undef"
fi


: ask about newmail running in the background automatically
case "$d_newauto" in
"$define")	dflt=y;;
"$undef")	dflt=n;;
*)		dflt=y;;
esac
$cat <<EOM

Newmail (Elm's utility to check for incoming mail) can be configured to
either run as a foreground process or as a process that automatically
forks and runs in the background.

EOM
rp="Should newmail automatically run in the background? [$dflt]"
$echo $n "$rp $c"
. myread
case "$ans" in
y*) d_newauto="$define";;
*)  d_newauto="$undef";;
esac

if $test "$mailer" != none; then

    if $test -f "$sendmail"; then
	    echo "You're running sendmail.  Suggesting noaddfrom; no usedomain"
	    S_noaddfrom="$define"
	    S_usedomain="$undef"
    elif $test -f "$submit"; then
	    echo "You're running submit with MMDF.  Suggesting no noaddfrom; usedomain"
	    S_noaddfrom="$undef"
	    S_usedomain="$define"
    elif $test -f "$execmail" -a "$d_mmdf" = "$define"; then
	    echo "You're running execmail with MMDF.  Suggesting no noaddfrom, no usedomain"
	    S_noaddfrom="$undef"
	    S_usedomain="$undef"
    else
	    S_noaddfrom="$undef"
	    S_usedomain="$define"
    fi

    if $test "$d_usedomain" = "" ; then
        d_usedomain="$S_usedomain"
    fi
    if $test "$d_noaddfrom" = "" ; then
        d_noaddfrom="$S_noaddfrom"
    fi

    case "$d_usedomain" in
	"$define") dflt=y;;
	"$undef")  dflt=n;;
	*)	   dflt=y;;
    esac
    
    $cat <<EOM
	
Are you running a machine where you want to have a domain name appended
to the hostname on outbound mail?

EOM

    rp="Would you like the domain name appended? [$dflt]"
    $echo $n "$rp $c"
    . myread
    case "$ans" in
	y*) d_usedomain="$define";;
	*)  d_usedomain="$undef";;
    esac

    case "$d_noaddfrom" in
	"$define") dflt=y;;
	"$undef")  dflt=n;;
	*)	   dflt=n;;
    esac
    echo " "
    rp="Does your mailer add the From: header for you? [$dflt]"
    $echo $n "$rp $c"
    . myread
    case "$ans" in
	    y*) d_noaddfrom="$define";;
	*)  d_noaddfrom="$undef";;
    esac

else
    : If mailer is none, user needs anyway define these on elm.rc

    d_noaddfrom="$undef"
    d_usedomain="$define"
fi

case "$d_noxheader" in
"$define") dflt=y;;
"$undef")  dflt=n;;
*)	dflt=n;;
esac
$cat <<EOM
 
Some sites do not like to see the mail header "X-Mailer:" in outgoing
messages.  If you choose, you may disable these headers.  However, it
is strongly urged to leave these headers in the mail to assist in
tracking down problems.

You can use global elm.rc variable 
   program-identification = +X-Mailer
or program-identification = -X-Mailer

EOM
rp="Would you like to disable the X-Mailer: headers? [$dflt]"
$echo $n "$rp $c"
. myread
case "$ans" in
y*) d_noxheader="$define";;
*)  d_noxheader="$undef";;
esac

: check for "kill(pid, 0)"
echo " "
case "$d_pidcheck" in
"$define")	;;
"$undef")	;;
*)
	    echo "Checking to see if kill(pid, 0) works..."
	    $cat >try.c <<'EOCP'
#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{
	int	pid, status0, status9;

	if ((pid = fork()) == 0)
		{
		sleep(30);
		return 1;
		}
	status0 = kill(pid, 0);
	status9 = kill(pid, 9);
	return(status0 == status9);
}
EOCP
	rmlist="$rmlist  try.c try.o try"

	if $cc try.c -o try >/dev/null 2>&1 ; then
		if try >/dev/null 2>&1 ; then
		    echo "Your system does not support kill(pid, 0)..."
		    d_pidcheck="$undef"
		else
		    d_pidcheck="$define"
		    echo "Your system supports kill(pid, 0)..."
		fi
	    else
		echo "Your system does not support kill(pid, 0)..."
		d_pidcheck="$undef"
	fi

	;;
esac

: see if /usr/include/sys/ptem.h exists, making it a possible System V/386
d_ptem="$undef"
if usg ; then
    echo " "
    echo "Checking to see if your system has sys/ptem.h..."
    if $test -f /usr/include/sys/ptem.h ; then
        echo "Yep, it does..."
        if "$contains" "struct winsize" /usr/include/sys/ptem.h >/dev/null 2>&1 ; then
	    d_ptem="$define"
	    echo "  and it has the needed structure."
	fi
    fi
fi

: see if there is a putenv
set putenv d_putenv
eval $inlibc

: get remove at last flag and number of lock attempts
$cat <<EOM

First, how many times should the Elm check for the removal of the lock
file before giving up? (After that many tries lock file is removed
if it more that 10 minutes old (and mailbox is not accessed) 
EOM

case "$maxattempts" in
    '') dflt=6;;
    *)  dflt=$maxattempts;;
esac
cont=true
while $test "$cont" ; do
    echo " "
    rp="Number of lock attempts: [$dflt]"
    $echo $n "$rp $c"
    . myread
    maxattempts="$ans"
    if $test "$maxattempts" -lt 3 -o "$maxattempts" -gt 10 ; then
	echo "The recommended range is 3-10"
	odflt=$dflt
	dflt=n
	rp="Should I use your answer of $maxattempts lock attempts anyway? [$dflt]"
	$echo $n "$rp $c"
	. myread
	dflt=$odflt
	case "$ans" in
	y*) cont='';;
	esac
    else
	cont=''
    fi
done

: determine where mail is spooled
case "$maildir" in
'')
    dflt=`loc . /var/mail /var/mail /usr/mail /var/spool/mail /usr/spool/mail`
    ;;
*)  dflt="$maildir"
    ;;
esac
$cat <<EOF

Give default directory where local incoming mailboxes are located.
You can later alter this with "mailhome-dir" global elm.rc variable.
EOF
cont=true
while $test "$cont" ; do
    echo " "
    rp="Where is yet-to-be-read mail spooled? [$dflt]"
    $echo $n "$rp $c"
    . myread
    maildir=`filexp "$ans"`
    if test -d $maildir; then
	cont=''
    else
	if $test "$fastread" = yes; then
	    dflt=y
	else
	    dflt=n
	fi
	rp="Directory $maildir doesn't exist.  Use that name anyway? [$dflt]"
	$echo $n "$rp $c"
	. myread
	dflt=''
	case "$ans" in
	y*) cont='';;
	esac
    fi
done

: determine the group of the mail directory and what group elm should use
mailgrp=`$ls -lgd $maildir/.`
mailgrp=`$expr "$mailgrp" : "[ld][rwxstS-]*[ 0123456789]*\(.*\)"`
: now mailgrp is either    user group size mon day time/year name
: or                       group size mon day time/year name
try1=`$expr "$mailgrp" : "[A-Za-z_0-9]* *\([A-Za-z_0-9]*\).*"`
try1a=`$expr "$try1" : "\([0-9]*\).*"`
if $test "$try1" = "$try1a"; then
    mailgrp=`$expr "$mailgrp" : "\([A-Za-z_0-9]*\).*"`
else
    mailgrp="$try1"
fi
case "$mailgrp" in
'')
    mailgrp=mail
    ;;
esac
echo " "
echo "Mail group is $mailgrp"

: ask about setgid running of Elm
case "$d_setgid" in
"$define")	dflt=y;;
"$undef")	dflt=n;;
*)		dflt=y;;
esac
cat <<EOM

Elm needs to be installed and run as a setgid program only if the mail
spool directory permissions do not allow world write access.  If your
mail spool directory has the permissions:

drwxrwxr-x  3 root     mail          512 Dec 24 17:20 /usr/mail

then Elm must be setgid to the same group as the mail spool directory
(in this case group mail).  However, if the spool permissions look
like:

drwxrwsrwt  2 root     staff         512 Dec 21 20:14 /usr/spool/mail

then Elm should not be installed or run as a setgid program.

EOM
if test -d $maildir
then
    cat <<EOM
You incoming mail spool $maildir permissions look following:

EOM
    $ls -ld $maildir
    echo " "
fi

rp="Am I going to be running as a setgid program? [$dflt]"
$echo $n "$rp $c"
. myread
case "$ans" in
y*) d_setgid="$define";;
*)  d_setgid="$undef";;
esac
case "$d_setgid" in
"$define")
    mailermode=2755
    ;;
*)  mailermode=755
    ;;
esac

: see if BSD sigset exists
echo " "
set sigset d_sigset
eval $inlibc
: See if sigaction exists -- POSIX has highest priority in match
if $contains sigaction libc.list >/dev/null 2>&1; then
    echo "sigaction() found."
    d_sigaction="$define"
    d_sigset="$undef"
    d_sigvec="$undef"
    d_sigvectr="$undef"
else
    d_sigaction="$undef"
: see if sigvector exists -- since sigvec will match the substring
    if $contains sigvector libc.list >/dev/null 2>&1; then
        echo 'sigvector() found--you must be running HP-UX.'
        d_sigvectr="$define"
        d_sigvec="$define"
    else
: try the original name
        d_sigvectr="$undef"
        if $contains sigvec libc.list >/dev/null 2>&1; then
	    echo 'sigvec() found.'
	    d_sigvec="$define"
        else
	    case "$d_sigset" in
	    "$define")
               echo 'sigvec() not found';;
	    *)
               echo 'sigvec() not found--race conditions with signals may occur.';;
	    esac
            d_sigvec="$undef"
        fi
    fi
fi

: see if sigprocmask exists -- POSIX has highest priority in match
echo " "
if $contains sigprocmask libc.list >/dev/null 2>&1; then
    echo 'sigprocmask() found.'
    d_sigprocmask="$define"
    d_sigblock="$undef"
    d_sighold="$undef"
else
    d_sigprocmask="$undef"
: see if sigblock exists
    if $contains sigblock libc.list >/dev/null 2>&1; then
	echo 'sigblock() found.'
	d_sigblock="$define"
	d_sighold="$undef"
    else
: see if sighold exists
	d_sigblock="$undef"
	if $contains sighold libc.list >/dev/null 2>&1; then
	    echo 'sighold() found.'
	    d_sighold="$define"
	else
	    echo 'No signal masking functions found.'
	    d_sighold="$undef"
	fi
    fi
fi

if $contains waitpid libc.list >/dev/null 2>&1; then
    echo "waitpid() found."
    d_waitpid="$define"
else
    d_waitpid="$undef"
fi

: see if strspn exists
set strspn d_strspn
eval $inlibc

: see if strcspn exists
set strcspn d_strcspn
eval $inlibc

: see if strpbrk exists
set strpbrk d_strpbrk
eval $inlibc

: see if there is a strstr
set strstr d_strstr
eval $inlibc

: see if there is a strtok
set strtok d_strtok
eval $inlibc

case "$d_subshell" in
"$define") dflt=y;;
"$undef")  dflt=n;;
*)	dflt=y;;
esac
$cat <<EOM
 
Some sites wish to disable the usage of the shell escape from Elm.
If you choose, you can disallow subshells from within Elm.

WARNING: This only controls Elm's usage of the ! command.  Any pager
or editor could still allow subshells.  It is also trivial to get a
subshell through manipulation of the pipe command or various option
settings.  DO NOT rely on this as a security measure.

EOM
rp="Would you like to allow the ! command (subshells)? [$dflt]"
$echo $n "$rp $c"
. myread
case "$ans" in
y*) d_subshell="$define";;
*)  d_subshell="$undef";;
esac

: see if symlink exists
set symlink d_symlink
eval $inlibc

: see if tempnam exists
set tempnam d_tempnam
eval $inlibc

: see if setlinebuf exists
set setlinebuf d_setlinebuf
eval $inlibc

: see if this is a termio system
: Prefer POSIX-approved termios.h over all else.
:
echo " "
d_termios="$undef"
d_termio="$undef"
if $test -r /usr/include/termios.h ; then
    set tcsetattr d_termios
    eval $inlibc
fi
if $test "$d_termios" = "$define" ; then
    echo "You have POSIX termios.h... good!"
elif Cppsym pyr ; then
    if $test "`/bin/universe`" = "ucb" ; then
	if $test -r /usr/include/sgtty.h ; then
	    echo "sgtty.h found."
	else
	    echo "System is a pyramid, and universe is bsd,"
	    echo "sgtty.h not found--you could have problems."
	fi
    else
	if $test -r /usr/include/termio.h ; then
	    d_termio="$define"
	    echo "termio.h found."
	else
	    echo "System is a pyramid, and universe is att,"
	    echo "termio.h not found--you could have problems."
	fi
    fi
elif bsd ; then
    if $test -r /usr/include/sgtty.h ; then
	echo "sgtty.h found."
    elif $test -r /usr/include/termio.h ; then
	d_termio="$define"
	echo "termio.h found."
    else
	echo "Neither termio.h nor sgtty.h found--you could have problems."
    fi
else
    if $test -r /usr/include/termio.h ; then
	d_termio="$define"
	echo "termio.h found."
    elif $test -r /usr/include/sgtty.h ; then
	echo "sgtty.h found."
    else
	echo "Neither termio.h nor sgtty.h found--you could have problems."
    fi
fi

: see if getdomainname exists
if $contains "^getdomainname\$" libc.list > /dev/null 2>&1; then
    echo "getdomainname() found"
    d_domname=$define;
elif $contains "^getdomnm\$" libc.list > /dev/null 2>&1; then
    echo "getdomainname() found"
    d_domname=$define;
else
    echo "getdomainname() not found"
    d_domname=$undef
fi

case "$d_domname" in
"$define")	cat <<EOM

The getdomainname system call was found.  When running NIS, this usually
returns the NIS domain and not the host's domain for mail.  If this is the 
case, it should not be used to obtain the host's domain, and the host's 
domain name should be compiled into the code, and the global elm.rc file should
be used to override the compiled in value.

If the getdomainname call does return the correct host's domain name, it can
be used.

You can use global elm.rc variable 
    name-resolution = +getdomainname
or  name-resolution = -getdomainname

EOM
   case "$i_netdb" in
	"$define")
	cat <<EOM
Elm will also try get host's domain name from hostname by gethostbyname().
If that succees either the compiled in value or getdomainname()
are not used.

You can use global elm.rc variable 
    name-resolution = +lookup
or  name-resolution = -lookup

EOM
	 ;;
   esac
		case "$d_usegetdom" in
		"$define")	dflt=y;;
		"$undef")	dflt=n;;
		*)		dflt=n;;
		esac
		echo " "
		rp="Should getdomainname() be used to obtain the mail domain? [$dflt]"
		$echo $n "$rp $c"
		. myread
		case "$ans" in
		y*) d_usegetdom="$define";;
		*)  d_usegetdom="$undef";;
		esac
		;;
*)		d_usegetdom="$undef";;
esac;
: see if we should include time.h, sys/time.h, or both
cat <<'EOM'
  
Testing to see if we should include <time.h>, <sys/time.h> or both.
I'm now running the test program...
EOM
$cat >try.c <<'EOCP'
#ifdef I_TIME
#include <time.h>
#endif
#ifdef I_SYSTIME
#ifdef SYSTIMEKERNEL
#define KERNEL
#endif
#include <sys/time.h>
#endif

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{
    struct tm foo;
#ifdef S_TIMEVAL
    struct timeval bar;
#endif
    if (foo.tm_sec == foo.tm_sec)
	return 0;
#ifdef S_TIMEVAL
    if (bar.tv_sec == bar.tv_sec)
	return 0;
#endif
    return 1;
}
EOCP

rmlist="$rmlist try.c try try.o"

flags=''
for s_timeval in '-DS_TIMEVAL' ''; do
    for d_systimekernel in '' '-DSYSTIMEKERNEL'; do
	for i_time in '-DI_TIME' ''; do
	    for i_systime in '-DI_SYSTIME' ''; do
		case "$flags" in
		'') echo "Trying $i_time $i_systime $d_systimekernel $s_timeval"
		    if $cc $ccflags $i_time $i_systime $d_systimekernel $s_timeval \
			    try.c -o try >/dev/null 2>&1 ; then
			set X $i_time $i_systime $d_systimekernel $s_timeval
			shift
			flags="$*"
			echo "Succeeded with $flags"
		    fi
		    ;;
		esac
	    done
	done
    done
done
case "$flags" in
*SYSTIMEKERNEL*) d_systimekernel="$define";;
*) d_systimekernel="$undef";;
esac
case "$flags" in
*I_TIME*) i_time="$define";;
*) i_time="$undef";;
esac
case "$flags" in
*I_SYSTIME*) i_systime="$define";;
*) i_systime="$undef";;
esac
case "$flags" in
*S_TIMEVAL*) s_timeval="$define";;
*) s_timeval="$undef";;
esac

: see if gettimeofday exists
set gettimeofday d_gettimeofday
eval $inlibc
if $test "$d_gettimeofday" = "$define" -a "$s_timeval" = "$define"; then  
     $echo "Testing suseconds_t ... " 

     $cat >trysuse.c <<'EOF'
#ifdef I_TIME
#include <time.h>
#endif
#ifdef I_SYSTIME
#ifdef SYSTIMEKERNEL
#define KERNEL
#endif
#include <sys/time.h>
#endif

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

struct timeval bar;

int main (argc,argv)
   int argc;
   char * argv[];
{

    SUSECONDS xxx;

    xxx = bar.tv_usec;

    return 0;
}
EOF
    flags=''
    d_suseconds="$undef"

    if $test "$d_systimekernel" = "$define" ; then
	flags="$flags -DSYSTIMEKERNEL"
    fi
    if $test "$i_time" = "$define" ; then
	flags="$flags -DI_TIME"
    fi
    if $test "$i_systime" = "$define" ; then
	flags="$flags -DI_SYSTIME"
    fi
    suseconds=''
    for xx in suseconds_t long; do
	case "$suseconds" in
	    '')
		echo "Trying -DSUSECONDS=$xx"
		if $cc $ccflags $flags "-DSUSECONDS=$xx" trysuse.c \
		    -o trysuse >/dev/null 2>&1 ; then

		    suseconds="$xx"
		    d_suseconds="$define"
		    echo "Succeeded with -DSUSECONDS=$suseconds"
		fi
	    ;;
	esac

    done

    rmlist="$rmlist trysuse.c trysuse.o trysuse"
else
    d_suseconds="$undef"
fi


: see if clock_gettime exists
set  clock_gettime d_clock_gettime
eval $inlibc

: see if utime.h is in includepath
echo " "
i_utime=`loc utime.h "" /usr/include $includepath`
if $test -n "$i_utime"; then
	echo "Found <utime.h>"
	i_utime="$define"
	i_sysutime="$undef"
else
	i_sysutime=`loc sys/utime.h "" /usr/include $includepath`
	if $test -n "$i_sysutime"; then
		echo "Found <sys/utime.h>"
		i_utime="$undef"
		i_sysutime="$define"
	else
		echo "Did not find <utime.h> or <sys/utime.h>"
		i_utime="$undef"
		i_sysutime="$undef"
	fi
fi

: check for utimbuf structure
echo " "
case "$d_utimbuf" in
"$define")	;;
"$undef")	;;
*)
: Pyramid passes the att compile test but still needs the definition
	if Cppsym pyr ; then
	    if $test "`/bin/universe`" = "att" ; then
		d_utimbuf="$undef"
		echo "I will use my 'utimbuf' structure..."
	    else
		d_utimbuf="$define"
		echo "You have the 'utimbuf' structure..."
            fi
	else
	  if $test "$d_utimbuf" != "$define"; then
	      echo "Checking to see if struct utimbuf exists."
	      $cat >try.c <<'EOCP'
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#define far /* to keep Xenix from complaining */
#if (defined(BSD_TYPE) || !defined(apollo))
#  include <sys/file.h>
#endif
#ifdef I_TIME
#  include <time.h>
#endif
#ifdef I_SYSTIME
#  include <sys/time.h>
#endif
#ifdef I_UTIME
#  include <utime.h>
#endif
#ifdef I_SYSUTIME
#  include <sys/utime.h>
#endif

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{
struct utimbuf test;
test.actime = 0;
return  1;
}
EOCP
	      cflags=$ccflags
	      if $test "$i_utime" = "$define"; then
		  cflags="$cflags -DI_UTIME"
	      fi
	      if $test "$i_sysutime" = "$define"; then
		  cflags="$cflags -DI_SYSUTIME"
	      fi
	      if $test "$i_time" = "$define"; then
		  cflags="$cflags -DI_TIME"
	      fi
	      if $test "$i_systime" = "$define"; then
		  cflags="$cflags -DI_SYSTIME"
	      fi
	      if $test "$d_bsd" = "$define"; then
		  cflags="$cflags -DBSD_TYPE"
	      fi
	      if $cc $cflags try.c -o try >/dev/null 2>&1 ; then
		  d_utimbuf="$define"
		  echo "You have the 'utimbuf' structure..."
	      else
		  echo "I will use my 'utimbuf' structure..."
		  d_utimbuf="$undef"
	      fi
	      
	    fi
	fi
	;;
esac

: see if there is a vfork
if Cppsym sgi ; then
    d_vfork="$undef"
else
    set vfork d_vfork
    eval $inlibc
fi

: see if memory.h is in includepath
echo " "
i_memory=`loc memory.h "" /usr/include $includepath`
if $test -n "$i_memory"; then
	echo "Found <memory.h>"
	i_memory="$define"
else
	echo "Did not find <memory.h>"
	i_memory="$undef"
fi

: see if unistd.h is in includepath
echo " "
i_unistd=`loc unistd.h "" /usr/include $includepath`
if $test -n "$i_unistd"; then
	echo "Found <unistd.h>"
	i_unistd="$define"
else
	echo "Did not find <unistd.h>"
	i_unistd="$undef"
fi

rmlist="$rmlist $$.tmp"

: see if signal is declared as pointer to function returning int or void
echo " "
$cppstdin $cppflags < /usr/include/signal.h >$$.tmp
if test "$uname_os" = "OSF1" ; then
    echo "You have void (*signal())()."
    sigtype="void"
elif $contains 'void.*[^s]signal' $$.tmp >/dev/null 2>&1 ; then
    echo "You have void (*signal())() instead of int."
    sigtype="void"
elif $contains 'int.*[^s]signal' $$.tmp >/dev/null 2>&1 ; then
    echo "You have int (*signal())() instead of void."
    sigtype="int"
elif $contains 'extern[ 	]*[(\*]*signal' $$.tmp >/dev/null 2>&1 ; then
    echo "You have int (*signal())() instead of void."
    sigtype="int"
elif $contains 'sigfunc_t.*[^s]signal' $$.tmp >/dev/null 2>&1 ; then
    echo "You have sigfunc_t (*signal())() instead of int."
    sigtype="sigfunc_t"
elif $test -n "$sigtype"; then
    echo $n "As you already told me, signal handlers return $sigtype"
else
    echo "I can't determine whether signal handlers return void or int..."
    echo "I'm assuming they return void like ANSI and POSIX want."
    echo "If not, you will have to change sigtype to match the typedef"
    echo "used by the signal handlers.  Change it config.sh at the edit "
    echo "question at the end of Configure."
    sigtype="void"
fi

: preserve RCS keywords in files with variable substitution, grrr
Log='$Log'
Header='$Header'
 
if $test -n "$prefix" ; then
    case "$prefix" in
	*/)
	    install_prefix="`$expr \"$prefix\" : '\(.*\)/'`"
	    ;;
	*)
	    install_prefix="$prefix"
	    ;;
    esac
    echo
    echo "Will use $install_prefix as installation prefix directory"
    echo
else
    case "$install_prefix" in
	"") dflt=none;;
	*)  dflt="$install_prefix";;
    esac
    $cat <<EOM

All files of $package can be installed under one directory hierarcy.
Give that directory as installation prefix. You can answer "none"
also. On that case directories are asked individually.
 
EOM
    rp="Installation prefix directory? [$dflt]"
    echo $n "$rp $c"
    . myread
    case "$ans" in
	none|"") install_prefix="";;
	*)  
	    install_prefix="`filexp \"$ans\"`"
	    echo
	    echo "Will use $install_prefix as installation prefix directory"
	    echo
	;;
    esac       
fi

: determine where public executables go
case "$bin" in
'')
    dflt=`loc . /bin /usr/local/bin /usr/lbin /usr/local /usr/bin`
    ;;
*)  dflt="$bin"
    ;;
esac

if $test -n "$install_prefix" ; then
    bin="$install_prefix/bin"
    echo "Will install $package public executables to $bin"
else
    cont=true
    while $test "$cont" ; do
	echo " "
	rp="Where do you want to put the public executables? [$dflt]"
	$echo $n "$rp $c"
	. myread
	bin="$ans"
	bin=`filexp $bin`
	if test -d $bin; then
	    cont=''
	else
	    case "$fastread" in
	    yes) dflt=y;;
	    *) dflt=n;;
	    esac
	    rp="Directory $bin doesn't exist.  Use that name anyway? [$dflt]"
	    $echo $n "$rp $c"
	    . myread
	    dflt=''
	    case "$ans" in
		y*) cont='';;
	    esac
	fi
    done
fi

bin_related="`$expr \"$bin\" : '\(.*\)/[^/]*'`"
man_mode=b

if $test -n "$install_prefix" ; then

     $cat <<EOM

Do you want install  unformatted manual pages, formatted manual pages
of both ?

Select
    u) Install unformatted manual pages to $install_prefix/man/man1
    f) Install formatted manual pages to $install_prefix/man/cat1
    b) Install both unformatted and formatted manual pages

EOM
     case "$mansrc!$catmansrc" in
	 $install_prefix/man/man1!$install_prefix/man/cat1)
	     dflt=b;;
	 $install_prefix/man/man1!none)
	     dflt=u;;
	 none!$install_prefix/man/cat1)
	     dflt=f;;
	 *!none)
	     dflt=u;;
	 none!*)
	     dflt=f;;
	 *)
	     dflt=b;;
     esac
	 
     rp="Your selection? [$dflt]"
     $echo $n "$rp $c"
     . myread
     case "$ans" in
	 u*) man_mode=u;;
	 f*) man_mode=f;;
	 b*|*) man_mode=b;;
     esac

    echo
    case "$man_mode" in
	f)  
	    mansrc=none
	    
	    echo "Unformatted manual pages will not be installed"
	    ;;
	b|u|*)
	    mansrc="$install_prefix/man/man1"

	    echo "Will install $package unformatted manual pages to $mansrc"
	    ;;

    esac
    echo
else
    : determine where manual pages go
    $cat <<EOM
  
$package has manual pages that can be installed in unformatted or formatted form.
Either or both (or neither) of these may be installed. 

Please give the location in which to store each type of man page. 
To specify that a particular type is not to be installed, answer "none"
to the question.

EOM
    case "$mansrc" in
    '')
	dflt="$bin_related/man/manl $bin_related/man/man1" 
	dflt="$dflt /usr/man/mann /usr/man/manl /usr/man/man.L /usr/man/local/man1"
	dflt="$dflt /usr/man/l_man/man1 /usr/local/man/u_man/man1"
	dflt="$dflt /usr/local/man/l_man/man1 /usr/man/man1 /usr/man/u_man/man1"
	dflt="$dflt /usr/share/man/man1 /usr/share/man/manl"
	dflt=`loc . none $dflt`
	;;
    *)  dflt="$mansrc"
	;;
    esac
    cont=true
    while $test "$cont" ; do
	echo " "
	rp="Where do the unformatted manual pages go? [$dflt]"
	$echo $n "$rp $c"
	. myread
	mansrc=`filexp "$ans"`
	if $test "$mansrc" = none -o -d "$mansrc"; then
	    cont=''
	else
	    if $test "$fastread" = yes; then
		dflt=y
	    else
		dflt=n
	    fi
	    rp="Directory $mansrc doesn't exist.  Use that name anyway? [$dflt]"
	    $echo $n "$rp $c"
	    . myread
	    dflt=''
	    case "$ans" in
		y*) cont='';;
	    esac
	fi
    done
fi

: determine the extension for man pages
if $test "$mansrc" != none ; then
    case "$manext" in
    '')
	if $test "$manext_choice" = none; then
	    dflt=none
	else
	    case "$mansrc" in
	    *l) dflt=.l ;;
	    *n) dflt=.n ;;
	    *L) dflt=.L ;;
	    *)  dflt=.1 ;;
	    esac
	fi
	;;
    .*)	dflt="$manext";;
    *)  dflt=".$manext";;
    esac

    $cat <<EOM

The installed unformatted manual pages can have various extensions to suit the
conventions of the host operating system, for example "page.1".

Note that the period '.' must be included as part of the extension.

To specify no extension, enter the word "none".

EOM
    rp="What extension should be used on installed unformatted man pages: [$dflt]"
    $echo $n "$rp $c"
    . myread
    manext=$ans
    manext_choice=$ans
    case "$manext" in
    'none')
	manext=''
	;;
    esac
    fi

: Now the formatted man pages ala System V

if $test -n "$install_prefix" ; then

    echo
    case "$man_mode" in
	u)  catmansrc=none
	    
	    echo "Formatted manual pages will not be installed"
	    ;;
	b|f|*)
	    catmansrc="$install_prefix/man/cat1"

	    echo "May install $package formatted manual pages to $catmansrc"
	    ;;
    esac
    echo
else
    case "$catmansrc" in
    '')
	dflt="$bin_related/man/catl $bin_related/man/cat1" 
	dflt="$dflt /usr/man/catn /usr/man/catl /usr/catman/man.L /usr/catman/local/man1"
	dflt="$dflt /usr/local/catman/u_man/man1 /usr/local/catman/l_man/man1"
	dflt="$dflt /usr/catman/l_man/man1 /usr/man/cat1 /usr/catman/man1"
	dflt="$dflt /usr/catman/u_man/man1 /usr/catman/URM/g1"
	dflt="$dflt /usr/share/man/cat1 /usr/share/man/catl"
	dflt=`loc . none $dflt`
	;;
    *)  dflt="$catmansrc"
	;;
    esac
    cont=true
    while $test "$cont" ; do
	echo " "
	rp="Where do the formatted manual pages go? [$dflt]"
	$echo $n "$rp $c"
	. myread
	catmansrc=`filexp "$ans"`
	if $test "$catmansrc" = none -o -d "$catmansrc"; then
	    cont=''
	else
	    if $test "$fastread" = yes; then
		dflt=y
	    else
		dflt=n
	    fi
	    rp="Directory $catmansrc doesn't exist.  Use that name anyway? [$dflt]"
	    $echo $n "$rp $c"
	    . myread
	    dflt=''
	    case "$ans" in
		y*) cont='';;
	    esac
	fi
    done
fi

: if installing formatted manual pages, determine a number of other things.
if $test "$catmansrc" != none ; then
    
    :    determine text processor to use, default to nroff if found.
    case "$manroff" in
    '')
	if $test -f "$nroff"; then
	    dflt="$nroff"
	elif $test -f "$troff"; then
	    dflt=$troff
	elif $test -f "$gtroff"; then
	   dflt=$gtroff
	else
	   dflt=none
	fi
	;;
    *)  dflt="$manroff";;
    esac
    $cat <<EOM

Online manual pages are generally formatted with nroff.  If you use an 
alternate text processor for on-line manual pages it can be specified here. 
Elm expects the text processor to write to standard out.

Note: This does not effect the formatter previously chosen for the Elm
      Elm documentation (Reference Guide, Configuration Guide, etc.).

If you do not want install formatted manual pages to $catmansrc,
you can answer "none".

EOM
    cont=true
    while $test "$cont" ; do
	echo " "
	echo "Give the name of the program used to format on-line manual pages"
	$echo $n "on your system: [$dflt] $c"
	rp="Preferred manual page formatter: [$dflt]"
	. myread
	manroff=$ans;
	if $test "$ans" = none; then
	    echo
	    echo "Canceling installtion of manual pages to $catmansrc"
	    catmansrc=none	    
	    cont=''
	elif $test -f "$ans"; then
	    cont=''
	else
	    lookup=`loc "$ans" "" . $pth`
	    if $test -f "$lookup"; then
		cont=''
		manroff=$lookup
	    else
		if $test "$fastread" = yes; then
		    dflt=y
  		else
  		    dflt=n
  		fi
		echo "Text processor $ans doesn't exist."
		rp="Use that name anyway? [$dflt]"
		$echo $n "$rp $c"
		. myread
		dflt=''
		case "$ans" in
		y*) cont='';;
		esac
	    fi
	fi
    done
fi

if $test "$catmansrc" != none ; then
    : determine text processor flags to use.
    $cat <<EOM

If this text processor requires any options for proper formatting, specify
then here.  To specify no options, enter the word "none".

EOM
    dflt="$manroffopts"
    rp="What options should Elm use with $manroff: [$dflt]"
    $echo $n "$rp $c"
    . myread
    manroffopts=$ans
    case "$manroffopts" in
    'none') manroffopts=''
	;;
    esac

    : determine the extension for catman pages
    case "$catmanext" in
    '')
	if $test "$catmanext_choice" = none; then
	    dflt=none
	else
	    case "$manext" in
	    .*) dflt=$manext ;;
	    *)
		if $test "$manext_choice" = none; then
		    dflt=none
		else
	            case "$catmansrc" in
	            *l) dflt=.l ;;
	            *n) dflt=.n ;;
	            *L) dflt=.L ;;
	            *g1) dflt=none ;;
	            *)  dflt=.1 ;;
	            esac
		fi
	    esac
	fi
	;;
    .*)	dflt="$catmanext";;
    *)  dflt=".$catmanext";;
    esac

    $cat <<EOM

The installed formatted manual pages can have various extensions to suit the
conventions of the host operating system, for example "page.1".

Note that the period '.' must be included as part of the extension.

To specify no extension, enter the word "none".

EOM
    rp="What extension should be used on installed formatted man pages: [$dflt]"
    $echo $n "$rp $c"
    . myread
    catmanext=$ans
    catmanext_choice=$ans
    case "$catmanext" in
    'none')
	catmanext=''
	;;
    esac

    if $test -f $pack -o -f $compress ; then
	
	:   See if the formatted manual pages are to be packed or compressed
	if $test -f $pack; then
	    $cat <<EOM

The formatted manual pages may be packed (.z suffix) or compressed (.Z
suffix) or left unpacked on your system.  The next two questions will deal
with how you want the formatted manual pages installed.  Answering no to
both packed and compressed will leave them unpacked.  Only one of packed
or compressed can be chosen.

EOM
	    case "$suffix" in
	    .Z) dflt=n;;
	    .z) dflt=y;;
	    *)  if [ "$catmansrc/*.z" != "`$echo $catmansrc/*.z`" ]; then
		    dflt=y
		else
		    dflt=n
		fi ;;
	    esac
	    rp="Should the formatted manual pages be packed? [$dflt]"
	    $echo $n "$rp $c"
	    . myread
	    case "$ans" in
	    y*) packed=y
		suffix=.z
		packer="$pack -f" ;;
	    *)  packed=n ;;
	    esac
	fi

	if $test -f $compress -a "$suffix" != ".z" ; then
	    case "$suffix" in
	    .z) dflt=n;;
	    .Z) dflt=y;;
	    *)  if [ "$catmansrc/*.Z" != "`$echo $catmansrc/*.Z`" ]; then
		    dflt=y
		else
		    dflt=n
		fi ;;
	    esac
	    rp="Should the formatted manual pages be compressed? [$dflt]"
	    $echo $n "$rp $c"
	    . myread
	    case "$ans" in
	    y*) packed=y
		suffix=.Z
		packer="$compress" ;;
	    *)  packed=n ;;
	    esac
	fi

	if $test "$packed" = 'n' ; then
	    suffix=''
	    packer=''
	fi
    else
	packed=''
	suffix=''
	packer=''
    fi

fi


if $test -n "$install_prefix" ; then
    lib="$install_prefix/lib"
    echo "Will install $package miscellaneous files to $lib"
else
    : determine where miscellaneous files go
    case "$lib" in
    '')
	dflt=`loc . "." /usr/local/lib /usr/lib /lib`
	;;
    *)  dflt="$lib"
	;;
    esac
    cont=true
    while $test "$cont" ; do
	echo " "
	rp="Where do you want to put the $package miscellaneous files? [$dflt]"
	$echo $n "$rp $c"
	. myread
	lib="$ans"
	lib=`filexp $lib`
	if $test -d "$lib"; then
	    cont=''
	else
	    case "$fastread" in
	    yes)	dflt=y;;
	    *)	dflt=n;;
	    esac
	    rp="Directory $lib doesn't exist.  Use that name anyway? [$dflt]"
	    $echo $n "$rp $c"
	    . myread
	    dflt=''
	    case "$ans" in
		y*) cont='';;
	    esac
	fi
    done
fi

if $test -n "$install_prefix" ; then
    etc="$lib"
    echo "Will install $package public config files to $etc"
else
    : determine where public config files go
    dflt="${etc:-$lib}"
    cont=true
    while $test "$cont" ; do
       echo " "
       rp="Where do you want to put the $package public config files? [$dflt]"
       $echo $n "$rp $c"
       . myread 
       etc="$ans"
       etc=`filexp $etc`
       if $test "$etc" = "/etc" -o "$etc" = "/etc/mail" ; then
           echo "DANGER: File /etc/aliases conflict with sendmail's file "
	   echo "        /etc/aliases. Do not use /etc or /etc/mail as configuration directory"
           echo 

           case "$fastread" in
           yes)        dflt=y;;
           *)  dflt=n;;
           esac
           rp="Directory $etc is reserved.  Use that name anyway? [$dflt]"
           $echo $n "$rp $c"
           . myread
           dflt=''
           case "$ans" in
               y*) cont='';;
           esac

       elif $test -d "$etc"; then
           cont=''
       else
           case "$fastread" in
           yes)        dflt=y;;
           *)  dflt=n;;
           esac
           rp="Directory $etc doesn't exist.  Use that name anyway? [$dflt]"
           $echo $n "$rp $c"
           . myread
           dflt=''
           case "$ans" in
               y*) cont='';;
           esac
       fi
    done
fi         

echo "Should Configure add to Makefile target 'package' which"
echo "install Elm to temporary area but not do post-install processing"
echo
echo "Use command   make package ROOT=/temporary/area"
echo
echo "If  'package' target is enabled, Configure assumes that $package"
echo "is compiled for binary package distribution, and do not store"
echo "domainname ($mydomain) as default domain."
echo

case "$build_package" in
"$define") dflt=y;;
"$undef")  dflt=n;;
*)	   dflt=n;;
esac
rp="Enable binary package target [$dflt]"
$echo $n "$rp $c"
. myread
case "$ans" in
y*) build_package="$define";;
*)  build_package="$undef";;
esac
echo

if $test -n "$install_prefix" ; then
    stage_dir="$install_prefix/var/stage-$package"
    echo "Will install $package post-install files to $stage_dir"
else
    echo "$package may use some data files for post-install processing"

    case "$stage_dir" in
    '')
	dflt="`loc . "." /usr/local/var /usr/var /var`/stage-$package"
	;;
    *)  dflt="$stage_dir"
	;;
    esac
    cont=true

    cont=true
    while $test "$cont" ; do
	echo " "
	rp="Where do you want to put the $package post-install files? [$dflt]"
	$echo $n "$rp $c"
	. myread
	stage_dir="$ans"
	stage_dir=`filexp $stage_dir`

	X="`dirname $stage_dir`" 
	if $test -d "$X"; then
	    cont=''
	else
	    case "$fastread" in
	    yes)	dflt=y;;
	    *)	dflt=n;;
	    esac
	    rp="Directory $X doesn't exist.  Use $stage_dir anyway? [$dflt]"
	    $echo $n "$rp $c"
	    . myread
	    dflt=''
	    case "$ans" in
		y*) cont='';;
	    esac
	fi
    done
fi

: Translate old value
case "$soname_include_path" in
    "$define")
	soname_include_path=y
	;;
    "$undef")
	soname_include_path=n
	;;
esac

soname_force='n'
if $test "$d_shared" = "$define" ; then

    if $test -n "$install_prefix" ; then
	shlib="$install_prefix/$libdirname"
	echo "Will install $package shared libraries to $shlib"

        if $test "X$soname_ok" != XOK ; then                
 		soname_include_path=n

        elif $test -f /etc/ld.so.conf ; then
	    ldsoinclude="`awk '$1 ~ /^include$/ { print $2; }' /etc/ld.so.conf`"

	    if $grep "^$shlib" < /etc/ld.so.conf >/dev/null; then
		echo "WARNING: Directory $shlib is listed on file /etc/ld.so.conf"
		echo "         Linux ldconfig gives errors when soname include pathnames"
		echo "         therefore disabling generating of pathnames to soname"
		soname_include_path=n
		soname_force='y'
	    elif $test "$ldsoinclude" != "" ; then
		for j in $ldsoinclude ; do
		    case "$j" in
			/*)
			    if $grep "^$shlib" $j >/dev/null; then
				echo "WARNING: Directory $shlib is listed on file $j "
				echo "         included from /etc/ld.so.conf"
				echo "         Linux ldconfig gives errors when soname include pathnames"
				echo "         therefore disabling generating of pathnames to soname"
				soname_include_path=n
				soname_force='y'
			    fi
			    ;;
			*)
			    if $grep "^$shlib" /etc/$j >/dev/null; then
				echo "WARNING: Directory $shlib is listed on file /etc/$j "
				echo "         included from /etc/ld.so.conf"
				echo "         Linux ldconfig gives errors when soname include pathnames"
				echo "         therefore disabling generating of pathnames to soname"
				soname_include_path=n
				soname_force='y'
			    fi
			    ;;
		    esac
		done
	    fi
	fi
    else
	: determine where shared libraries go
	case "$shlib" in
	'')
	    dflt=`loc . "." /usr/local/shlib /usr/local/$libdirname /usr/local/lib /usr/shlib /usr/$libdirname /usr/lib /shlib /$libdirname /lib`
	    ;;
	*)  dflt="$shlib"
	    ;;
	esac
	$cat<<EOM

Elm ME+ is able to put routines, which it it's companion programs
use, to shared library (libelmme-base.so). That makes companion programs 
to smaller. Shared library directory does not need to be one of default 
directories used by run time linker. To disabled Elm ME+'s shared library 
support  you can give "none" as shared library directory.
EOM

	cont=true
	while $test "$cont" ; do
	    echo " "
	    rp="Where do you want to put the $package shared libraries? [$dflt]"
	    $echo $n "$rp $c"
	    . myread
	    shlib="$ans"
	    
	    if $test "$shlib" = none ; then
		echo "Shared library support disabled"
		d_shared="$undef"
		d_dlopen_libs="$undef"
		dlopen_lib=
		d_dynamic_main="$undef"
		dynamic_opt=
		cont=''
	    else
		shlib=`filexp $shlib`
		if $test -d "$shlib"; then
		    cont=''

		    if $test "X$soname_ok" != XOK ; then                
			soname_include_path=n

		    elif $test -f /etc/ld.so.conf ; then
			ldsoinclude="`awk '$1 ~ /^include$/ { print $2; }' /etc/ld.so.conf`"

			A=
			if $grep "^$shlib" < /etc/ld.so.conf >/dev/null; then
			    A=/etc/ld.so.conf

			elif $test "$ldsoinclude" != "" ; then
			    for j in $ldsoinclude ; do
				case "$j" in
				    /*)
					if $grep "^$shlib" $j >/dev/null; then
					    A="$j included from /etc/ld.so.conf"
					fi
					;;
				    *)
					if $grep "^$shlib" /etc/$j >/dev/null; then
					    A="/etc/$j included from /etc/ld.so.conf"
					    fi
					;;
				esac
			    done
			fi

			if $test "X$A" != X ; then
			    $cat <<EOF
WARNING: Directory $shlib is listed on file $A
         Linux ldconfig gives errors when soname include pathnames.
Select
    c) Change $package shared library location
    o) Omit pathname from soname
    i) ignore ldconfig warnings and include path on soname
EOF
			    if $test "$soname_include_path" = y; then
				dflt=i
			    else
				dflt=o
			    fi
			    rp="Your selection? [$dflt]"
			    $echo $n "$rp $c"
			    . myread
			    case "$ans" in
				c*) cont=true;;
				o*) soname_include_path=n 
				    soname_force='y'
				    ;;
				*) soname_include_path=y
				    ;;
			    esac		
			fi

		    fi
		else
		    case "$fastread" in
		    yes)	dflt=y;;
		    *)	dflt=n;;
		    esac
		    rp="Directory $shlib doesn't exist.  Use that name anyway? [$dflt]"
		    $echo $n "$rp $c"
		    . myread
		    dflt=''
		    case "$ans" in
			y*)   
			       cont=''

			;;
		    esac
		fi
	    fi
	done
    fi
fi

if $test "$d_shared" = "$define" ; then

    if $test "$soname_force" != y ; then

	if $test "X$soname_ok" != XOK ; then                
	    soname_include_path=n
	elif $test "X$rpath_ok" != XOK ; then                
	    soname_include_path=y

	else 
	    $cat <<EOF

Setting rpath pointing to $shlib on executable seems work.
This can be used to locate shared library. Also putting
full path to soname of linked shared libraty, may be used
to locate shared library.

EOF
	    case "$soname_include_path" in
		y)
		    dflt=n
		    ;;
		*)
		    dflt=y
		    ;;
	    esac
	    
	    rp="Omit pathname from soname (as duplicate effort)? [$dflt]"
	    $echo $n "$rp $c"
	    . myread
	    dflt=''
	    case "$ans" in
		'y')
		    soname_include_path=n
		    ;;
		*)
		    soname_include_path=y
		    ;;
	    esac	    
	fi
    fi
else
    soname_include_path=''
fi

d_sharedtag="`grep SHAREDTAG: $source_dir/hdrs/patchlevel.h | cut -d' ' -f2`"
	$cat<<EOF

Using version tag $d_sharedtag

EOF

if $test "$d_shared" = "$define" ; then

    if $test "$libsuffix" != "" ; then

	case "$libsuffix" in
	    .*)
	    d_shared_rev="$d_sharedtag$libsuffix"
	    ;;
	    *)
	    d_shared_rev="$d_sharedtag.$libsuffix"
	    ;;
        esac

    else
	$cat<<EOF

If you use several versions of ELM ME+, version number need to be added
to libelmme-base.so name.

EOF
	case "$d_shared_rev" in
	    '')    dflt=n;;
	    *)    dflt=y;;
	esac

	rp="Add version number to libelmme-base.so library? [$dflt]"
	echo $n "$rp $c"
	. myread
	case "$ans" in
	    y)
	    d_shared_rev="$d_sharedtag"
	    ;;
	    *)
	    d_shared_rev=
	   ;;
	esac
    fi
    $echo "Using name libelmme-base.so$d_shared_rev"

fi



Xfallback=msg-id.elmme-mailer.org

cat <<EOF

Elm ME+ may generate message-id header when sending mail. This can be changed
on global elm.rc or on per user elmrc (variable message-id). Used domain
for message-id must be found from valid-msg-id-domains elmrc option
EOF
if $test "$d_dlopen_libs" = "$define" ; then
    cat <<EOF
or name must be found from DNS (with resolv shared libarary).
EOF
else
    cat <<EOF
(when no shared libraries are available).
EOF
fi
cat <<EOF
What is fall back domain name for message-id? $Xfallback is suggested.
Give "none" if fall back name is not used.

EOF
case "$d_msgiddomain" in
    "$undef")
	dflt=none
	;;
    *)
	if $test "X$fmsgiddomain" = X ; then
	    dflt="$Xfallback"
	else
	    dflt="$fmsgiddomain"
	fi
	;;
esac
rp="Fall back message-id domain?  [$dflt]"
$echo $n "$rp $c"
. myread
case "$ans" in
    ""|"none")
	d_msgiddomain="$undef"
	fmsgiddomain=""
	;;
    *)
	d_msgiddomain="$define"
	fmsgiddomain="$ans"
	;;
esac

: see if there is a strftime
set strftime d_strftime
eval $inlibc

: see if there is a mktime
set mktime d_mktime
eval $inlibc

: see if there is a getusershell
set getusershell d_getusershell
eval $inlibc

: get default batch subject
$cat <<EOM
 
Elm will provide a default subject for mail messages that are sent
in batch mode (redirected from a file.)
EOM

case "$defbatsub" in
    '') dflt='no subject (file transmission)';;
    *)  dflt="$defbatsub";;
esac
echo " "
rp="Default batch subject: [$dflt]"
$echo $n "$rp $c"
. myread
defbatsub="$ans"

: determine default editor
case "$defeditor" in
'')
    if $test -f /usr/bin/editor; then
	dflt=/usr/bin/editor
    elif $test -L /usr/bin/editor 2> /dev/null; then
	dflt=/usr/bin/editor
    else
	case "$vi" in
	    */*) dflt="$vi";;
	    *) dflt=/usr/ucb/vi;;
	esac
    fi
    ;;
*)  dflt="$defeditor"
    ;;
esac

$cat <<EOM

Elm must be configured with a default editor.  On most systems this may
be 'vi'.  If you prefer to use some other, easier editor enter it here.
EOM

if $test -L /usr/bin/editor 2> /dev/null; then
$cat <<EOM
Name /usr/bin/editor appears to be symbolic link. That provides
facility to select default editor.
EOM
elif $test -f /usr/bin/editor ; then
$cat <<EOM
On Linux default editor is often /usr/bin/editor. That provides
facility to select default editor.
EOM
fi

$cat <<EOM
You will be given a change to provide command line options to this
command in the next question.

EOM


cont=true
while $test "$cont" ; do
    echo " "
    rp="What is the default editor on your system? [$dflt]"
    $echo $n "$rp $c"
    . myread
    defeditor="$ans"
    if $test -f "$ans"; then
	cont=''
    elif $test -L "$ans" 2> /dev/null ; then
	echo "$ans is dangling symbolic link. Using anyway."
	cont=''
    else
	lookup=`loc "$ans" "" . $pth`
	if $test -f "$lookup"; then
	    cont=''
	    defeditor=$lookup
	else
	    if $test "$fastread" = yes; then
	        dflt=y
	    else
	        dflt=n
	    fi
	    echo "Editor $ans doesn't exist."
	    rp="Use that name anyway? [$dflt]"
	    $echo $n "$rp $c"
	    . myread
	    dflt=''
	    case "$ans" in
	    y*) cont='';;
	    esac
        fi
    fi
done

: determine the editor flags to use
$cat <<EOM

If this editor requires any options for proper use, specify them
here.  To specify no options, enter the word "none".  For example,
'pico' users will want to use the -t option.  This is the proper
place to specify that option.

EOM
dflt="$editoropts"
rp="What options should Elm use with $defeditor: [$dflt]"
$echo $n "$rp $c"
. myread
editoropts=$ans
case "$editoropts" in
'none') editoropts=''
     ;;
esac

: ask the preferred line printer and options for this system.
case "$linepr" in
'')
    if $test -f "$lp"; then
	dflt="$lp"
    elif $test -f "$lpr"; then
	dflt="$lpr"
    else
	dflt=none
    fi
    ;;
*)  dflt="$linepr";;
esac

linepr='blurfl/dyick'
$cat <<EOM

Elm has an option to send messages to the printer.  This question
asks for the default spooler name.  You can also specify options to
the command by separating them from the command by at least one space. 

Use value none for no compiled time default.
EOM
cont=true
while $test "$cont" ; do
    rp="What print spooler do you prefer to use with Elm? [$dflt]"
    $echo $n "$rp $c"
    . myread
    linepr="$ans"
    ans=`$expr "$linepr" : "\([^ ]*\).*"`
    case "$ans" in
    /*)
	if $test -f "$ans"; then
	    cont=''
	else
	    if $test "$fastread" = yes; then
		dflt=y
	    else
		dflt=n
	    fi
	    rp="File $ans doesn't exist.  Use that name anyway? [$dflt]"
	    $echo $n "$rp $c"
	    . myread
	    case "$ans" in
	    y*) cont='';;
	    esac
	fi
	;;
    none)
        echo "OK. Specify correct value on the global elm.rc instead."
	cont=''
	;;
    *)
        if $test "$fastread" = yes; then
	    echo "The print spooler needs to be a full path name."
	    echo "Using the current, possibly improper, value."
	    cont=''
	else
	    echo "Please give the full path name."
	fi
	;;
    esac
done

: ask the preferred pager for this system.
case "$pager" in
'') dflt="builtin++";;
*)  dflt="$pager";;
esac

$cat <<EOM

Default pager selected on compilation time is used only
if environment variable \$PAGER is not set. If you select
builtin++ as default pager, you have provided to option
to ignore \$PAGER environment variable.

If pager is set on global elm.rc, compile time default pager
does not matter.

EOM

pager='blurfl/dyick'
echo " "
cont=true
while $test "$cont" ; do
    rp="What pager do you prefer to use with $package? [$dflt]"
    $echo $n "$rp $c"
    . myread
    pager="$ans"
    case "$ans" in
    builtin|builtin+|builtin++)
        cont=''
        ;;
    /*)
	if $test -f "$ans"; then
	    cont=''
	else
	    if $test "$fastread" = yes; then
		dflt=y
	    else
		dflt=n
	    fi
	    rp="File $ans doesn't exist.  Use that name anyway? [$dflt]"
	    $echo $n "$rp $c"
	    . myread
	    case "$ans" in
	    y*) cont='';;
	    esac
	fi
	;;
    *)
	echo "Please give the full path name."
	;;
    esac
done

case "$pager" in

    builtin|builtin+|builtin++)
    
	$cat <<EOM

You selected $pager as default pager. Should builtin
pager used even whan \$PAGER variable is set?

EOM
    case "$use_builtin_pager" in
      "$define") dflt=y;;
      "$undef")  dflt=n;;
	*) dflt=y;;
    esac

    rp="Builtin pager ignores \$PAGER variable? [$dflt]"
    $echo $n "$rp $c"
    . myread
    case "$ans" in
	y*)
	    use_builtin_pager="$define"
	    ;;
	*)
       	    use_builtin_pager="$undef"
	    ;;
    esac
    ;;
    *)
               use_builtin_pager="$undef"
    ;;
esac

: see if ar generates random libraries by itself
echo " "
echo "Checking how to generate random libraries on your machine..."
$ar rc ran.a /dev/null
if $ar ts ran.a >/dev/null 2>&1; then
	echo "ar appears to generate random libraries itself."
	orderlib=false
	ranlib=":"
	if test "$uname_os" = "Darwin"; then
	    
		: Mac OS X patch to fix undefined symbols errors caused by $non_lazy_ptr
		echo "Patching for Mac OS X."
		ranlib="ranlib -c"
	fi
else
        ranlib=`loc ranlib ranlib $pth`

	if test  "$ranlib" != ranlib; then
		echo "your system has $ranlib; we'll use that."
		orderlib=false
	else
		echo "your system doesn't seem to support random libraries"
		echo "so we'll use lorder and tsort to order the libraries."
		orderlib=true
		ranlib=":"
	fi
fi

: determine the name of the tape device
rmttape=`loc rct0 "" /dev`
if $test -z "$rmttape"; then
	rmttape=`loc rmt0 "" /dev`
fi
if $test -z "$rmttape"; then
	rmttape=`loc rtp0 "unknown-remote-tape-unit" /dev`
fi
echo "remote tape drive is $rmttape"
echo " "
: where do we get termlib routines from
echo " "
case "$d_havetlib" in
"$define")
    echo "Terminfo routines in ${termlib:-system} library from prior Configure run"
    ;;
*)
    $echo "Trying locate terminfo routines"
    $cat > try_term.c <<'EOF'

#include <stdio.h>

#if defined(__STDC__)

int putit(int c);
int tputs(const char *str, int affcnt, int (*putc)(int));
int main (int argc, char * argv[]);

#endif

int putit(c)
    int c;
{
    return putchar(c);
}

int main (argc,argv)
   int argc;
   char * argv[];
{
    tputs("\nTest output\n",1,putit);

    return 0;
}

EOF
    d_havetlib=''

    rmlist="$rmlist try_term.c try_term try.log try2.log"

    echo > failed.log
    
    for A in '' '-ltermlib' '-lcurses' '-ltermcap' '-lncurses'; do 
	case "$d_havetlib" in
	'')
	    echo "  Trying ${A:-system} library"
	    if $cc $ccflags -o try_term try_term.c $A $libs > try.log 2>&1
	    then
		if ./try_term > try2.log 2>&1	            
		then
		    echo "Succeed to found terminfo routines from ${A:-system} library"
		    termlib="$A"
		    d_havetlib="$define"
		else
		    echo "=== Failed to execute terminfo test with ${A:-system} library" >> failed.log
		    cat  try2.log >> failed.log
		fi
	    else
		echo "=== Failed to compile or link terminfo test with ${A:-system} library" >> failed.log
		cat try.log >> failed.log
	    fi
	;;
	esac
    done

    if $test "$d_havetlib" = ''
    then
	case "$termlib" in
	    '')
		cat failed.log
		echo
		
		dflt=y
		
		rp="Your system appears to NOT have termlib-style routines.  Is this true? [$dflt]"
		$echo $n "$rp $c"
		. myread
		case "$ans" in
		    n*|f*) d_havetlib="$define"
			   echo "Then where are the termlib-style routines kept (specify either -llibname"
			   $echo $n " or full pathname (~name ok))? $c"
			   rp='Specify termlib:'
			   . myread
			   termlib=`filexp $ans`
			   ;;
		    *)    d_havetlib="$undef"
			  termlib=''
			  echo "OK. I quit then."
			  exit 1
			  ;;
		esac
		echo " "
		;;
	    *)  echo "You said termlib was $termlib before."
		;;
	esac
    fi

     $rm -f failed.log
    ;;
esac

if $test -f /usr/include/term.h ; then
    echo "<term.h> found"

   if $test -f /usr/include/curses.h ; then
        echo "<curses.h> found"

	$cat <<EOM

Both <term.h> and <curses.h> found. Which one I should include for
prototypes of tgetent() like functions when using $termlib. Select
    t) Include only <term.h>,
    c) Include only <curses.h>
or  b) Include both <curses.h> and <term.h>

EOM
	case "$i_term:$i_curses" in    
	    "$define:$define") dflt=b;;
	    "$define:$undef")  dflt=t;;
	    "$undef:$define")  dflt=c;;
	    *)
	    case "$uname_os" in
		AIX|IRIX*)
		    dflt=c
		    ;;
                SunOS)
		    dflt=b
		    ;;
		*)
		    dflt=t
		    ;;
	    esac
	    ;;
	esac
	rp="Should <term.h>, <curses.h> or both included when using $termlib ? [$dflt]"
	$echo $n "$rp $c"
	. myread
	case "$ans" in
	c*)
	    i_curses="$define"
	    i_term="$undef"
	    ;;
	b*)
	    i_curses="$define"
	    i_term="$define"
	    ;;
	*)
	    i_curses="$undef"
	    i_term="$define"
	    ;;
	esac
    else
	i_curses="$undef"
	i_term="$define"
    fi
else
    i_term="$undef"
    i_curses="$undef"
fi

if $test -f /usr/include/execinfo.h ; then
    echo "Found <execinfo.h>"
    if $contains '^backtrace$' libc.list >/dev/null 2>&1; then
	echo 'backtrace() found.'
        echo " "
        $echo $n "Testing if backtrace()  can be used ... $c"
	$cat > try.c <<'EOF'
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define SIZE 100

void crashit() 
{
	void * buffer[SIZE];
	int count = backtrace(buffer, SIZE);
 
        backtrace_symbols_fd(buffer,count,1);

}

void FOUDME() {

      crashit();

}

#if defined(__STDC__)
int main (int argc, char * argv[]);
#endif

int main (argc,argv)
   int argc;
   char * argv[];
{
    
     FOUDME();

     return 0;      /* OK */
}
EOF

	rmlist="$rmlist  try.c try try.out"

	if $cc $ccflags -o try try.c >/dev/null 2>&1 &&  ./try > try.out; then
	    echo "OK. It success.";

	    d_backtrace="$define"
	    
	    if $contains FOUDME try.out; then
		echo "It also includes function names"
		
		: Not needed
		backtrace_opt=
	    else
		echo "Output does not include function names"
		
		: $backtrace_opt is nornally same than $dynamic_opt
		backtrace_opt=BAD
		for A in '-rdynamic' ; do
		    case "$backtrace_opt" in
			BAD)
			    $rm -f try try.out

			    echo "  Trying with option ${A:-(none)}"
			    if $cc $ccflags $A -o try try.c >/dev/null 2>&1 &&  ./try > try.out; then
				if $contains FOUDME try.out; then
				    echo "Succeed with option ${A:-(none)}"
				    backtrace_opt="$A"
				else
				    echo "  Works but does not include function names"
				fi
                             else
				echo "  Does not compile or work"
			     fi
			;;
		    esac
               done

	       if $test "X$backtrace_opt" = XBAD; then
		   backtrace_opt=
		   echo "Unable to include function names to backtrace"

               elif $test "X$optimize" != X -a "X$optimize" != "X " ; then
		   $rm -f try try.out
		   
		   echo "   Testing with optimizer/debugger flag $optimize"
		   if $cc $ccflags $backtrace_opt $optimize -o try try.c >/dev/null 2>&1 &&  ./try > try.out; then
		       
		        if $contains FOUDME try.out; then
			    echo "Still works with option $optimize"
			else
			    echo "   Can not use option $optimize"
			    
			    canuse=" "
			    for A in $optimize ; do
				 $rm -f try try.out
		   
				 echo "   Testing with option $A"
				 if $cc $ccflags $backtrace_opt $A -o try try.c >/dev/null 2>&1 &&  ./try > try.out; then

				     if $contains FOUDME try.out; then
					 echo "   Still works with option $A"
					 canuse="$canuse $A"
                                     else
					 echo "   Can not use option $A"
				     fi
				 else
				     echo "   OOPS!  Option $A does not compile!"
				 fi

			    done
			    optimize="$canuse"
			    
			    if $test "X$optimize" != "X " ; then
				echo "Setting  optimizer/debugger flag to $optimize"
                            fi
			fi
                   else
		       echo "   OOPS!  Option $optimize does not compile!"
		       optimize=
		   fi

	       fi
	    fi

	else
           echo "Failed."
	   d_backtrace="$undef" 
	   backtrace_opt=
        fi

    else
       d_backtrace="$undef"
       backtrace_opt=
    fi
else
    d_backtrace="$undef"
    backtrace_opt=
fi

: determine where temporary files should go
case "$tmpdir" in
'')
    dflt=`loc . "." "/tmp /usr/tmp"`
    ;;
*)  dflt="$tmpdir"
    ;;
esac
if $test -d "$tmpdir" -a "$tmpdir" != ""; then
	$echo " "
	$echo "Temporary files will be put in the $tmpdir directory"
else
	cont=true
	while $test "$cont" ; do
	    $echo " "
	    rp="Where do you want to put the temporary files? [$dflt]"
	    $echo $n "$rp $c"
	    . myread
	    tmpdir="$ans"
	    tmpdir=`filexp $tmpdir`
	    if $test -d "$tmpdir" -a "$tmpdir" != ""; then
		cont=''
	    else
		if $test "$fastread" = yes; then
		    dflt=y
		else
		    dflt=n
		fi
		rp="Directory $tmpdir doesn't exist.  Use that name anyway? [$dflt]"
		$echo $n "$rp $c"
		. myread
		dflt=''
		case "$ans" in
		y*) cont='';;
		esac
	    fi
	done
fi

: if pmake exists, allow its use for parallel make
 
if $test -f "$pmake" ; then
    case "$use_pmake" in
	n)  dflt=n;;
	*)  dflt=y;;
    esac

    $cat <<EOM
 
The executable file pmake was found on this system.  Usually this
file indicates a parallel make, which executes much faster.  Should
this system use the pmake command as its make command?

EOM
    rp="Does this system use pmake as its make? [$dflt]"
    $echo $n "$rp $c"
    . myread
    case "$ans" in
	y*) use_pmake=y
	    make="$pmake";;
	*)  use_pmake=n;;
    esac
else
    use_pmake=n
fi

: 
echo "Testing whatever $make sets \$(MAKE) macro ..."
cat <<'EOF' > makefile.test
target:
	@ echo $(MAKE) 
EOF

rmlist="$rmlist result makefile.test"

if $make -f makefile.test target > result ; then

    a="`$basename $make`"

    if $grep "^$make" < result ; then
	echo "  Yes, it does"
	make_sets_make="$define"
    elif $grep "^$a" < result ; then
	echo "  Yes, it does (sets it to $a -- not to $make)"
	make_sets_make="$define"
    else
	echo "  No, it does not"
	make_sets_make="$undef"
    fi

else
    echo "  No, it does not ($make command failed)"
    make_sets_make="$undef"
fi

: figure out timezone handling

cp "$source_dir/lib/get_tz.c" try.c 2>/dev/null \
	|| $echo "Oh no!  I cannot find the \"lib/get_tz.c\" file."
cat >elm_defs.h <<EOF
#$i_time I_TIME
#$i_systime I_SYSTIME
#include <stdio.h>
#include <sys/types.h>


#ifdef I_TIME
#  include <time.h>
#endif
#ifdef I_SYSTIME
#  include <sys/time.h>
#endif

#ifndef	_POSIX_SOURCE
extern struct tm *localtime();
extern time_t	  time();
#endif

#undef P_
#ifdef __STDC__
#define P_(x) x
#else
#define P_(x) ()

#ifndef const
#define const
#endif

#endif

struct debug_struct {
    const char          * class;
    const char          * file;
    const char          * ID;
    void                * target;
    int   active;
};

/* Dummy .... */
#define DPRINT(x,level,action)      do { if (x.active >= level) { } } while(0)
#define DEBUG_VAR(x,file,class) \
static struct debug_struct x = { class, file, rcsid, NULL, -1 }

extern const char *get_tz_name P_((const struct tm *));
EOF

rmlist="$rmlist  headers.h try.c try.o try try.out try.log"

$echo " "
dflt_handling=$tzname_handling
tzname_handling=
$echo > try.log
if $test -f try.c ; then
    $echo "Figuring out how to get timezone names."
    for tzname_handling in DFLT TM_NAME TM_ZONE TZNAME TIMEZONE ERROR ; do
	case "$tzname_handling" in
	DFLT)		$test "$dflt_handling" = "" && continue
			tzname_handling=$dflt_handling
			;;
	ERROR)		tzname_handling=
			break
			;;
	$dflt_handling)	: avoid doing default twice
			continue
			;;
	esac
	$echo "Trying -DTZNAME_USE_$tzname_handling"
	$echo "========== Trying -DTZNAME_USE_$tzname_handling" >> try.log
	$cc -D_CONFIGURE -DTZNAME_USE_$tzname_handling $ccflags \
		try.c -o try >>try.log 2>&1
	if $test $? -eq 0 && ./try >try.out 2>&1 
        then
		$echo "Alright!  That seems to have worked."
		break
	fi
    done
fi
if $test "$tzname_handling" = "" ; then
    cat try.log

    $echo "I cannot figure out how to get timezone names."
    if $test "$dflt_handling" != "" ; then
	tzname_handling="$dflt_handling"
	$echo "You said \"$tzname_handling\" worked last time so I'll use that."
    else
	tzname_handling=UNKNOWN
	$echo "You will have to set \"tzname_handling\" manually."
    fi

    sleep 3
fi





: Looking for shared libs
shared_list=''
if $test "$d_dlopen_libs" = "$define" ; then
    t=`$ls "$source_dir/shared_libs"`
    for a in $t ; do
	if $test -d "$source_dir/shared_libs/$a" ; then
	    if $test -r "$source_dir/shared_libs/$a/config" ; then
		shared_list="$shared_list $a"
	    else
		case "$a" in
		    include)
		    ;;
		    CVS)
		    ;;
		    *)
			: test may report unreadable when setfacl is used

			if cat "$source_dir/shared_libs/$a/config" > /dev/null; 
			then
			    shared_list="$shared_list $a"
			else
			    echo "ERROR: $source_dir/shared_libs/$a/config not readable!"
			fi
			;;
		esac
	    fi
	fi
    done

    echo "Shared libraries are: $shared_list"

    if test ! -d "$build_dir/shared_libs" ; then

	echo "Creating build subdirectory $build_dir/shared_libs ..."
	mkdir "$build_dir/shared_libs" || exit 1

    fi

    for doconfig in $shared_list ; do

	if test ! -d "$build_dir/shared_libs/$doconfig" ; then
	    echo "Creating build subdirectory $build_dir/shared_libs/$doconfig ..."
	    mkdir "$build_dir/shared_libs/$doconfig" || exit 1
	fi

	echo
	echo "(Doing configure for $doconfig)"
	rm -f "$build_dir/shared_libs/$doconfig/config.res"
	( 
	  : On Dunix we can not pass arguments to '.' instead we need set them...

          set shared_libs/$doconfig
	  . "$source_dir/shared_libs/$doconfig/config" shared_libs/$doconfig 
	)
    done

    case "$shared_register" in
	'')
	    dflt="$shared_list"
	    ;;
	*)
	    dflt="$shared_register"
	    ;;
    esac
    $cat <<EOF

These shared libraries
         $shared_list
may be registered after installation, by writing to the global elm.rc file
varible use-library. Give list which libraries from these should be registered.
Give "none" if no libraries should be registered automatically.

EOF

    rp="Libraries for registeration? [$dflt]" 
    echo $n "$rp $c"
    . myread

    case "$ans" in
	none)
	  shared_register=none
	  ;;
	*)
	shared_register=    
	for doconfig in $ans ; do
	    if $test -r "$build_dir/shared_libs/$doconfig/config.res" ; then
		shared_register="$shared_register $doconfig"
	    else
		echo "Library $doconfig not available"
	    fi
	done
	echo "Will register following libraries: $shared_register"
	echo
	;;
    esac

fi

: the "config.over" file can be used to patch configuration changes
if test -f "$start_dir/config.over" ; then
	echo " "
	echo "I have found a \"config.over\" file."
	dflt=y
	rp="Do you want to load the \"config.over\" file? [$dflt]"
	$echo $n "$rp $c"
	. myread
	case "$ans" in
    	n*)	echo "OK, I'll ignore it."
		;;
	*)	. "$start_dir/config.over"
		echo "Configuration override changes have been loaded from config.over."
		;;
	esac
fi

: clean up one time files
for file in OneTime.PL* ; do
	if test -f "$file" ; then
		echo "Removing patch cleanup script $file . . ."
		$rm -f $file
	fi
done

: create config.sh file
echo " "
cd "$build_dir" || exit 1

echo "Creating config.sh..."
$spitshell <<EOT >config.sh
$startsh
# config.sh
# This file was produced by running the Configure script.

Log='$Log'
Header='$Header'
install_prefix='$install_prefix'
bin='$bin'
contains='$contains'
cppstdin='$cppstdin'
cppminus='$cppminus'
diff='$diff'
d_getopt='$d_getopt'
d_getopt_type='$d_getopt_type'
ascii_codeset='$ascii_codeset'
d_memcpy='$d_memcpy'
d_symlink='$d_symlink'
d_whoami='$d_whoami'
d_poll='$d_poll'
d_select='$d_select'
i_sys_select='$i_sys_select'
i_sysexits='$i_sysexits'
i_stdint='$i_stdint'
d_mmap='$d_mmap'
d_have_int128='$d_have_int128'
d_have_socket='$d_have_socket'
d_have_soerror='$d_have_soerror'
d_have_getsockname='$d_have_getsockname'
getsockname_socklen='$getsockname_socklen'
i_netdb='$i_netdb'
d_addrinfo='$d_addrinfo'
d_addrconfig='$d_addrconfig'
d_getnameinfo='$d_getnameinfo'
i_netinet_in='$i_netinet_in'
d_have_in6='$d_have_in6'
d_have_scope='$d_have_scope'
d_ipv6_scope_id='$d_ipv6_scope_id'
scope_id_default='$scope_id_default'
d_ifaddrs='$d_ifaddrs'
d_usegetifaddrs='$d_usegetifaddrs'
i_arpa_inet='$i_arpa_inet'
d_use_aton='$d_use_aton'
d_use_xtox_pn='$d_use_xtox_pn'
i_net_if='$i_net_if'
d_nameindex='$d_nameindex'
i_inttypes='$i_inttypes'
d_nointtypes='$d_nointtypes'
n='$n'
c='$c'
orderlib='$orderlib'
ranlib='$ranlib'
ar='$ar'
nm='$nm'
nm_opts='$nm_opts'
package='$package'
pager='$pager'
use_builtin_pager='$use_builtin_pager'
startsh='$startsh'
define='$define'
loclist='$loclist'
expr='$expr'
sed='$sed'
echo='$echo'
cat='$cat'
rm='$rm'
mv='$mv'
cp='$cp'
tail='$tail'
tr='$tr'
sort='$sort'
test='$test'
uniq='$uniq'
grep='$grep'
fgrep='$fgrep'
head='$head'
trylist='$trylist'
test='$test'
inews='$inews'
ispell='$ispell'
egrep='$egrep'
more='$more'
pg='$pg'
Mcc='$Mcc'
vi='$vi'
mailx='$mailx'
mail='$mail'
cpp='$cpp'
perl='$perl'
emacs='$emacs'
ls='$ls'
rmail='$rmail'
sendmail='$sendmail'
shar='$shar'
smail='$smail'
submit='$submit'
tbl='$tbl'
troff='$troff'
nroff='$nroff'
uname='$uname'
uuname='$uuname'
line='$line'
chgrp='$chgrp'
chmod='$chmod'
lint='$lint'
sleep='$sleep'
pr='$pr'
tar='$tar'
ln='$ln'
lpr='$lpr'
lp='$lp'
touch='$touch'
make='$make'
make_sets_make='$make_sets_make'
date='$date'
csh='$csh'
pmake='$pmake'
mips='$mips'
col='$col'
pack='$pack'
compress='$compress'
execmail='$execmail'
gencat='$gencat'
libswanted='$libswanted'
noaddlib='$noaddlib'
c_date='$c_date'
d_ascii='$d_ascii'
d_backtrace='$d_backtrace'
backtrace_opt='$backtrace_opt'
d_broke_ctype='$d_broke_ctype'
d_calendar='$d_calendar'
calendar='$calendar'
d_chown_neg1='$d_chown_neg1'
d_content='$d_content'
d_crypt='$d_crypt'
i_crypt='$i_crypt'
cryptlib='$cryptlib'
d_disphost='$d_disphost'
d_domname='$d_domname'
d_usegetdom='$d_usegetdom'
d_errlst='$d_errlst'
d_flock='$d_flock'
d_dotlock='$d_dotlock'
d_fcntlock='$d_fcntlock'
has_flock='$has_flock'
has_fcntl='$has_fcntl'
d_compile_flock='$d_compile_flock'
d_compile_fcntl='$d_compile_fcntl'
d_ftruncate='$d_ftruncate'
d_gethname='$d_gethname'
d_douname='$d_douname'
ign_hname='$ign_hname'
d_havetlib='$d_havetlib'
termlib='$termlib'
i_curses='$i_curses'
i_term='$i_term'
d_index='$d_index'
d_ispell='$d_ispell'
ispell_path='$ispell_path'
ispell_options='$ispell_options'
i_locale='$i_locale'
i_nl_types='$i_nl_types'
d_mailname='$d_mailname'
mailname_file='$mailname_file'
d_usemailname='$d_usemailname'
d_msgcat='$d_msgcat'
d_usenls='$d_usenls'
d_mallocvoid='$d_mallocvoid'
d_mboxedit='$d_mboxedit'
metamail_path='$metamail_path'
d_8bitmime='$d_8bitmime'
d_binarymime='$d_binarymime'
d_dsn='$d_dsn'
defsystemcharset='$defsystemcharset'
d_mmdf='$d_mmdf'
d_newauto='$d_newauto'
d_noaddfrom='$d_noaddfrom'
d_usedomain='$d_usedomain'
d_noxheader='$d_noxheader'
d_pidcheck='$d_pidcheck'
d_ptem='$d_ptem'
d_putenv='$d_putenv'
maxattempts='$maxattempts'
d_setgid='$d_setgid'
mailermode='$mailermode'
d_sigvec='$d_sigvec'
d_sigvectr='$d_sigvectr'
d_sigset='$d_sigset'
d_sighold='$d_sighold'
d_sigprocmask='$d_sigprocmask'
d_sigblock='$d_sigblock'
d_waitpid='$d_waitpid'
d_sigaction='$d_sigaction'
d_strcspn='$d_strcspn'
d_strspn='$d_strspn'
d_strpbrk='$d_strpbrk'
d_strerror='$d_strerror'
d_strftime='$d_strftime'
d_mktime='$d_mktime'
d_getusershell='$d_getusershell'
d_strings='$d_strings'
d_pwdinsys='$d_pwdinsys'
strings='$strings'
includepath='$includepath'
d_strstr='$d_strstr'
d_strtok='$d_strtok'
d_subshell='$d_subshell'
d_tempnam='$d_tempnam'
d_setlinebuf='$d_setlinebuf'
d_sharedtag='$d_sharedtag'
d_shared='$d_shared'
d_shared_rev='$d_shared_rev'
d_dlopen_libs='$d_dlopen_libs'
shared_list='$shared_list'
shared_register='$shared_register'
d_dynamic_main='$d_dynamic_main'
dynamic_opt='$dynamic_opt'
dlopen_lib="$dlopen_lib"
rpath_opt='$rpath_opt'
rpath_ok='$rpath_ok'
soname_opt='$soname_opt'
soname_include_path="$soname_include_path"
soname_ok='$soname_ok'
tempnamo='$tempnamo'
tempnamc='$tempnamc'
d_termio='$d_termio'
d_termios='$d_termios'
d_utimbuf='$d_utimbuf'
d_vfork='$d_vfork'
d_directory='$d_directory'
d_directyry_type='$d_directyry_type'
defbatsub='$defbatsub'
defeditor='$defeditor'
editoropts='$editoropts'
hostname='$hostname'
phostname='$phostname'
mydomain='$mydomain'
d_dummydomain='$d_dummydomain'
dummydomain='$dummydomain'
autohostname='$autohostname'
fmsgiddomain='$fmsgiddomain'
d_msgiddomain='$d_msgiddomain'
i_memory='$i_memory'
i_time='$i_time'
i_systime='$i_systime'
s_timeval='$s_timeval'
d_systimekernel='$d_systimekernel'
d_gettimeofday='$d_gettimeofday'
suseconds='$suseconds'
d_suseconds='$d_suseconds'
d_clock_gettime='$d_clock_gettime'
i_unistd='$i_unistd'
i_utime='$i_utime'
i_sysutime='$i_sysutime'
lib='$lib'
etc='$etc'
stage_dir='$stage_dir'
build_package='$build_package'
shlib='$shlib'
libdirname='$libdirname'
libc='$libc'
linepr='$linepr'
maildir='$maildir'
mailer='$mailer'
mailer_bv_ok='$mailer_bv_ok'
mailgrp='$mailgrp'
mansrc='$mansrc'
catmansrc='$catmansrc'
manext='$manext'
manext_choice='$manext_choice'
catmanext='$catmanext'
catmanext_choice='$catmanext_choice'
packed='$packed'
manroff='$manroff'
manroffopts='$manroffopts'
suffix='$suffix'
packer='$packer'
optimize='$optimize'
ccflags='$ccflags'
picflag='$picflag'
nopic='$nopic'
shared_extra='$shared_extra'
cppflags='$cppflags'
ldflags='$ldflags'
cc='$cc'
libs='$libs'
nametype='$nametype'
d_passnames='$d_passnames'
d_berknames='$d_berknames'
d_usgnames='$d_usgnames'
rmttape='$rmttape'
sigtype='$sigtype'
spitshell='$spitshell'
shsharp='$shsharp'
sharpbang='$sharpbang'
tmpdir='$tmpdir'
tzname_handling='$tzname_handling'
use_pmake='$use_pmake'
xencf='$xencf'
xenlf='$xenlf'
d_xenix='$d_xenix'
d_bsd='$d_bsd'
locale='$locale'
have_codeset='$have_codeset'
d_pgp='$d_pgp'
pgp='$pgp'
pgp2_path='$pgp2_path'
pgp5_dir='$pgp5_dir'
gpg_path='$gpg_path'
special_path='$special_path'
special_path2='$special_path2'
locale_dir='$locale_dir'
d_wchar='$d_wchar'
d_wcwidth='$d_wcwidth'
CONFIG=true
EOT

for doconfig in $shared_list ; do
      echo "  Copying configure of $doconfig to config.sh..."
      cat shared_libs/$doconfig/config.res >> config.sh
done

: config.sh is needed by ConfTool/GenCharmap 
: Also config.h and hdrs/sysdefs.h

if test ! -d hdrs ; then
    echo "making hdrs directory"
    mkdir hdrs || exit 1
fi
( 
  . config.sh
  ( . "$source_dir/config.h.SH" ) || exit 1
  ( 
     cd hdrs || exit 1
      subdir=hdrs
      . "$source_dir/hdrs/sysdefs.SH" 
  ) || exit 1
) || exit 1

$cat <<EOF

Elm ME+ have ability to map locale's LC_CTYPE to MIME character set.
That is done via file elm.mimecharsets on elm's library directory.
That file also includes MIME character set information.
EOF

if [ "$have_codeset" = "$define" ] ; then
$cat <<EOF
Also codeset name returned by nl_langinfo(CODESET) is used to determine
MIME character set.
EOF
fi

if [ "$i_locale" = "$define" ] ; then
    $cat <<EOM

EOM
    locale_dir="`$UU/loc . none /usr/lib/locale /usr/share/locale`"
else
    $cat <<EOF
This system seems not supports locales (locale.h not found).
Thherefore system ctype() routines support only one character
set. That character set is specified by giving mapping for
locale NONE in file elm.mimecharsets on elm's library directory.

EOF
    locale_dir=none
fi

(
    :   cd ..

	$cat <<EOF
During configure that file goes to bin/elm.mimecharsets.

Existing (if any) elm.mimecharsets from elm global library 
directory is merged with to bin/elm.mimecharsets during 
installation.

EOF
	rp="[Type carriage return to continue]"
	$echo $n "$rp $c"

	. $UU/myread

    nomap=

    if [ "$have_codeset" = "$define" ] ; then

	$cat <<EOF
Because nl_langinfo(CODESET) is supported,
$lib/elm.mimecharsets need not include mapping
definations from locale to charset. 

EOF
	dflt=n
	rp="Should Configure generate (new) mappings from locale to charset? [$dflt]"
	$echo $n "$rp $c"
	. $UU/myread
	case "$ans" in
	y*) nomap=;;
	*) nomap=y;;
	esac
    fi

    . "$source_dir/ConfTool/GenCharmap"

    $echo 
    $echo "Resulting elm.mimecharsets is following:"
    $echo
    if $test "$fastread" = yes; then
	$cat bin/elm.mimecharsets
    elif $test $more != more ; then
	$more bin/elm.mimecharsets
    else
	$cat bin/elm.mimecharsets
    fi
    $echo

    if $test "$bad" != "" ; then
	$cat <<EOF

Generation of mappings from locale to MIME charset 
for following locales was unsuccesfull (marked as '(unknown)'):

$bad

Please fix mappings by editing bin/elm.mimecharsets manually.

EOF
    fi

    rp="If you need to edit bin/elm.mimecharsets, do it as a shell escape here:"
    $echo $n "$rp $c"
    . $UU/myread
    $echo

    $cat <<EOM
Generating elm.iso2022sets file. During configure that file goes 
to bin/elm.iso2022sets. For now doc/iso2022.sets is just used
for that.

Existing (if any) elm.iso2022sets from elm global library 
directory is merged with to bin/elm.iso2022sets during 
installation.

EOM
    rp="[Type carriage return to continue]"
    $echo $n "$rp $c"

    . $UU/myread

    . "$source_dir/ConfTool/GenIso2022sets"

    $echo "Resulting elm.iso2022sets is following:"
    $echo
    if $test "$fastread" = yes; then
	$cat bin/elm.iso2022sets
    elif $test $more != more ; then
	$more bin/elm.iso2022sets
    else
	$cat bin/elm.iso2022sets
    fi
    $echo

$cat <<EOM
Elm ME+ is ability change charset of terminal. That is done via file
elm.terminalinfo elm's library directory. 

EOM

	$cat <<EOM
Generating elm.terminalinfo file. During configure that file goes 
to bin/elm.terminalinfo. For now doc/terminal.info is just used
for that.

Existing (if any) elm.terminalinfo from elm global library 
directory is merged with to bin/elm.terminalinfo during 
installation.

EOM
    rp="[Type carriage return to continue]"
    $echo $n "$rp $c"

    . $UU/myread

    . "$source_dir/ConfTool/GenTerminalinfo"
    
    $echo 
    $echo "Resulting elm.terminalinfo is following:"
    $echo
    if $test "$fastread" = yes; then
	$cat bin/elm.terminalinfo
    elif $test $more != more ; then
	$more bin/elm.terminalinfo
    else
	$cat bin/elm.terminalinfo
    fi
    $echo

    $cat <<EOM

bin/elm.terminalinfo may include some extra chracter sets. During
installation these may cause some error messages, but you should
able to ignore them. 

You may want now edit bin/elm.terminalinfo manually.

EOM

    rp="If you need to edit bin/elm.terminalinfo, do it as a shell escape here:"
    $echo $n "$rp $c"
    . $UU/myread
    $echo

	$cat <<EOM
Generating elm.mimetypes file. During configure that file goes 
to bin/elm.mimetypes. For now doc/terminal.info is just used
for that.

Existing (if any) elm.mimetypes from elm global library 
directory is merged with to bin/elm.mimetypes during 
installation.

EOM
    rp="[Type carriage return to continue]"
    $echo $n "$rp $c"

    . $UU/myread

    . "$source_dir/ConfTool/GenMimetypes"
    
    $echo 
    $echo "Resulting elm.mimetypes is following:"
    $echo
    if $test "$fastread" = yes; then
	$cat bin/elm.mimetypes
    elif $test $more != more ; then
	$more bin/elm.mimetypes
    else
	$cat bin/elm.mimetypes
    fi
    $echo

    rp="If you need to edit bin/elm.mimetypes, do it as a shell escape here:"
    $echo $n "$rp $c"
    . $UU/myread
    $echo


    $cat <<EOM
Generating elm.mailinglists file. During configure that file goes 
to bin/elm.mailinglists. For now doc/mailing.lists is just used
for that.

Existing (if any) elm.mailinglists from elm global library 
directory is merged with to bin/elm.mailinglists during 
installation.

EOM
    rp="[Type carriage return to continue]"
    $echo $n "$rp $c"

    . $UU/myread

    . "$source_dir/ConfTool/GenMailinglists"

    $echo "Resulting elm.mailinglists is following:"
    $echo
    if $test "$fastread" = yes; then
	$cat bin/elm.mailinglists
    elif $test $more != more ; then
	$more bin/elm.mailinglists
    else
	$cat bin/elm.mailinglists
    fi
    $echo

    rp="If you need to edit bin/elm.mailinglists, do it as a shell escape here:"
    $echo $n "$rp $c"
    . $UU/myread
    $echo

    $cat <<EOM
Generating elm.aliases file. During configure that file goes 
to bin/elm.aliases. For now doc/mailing.lists is just used
for that.

Existing (if any) elm.aliases from elm global library 
directory is merged with to bin/elm.aliases during 
installation.

EOM
    rp="[Type carriage return to continue]"
    $echo $n "$rp $c"

    . $UU/myread

    . "$source_dir/ConfTool/GenAliases"

    $echo "Resulting elm.aliases is following:"
    $echo
    if $test "$fastread" = yes; then
	$cat bin/elm.aliases
    elif $test $more != more ; then
	$more bin/elm.aliases
    else
	$cat bin/elm.aliases
    fi
    $echo

    rp="If you need to edit bin/elm.aliases, do it as a shell escape here:"
    $echo $n "$rp $c"
    . $UU/myread
    $echo

    $cat <<EOM
Generating elm.mailservices file. During configure that file goes 
to bin/elm.mailservices. For now doc/mail.services is just used
for that.

Existing (if any) elm.mailservices from elm global library 
directory is merged with to bin/elm.mailservices during 
installation.

EOM
    rp="[Type carriage return to continue]"
    $echo $n "$rp $c"

    . $UU/myread

    . "$source_dir/ConfTool/GenMailServices"

    $echo 
    $echo "Resulting bin/elm.mailservices is following:"
    $echo
    if $test "$fastread" = yes; then
	$cat bin/elm.mailservices
    elif $test $more != more ; then
	$more bin/elm.mailservices
    else
	$cat bin/elm.mailservices
    fi
    $echo

    rp="If you need to edit bin/elm.mailservices, do it as a shell escape here:"
    $echo $n "$rp $c"
    . $UU/myread
    $echo

    . "$source_dir/ConfTool/GenHashMarks"

    $echo 
    $echo "Resulting bin/elm.hashmarks is following:"
    $echo
    if $test "$fastread" = yes; then
	$cat bin/elm.hashmarks
    elif $test $more != more ; then
	$more bin/elm.hashmarks
    else
	$cat bin/elm.hashmarks
    fi
    $echo

    rp="If you need to edit bin/elm.hashmarks, do it as a shell escape here:"
    $echo $n "$rp $c"
    . $UU/myread
    $echo
    
    . "$source_dir/ConfTool/GenEntities"
        
    $echo 
    $echo "Resulting bin/elm.tagfilter.entities  is following:"
    $echo
    if $test "$fastread" = yes; then
	$cat bin/elm.tagfilter.entities
    elif $test $more != more ; then
	$more bin/elm.tagfilter.entities
    else
	$cat bin/elm.tagfilter.entities
    fi
    $echo

)

echo " "
echo "End of configuration questions."
echo " "

CONFIG=true

echo " "

case "$batchmode" in
    yes)
    ;;
    *)
    dflt=''
    fastread=''
    echo "If you didn't make any mistakes, then just type a carriage return here."
    rp="If you need to edit config.sh, do it as a shell escape here:"
    $echo $n "$rp $c"
    . $UU/myread
    case "$ans" in
    '') ;;
    *) : in case they cannot read
	eval $ans;;
    esac
esac
: if this fails, just run all the .SH files by hand
. "$source_dir/ConfTool/Substitute"

$rm -f kit*isdone
: the following is currently useless
cd $UU && $rm -f $rmlist
: since this removes it all anyway
cd "$build_dir" && $rm -rf UU
: end of Configure
