#!/bin/sh
CWD=`pwd`
PKG1=/tmp/package-libwmf
PKG2=/tmp/package-libwmf-docs

VERSION=0.2.8.4
ARCH=${ARCH:-i486}
BUILD=3

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

rm -rf $PKG1 $PKG2
mkdir -p $PKG1 $PKG2
cd /tmp
rm -rf libwmf-$VERSION
tar xjvf $CWD/libwmf-$VERSION.tar.bz2
cd libwmf-$VERSION
chown -R root:root .
find . -perm 777 -exec chmod 755 {} \;
find . -perm 664 -exec chmod 644 {} \;
CFLAGS="$SLKCFLAGS" \
./configure \
  --prefix=/usr \
  --enable-static=no \
  --build=$ARCH-slackware-linux
make -j4 || exit 1
make install DESTDIR=$PKG1
( cd $PKG1
  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 $PKG2/usr/doc
mv $PKG1/usr/share/doc/libwmf $PKG2/usr/doc/libwmf-$VERSION
rmdir $PKG1/usr/share/doc
cp -a AUTHORS BUILDING COPYING CREDITS NEWS README TODO \
  $PKG1/usr/doc/libwmf-$VERSION
mkdir -p $PKG1/install
cat $CWD/slack-desc > $PKG1/install/slack-desc
mkdir -p $PKG2/install
cat $CWD/slack-desc-docs > $PKG2/install/slack-desc

cd $PKG1
makepkg -l y -c n ../libwmf-$VERSION-$ARCH-$BUILD.tgz
cd $PKG2
makepkg -l y -c n ../libwmf-docs-$VERSION-noarch-$BUILD.tgz