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

VERSION=1.3.3
ARCH=i386
BUILD=2

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

cd $PKG
explodepkg $CWD/_gzip.tar.gz

echo "+=============+"
echo "| gzip-$VERSION |"
echo "+=============+"
cd $TMP
tar xzvf $CWD/gzip-$VERSION.tar.gz
cd gzip-$VERSION
chown -R root.root .
CFLAGS="-O2 -march=i386 -mcpu=i686" ./configure --prefix=/usr
make
strip gzip 
cat gzip > $PKG/bin/gzip
cat gzexe > $PKG/usr/bin/gzexe
cat zdiff > $PKG/usr/bin/zdiff
cat zforce > $PKG/usr/bin/zforce
cat zgrep > $PKG/usr/bin/zgrep
cat zless > $PKG/usr/bin/zless
cat zmore > $PKG/usr/bin/zmore
cat znew > $PKG/usr/bin/znew
for page in gunzip.1 gzexe.1 gzip.1 zcat.1 zcmp.1 zdiff.1 zforce.1 zgrep.1 zless.1 zmore.1 znew.1 ; do
  cat $page | gzip -9c > $PKG/usr/man/man1/$page.gz
done
mkdir -p $PKG/usr/info
cat gzip.info | gzip -9c > $PKG/usr/info/gzip.info.gz
mkdir -p $PKG/usr/doc/gzip-$VERSION
cp -a \
  README AUTHORS COPYING INSTALL NEWS README-alpha THANKS TODO \
  $PKG/usr/doc/gzip-$VERSION
chmod 644 $PKG/usr/doc/gzip-$VERSION/*
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Build the package:
cd $PKG
makepkg -l y -c n $TMP/gzip-$VERSION-$ARCH-$BUILD.tgz

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