#
# $Revision: 3.12 $$Date: 1996/03/03 10:09:47 $
#
echo " "
echo "This Configure script was written by Fred Baumgarten <dc6iq@insu1.etec.uni-"
echo "karlsruhe.de> to serve the 'Ping-Pong' conversd program. If you have problems"
echo "using the script, feel free to fix it and send me patches since I wrote it"
echo "from scratch and did not test all possibilities :-)"
echo " "
echo "It must be given to bash(1), ksh(1) or zsh(1), other shells like csh won't do"
echo "the job ! Before starting the configuration, let's see if this is one of these..."
echo " "
set >/tmp/Configure.01
grep BASH /tmp/Configure.01 >/dev/null && echo "Yes it _really_ is a bash, fine for you :-)"
grep "SHELL=" /tmp/Configure.01 | grep "ksh" >/dev/null && export BASH=$SHELL
grep "SHELL=" /tmp/Configure.01 | grep "ksh" >/dev/null && set >/tmp/Configure.01 && \
 echo "aaah, ksh is up and running..."
grep "VERSION=zsh" /tmp/Configure.01 >/dev/null && export BASH=$SHELL
grep "VERSION=zsh" /tmp/Configure.01 >/dev/null && set >/tmp/Configure.01 && \
 echo "aaah, zsh is up and running..."
grep BASH /tmp/Configure.01 >/dev/null || \
 echo "no bash, ksh or zsh, go for it or copy Makefile.in to Makefile and edit it by Hand !" 
echo " "
grep BASH /tmp/Configure.01 >/dev/null || exit -1
#
rm /tmp/Configure.01
NETPATH=
BA=
#
echo "first, let's have a look at your make utility..."
make -v 2>/dev/null | head -1 | grep GNU >/dev/null 2>&1 && \
 echo "Yeah, no problems with the standard Makefile expected !"
make -v 2>/dev/null | head -1 | grep GNU >/dev/null 2>&1 || \
 (echo "Oops - no GNU make ! Either go for it or comment out the ifeq...endif lines"; \
  echo "in Makefile. Dependencies will take no effect then, but everthing will work."; \
  echo "Conform this statement by pressing ENTER"; read ans)
echo " "
#
echo "Now let's see which compiler you are using..."
if [ -z "`type gcc 2>/dev/null|grep -v not\ found`" ]; then
 echo "poor boy, there's no gnu cc in your path, let's see if there is a traditional"
 echo "traditional c compiler..."
 CC=cc
 CDEF0="-O -I\$(TCPLIB_DIR)"
 if [ -z "`type cc 2>/dev/null|grep -v not\ found`" ]; then
  echo "hey - there's also no cc in your path, how shall a c source be compiled without"
  echo "c compiler ? giving up :-("
  echo " "
  CC=none
  exit -2
 fi
 echo "Ok, you are running a traditional cc - let's look for cpp definitions..."
 rm -f getdefs
 cc -o getdefs -O getdefs.c 2>/dev/null 
 if [ ! -x getdefs ]; then
  echo "oops, your cc is broken ! giving up :-("
  echo " "
  exit -2
 fi
else
 echo "Ok, you are running gcc - let's look up the cpp definitions..."
 CC=gcc
 CDEF0="-Wall -pedantic -O2 -I\$(TCPLIB_DIR)"
 LDEF1="-s"
 rm -f getdefs
 gcc -o getdefs -O getdefs.c 2>/dev/null 
 if [ ! -x getdefs ]; then
  echo "hmm, your gcc is broken !"
  rm -f getdefs
  cc -o getdefs -O getdefs.c 2>/dev/null 
  if [ ! -x getdefs ]; then
   CC=cc
   CDEF0="-O -I\$(TCPLIB_DIR)"
   echo "oops, your cc is also broken ! giving up :-("
   echo " "
   exit -2
  fi
 fi
