#!/bin/sh
# Build hsql-mysql for Slackware (by arossato@istitutocolli.org)
CWD=`pwd` 

VERSION=1.7
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1ar}


PKG=/tmp/package-hsql-mysql
rm -rf $PKG
mkdir $PKG
cd /tmp
rm -rf hsql-mysql
tar xzvf $CWD/hsql-mysql-$VERSION.tar.gz
cd `basename hsql-mysql-$VERSION i`

chown -R root:root .

runhaskell Setup.lhs configure --ghc --prefix=/usr -p
runhaskell Setup.lhs build
runhaskell Setup.lhs haddock
runhaskell Setup.lhs haddock --hoogle
runhaskell Setup.lhs copy --destdir=$PKG
runhaskell Setup.lhs register --gen-script --with-hc-pkg=/usr/bin/ghc-pkg

( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
gzip -9 $PKG/usr/man/man?/*

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh
cat $CWD/slack-required > $PKG/install/slack-required
cat register.sh  > $PKG/install/register.sh

mkdir -p $PKG/var/spool/hoogle/
cp $PKG/usr/share/hsql-mysql-$VERSION/doc/html/hsql-mysql-$VERSION.txt $PKG/var/spool/hoogle/

mkdir -p $PKG/usr/doc/hsql-mysql-$VERSION
cp -a \
  LICENSE \
  $PKG/usr/doc/hsql-mysql-$VERSION
ln -s /usr/share/hsql-mysql-$VERSION/doc/html $PKG/usr/doc/hsql-mysql-$VERSION/html 

cd $PKG
makepkg -l y -c n ../hsql-mysql-$VERSION-$ARCH-$BUILD.tgz

