#!/bin/sh

# Settings

PKG_NAME=blas
NCORES=`sysctl hw.ncpu | awk '{print $2}'`

# 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     = -O3
DRVOPTS  = -O3
NOOPT    =
LOADER   = gfortran
LOADOPTS =
ARCH     = ar
ARCHFLAGS= cr
RANLIB   = ranlib
BLASLIB  = libblas.a
EOF

# Change into build dir

BUILD_DIR=${SRC_DIR}

echo "Building in $BUILD_DIR"

cd $BUILD_DIR

# Build

make clean

make -j$NCORES

# Install

cp -a libblas.a ${ROOT_DIR}/lib/

# Finish