fi
#
PP="`./getdefs`"
echo " "
echo "Your preprocessor defines the following:"
echo "$PP"
echo " "
if [ ! -z "`echo $PP | grep linux`" ]; then
 echo "fine you are running Linux - should work without problems."
 CDEF1="-DREADLINE -I."
 RL="readline/libreadline.a"
 CDEF2="-DPOSIX"
 PSEXT="ax"
elif [ ! -z "`echo $PP | grep mips`" ]; then
 echo "Fine, you are running a DEC mips machine, don't think that it"
 echo "_really_ uses POSIX standards :-)"
 CDEF1="-DREADLINE -I."
 RL="readline/libreadline.a"
 PSEXT="ax"
elif [ ! -z "`echo $PP | grep sun`" ]; then
 echo "You are running a sun, no POSIX standards."
 CDEF1="-DREADLINE -I."
 RL="readline/libreadline.a"
 PSEXT="ax"
elif [ ! -z "`echo $PP | grep _AIX`" ]; then
 echo "you are running AIX, forget about the READLINE and POSIX"
 echo "stuff :-("
 PSEXT="-ef"
elif [ ! -z "`echo $PP | grep hpux`" ]; then
 echo "You are running a High prices machine, no POSIX and READLIN standards..."
 PSEXT="-ef"
 CDEF1="-D_INCLUDE_HPUX_SOURCE"
elif [ ! -z "`echo $PP | grep rons_machine_type`" ]; then
 echo "you are running BSD on a sun, forget about the READLINE and POSIX"
 echo "stuff :-("
 PSEXT="ax"
fi
echo " "
#
echo "Now let's check, if you may use the LOGGING feature. I should find"
echo "the libwrap.a for this possibility..."
if [ -r /usr/lib/libwrap.a ]; then
 echo "Yes, the libwrap.a is available in /usr/lib."
 CDEF3="-DLOGGING"
 LIBWRAP="-lwrap"
elif [ -r /usr/local/lib/libwrap.a ]; then
 echo "Yes, the libwrap.a is available in /usr/local/lib."
 CDEF3="-DLOGGING"
 LDEF0="-L/usr/local/lib"
 LIBWRAP="-lwrap"
else
 echo "no, I was unable to find the tcp wrapper library. Would have been"
 echo "nice to have it, but it really doesn't matter at all."
fi
echo " "
#
echo "Maybe you like to see the speaker library in use. Then a file called"
echo "libspeak.a should be available..."
if [ -r /usr/lib/libspeak.a ]; then
 echo "Yes, the libspeak.a is available in /usr/lib."
 CDEF4="-DPCSP"
 LIBSPEAK="-lspeak"
elif [ -r /usr/local/lib/libspeak.a ]; then
 echo "Yes, the libspeak.a is available in /usr/local/lib."
 CDEF4="-DPCSP"
 LDEF0="-L/usr/local/lib"
 LIBSPEAK="-lspeak"
else
 echo "no, I was unable to find the pc speaker library. Don't worry about it"
 echo "since it is useful to selfbuilt PC hardware only."
fi
echo " "
#
echo "...now I am going to look if you are running WAMPES."
if [ -f /tcp/lib/libutil.a ]; then
 echo "big deal ! You are running a recent version of WAMPES in /tcp/net. This is the"
 echo "same configuration that I used to have - hopefully no problems will occur..."
 NETPATH=/tcp/lib
 BA=libutil.a
elif [ -f /tcp/lib/buildsaddr.c ]; then
 echo "big deal ! You are running a recent version of WAMPES in /tcp/net. You haven't"
 echo "compiled the library yet - but thats no problem :-)"
 NETPATH=/tcp/lib
 BA=libutil.a
