#!/bin/sh
CWD=`pwd`

VERSION=3.3.02
ARCH=${ARCH:-sparc}
BUILD=${BUILD:-1}

if [ "$ARCH" = "i386" ]; then
  SLKCFLAGS="-O2 -march=i386 -mcpu=i686"
elif [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mcpu=i686"
elif [ "$ARCH" = "s390" ]; then
  SLKCFLAGS="-O2"
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2"
elif [ "$ARCH" = "sparc" ]; then
  SLKCFLAGS="-O2"
fi


if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-ispell

cd $TMP
tar xzvf $CWD/ispell-$VERSION.tar.gz
cd ispell-$VERSION
#zcat $CWD/ispell.diff.gz | patch -p1 --verbose
#zcat $CWD/patches-splack/ispell-3.2.06-coreutilstailfix-1.diff.gz \
#  | patch -p0 --verbose
CFLAGS="$SLKCFLAGS" \
  make

# Build directory structure
rm -rf $PKG/usr
mkdir -p $PKG/usr/lib/ispell $PKG/usr/bin $PKG/usr/doc/ispell \
         $PKG/usr/man/man1 $PKG/usr/man/man4 $PKG/usr/man/man3
cp -a ispell buildhash icombine ijoin munchlist findaffix tryaffix \
      $PKG/usr/bin
chown root.root $PKG/usr/bin/*
chmod 755       $PKG/usr/bin/*

gzip -9c ispell.1 > $PKG/usr/man/man1/ispell.1.gz
gzip -9c fields.3 > $PKG/usr/man/man3/fields.3.gz
gzip -9c ispell.4 > $PKG/usr/man/man4/ispell.4.gz

cp -a languages/english/english.aff $PKG/usr/lib/ispell
cp -a languages/american/americanmed.hash $PKG/usr/lib/ispell 

( cd $PKG/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 addons \
  $PKG/usr/doc/ispell-$VERSION
chown -R root.root $PKG/usr/doc/ispell-$VERSION

# Build the package:
cd $PKG
makepkg -l y -c n $TMP/ispell-$VERSION-$ARCH-$BUILD.tgz

# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP/ispell-$VERSION
  rm -rf $PKG
fi

