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

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

PKG=/tmp/package-happy
rm -rf $PKG
mkdir $PKG
cd /tmp
rm -rf happy
tar xzvf $CWD/happy-$VERSION.tar.gz
cd `basename happy-$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 copy --destdir=$PKG
runhaskell Setup.lhs register --gen-script --with-hc-pkg=/usr/bin/ghc-pkg

( cd doc
     autoconf
    ./configure
    make
)

( 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/usr/doc/happy-$VERSION/html
cp -a \
  README ANNOUNCE CHANGES TODO LICENSE \
  $PKG/usr/doc/happy-$VERSION
cp -ar doc/happy $PKG/usr/doc/happy-$VERSION/happy

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

