#!/bin/sh
################################################################################
##          (C) Copyright 1993, Xyplex, Inc. All Rights Reserved.             ##
################################################################################
################################################################################
##  
##    Xyplex HOST utilities installation script.  Based upon Larry Wall's perl
##    "Configure" script.  Simply type "Install" to run.  This script has 
##    run on the following platforms:
##
##      SunOS       4.1.3  (Solaris 1.0.1)
##      SunOS       5.1    (Solaris 2.1)
##      AIX         3.2    
##      Ultrix-32   3.0, 4.3
##      UMIPS       4.02, 4.52
##	Interactive 3.2
##      HP-UX       9.03
##	SCO Unix    3.2
##	NCR
##
################################################################################
#    $Id: Install,v 1.11 1995/04/27 19:16:18 sas Exp $
################################################################################

#  Make sure this was invoked with sh...

cat >/tmp/c1$$ <<EOF
You didn't run $0 with sh!
I will do it for you...

EOF

export PATH || (cat /tmp/c1$$; sh $0; kill $$)
rm -f /temp/c1$$

#  We're running sh, check for proper invocation....

if test ! -t 0; then
    echo "Usage: ./$0 OR sh $0, NOT sh < $0"
    exit 1
fi

#  Make sure . is on our path.

PATH=$PATH:.

#  We're up and running...Load up the release information.

if test -f ./.release ; then
    . ./.release
fi

#  Create our working directory (if we need to)

if sh -c 'unset CDPATH' >/dev/null 2>&1 ; then
:
else
:
fi

if test ! -d ../UU; then
    if test ! -d UU; then
	mkdir UU
    fi
    cd UU
fi

#  Set up for fast reads...

case "$1" in
-d) shift; fastread='yes';;
esac

ROOT=".."
INSTALL="/usr/$company"

CONFIG_H="$ROOT/src/config.h"
MAKEFILE="$ROOT/src/Makefile"
BUILDOPTS="$ROOT/src/build.opts"
#
#  List of tools being built.  To add a new one do the following:
#    1)  Add its name to TOOLS.
#    2)  Create a new directory src/name.
#    3)  Create a new Makefile src/name/Makefile.
#
TOOLS="csportd apgen"

ptystyle=''
dflt=''
ptybanks=''
ptyunits=''

libc=''
nm_opts=''
inclPath=''
libpth=''
libs=''

define='define'
undef='undef'

#  Define the libraries we might need...

libswanted="c_s net_s net socket nsl_s nsl nm ndir dir ndbm dbm PW malloc sun m bsd BSD x posix ucb pt qb elf i inet"

#  Define where to look for the includes we need...

inclwanted='/usr/include /usr/netinclude /usr/include/sun /usr/include/bsd /usr/include/lan /usr/ucbinclude'


#  Define the functions we'll need

#  Standard UNIX stuff...

unixfuncs="bcopy bzero link symlink mknod"

#  Socket functions...

sockfuncs="socket setsockopt accept connect bind listen getsockname"

#  USG (AT&T SysV) pty functions...

sysVptyfuncs="ptsname unlockpt grantpt"

#  SGI/IRIX specific pty functions...

sgisofunctions=""

#  AIX functions

aixfuncs=""

#  List of programs we need...We'll have problems if these can't be found.

loclist="ar awk cat cc cp echo expr grep ls make mkdir mv nm rm sed sort tr uniq nroff"

#  Here we go...
echo " "
echo "Beginning of configuration questions for $package kit."
# Eunice requires " " instead of "", can you believe it
echo " "


#  change the next line if compiling for Xenix/286 on Xenix/386
xlibpth='/usr/lib/386 /lib/386'


#  Create a library path...

test -d /usr/cs/lib		&& libpth="$libpth /usr/cs/lib"
test -d /usr/ccs/lib		&& libpth="$libpth /usr/ccs/lib"
test -d /usr/lib		&& libpth="$libpth /usr/lib"
test -d /usr/ucblib		&& libpth="$libpth /usr/ucblib"
test -d /usr/local/lib		&& libpth="$libpth /usr/local/lib"
test -d /usr/lib/large		&& libpth="$libpth /usr/lib/large"
test -d /lib			&& libpth="$libpth /lib"
				   libpth="$libpth $xlibpth"
test -d /lib/large		&& libpth="$libpth /lib/large"
test -d /usr/lib/small		&& libpth="$libpth /usr/lib/small"
test -d /lib/small		&& libpth="$libpth /lib/small"
test -d /usr/lib/cmplrs/cc	&& libpth="$libpth /usr/lib/cmplrs/cc"

trap 'echo " "; exit 1' 1 2 3

