#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-tcsh

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
if [ ! -d $PKG ]; then
  mkdir -p $PKG # place for the package to be built
fi

# Explode the package framework:
cd $PKG
explodepkg $CWD/_tcsh.tar.gz

echo "+===========+"
echo "| tcsh-6.10 |"
echo "+===========+"
cd $TMP
tar xzvf $CWD/tcsh-6.10.tar.gz
cd tcsh-6.10.00
mkdir -p $PKG/usr/doc/tcsh-6.10
cp -a FAQ Fixes NewThings Ported README README.imake WishList Y2K \
  $PKG/usr/doc/tcsh-6.10
chmod 644 $PKG/usr/doc/tcsh-6.10/*
chown root.root $PKG/usr/doc/tcsh-6.10/*
CFLAGS=-O2 ./configure --prefix=  i386-slackware-linux
make
cat tcsh > $PKG/bin/tcsh
cat tcsh.man | gzip -9c > $PKG/usr/man/man1/tcsh.1.gz
echo '.so man1/tcsh.1' | gzip -9c > $PKG/usr/man/man1/csh.1.gz

# Build the package:
cd $PKG
tar czvf $TMP/tcsh.tgz .

# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP/tcsh-6.10.00
  rm -rf $PKG
fi
