#!/bin/bash
# Heavily based on the Slackware 12.0 SlackBuild
# http://galculator.sourceforge.net/

NAME="galculator"
VERSION="1.3.1"
ARCH="i486"
BUILD="1gal"
TMP="/tmp/build-$NAME"
PKG="$TMP/pkg"
CWD="`pwd`"
OPTFLAGS="-O2 -march=$ARCH -mtune=i686"
TARGET="i486"

[ -e $TMP ] && rm -rf $TMP
mkdir $TMP

tar xvjf $NAME-$VERSION.tar.bz2 -C $TMP
cd $TMP/$NAME-$VERSION

CFLAGS=${OPTFLAGS} \
sh configure --prefix=/usr \
             --mandir=/usr/man \
	     --program-prefix="" \
	     --program-suffix="" \
	     --build=$TARGET-slackware-linux
 
make -j3
make install DESTDIR=$PKG

mkdir -p $PKG/usr/doc/$NAME-$VERSION

cp -a	ABOUT-NLS \
	AUTHORS \
	ChangeLog \
	COPYING \
	INSTALL	\
	README \
	TODO \
	NEWS \
	THANKS \
	$PKG/usr/doc/$NAME-$VERSION

cd $PKG
chown -R root:root .

find . | xargs file | grep "not stripped" | cut -d : -f1 | xargs strip 

gzip -9 $PKG/usr/man/*/*

mkdir $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/slack-desc > $PKG/usr/doc/$NAME-$VERSION/slack-desc
cat $CWD/$NAME.SlackBuild > $PKG/usr/doc/$NAME-$VERSION/$NAME.SlackBuild

echo
echo -n "making $NAME package.. "
cd $PKG
requiredbuilder -v -y -s $CWD $PKG
makepkg -c n -l y $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz &>/dev/null
echo "done"

if [ "$1" == "--cleanup" ]; then
  echo -n "cleaning up.. "
  rm -rf $TMP
  echo "done"
fi

## EOF ##