test -d /bin                    && ALLBIN=/bin
test -d /usr/bin                && ALLBIN=$ALLBIN:/bin
test -d /usr/local/bin          && ALLBIN=$ALLBIN:/usr/local/bin
test -d /usr/ucb                && ALLBIN=$ALLBIN:/usr/ucb
test -d /usr/ccs/bin            && ALLBIN=$ALLBIN:/usr/ccs/bin
test -d /usr/gnu/bin            && ALLBIN=$ALLBIN:/usr/gnu/bin
test -d /usr/lbin               && ALLBIN=$ALLBIN:/usr/lbin
test -d /usr/5bin               && ALLBIN=$ALLBIN:/usr/5bin
test -d /vol/local/bin          && ALLBIN=$ALLBIN:/vol/local/bin
test -d /sys5.3/bin             && ALLBIN=$ALLBIN:/sys5.3/bin
test -d /sys5.3/usr/bin         && ALLBIN=$ALLBIN:/sys5.3/usr/bin
test -d /bsd4.3/bin             && ALLBIN=$ALLBIN:/bsd4.3/bin
test -d /bsd4.3/usr/bin         && ALLBIN=$ALLBIN:/bsd4.3/usr/bin
test -d /bsd43/usr/bin          && ALLBIN=$ALLBIN:/bsd43/usr/bin

#  We must find out about Eunice early
eunicefix=':'
if test -f /etc/unixtovms; then
    eunicefix=/etc/unixtovms
fi
if test -f /etc/unixtovms.exe; then
    eunicefix=/etc/unixtovms.exe
fi

boPATH=""
eoPATH="/usr/ucb /bin /usr/bin /usr/local /usr/local/bin /usr/lbin /usr/plx /usr/5bin /vol/local/bin /etc /usr/lib /lib /usr/local/lib /sys5.3/bin /sys5.3/usr/bin /bsd4.3/bin /bsd4.3/usr/bin /bsd4.3/usr/ucb /bsd43/usr/bin /usr/ccs/bin /usr/ccs/lib /opt/SUNWste/bin /usr/opt/SUNWste/bin /usr/gnu/bin"

d_newshome="/usr/NeWS"
errnolist=errnolist
h_fcntl=false
h_sys_file=false
serve_shm=""
serve_msg="$undef"
serve_inet_udp=""
serve_inet_tcp=""
serve_unix_udp=""
serve_unix_tcp=""
d_ndir=ndir
voidwant=1
voidwant=7

#  some greps do not return status, grrr.

echo "grimblepritz" >contains.txt
if grep blurfldyick contains.txt >/dev/null 2>&1 ; then
    contains=contains
elif grep grimblepritz contains.txt >/dev/null 2>&1 ; then
    contains=grep
else
    contains=contains
fi

#  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..."
    if test -f /bsd43/bin/echo; then
	echo "#!/bsd43/bin/echo hi" > spit.sh
    else
	echo "#!/bin/echo hi" > spit.sh
    fi
    $eunicefix spit.sh
    chmod +x spit.sh
    ./spit.sh > today
    if $contains hi today >/dev/null 2>&1; then
	echo "It does."
	sharpbang='#!'
    else
	echo "#! /bin/echo hi" > spit.sh
	$eunicefix spit.sh
	chmod +x spit.sh
	./spit.sh > 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
    $eunicefix 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 >start.sh <<EOSS
$startsh
set abc
test "$?abc" != 1
EOSS

chmod +x start.sh
$eunicefix start.sh
if ./start.sh; then
    echo "Yup, it does."
else
    echo "Nope.  You may have to fix up the shell scripts to make sure sh runs them."
fi

#  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
echo $n "Type carriage return to continue.  Your cursor should be here-->$c"
read ans

#  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 $company $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
many UNIX systems.  If your system proves to be an exception, you may have
to edit src/config.h, and/or src/Makefile, and/or src/build.opts and/or 
this script ($0) by hand.

This installation script will create 3 files, src/config.h, src/Makefile and
src/build.opts.  src/config.h is included by the 'C' programs and defines your 
system's configuration.  src/Makefile and src/build.opts is used to build and 
install the $company $package package.

You must be root in order to install the package, but any user can build it.

If you run into problems, you may wish to contact $company for assistance.

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

#  find out where common programs are

cat <<EOH

I will now locate the programs I need to run this script.  If any of these 
programs cannot be found you will probaly run into problems with this 
installation script.  To remedy this situation, add the directory 
containing the missing program(s) to your PATH and invoke $0.

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

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
	elif test -f \$dir/\$thing.exe; then
	    : on Eunice apparently
	    echo \$dir/\$thing
	    exit 0
	fi
	;;
    esac
