#!/bin/sh

# Slackware build script for fftw
# Written by Kyle Guinn <elyk03@gmail.com>

PRGNAM=fftw
VERSION=${VERSION:-3.2.2}
BUILD=${BUILD:-1}
ARCH=alpha
CWD=$(pwd)
TMP=${TMP:-/tmp}
PKG=$TMP/package-$PRGNAM-$VERSION
TARGET=$ARCH-alphaslack-linux
DOCS="AUTHORS CONVENTIONS COPY* INSTALL NEWS README* TODO doc/html"

#if [ "${PORTABLE:-yes}" = "no" ]; then
    # According to doc/fftw3.pdf the configure script should choose the best
    # value for $CFLAGS.  These variables must be unset so that the configure
    # script will decide.

    # If you are interested in further optimizations such as alternative
    # multithreading and support for other processors, check this page for
    # details:
    # http://www.fftw.org/fftw3_doc/Installation-on-Unix.html
#    unset CFLAGS
#    unset CXXFLAGS
#    unset FFLAGS
#    PKGARCH="custom"
#    do_portable=""
#else
#    PKGARCH=$ARCH
#    do_portable="--enable-portable-binary"
#fi

rm -rf $PKG
mkdir -p $PKG
(cd $TMP
rm -rf $PRGNAM-$VERSION
tar xf $CWD/$PRGNAM-$VERSION.tar.?z* || exit 1
cd $PRGNAM-$VERSION
chown -R root:root .
chmod -R u+w,go+r-w,a-st .

# compile libfftw3
./configure \
 --prefix=/usr \
 --sysconfdir=/etc \
 --localstatedir=/var \
 --mandir=/usr/man \
 --infodir=/usr/info \
 --docdir=/usr/doc/fftw-$VERSION \
 --enable-shared \
 --disable-static \
 --enable-threads \
 --disable-sse2 \
 --build=$TARGET

make || exit 1
make install-strip DESTDIR=$PKG || exit 1

# compile libfftw3f
./configure \
 --prefix=/usr \
 --sysconfdir=/etc \
 --localstatedir=/var \
 --mandir=/usr/man \
 --infodir=/usr/info \
 --docdir=/usr/doc/fftw-$VERSION \
 --enable-shared \
 --disable-static \
 --enable-threads \
 --enable-float \
 --disable-sse2 \
 --build=$TARGET

make || exit 1
make install-strip DESTDIR=$PKG || exit 1

# compile libfftw3l
./configure \
 --prefix=/usr \
 --sysconfdir=/etc \
 --localstatedir=/var \
 --mandir=/usr/man \
 --infodir=/usr/info \
 --docdir=/usr/doc/fftw-$VERSION \
 --enable-shared \
 --disable-static \
 --enable-threads \
 --enable-long-double \
 --build=$TARGET

make || exit 1
make install-strip DESTDIR=$PKG || exit 1

( cd $PKG/usr/man
    find . -type f -exec gzip -9 {} \;
    for i in $(find . -type l); do \
        ln -s $(readlink $i).gz $i.gz; \
        rm $i; \
    done
)

rm -f $PKG/usr/info/dir
gzip -9 $PKG/usr/info/*

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a $DOCS $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

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

cd $PKG
makepkg -l y -c n $TMP/$PRGNAM-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/$PRGNAM.build.log
