#!/bin/sh
# Heavily based on the Slackware 11.0 SlackBuild
# http://www.netlib.org/lapack/

NAME=lapack
VERSION=3.1.1
CWD=`pwd`
wget -c $SOURCE

CWD=`pwd`
if ["$TMP" = ""]; then
 TMP=/tmp/pkg
fi
PKG=$TMP/package-$NAME

ARCH=${ARCH:-i686}
BUILD=1lu

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

mkdir -p $PKG/usr/lib/
cd $TMP/
tar xzvf $CWD/$NAME-$VERSION.tgz
cd $TMP/$NAME-$VERSION
mv INSTALL/make.inc.LINUX make.inc
make blaslib
make
cp blas_LINUX.a lapack_LINUX.a tmglib_LINUX.a $PKG/usr/lib/
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a README INSTALL/lawn81.pdf $PKG/usr/doc/$NAME-$VERSION
cd $PKG/usr/lib
ln -s blas_LINUX.a libblas.a
ln -s lapack_LINUX.a liblapack.a
ln -s tmglib_LINUX.a tmglib.a
cd $PKG
find . | xargs file | grep "current ar archive" | cut -f 1 -d : | xargs strip -g 2> /dev/null
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
requiredbuilder -v -y -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