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

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


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

chown -R root:root .

runhaskell Setup.hs configure --prefix=/usr -p
runhaskell Setup.hs build
runhaskell Setup.hs haddock
runhaskell Setup.hs haddock --hoogle
runhaskell Setup.hs copy --destdir=$PKG
runhaskell Setup.hs register --gen-script

( 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/doc/html-$VERSION/html/html-$VERSION.txt $PKG/var/spool/hoogle/

mkdir -p $PKG/usr/doc/html-$VERSION
cp -a \
  LICENSE \
  $PKG/usr/doc/html-$VERSION

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

