#!/bin/sh
#
# Configure $B%9%/%j%W%H(J
#   July 1. 1992
#
# $B$3$N%9%/%j%W%H$,;H$&JQ?t$N=i4|2=(J
config_sh=config.sh
debug_options=''

# Config $BJQ?t$N=i4|2=(J

if [ -f ${config_sh} ]; then
    # $BA02s$N(J Configure $B$N<B9T7k2L(J(config.sh)$B$N<hF@(J
    . ${config_sh}
else
	machine="symmetry"
	bindir="/usr/local/bin"
	libdir="/usr/local/lib/aum"
	oldlib="no"
	parsegen="bison"
	havedld="yes"
	usesocket="no"
	mbox="socket"
fi

# $B$=$NB>$NJQ?t$N=i4|2=(J

yacc=''
plusplus=''
options=''
debug_options=''
dynamic_link=''
dldlib=''
socket_comm=''
d_iostream=''

top=`pwd`

# $B%f!<%6!<$X$N<ALd(J

cat <<EOM

This program asks you a few questions and generates Makefiles in
several directories in this kit. Type carrige return to take default
answers, shown in square brackets.
EOM

## $BBP>]%O!<%I%&%'%"!?(JOS$B$N<oN`(J
if [ -f "/bin/arch" ]; then
    machine=`/bin/arch`
fi

cont="true"
while test "$cont" ; do
  echo ''
  echo -n "Which is the target machine, sun4 or symmetry[$machine]? "
  read ans
  case $ans in
  '')
	cont=''
    ;;
  "sun4"|"symmetry")
	machine="$ans"
	cont=''
    ;;
  esac
done

## $B<B9T%U%!%$%k$N%$%s%9%H!<%k>l=j(J

cat <<EOM

Now I ask you a few pathnames. Please answer them in absolute forms;
do not use '.' or '..' in them.
EOM

### $B0lHL$N<B9T%U%!%$%k$N%$%s%9%H!<%k>l=j(J

echo ''
echo -n "Where do you install executable programs[$bindir]? "
read ans
case $ans in
'')
  ;;
*)
  bindir="$ans"
  ;;
esac

## $B%i%$%V%i%j%U%!%$%k$N%$%s%9%H!<%k>l=j(J

echo ''
echo -n "Where do you install library files[$libdir]? "
read ans
case $ans in
'')
  ;;
*)
  libdir="$ans"
  ;;
esac

execdir="$libdir/exec"

## GNU C++ $B%i%$%V%i%j$N%P!<%8%g%s(J
# $B!J8E$$HG$N(J C++ $B$G$O%3%s%Q%$%k$G$-$J$/$J$C$?$N$G(J
#  $B$3$N<ALd$O>C5n$7$?!K!#(J
# cat <<EOM
# 
# Older versions(before version 2) of the GNU C++ library provide
# different I/O stream functions than current ones. If you are not sure
# of your library's version, see whether there is a file "strstream.h"
# in standard include file directory. If there is not, your library is
# one of older versions.
# EOM
# 
# cont="true"
# while test "$cont" ; do
#   echo ''
#   echo -n "Is your GNU C++ library an old version[$oldlib]? "
#   read ans
#   case $ans in
#   '')
#     cont=''
# 	;;
#   "yes"|"no")
# 	oldlib="$ans"
#     cont=''
# 	;;
#   esac
# done

oldlib="no"

if test "$oldlib" = "yes"; then
	plusplus="g++"
else
	plusplus="g++ -DIOSTREAM_2_0"
fi

if test "$oldlib" = "yes"; then
	d_iostream=''
else
	d_iostream="-DIOSTREAM_2_0"
fi

## $B%Q!<%6%8%'%M%l!<%?(J

cont="true"
while test "$cont" ; do
  echo ''
  echo -n "Which parser generator do you use, yacc or bison[$parsegen]? "
  read ans
  case $ans in
  '')
	cont=''
    ;;
  "yacc"|"bison")
	parsegen="$ans"
	cont=''
    ;;
  esac
done

case $parsegen in
bison)
  yacc="bison -y"
  ;;
yacc)
  yacc="yacc"
  ;;
esac

## $BB>8@8l%W%m%0%i%`$N5/F0;~%j%s%/5!G=(J

cat <<EOM

The GNU Dld library is necessary for linking foreign language programs
at the beginning of its execution. To see whether it is available,
look for a file 'libdld.a' in directories like '/usr/lib',
'/usr/local/lib', '/usr/gnu/lib', etc.  If you do not have the library, 
you are still able to call foreign language programs by linking them at
A'UM-90's compilation.
EOM

cont="true"
while test "$cont"; do
  echo ''
  echo -n "Do you have Dld[$havedld]? "
  read ans
  case $ans in
  '')
    cont=''
	;;
  "yes"|"no")
	havedld="$ans"
    cont=''
	;;
  esac
done

if test $havedld = "yes" ; then
  dynamic_link="-DDYNAMIC_LINK"
else
  dynamic_link=''
fi

if test $havedld = "yes" ; then
  dldlib="-ldld"
else
  dldlib=''
fi

## $B%a%C%;!<%8DL?.$N<BAu(J

if test "$machine" = "symmetry" ; then
  cat <<EOM

On a symmetry, you can choose an implementation of message
communication from the following two: one using shared memory and the
other using socket library. The former is much faster than the other,
while the latter allows communication with different hosts.
EOM
  cont=true
  while test "$cont" ; do 
    echo ''
	echo -n "Do you want to use socket implementation[$usesocket]?"
	read ans
	case $ans in
	'')
	  cont=''
	  ;;
	"yes"|"no")
	  usesocket="$ans"
	  cont=''
	  ;;
	esac
  done
  if test $usesocket = "yes" ; then
    mbox="socket"
  else
    mbox="symmetry"
  fi
else
  mbox="socket"
fi

if test "$mbox" = "socket" ; then
    socket_comm="-DSOCKET_COMM"
else
    socket_comm=''
fi

# $B@_Dj5-O?%U%!%$%k(J(config.sh)$B$N:n@.(J

if test -f $config_sh ; then
    mv $config_sh "old${config_sh}"
fi
cat <<EOT >config.sh
#!/bin/sh
# config.sh
# This is an output of the Configure script
top='$top'
machine='$machine'
bindir='$bindir'
execdir='$execdir'
libdir='$libdir'
oldlib='$oldlib'
parsegen='$parsegen'
havedld='$havedld'
usesocket='$usesocket'
mbox='${mbox}'
#
yacc='${yacc}'
plusplus='${plusplus}'
options='$options'
dynamic_link='${dynamic_link}'
debug_options='${debug_options}'
dldlib='${dldlib}'
socket_comm='${socket_comm}'
d_iostream='$d_iostream'
EOT

# Makefile $B$N:n@.(J

echo ''
echo "(cd aumc; . Makefile.sh)"
(cd aumc; . Makefile.sh)
echo "(cd pas; . Makefile.sh)"
(cd pas; . Makefile.sh)
echo "(cd bin; . Makefile.sh)"
(cd bin; . Makefile.sh)

