#!/bin/sh
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-ispell
VERSION=3.3.02
ARCH=alpha
BUILD=2

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf ispell-$VERSION
tar xzf $CWD/ispell-$VERSION.tar.gz
cd ispell-$VERSION
zcat $CWD/ispell.diff.gz | patch -p1 --verbose || exit
make || exit
mkdir -p $PKG/usr/bin $PKG/usr/lib/ispell $PKG/usr/man/man1 $PKG/usr/man/man5
cat buildhash > $PKG/usr/bin/buildhash
cat findaffix > $PKG/usr/bin/findaffix
cat icombine > $PKG/usr/bin/icombine
cat ijoin > $PKG/usr/bin/ijoin
cat ispell > $PKG/usr/bin/ispell
cat munchlist > $PKG/usr/bin/munchlist
cat tryaffix > $PKG/usr/bin/tryaffix
cat zapdups > $PKG/usr/bin/zapdups
cat deformatters/defmt-c > $PKG/usr/bin/defmt-c
cat deformatters/defmt-sh > $PKG/usr/bin/defmt-sh
( 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
)
chmod 755 $PKG/usr/bin/*
cat languages/american/americanmed.hash > $PKG/usr/lib/ispell/americanmed.hash
cat languages/english/english.aff > $PKG/usr/lib/ispell/english.aff
cat languages/english/english.5X |gzip -9c  > $PKG/usr/man/man5/english.5.gz
cat ispell.1 |gzip -9c > $PKG/usr/man/man1/ispell.1.gz
cat ispell.5 |gzip -9c > $PKG/usr/man/man5/ispell.5.gz
echo '.so man1/ispell.1' | gzip -9c > $PKG/usr/man/man1/buildhash.1.gz
echo '.so man1/ispell.1' | gzip -9c > $PKG/usr/man/man1/findaffix.1.gz
echo '.so man1/ispell.1' | gzip -9c > $PKG/usr/man/man1/munchlist.1.gz
echo '.so man1/ispell.1' | gzip -9c > $PKG/usr/man/man1/tryaffix.1.gz
( cd $PKG
  cd usr/lib/ispell
  ln -sf americanmed.hash american.hash
  ln -sf americanmed.hash english.hash
)
mkdir -p $PKG/usr/doc/ispell-$VERSION
cp -a Contributors Magiclines README WISHES $PKG/usr/doc/ispell-$VERSION
chown -R root.root $PKG/usr/doc/ispell-$VERSION
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n $TMP/ispell-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/ispell.build.log
