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

VERSION=1.35
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/_bison.tar.gz

echo "+============+"
echo "| bison-$VERSION |"
echo "+============+"
cd $TMP
tar xjvf $CWD/bison-$VERSION.tar.bz2
cd bison-$VERSION
mkdir -p $PKG/usr/doc/bison-$VERSION
cp -a ABOUT-NLS AUTHORS COPYING ChangeLog INSTALL NEWS OChangeLog README REFERENCES THANKS doc/FAQ $PKG/usr/doc/bison-$VERSION
chmod 644 $PKG/usr/doc/bison-$VERSION/*
chown root.root $PKG/usr/doc/bison-$VERSION/*
CFLAGS=-O2 LDFLAGS=-s ./configure --prefix=/usr
make
cd src
cat bison.simple > $PKG/usr/share/bison/bison.simple
cat bison.hairy > $PKG/usr/share/bison/bison.hairy
cat bison > $PKG/usr/bin/bison
cd ../doc
mkdir -p $PKG/usr/info
for file in bison.info* ; do
 cat $file | gzip -9c > $PKG/usr/info/$file.gz
done
cat bison.1 | gzip -9c > $PKG/usr/man/man1/bison.1.gz
cd ../po
for file in *.gmo ; do
  mkdir -p $PKG/usr/share/locale/`basename $file .gmo`/LC_MESSAGES
  cat $file > $PKG/usr/share/locale/`basename $file .gmo`/LC_MESSAGES/bison.mo
done
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

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

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