#! /bin/bash ################################################################################ # Prepare ################################################################################ # Set up shell set -x # Output commands set -e # Abort on errors ################################################################################ # Search ################################################################################ if [ -z "${SAGA_DIR}" ]; then echo "BEGIN MESSAGE" echo "SAGA selected, but SAGA_DIR not set. Checking some places..." echo "END MESSAGE" FILES="include/saga/saga-config.hpp lib/libsaga_core.a" DIRS="/usr /usr/local /usr/local/saga /usr/local/packages/saga /usr/local/apps/saga /opt/local ${HOME} ${HOME}/saga c:/packages/saga" for dir in $DIRS; do SAGA_DIR="$dir" for file in $FILES; do if [ ! -r "$dir/$file" ]; then unset SAGA_DIR break fi done if [ -n "$SAGA_DIR" ]; then break fi done if [ -z "$SAGA_DIR" ]; then echo "BEGIN MESSAGE" echo "SAGA not found" echo "END MESSAGE" else echo "BEGIN MESSAGE" echo "Found SAGA in ${SAGA_DIR}" echo "END MESSAGE" fi fi ################################################################################ # Build ################################################################################ if [ -z "${SAGA_DIR}" -o "${SAGA_DIR}" = 'BUILD' ]; then echo "BEGIN MESSAGE" echo "Building SAGA..." echo "END MESSAGE" # Set locations THORN=SAGA NAME=saga-core-1.6 SRCDIR=$(dirname $0) BUILD_DIR=${SCRATCH_BUILD}/build/${THORN} if [ -z "${SAGA_INSTALL_DIR}" ]; then echo "BEGIN MESSAGE" echo "SAGA install directory, SAGA_INSTALL_DIR, not set. Installing in the default configuration location. " echo "END MESSAGE" INSTALL_DIR=${SCRATCH_BUILD}/external/${THORN} else echo "BEGIN MESSAGE" echo "SAGA install directory, SAGA_INSTALL_DIR, selected. Installing SAGA at ${SAGA_INSTALL_DIR} " echo "END MESSAGE" INSTALL_DIR=${SAGA_INSTALL_DIR} fi DONE_FILE=${SCRATCH_BUILD}/done/${THORN} SAGA_DIR=${INSTALL_DIR} ( exec >&2 # Redirect stdout to stderr set -x # Output commands set -e # Abort on errors cd ${SCRATCH_BUILD} if [ -e ${DONE_FILE} -a ${DONE_FILE} -nt ${SRCDIR}/dist/${NAME}.tgz \ -a ${DONE_FILE} -nt ${SRCDIR}/SAGA.sh ] then echo "SAGA: The enclosed SAGA library has already been built; doing nothing" else echo "SAGA: Building enclosed SAGA library" # Should we use gmake or make? MAKE=$(gmake --help > /dev/null 2>&1 && echo gmake || echo make) # Should we use gtar or tar? TAR=$(gtar --help > /dev/null 2> /dev/null && echo gtar || echo tar) # Should we use gpatch or patch? if [ -z "$PATCH" ]; then PATCH=$(gpatch -v > /dev/null 2>&1 && echo gpatch || echo patch) fi # Set up environment unset LIBS if echo '' ${ARFLAGS} | grep 64 > /dev/null 2>&1; then export OBJECT_MODE=64 fi echo "SAGA: Preparing directory structure..." mkdir build external done 2> /dev/null || true rm -rf ${BUILD_DIR} ${INSTALL_DIR} mkdir ${BUILD_DIR} ${INSTALL_DIR} echo "SAGA: Unpacking archive..." pushd ${BUILD_DIR} ${TAR} xzf ${SRCDIR}/dist/${NAME}.tgz ${PATCH} -p0 < ${SRCDIR}/dist/icpc_options.patch ${PATCH} -p0 < ${SRCDIR}/dist/check_if_open__missing_this echo "SAGA: Configuring..." cd ${NAME} # Enforce gcc if Intel compiler would otherwise be used, until Saga # builds with Intel compiler if $CC --version | grep -q icc; then CC=gcc CFLAGS="-O2" CXX=g++ CXXFLAGS="-O2" fi ./configure --prefix=${SAGA_DIR} echo "SAGA: Building..." ${MAKE} -n echo "SAGA: Installing..." ${MAKE} install popd echo "SAGA: Cleaning up..." rm -rf ${BUILD_DIR} date > ${DONE_FILE} echo "SAGA: Done." fi ) if (( $? )); then echo 'BEGIN ERROR' echo 'Error while building SAGA. Aborting.' echo 'END ERROR' exit 1 fi fi # Set options SAGA_INC_DIRS="$(${SAGA_DIR}/bin/saga-config --cppflags | sed -e 's/ \+-[^I][^ ]\+//g;s/^ *-[^I][^ ]\+ *//g;s/ \+-I/ /g;s/^ *-I//g')" SAGA_LIB_DIRS="$(${SAGA_DIR}/bin/saga-config --libs | sed -e 's/ \+-[^L][^ ]\+//g;s/^ *-[^L][^ ]\+ *//g;s/ \+\/.*//g;s/ \+-L/ /g;s/^ *-L//g')" # remove standard lib dirs (e.g. /usr/lib) SAGA_LIB_DIRS=`echo $SAGA_LIB_DIRS | sed -e 's/\/usr\/\+lib//g'` SAGA_LIBS="$(${SAGA_DIR}/bin/saga-config --libs | sed -e 's/ \+-[^l][^ ]\+//g;s/^ *-[^l][^ ]\+ *//g;s/ \+\/.*//g;s/ \+-l/ /g;s/^ *-l//g')" ################################################################################ # Configure Cactus ################################################################################ # Pass options to Cactus echo "BEGIN MAKE_DEFINITION" echo "HAVE_SAGA = 1" echo "SAGA_DIR = ${SAGA_DIR}" echo "SAGA_INC_DIRS = ${SAGA_INC_DIRS}" echo "SAGA_LIB_DIRS = ${SAGA_LIB_DIRS}" echo "SAGA_LIBS = ${SAGA_LIBS}" echo "END MAKE_DEFINITION" echo 'INCLUDE_DIRECTORY $(SAGA_INC_DIRS)' echo 'LIBRARY_DIRECTORY $(SAGA_LIB_DIRS)' echo 'LIBRARY $(SAGA_LIBS)'