#! /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 package 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: Head.U,v 1.0 87/05/22 12:28:10 lwall Exp $
#
# Yes, you may rip this off to use in other distribution packages.
# (Note: this Configure script was generated automatically.  Rather than
# working with this copy of Configure, you may wish to get metaconfig.)

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

if test ! -t 0; then
    echo "Say 'sh Configure', not 'sh <Configure'"
    exit 1
fi

(alias) >/dev/null 2>&1 && \
    echo "(I see you are using the Korn shell.  Some ksh's blow up on Configure," && \
    echo "especially on exotic machines.  If yours does, try the Bourne shell instead.)"

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

d_eunice=''
eunicefix=''
define=''
loclist=''
expr=''
sed=''
echo=''
cat=''
rm=''
mv=''
cp=''
tail=''
tr=''
mkdir=''
sort=''
uniq=''
grep=''
trylist=''
test=''
inews=''
egrep=''
more=''
pg=''
Mcc=''
vi=''
mailx=''
mail=''
contains=''
cpp=''
cppminus=''
d_charsprf=''
d_voidsig=''
libc=''
n=''
c=''
package=''
spitshell=''
shsharp=''
sharpbang=''
startsh=''
voidflags=''
defvoidused=''
d_getopt=''
d_itimer=''
d_systime=''
d_memset=''
d_bstring=''
d_psignal=''
d_rename=''
d_rusage=''
d_server=''
d_sigvec=''
d_sigvectr=''
d_socket=''
d_oldsock=''
socketlib=''
sockethdr=''
inc=''
lib=''
lintlib=''
mkdep=''
orderlib=''
ranlib=''
stackdir=''
CONFIG=''
d_cckr=''

: set package name
package=REAL5.0

echo " "
: Eunice requires " " instead of "", can you believe it
echo " "

define='define'
undef='/*undef'
libpth='/usr/lib /usr/local/lib /lib'
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
attrlist="mc68000 sun gcos unix ibm gimpel interdata tss os mert pyr"
attrlist="$attrlist vax pdp11 i8086 z8000 u3b2 u3b5 u3b20 u3b200"
attrlist="$attrlist ns32000 ns16000 iAPX286 mc300 mc500 mc700 sparc"
attrlist="$attrlist hp9000s200 hp9000s300 hp9000s500 hp9000s800"
pth="/usr/ucb /bin /usr/bin /usr/local /usr/local/bin /usr/lbin /etc /usr/lib"
defvoidused=7

defvoidused=1
undef='undef'
: 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 755 contains
esac

: 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
rm -f .echotmp

: now set up to do reads with possible shell escape and default assignment
cat <<EOSC >myread
ans='!'
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


: copyright notice

cat <<EOH


Copyright (c) 1989, 90, 93 The Regents of the University of California.
All Rights Reserved.

Permission to use, copy, modify, and distribute this software and its
documentation for educational, research and non-profit purposes, 
without fee, and without a written agreement is hereby granted, 
provided that the above copyright notice and the following four
paragraphs appear in all copies.  

Permission to incorporate this software into commercial products may 
be obtained from the Office of Technology Licensing, 2150 Shattuck 
Avenue, Suite 510, Berkeley, CA  94704. 

IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, 
INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND 
ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN 
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE 
PROVIDED HEREUNDER IS ON AN RAS ISS BASIS, AND THE UNIVERSITY OF 
CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, 
UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

The enhancements made in REAL 4.0 have been funded by AT&T and
have been released into the public domain for research use.

Enhancements made in REAL 5.0  have been done at Cornell University and 
are in the public domain.
EOH

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

: 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.  It will create
a file called config.sh, which it will execute to define a set of environment 
variables. These variables are then used to convert the .SH files in this 
directory to regular files, with the right defines in them. The process is 
somewhat complicated, but works most of the time. 

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. Also, let me (lwall@netlabs.com)
know how I blew it.  If you can't run Configure for some reason, you'll have
to generate a config.sh file by hand.

