#!/bin/sh
PKG=/tmp/package-libxslt
rm -rf $PKG
mkdir -p $PKG

CWD=`pwd` 
VERSION=1.1.24
ARCH=${ARCH:-i486}
BUILD=1

if [ "$ARCH" = "i386" ]; then
  SLKCFLAGS="-O2 -march=i386 -mcpu=i686"
elif [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
elif [ "$ARCH" = "s390" ]; then
  SLKCFLAGS="-O2"
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2"
fi

cd /tmp
rm -rf libxslt-$VERSION
tar xjvf $CWD/libxslt-$VERSION.tar.bz2 || exit 1
cd libxslt-$VERSION
chown -R root:root .
CFLAGS="$SLKCFLAGS" \
./configure \
  --prefix=/usr \
  --mandir=/usr/man \
  --build=$ARCH-slackware-linux 
make -j4 || exit 1
make install DESTDIR=$PKG
mv $PKG/usr/share/doc $PKG/usr
mv $PKG/usr/doc/libxslt-python-$VERSION $PKG/usr/doc/libxslt-$VERSION
cp -a \
  AUTHORS COPYING* Copyright FEATURES INSTALL IPR NEWS README TODO libxslt.spec \
  $PKG/usr/doc/libxslt-$VERSION
find $PKG/usr/doc/libxslt-$VERSION -type f | xargs chmod 644
( 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
#echo
#echo "Only the python bindings in /usr/lib/python__/site-packages/ should"
#echo "be kept... toss the other stuff"
#echo

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