#!/bin/sh
# Heavily based on the Slackware 11.0 SlackBuild
# http://windsor.gsfc.nasa.gov/standards/cdf/dist/cdf30/unix/
# Packagers Gohanz ( gohanz@infinito.it)
# http://www.slacky.it

CWD=`pwd`
if ["$TMP" = ""]; then
 TMP=/tmp
fi
PKG=$TMP/package-cdf
NAME=cdf
VERSION=30
ARCH=${ARCH:-i686}
BUILD=2as

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

cd $TMP
tar xvzf $CWD/$NAME$VERSION-dist-all.tar.gz
cd $NAME$VERSION-dist
CFLAGS="$SLKCFLAGS" \

make OS=linux ENV=gnu all
make test
make test.help
make install.help
make INSTALLDIR=$PKG/usr install

( cd $PKG 
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null 
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
  find . | xargs file | grep "current ar archive" | cut -f 1 -d : | xargs strip -g 2> /dev/null
)

cd   $TMP/$NAME$VERSION-dist/src/include
find -iname 'cdf*.h' -exec cp {} $PKG/usr/include \;

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cd   $TMP/$NAME$VERSION-dist
cp -a \
CDF_copyright.txt CHANGES.txt Help.all Help.install Help.test README.after_install README.install README.install_java_APIs Release.notes Welcome.txt \
$PKG/usr/doc/$NAME-$VERSION
cd $CWD
cp -a *.SlackBuild slack-desc $PKG/usr/doc/$NAME-$VERSION

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

mkdir -p $PKG/etc/profile.d
cp -a  $CWD/cdf.sh    $PKG/etc/profile.d

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/$NAME-$VERSION
 rm -rf $PKG
fi
