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

VERSION=0.7
ARCH=${ARCH:-i386}
BUILD=${BUILD:-1ar}
GHCVERSION=6.4.2

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

chown -R root:root .

runhaskell Setup.hs configure --prefix=/usr
runhaskell Setup.hs build
runhaskell Setup.hs haddock
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

# bad hack: see fps.cabal
mkdir -p $PKG/cbits
cp -ar cbits/fpstring.h $PKG/cbits/

mkdir -p $PKG/usr/doc/fps-$VERSION
cp -a \
  LICENSE README TODO \
  $PKG/usr/doc/fps-$VERSION
cp -ar tests $PKG/usr/doc/fps-$VERSION
cp -ar dist/doc/html $PKG/usr/doc/fps-$VERSION

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