#!/bin/sh
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-kdebindings

# Set the config option variables if they are not already set:
if [ -r ../KDE.options.s390x ]; then
 . ../KDE.options.s390x
fi

# The global options may be overridden here (if needed):
if [ -r ./local.options ]; then
 . ./local.options
fi

rm -rf $PKG
mkdir -p $PKG/opt/kde

# Avoid a version number in .la files:
if [ -d /usr/lib/qt ]; then
 QTDIR=/usr/lib/qt
fi
cd $TMP
echo "Building kdebindings-$VERSION.tar.bz2..."
tar xjvf $CWD/kdebindings-$VERSION.tar.bz2
cd kdebindings-$VERSION
cat $CWD/python.makefile.in.diff | patch -p1 --backup --suffix=.orig || exit 1

chown -R root:root .
RUBYLIB=/usr/lib64/ruby/1.8/s390x-linux/ \
CFLAGS=$CPUOPT \
CXXFLAGS=$CPUOPT \
/configure \
 --prefix=/opt/kde \
 --enable-libsuffix=64 \
 --with-qt-libraries=/usr/lib/qt/lib64 \
 --with-xinerama \
 --disable-debug \
 --program-prefix="" \
 --program-suffix="" \
 $TARGET-slackware-linux
# This group is _really_ special.  They need two symlinks instead of one.  :(
( cd /usr/lib/qt
#   ln -sf lib64 lib
)
( cd /opt/kde
#   ln -sf lib64 lib
)
make || exit 1
#make $NUMJOBS || exit 1
make install DESTDIR=$PKG
rm -f /usr/lib/qt/lib /opt/kde/lib
mkdir -p $PKG/usr/doc/kdebindings-$VERSION
cp -a AUTHORS COPYING COPYING.LIB INSTALL NEWS README $PKG/usr/doc/kdebindings-$VERSION
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

( 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
)
if [ -d $PKG/opt/kde/man ]; then
 gzip -9 $PKG/opt/kde/man/man?/*
fi
if [ -d $PKG/usr/share/man ]; then
 mv $PKG/usr/share/man $PKG/usr
 rmdir $PKG/usr/share
 gzip -9 $PKG/usr/man/man?/*
fi

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