#!/bin/bash # Copyright (c) 2014, Joseph Hunkeler # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. export ATLAS_VERSION=3.10.2 export LAPACK_VERSION=3.5.0 export ATLAS_URL=http://sourceforge.net/projects/math-atlas/files/Stable/${ATLAS_VERSION}/atlas${ATLAS_VERSION}.tar.bz2 export LAPACK_URL=http://www.netlib.org/lapack/lapack-${LAPACK_VERSION}.tgz if [ ! -z "${UR_DIR}" ]; then echo "UREKA must not be active." exit 1 fi export build_temp=/tmp/ur_optimize_build function init_optimize { if [ -d "${PREFIX}" ]; then echo "${PREFIX} exists. Abort." exit 1 fi mkdir -p ${PREFIX} if (( $? > 0 )); then exit $? fi if [ -d "${build_temp}" ]; then deinit_optimize fi mkdir -p "${build_temp}" cd "${build_temp}" } function deinit_optimize { rm -rf "${build_temp}" } function stage_ATLAS { local url="${ATLAS_URL}" local tarball="$(basename ${url})" wget "${url}" tar xf "${tarball}" } function stage_LAPACK { local url="${LAPACK_URL}" local tarball="$(basename ${url})" wget "${url}" #tar xf "${tarball}" } function fix_barriers { # Make sure we have libgfortran available before removing it from Ureka sys_libgfortran_path=$(ldconfig -p | grep libgfortran.so.3 | awk '{ print $4 }') if [ -z "${sys_libgfortran_path}" ]; then echo "Aborting: Please make sure libgfortran.so.3 is installed." exit 1 fi # Remove Ureka's libgfortran ureka_libgfortran_path="${UREKA}/python/lib/libgfortran.so.3" ureka_libgfortran_dirname="$(dirname ${ureka_libgfortran_path})" ureka_libgfortran_basename="$(basename ${ureka_libgfortran_path})" if [ -f "${ureka_libgfortran_path}" ]; then echo "Moving Ureka's libgfortran.so.3 out of the way..." ( cd "${ureka_libgfortran_dirname}" && \ mv "${ureka_libgfortran_basename}" "${ureka_libgfortran_basename}.unused" ) fi } function build_ATLAS { local BUILDROOT=`pwd` stage_ATLAS stage_LAPACK cd ATLAS mkdir -p BUILD && cd BUILD ../configure --prefix=${PREFIX} \ --with-netlib-lapack-tarfile=${BUILDROOT}/$(basename ${LAPACK_URL}) \ --shared \ -b 64 \ -Fa alg "-fPIC -Wl,-rpath=${PREFIX}/lib,--enable-new-dtags" \ -Si latune 1 make make shared make ptshared make install return $? } function build_modules { export ATLAS="${PREFIX}" export BLAS="${PREFIX}" export LAPACK="${PREFIX}" local packages=( numpy scipy ) for package in "${packages[@]}" do yes | pip uninstall ${package} done for package in "${packages[@]}" do yes | pip install --upgrade --force ${package} done return $? } NO_ARGS=0 E_OPTERROR=85 if [ $# -eq "$NO_ARGS" ]; then echo "Usage: `basename $0` -p {ureka_installation_path}" exit $E_OPTERROR fi while getopts ":p:" opt do case $opt in p) export UREKA=${OPTARG} ;; :) echo "-$OPTARG requires an argument (e.g. path to UREKA installation)" ;; esac done shift $(($OPTIND - 1)) # Begin main script set -x export PREFIX="${UREKA}/ext" fix_barriers init_optimize build_ATLAS if (( $? > 0 )); then echo "ATLAS build failed. Abort." exit 1 fi # Initialize UREKA for building modules eval `${UREKA}/bin/ur-setup-real -sh` # Configure build environment variables to avoid UREKA entirely # - ABSOLUTELY REQUIRED - export F77="gfortran" export F2C="" export CC="/usr/bin/gcc" export CXX="/usr/bin/g++" export CPP=${CXX} build_modules if (( $? > 0 )); then echo "Python module builds failed. Abort." exit 1 fi deinit_optimize