This installation script affects things by making variable substitutions
in all files that end with .SH in the sim/src directory. In $package,
these are Makefile.SH, nest.h.SH, makedepend.SH and makelib.SH.
It also builds a config.h file, which is never used - only nest.h
is actually used.  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


: offer to register user 

cat << EOM
If you register yourself as a user of $package, you will be 
informed about bug fixes and future releases. You only need to
send me one message--please answer 'n' for every subsequent run
of Configure.

EOM

rp="Would you like this script to send mail to register you as a user?[yn]"
echo $n "$rp $c"
. myread
case "$ans" in
   n*) echo "OK, I'll ignore it.";;
    *)  echo "OK, I'm sending mail to skeshav@cs.cornell.edu..."
cat <<EOM > __msg__
Configuration done for REAL 5.0 on this system.

EOM

if test -f /bin/mail; then
     /bin/mail skeshav@cs.cornell.edu  < __msg__
elif test -f /usr/ucb/mail; then
    /usr/ucb/mail skeshav@cs.cornell.edu < __msg__
elif test -f /usr/bin/mail; then
    /usr/bin/mail skeshav@cs.cornell.edu < __msg__
else 
    echo "Sorry, couldn't seem to be able to access your mailer"
fi

rm -f  __msg__
	;;
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 755 loc
$eunicefix loc
loclist="
expr
sed
echo
cat
rm
tr
sort
grep
"
trylist="
test
"
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)
    echo " "
    if sh -c "PATH= test true" >/dev/null 2>&1
    then
	echo "Using the test built into 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"

: get list of predefined functions in a handy place
echo " "
if test -f /lib/libc.a; then
    echo "Your C library is in /lib/libc.a.  You're normal."
    libc=/lib/libc.a
else
    ans=`loc libc.a blurfl/dyick $libpth`
    if test -f $ans; then
	echo "Your C library is in $ans, of all places."
	libc=$ans
    else
	if test -f "$libc"; then
	    echo "Your C library is in $libc, like you said before."
	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
fi
echo " "
$echo $n "Extracting names from $libc for later perusal...$c"
if ar t $libc > libc.list; then
    echo "done"
else
    echo " "
    echo "The archiver doesn't think $libc is a reasonable library."
    echo "Trying nm instead..."
    if nm -g $libc > libc.list; then
	echo "Done.  Maybe this is Unicos, or an Apollo?"
    else
	echo "That didn't work either.  Giving up."
	exit 1
    fi
fi
rmlist="$rmlist libc.list"

: make some quick guesses about what we are up against
echo " "
$echo $n "Hmm...  $c"
if $contains SIGTSTP /usr/include/signal.h >/dev/null 2>&1 ; then
    echo "Looks kind of like a BSD system, but we'll see..."
    echo exit 0 >bsd
    echo exit 1 >usg
    echo exit 1 >v7
elif $contains fcntl libc.list >/dev/null 2>&1 ; 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
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 $contains vmssystem libc.list >/dev/null 2>&1 ; then
    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
    eunicefix=unixtovms
    d_eunice="$define"
: it so happens the Eunice I know will not run shell scripts in Unix format
else
    echo " "
    echo "Congratulations.  You aren't running Eunice."
    eunicefix=':'
    d_eunice="$undef"
    echo "exit 1" >eunice
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 755 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 755 bsd usg v7 eunice venix xenix
$eunicefix bsd usg v7 eunice venix xenix
rmlist="$rmlist bsd usg v7 eunice venix xenix"

: 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..."
    echo "#!/bin/echo hi" > try
    $eunicefix try
    chmod 755 try
    try > today
    if test -s today; then
	echo "It does."
	sharpbang='#!'
    else
	echo "#! /bin/echo hi" > try
	$eunicefix try
	chmod 755 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 755 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 >try <<EOSS
$startsh
set abc
test "$?abc" != 1
EOSS

chmod 755 try
$eunicefix 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

