#!/bin/sh
# Copyright 2001 BSDi, Inc. Concord, CA, USA
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

VERSION=5.32.1

CWD=$(pwd)
TMP=/tmp/build-wget

rm -rf $TMP
mkdir $TMP
cd $TMP

( cd /tmp
  tar -xvzf $CWD/tcl8.3.3.tar.gz
  cd tcl8.3.3/unix
  ./configure --prefix=/usr
)

tar -xvzf $CWD/expect-$VERSION.tar.gz
cp -a expect-$VERSION expect.shared/

#
# build the static version
# 
cd $TMP/expect-$VERSION/
./configure --prefix=/usr \
            --with-tclconfig=/usr/lib \
            --with-tclinclude=/tmp/tcl8.3.3/generic
 make

#
# build the shared version
#
cd $TMP/expect.shared/
./configure --prefix=/usr \
            --with-tclconfig=/usr/lib \
            --with-tclinclude=/tmp/tcl8.3.3/generic \
            --enable-shared
make
}

#
# install the static version
#
cd $TMP/expect-$VERSION/
mkdir -p /usr/doc/expect-$VERSION
cp -a FAQ HISTORY INSTALL NEWS README example \
      /usr/doc/expect-$VERSION
make install

#
# install the shared version
#
cd $TMP/expect.shared/
make install

( cd /usr/lib ; rm -rf libexpect.a )
( cd /usr/lib ; ln -sf libexpect5.32.a libexpect.a )
( cd /usr/lib ; rm -rf libexpect.so )
( cd /usr/lib ; ln -sf libexpect5.32.so libexpect.so )

rm -r /tmp/tcl8.3.3

chown -R root.root /usr/doc/expect-${VERSION}
find /usr/doc/expect-${VERSION} -type f -exec chmod 644 {} \;

( cd /usr/doc/expect-$VERSION/example

  chmod 754 autoexpect beer.exp chess.exp cryptdir decryptdir dislocate \
            dvorak ftp-inband ftp-rfc gethostbyaddr kibitz lpunlock     \
            mkpasswd passmass rftp robohunt rogue.exp term_expect       \
            tknewsbiff tkpasswd tkterm virterm weather xkibitz xpstat
 
  chmod 755 archie autopasswd irsh rlogin-cwd telnet-cwd timed-read \
            timed-run unbuffer vrfy
)