elif [ -d /tcp ]; then
 echo "ok, you have a /tcp directory on your machine, let's check out if there is an"
 echo "older WAMPES version."
 if [ ! -f /tcp/net ]; then
  echo "hmmm - there is no executable :-("
 else
  WAMPES_ID=`strings /tcp/net | grep WAMPES | grep -v @`
  if [ -z "$WAMPES_ID" ]; then
   echo "hmmm, you are not holding a WAMPES in /tcp :-("
  else
   echo "I found $WAMPES_ID in /tcp/net - but libutil.a is not present."
   echo "Maybe its an older version which uses /tcp/src/buildsaddr.c"
   if [ -f /tcp/src/buildsaddr.c ]; then
    echo "yep, you keep an old version of wampes."
    NETPATH=/tcp/src
    BA=buildsaddr.o
   else
    echo "Hmmm - I even cannot find an old source tree in /tcp/src. Maybe there is more"
    echo "success in scanning all disks."
   fi
  fi
 fi
else
 echo "hmmm, there's no /tcp directory. Therefore no default WAMPES installation is"
 echo "done on your machine."
fi
#
if [ -z "$BA" ]; then
 echo " "
 echo "Now i'll look up _all_ directories for the net program, the bigger your disks,"
 echo "the longer it takes :-)"
 files=`find / -name net -print 2>/dev/null`
 if [ -z "$files" ]; then
  echo "Oh there is no \"net\" program on the entire disk available for you so I must"
  echo "set up the library stuff for socket communications."
 else
  echo "I found a file called \"net\" in the following places:"
  for i in $files; do
   echo $i
  done
  n=0
  for i in $files; do
    echo " "
   if [ -d $i ]; then
    echo "$i is a directory - no WAMPES here..."
   else 
    if [ -x $i ]; then
     echo "$i is an executable - let's check it out... "
     WAMPES_ID=`strings $i | grep WAMPES | grep -v @`
     if [ -z $WAMPES_ID ]; then
      echo "sad, but that was no WAMPES :-("
     else
      echo "I found $WAMPES_ID, let's see if it uses libutil.a"
      dir_list="$dir_list `dirname $i`"
      n=`expr $n + 1`
     fi
    else
     echo "$i is no executable - no WAMPES here..."
    fi
   fi
  done
 fi
 if [ ! -z "$dir_list" ]; then
  if [ n = 1 ]; then
   NETPATH=$dir_list
   echo " "
   echo "Ok, I found the only WAMPES on your disk. Let's see if it uses libutil.a"
  elif [ n = 0 ]; then
   echo " "
   echo "ok, I found no WAMPES on your disk."
   NETPATH=.
   BA=ba_stub.o
  else
   echo " "
   echo "I found $n WAMPES net programs on your file system... Now let's see, which"
   echo "is the right one :-)"
  fi
  m=0
  for i in $dir_list; do
   echo " "
   echo "checking $i..."
   if [ -d $i/lib ]; then
    m=`expr $m + 1`
    echo -n "a lib directory exists, "
    if [ -f $i/lib/libutil.a ]; then
     echo "and the belonging libutil.a also exists !"
     NETPATH=$i/lib
     BA=libutil.a
    else
     echo "but i did not find the library :-("
     if [ -f $i/lib/buildsaddr.c ]; then
      echo "Aaaah - just just have not finished a compilation in there - the"
      echo "directory itself seems to be ok for me. - I take it."
      NETPATH=$i/lib
      BA=libutil.a
     else
      if [ -z "$BA" ]; then 
       if [ -f $i/src/buildsaddr.c ]; then
        echo "surprise ! I found out you keep an old version of buildsaddr.c"
        echo "let's take it until I find something better..."
        NETPATH=$i/src
        BA=buildsaddr.o
       else
        echo "and no sources are in there. I hope I can find out another one."
       fi
      fi
      if [ n = m ]; then
       if [ -z "$BA" ]; then
        echo "I am very sad, but there is no proper WAMPES on your machine."
        echo "I will set up conversd for kernel TCP/IP only."
        NETPATH=.
        BA=ba_stub.o
       fi
      fi
     fi
    fi
   fi
  done
 fi
fi
# 
if [ -z "$BA" ]; then
 echo " "
 echo "Hmm, theres no WAMPES around here, I'll use the stub file to deal"
 echo "with the internet sockets of this machine..."
 BA=ba_stub.o
 NETPATH=.