: 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
ABC
EOT
echo 'Maybe "/lib/cpp" will work...'
/lib/cpp <testcpp.c >testcpp.out 2>&1
if $contains 'abc' testcpp.out >/dev/null 2>&1 ; then
    echo "Yup, it does."
    cpp='/lib/cpp'
    cppminus='';
else
    echo 'Nope, maybe "/lib/cpp -" will work...'
    /lib/cpp - <testcpp.c >testcpp.out 2>&1
    if $contains 'abc' testcpp.out >/dev/null 2>&1 ; then
	echo "Yup, it does."
	cpp='/lib/cpp'
	cppminus='-';
    else
	echo 'No such luck...maybe "cc -E" will work...'
	cc -E <testcpp.c >testcpp.out 2>&1
	if $contains 'abc' testcpp.out >/dev/null 2>&1 ; then
	    echo "It works!"
	    cpp='cc -E'
	    cppminus='';
	else
	    echo 'Nixed again...maybe "cc -E -" will work...'
	    cc -E - <testcpp.c >testcpp.out 2>&1
	    if $contains 'abc' testcpp.out >/dev/null 2>&1 ; then
		echo "Hooray, it works!  I was beginning to wonder."
		cpp='cc -E'
		cppminus='-';
	    else
		echo 'Nope...maybe "/opts/SUNWspro/bin/cc -P" will work...'
		    /opts/SUNWspro/bin/cc -P <testcpp.c >testcpp.out 2>&1
		    if $contains 'abc' testcpp.out >/dev/null 2>&1 ; then
		        echo "Yup, that does."
			cpp='/opts/SUNWspro/bin/cc -P'
		        cppminus='';
		    else
		    	echo 'Nope...maybe "cc -P" will work...'
			cc -P <testcpp.c >testcpp.out 2>&1
			if $contains 'abc' testcpp.out >/dev/null 2>&1 ; then
		    	    echo "Yup, that does."
		    	    cpp='cc -P'
		    	    cppminus='';
		    	else
			    echo 'Hmm...perhaps you already told me...'
		     	    case "$cpp" in
			        '') ;;
			        *) $cpp $cppminus <testcpp.c >testcpp.out 2>&1;;
			    esac
			    if $contains 'abc' testcpp.out >/dev/null 2>&1 ; then
			       echo "Hooray, you did!  I was beginning to wonder."
			    else
			       echo 'Uh-uh.  Time to get fancy...'
			       echo 'Trying (cat >/tmp/$$.c; cc -E /tmp/$$.c; rm /tmp/$$.c)'
			       cpp='(cat >/tmp/$$.c; cc -E /tmp/$$.c; rm /tmp/$$.c)'
			       cppminus='';
			       $cpp <testcpp.c >testcpp.out 2>&1
			       if $contains 'abc' 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
				   cpp="$ans"
				   $cpp <testcpp.c >testcpp.out 2>&1
				   if $contains 'abc' 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

: see if memory functions exist
echo " "
if $contains memcmp libc.list >/dev/null 2>&1; then
    d_memset="$define"
    if $contains bcmp libc.list >/dev/null 2>&1; then
	echo 'both memory and bstring functions found.'
	d_bstring="$define"
    else
	echo 'memory functions found.'
	d_bstring="$undef"
    fi
else
    d_memset="$undef"
    if $contains bcmp libc.list >/dev/null 2>&1; then
	echo 'bstring functions found.'
	d_bstring="$define"
    else
	echo 'no memory or bstring functions found.'
	d_bstring="$undef"
    fi
fi
: see if sprintf is declared as int or pointer to char
echo " "
if $contains 'char.*sprintf' /usr/include/stdio.h >/dev/null 2>&1 ; then
    echo "Your sprintf() returns (char*)."
    d_charsprf="$define"
else
    echo "Your sprintf() returns (int)."
    d_charsprf="$undef"
fi

: see if getopt exists
echo " "
if $contains getopt libc.list >/dev/null 2>&1; then
    echo 'getopt() found.'
    d_getopt="$define"
