#!/bin/sh
#
# Heavily based on the Slackware 11.0 SlackBuild
#
# Software downloaded from ftp://ftp.linux-france.org/pub/macintosh/oe2mbx-1.21.tar.gz
# packager: Gabriele Inghirami - suonodelsilenzio A-t tiscalinet dOt it

CWD=$(pwd)

if [ "$TMP" = "" ]; then
TMP="/tmp"
fi

PKG=$TMP/package-oe2mbx
NAME=oe2mbx
VERSION=1.21
ARCH=i486
BUILD=1gi

if [ ! -d $TMP ]; then
mkdir -p $TMP
fi

if [ ! -d $PKG ]; then
mkdir -p $PKG
fi

echo "**** Start SlackBuild $NAME-$VERSION ****"
echo ""

cd $TMP
tar xzvf $CWD/$NAME-$VERSION.tar.gz
cd $NAME-$VERSION
# There is no need to act on permissions since only one executable is produced...
# There is no configure, so perhaps the best choice is to set gcc flags using an alias
alias gcc='gcc -O2 -march=i486 -mtune=i686'
make
# We create a directory for executable in $PKG
mkdir -p $PKG/usr/bin
# We copy the executable directly in the package directory
cp bin/oe2mbx $PKG/usr/bin
# We create a directory for documentation
mkdir -p $PKG/usr/doc/$NAME-$VERSION
# We copy in the documentation directory some useful informations
cp -a LICENSE ChangeLog README $PKG/usr/doc/$NAME-$VERSION
# We strip the executable
strip $PKG/usr/bin/oe2mbx
# We give the correct ownership and permissions to the executable
chmod 755 $PKG/usr/bin/oe2mbx
# We give the usual ownership and permissions to the documentation
chown -R root:root $PKG/usr/doc/$NAME-$VERSION
chmod 755 $PKG/usr/doc/$NAME-$VERSION
chmod 644 $PKG/usr/doc/$NAME-$VERSION/*
# We create the install directory
mkdir -p $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

# We create the package
cd $PKG
requiredbuilder -v -y -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

# If requested, we delete the temporary directories

if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP/$NAME-$VERSION
 rm -rf $PKG
fi
