#!/bin/sh
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-pango
VERSION=1.26.2
ARCH=alpha
BUILD=2
TARGET=$ARCH-alphaslack-linux

rm -rf $PKG
mkdir -p $PKG/usr
( cd $TMP
rm -rf pango-$VERSION
tar xjf $CWD/pango-$VERSION.tar.bz2
cd pango-$VERSION

zcat $CWD/pango.etc.host.location.diff.gz | patch -p1 --verbose || exit 1

chown -R root.root .
find . -perm 664 -exec chmod 644 {} \;

sed -i -e 's#linux|linux-gnu|#linux|linux|#' config.sub

./configure \
 --prefix=/usr \
 --mandir=/usr/man \
 --infodir=/usr/info \
 --docdir=/usr/doc/pango-$VERSION \
 --sysconfdir=/etc \
 --build=$TARGET \
 --host=$TARGET \
 --target=$TARGET

make || exit 1

# Check the host value that is passed to the compile to the one in this script:
host="$ARCH-alphaslack-linux"
compile_host=$(grep 'host_triplet =' pango/Makefile | sed "s/.* = //")
if [ "x$compile_host" != "x$host" ]; then
  echo "Host mismatch: compile='$compile_host', SlackBuild='$host'" && exit 1
fi

make install DESTDIR=$PKG || exit 1

# Install wrapper for pango-querymodules:
cp $CWD/update-pango-querymodules $PKG/usr/bin/update-pango-querymodules
chmod 0755 $PKG/usr/bin/update-pango-querymodules

# Do not remove pangox.aliases
rm -f $PKG/etc/pango/pango.modules
mkdir -p $PKG/etc/pango/$host
touch $PKG/etc/pango/$host/pango.modules

( cd $PKG
 find . -type f | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
 find . -type f | xargs file | grep "shared" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)

gzip -9 $PKG/usr/man/man?/*.?
mkdir -p $PKG/usr/doc/pango-$VERSION
cp -a AUTHORS COPYING ChangeLog NEWS README $PKG/usr/doc/pango-$VERSION

mkdir -p $PKG/install
cat <<EOF > $PKG/install/doinst.sh
# Updating the pango.modules file:
chroot . /sbin/ldconfig 2> /dev/null
if [ -x /usr/bin/update-pango-querymodules ]; then
  /usr/bin/update-pango-querymodules
fi
EOF

cat $CWD/slack-desc > $PKG/install/slack-desc
cd $TMP/package-pango
makepkg -l y -c n $TMP/pango-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/pango.build.log
