#!/bin/sh
CWD=`pwd`
PKG=/tmp/package-abiword

# main source
VERSION=2.2.9
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1}

## libfribidi
#FVER=0.10.5
## enchant
#ENCHVER=1.1.6

rm -rf $PKG
mkdir $PKG

## This is now in 'L'.
#cd /tmp
#rm -rf fribidi-$FVER
#tar xjvf $CWD/fribidi-$FVER.tar.bz2
#cd fribidi-$FVER
#find . -perm 664 -exec chmod 644 {} \;
#chown -R root.root .
#CFLAGS=-O2 \
#./configure --prefix=/usr \
#  --enable-shared=no \
#  --with-pic
#make -j3
#make install
#make install DESTDIR=$PKG
#strip -g $PKG/usr/lib/libfribidi.a
#mkdir -p $PKG/usr/doc/fribidi-$FVER
#cp -a \
#  ANNOUNCE AUTHORS COPYING NEWS README THANKS TODO \
#  $PKG/usr/doc/fribidi-$FVER

#cd /tmp
#rm -rf enchant-$ENCHVER
#tar xjvf $CWD/enchant-$ENCHVER.tar.bz2
#cd enchant-$ENCHVER
#find . -perm 664 -exec chmod 644 {} \;
#chown -R root.root .
#CFLAGS=-O2 \
#./configure --prefix=/usr \
#  --enable-shared=no \
#  --with-pic \
#  --disable-ispell \
#  --disable-myspell \
#  --disable-uspell \
#  --disable-hspell
#make -j3
#make install
#make install DESTDIR=$PKG
#strip -g $PKG/usr/lib/libenchant.a
#gzip $PKG/usr/man/man1/enchant.1
mkdir -p $PKG/usr/doc/enchant-$ENCHVER
#cp -a \
#  AUTHORS COPYING.LIB NEWS README TODO \
#  $PKG/usr/doc/enchant-$ENCHVER
	
cd /tmp
rm -rf abiword-$VERSION
tar xjvf $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
CFLAGS=-O2 CXXFLAGS=-O2 \
./configure \
  --prefix=/usr \
  --disable-debug \
  --disable-gnome \
  --enable-threads \
  $ARCH-slackware-linux
make
make install
make install DESTDIR=$PKG

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

#mkdir -p $PKG/usr/share/gnome/apps/Applications
#cat src/pkg/linux/rpm/data/abiword.desktop > $PKG/usr/share/gnome/apps/Applications/abiword.desktop

cd ../abiword-docs/man
mkdir -p $PKG/usr/man/man1
cat abiword.1 | gzip -9c > $PKG/usr/man/man1/abiword.1.gz
cd ..
mkdir -p $PKG/usr/share/AbiSuite-2.2/AbiWord
#cp -a help $PKG/usr/share/AbiSuite-2.2/AbiWord
cp -a Manual/en/Abiword_Manual.abw $PKG/usr/doc/abiword-$VERSION/docs
cd ../abiword-plugins
./configure \
  --prefix=/usr \
  --disable-debug \
  --disable-gnome \
  $ARCH-slackware-linux
make -j3
make install
make install DESTDIR=$PKG
( 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/*.a
chown -R root:bin $PKG/usr/bin
mkdir -p $PKG/usr/share/applications
zcat $CWD/abiword.desktop.gz > $PKG/usr/share/applications/abiword.desktop
# Since we're not linking with bonobo I assume we don't need this...
rm -rf $PKG/usr/share/bonobo
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

