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

NAME="adesklets"
VERSION="0.6.1"
ARCH="i486"
BUILD="3gal"
TMP="/tmp/build-$NAME"
PKG="$TMP/pkg"
CWD="`pwd`"
OPTFLAGS="-O2 -march=$ARCH -mtune=i686"

rm -rf $TMP
mkdir $TMP

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

CFLAGS=${OPTFLAGS} \
CXXFLAGS=${OPTFLAGS} \
sh configure --prefix=/usr \
--with-x \
--program-prefix= \
--program-suffix= \
--without-fontconfig \
--build=$ARCH-slackware-linux
make -j3
make install DESTDIR=$PKG

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

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

rm -rf $PKG/usr/info
rm -rf $PKG/usr/man
mkdir -p $PKG/usr/info
mkdir -p $PKG/usr/man/man1
cp -a doc/*.info $PKG/usr/info
cp -a doc/adesklets.1 $PKG/usr/man/man1
mv $TMP/adesklets_htmldoc-0.6.1/* $PKG/usr/doc/$NAME-$VERSION/htmldoc

( 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
)

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

mkdir $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $CWD
cp -a *.SlackBuild slack-desc $PKG/usr/doc/$NAME-$VERSION
cd $PKG
chown -R root:root .
requiredbuilder -v -y -s $CWD $PKG
echo -n "making $NAME package.. "
makepkg -c n -l y $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz
echo "done"

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

## EOF ##
