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

VERSION=6.11
ARCH=i386
BUILD=1

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-$VERSION |"
echo "+===========+"
cd $TMP
tar xzvf $CWD/tcsh-$VERSION.tar.gz
cd tcsh-$VERSION.00
mkdir -p $PKG/usr/doc/tcsh-$VERSION
cp -a FAQ Fixes NewThings Ported README README.imake WishList Y2K \
  $PKG/usr/doc/tcsh-$VERSION
chmod 644 $PKG/usr/doc/tcsh-$VERSION/*
chown root.root $PKG/usr/doc/tcsh-$VERSION/*
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
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Build the package:
cd $PKG
echo "n" | makepkg $TMP/tcsh-$VERSION-$ARCH-$BUILD.tgz

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