#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# http://atlas.sourceforge.net/
# Packagers Gohanz ( gohanz@infinito.it)
# http://www.slacky.eu
# Depends On:
# FlightGear.......( http://www.flightgear.org/ )
# Ode..............( http://www.ode.org/ )
# OpenAl...........( http://www.openal.org )
# FreeAlut.........( http://www.openal.org )
# Plib.............( http://plib.sourceforge.net/ )
# Smpeg............( http://www.lokigames.com/ )
# SimGear..........( http://www.simgear.org/ )

CWD=`pwd`
if ["$TMP" = ""]; then
 TMP=/tmp/tgz
fi
PKG=$TMP/package-atlas
NAME=atlas
VERSION=$(date +%Y%m%d)
TARGET=i686
ARCH=${ARCH:-i686}
BUILD=1as

if [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2"
elif [ "$ARCH" = "athlonxp" ]; then 
  SLKCFLAGS="-O3 -march=athlon-xp -mtune=athlon-xp -pipe -fomit-frame-pointer -ffast-math -mmmx -m3dnow -msse -mfpmath=sse"

fi

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

cd $TMP
cvs -z3 -d:pserver:anonymous@atlas.cvs.sourceforge.net:/cvsroot/atlas co Atlas

echo "+-------------------------------------+"
echo "| Starting SlackBuild  $NAME-$VERSION    |"
echo "+-------------------------------------+"

cd Atlas

chown -R root.root .
./autogen.sh
CFLAGS="$SLKCFLAGS" \
./configure --prefix=/usr \
--disable-debug \
--program-prefix="" \
--program-suffix="" \
--build=$TARGET-slackware-linux
make|| exit 1
make install DESTDIR=$PKG|| exit 1

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a \
AUTHORS COPYING ChangeLog INSTALL NEWS README \
 $PKG/usr/doc/$NAME-$VERSION
cd $CWD
cp -a *.SlackBuild slack-desc $PKG/usr/doc/$NAME-$VERSION
chown -R root.root $PKG/usr/doc/$NAME-$VERSION

mkdir -p $PKG/usr/share/FlightGear
cp -a    $TMP/Atlas/src/AtlasPalette $PKG/usr/share/FlightGear

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null

ADD="flightgear >= 1.0.0-i686-2as,ode >= 0.9-i486-2as,openal >= 0.0.8-i486-3as,\
freealut >= 1.1.0-i486-1sl,plib >= 1.8.5-i486-2sl,smpeg >= 20080506-i486-1as,\
simgear >= 1.0.0-i486-2as" \
requiredbuilder -y -v -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

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