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

VERSION=1.875
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

echo "+============+"
echo "| bison-$VERSION |"
echo "+============+"
cd $TMP
tar xjvf $CWD/bison-$VERSION.tar.bz2
cd bison-$VERSION
chown -R root.root .
mkdir -p $PKG/usr/doc/bison-$VERSION
cp -a ABOUT-NLS AUTHORS COPYING INSTALL NEWS README REFERENCES THANKS doc/FAQ $PKG/usr/doc/bison-$VERSION
chmod 644 $PKG/usr/doc/bison-$VERSION/*
CFLAGS="-O2 -march=i386 -mcpu=i686" LDFLAGS=-s ./configure --prefix=/usr
make
make install DESTDIR=$PKG
strip $PKG/usr/bin/bison
chown -R root.bin $PKG/usr/bin
rm -f $PKG/usr/info/dir
gzip -9 $PKG/usr/info/*
gzip -9 $PKG/usr/man/man1/bison.1
mkdir -p $PKG/install
zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh
cat $CWD/slack-desc > $PKG/install/slack-desc

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

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