else
    echo 'getopt() not found--will use our getopt instead.'
    d_getopt="$undef"
fi
: see if timeval exists
echo " "
if test -f /usr/include/sys/time.h; then
    if $contains timeval /usr/include/sys/time.h >/dev/null 2>&1; then
        echo 'timeval found.'
        d_itimer="$define"
	d_systime=/usr/include/sys/time.h
    else
        d_itimer="$undef"
        d_systime=/usr/include/time.h
    fi
else 
    if test -f /usr/include/time.h; then
        if $contains timeval /usr/include/time.h >/dev/null 2>&1; then
            echo 'timeval found.'
            d_itimer="$define"
	    d_systime=/usr/include/time.h
        else
            d_itimer="$undef"
            d_systime=/usr/include/time.h
        fi
    else
        echo 'timeval not found'
    fi
fi

socketlib=''
sockethdr=''
: see whether socket exists
echo " "
if $contains socket libc.list >/dev/null 2>&1; then
    echo "Looks like you have Berkeley networking support."
    d_socket="$define"
    : now check for advanced features
    if $contains setsockopt libc.list >/dev/null 2>&1; then
	d_oldsock="$undef"
    else
	echo "...but it uses the old 4.1c interface, rather than 4.2"
	d_oldsock="$define"
    fi
else
    : hpux, for one, puts all the socket stuff in socklib.o
    if $contains socklib libc.list >/dev/null 2>&1; then
	echo "Looks like you have Berkeley networking support."
	d_socket="$define"
	: we will have to assume that it supports the 4.2 BSD interface
	d_oldsock="$undef"
    else
	echo "Hmmm...you don't have Berkeley networking in libc.a..."
	: look for an optional networking library
	if test -f /usr/lib/libnet.a; then
	    (ar t /usr/lib/libnet.a ||
		nm -g /usr/lib/libnet.a) 2>/dev/null >> libc.list
	    if $contains socket libc.list >/dev/null 2>&1; then
		echo "but the Wollongong group seems to have hacked it in."
		socketlib="-lnet"
		sockethdr="-I/usr/netinclude"
		d_socket="$define"
		: now check for advanced features
		if $contains setsockopt libc.list >/dev/null 2>&1; then
		    d_oldsock="$undef"
		else
		    echo "...using the old 4.1c interface, rather than 4.2"
		    d_oldsock="$define"
		fi
	    else
		echo "or even in libnet.a, which is peculiar."
		d_socket="$undef"
		d_oldsock="$undef"
	    fi
	else
	    echo "or anywhere else I see."
	    d_socket="$undef"
	    d_oldsock="$undef"
	fi
    fi
fi
: see if rename exists
echo " "
if $contains rename libc.list >/dev/null 2>&1; then
    echo 'rename() found.'
    d_rename="$define"
else
    echo 'rename() not found--link() and unlink() will be used instead.'
    d_rename="$undef"
fi
: see if getrusage exists
echo " "
if $contains getrusage libc.list >/dev/null 2>&1; then
    echo 'getrusage() found.'
    d_rusage="$define"
else
    echo 'getrusage() not found--cpu accounting may be less accurate.'
    d_rusage="$undef"
fi

: Force the server option to be undefined, since this is unsupported in REAL 3.0

d_server="$undef"

: see if sigvector exists -- since sigvec will match the substring
echo " "
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
	echo 'sigvec() not found--race conditions with signals may occur.'
	d_sigvec="$undef"
    fi
fi
: see if signal is declared as pointer to function returning int or void
echo " "
if $contains 'void.*signal' /usr/include/signal.h >/dev/null 2>&1 ; then
    echo "You have void (*signal())() instead of int."
    d_voidsig="$define"
else
    echo "You have int (*signal())() instead of void."
    d_voidsig="$undef"
fi

