#!/bin/sh
# Heavily based on the Slackware 12.0 SlackBuild
# Requirements: wxwidgets
# http://filezilla-project.org
# Packager baldelario ~at~ gmail ~dot~ com
# http://www.slacky.it
# Note: FileZilla 3  is the next generation (S)FTP-client 
# from the FileZilla project and is currently in development.

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-filezilla
rm -rf $PKG
mkdir -p $PKG

NAME=filezilla
SRCNAME=FileZilla_3.0.9.2_src
VERSION=3.0.9.2
CHOST=i486
ARCH=${ARCH:-i486}
BUILD=1bj

if [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
else
  SLKCFLAGS="-O3"
fi

cd $TMP
rm -rf $NAME-$VERSION
tar xjvf $CWD/$SRCNAME.tar.bz2
cd $NAME-$VERSION
chown -R root:root .
mkdir compile

(cd compile
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
../configure --prefix=/usr \
             --program-prefix= \
	     --program-suffix= \
	     --mandir=/usr/man \
	     --build=$CHOST-slackware-linux

make
make install DESTDIR=$PKG
strip $PKG/usr/bin/*
)

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a AUTHORS ChangeLog COPYING README INSTALL \
$PKG/usr/doc/$NAME-$VERSION
mkdir -p $PKG/usr/share/applications
cp -a $CWD/*.desktop $PKG/usr/share/applications

find $PKG/usr/man -type f -exec gzip -9 {} \;

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cp -a $CWD/{*.SlackBuild,slack-desc} $PKG/usr/doc/$NAME-$VERSION

cd $PKG
chown -R root:root .
requiredbuilder -y -v -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP
fi