done
echo \$dflt
exit 1
EOSC
chmod +x loc
$eunicefix loc

pth=`echo :$boPATH:$PATH:$eoPATH: | sed -e 's/:/ /g'`

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


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" >Loc1.txt
    echo $n "hi there$c" >Loc2.txt
    if cmp Loc1.txt Loc2.txt >/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
    ;;
*)
    : cross your fingers
    echo=echo
    ;;
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
$eunicefix filexp

cat >whoa <<'EOF'
eval "was=\$$2"
dflt=y
echo ' '
echo "*** WHOA THERE!!! ***"
echo "    The $hint value for \$$2 on this machine was \"$was\"!"
rp="    Keep the $hint value? [y]"
echo $n "$rp $c"
. ./myread
case "$ans" in
y) td=$was; tu=$was;;
esac
EOF

setvar='td=$define; tu=$undef; set X $1; eval "was=\$$2";
case "$val$was" in
defineundef) . whoa; eval "$2=\$td";;
undefdefine) . whoa; eval "$2=\$tu";;
*) eval "$2=$val";;
esac'
# determine where public executables go
cat <<EOF

Find where to put executables... 
 
EOF
case "$bin" in
'')
    dflt=`./loc . /usr/local/bin /usr/local/bin /usr/lbin /usr/local /usr/bin /bin`
    ;;
*)  dflt="$bin"
    ;;
esac
cont=true
while $test "$cont" ; do
    rp="Where do you want the executables installed (~name ok)? [$dflt]"
    $echo "Where do you want the executables installed (~name ok)?"
    $echo $n "[$dflt] $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

case "$bin" in
  ?????????????????????????)
    cat <<EOF

NOTE: you have a fairly long path name there.  Some systems have trouble
executing a script if the #! line ends up longer than 32 characters.  If
you have this trouble you may have to reinstall somewhere else, or make
a symbolic link from someplace with a shorter name.

EOF
    ;;
esac


# determine where manual pages go
$cat <<EOM
  
$package has manual pages available in source form.
EOM
case "$nroff" in
'nroff')
    echo "However, you don't have nroff, so they're probably useless to you."
    echo "The cat version of the pages will be installed in the directory"
    echo "that you specify."
    catman="yes"    
    case "$mansrc" in
    '')
	mansrc=''
	;;
    esac
esac
echo "If you don't want the manual pages installed, answer 'none'."
case "$mansrc" in
'')
    case "$catman" in
    '')
        dflt=`./loc . none /usr/man/local/man1 /usr/man/man.L /usr/man/manl /usr/man/mann /usr/man/u_man/man1 /usr/local/man/man1 /usr/local/man /usr/man/man1`
	;;
    'yes')
      	dflt='/usr/man/catman/u_man/manl'
        ;;
    esac
    ;;
*)  dflt="$mansrc"
    ;;
esac
cont=true
while $test "$cont" ; do
    echo " "
    rp="Where do the manual pages (source) go (~name ok)? [$dflt]"
    $echo $n "$rp $c"
    . ./myread
    case "$ans" in
    'none')
	mansrc='none'
	cont=''
	;;
    *)
        mansrc=`./filexp "$ans"`
        if $test -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
	;;
    esac
done
case "$mansrc" in
'')
    mansrc='none'
    ;;
'none')
    manext=''
    ;;
*l)
    manext=l
    ;;
*n)
    manext=n
    ;;
*o)
    manext=l
    ;;
*p)
    manext=n
    ;;
*C)
    manext=C
    ;;
*L)
    manext=L
    ;;
*)
    manext=1
    ;;
esac

case "$usrinclude" in
'') dflt='/usr/include';;
*) dflt=$usrinclude;;
esac

cont=true
while $test "$cont" ; do
    echo " "
    rp="Where are the include files you want to use? [$dflt]"
    $echo $n "$rp $c"
    . ./myread
    usrinclude="$ans"
    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
	dflt=''
	case "$ans" in
	y*) cont='';;
	esac
    fi
done

#  make some quick guesses about what we are up against

#  Sigh.  Well, at least the box is fast...

echo " "
$echo $n "Hmm...  $c"
inclPath=''
if $test -f /bin/mips && /bin/mips; then
    echo "Looks like a MIPS system..."
    echo "exit 0" >mips
    chmod +x mips
    $eunicefix mips
    $cat >usrinclude.c <<'EOCP'
#ifdef SYSTYPE_BSD43
/bsd43
#endif
EOCP
    if $cc -E usrinclude.c > usrinclude.out && $contains / usrinclude.out >/dev/null 2>&1 ; then
	echo "and you're compiling with the BSD43 compiler and libraries."
	dflt='/bsd43/usr/include'
	inclPath='/bsd43'
    else
	echo "and you're compiling with the SysV compiler and libraries."
    fi