: check for void type
echo " "
$cat <<EOM
Checking to see how well your C compiler groks the void type...

  Support flag bits are:
    1: basic void declarations.
    2: arrays of pointers to functions returning void.
    4: operations between pointers to and addresses of void functions.

EOM
case "$voidflags" in
'')
    $cat >try.c <<'EOCP'
#if TRY & 1
void main() {
#else
main() {
#endif
	extern void moo();
	void (*goo)();
#if TRY & 2
	void (*foo[10])();
#endif

#if TRY & 4
	if(goo == moo) {
		exit(0);
	}
#endif
	exit(0);
}
EOCP
    if cc -S -DTRY=7 try.c >.out 2>&1 ; then
	voidflags=7
	echo "It appears to support void fully."
	if $contains warning .out >/dev/null 2>&1; then
	    echo "However, you might get some warnings that look like this:"
	    $cat .out
	fi
    else
	echo "Hmm, your compiler has some difficulty with void.  Checking further..."
	if cc -S -DTRY=1 try.c >/dev/null 2>&1 ; then
	    echo "It supports 1..."
	    if cc -S -DTRY=3 try.c >/dev/null 2>&1 ; then
		voidflags=3
		echo "And it supports 2 but not 4."
	    else
		echo "It doesn't support 2..."
		if cc -S -DTRY=5 try.c >/dev/null 2>&1 ; then
		    voidflags=5
		    echo "But it supports 4."
		else
		    voidflags=1
		    echo "And it doesn't support 4."
		fi
	    fi
	else
	    echo "There is no support at all for void."
	    voidflags=0
	fi
    fi
esac
dflt="$voidflags";
rp="Your void support flags add up to what? [$dflt]"
$echo $n "$rp $c"
. myread
voidflags="$ans"
$rm -f try.* .out

: 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 755 filexp
$eunicefix filexp

: see if we have the 4.3 /lib/cpp -M feature
echo " "
echo "Checking how to generate makefile dependencies on your machine..."
$cat >dep.c <<'EOCP'
#include "dep.h"
EOCP
$cat >dep.h <<'EOCP'
EOCP
if $cpp -M dep.c >dep.out 2>/dev/null </dev/null &&
	$contains 'dep\.o:.*dep\.h' dep.out >/dev/null 2>&1
then
	echo "$cpp -M seems to work here."
	mkdep="$cpp -M"
else
    if cc -xM1 dep.c >dep.out 2>/dev/null </dev/null &&
	$contains 'dep\.o:.*dep\.h' dep.out >/dev/null 2>&1
    then
: this is for solaris
	echo "cc -xM1 seems to work here."
	mkdep="cc -xM1"
    else
	echo $n "$cc -xM1 doesn't seem to work...$c"
	case "$mkdep" in
	'') ;;
	`pwd`/mkdep)
		mkdep=
		;;
	*)
		if $mkdep dep.c >dep.out 2>/dev/null &&
			$contains 'dep\.o:.*dep\.h' dep.out >/dev/null 2>&1
		then
			echo "but $mkdep does, as you said before."
		else
			mkdep=
		fi
		;;
	esac
	if test -z "$mkdep"; then
		$spitshell >mkdep <<EOS
