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

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf abiword-$VERSION
tar xjf $CWD/abiword-$VERSION.tar.bz2
cd abiword-$VERSION
chown -R root.root .
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
cd abi
./configure \
 --prefix=/usr \
 --disable-gnome \
 --enable-threads \
 $TARGET
make || exit
make install DESTDIR=$PKG || exit
mkdir -p $PKG/usr/doc/abiword-$VERSION/docs
cp -a BUILD.TXT BiDiReadme.txt COPYING COPYRIGHT.TXT CREDITS.TXT README.TXT $PKG/usr/doc/abiword-$VERSION
cp -a docs/*.abw $PKG/usr/doc/abiword-$VERSION/docs
cd ../abiword-docs/man
# 8?
mkdir -p $PKG/usr/man/man1
cat abiword.1 | gzip -9c > $PKG/usr/man/man1/abiword.1.gz
cd ..
cp -a Manual/en/Abiword_Manual.abw $PKG/usr/doc/abiword-$VERSION/docs
cd ../abiword-plugins
./configure \
 --prefix=/usr \
 --without-ots \
 --without-gda \
 --without-aiksaurus \
 --without-psion \
 --with-magick \
 --disable-gnome \
 --enable-threads \
 $TARGET
rm -rf libtool ; ln -sf /usr/bin/libtool libtool
make || exit
make install DESTDIR=$PKG || exit
( 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
)
strip -g $PKG/usr/lib/AbiWord-2.2/plugins/*.a
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n $TMP/abiword-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/abiword.build.log