fi
#
DATA_DIR="/tcp"
CONF_DIR="/tcp"
BIN_DIR="/tcp"
UBIN_DIR="/usr/bin"
echo " "
echo "Now let's have a look at your directory structure..."
echo " "
if [ -d /usr/local/etc ]; then 
 echo "I found /usr/local/etc - and will use this directory for the configuration files"
 CONF_DIR="/usr/local/etc"
else
 echo "No directory /usr/local/etc - will use /tcp for the configuration files"
fi
if [ -d /var/local/spool ]; then 
 echo "I found /var/local/spool - and will use this a convers directory for the"
 echo "log files and the sockets."
 DATA_DIR="/var/local/spool/convers"
else
 echo "No directory /var/local/spool - will use /tcp for the log files"
fi
if [ -d /usr/local/sbin ]; then 
 echo "I found /usr/local/sbin - and will place daemons in this directory"
 BIN_DIR="/usr/local/sbin"
else
 echo "No directory /usr/local/sbin - will place daemons in /tcp"
fi
if [ -d /usr/local/bin ]; then 
 echo "I found /usr/local/bin - and will place clients in this directory"
 UBIN_DIR="/usr/local/bin"
else
 echo "No directory /usr/local/bin - will place clients in /usr/bin"
fi
if [ -d /usr/local/man ]; then 
 echo "I found /usr/local/man - and will place man pages in this directory"
 MAN_DIR="/usr/local/man"
else
 echo "No directory /usr/local/man - will place man pages in /usr/man"
fi
#
echo " "
echo "I decided to patch Makefile as follows:"
echo "DATA_DIR= $DATA_DIR"
echo "CONF_DIR= $CONF_DIR"
echo "BIN_DIR= $BIN_DIR"
echo "UBIN_DIR= $UBIN_DIR"
echo "MAN_DIR= $MAN_DIR"
echo "TCPLIB_DIR= $NETPATH"
echo "BA= $BA"
echo "CC= $CC"
echo "CDEF0= $CDEF0"
echo "CDEF1= $CDEF1"
echo "CDEF2= $CDEF2"
echo "CDEF3= $CDEF3"
echo "CDEF4= $CDEF4"
echo "LDEF0= $LDEF0"
echo "LDEF1= $LDEF1"
echo "LIBWRAP= $LIBWRAP"
echo "LIBSPEAK= $LIBSPEAK"
echo "RL= $RL"
echo "PSEXT= $PSEXT"
#
head -6 Makefile.in >Makefile.new
echo "DATA_DIR= $DATA_DIR" >>Makefile.new
echo "CONF_DIR= $CONF_DIR" >>Makefile.new
echo "BIN_DIR= $BIN_DIR" >>Makefile.new
echo "UBIN_DIR= $UBIN_DIR" >>Makefile.new
echo "MAN_DIR= $MAN_DIR" >>Makefile.new
echo "TCPLIB_DIR= $NETPATH" >>Makefile.new
echo "BA= $BA" >>Makefile.new
echo "CC= $CC" >>Makefile.new
echo "CDEF0= $CDEF0" >>Makefile.new
echo "CDEF1= $CDEF1" >>Makefile.new
echo "CDEF2= $CDEF2" >>Makefile.new
echo "CDEF3= $CDEF3" >>Makefile.new
echo "CDEF4= $CDEF4" >>Makefile.new
echo "LDEF0= $LDEF0" >>Makefile.new
echo "LDEF1= $LDEF1" >>Makefile.new
echo "LIBWRAP= $LIBWRAP" >>Makefile.new
echo "LIBSPEAK= $LIBSPEAK" >>Makefile.new
echo "RL= $RL" >>Makefile.new
echo "PSEXT= $PSEXT" >>Makefile.new
tail +26 Makefile.in >>Makefile.new
mv Makefile.new Makefile
#
echo " "
echo "Your Makefile should be available at this point. You can do a \"make\" now."
echo " "
