#!/bin/sh
# Heavily based on the Slackware 12.0 SlackBuild
# http://www.public.iastate.edu/~chris129/code/ejourn/
# http://www.slacky.it

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-ejourn
rm -rf $PKG
mkdir -p $PKG

NAME=ejourn
VERSION=0.4.2
TARGET=i486
ARCH=${ARCH:-i486}
BUILD=2bj

cd $TMP
rm -rf eJourn
tar xjvf $CWD/$NAME-$VERSION.tar.bz2
cd eJourn
chown -R root:root .
sed -i "s|-O2|-O2 -march=i486 -mtune=i686|g" Makefile
./configure --prefix=/usr \
            --program-prefix="" \
	    --program-suffix="" \
	    --build=$TARGET-slackware-linux
make
make install DESTDIR=$PKG/usr
( cd $PKG/usr/lib ; rm -rf libejourn.so.1 
ln -sf ../lib/libejourn.so libejourn.so.1 )
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a \
  AUTHORS CHANGELOG DEVELOPERS README* INSTALL TODO \
  $PKG/usr/doc/$NAME-$VERSION
  
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

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cp -a $CWD/{*.SlackBuild,slack-desc} $PKG/usr/doc/$NAME-$VERSION

requiredbuilder -y -v -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP
fi
