#!/bin/bash
# This is the script to install the ffsb program
#

. /etc/autobench.conf || . functions

WEB_LOCATION="ftp://ausgsa.austin.ibm.com/projects/l/ltcperformance/2003benchmarks/ffsb/resources/ffsbnew-latest.tar.gz"
. $AUTODIR/var/server-repository

wget -q -O $AUTODIR/sources/ffsbnew-latest.tar.gz $SERVER_REPO/sources/ffsbnew-latest.tar.gz
if [ $? -ne 0 ]; then
  # Didn't find it on the repo, try the web location
  echo "Fetching from the network"
  wget -q -O $AUTODIR/sources/ffsb-latest.tar.gz $WEB_LOCATION
  if [ $? -ne 0 ]; then
    # Couldn't get the source -- complain
    echo "WARNING: could not download the source for ffsbnew"
    exit 1
  fi
fi

# Uncompress it
pushd $AUTODIR/sources > /dev/null
rm -rf ffsbnew 2> /dev/null

DST_DIR=$(tar ztf ffsbnew-latest.tar.gz | head -n 1 )
tar zxf ffsbnew-latest.tar.gz
ln -sf $DST_DIR ffsbnew

# build it...
popd > /dev/null
pushd $AUTODIR/sources/ffsbnew > /dev/null
export CFLAGS=-D_GNU_SOURCE $CFLAGS

./configure
make
if [ $? -ne 0 ]; then
  echo "ERROR: unable to make ffsb"
  popd > /dev/null
  exit 1
fi

# if we are on a power box, then build a 64bit version
if [ $(uname -p) -ne "ppc64" ]; then
    popd > /dev/null;
    exit 0;
fi

mv ffsb ffsb32
export CFLAGS=-m64 $CFLAGS
make clean
./configure
make
if [ $? -ne 0 ]; then
  echo "ERROR: unable to make ffsb64 bit"
  popd > /dev/null
  exit 1
fi
mv ffsb ffsb64
ln -s ffsb64 ffsb
popd > /dev/null











