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

# main source
VERSION=2.0.12
# libfribidi
FVER=0.10.4
# libwpd
WVER=0.7.2
ARCH=${ARCH:-sparc}
BUILD=${BUILD:-1}
# TUPLE=$ARCH-slackware-linux
TUPLE=$ARCH-splack-linux

rm -rf $PKG
mkdir $PKG
cd /tmp
rm -rf fribidi-$FVER
tar xjf $CWD/fribidi-$FVER.tar.bz2
cd fribidi-$FVER
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 libwpd-$WVER
tar xjf $CWD/libwpd-$WVER.tar.bz2
cd libwpd-$WVER
chown -R root.root .
find . -perm 664 -exec chmod 644 {} \;
CFLAGS=-O2 \
./configure --prefix=/usr \
  --enable-shared=no \
  --enable-static \
  --with-pic
make -j3
make install
make install DESTDIR=$PKG
strip -g $PKG/usr/lib/libwpd-1.a
mkdir -p $PKG/usr/doc/libwpd-$WVER
cp -a \
  CHANGES COPYING INSTALL TODO \
  $PKG/usr/doc/libwpd-$WVER

cd /tmp
rm -rf abiword-$VERSION
tar xjvf $CWD/abiword-$VERSION.tar.bz2
cd abiword-$VERSION

## Use the standard ispell format so that we don't have to ship another
## redundant dictionary.  Really, why can't abi use ispell or aspell
## directly if it is available?  Seems inefficient.
#zcat $CWD/abiword.std.ispell.fileformat.diff.gz | patch -p1 --verbose
# COMMENTED OUT AS "PROBABLY NOT A GOOD IDEA TO MESS WITH" ;-)
zcat $CWD/patches-splack/abiword-2.0.12-msolehack-1.diff.gz | \
  patch -p0 --verbose --backup --suffix=.orig -E
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 {} \;
# This needs to be built first...
cd wv
./configure \
  --prefix=/usr \
  --disable-shared \
  $TUPLE
make -j3
strip -g *.a
cd ../abi
CFLAGS=-O2 CXXFLAGS=-O2 \
./configure \
  --prefix=/usr \
  --disable-debug \
  --disable-gnome \
  $TUPLE
make -j3
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
# 8?
mkdir -p $PKG/usr/man/man8
cat abiword.8 | gzip -9c > $PKG/usr/man/man8/abiword.8.gz
cd ..
mkdir -p $PKG/usr/share/AbiSuite-2.0/AbiWord
cp -a help $PKG/usr/share/AbiSuite-2.0/AbiWord
cp -a Manual/en/Abiword_Manual.abw $PKG/usr/doc/abiword-$VERSION/docs
cd ../abiword-plugins
./configure \
  --prefix=/usr \
  --disable-debug \
  --disable-gnome \
  $TUPLE
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
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

