#!/bin/sh

# Settings

PKG_NAME=lapack
NCORES=`cat /proc/cpuinfo | grep "core\ id" | wc -l`

# Work out the root directory

pushd ../.. > /dev/null
ROOT_DIR=`pwd`
popd > /dev/null

# Create the make.inc configuration file in the source tree

SRC_DIR=$ROOT_DIR/src/$PKG_NAME

cat > ${SRC_DIR}/make.inc <<EOF
SHELL    = /bin/sh
PLAT     = _GFORTRAN
FORTRAN  = gfortran 
OPTS     = -O2
DRVOPTS  = -O2
NOOPT    = -O0
LOADER   = gfortran
LOADOPTS =
TIMER    = INT_ETIME
ARCH     = ar
ARCHFLAGS= cr
RANLIB   = ranlib
XBLASLIB =
BLASLIB  = ${ROOT_DIR}/lib/libblas.a
LAPACKLIB= liblapack.a
TMGLIB   = libtmg.a
EOF

# Change into build dir

BUILD_DIR=${SRC_DIR}/SRC

echo "Building in $BUILD_DIR"

cd $BUILD_DIR

# Build

make clean

make -j$NCORES

# Install

cp -a ${SRC_DIR}/liblapack.a ${ROOT_DIR}/lib/

# Finish
