#!/bin/sh

[ -z $PREPKG ] && exit 1

PACKAGE=xsri
VERSION=2.1.0
FILES=$(cd $(dirname $0) ; pwd)

mkdir -p \
  $PREPKG/{install,usr/doc/$PACKAGE-$VERSION}/

tar xf $FILES/$PACKAGE-$VERSION.tar.gz || exit 1

chmod -R \
  g-w .
chown -R \
  root:root .
cd $PACKAGE-$VERSION/

# funky prepwork from gentoo
# http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/x11-misc/xsri/xsri-2.1.0-r1.ebuild
sed -i '/-DG.*_DISABLE_DEPRECATED/d' Makefile.am
sed -i 's/PKG_CHECK_MODULES(GTK,/& x11 /' configure.in
autoreconf &> autoreconf.output || exit 1

CFLAGS="-O2 -march=i486 -mtune=i686" \
  ./configure \
  --prefix=/usr \
  --build=i486-slackware-linux &> configure.output || exit 1
make $MAKEJOBS &> make.output || exit 1
make DESTDIR=$PREPKG install &> make_install.output || exit 1

cp -p \
  AUTHORS COPYING ChangeLog README \
  $PREPKG/usr/doc/$PACKAGE-$VERSION/

cp \
  $FILES/slack-desc \
  $PREPKG/install/

find $PREPKG -exec file {} \; \
  | awk -F : '/ ELF / {print $1}' \
  | xargs strip -p --strip-unneeded
