#!/bin/sh
# Heavily based on the Slackware 12.2 SlackBuild
# http://www.xaraxtreme.org/developers/sourcecode.html
# Packagers Andrea Sciucca  ( gohanz at infinito.it)
# http://www.slacky.it
# Required wxwidgets (Unicode)

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-xaralx
NAME=xaralx
VERSION=0.7r1785
CHOST=i486
ARCH=${ARCH:-i486}
BUILD=4as
SOURCE=http://downloads2.xara.com/opensource/XaraLX-$VERSION.tar.bz2

if [ ! -e XaraLX-$VERSION.tar.bz2 ]; then
wget -c $SOURCE
fi

if [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O3 -march=i686 -pipe -fomit-frame-pointer"
elif [ "$ARCH" = "athlon64" ]; then
  SLKCFLAGS="-O2 -march=athlon64 -pipe"
elif [ "$ARCH" = "athlonxp" ]; then
  SLKCFLAGS="-O3 -march=athlon-xp -pipe -fomit-frame-pointer"
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2"
elif [ "$ARCH" = "s390" ]; then
  SLKCFLAGS="-O2"
fi

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

cd $TMP
tar xvjf $CWD/XaraLX-$VERSION.tar.bz2

echo -e "\E[0;32m+----------------------------------+\E[0;0m"
echo -e "\E[0;32m| Start SlackBuild $NAME-$VERSION |\E[0;0m"
echo -e "\E[0;32m+----------------------------------+\E[0;0m"

cd XaraLX-$VERSION

find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;
find . -perm 666 -exec chmod 644 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;

chown -R root:root .

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure --prefix=/usr \
--disable-debug \
--enable-filters \
--enable-svgfilter \
--program-prefix= \
--program-suffix= \
--build=$CHOST-slackware-linux
make
make install DESTDIR=$PKG

mkdir -p $PKG/usr/share/applications

cat << EOF > $PKG/usr/share/applications/xaralx.desktop
[Desktop Entry]
Version=1.0
Encoding=UTF-8
Name=Xara Xtreme
Comment=Versatile vector graphics program
Comment[de_DE]=Leistungsstarkes Vektorgrafik-Programm
Comment[fr_FR]=Logiciel d'illustration vectorielle polyvalent
Comment[it_IT]=Versatile programma di grafica vettoriale
Comment[pt_BR]=Versátil programa para gráficos vetoriais
Icon=/usr/share/pixmaps/xaralx.png
Terminal=false
Type=Application
Categories=Application;Graphics;
StartupNotify=true
MimeType=application/vnd.xara;application/x-extension-xar;
FilePattern=xaralx;
Exec=XaraLX %F
TryExec=XaraLX
EOF

mkdir -p $PKG/usr/share/pixmaps
cp -a    $TMP/XaraLX-$VERSION/xaralx.png $PKG/usr/share/pixmaps

mkdir -p $PKG/usr/man/man1
cp -a  $TMP/XaraLX-$VERSION/doc/xaralx.1 $PKG/usr/man/man1

mkdir -p $PKG/usr/share/xaralx/Examples
cp -a    $TMP/XaraLX-$VERSION/Designs/*   $PKG/usr/share/xaralx/Examples
cp -a -r $TMP/XaraLX-$VERSION/Templates   $PKG/usr/share/xaralx
cp -a -r $TMP/XaraLX-$VERSION/TextDesigns $PKG/usr/share/xaralx

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a ABOUT-NLS AUTHORS COPYING ChangeLog GPL  INSTALL LICENSE NEWS README *.txt \
$PKG/usr/doc/$NAME-$VERSION

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

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

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
fi