else
    echo "Doesn't look like a MIPS system."
    echo "exit 1" >mips
    chmod +x mips
    $eunicefix mips
fi

echo exit 1 >bsd
echo exit 1 >usg
echo exit 1 >v7
echo exit 1 >osf1
echo exit 1 >eunice
echo exit 1 >xenix
echo exit 1 >venix
echo exit 1 >aix
echo exit 1 >hpux
echo exit 1 >sco
echo exit 1 >ncr
cat $usrinclude/signal.h $usrinclude/sys/signal.h >guess.txt 2>/dev/null
if test "$usrinclude" = "/bsd43/usr/include" ; then
    echo "Looks kind of like a SysV MIPS running BSD, but we'll see..."
    echo exit 0 >bsd
elif test -f /osf_boot || $contains "OSF/1" /usr/include/ctype.h; then
    echo "Looks like an OSF/1 system, but we'll see..."
    echo exit 0 >osf1
elif test `echo abc | tr a-z A-Z` = Abc ; then
    echo "Looks kind of like a USG system, but we'll see..."
    echo exit 0 >usg
elif $contains SIGTSTP guess.txt >/dev/null 2>&1 ; then
    echo "Looks kind of like a BSD system, but we'll see..."
    echo exit 0 >bsd
else
    echo "Looks kind of like a version 7 system, but we'll see..."
    echo exit 0 >v7
fi
case "$eunicefix" in
*unixtovms*)
    cat <<'EOI'
There is, however, a strange, musty smell in the air that reminds me of
something...hmm...yes...I've got it...there's a VMS nearby, or I'm a Blit.
EOI
    echo "exit 0" >eunice
    d_eunice="$define"
    ;;
*)
    echo "Congratulations.  You aren't running Eunice."
    d_eunice="$undef"
    ;;
esac
if test -f /xenix; then
    echo "Actually, this looks more like a XENIX system..."
    echo "exit 0" >xenix
else
    echo "It's not Xenix..."
fi
chmod +x xenix
$eunicefix xenix
if test -f /venix; then
    echo "Actually, this looks more like a VENIX system..."
    echo "exit 0" >venix
else
    if xenix; then
	: null
    else
	echo "It's not Venix..."
    fi
fi

if test -f /lib/syscalls.exp; then
    echo "Looks like AIX."
    echo "exit 0" >aix
else
    echo "It's not AIX..."
fi

if test -x /bin/uname; then
	if test "`/bin/uname`" = HP-UX; then
	   echo "Looks like HP-UX."
	   echo "exit 0" >hpux
	else
       echo "It's not HP-UX..."
	fi
else
	echo "It's not HP-UX..."
fi

if test -d /usr/lib/sco; then
    echo "Looks like SCO Unix."
    echo "exit 0" >sco
else
    echo "It's not SCO Unix..."
fi

if test -f /usr/sbin/machinetype; then
    echo "Looks like NCR."
    echo "exit 0" >ncr
else
    echo "It's not NCR..."
fi

chmod +x bsd usg v7 osf1 eunice venix aix hpux sco ncr
$eunicefix bsd usg v7 eunice venix aix hpux sco ncr

#
#  Do any system specific set up here.
#
if mips ; then
    nm_opts='-B'
    awk='/usr/bsd43/bin/awk'
    ls='/usr/bsd43/bin/ls'
    cat <<EOH

Since this is a MIPs system, I will be using the following...

    nm options : $nm_opts
    awk        : $awk
    ls         : $ls

