#!/bin/sh
# Heavily based on the Slackware 11.0 SlackBuild 
# Url: http://wolfpack.twu.net/MenuEditor/
# Packager baldelario ~at~ gmail ~dot~ com
# http://www.slacky.it 

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-menueditor

NAME=menueditor
VERSION=1.3.2
TARGET=i486
ARCH=${ARCH:-i486}
BUILD=1bj

cd $TMP
rm -rf $NAME-$VERSION
rm -rf $PKG
mkdir -p $PKG 
tar xjvf $CWD/$NAME-$VERSION.tar.bz2
cd $NAME-$VERSION

chown -R root:root .
./configure Linux -v --prefix=/usr --CFLAGS="-O2 -march=i486 -mtune=i686"
make
make install PREFIX=$PKG/usr
chown -R root.root $PKG/usr/bin
strip $PKG/usr/bin/*

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a AUTHORS INSTALL LICENSE README $PKG/usr/doc/$NAME-$VERSION
mv $PKG/usr/share/menueditor/help $PKG/usr/doc/$NAME-$VERSION
rm -rf $PKG/usr/share/menueditor

mkdir -p $PKG{/install,/usr/share/applications,/usr/share/pixmaps}
cp -a $CWD/*.desktop $PKG/usr/share/applications
mv $PKG/usr/share/icons/menueditor.xpm $PKG/usr/share/pixmaps
rm -rf $PKG/usr/share/icons
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
chmod -R 755 $PKG/usr/share/*

cd $PKG
requiredbuilder -v -y -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz 
if [ "$1" = "--cleanup" ]; then 
  rm -rf $TMP/$NAME-$VERSION
  rm -rf $PKG 
fi
