#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-indent

VERSION=2.2.9
ARCH=i386
BUILD=1

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
if [ ! -d $PKG ]; then
  mkdir -p $PKG # place for the package to be built
fi

cd $TMP
tar xjvf $CWD/indent-$VERSION.tar.bz2
cd indent-$VERSION
chown -R root.root .
CFLAGS="-O2 -march=i386 -mcpu=i686" \
./configure --prefix=/usr i386-slackware-linux
make
strip src/indent
mkdir -p $PKG/usr/bin
cat src/indent > $PKG/usr/bin/indent
chown -R root.bin $PKG/usr/bin
chmod 755 $PKG/usr/bin/indent
mkdir -p $PKG/usr/info
cat doc/indent.info | gzip -9c > $PKG/usr/info/indent.info.gz
mkdir -p $PKG/usr/man/man1
cat man/indent.1 | gzip -9c > $PKG/usr/man/man1/indent.1.gz
( cd po
  for locale in *.gmo ; do
    mkdir -p $PKG/usr/share/locale/`basename $locale .gmo`/LC_MESSAGES
    cat $locale > $PKG/usr/share/locale/`basename $locale .gmo`/LC_MESSAGES/indent.mo
  done
)
mkdir -p $PKG/usr/doc/indent-$VERSION
cp -a \
  AUTHORS COPYING* INSTALL NEWS README \
  $PKG/usr/doc/indent-$VERSION
chmod 644 $PKG/usr/doc/indent-$VERSION/*
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

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

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