EOH
fi
	
    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`
    case "$nativegcc" in
    '') case "$ccflags" in
	*-fpcc-struct-return*) dflt=n;;
	*) dflt=y;;
	esac
	;;
    undef) dflt=n;;
    *) dflt=y;;
    esac
    echo " "
    rp="Are your system (especially dbm) libraries compiled with gcc? [$dflt]"
    $echo $n "$rp $c"
    . ./myread
    case "$ans" in
    n*) nativegcc="$undef"; gccflags='-fpcc-struct-return';;
    *) nativegcc="$define"; gccflags='';;
    esac
    case "$gccflags" in
    *-ansi*) ;;
    *-traditional*) ;;
    *) gccflags="$gccflags -traditional -Dvolatile=__volatile__" ;;
    esac
    ;;
esac

# determine optimize, if desired, or use for debug flag also
case "$optimize" in
' ') dflt="none"
     ;;
'') dflt="-O";
    ;;
*)  dflt="$optimize"
    ;;
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".
  
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="$gccflags";;
    *) dflt='';;
    esac
    ;;
*-fpcc-struct-return*) dflt="$ccflags";;
*) case "$cc" in
    *gcc*) dflt="$ccflags $gccflags";;
    *) dflt="$ccflags";;
    esac
    ;;
esac
for thisincl in $inclwanted; do
    if test -d $thisincl; then
	if test "x$thisincl" != "x$usrinclude"; then
	    case "$dflt" in
	    *$thisincl*);;
	    *) dflt="$dflt -I$thisincl";;
	    esac
	fi
    fi
done
case "$optimize" in
-g*)
    case "$dflt" in
    *DEBUGGING*);;
    *) dflt="$dflt -DDEBUGGING";;
    esac
    ;;
esac
if $contains 'LANGUAGE_C' $usrinclude/signal.h >/dev/null 2>&1; then
    case "$dflt" in
    *LANGUAGE_C*);;
    *) dflt="$dflt -DLANGUAGE_C";;
    *) if osf1; then
          dflt="$dflt -D__LANGUAGE_C__"
       else
          dflt="$dflt -DLANGUAGE_C"
       fi
       ;;
    esac
fi
if $contains '_NO_PROTO' $usrinclude/signal.h >/dev/null 2>&1; then
    case "$dflt" in
    *_NO_PROTO*);;
    *) osf1 || dflt="$dflt -D_NO_PROTO";;
    esac
fi
case "$dflt" in
'') dflt=none;;
esac
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.  For instance, this would be a good place to specify
-DDEBUGGING.  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*|-U*|-I*|-traditional|-ansi|-nostdinc) cppflags="$cppflags $flag";;
	esac
    done
    case "$cppflags" in
    *-*)  echo "(C preprocessor flags: $cppflags)";;
    esac
    ;;
esac

echo " "
echo "Checking for optional libraries...(Don't worry if some are missing.)"
case "$libs" in
'') dflt=' ';;
*) dflt="$libs ";;
esac
case "$libswanted" in
'') libswanted='c_s';;
esac
for thislib in $libswanted; do
    case "$thislib" in
    dbm) thatlib=ndbm;;
    *_s) thatlib=NONE;;
    *) thatlib="${thislib}_s";;
    *) thatlib=NONE;;
    esac
    xxx=`./loc lib$thislib.a X /usr/ccs/lib /usr/lib /usr/ucblib /usr/local/lib /lib`
    if test -f $xxx; then
	echo "Found -l$thislib."
	case "$dflt" in
	*-l$thislib\ *|*-l$thatlib\ *);;
	*) dflt="$dflt -l$thislib ";;
	esac
    else
	xxx=`./loc lib$thislib.a X $libpth`
	if test -f $xxx; then
	    echo "Found $xxx."
	    case "$dflt" in
	    *"$xxx "*);;
	    *) dflt="$dflt $xxx ";;
	    esac
	else
	    xxx=`./loc Slib$thislib.a X $xlibpth`
	    if test -f $xxx; then
		echo "Found -l$thislib."
		case "$dflt" in
		*-l$thislib\ *|*-l$thatlib\ *);;
		*) dflt="$dflt -l$thislib ";;
		esac
	    else
		xxx=`./loc lib$thislib.so X /usr/ccs/lib /usr/lib /usr/ucblib /usr/local/lib /lib`
		if test -f $xxx; then
		    echo "Found -l$thislib as a shared object only."
		    case "$dflt" in
		    *-l$thislib\ *|*-l$thatlib\ *);;
		    *) dflt="$dflt -l$thislib ";;
		    esac
		else
		    echo "No -l$thislib."
		fi
	    fi
	fi
    fi
done
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='';
esac
libs="$ans"

#  get list of predefined functions in a handy place
echo " "
case "$libc" in
'') libc=unknown;;
esac
case "$nm_opts" in
'') if test -f /mach_boot; then
	nm_opts=''
    elif test -d /usr/ccs/lib; then
	nm_opts='-p'
    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/lib/libc.so
test -f $1 || set /usr/shlib/libc.so
test -f $1 || set /usr/lib/libc.so.[0-9]*
test -f $1 || set /lib/libsys_s.a
eval set \$$#
if test -f "$1"; then
    echo "Your (shared) C library seems to be in $1."
    libc="$1"
elif test -f "$libc"; then
    echo "Your C library seems to be in $libc."
elif test -f /lib/libc.a; then
    echo "Your C library seems to be 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 seems to be 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
cat <<END
 
If the guess above is wrong (which it might be if you're using a strange
compiler, or your machine supports multiple models), you can override it here.
END
dflt="$libc";
rp="Your C library is where? [$dflt]"
$echo $n "$rp $c"
. ./myread
libc="$ans"
echo " "
echo $libc $libnames | tr ' ' '\012' | sort | uniq >libnames
$echo "Extracting names from the following files for later perusal:"
sed 's/^/	/' libnames
echo $n "This may take a while...$c"
set X `cat libnames`
shift
$nm $nm_opts $* 2>/dev/null >libc.tmp
$sed -n -e 's/^.* [ATDS]  *[_.]*//p' -e 's/^.* [ATDS] //p' <libc.tmp >libc.list
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 '/ file/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/^[         ]*[0-9][0-9a-f]*[       ]*Def. Text[    ]*//p' \
	   < libc.tmp | $sed -e 's/\[.*\]//' > 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/^.* [AT]  *_[_.]*//p' -e 's/^.* [AT] //p' <libc.tmp >libc.list
    if $contains '^printf$' libc.list >/dev/null 2>&1; then
	nm_opts='-p'
	echo "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
if test -f /lib/syscalls.exp; then
    echo "Also extracting names from /lib/syscalls.exp for good ole AIX..."
    sed -n 's/^\([^ 	]*\)[ 	]*syscall$/\1/p' /lib/syscalls.exp >>libc.list
fi

inlibc='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'

#
#  Figure out any ld flags....
#


$awk 'BEGIN{FS="/"}{for (i=1;i<NF;i++){if ($i!="") printf "/%s",$i}}{print ""}' libnames | sort -u > .ldlibdirs
for ldlibdir in `cat .ldlibdirs`; do
    ldflags=$ldflags" -L$ldlibdir"
done

case "$ldflags" in
'') if venix; then
	dflt='-i -z'
    else
	dflt='none'
    fi
    ;;
*) dflt="$ldflags";;
esac

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


echo " "
if test -s $CONFIG_H ; then
    echo "Saving src/config.h in src/config.h.old."
    mv $CONFIG_H $CONFIG_H.old
fi

if test -s $MAKEFILE ; then
    echo "Saving src/Makefile in src/Makefile.old."
    mv $MAKEFILE $MAKEFILE.old
fi

if test -s $BUILDOPTS; then
    echo "Saving src/build.opts in src/build.opts.old."
    mv $BUILDOPTS $BUILDOPTS.old
fi

if bsd; then
    cat <<EOH

I think your system is a BSD style of UNIX.  I expect pseudo terminal
entries to be in /dev and have the form "ptyXY" where X is typically a 
letter from p -> s and Y is a hex digit from o -> f.

Checking your system for "BSD" pseudo terminal entries...

EOH
   $ls -1 /dev/pty?? 2>/dev/null | sort >./.pty.list
   if test -s ./.pty.list; then
	$sed 's/\/dev\/pty//' ./.pty.list >./.pty.data 2>&1
	$awk '{print substr($1,1,1)}' ./.pty.data  | sort -ur >./.pty.banks
	$awk '{print substr($1,2,1)}' ./.pty.data  | sort -ur >./.pty.units
	for bank in `cat ./.pty.banks`; do
	    ptybanks=$ptybanks$bank
	done
	for unit in `cat ./.pty.units`; do
	    ptyunits=$ptyunits$unit
        done

    dflt=$ptybanks    
    rp="Pseudo terminal banks [$dflt]: "
    echo $n $rp $c
    . ./myread
    ptybanks=$ans

    dflt=$ptyunits
    rp="Pseudo terminal units [$dflt]: "
    echo $n $rp $c
    . ./myread
    ptyunits=$ans

    ptystyle="BSD"
   
    else
	echo " "
  	echo "There doesn't seem to by any /dev/pty?? entries!"
        echo "Looking for /dev/ptmx.."
	if [ -r /dev/ptmx ] ; then
	    echo "Will try to use System V pseudo terminals..."
	    ptystyle="SYSV"
	else
	    echo "I cant find any pseudo terminals, the following"
	    ptystyle="NONE"
	fi
   fi
fi

if usg; then
    if [ -r /dev/ptmx ] ; then
	echo " "
        echo "System V pseudo terminals found."
	ptystyle="SYSV"
    else
        echo " "
        echo "Your system looks like a System V type system, but /dev/ptmx "
        echo "doesn't exist.  Checking for BSD type  pseudo terminals devices..."
        $ls -1 /dev/pty?? 2>/dev/null | sort >./.pty.list
        if test -s ./.pty.list; then
  	    $sed 's/\/dev\/pty//' ./.pty.list >./.pty.data 2>&1
	    $awk '{print substr($1,1,1)}' ./.pty.data  | sort -ur >./.pty.banks
	    $awk '{print substr($1,2,1)}' ./.pty.data  | sort -ur >./.pty.units
	    for bank in `cat ./.pty.banks`; do
	        ptybanks=$ptybanks$bank
	    done
	    for unit in `cat ./.pty.units`; do
	        ptyunits=$ptyunits$unit
            done

            dflt=$ptybanks    
            rp="Pseudo terminal banks [$dflt]: "
            echo $n $rp $c
            . ./myread
            ptybanks=$ans

            dflt=$ptyunits
            rp="Pseudo terminal units [$dflt]: "
            echo $n $rp $c
            . ./myread
            ptyunits=$ans
  
            ptystyle="BSD"
   
        else
	    echo "I cant find any pseudo terminals..."
	    ptystyle="NONE"
	fi
    fi
fi


echo " "
echo "Checking for the functions I need...(They will be supplied if missing.)"
echo " "

for func in $unixfuncs ; do
    eval set $func d_$func
    eval $inlibc
done

for func in $sockfuncs ; do
    eval set $func d_$func
    eval $inlibc
done

if [ "$ptystyle" = "SYSV" ] ; then
    for func in $sysVptyfuncs ; do
        eval set $func d_$func
        eval $inlibc
    done
fi

#########################################################################


#
#  Time to create config.h
#
echo "Creating $CONFIG_H..."
cat <<EOH >$CONFIG_H
/*************************************************************************
 *  $company - $package config.h created by $0.
 *  Date :  `date`.  
 *************************************************************************/
/*
 *  Define the "type" of system we're building on.
 */

EOH

if bsd  ; then echo "#define BSD"  >>$CONFIG_H ; fi
if aix  ; then echo "#define AIX"  >>$CONFIG_H ; fi
if usg  ; then echo "#define SYSV" >>$CONFIG_H ; fi
if mips ; then echo "#define MIPS" >>$CONFIG_H ; fi
if hpux ; then echo "#define HPUX" >>$CONFIG_H ; fi
if sco  ; then echo "#define SCO"  >>$CONFIG_H ; fi
if ncr  ; then echo "#define NCR"  >>$CONFIG_H ; fi

cat <<EOH >>$CONFIG_H

/*  PTYSTYLE
 *
 *  Defines the "style" of pseudo terminals the system supports.
 */
#define PTYSTYLE_$ptystyle

EOH

if [ "$ptystyle" = "BSD" ] ; then
    cat <<EOH >>$CONFIG_H
/*  PTYBANKS
 *
 *  Defines the banks of PTYs available on the system.
 */
#define PTYBANKS "$ptybanks"

/*  PTYUNITS
 *
 *  Defines the PTY units (for each bank).
 */
#define PTYUNITS "$ptyunits"

EOH
fi
cat <<EOH >>$CONFIG_H
/*  HAS_BZERO
 * 
 *  Defines if bzero() is available.  If bzero() does not exist, we'll use
 *  our own version.
 */
#$d_bzero HAS_BZERO

/*  HAS_BCOPY
 *
 *  Defines if bcopy() is available.  If bcopy() does not exist, we'll use
 *  our own version.
 */
#$d_bcopy HAS_BCOPY

/*  HAS_SYMLINK
 *
 *  Defines if symlink() is available.  If symlink() doesn't exists, the
 *  "-s" option becomes invalid.
 */
#$d_symlink HAS_SYMLINK

EOH
if aix ; then
    cat <<EOH >>$CONFIG_H
/*  Exit Codes
 *
 *  These constants define the exit codes.  
 *
 *    EXIT_OK     - Everything worked OK.
 *    EXIT_BAD    - Took an error, try again.
 *    EXIT_FATAL  - Took an error which requires user intervention to correct.
 *			(Will bring down printer queues on IBM AIX!)
 *
 *  These values are used in case we're running as a print filter under
 *  the IBM Q daemon.  If we're not acting like a print filter, then 
 *  the exit codes do not matter.
 */
#define EXIT_OK    0
#define EXIT_BAD   101
#define EXIT_FATAL 102

EOH
else
    cat <<EOH >>$CONFIG_H
/*  Exit Codes
 *
 *  These constants define the exit codes.  
 *
 *    EXIT_OK     - Everything worked OK.
 *    EXIT_BAD    - Took an error, try again.
 *    EXIT_FATAL  - Took an error which requires user intervention to correct.
 */
#define EXIT_OK    0
#define EXIT_BAD   1
#define EXIT_FATAL 2

EOH
fi
echo "Creating $BUILDOPTS..."
cat <<EOH >$BUILDOPTS
#
#  Build options generated by $0 on `date`.
#
CC      	= $cc
CCFLAGS 	= $ccflags
LDFLAGS 	= $ldflags
LIBS    	= $libs
RM		= rm

EOH

echo "Creating $MAKEFILE..."
cat <<EOH >$MAKEFILE
#
#  Makefile generated by $0 on `date`.
#

SHELL           = /bin/sh
BIN_DIR         = $bin
MAN_SRC         = $mansrc
MAN_CAT         = $catman
MAN_EXT         = $manext
TOOLS		= $TOOLS

all:	$TOOLS

EOH
for tool in $TOOLS; do
    cat <<EOH >>$MAKEFILE

$tool:	$tool.actions

$tool.actions:
	@if [ -d $tool ] ; then \\
		$echo "==========  Building $tool  ==========" ;\\
		cd $tool ; $make -f ../build.opts -f Makefile  ;\\
	else \\
		: ;\\
	fi
EOH
done

cat <<EOH >>$MAKEFILE

install:
	@$echo "==========  Installing Man Pages  =========="
	@if [ "$(MAN_SRC)" = "none" ] ; then \\
	    $echo "  No place to install man pages...skipping" ; \\
	else \\
	    if [ ! -d $(MAN_SRC) ] ; then \\
               $echo "  Creating $(MAN_SRC)..." ; \\
               mkdir $(MAN_SRC)                ; \\
               chmod 755 $(MAN_SRC)            ; \\
	    fi ;\\
	    for tool in $(TOOLS) ; do		 \\
	       if [ -d \$\$tool ] ; then 	\\
	       		$echo "  \$\$tool..."		; \\
	       		if [ "$(MAN_CAT)" = "yes" ] ; then \\
		   	     cp ../man/cat/\$\$tool.l $(MAN_SRC) ;\\
	       		else \\
	           	     cp ../man/src/\$\$tool.l $(MAN_SRC) ;\\
	       		fi ;\\
	       		chmod 444 $(MAN_SRC)/\$\$tool.l	;\\
		else \\
			: ;\\
		fi ;\\
	    done ;\\
	fi
	@$echo "==========  Installing Tools  =========="
	@if [ ! -d $(BIN_DIR) ] ; then \\
            $echo "  Creating $(BIN_DIR)..." ; \\
            mkdir $(BIN_DIR)                ; \\
            chmod 755 $(BIN_DIR)            ; \\
	fi ;\\
	for tool in $(TOOLS) ; do            \\
	    if [ -d \$\$tool ] ; then 	\\
            	$echo "  \$\$tool..."    		;\\
	        cp \$\$tool/\$\$tool $(BIN_DIR)   	;\\
            	chown root $(BIN_DIR)/\$\$tool     	;\\
            	chmod 755  $(BIN_DIR)/\$\$tool     	;\\
	    else \\
		: ;\\
	    fi ;\\
	done

clean:
	rm -rf ../UU
	rm ../*.out 2>/dev/null
	for tool in $(TOOLS) ; do		 \\
	    if [ -d \$\$tool ] ; then 	\\
	    	cd \$\$tool				;\\
	    	$make clean				;\\
	    	cd ..				;\\
	    else \\
		exit 0 ;\\
	    fi ;\\
	done
	rm *.old 2>/dev/null
	rm config.h build.opts Makefile
EOH

echo " "
echo "Configuration Complete."
echo " "

built=false
installed=false

rp="Shall I compile $package for you?[y]"
$echo $n "$rp $c"
. ./myread

case "$ans" in
n*)
	;;
N*)
	;;
*)
	echo " "
        echo "Compiling $package ...output saved in \"make.out\""
	echo " "
  	cd ../src
	PATH=$PATH:$ALLBIN
	$make > ../make.out 2>&1 && built=true
	$built || {
		echo " "
		echo "Build failed:"
		cat ../make.out
		echo " "
	}
	echo " "	
	;;
esac
if $built; then
  if [ ! -w "/" ] ; then
    echo " "
    echo "Note: you must be running as root to install."
    echo "      Become root and type \"make install\""
    echo " "
  else
	cd ../UU
	rp="Shall I install $package for you?[y]"
	$echo $n "$rp $c"
	. ./myread
	case "$ans" in 
	    n*)
		;;
	    N*)
		;;
	    *)
		echo " "
		echo "Installing... output saved in \"Install.out\""
		echo " "
		cd ../src
		$make install > ../Install.out 2>&1 && installed=true
		$installed || {
	 		echo " "
			echo "Installation failed."
			echo " "
			}
		;;
	esac
	
  fi
fi

$built && $installed || {
    echo " "
    echo "Installation was not completed."
    $built || echo "To compile $package use \"cd src ; $make \""
    $installed || echo "To install $package use \"cd src ; $make install \""
    }

echo " "
echo "$0 Done."
echo " "