$startsh
for srcfile
do
	filebase=\`basename \$srcfile .c\`
	$sed -n -e '/^#/!d' -e 's|/\*.*$||' -e p \$srcfile | \\
	$cpp $cppminus | \\
	$sed -e '/^# *[0-9]/!d' \\
		-e 's/^.*"\(.*\)".*\$/'\$filebase'.o: \1/' \\
		-e 's|: \./|: |' \\
		-e 's|: *$|: '\$srcfile'|' | \\
	$sort -u
done
EOS
		chmod +x mkdep
		mkdep=`pwd`/mkdep
		if $mkdep dep.c >dep.out 2>/dev/null &&
			$contains 'dep\.o:.*dep\.h' dep.out >/dev/null 2>&1
		then
			echo "but a shell script using $cpp does."
		else
			echo " "
			echo "in fact, $cpp doesn't seem to be any use at all."
			$spitshell >mkdep2 <<EOS
$startsh
for srcfile
do
	echo \`basename \$srcfile .c\`.o: \$srcfile
	$grep '^#[  ]*include' \$srcfile /dev/null || true | 
	$sed -e 's,<\(.*\)>,"/usr/include/\1",' \\
		-e 's/:[^"]*"\([^"]*\)".*/: \1/' \\
		-e 's/\.c:/\.o:/'
done
EOS
			chmod +x mkdep2
			mkdep=${mkdep}2
			if $mkdep dep.c >dep.out 2>/dev/null &&
			    $contains 'dep\.o:.*dep\.h' dep.out >/dev/null 2>&1
			then
				cat << EOM
I can use a script with grep instead, but it will make some incorrect
dependencies, since it doesn't understand about conditional compilation.
If you have a program which generates makefile dependencies, you may want
to use it.  If not, you can use the script and edit the Makefile by hand
if you need to.
EOM
			else
				mkdep=
				cat << EOM
I can't seem to generate makefile dependencies at all!  Perhaps you have a
program which does?  If you don't, you might look in `pwd` at the
mkdep and mkdep2 scripts to see if you can create one which works.
EOM
			fi
		fi	
	fi
	cont=true
	dflt="$mkdep"
	while $test "$cont" ; do
		echo " "
	rp="Name of program to make makefile dependencies? [$dflt]"
	$echo $n "$rp $c"
	. myread
	mkdep="$ans"
	mkdep=`filexp $mkdep`
	if test -f "$mkdep"; then
		cont=''
	else
		dflt=n
		rp="$mkdep doesn't exist.  Use that name anyway? [$dflt]"
		$echo $n "$rp $c"
		. myread
		dflt=''
		case "$ans" in
		y*) cont='';;
		esac
	fi
done
    fi
fi
rm -f dep.c dep.h dep.o dep.out
: 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=":"
else
	if test -f /usr/bin/ranlib; then
		ranlib=/usr/bin/ranlib
	elif test -f /bin/ranlib; then
		ranlib=/bin/ranlib
	fi

	if test -n "$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
: get C preprocessor symbols handy
echo " "
echo $attrlist | $tr '[ - ]' '[\012-\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-\012]' | $sed -e 's/\(.*\)/\\
#ifdef \1\\
exit 0; _ _ _ _\1\\	 \1\\
#endif\\
/' >/tmp/Cppsym\$\$
echo exit 1 >>/tmp/Cppsym\$\$
$cpp $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 755 Cppsym
$eunicefix 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 which way the stack grows

case "$stackdir" in
'')
    if Cppsym vax sun mc68000 ns32000 ns16000; then
	dflt=y
    elif Cppsym u3b2; then
	dflt=n
    else
	dflt=y
    fi
    ;;
1)  dflt=n ;;
-1) dflt=y ;;
esac
cat <<EOH
 
On different machines the stack grows in different directions.  The usual
case is for the stack to grow from higher addresses towards lower addresses.
If you're not sure, try the default.  If that causes $package to fail,
run Configure again and try it the other way.

EOH
rp="Does this machine's stack grow in the usual direction (from high to low)?"
$echo $n "$rp [$dflt] $c"
. myread
case "$ans" in
n*)
    stackdir=1 ;;
*)
    stackdir=-1 ;;
esac

: check for structure copying
echo " "
echo "Checking to see if your C compiler can copy structs..."
$cat >try.c <<'EOCP'
main()
{
	struct blurfl {
	    int dyick;
	} foo, bar;

	foo = bar;
}
EOCP
if cc -c try.c >/dev/null 2>&1 ; then
    echo "Yup, it can."
else
    echo "Nope, it can't.  Get a real C compiler if you want to use $package."
fi
$rm -f try.*

: check for -cckr option
echo " "
echo "Checking to see if your C compiler understands the -cckr option" 
$cat >try.c <<'EOCP'
main()
{
;
}
EOCP
cc -cckr try.c 2>try.cckr
if $contains unknown try.cckr >/dev/null 2>&1; then
    echo "Nope, it can't. "
    d_cckr='' 
elif $contains unrecognized try.cckr >/dev/null 2>&1; then
    echo "Nope, it can't."
    d_cckr=''
elif $contains illegal try.cckr >/dev/null 2>&1; then
    echo "Nope, it can't."
    d_cckr=''
else
    echo "Yup, it can."
    d_cckr='-cckr'
fi
$rm -f try.* 

: check for state assembler routines

cat << EOM
Nest requires four assembler routines, stack, xstack, freeze and cook, in the
file state.S.  If you have not already extracted state.s from this file,
please do a shell escape now and edit state.S.

If your machine does not exist in the state.S, you will need to write 
versions of these four routines for your machine.  The comments 
in state.S describe the function of these routines.
After reading these comments, looking at the source (or a disassembly) of
the setjmp() and longjmp() routines should get you started.

EOM

echo " "
echo "End of configuration questions."
echo " "

: create config.sh file
echo " "
if test -d ../UU; then
    cd ..
fi
echo "Creating config.sh..."
$spitshell <<EOT >config.sh
$startsh
# config.sh
# This file was produced by running the Configure script.

d_eunice='$d_eunice'
eunicefix='$eunicefix'
define='$define'
expr='$expr'
sed='$sed'
echo='$echo'
cat='$cat'
rm='$rm'
tr='$tr'
sort='$sort'
grep='$grep'
test='$test'
contains='$contains'
cpp='$cpp'
cppminus='$cppminus'
d_charsprf='$d_charsprf'
d_voidsig='$d_voidsig'
libc='$libc'
n='$n'
c='$c'
package='$package'
spitshell='$spitshell'
shsharp='$shsharp'
sharpbang='$sharpbang'
startsh='$startsh'
voidflags='$voidflags'
defvoidused='$defvoidused'
d_getopt='$d_getopt'
d_itimer='$d_itimer'
d_systime='$d_systime'
d_memset='$d_memset'
d_bstring='$d_bstring'
d_psignal='$d_psignal'
d_rename='$d_rename'
d_rusage='$d_rusage'
d_server='$d_server'
d_sigvec='$d_sigvec'
d_sigvectr='$d_sigvectr'
d_socket='$d_socket'
d_oldsock='$d_oldsock'
socketlib='$socketlib'
sockethdr='$sockethdr'
inc='$inc'
lib='$lib'
lintlib='$lintlib'
mkdep='$mkdep'
orderlib='$orderlib'
ranlib='$ranlib'
stackdir='$stackdir'
d_cckr='$d_cckr'
CONFIG=true
EOT
 
echo " "
dflt=''
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

echo " "
echo "Doing variable substitutions on .SH files..."
CONFIG=false
. config.sh
set x `awk '{print $1}' <MANIFEST | $grep '\.SH'`
shift
case $# in
0) set x *.SH; shift;;
esac
if test ! -f $1; then
    shift
fi
for file in $*; do
    case "$file" in
    */*)
	dir=`$expr X$file : 'X\(.*\)/'`
	file=`$expr X$file : 'X.*/\(.*\)'`
	(cd $dir && . $file)
	;;
    *)
	. $file
	;;
    esac
done

: make depend and nest.a

dflt=n
echo Running make depend...
make depend
echo making nest.a library
make nest.a
echo cd to ../sim
cd ../sim
echo cd kernel
cd kernel
echo sh makefile.SH
sh makefile.SH
cd ..
echo Running make depend
make depend 
echo Running make
make
cd ../src
echo "If any of the previous steps failed, do not worry! Check the options in src/Makefile (for using shared libraries), in sim/makefile (for choices of cc and nm flags). You can usually get things to work by making changes in one or more of these files."

: cleanup

$rm -f kit*isdone
cd UU && $rm -f $rmlist

: end of Configure
