#!/bin/bash
export VISIT_VERSION=${VISIT_VERSION:-"2.10.2"}
export TRUNK_BUILD="no"
export SVN_SOURCE_PATH=${SVN_SOURCE_PATH-"tags/2.10.2/src"}
export SVN_THIRDPARTY_PATH=${SVN_THIRDPARTY_PATH-"tags/2.10.2/third_party"}
export INITIAL_PWD=$PWD
export bv_PATH=.
export bv_PREFIX=$bv_PATH/bv_support/
export build_version=""
export webroot="http://visit.ilight.com/svn/visit/"
export webaddr="${webroot}/trunk/src/svn_bin/bv_support/"
declare -a reqlibs
declare -a optlibs
declare -a grouplibs_name
declare -a grouplibs_deps
declare -a grouplibs_comment
declare -a grouplibs_enabled
declare -a defaultLicenses
declare -a args
check_for_versioning () 
{ 
    local next_arg="no";
    for arg in "$@";
    do
        if [[ "$next_arg" == "build-version" ]]; then
            build_version="$arg";
            next_arg="no";
        else
            if [[ "$arg" == "--build-version" ]]; then
                next_arg="build-version";
            else
                args[${#args[*]}]="$arg";
            fi;
        fi;
    done;
    if [[ "$build_version" != "" ]]; then
        VISIT_VERSION="$build_version";
        webaddr="${webroot}/tags/$VISIT_VERSION/src/svn_bin/build_visit";
        echo "using $webaddr for source";
    fi
}
call_build_visit () 
{ 
    if [[ "${build_version}" == "" ]]; then
        return;
    fi;
    build_visit_ver="build_visit${build_version}";
    if [[ -e "$build_visit_ver" ]]; then
        echo "Found $build_visit_ver";
        exec bash $build_visit_ver "${args[@]}";
    fi;
    for choice in `echo "curl wget svn"`;
    do
        echo "Trying to fetch $build_visit_ver using: $choice";
        tmp_choice=`which $choice`;
        if [ $? != 0 ]; then
            continue;
        fi;
        if [[ $choice == "curl" ]]; then
            curl -s ${webaddr} -o $build_visit_ver;
            if [ $? != 0 ]; then
                continue;
            fi;
        else
            if [[ $choice == "wget" ]]; then
                wget -q ${webaddr} -O $build_visit_ver;
                if [ $? != 0 ]; then
                    continue;
                fi;
            else
                svn -q export ${webaddr} $build_visit_ver;
            fi;
        fi;
        if [[ -e "$build_visit_ver" ]]; then
            echo "Success using $choice";
            break;
        fi;
    done;
    if [[ -e "$build_visit_ver" ]]; then
        if [[ -d bv_support ]]; then
            echo "Removing previous support directory...";
            rm -fR bv_support;
        fi;
        SVN_SOURCE_PATH="tags/${VISIT_VERSION}/src";
        SVN_THIRDPARTY_PATH="tags/${VISIT_VERSION}/third_party";
        bv_PREFIX=$PWD/bv_support;
        webaddr="$webroot/tags/$build_version/src/svn_bin/bv_support/";
        echo "rerouting support from $webaddr";
        configure_support_files;
        echo "SVN_SOURCE_PATH=$SVN_SOURCE_PATH" >> bv_support/helper_funcs.sh;
        echo "SVN_THIRDPARTY_PATH=$SVN_THIRDPARTY_PATH" >> bv_support/helper_funcs.sh;
        declare -f download_file >> bv_support/helper_funcs.sh;
        echo "Executing $build_visit_ver";
        exec bash $build_visit_ver "${args[@]}";
    else
        echo "Failed to execute another version of VisIt";
        exit 2;
    fi
}
configure_support_files () 
{ 
    if [ ! -d $bv_PREFIX ]; then
        bv_PREFIX=$PWD/bv_support/;
        if [ ! -d $bv_PREFIX ]; then
            for choice in `echo "curl wget svn"`;
            do
                echo "Trying to fetch support files using: $choice";
                tmp_choice=`which $choice`;
                if [ $? != 0 ]; then
                    continue;
                fi;
                if [[ $choice == "curl" ]]; then
                    tmp_curl=`curl -s ${webaddr}/ | grep 'sh\|xml' | grep li|sed s/.*bv_/bv_/g | sed -e s/\.sh.*/\.sh/g | sed -e s/.*href\=\"//g | sed -e s/\".*//g;`;
                    if [ $? != 0 ]; then
                        continue;
                    fi;
                    mkdir -p bv_support_tmp;
                    is_successful=1;
                    for curl_files in `echo $tmp_curl`;
                    do
                        curl -s ${webaddr}/${curl_files} -o bv_support_tmp/$curl_files;
                        if [ $? != 0 ]; then
                            echo "failed to download ${curl_files}";
                            is_successful=0;
                            break;
                        fi;
                    done;
                    if [ $is_successful == 0 ]; then
                        rm -fR bv_support_tmp;
                    else
                        mv bv_support_tmp bv_support;
                    fi;
                else
                    if [[ $choice == "wget" ]]; then
                        wget -r -nH --cut-dirs=6 --no-parent --reject="index.html,robots.txt" -q ${webaddr};
                    else
                        svn -q co ${webaddr} bv_support;
                    fi;
                fi;
                if [ ! -d $bv_PREFIX ]; then
                    echo "$choice failed to retrieve support files";
                else
                    echo "Success. downloaded support, continuing";
                    break;
                fi;
            done;
        fi;
        if [ ! -d $bv_PREFIX ]; then
            echo "Failed to detect or fetch support files, please contact visit-users mailing list with error. Quitting...";
            exit 2;
        fi;
    fi
}
function initialize_build_visit()
{

# *************************************************************************** #
#                       Section 1, setting up inputs                          #
# --------------------------------------------------------------------------- #
# This section sets up the inputs to the VisIt script.  This is where you can #
# specify which compiler to use, which versions of the third party libraries, #
# etc.  Note that this script is really only known to work with gcc.          #
# *************************************************************************** #

# This env. variable is NOT to be overriden by user. It is intended to
# contain user's env. just prior to running build_visit.
export BUILD_VISIT_ENV=$(env | cut -d'=' -f1 | sort | uniq)

# allow users to set an external hostname for output filename
export EXTERNAL_HOSTNAME=""

# Can cause problems in some build systems.
unset CDPATH

# Some systems tar command does not support the deep directory hierarchies
# used in Qt, such as AIX. Gnu tar is a good alternative.
### export TAR=/usr/local/bin/tar # Up and Purple
export TAR=tar

#
# we have logic that assumes lib dirs are named "lib", not "lib64". On 
# openSuSe some of the autoconf based 3rd party libs will install to "lib64"
# unless the "CONFIG_SITE" env var is cleared  
#
export CONFIG_SITE=""


# Determine if gfortran is present. This overly complex coding is to prevent
# the "which" command from echoing failure to the user.
which gfortran >& /dev/null
if [[ $? == 0 ]]; then
    export GFORTRAN=`which gfortran | grep '^/'`
else
    export GFORTRAN=""
fi

export OPSYS=${OPSYS:-$(uname -s)}
export PROC=${PROC:-$(uname -p)}
export REL=${REL:-$(uname -r)}
# Determine architecture
if [[ "$OPSYS" == "Darwin" ]]; then
   export ARCH=${ARCH:-"${PROC}-apple-darwin${REL%%.*}"}
#  export VISITARCH=${VISITARCH-${ARCH}}
   export SO_EXT="dylib"
   VER=$(uname -r)
# Check for Panther, because MACOSX_DEPLOYMENT_TARGET will default to 10.1
# Used http://en.wikipedia.org/wiki/Darwin_(operating_system) to map Darwin
# Kernel versions to OSX version numbers.
# Other options for dealing with MACOSX_DEPLOYMENT_TARGET didn't work
# See issue #1499 (https://visitbugs.ornl.gov/issues/1499)

# use gcc for 10.9 & earlier


   if (( ${VER%%.*} < 8 )) ; then
      export MACOSX_DEPLOYMENT_TARGET=10.3
   elif [[ ${VER%%.*} == 8 ]] ; then
      export MACOSX_DEPLOYMENT_TARGET=10.4
   elif [[ ${VER%%.*} == 9 ]] ; then
      export MACOSX_DEPLOYMENT_TARGET=10.5
   elif [[ ${VER%%.*} == 10 ]] ; then
      export MACOSX_DEPLOYMENT_TARGET=10.6
   elif [[ ${VER%%.*} == 11 ]] ; then
      export MACOSX_DEPLOYMENT_TARGET=10.7
   elif [[ ${VER%%.*} == 12 ]] ; then
      export MACOSX_DEPLOYMENT_TARGET=10.8
   elif [[ ${VER%%.*} == 13 ]] ; then
      export MACOSX_DEPLOYMENT_TARGET=10.9
      export C_COMPILER=${C_COMPILER:-"clang"}
      export CXX_COMPILER=${CXX_COMPILER:-"clang++"}
   elif [[ ${VER%%.*} == 14 ]] ; then
      export MACOSX_DEPLOYMENT_TARGET=10.10
      export C_COMPILER=${C_COMPILER:-"clang"}
      export CXX_COMPILER=${CXX_COMPILER:-"clang++"}
   else
      export MACOSX_DEPLOYMENT_TARGET=10.10
      export C_COMPILER=${C_COMPILER:-"clang"}
      export CXX_COMPILER=${CXX_COMPILER:-"clang++"}
   fi


   export C_COMPILER=${C_COMPILER:-"gcc"}
   export CXX_COMPILER=${CXX_COMPILER:-"g++"}

   # Disable Fortran on Darwin since it causes HDF5, H5Part, Silo, ADIOS builds to explode.
   export FC_COMPILER=""
   export C_OPT_FLAGS=${C_OPT_FLAGS:-"-O2"}
   export CFLAGS=${CFLAGS:-"-fno-common -fexceptions"}
   export CXX_OPT_FLAGS=${CXX_OPT_FLAGS:-"-O2"}
   export CXXFLAGS=${CXXFLAGS:-"-fno-common -fexceptions"}
   export FCFLAGS=${FCFLAGS:-$CFLAGS}
   export MESA_TARGET=${MESA_TARGET:-"darwin"}
   export QT_PLATFORM=${QT_PLATFORM:-"macx-g++"}
elif [[ "$OPSYS" == "Linux" ]]; then
   export ARCH=${ARCH:-"linux-$(uname -m)"} # You can change this to say RHEL, SuSE, Fedora.
   export SO_EXT="so"
   if [[ "$(uname -m)" == "i386" ]] ; then
###   export MESA_TARGET=${MESA_TARGET:-"linux-x86"} # Mesa-6.x
      export MESA_TARGET=${MESA_TARGET:-"linux"}
   elif [[ "$(uname -m)" == "i686" ]] ; then
###   export MESA_TARGET=${MESA_TARGET:-"linux-x86"} # Mesa-6.x
      export MESA_TARGET=${MESA_TARGET:-"linux"}
   elif [[ "$(uname -m)" == "x86_64" ]] ; then
      CFLAGS="$CFLAGS -m64 -fPIC"
      FCFLAGS="$FCFLAGS -m64 -fPIC"
      if [[ "$C_COMPILER" == "gcc" || "$C_COMPILER" == "" ]]; then
          C_OPT_FLAGS="$C_OPT_FLAGS -O2"
      fi
      CXXFLAGS="$CXXFLAGS -m64 -fPIC"
      if [[ "$CXX_COMPILER" == "g++" || "$CXX_COMPILER" == "" ]]; then
          CXX_OPT_FLAGS="$CXX_OPT_FLAGS -O2"
      fi
###   export MESA_TARGET=${MESA_TARGET:-"linux-x86-64"} # Mesa-6.x
      export MESA_TARGET=${MESA_TARGET:-"linux"}
      QT_PLATFORM="linux-g++-64"
   elif [[ "$(uname -m)" == "ppc64" ]] ; then
      if [[ "$C_COMPILER" == "xlc" ]] ; then
          CFLAGS="$CFLAGS -qpic"
          FCFLAGS="$FCFLAGS -qpic"
          CXXFLAGS="$CXXFLAGS -qpic"
          export CXX_COMPILER=${CXX_COMPILER-"xlC"}
          export MESA_TARGET=${MESA_TARGET-"linux"}
          QT_PLATFORM="linux-xlc" #aix-xlc"
      elif [[ "$C_COMPILER" == "bgxlc" ]] ; then
          export CXX_COMPILER=${CXX_COMPILER-"bgxlC"}
      else
          CFLAGS="$CFLAGS -fPIC"
          FCFLAGS="$FCFLAGS -fPIC"
          if [[ "$C_COMPILER" == "gcc" || "$C_COMPILER" == "" ]]; then
              C_OPT_FLAGS="$C_OPT_FLAGS -O2"
          fi
          CXXFLAGS="$CXXFLAGS -fPIC"
          if [[ "$CXX_COMPILER" == "g++" || "$CXX_COMPILER" == "" ]]; then
              CXX_OPT_FLAGS="$CXX_OPT_FLAGS -O2"
          fi
          export MESA_TARGET=${MESA_TARGET-"linux"}
          QT_PLATFORM="linux-g++"
      fi
   elif [[ "$(uname -m)" == "ia64" ]] ; then
      CFLAGS="$CFLAGS -fPIC"
      FCFLAGS="$FCFLAGS -fPIC"
      if [[ "$C_COMPILER" == "gcc" || "$C_COMPILER" == "" ]]; then
          C_OPT_FLAGS="$C_OPT_FLAGS -O2"
      fi
      CXXFLAGS="$CXXFLAGS -fPIC"
      if [[ "$CXX_COMPILER" == "g++" || "$CXX_COMPILER" == "" ]]; then
          CXX_OPT_FLAGS="$CXX_OPT_FLAGS -O2"
      fi
      QT_PLATFORM="linux-g++"
   fi
   export C_COMPILER=${C_COMPILER:-"gcc"}
   export CXX_COMPILER=${CXX_COMPILER:-"g++"}
   export FC_COMPILER=${FC_COMPILER:-$GFORTRAN}
   export C_OPT_FLAGS=${C_OPT_FLAGS:-"-O2"}
   export CXX_OPT_FLAGS=${CXX_OPT_FLAGS:-"-O2"}
   export MESA_TARGET=${MESA_TARGET:-"linux"}
   export QT_PLATFORM=${QT_PLATFORM:-"linux-g++"}
elif [[ "$OPSYS" == "AIX" ]]; then
   export ARCH="aix" # You can change this to say RHEL, SuSE, Fedora, etc.
   export SO_EXT="a"
   export C_COMPILER=${C_COMPILER:-"xlc"}
   export FC_COMPILER=${FC_COMPILER:-$(which xlf | grep '^/')}
   export CXX_COMPILER=${CXX_COMPILER:-"xlC"}
   export C_OPT_FLAGS=${C_OPT_FLAGS:-"-O2"}
   export CXX_OPT_FLAGS=${CXX_OPT_FLAGS:-"-O2"}
   export MAKE=${MAKE:-"gmake"}
   export MESA_TARGET=${MESA_TARGET:-"aix"}
   if [[ "$OBJECT_MODE" == 32 ]]; then
      export QT_PLATFORM=${QT_PLATFORM:-"aix-xlc"}
   else
      export QT_PLATFORM=${QT_PLATFORM:-"aix-xlc-64"}
   fi
elif [[ "$OPSYS" == "IRIX64" ]]; then
   export ARCH="irix64" # You can change this to say RHEL, SuSE, Fedora, etc.
   export SO_EXT="so"
   export C_COMPILER=${C_COMPILER:-"gcc"}
   export FC_COMPILER=${FC_COMPILER:-$GFORTRAN}
   export CXX_COMPILER=${CXX_COMPILER:-"g++"}
   export C_OPT_FLAGS=${C_OPT_FLAGS:-"-O2"}
   export CXX_OPT_FLAGS=${CXX_OPT_FLAGS:-"-O2"}
   export MAKE=${MAKE:-"gmake"}
   export MESA_TARGET=${MESA_TARGET:-"irix6-64-dso"}
elif [[ "$OPSYS" == "SunOS" ]]; then
   export ARCH=${ARCH:-"sunos5"}
   export SO_EXT="so"
   export C_COMPILER=${C_COMPILER:-"gcc"}
   export FC_COMPILER=${FC_COMPILER:-$GFORTRAN}
   export CXX_COMPILER=${CXX_COMPILER:-"g++"}
   export C_OPT_FLAGS=${C_OPT_FLAGS:-"-O2"}
   export CXX_OPT_FLAGS=${CXX_OPT_FLAGS:-"-O2"}
   export MAKE=${MAKE:-"make"}
   export MESA_TARGET=${MESA_TARGET:-"sunos5-gcc"}
   export QT_PLATFORM="solaris-g++"
else
   export ARCH=${ARCH:-"linux-$(uname -m)"} # You can change this to say RHEL, SuSE, Fedora.
   export SO_EXT="so"
   if [[ "$(uname -m)" == "x86_64" ]] ; then
      CFLAGS="$CFLAGS -m64 -fPIC"
      FCFLAGS="$FCFLAGS -m64 -fPIC"
      if [[ "$C_COMPILER" == "gcc" || "$C_COMPILER" == "" ]]; then
          C_OPT_FLAGS="$C_OPT_FLAGS -O2"
      fi
      CXXFLAGS="$CXXFLAGS -m64 -fPIC"
      if [[ "$CXX_COMPILER" == "g++" || "$CXX_COMPILER" == "" ]]; then
          CXX_OPT_FLAGS="$CXX_OPT_FLAGS -O2"
      fi
      QT_PLATFORM="linux-g++-64"
   fi
   if [[ "$(uname -m)" == "ia64" ]] ; then
      CFLAGS="$CFLAGS -fPIC"
      FCFLAGS="$FCFLAGS -fPIC"
      if [[ "$C_COMPILER" == "gcc" || "$C_COMPILER" == "" ]]; then
          C_OPT_FLAGS="$C_OPT_FLAGS -O2"
      fi
      CXXFLAGS="$CXXFLAGS -fPIC"
      if [[ "$CXX_COMPILER" == "g++" || "$CXX_COMPILER" == "" ]]; then
          CXX_OPT_FLAGS="$CXX_OPT_FLAGS -O2"
      fi
      QT_PLATFORM="linux-g++-64"
   fi
   export C_COMPILER=${C_COMPILER:-"gcc"}
   export FC_COMPILER=${FC_COMPILER:-$GFORTRAN}
   export CXX_COMPILER=${CXX_COMPILER:-"g++"}
   export C_OPT_FLAGS=${C_OPT_FLAGS:-"-O2"}
   export CXX_OPT_FLAGS=${CXX_OPT_FLAGS:-"-O2"}
   export QT_PLATFORM=${QT_PLATFORM:-"linux-g++"}
fi
export MAKE=${MAKE:-"make"}
export THIRD_PARTY_PATH=${THIRD_PARTY_PATH:-"./visit"}
export GROUP=${GROUP:-"visit"}
#export LOG_FILE=${LOG_FILE:-"${0##*/}_log"}
export SVNREVISION=${SVNREVISION:-"HEAD"}
# Created a temporary value because the user can override most of
# the components, which for the GUI happens at a later time.
# the tmp value is useful for user feedback.
if [[ $VISITARCH == "" ]] ; then
    export VISITARCHTMP=${ARCH}_${C_COMPILER}
    if [[ "$CXX_COMPILER" == "g++" ]] ; then
        VERSION=$(g++ -v 2>&1 | grep "gcc version" | cut -d' ' -f3 | cut -d'.' -f1-2)
        if [[ ${#VERSION} == 3 ]] ; then
            VISITARCHTMP=${VISITARCHTMP}-${VERSION}
        fi
    fi
else
# use environment variable value
    export VISITARCHTMP=$VISITARCH
fi

REDIRECT_ACTIVE="no"
ANY_ERRORS="no"

#initialize VisIt
bv_visit_initialize

#
# OPTIONS
#
#initialize required libraries..

for (( bv_i=0; bv_i<${#reqlibs[*]}; ++bv_i ))
do
    initializeFunc="bv_${reqlibs[$bv_i]}_initialize"
    $initializeFunc
done

for (( bv_i=0; bv_i<${#optlibs[*]}; ++bv_i ))
do
    initializeFunc="bv_${optlibs[$bv_i]}_initialize"
    $initializeFunc
done

export DO_HOSTCONF="yes"
export ON_HOSTCONF="on"

export DO_DEBUG="no"
export ON_DEBUG="off"
export DO_GROUP="no"
export ON_GROUP="off"
export DO_LOG="no"
export ON_LOG="off"
parallel="no"
ON_parallel="off"
export DO_SVN="no"
export DO_SVN_ANON="no"
export ON_SVN="off"
export DO_REVISION="no"
export ON_REVISION="off"
USE_VISIT_FILE="no"
ON_USE_VISIT_FILE="off"
export DO_PATH="no"
export ON_PATH="off"
export DO_VERSION="no"
export ON_VERSION="off"
export DO_VERBOSE="no"
export ON_VERBOSE="off"
export DO_JAVA="no"
export ON_JAVA="off"
export DO_FORTRAN="no"
export ON_FORTRAN="off"
export DO_SLIVR="no"
export ON_SLIVR="off"
export DO_PARADIS="no"
export ON_PARADIS="off"
export PREVENT_ICET="no"
GRAPHICAL="no"
ON_GRAPHICAL="off"
verify="no"
ON_verify="off"
export DO_OPTIONAL="yes"
export ON_OPTIONAL="on"
export DO_OPTIONAL2="no"
export ON_OPTIONAL2="off"
export DO_MORE="no"
export ON_MORE="off"
export DO_DBIO_ONLY="no"
export DO_ENGINE_ONLY="no"
export DO_SERVER_COMPONENTS_ONLY="no"
export DO_STATIC_BUILD="no"
export DO_THREAD_BUILD="no"
export USE_VISIBILITY_HIDDEN="no"
export VISIT_INSTALL_PREFIX=""
export VISIT_BUILD_MODE="Release"
export VISIT_SELECTED_DATABASE_PLUGINS=""
export DO_XDB="no"
DOWNLOAD_ONLY="no"


if [[ "$CXX_COMPILER" == "g++" ]] ; then
    VERSION=$(g++ -v 2>&1 | grep "gcc version" | cut -d' ' -f3 | cut -d'.' -f1-1)
    if [[ ${VERSION} -ge 4 ]] ; then
        export USE_VISIBILITY_HIDDEN="yes"
    fi
fi


export SVN_ANON_ROOT_PATH="http://visit.ilight.com/svn/visit"
# Setup svn path: use SVN_NERSC_NAME if set
if test -z "$SVN_NERSC_NAME" ; then
    export SVN_REPO_ROOT_PATH="svn+ssh://portal-auth.nersc.gov/project/projectdirs/visit/svn/visit"
else
    export SVN_REPO_ROOT_PATH="svn+ssh://$SVN_NERSC_NAME@portal-auth.nersc.gov/project/projectdirs/visit/svn/visit"
fi




if [[ "$OPSYS" != "Darwin" ]]; then
    WGET_MINOR_VERSION=$(wget --version| head -n 1|cut -d. -f 2)
    # version 1.7 pre-dates ssl integration
    if [[ "${WGET_MINOR_VERSION}" == "8" ]] ; then
       export WGET_OPTS=${WGET_OPTS=""}
    elif [[ "${WGET_MINOR_VERSION}" == "9" ]] ; then
       export WGET_OPTS=${WGET_OPTS:="--sslcheckcert=0"}
    else
       export WGET_OPTS=${WGET_OPTS:-"--no-check-certificate"}
    fi
fi


#get visit information..
bv_visit_info

#
# TARBALL LOCATIONS AND VERSIONS
#
if [[ "$VISIT_FILE" != "" ]] ; then
  USE_VISIT_FILE="yes"
  ON_USE_VISIT_FILE="on"
fi
export VISIT_FILE=${VISIT_FILE:-"visit${VISIT_VERSION}.tar.gz"}

for (( bv_i=0; bv_i<${#reqlibs[*]}; ++bv_i ))
do
    initializeFunc="bv_${reqlibs[$bv_i]}_info"
    $initializeFunc
done

for (( bv_i=0; bv_i<${#optlibs[*]}; ++bv_i ))
do
    initializeFunc="bv_${optlibs[$bv_i]}_info"
    $initializeFunc
done


# Dialog-related variables.
DLG="dialog"
DLG_BACKTITLE="VisIt $VISIT_VERSION Build Process"
DLG_HEIGHT="5"
DLG_HEIGHT_TALL="25"
DLG_WIDTH="60"
DLG_WIDTH_WIDE="80"
WRITE_UNIFIED_FILE=""
VISIT_INSTALLATION_BUILD_DIR=""
VISIT_DRY_RUN=0
DO_SUPER_BUILD="no"
DO_MANGLED_LIBRARIES="no"
}




# *************************************************************************** #
# Function: starts_with_quote                                                 #
#                                                                             #
# Purpose: Meant to be used in `if $(starts_with_quote "$var") ; then`        #
#          conditionals.                                                      #
#                                                                             #
# Programmer: Tom Fogal                                                       #
# Date: Thu Oct  9 15:24:04 MDT 2008                                          #
#                                                                             #
# *************************************************************************** #

function starts_with_quote
{
    if test "${1:0:1}" = "\""; then #"
        return 0
    fi
    if test "${1:0:1}" = "'" ; then
        return 0
    fi
    return 1
}

# *************************************************************************** #
# Function: ends_with_quote                                                   #
#                                                                             #
# Purpose: Meant to be used `if $(ends_with_quote "$var") ; then`             #
#          conditionals.                                                      #
#                                                                             #
# Programmer: Tom Fogal                                                       #
# Date: Thu Oct  9 15:24:13 MDT 2008                                          #
#                                                                             #
# *************************************************************************** #

function ends_with_quote
{
    if test "${1: -1:1}" = "\""; then #"
        return 0
    fi
    if test "${1: -1:1}" = "'"; then
        return 0
    fi
    return 1
}

# *************************************************************************** #
# Function: strip_quotes                                                      #
#                                                                             #
# Purpose: Removes all quotes from the given argument.  Meant to be used in   #
#          $(strip_quotes "$some_string") expressions.                        #
#                                                                             #
# Programmer: Tom Fogal                                                       #
# Date: Thu Oct  9 16:04:25 MDT 2008                                          #
#                                                                             #
# *************************************************************************** #

function strip_quotes
{
    local arg="$@"
    str=""
    while test -n "$arg" ; do
        if test "${arg:0:1}" != "\"" ; then
            str="${str}${arg:0:1}"
        fi
        arg="${arg:1}"
    done
    echo "${str}"
}

function bv_enable_group
{
    local name=${1/--}
    local match=0

    for (( bv_i=0; bv_i < ${#grouplibs_name[*]}; ++bv_i ))
    do
        #replace | with space
        group_flag=${grouplibs_name[$bv_i]}
        group_flag=${group_flag//\|/ }
        for group in `echo $group_flag`;
        do
            if [[ "$group" == "$name" ]]; then
                echo "executing group $name"
                match=1
                for group_dep in `echo ${grouplibs_deps[$bv_i]}`;
                do
                    if [[ "$group_dep" == no-* ]]; then
                        group_dep=${group_dep/no-}
                        #info "disabling $group_dep"
                        initializeFunc="bv_${group_dep}_disable"
                        $initializeFunc
                    else
                        #info "enabling $group_dep"
                        initializeFunc="bv_${group_dep}_enable"
                        $initializeFunc
                    fi
                done
            fi
        done
    done

    return $match
}

function enable_dependent_libraries
{
    local depends_on=""

    for (( bv_i=0; bv_i<${#reqlibs[*]}; ++bv_i ))
    do
        $"bv_${reqlibs[$bv_i]}_is_enabled"

        #if not enabled then skip
        if [[ $? == 0 ]]; then
            continue
        fi

        #enabled library, check dependencies..
        depends_on=$("bv_${reqlibs[$bv_i]}_depends_on")

        #replace commas with spaces if there are any..
        depends_on=${depends_on//,/ }

        for depend_lib in `echo $depends_on`;
        do
            $"bv_${depend_lib}_is_enabled"
            if [[ $? == 0 ]]; then
                error "ERROR: library ${depend_lib} was not set ${reqlibs[$bv_i]} depends on it, please enable"
                #echo "library ${depend_lib} was not set but another library depends on it, enabling it"
                #$"bv_${depend_lib}_enable"
            fi
        done
    done

    for (( bv_i=0; bv_i<${#optlibs[*]}; ++bv_i ))
    do
        $"bv_${optlibs[$bv_i]}_is_enabled"

        #if not enabled then skip
        if [[ $? == 0 ]]; then
            continue
        fi

        #enabled library, check dependencies..
        depends_on=$("bv_${optlibs[$bv_i]}_depends_on")

        #replace commas with spaces if there are any..
        depends_on=${depends_on//,/ }

        for depend_lib in `echo $depends_on`;
        do
            $"bv_${depend_lib}_is_enabled"
            if [[ $? == 0 ]]; then
                error "ERROR: library ${depend_lib} was not set ${optlibs[$bv_i]} depends on it, please enable"
                echo "library ${depend_lib} was not set but another library depends on it, enabling it"
                $"bv_${depend_lib}_enable"
            fi
        done
    done
}

#TODO: enable this feature and remove this from ensure..
function initialize_module_variables
{
    info "initializing module variables"
    for (( bv_i=0; bv_i<${#reqlibs[*]}; ++bv_i ))
    do
        $"bv_${reqlibs[$bv_i]}_is_enabled"

        #if not enabled then skip
        if [[ $? == 0 ]]; then
            continue
        fi

        declare -F "bv_${reqlibs[$bv_i]}_initialize_vars" &>/dev/null

        if [[ $? == 0 ]]; then
            info "initialize module variables for ${reqlibs[$bv_i]}"
            $"bv_${reqlibs[$bv_i]}_initialize_vars"
        fi
    done

    for (( bv_i=0; bv_i<${#optlibs[*]}; ++bv_i ))
    do
        $"bv_${optlibs[$bv_i]}_is_enabled"

        #if not enabled then skip
        if [[ $? == 0 ]]; then
            continue
        fi

        declare -F "bv_${optlibs[$bv_i]}_initialize_vars" &>/dev/null

        if [[ $? == 0 ]]; then
            info "initialize module variables for ${optlibs[$bv_i]}"
            $"bv_${optlibs[$bv_i]}_initialize_vars"
        fi
    done
}


function build_library
{
    local build_lib=$1
    local depends_on=""

    #check if library is already installed..
    $"bv_${build_lib}_is_installed"

    if [[ $? == 1 ]]; then
        info "$build_lib is already installed, skipping"
        return
    fi

    #Make sure that the recursive enable feature is working properly
    $"bv_${build_lib}_is_enabled"

    if [[ $? == 0 ]]; then
        error "$build_lib was disabled, but seems that another library requires it "
    fi

    depends_on=$("bv_${build_lib}_depends_on")

    if [[ $depends_on != "" ]]; then
        info "library $build_lib depends on $depends_on"
    fi

    #replace commas with spaces if there are any..
    depends_on=${depends_on//,/ }

    for depend_lib in `echo $depends_on`;
    do
        build_library $depend_lib
    done

    #build ..
    $"bv_${build_lib}_build"
}

function build_libraries_serial
{
    info "building required libraries"
    for (( bv_i=0; bv_i<${#reqlibs[*]}; ++bv_i ))
    do
        $"bv_${reqlibs[$bv_i]}_is_enabled"

        if [[ $? == 0 ]]; then
            continue
        fi

        $"bv_${reqlibs[$bv_i]}_is_installed"

        if [[ $? == 0 ]]; then
            cd "$START_DIR"
            build_library ${reqlibs[$bv_i]}
        else
            info "${reqlibs[$bv_i]} already installed, skipping"
        fi
    done

    info "building optional libraries"
    for (( bv_i=0; bv_i<${#optlibs[*]}; ++bv_i ))
    do
        $"bv_${optlibs[$bv_i]}_is_enabled"

        if [[ $? == 0 ]]; then
            continue
        fi

        $"bv_${optlibs[$bv_i]}_is_installed"

        if [[ $? == 0 ]]; then
            cd "$START_DIR"
            build_library ${optlibs[$bv_i]}
        else
            info "${optlibs[$bv_i]} already installed, skipping"
        fi
    done
}

function build_libraries_parallel
{
    #launch all non dependent libraries in parallel..
    info "building parallel required libraries"
    for (( bv_i=0; bv_i<${#reqlibs[*]}; ++bv_i ))
    do
        $"bv_${reqlibs[$bv_i]}_is_enabled"

        if [[ $? == 0 ]]; then
            continue
        fi

        $"bv_${reqlibs[$bv_i]}_is_installed"
        if [[ $? == 0 ]]; then

            depends_on=$("bv_${reqlibs[$bv_i]}_depends_on")
            if [[ "$depends_on" == "" ]]; then
                (cd "$START_DIR" && build_library ${reqlibs[$bv_i]}) &
            fi
        else
            info "${reqlibs[$bv_i]} already installed, skipping"
        fi
    done

    wait

    #load the serial ones..
    for (( bv_i=0; bv_i<${#reqlibs[*]}; ++bv_i ))
    do
        $"bv_${reqlibs[$bv_i]}_is_enabled"

        if [[ $? == 0 ]]; then
            continue
        fi

        $"bv_${reqlibs[$bv_i]}_is_installed"

        if [[ $? == 0 ]]; then
            cd "$START_DIR"
            build_library ${reqlibs[$bv_i]}
        else
            info "${reqlibs[$bv_i]} already installed, skipping"
        fi
    done

    info "building parallel optional libraries"
    for (( bv_i=0; bv_i<${#optlibs[*]}; ++bv_i ))
    do
        $"bv_${optlibs[$bv_i]}_is_enabled"

        if [[ $? == 0 ]]; then
            continue
        fi
        $"bv_${optlibs[$bv_i]}_is_installed"
        if [[ $? == 0 ]]; then

            depends_on=$("bv_${optlibs[$bv_i]}_depends_on")
            if [[ "$depends_on" == "" ]]; then
                (cd "$START_DIR" && build_library ${optlibs[$bv_i]}) &
            fi
        else
            info "${optlibs[$bv_i]} already installed, skipping"
        fi
    done

    wait

    #load serial
    for (( bv_i=0; bv_i<${#optlibs[*]}; ++bv_i ))
    do
        $"bv_${optlibs[$bv_i]}_is_enabled"

        if [[ $? == 0 ]]; then
            continue
        fi

        $"bv_${optlibs[$bv_i]}_is_installed"

        if [[ $? == 0 ]]; then
            cd "$START_DIR"
            build_library ${optlibs[$bv_i]}
        else
            info "${optlibs[$bv_i]} already installed, skipping"
        fi
    done

}

# *************************************************************************** #
#                       Section 2, building VisIt                             #
# --------------------------------------------------------------------------- #
# This section does some set up for building VisIt, and then calls the        #
# functions to build the third party libraries and VisIt itself.              #
# *************************************************************************** #
function run_build_visit()
{
declare -a arguments

# Will be set if the next argument is an argument to an argument (I swear that
# makes sense).  Make sure to unset it after pulling the argument!
next_arg=""
# If the user gives any deprecated options, we'll append command line options
# we think they should use here.
deprecated=""
# A few options require us to perform some action before we start building
# things, but we'd like to finish option parsing first.  We'll set this
# variable in those cases, and test it when we finish parsing.
next_action=""

#handle groups first since they affect multiple libraries..
for arg in "$@" ;
do
    bv_enable_group "$arg"
    #not part of a group, add to argument list..
    if [[ $? == 0 ]]; then
        local match=0

        #suppress licenses from argument list
        for license in `echo $defaultLicenses`
        do
            if [[ "${arg/--}" == "$license" ]]; then
                match=1
                break
            fi
        done

        #suppress licenses as well..
        if [[ $match == 0 ]]; then
            arguments[${#arguments[*]}]="$arg"
        fi
    fi
done

for arg in "${arguments[@]}" ; do

    # Was the last option something that took an argument?
    if test -n "$next_arg" ; then
        # Yep.  Which option was it?
        case $next_arg in
            extra_commandline_arg) $EXTRA_COMMANDLINE_ARG_CALL "$arg";;
            visit-build-hostname) EXTERNAL_HOSTNAME="$arg";;
            installation-build-dir) VISIT_INSTALLATION_BUILD_DIR="$arg";;
            write-unified-file) WRITE_UNIFIED_FILE="$arg";;
            append-cflags) C_OPT_FLAGS="${C_OPT_FLAGS} ${arg}";;
            append-cxxflags) CXX_OPT_FLAGS="${CXX_OPT_FLAGS} ${arg}";;
            arch) VISITARCH="${arg}";;
            build-mode) VISIT_BUILD_MODE="${arg}";;
            cflags) C_OPT_FLAGS="${arg}";;
            cxxflags) CXX_OPT_FLAGS="${arg}";;
            cc) C_COMPILER="${arg}";;
            cxx) CXX_COMPILER="${arg}";;
            database-plugins) VISIT_SELECTED_DATABASE_PLUGINS="${arg}";;
            log-file) LOG_FILE="${arg}";;
            makeflags) MAKE_OPT_FLAGS="${arg}";;
            prefix) VISIT_INSTALL_PREFIX="${arg}";;
            group) GROUP="${arg}";;
            svn) SVNREVISION="${arg}";;
            tarball) VISIT_FILE="${arg}";;
            thirdparty-path) THIRD_PARTY_PATH="${arg}";;
            version) VISIT_VERSION="${arg}"
                     VISIT_FILE="visit${VISIT_VERSION}.tar.gz";;
            *) error "Unknown next_arg value '$next_arg'!"
        esac
        # Make sure we process the next option as an option and not an
        # argument to an option.
        next_arg=""
        continue
    fi

    if [[ ${#arg} -gt 2 ]] ; then #has --

        #one module at a time
        resolve_arg=${arg:2} #remove --
        declare -F "bv_${resolve_arg}_enable" &>/dev/null

        if [[ $? == 0 ]] ; then
            #echo "enabling ${resolve_arg}"
            initializeFunc="bv_${resolve_arg}_enable"
            #argument is being explicitly set by the user so add a "force" flag
            $initializeFunc force
            continue
        elif [[ ${#resolve_arg} -gt 3 ]] ; then #in case it is --no-
            resolve_arg_no_opt=${resolve_arg:3}
            #disable library if it does not exist..
            declare -F "bv_${resolve_arg_no_opt}_disable" &>/dev/null
            if [[ $? == 0 ]] ; then
                #echo "disabling ${resolve_arg_no_opt}"
                initializeFunc="bv_${resolve_arg_no_opt}_disable"
                $initializeFunc
                #if disabling icet, prevent it as well
                if [[ ${resolve_arg_no_opt} == "icet" ]]; then
                    echo "preventing icet from starting"
                    PREVENT_ICET="yes"
                fi
                continue
           fi
        fi

        #command line arguments created by modules
        #checking to see if additional command line arguments were requested
        resolve_arg=${arg:2} #remove --
        local match=0
        for (( bv_i=0; bv_i<${#extra_commandline_args[*]}; bv_i += 5 ))
        do
            local module_name=${extra_commandline_args[$bv_i]}
            local command=${extra_commandline_args[$bv_i+1]}
            local args=${extra_commandline_args[$bv_i+2]}
            local comment=${extra_commandline_args[$bv_i+3]}
            local fp=${extra_commandline_args[$bv_i+4]}
            if [[ "$command" == "$resolve_arg" ]]; then
                if [ $args -eq 0 ] ; then
                  #call function immediately
                  $fp
                else
                  #call function with next argument
                  next_arg="extra_commandline_arg"
                  EXTRA_COMMANDLINE_ARG_CALL="$fp"
                fi
                match=1
                break;
            fi
        done

        #found a match in the modules..
        if [[ $match -eq 1 ]]; then
           continue
        fi
    fi


    case $arg in
        --visit-build-hostname) next_arg="visit-build-hostname";;
        --installation-build-dir) next_arg="installation-build-dir";;
        --write-unified-file) next_arg="write-unified-file";;
        --parallel-build) DO_SUPER_BUILD="yes";;
        --dry-run) VISIT_DRY_RUN=1;;
        --arch) next_arg="arch";;
        --build-mode) next_arg="build-mode";;
        --cflag) next_arg="append-cflags";;
        --cflags) next_arg="cflags";;
        --cxxflag) next_arg="append-cxxflags";;
        --cxxflags) next_arg="cxxflags";;
        --cc) next_arg="cc";;
        --cxx) next_arg="cxx";;
        --log-file) next_arg="log-file";;
        --console) GRAPHICAL="no"; ON_GRAPHICAL="off";;
        --gui) GRAPHICAL="yes"; ON_GRAPHICAL="on";;
        --database-plugins) next_arg="database-plugins";;
        --debug) C_OPT_FLAGS="${C_OPT_FLAGS} -g"; CXX_OPT_FLAGS="${CXX_OPT_FLAGS} -g"; VISIT_BUILD_MODE="Debug";;
        --bv-debug) set -vx;;
        --download-only) DOWNLOAD_ONLY="yes";;
        --engine-only) DO_ENGINE_ONLY="yes";;
        --flags-debug) C_OPT_FLAGS="${C_OPT_FLAGS} -g"; CXX_OPT_FLAGS="${CXX_OPT_FLAGS} -g"; VISIT_BUILD_MODE="Debug";;
        --gdal) DO_GDAL="yes"; ON_GDAL="on";;
        --fortran) DO_FORTRAN="yes"; ON_FORTRAN="on";;
        --group) next_arg="group"; DO_GROUP="yes"; ON_GROUP="on";;
        -h|--help) next_action="help";;
        --java) DO_JAVA="yes"; ON_JAVA="on";;
        --makeflags) next_arg="makeflags";;
        --no-hostconf) DO_HOSTCONF="no"; ON_HOSTCONF="off";;
        --no-boost) DO_BOOST="no"; ON_BOOST="off";;
        --parallel) parallel="yes"; DO_ICET="yes"; ON_ICET="on"; ON_parallel="on";;
        --prefix) next_arg="prefix";;
        --print-vars) next_action="print-vars";;
        --server-components-only) DO_SERVER_COMPONENTS_ONLY="yes";;
        --slivr) DO_SLIVR="yes"; ON_SLIVR="on";;
        --paradis) DO_PARADIS="yes"; ON_PARADIS="on";;
        --static) DO_STATIC_BUILD="yes"
                  export USE_VISIBILITY_HIDDEN="no"
                  CXXFLAGS=$(echo $CXXFLAGS | sed "s/-fPIC//g")
                  CFLAGS=$(echo $CFLAGS | sed "s/-fPIC//g")
                  ;;
        --thread) DO_THREAD_BUILD="yes";;
        --stdout) LOG_FILE="/dev/tty";;
        --svn) DO_SVN="yes"; export SVN_ROOT_PATH=$SVN_REPO_ROOT_PATH;;
        --svn-anon) DO_SVN="yes"; DO_SVN_ANON="yes" ; export SVN_ROOT_PATH=$SVN_ANON_ROOT_PATH ;;
        --svn-anonymous) DO_SVN="yes"; DO_SVN_ANON="yes" ; export SVN_ROOT_PATH=$SVN_ANON_ROOT_PATH ;;
        --svn-revision) next_arg="svn"; DO_SVN="yes"; DO_REVISION="yes"; DO_SVN_ANON="yes" ; export SVN_ROOT_PATH=$SVN_ANON_ROOT_PATH ;;
        --tarball) next_arg="tarball"
                   USE_VISIT_FILE="yes"
                   ON_USE_VISIT_FILE="on";;
        --thirdparty-path) next_arg="thirdparty-path"
                           ON_THIRD_PARTY_PATH="on";;
        --version) next_arg="version";;
        --xdb) DO_XDB="yes";;
        -4) deprecated="${deprecated} --hdf4";;
        -5) deprecated="${deprecated} --hdf5";;
        -c) deprecated="${deprecated} --cgns";;
        -C) deprecated="${deprecated} --ccmio";;
        -d) deprecated="${deprecated} --cflags '$C_OPT_FLAGS -g'";;
        -D) deprecated="${deprecated} --cflags '$C_OPT_FLAGS -g#'";;
        -E) deprecated="${deprecated} --print-vars";;
        -e) deprecated="${deprecated} --exodus";;
        -H) deprecated="${deprecated} --help";;
        -i) deprecated="${deprecated} --absolute";;
        -J) deprecated="${deprecated} --makeflags '-j <something>'";;
        -j) deprecated="${deprecated} --no-visit";;
        -m) deprecated="${deprecated} --mili";;
        -M) deprecated="${deprecated} --tcmalloc";;
        -r) deprecated="${deprecated} --h5part";;
        -R) deprecated="${deprecated} --svn <REVISION>";;
        -s) deprecated="${deprecated} --svn HEAD";;
        -S) deprecated="${deprecated} --slivr";;
        -t) deprecated="${deprecated} --tarball '<file>'";;
        -v) deprecated="${deprecated} --tarball 'visit<version>.tar.gz'";;
        -b|-B) deprecated="${deprecated} --boxlib";;
        -f|-F) deprecated="${deprecated} --cfitsio";;
        -g|-G) deprecated="${deprecated} --gdal";;
        -k|-K) deprecated="${deprecated} --no-thirdparty";;
        -l|-L) deprecated="${deprecated} --group '<arg>'";;
        -n|-N) deprecated="${deprecated} --netcdf";;
        -o|-O) deprecated="${deprecated} --stdout";;
        -p|-P) deprecated="${deprecated} --parallel";;
        -u|-U) deprecated="${deprecated} --thirdparty-path <path>";;
        -w|-W) deprecated="${deprecated} --python";;
        -y|-Y) deprecated="${deprecated} --java";;
        -z|-Z) deprecated="${deprecated} --console";;
        *)
            echo "Unrecognized option '${arg}'."
            ANY_ERRORS="yes";;
    esac
done

#error check to make sure that next arg is not left blank..
if [[ $next_arg != "" ]] ; then
    echo "command line arguments are used incorrectly: argument $next_arg not fullfilled"
    exit 1
fi

if [[ "$ANY_ERRORS" == "yes" ]] ; then
    echo "command line arguments are used incorrectly. unrecognized options..."
    exit 1
fi

if test -n "${deprecated}" ; then
    summary="You are using some deprecated options to $0.  Please re-run"
    summary="${summary} $0 with a command line similar to:"
    echo "$summary"
    echo ""
    echo "$0 ${deprecated}"
    exit 1
fi

if test -n "${next_action}" ; then
    case ${next_action} in
        print-vars) printvariables; exit 2;;
        help) usage; exit 2;;
    esac
fi

#
# Echo the current invocation command line to the log file
#
info "[build_visit invocation arguments] $@"


#
# Write a unified file
#
if [[ $WRITE_UNIFIED_FILE != "" ]] ; then
    bv_write_unified_file $WRITE_UNIFIED_FILE
    exit 0
fi

#
# If we doing a trunk build then make sure we are using SVN
#
if [[ "$TRUNK_BUILD" == "yes" ]]; then
    if [[ "$DO_SVN" == "no" ]]; then
        DO_SVN="yes"
        DO_SVN_ANON="yes"
        export SVN_ROOT_PATH=$SVN_ANON_ROOT_PATH
    fi
fi

#
# If we are AIX, make sure we are using GNU tar.
#
if [[ "$OPSYS" == "AIX" ]]; then
    TARVERSION=$($TAR --version >/dev/null 2>&1)
    if [[ $? != 0 ]] ; then
        echo "Error in build process. You are using the system tar on AIX."
        echo "Change the TAR variable in the script to the location of the"
        echo "GNU tar command."
        exit 1
    fi
fi

# Disable fortran support unless --fortran specified and a fortran compiler
# was specified or found.
if [[ $DO_FORTRAN == "no" || $FC_COMPILER == "" ]]; then
    export FC_COMPILER="no";
    warn "Fortran support for thirdparty libraries disabled."
fi

# Show a splashscreen. This routine also determines if we have "dialog"
# or "whiptail", which we use to show dialogs. If we do not have either
# then proceed in non-graphical mode.
#

if [[ "$GRAPHICAL" == "yes" ]] ; then
    DLG=$(which dialog)

    # Guard against bad "which" implementations that return
    # "no <exe> in path1 path2 ..." (these implementations also
    # return 0 as the exit status).
    if [[ "${DLG#no }" != "${DLG}" ]] ; then
        DLG=""
    fi
    if [[ "$DLG" == "" ]] ; then
        warn "Could not find 'dialog'; looking for 'whiptail'."
        DLG=$(which whiptail)
        if [[ "${DLG#no }" != "${DLG}" ]] ; then
           DLG=""
        fi
        if [[ "$DLG" == "" ]] ; then
            GRAPHICAL="no"
            warn "'whiptail' not found."
            warn ""
            warn "Unable to find utility for graphical build..."
            warn "Continuing in command line mode..."
            warn ""
            test -t 1
            if test $? != 1 ; then
              warn "Please hit enter to continue."
              (read junkvar)
            fi
        else
            warn "Some versions of 'whiptail' fail to display anything with --infobox."
            warn "Continuing in command line mode..."
        fi
    fi
fi
if [[ "$GRAPHICAL" == "yes" ]] ; then
    result=$($DLG --backtitle "$DLG_BACKTITLE" \
    --title "Build options" \
    --checklist \
"Welcome to the VisIt $VISIT_VERSION build process.\n\n"\
"This program will build VisIt and its required "\
"3rd party sources, downloading any missing source packages "\
"before building. The required and optional 3rd party libraries "\
"are built and installed before VisIt is built, so please be patient. "\
"Note that you can build a parallel version of VisIt by "\
"specifying the location of your MPI installation when prompted.\n\n"\
"Select the build options:" 0 0 0 \
           "Groups"    "select 3rd party and advanced build"  $ON_OPTIONAL\
           "Custom"    "select custom flags provided by each module"  $ON_OPTIONAL2\
           "SVN"        "get sources from SVN server"     $ON_SVN\
           "Tarball"    "specify VisIt tarball name"      $ON_USE_VISIT_FILE\
           "Parallel"   "specify parallel build flags"    $ON_parallel\
           "Java"       "enable java client library"      $ON_JAVA\
           "Fortran"    "enable fortran in third party libraries"  $ON_FORTRAN\
           "SLIVR"      "enable SLIVR volume rendering library"  $ON_SLIVR\
           "Paradis"    "enable paraDIS client library"   $ON_PARADIS\
           "EnvVars"    "specify build environment var values"   $ON_verify\
           "Advanced"   "display advanced options"        $ON_MORE  3>&1 1>&2 2>&3)
    retval=$?

    # Remove the extra quoting, new dialog has --single-quoted
    choice="$(echo $result | sed 's/\"//g' )"

    case $retval in
      0)
        DO_OPTIONAL="no"
        DO_OPTIONAL2="no"
        DO_SVN="no"
        USE_VISIT_FILE="no"
        parallel="no"
        DO_JAVA="no"
        DO_FORTRAN="no"
        DO_SLIVR="no"
        DO_PARADIS="no"
        verify="no"
        DO_MORE="no"
        for OPTION in $choice
        do
            case $OPTION in
              Groups)
                 DO_OPTIONAL="yes";;
              Custom)
                 DO_OPTIONAL2="yes";;
              SVN)
                 DO_SVN="yes";DO_SVN_ANON="yes";export SVN_ROOT_PATH=$SVN_ANON_ROOT_PATH ;;
              Tarball)
                 result=$($DLG --backtitle "$DLG_BACKTITLE" \
                    --nocancel --inputbox \
"Enter $OPTION value:" 0 $DLG_WIDTH_WIDE "$VISIT_FILE" 3>&1 1>&2 2>&3)
                 VISIT_FILE="$(echo $result)"
                 USE_VISIT_FILE="yes";;
              Parallel)
                 parallel="yes"; DO_ICET="yes"; ON_ICET="on";;
              Java)
                 DO_JAVA="yes";;
              Fortran)
                 DO_FORTRAN="yes";;
              SLIVR)
                 DO_SLIVR="yes";;
              Paradis)
                 DO_PARADIS="yes";;
              EnvVars)
                 verify="yes";;
              Advanced)
                 DO_MORE="yes";;
            esac
        done
        ;;
      1)
        warn "Cancel pressed."
        exit 1;;
      255)
        warn "ESC pressed.";;
      *)
        warn "Unexpected return code: $retval";;
    esac
fi

if [[ "$DO_OPTIONAL" == "yes" && "$GRAPHICAL" == "yes" ]] ; then

    local add_checklist_vars=""

    for (( bv_i=0; bv_i < ${#grouplibs_name[*]}; ++bv_i ))
    do
        name="${grouplibs_name[$bv_i]}"
        comment="${grouplibs_comment[$bv_i]}"
        output_str="$name \"$comment\" 0 \"  Customize($name)\" \"Customize selection of $name\" 0"
        add_checklist_vars="$add_checklist_vars ${output_str}"
    done

    #calling whiptail directly is having issues delimiting by space , so hacking around it
    result=$(echo "$DLG --backtitle \"Group options\" --title \"Groups provided by build_visit\" --checklist \"select\" 0 0 0 $add_checklist_vars 3>&1 1>&2 2>&3 || echo \"Cancelled Operation\"" | awk '{system($0)}')

    if [[ $result == "Cancelled Operation" ]]; then
        warn "Operation was cancelled, exiting"
        exit 1
    fi

    # Remove the extra quoting, new dialog has --single-quoted
    choice="$(echo $result | sed 's/\"//g' )"
    for OPTION in $choice
    do
        #if customize operation
        if [[ "$OPTION" != Customize* ]]; then
            #execute the entire group..
            bv_enable_group "$OPTION"
            continue
        fi

        #allow modification of predefined groups
        add_checklist_vars=""

        for (( bv_i=0; bv_i < ${#grouplibs_name[*]}; ++bv_i ))
        do
            name="${grouplibs_name[$bv_i]}"
            #dialog and whiptail treat parantheses differently
            if [[ "Customize($name)" == "$OPTION" || "Customize\\($name\\)" == "$OPTION" ]]; then
                echo "Customizing $name"
                comment="${grouplibs_comment[$bv_i]}"

                for group_dep in `echo ${grouplibs_deps[$bv_i]}`
                do
                    output_str="${group_dep} \"Enable/Disable $group_dep library\" 1"
                    add_checklist_vars="$add_checklist_vars ${output_str}"
                done
                result=$(echo "$DLG --backtitle \"$comment\" \
                                    --title \"Custom options for $name\" \
                                    --checklist \"select\" 0 0 0 $add_checklist_vars \
                                    3>&1 1>&2 2>&3 || echo \"Cancelled Operation\"" \
                                    | awk '{system($0)}')

                if [[ $result == "Cancelled Operation" ]]; then
                    echo "Operation was cancelled"
                    exit 1
                fi
                choice_custom="$(echo $result | sed 's/\"//g' )"
                for OPTION_CUSTOM in $choice_custom
                do
                    #initialize all the ones
                    if [[ "$OPTION_CUSTOM" == no-* ]]; then
                        OPTION_CUSTOM=${OPTION_CUSTOM/no-}
                        #echo "disabling $OPTION_CUSTOM"
                        initializeFunc="bv_${OPTION_CUSTOM}_disable"
                        $initalizeFunc
                    else
                        #echo "enable $OPTION_CUSTOM"
                        initializeFunc="bv_${OPTION_CUSTOM}_enable"
                        $initializeFunc
                    fi
                done
            fi
        done
    done
fi

if [[ "$DO_OPTIONAL2" == "yes" && "$GRAPHICAL" == "yes" ]] ; then

    local needsRerun=1

    while [[ $needsRerun == 1 ]];
    do
        needsRerun=0
        local add_checklist_vars=""
        for (( bv_i=0; bv_i<${#extra_commandline_args[*]}; bv_i += 5 ))
        do
            local module_name=${extra_commandline_args[$bv_i]}
            local command=${extra_commandline_args[$bv_i+1]}
            #local args=${extra_commandline_args[$bv_i+2]}
            local comment=${extra_commandline_args[$bv_i+3]}
            output_str="\"$command\" \"$comment ($module_name)\" 0"
            add_checklist_vars="$add_checklist_vars ${output_str}"
        done

        #calling whiptail directly is having issues delimiting by space , so hacking around it
        result=$(echo "$DLG --backtitle \"Custom options\" --title \"d by build_visit\" --checklist \"select\" 0 0 0 $add_checklist_vars 3>&1 1>&2 2>&3 || echo \"Cancelled Operation\"" | awk '{system($0)}')

        if [[ $result == "Cancelled Operation" ]]; then
            warn "Operation was cancelled, skipping"
            break
        fi

        # Remove the extra quoting, new dialog has --single-quoted
        choice="$(echo $result | sed 's/\"//g' )"
        for OPTION in $choice
        do
            for (( bv_i=0; bv_i<${#extra_commandline_args[*]}; bv_i += 5 ))
            do
                local module_name=${extra_commandline_args[$bv_i]}
                local command=${extra_commandline_args[$bv_i+1]}
                local args=${extra_commandline_args[$bv_i+2]}
                local comment=${extra_commandline_args[$bv_i+3]}
                local fp=${extra_commandline_args[$bv_i+4]}
                if [[ "$command" == "$OPTION" ]]; then
                    if [[ $args -ne 0 ]]; then
                        result=$($DLG --backtitle "$DLG_BACKTITLE" \
                            --inputbox \
                            "Enter $OPTION value:" 0 $DLG_WIDTH_WIDE "" 3>&1 1>&2 2>&3)
                        retval=$?
                        if [[ $retval == 0 ]]; then
                            echo "executing $command"
                            $fp "$result"
                        else
                            needsRerun=1
                        fi
                    else
                        $fp
                    fi
                fi
            done
        done
    done
fi

# make all VisIt related builds in its own directory..
if [[ $VISIT_INSTALLATION_BUILD_DIR != "" ]] ; then
    if [[ -d $VISIT_INSTALLATION_BUILD_DIR ]]; then
        echo "Using already existing directory: $VISIT_INSTALLATION_BUILD_DIR"
    else
        mkdir -p $VISIT_INSTALLATION_BUILD_DIR
    fi

    if [[ ! -d $VISIT_INSTALLATION_BUILD_DIR ]]; then
        echo "Directory does not exist or I do not have permission to create it. Quitting"
        exit 0
    fi
    cd $VISIT_INSTALLATION_BUILD_DIR
fi

#
# See if the user needs to modify some variables
#
check_more_options
if [[ $? != 0 ]] ; then
   error "Stopping build because of bad variable option setting error."
fi

#
# Log build_visit invocation w/ arguments & the start time.
# Especially helpful if there are multiple starts dumped into the
# same log.
#
LINES="------------------------------------------------------------"
log $LINES
log $0 $@
log "Started:" $(date)
log $LINES

if [[ "$DO_SVN" == "yes" ]] ; then
    check_svn_client
    if [[ $? != 0 ]]; then
        error "Fatal Error: SVN mode selected, but svn client is not available."
    fi
fi

#enabling any dependent libraries, handles both dependers and dependees..
#TODO: handle them seperately
info "enabling any dependent libraries"
enable_dependent_libraries

## At this point we are after the command line and the visual selection
#dry run, don't execute anything just run the enabled stuff..
#happens before any downloads have taken place..
if [[ $VISIT_DRY_RUN -eq 1 ]]; then
    for (( bv_i=0; bv_i<${#reqlibs[*]}; ++bv_i ))
    do
        initializeFunc="bv_${reqlibs[$bv_i]}_dry_run"
        $initializeFunc
    done

    for (( bv_i=0; bv_i<${#optlibs[*]}; ++bv_i ))
    do
        initializeFunc="bv_${optlibs[$bv_i]}_dry_run"
        $initializeFunc
    done

    bv_visit_dry_run
    exit 0
fi

START_DIR="$PWD"

if [[ "$DOWNLOAD_ONLY" == "no" ]] ; then
   if [[ ! -d "$THIRD_PARTY_PATH" ]] ; then
      if [[ "$THIRD_PARTY_PATH" == "./visit" ]] ; then
         mkdir "$THIRD_PARTY_PATH"
         if [[ $? != 0 ]] ; then
            error "Unable to write files to the third party library location." \
                  "Bailing out."
         fi
      else
         if [[ "$GRAPHICAL" == "yes" ]] ; then
             if [[ "$REDIRECT_ACTIVE" == "yes" ]] ; then
                 $DLG --backtitle "$DLG_BACKTITLE" --yesno "The third party library location does not exist. Create it?" 0 0 1>&3
             else
                 $DLG --backtitle "$DLG_BACKTITLE" --yesno "The third party library location does not exist. Create it?" 0 0
             fi
             if [[ $? == 1 ]] ; then
                 error "The third party library location does not exist." \
                       "Bailing out."
             else
                 mkdir "$THIRD_PARTY_PATH"
                 if [[ $? != 0 ]] ; then
                    error "Unable to write files to the third party library location." \
                          "Bailing out."
                 fi
             fi
         else
             info "The third party library location does not exist. Create it?"
             read RESPONSE
             if [[ "$RESPONSE" != "yes" ]] ; then
                 error "The third party library location does not exist." \
                       "Bailing out."
             else
                 mkdir "$THIRD_PARTY_PATH"
                 if [[ $? != 0 ]] ; then
                    error "Unable to write files to the third party library location." \
                          "Bailing out."
                 fi
             fi
         fi
      fi
   fi

   cd "$THIRD_PARTY_PATH"
   if [[ $? != 0 ]] ; then
      error "Unable to access the third party location. Bailing out."
   fi
fi

if [[ $VISITARCH == "" ]] ; then
    export VISITARCH=${ARCH}_${C_COMPILER}
    if [[ "$CXX_COMPILER" == "g++" ]] ; then
       VERSION=$(g++ -v 2>&1 | grep "gcc version" | cut -d' ' -f3 | cut -d'.' -f1-2)
       if [[ ${#VERSION} == 3 ]] ; then
          VISITARCH=${VISITARCH}-${VERSION}
       fi
    fi
fi

export VISITDIR=${VISITDIR:-$(pwd)}
cd "$START_DIR"

#
# See if the user wants to build a parallel version.
#
check_parallel
if [[ $? != 0 ]] ; then
   error "Stopping build because necessary parallel options are not set."
fi

check_variables
if [[ $? != 0 ]] ; then
   error "Stopping build because of bad variable option setting error."
fi

if [[ "$DO_ICET" == "yes" && "$PREVENT_ICET" != "yes" ]] ; then
    DO_CMAKE="yes"
fi

#initialize module variables, since all of VisIt's variables should be set by now..
initialize_module_variables
#
# Later we will build Qt.  We are going to bypass their licensing agreement,
# so echo it here.
#
if [[ "$USE_SYSTEM_QT" != "yes" && "$DO_QT" == "yes" && "$DO_SERVER_COMPONENTS_ONLY" == "no" ]]; then
    BYPASS_QT_LICENSE="no"
    check_if_installed "qt" $QT_VERSION
    if [[ $? == 0 ]] ; then
        BYPASS_QT_LICENSE="yes"
    fi

    if [[ "$BYPASS_QT_LICENSE" == "no" && "$DOWNLOAD_ONLY" == "no" ]] ; then
        qt_license_prompt
        if [[ $? != 0 ]] ;then
            error "Qt4 Open Source Edition License Declined. Bailing out."
        fi
    fi
fi

#
# Save stdout as stream 3, redirect stdout and stderr to the log file.
# After this maks sure to use the info/warn/error functions to display
# messages to the user
#

if [[ "${LOG_FILE}" != "/dev/tty" ]] ; then
    exec 3>&1 >> ${LOG_FILE} 2>&1
    REDIRECT_ACTIVE="yes"
else
    exec 2>&1
fi

#
#
# Now make sure that we have everything we need to build VisIt, so we can bail
# out early if we are headed for failure.
#
check_files
if [[ $? != 0 ]] ; then
   error "Stopping build because necessary files aren't available."
fi

#
# Exit if we were told to only download the files.
#
if [[ "$DOWNLOAD_ONLY" == "yes" ]] ; then
    info "Successfully downloaded the specified files."
    exit 0
fi

if [[ $DO_MANGLED_LIBRARIES == "yes" ]]; then
    info "Mangling libraries while building"
    info "Any libraries that support mangling will do so"
fi

if [[ "$DO_SUPER_BUILD" == "yes" ]]; then
    build_libraries_parallel
else
    build_libraries_serial
fi

#
# Create the host.conf file
#

if [[ "$DO_HOSTCONF" == "yes" ]] ; then
    info "Creating host.conf"
    build_hostconf
fi

#build visit itself..
bv_visit_build
}
export LOG_FILE=${LOG_FILE:-"${0##*/}_log"}

# *************************************************************************** #
# Function: errorFunc                                                         #
#                                                                             #
# Purpose: Error messages                                                     #
#                                                                             #
# *************************************************************************** #
function errorFunc
{
  echo $1
  exit 0
}

# *************************************************************************** #
# Function: log                                                               #
#                                                                             #
# Purpose: Log message for the log.                                           #
#                                                                             #
# Programmer: Tom Fogal                                                       #
# Date: Fri Oct  3 09:37:51 MDT 2008                                          #
#                                                                             #
# *************************************************************************** #
function log
{
    echo "$@" >> ${LOG_FILE}
}


# *************************************************************************** #
# Function: warn                                                              #
#                                                                             #
# Purpose: Echo to screen and log.                                            #
#                                                                             #
# Programmer: Cyrus Harrison                                                  #
# Date: Tue Nov 18 15:09:47 PST 2008                                          #
#                                                                             #
# Modifications:                                                              #
#                                                                             #
#   Hank Childs, Fri Jan 28 10:32:06 PST 2011                                 #
#   Add -e to echo so tabs are printed.                                       #
#                                                                             #
# *************************************************************************** #
function warn
{
    if [[ "$REDIRECT_ACTIVE" == "yes" ]] ; then
        echo -e "$@" 1>&3
    else
        echo -e "$@"
    fi
    
    if [[ "${LOG_FILE}" != "/dev/tty" ]] ; then
        # write message to log as well
        log "$@"
    fi
}

# *************************************************************************** #
# Function: error                                                             #
#                                                                             #
# Purpose: Report an error message and exit.                                  #
#                                                                             #
# Programmer: Tom Fogal                                                       #
# Date: Fri Oct  3 09:37:51 MDT 2008                                          #
#                                                                             #
# Modifications:                                                              #
#    Jeremy Meredith, Fri Jul 22 10:36:20 EDT 2011                            #
#    Added a little more text to help users.                                  #
# *************************************************************************** #

function error
{
    warn "$@"
    if test "${LOG_FILE}" != "/dev/tty" ; then
        warn "Error in build process.  See ${LOG_FILE} for more information."\
             "If the error is unclear, please include ${LOG_FILE} in a "\
             "message to the visit-users@ornl.gov list.  You will probably "\
             "need to compress the ${LOG_FILE} using a program like gzip "\
             "so it will fit within the size limits for email attachments."
    fi
    exit 1
}

# *************************************************************************** #
# Function: issue_command                                                     #
#                                                                             #
# Purpose: Print a command and execute it too.                                #
#                                                                             #
# Programmer: Brad Whitlock,                                                  #
# Date: Tue Feb 28 17:04:43 PST 2012                                          #
#                                                                             #
# Modifications:                                                              #
#
# *************************************************************************** #

function issue_command
{
    echo "$@"
    "$@"
    return $?
}

# *************************************************************************** #
# Function: add_extra_commandline_args                                        #
#                                                                             #
# Purpose: Allows modules to add extra arguments to VisIt                     #
#                                                                             #
# Programmer: Hari Krishnan,                                                  #
# Date: Thu Dec 15 14:38:36 PST 2011                                          #
#                                                                             #
# Modifications:                                                              #
#   Eric Brugger, Wed Jan 18 08:17:48 PST 2012                                #
#   I re-enabled the code that replaces dashes with underscores in the        #
#   name of the enable function.                                              #
#                                                                             #
# *************************************************************************** #
#global argument list for extra args..
declare -a extra_commandline_args
export EXTRA_COMMANDLINE_ARG_CALL=""

function add_extra_commandline_args 
{

  if [[ $# != 4 ]]; then
   echo "extra command line usage requires 4 parameters"
   return
  fi

  #replace all occurrences of "-" with "_"
  local enable_func="bv_$1_${2//-/_}"

  #check if function exists..
  #maybe this should be moved to build_visit rather than here..
  #in case some bash consoles don't have declare -F capabilities?
  declare -F "$enable_func" &>/dev/null || errorFunc "function pointer $enable_func not found"

  #add parameters..
  for f in "$@"; do
    extra_commandline_args[${#extra_commandline_args[*]}]="$f"
  done

  #add function pointer..
  extra_commandline_args[${#extra_commandline_args[*]}]="$enable_func"
}


function verify_required_module_exists
{
    local reqlib=$1
    #check if required functions exist..
    declare -F "bv_${reqlib}_enable" &>/dev/null || errorFunc "${reqlib} enable not found"
    declare -F "bv_${reqlib}_disable" &>/dev/null || errorFunc "${reqlib} disable not found"
    declare -F "bv_${reqlib}_initialize" &>/dev/null || errorFunc "${reqlib} initialize not found"
    declare -F "bv_${reqlib}_info" &>/dev/null || errorFunc "${reqlib} info not found"
    declare -F "bv_${reqlib}_ensure" &>/dev/null || errorFunc "${reqlib} ensure not found"
    declare -F "bv_${reqlib}_build" &>/dev/null || errorFunc "${reqlib} build not found"
    declare -F "bv_${reqlib}_depends_on" &>/dev/null || errorFunc "${reqlib} depends_on not found"
    declare -F "bv_${reqlib}_print" &>/dev/null || errorFunc "${reqlib} print not found"
    declare -F "bv_${reqlib}_print_usage" &>/dev/null || errorFunc "${reqlib} print_usage not found"
    declare -F "bv_${reqlib}_dry_run" &>/dev/null || errorFunc "${reqlib} dry_run not found"
    declare -F "bv_${reqlib}_is_installed" &>/dev/null || errorFunc "${reqlib} is_installed not found"
    declare -F "bv_${reqlib}_is_enabled" &>/dev/null || errorFunc "${reqlib} is_enabled not found"
}


function verify_optional_module_exists
{
    local optlib=$1
    declare -F "bv_${optlib}_enable" &>/dev/null || errorFunc "${optlib} enable not found"
    declare -F "bv_${optlib}_disable" &>/dev/null || errorFunc "${optlib} disable not found"
    declare -F "bv_${optlib}_initialize" &>/dev/null || errorFunc "${optlib} info not found"
    declare -F "bv_${optlib}_info" &>/dev/null || errorFunc "${optlib} info not found"
    declare -F "bv_${optlib}_ensure" &>/dev/null || errorFunc "${optlib} ensure not found"
    declare -F "bv_${optlib}_build" &>/dev/null || errorFunc "${optlib} build not found"
    declare -F "bv_${optlib}_depends_on" &>/dev/null || errorFunc "${optlib} depends_on not found"
    declare -F "bv_${optlib}_print" &>/dev/null || errorFunc "${optlib} print not found"
    declare -F "bv_${optlib}_print_usage" &>/dev/null || errorFunc "${optlib} print_usage not found"
    declare -F "bv_${optlib}_host_profile" &>/dev/null || errorFunc "${optlib} host_profile not found"
    declare -F "bv_${optlib}_graphical" &>/dev/null || errorFunc "${optlib} graphical not found"
    declare -F "bv_${optlib}_dry_run" &>/dev/null || errorFunc "${optlib} dry_run not found"
    declare -F "bv_${optlib}_is_installed" &>/dev/null || errorFunc "${optlib} is_installed not found"
    declare -F "bv_${optlib}_is_enabled" &>/dev/null || errorFunc "${optlib} is_enabled not found"
}

# *************************************************************************** #
# Function: info_box                                                          #
#                                                                             #
# Purpose: Show an information box with a message.                            #
#                                                                             #
# Programmer: Brad Whitlock,                                                  #
# Date: Thu Apr 5 14:38:36 PST 2007                                           #
#                                                                             #
# *************************************************************************** #

function info_box
{
    if [[ "$GRAPHICAL" == "yes" ]] ; then
        $DLG --backtitle "$DLG_BACKTITLE" --infobox "$1" $DLG_HEIGHT $DLG_WIDTH
    fi
    return 0
}

# *************************************************************************** #
# Function: info                                                              #
#                                                                             #
# Purpose: Give an informative message to the user.                           #
#                                                                             #
# Programmer: Tom Fogal                                                       #
# Date: Fri Oct  3 09:41:50 MDT 2008                                          #
#                                                                             #
# *************************************************************************** #
function info
{
    if [[ "$REDIRECT_ACTIVE" == "yes" ]] ; then
        if test "${GRAPHICAL}" = "yes" ; then
            info_box "$@" 1>&3
        else
            echo "$@" 1>&3
        fi
    else
        if test "${GRAPHICAL}" = "yes" ; then
            info_box "$@"
        else
            echo "$@"
        fi
    fi

    if [[ "${LOG_FILE}" != "/dev/tty" ]] ; then
        # write message to log as well
        log "$@"
    fi
}

# *************************************************************************** #
# Function: info_box_large                                                    #
#                                                                             #
# Purpose: Show a large information box with a message.                       #
#                                                                             #
# Programmer: Eric Brugger,                                                   #
# Date: Thu Jul 21 08:25:52 PDT 2011                                          #
#                                                                             #
# *************************************************************************** #

function info_box_large
{
    if [[ "$REDIRECT_ACTIVE" == "yes" ]] ; then
        if [[ "$GRAPHICAL" == "yes" ]] ; then
            $DLG --backtitle "$DLG_BACKTITLE" --infobox "$1" $DLG_HEIGHT_TALL $DLG_WIDTH 1>&3
        fi
    else
        if [[ "$GRAPHICAL" == "yes" ]] ; then
            $DLG --backtitle "$DLG_BACKTITLE" --infobox "$1" $DLG_HEIGHT_TALL $DLG_WIDTH
        fi
    fi
    return 0
}

# *************************************************************************** #
# Function: uncompress_untar
#                                                                             #
# Purpose: Uncompress and untar the file, checking if GNU tar can be used.    #
#                                                                             #
# Programmer: Thomas R. Treadway                                              #
# Date: Tue May 15 16:48:01 PDT 2007                                          #
#                                                                             #
# *************************************************************************** #

function uncompress_untar
{
    # Check if GNU tar
    if [[ $(echo $1 | egrep "\.gz$" ) != "" ]] ; then
        COMPRESSTYPE="gzip"
    elif [[ $(echo $1 | egrep "\.bz2$" ) != "" ]] ; then
        COMPRESSTYPE="bzip"
    elif [[ $(echo $1 | egrep "\.tgz$" ) != "" ]] ; then
        COMPRESSTYPE="targzip"
    elif [[ $(echo $1 | egrep "\.tar.gz$" ) != "" ]] ; then
        COMPRESSTYPE="targzip"
    elif [[ $(echo $1 | egrep "\.zip$" ) != "" ]] ; then
        COMPRESSTYPE="zip"
    else
        warn "unsupported decompression method"
        return 1
    fi
    TARVERSION=$($TAR --version >/dev/null 2>&1)
    if [[ $? == 0 ]] ; then
        case $COMPRESSTYPE in
            gzip|targzip) $TAR zxf $1;;
            bzip) $TAR jxf $1;;
            zip) unzip $1;;
        esac
        
        if [[ $? != 0 ]]; then
            warn "error decompressing $1"
            return 1
        fi

    else
        case $COMPRESSTYPE in
            gzip) 
               gunzip $1
               $TAR xf ${1%.gz}
               ;;
            targzip) 
               gunzip $1
               $TAR xf "${1%.tgz}.tar"
               ;;
            bzip)
               bunzip2 $1
               $TAR xf ${1%.bz2}
               ;;
            zip)
               unzip $1
               ;;
        esac
        
        if [[ $? != 0 ]]; then
            warn "error decompressing $1"
            return 1
        fi
    fi
}

# *************************************************************************** #
# Function: verify_checksum                                                   #
#                                                                             #
# Purpose: Verify the checksum of given file                                  #
#                                                                             #
# verify_md5_checksum: checks md5                                             #
# verify_sha_checksum: checks sha (256,512)                                   #
# Programmer: Hari Krishnan                                                   #
# *************************************************************************** #

function verify_md5_checksum
{
    checksum=$1
    dfile=$2

    tmp=`which md5sum`
    if [[ $? != 0 ]]; then
        info "could not find md5sum, disabling check"
        return 0
    fi
    tmp=`md5sum $dfile | awk '{print $1}'`
    if [[ $tmp == ${checksum} ]]; then
        info "verified"
        return 0
    fi

    info "md5sum failed: looking for $checksum got $tmp"
    return 1
}

function verify_sha_checksum
{
    checksum_algo=$1
    checksum=$2
    dfile=$3

    tmp=`which shasum`
    if [[ $? != 0 ]]; then
        info "could not find shasum, disabling check"
        return 0
    fi

    tmp=`shasum -a $checksum_algo $dfile`
    if [[ $? == 0 ]]; then
        tmp=`echo $tmp| awk '{print $1}'`
        if [[ $tmp == $checksum ]]; then
            info "verified"
            return 0
        else
            info "shasum -a $checksum_algo failed: looking for $checksum got $tmp"
            return 1
        fi
    fi

    info "shasum does not support $checksum_algo, check disabled"
    return 0
}

function verify_checksum
{
    checksum_type=$1
    checksum=$2
    dfile=$3

    info "verifying type $checksum_type, checksum $checksum for $dfile . . ."

    if [[ "$checksum_type" == "MD5" ]]; then
        verify_md5_checksum $checksum $dfile
        return $?
    fi

    if [[ $checksum_type = "SHA256" ]]; then
        verify_sha_checksum 256 $checksum $dfile
        return $?
    fi

    if [[ $checksum_type = "SHA512" ]]; then
        verify_sha_checksum 512 $checksum $dfile
        return $?
    fi

    #since this is an optional check, all cases should pass if it gets here..
    info "checksum string not MD5, SHA256, or SHA512, check disabled"
    return 0
}


# *************************************************************************** #
# Function: download_file                                                     #
#                                                                             #
# Purpose: Downloads a file using wget and show a dialog screen.              #
#                                                                             #
# Programmer: Brad Whitlock,                                                  #
# Date: Thu Apr 5 14:38:36 PST 2007                                           #
#                                                                             #
# Modifications:                                                              #
#                                                                             #
#   Hank Childs, Mon Oct 15 15:55:22 PDT 2007                                 #
#   Fail gracefully if wget is not available.                                 #
#                                                                             #
#   Thomas R. Treadway, Tue Nov 27 16:37:21 PST 2007                          # 
#   Deal with LLNL's invalid certificates                                     #
#                                                                             #
#   Cyrus Harrison, Mon Nov 17 16:22:54 PST 2008                              # 
#   Check return value of svn cat or download for errors. Clean up a          #
#   partially downloaded file.                                                #
#                                                                             #
#   Hank Childs, Fri Dec 12 09:28:35 PST 2008                                 #
#   Add special logic for Ice-T.                                              #
#                                                                             #
#   Mark C. Miller, Thu Feb 19 09:16:46 PST 2009                              #
#   Added argument to specify a download_path. Removed special IceT coding.   #
#                                                                             #
#   Mark C. Miller, Thu Feb 19 12:21:55 PST 2009                              #
#   Changed to support multiple sites as well as default visit places.        #
#                                                                             #
#   Cyrus Harrison, Thu Feb 19 12:21:55 PST 2009                              #
#   Fixed problem where if a download path was given, svn mode was skipped    #
#                                                                             #
#   Cyrus Harrison, Thu Apr  9 19:21:13 PDT 2009                              #
#   Applied patch from Rick Wagner to fix curl downloads on OSX.              #
#                                                                             #
#   Mark C. Miller, Wed Feb  3 09:47:52 PST 2010                              #
#   Made it fall back to anon svn checkout                                    #
#                                                                             #
#   Eric Brugger, Mon Jan 10 16:00:13 PST 2011                                #
#   I made it always fall back to anonymous svn checkout.                     #
#                                                                             #
#   Eric Brugger, Tue Jul 19 10:19:50 PDT 2011                                #
#   I made it use the anonymous svn site as the fallback download site        #
#   instead of llnl's web site.                                               #
#                                                                             #
# *************************************************************************** #

function download_file
{
# $1 is the file name to download
# $2...$* [OPTIONAL] list of sites to obtain the file from
#
# Since we always pass optional download sites to this function for
# some third party libs - we can't skip svn mode just b/c this info is given.
#
    typeset dfile=$1
    info "Downloading $dfile . . ." 
    shift
    
    SVN_ROOT_PREFIX="${SVN_ROOT_PATH}/${SVN_THIRDPARTY_PATH}"
    SVN_ANON_ROOT_PREFIX="${SVN_ANON_ROOT_PATH}/${SVN_THIRDPARTY_PATH}"
    # If SVN is requested, try that first before anything else
    if [[ "$DO_SVN" == "yes" ]] ; then
        svn cat $SVN_ROOT_PREFIX/$dfile > $dfile
        if [[ $? == 0 && -e $dfile ]] ; then
            info "SVN download succeeded: $SVN_ROOT_PREFIX/$dfile"
            return 0
        else
            warn "Normal svn failed. Trying anonymous svn." 
            svn cat $SVN_ANON_ROOT_PREFIX/$dfile > $dfile
            if [[ $? == 0 && -e $dfile ]] ; then
                info "Anonymous SVN download succeeded: $SVN_ANON_ROOT_PREFIX/$dfile"
                return 0
            fi
        fi
        warn "SVN download attempt failed: $SVN_ROOT_PATH/$SVN_THIRDPARTY_PATH/$dfile"
        warn "Anonymous SVN download attempt failed: $SVN_ANON_ROOT_PREFIX/$dfile"
        rm -f $dfile
    elif [[ "$DO_SVN_ANON" == "yes" ]] ; then
        svn cat $SVN_ANON_ROOT_PREFIX/$dfile > $dfile
        if [[ $? == 0 && -e $dfile ]] ; then
            info "Anonymous SVN download succeeded: $SVN_ANON_ROOT_PREFIX/$dfile"
            return 0
        fi
        warn "Anonymous SVN download attempt failed: $SVN_ANON_ROOT_PREFIX/$dfile"
        rm -f $dfile
    fi

    # If the visit source code is requested try that next.
    if [[ "$dfile" == "$VISIT_FILE" ]] ; then
        try_download_file $SVN_ANON_ROOT_PATH/trunk/releases/$VISIT_VERSION/$dfile $dfile
        if [[ $? == 0 ]] ; then
            return 0
        fi
    fi

    # Now try the various places listed.
    if [[ "$1" != "" ]] ; then
        for site in $* ; do
            try_download_file $site/$dfile $dfile
            if [[ $? == 0 ]] ; then
                return 0
            fi
        done
    fi

    # Now try anonymous svn unless we tried it above.
    if [[ "$DO_SVN" != "yes" && "$DO_ANON_SVN" != "yes" ]] ; then
        svn cat $SVN_ANON_ROOT_PREFIX/$dfile > $dfile
        if [[ $? == 0 && -e $dfile ]] ; then
            info "Anonymous SVN download succeeded: $SVN_ANON_ROOT_PREFIX/$dfile"
            return 0
        fi
        warn "Anonymous SVN download attempt failed: $SVN_ANON_ROOT_PREFIX/$dfile"
        rm -f $dfile
    fi

    # Now try the anonymous svn site with wget or curl.
    try_download_file $SVN_ANON_ROOT_PREFIX/$dfile $dfile
    if [[ $? == 0 ]] ; then
        return 0
    fi
    info "Failed to download $dfile"
    return 1
}

# *************************************************************************** 
# Function: try_download_file
#
# Purpose: DONT USE THIS FUNCTION. USE download_file.
# Downloads a file using wget or curl. 
#
# Programmer: Refactored from other sources (Mark C. Miller)
# Creation: February 19, 2009
#
#   Cyrus Harrison, Tue 24 Mar 13:44:31 PST 2009 
#   As an extra guard, check that the downloaded file actually exisits. 
#   (Firewalls can cause strange files to be created.)
# 
#   Cyrus Harrison, Thu Apr  9 19:21:13 PDT 2009
#   Applied patch from Rick Wagner to fix curl downloads on OSX.
#
#   Tom Fogal, Sun Jul 26 17:19:26 MDT 2009
#   Follow redirects.  Don't use a second argument.
#
#   Gunther H. Weber, Fri Oct 23 13:17:34 PDT 2009
#   Specify explicit path to system curl so that we do not use another
#   version without SSL support
#
# *************************************************************************** 

function try_download_file
{
    if [[ "$OPSYS" == "Darwin" ]]; then
        # MaxOS X comes with curl
        /usr/bin/curl -ksfLO $1
    else
        check_wget
        if [[ $? != 0 ]] ; then
            error "Need to download $1, but \
                   cannot locate the wget utility to do so."
        fi
        wget $WGET_OPTS -o /dev/null $1
    fi

    if [[ $? == 0 && -e `basename $1` ]] ; then
        info "Download succeeded: $1"
        return 0
    else    
        warn "Download attempt failed: $1"
        rm -f `basename $1`
        return 1
    fi
}


# *************************************************************************** #
# Function: check_svn_client                                                  #
#                                                                             #
# Purpose: Helper that checks if a svn client is available.                    #
#                                                                             #
# Programmer: Cyrus Harrison                                                  #
# Date:  Mon Nov 17 14:52:37 PST 2008                                         #
#                                                                             #
# *************************************************************************** #

function check_svn_client
{
    # check for svn client
    SVN_CLIENT=$(which svn)
    if [[ $SVN_CLIENT == "" ]] ; then
        return 1
    fi
    return 0
}

# *************************************************************************** #
# Function: check_wget                                                        #
#                                                                             #
# Purpose: Helper that checks if a wget is available.                         #
#                                                                             #
# Programmer: Cyrus Harrison                                                  #
# Date:  Mon Nov 17 14:52:37 PST 2008                                         #
#                                                                             #
# *************************************************************************** #

function check_wget
{
    WGET_CLIENT=$(which wget)
    # check for wget
    if [[ $WGET_CLIENT == "" ]] ; then
        return 1
    fi
    return 0
}

# *************************************************************************** #
# Function: check_if_installed                                                #
#                                                                             #
# Purpose: Checks if $VISITDIR/$1/$2/$VISITARCH exists.                       #
#                                                                             #
# Programmer: Cyrus Harrison                                                  #
# Date: Wed Nov 19 07:31:08 PST 2008                                          #
#                                                                             #
# *************************************************************************** #
function check_if_installed
{
    BUILD_NAME=$1
    BUILD_VERSION=""

    if [[ $# == 2 ]]; then
        BUILD_VERSION=$2
    fi
    
    if [[ $BUILD_VERSION != "" ]]; then
        INSTALL_DIR=$VISITDIR/$BUILD_NAME/$BUILD_VERSION/$VISITARCH
    else
        INSTALL_DIR=$VISITDIR/$BUILD_NAME/$VISITARCH
    fi

    if [[ -d ${INSTALL_DIR} ]] ; then
        return 0
    else
        return 1
    fi
}

# *************************************************************************** #
# Function: ensure_built_or_ready                                             #
#                                                                             #
# Purpose: Helper that checks for proper installed version. If this doesn't   #
#  exist, makes sure the source file is avalaible for building.               #
#                                                                             #
# Programmer: Cyrus Harrison                                                  #
# Date: Fri Nov 14 08:23:26 PST 2008                                          #
#                                                                             #
# *************************************************************************** #
function ensure_built_or_ready
{
    BUILD_NAME=$1
    BUILD_VERSION=$2
    INSTALL_DIR=$VISITDIR/$BUILD_NAME/$BUILD_VERSION/$VISITARCH
    BUILD_DIR=$3
    SRC_FILE=$4
    DOWNLOAD_PATH=$5

    info "Checking for ${BUILD_NAME}-${BUILD_VERSION}"
    
    ALREADY_INSTALLED="NO"
    HAVE_TARBALL="NO"
    
    check_if_installed $BUILD_NAME $BUILD_VERSION
    if [[ $? == 0 || -d $BUILD_DIR ]] ; then
        ALREADY_INSTALLED="YES"
    fi
    if [[ -e ${SRC_FILE%.gz} || -e ${SRC_FILE} ]] ; then
        HAVE_TARBALL="YES"
    fi
    
    if [[ "$ALREADY_INSTALLED" == "NO" && "$HAVE_TARBALL" == "NO" ]] ; then
        download_file ${SRC_FILE} ${DOWNLOAD_PATH}
        if [[ $? != 0 ]] ; then
            warn "Error: Cannot obtain source for $BUILD_NAME."
            return 1
        fi
    fi
    return 0
}


# *************************************************************************** #
# Function: prepare_build_dir                                                 #
#                                                                             #
# Purpose: Helper that prepares a build directory from a src file.            #
#                                                                             #
# Returns:                                                                    #
#          -1 on failure                                                      #
#           0 for success without untar                                       #
#           1 for success with untar                                          #
#           2 for failure with checksum                                       #
#                                                                             #
# Programmer: Cyrus Harrison                                                  #
# Date: Thu Nov 13 09:28:26 PST 2008                                          #
#                                                                             #
# Modifications:                                                              #
#                                                                             #
#   Paul Selby, Wed  4 Feb 17:25:22 GMT 2015                                  #
#   Fixed typo which prevented verify_checksum being called                   #
# *************************************************************************** #
function prepare_build_dir
{
    BUILD_DIR=$1
    SRC_FILE=$2
    
    #optional
    CHECKSUM_TYPE=$3
    CHECKSUM_VALUE=$4

    untarred_src=0
    if [[ -d ${BUILD_DIR} ]] ; then
       info "Found ${BUILD_DIR} . . ."
       untarred_src=0
    elif [[ -f ${SRC_FILE} ]] ; then
       if [[ $CHECKSUM_VALUE != "" && $CHECKSUM_TYPE != "" ]]; then
            verify_checksum $CHECKSUM_TYPE $CHECKSUM_VALUE ${SRC_FILE}
            if [[ $? != 0 ]]; then
                return 2
            fi
       fi
       info "Unzipping/Untarring ${SRC_FILE} . . ."
       uncompress_untar ${SRC_FILE}
       untarred_src=1
       if [[ $? != 0 ]] ; then
          warn \
"Unable to untar $SRC_FILE  Corrupted file or out of space on device?"
          return -1
       fi
    elif [[ -f ${SRC_FILE%.*} ]] ; then
       info "Untarring ${SRC_FILE%.*} . . ."
       $TAR xf ${SRC_FILE%.*}
       untarred_src=1
       if [[ $? != 0 ]] ; then
          warn \
"Unable to untar ${SRC_FILE%.*}.  Corrupted file or out of space on device?"
          return -1
       fi
    fi
    
    return $untarred_src
}

# *************************************************************************** #
#                   Function 1.3, check_optional_3rdparty                     #
# --------------------------------------------------------------------------- #
# This function will check to make sure that all of the necessary source      #
# files for the optional 3rd party libraries actually exist.                  #
#
# *************************************************************************** #

function check_optional_3rdparty
{
    info "Checking optional 3rd party libs"

    for (( i = 0; i < ${#optlibs[*]}; ++i ))
    do
        ensure="bv_${optlibs[$i]}_ensure"
        $ensure
        if [[ $? != 0 ]] ; then
            return 1
        fi
    done
}


# *************************************************************************** #
#                    Function 1.1, check_required_3rdparty                    #
# --------------------------------------------------------------------------- #
# This function will check to make sure that all of the necessary files       #
# for the required third party libraries actually exist.                      #
# *************************************************************************** #

function check_required_3rdparty
{
    info "Checking for files . . ."

    for (( i = 0; i < ${#reqlibs[*]}; ++i ))
    do
        ensure="bv_${reqlibs[$i]}_ensure"
        $ensure
        if [[ $? != 0 ]] ; then
            return 1
        fi
    done

    return 0
}


# *************************************************************************** #
#                         Function 1.0, check_files                           #
# --------------------------------------------------------------------------- #
# This function will check to make sure that all of the necessary files       #
# actually exist.                                                             #
# *************************************************************************** #

function check_files
{
    check_required_3rdparty
    if [[ $? != 0 ]]; then
        return 1
    fi

    if [[ "$DO_VISIT" == "yes" ]] ;  then
       bv_visit_ensure_built_or_ready
       if [[ $? != 0 ]]; then
           return 1
       fi
    fi

    check_optional_3rdparty
    if [[ $? != 0 ]]; then
        return 1
    fi
    return 0
}


# *************************************************************************** #
#                         Function 2.0, check_more_options                    #
# --------------------------------------------------------------------------- #
# This function will display variables and optionally allow changing          #
# *************************************************************************** #

function check_more_options
{

    # Override variable settings dialog
    #
    if [[ "$DO_MORE" == "yes" && "$GRAPHICAL" == "yes" ]] ; then
        result=$($DLG --backtitle "$DLG_BACKTITLE" \
        --title "More build options" \
        --checklist \
"Version: specify version of VisIt to download and build\n"\
"Build: build VisIt, disable to build 3rd party only\n"\
"Required: build required 3rd party libraries\n"\
"Logging: display build log to stdout\n"\
"Symbol: turn on -g, debugging flag\n"\
"Group: specify the group name for install\n"\
"Path: specify the root directory for libraries\n"\
"to use the given Path rather than the default [@executable_path/../lib]\n"\
"Trace: print a trace of commands and arguments during build\n\n"\
"Select build and installed options:" 0 0 0 \
           "Version"   "specify VisIt version [$VISIT_VERSION]" $ON_VERSION \
           "Build"     "enable building VisIt"                  $ON_VISIT \
           "Logging"   "disable logging to file"                $ON_LOG \
           "Symbol"    "enable debug compiling"                 $ON_DEBUG \
           "Group"     "specify group name for install"         $ON_GROUP \
           "HostConf"  "create host.conf file"                  $ON_HOSTCONF \
           "Path"      "specify library path [$THIRD_PARTY_PATH]" $ON_PATH \
           "Trace"     "enable SHELL debugging"      $ON_VERBOSE 3>&1 1>&2 2>&3)
        retval=$?

    # Remove the extra quoting, new dialog has --single-quoted
        choice="$(echo $result | sed 's/"//g' )"
        case $retval in
          0)
            DO_VERSION="no"
            DO_VISIT="no"
            DO_REQUIRED_THIRD_PARTY="no"
            DO_LOG="no"
            DO_DEBUG="no"
            DO_GROUP="no"
            DO_HOSTCONF="no"
            DO_PATH="no"
            DO_VERBOSE="no"
            for OPTION in $choice
            do
                case $OPTION in
                  Version)
                     result=$($DLG --backtitle "$DLG_BACKTITLE" \
                        --nocancel --inputbox \
"Enter $OPTION value:" 0 $DLG_WIDTH_WIDE "$VISIT_VERSION"   3>&1 1>&2 2>&3) 
                     VISIT_VERSION="$result"
                     VISIT_FILE="visit${VISIT_VERSION}.tar.gz"
                     DO_VERSION="yes";;
                  Build)
                     DO_VISIT="yes";;
                  Logging)
                     DO_LOG="yes";;
                  Symbol)
                     DO_DEBUG="yes";;
                  Group)
                     result=$($DLG --backtitle "$DLG_BACKTITLE" \
                        --nocancel --inputbox \
"Enter $OPTION value:" 0 $DLG_WIDTH_WIDE "$GROUP" 3>&1 1>&2 2>&3)
                     GROUP="$result"
                     DO_GROUP="yes";;
                  HostConf)
                      DO_HOSTCONF="yes";;
                  Path)
                     result=$($DLG --backtitle "$DLG_BACKTITLE" \
                        --nocancel --inputbox \
"Enter $OPTION value:" 0 $DLG_WIDTH_WIDE "$THIRD_PARTY_PATH" 3>&1 1>&2 2>&3)
                     THIRD_PARTY_PATH="$result"
                     DO_PATH="yes";;
                  Trace)
                     DO_VERBOSE="yes";;
                esac
            done
            ;;
          1)
            warn "Cancel pressed."
            exit 1;;
          255)
            warn "ESC pressed.";;
          *)
            warn "Unexpected return code: $retval";;
        esac
    fi
    return 0
}

# *************************************************************************** #
#                          extract_parallel_ldflags                           #
# --------------------------------------------------------------------------- #
# VisIt's cmake config wants lib names stripped of "-l"                       #
# If PAR_LIBS is used to pass parallel LDFLAGS we need to separate the libs   #
# from the linker flags and strip the "-l" prefixes.                          #
# This function accomplishes this and creates two new  variables:             #
#   PAR_LINKER_FLAGS & PAR_LIBRARY_NAMES                                      #
# *************************************************************************** #
function process_parallel_ldflags
{
    export PAR_LINKER_FLAGS=""
    export PAR_LIBRARY_NAMES=""

    for arg in $1; do
        pos=`echo "$arg" | awk '{ printf "%d", index($1,"-l"); }'`
        if [[ "$pos" != "0" ]] ; then
            # we have a lib, remove the "-l" prefix & add it to the running
            # list
            LIB_NAME=${arg#-l}
            export PAR_LIBRARY_NAMES="$PAR_LIBRARY_NAMES$LIB_NAME "
        else
            # we have a linker flag, add it to the running list.
            export PAR_LINKER_FLAGS="$PAR_LINKER_FLAGS$arg "
        fi
    done

}


# *************************************************************************** #
#                         Function 2.1, check_parallel                        #
# --------------------------------------------------------------------------- #
# This function will check to make sure that parallel options have been setup #
# if we're going to build a parallel version of VisIt.                        #
# *************************************************************************** #

function check_parallel
{
    rv=0

    if [[ "$DO_MPICH" == "yes" && "$parallel" == "no" ]] ; then
        parallel="yes"
    fi

    # if we are using PAR_LIBS, call helper to split this into:
    # PAR_LIBRARY_NAMES & PAR_LINKER_FLAGS
    process_parallel_ldflags "$PAR_LIBS"

    #
    # Parallelization
    #
    if [[ "$parallel" == "yes" ]] ; then

        #
        # VisIt's cmake build can obtain all necessary MPI flags from
        # a MPI compiler wrapper.
        # Check if PAR_COMPILER is set & if so use that.
        #
        export VISIT_MPI_COMPILER=""
        export VISIT_MPI_COMPILER_CXX=""
        if [[ "$PAR_COMPILER" != "" ]] ; then
            export VISIT_MPI_COMPILER="$PAR_COMPILER"
            info \
                "Configuring with mpi compiler wrapper: $VISIT_MPI_COMPILER"
            if [[ "$PAR_COMPILER_CXX" != "" ]] ; then
                export VISIT_MPI_COMPILER_CXX="$PAR_COMPILER_CXX"
                "Configuring with mpi c++ compiler wrapper: $VISIT_MPI_COMPILER_CXX"
            fi
            return 0
        fi

        #
        # VisIt's build_visit can obtain all necessary MPI flags from
        # bv_mpich. If we are building mpich and the user
        # did not set PAR_LIBS or PAR_INCLUDE we are done.
        #
        if [[ "$DO_MPICH" == "yes" && "$PAR_INCLUDE" == "" && "$PAR_LIBS" == "" && "$MPIWRAPPER" == "" ]] ; then

            export MPICH_COMPILER="${VISITDIR}/mpich/$MPICH_VERSION/${VISITARCH}/bin/mpicc"
            export MPICH_COMPILER_CXX="${VISITDIR}/mpich/$MPICH_VERSION/${VISITARCH}/bin/mpic++"
            export VISIT_MPI_COMPILER="$MPICH_COMPILER"
            export VISIT_MPI_COMPILER_CXX="$MPICH_COMPILER_CXX"
            export PAR_COMPILER="$MPICH_COMPILER"
            export PAR_COMPILER_CXX="$MPICH_COMPILER_CXX"
            info  "Configuring parallel with mpich build: "
            info  "  PAR_COMPILER: $MPICH_COMPILER " 
            info  "  PAR_COMPILER_CXX: $MPICH_COMPILER_CXX"
            return 0
        fi

        #
        # Check the environment that mpicc would set up as a first stab.
        # Since VisIt currently only ever uses MPI's C interface, we need
        # only the information to link to MPI's implementation of its C
        # interface. So, although VisIt is largely a C++ code, it is fine
        # and correct to utilize an MPI C compiler here.
        #
        MPICC_CPPFLAGS=""
        MPICC_LDFLAGS=""
        MPIWRAPPER=$(which mpicc)
        if [[ "${MPIWRAPPER#no }" != "${MPIWRAPPER}" ]] ; then
           MPIWRAPPER=""
        fi
        if [[ "$MPIWRAPPER" == "" ]] ; then
            warn "Unable to find mpicc..."
        fi

        #
        # VisIt's cmake build can obtain all necessary MPI flags from
        # a MPI compiler wrapper. If we have found one & the user
        # did not set PAR_LIBS or PAR_INCLUDE we are done.
        #
        if [[ "$PAR_INCLUDE" == "" && "$PAR_LIBS" == "" && "$MPIWRAPPER" != "" ]] ; then
            export VISIT_MPI_COMPILER=$MPIWRAPPER
            export PAR_COMPILER=$MPIWRAPPER
            info \
                "Configuring with mpi compiler wrapper: $VISIT_MPI_COMPILER"
            return 0
        fi

        #
        # VisIt's build_visit can obtain all necessary MPI flags from
        # bv_mpich. If we are building mpich and the user
        # did not set PAR_LIBS or PAR_INCLUDE we are done.
        #
        if [[ "$DO_MPICH" == "yes" && "$PAR_INCLUDE" == "" && "$PAR_LIBS" == "" && "$MPIWRAPPER" == "" ]] ; then

            export MPICH_COMPILER="${VISITDIR}/mpich/$MPICH_VERSION/${VISITARCH}/bin/mpicc"
            export VISIT_MPI_COMPILER="$MPICH_COMPILER"
            export PAR_COMPILER="$MPICH_COMPILER"
            info \
                "Configuring with build mpich: $MPICH_COMPILER"
            return 0
        fi

        #
        # If we have not found a MPI compiler wrapper. 
        # Keep trying to discover mpi setttings.
        #
        if [[ "$PAR_CPPFLAGS" == "" ]] ; then
            warn \
"We have no guesses as to where MPI might reside. Look for it..."
            if [[ -e /usr/include/mpi.h ]] ; then
                PAR_CPPFLAGS="-I/usr/include"
                PAR_LDFLAGS="-L/usr/lib -lmpi"
            fi
        fi

        if [[ "$GRAPHICAL" == "yes" ]] ; then
            # We have suggestions from the user or mpicc as to where mpi might
            # be located. See what the user thinks of the options.
            tryagain=1
            while [[ $tryagain == 1 ]]; do
                $DLG --backtitle "$DLG_BACKTITLE" --yesno \
"The CPPFLAGS for MPI are:\n\n$PAR_CPPFLAGS\n\nDo these look right?" \
                15 $DLG_WIDTH 3>1& 1>&2 2>&3
                if [[ $? == 1 ]] ; then
                    tryagain=1
                    result=$($DLG --backtitle "$DLG_BACKTITLE" \
                    --nocancel --inputbox \
"Enter CPPFLAGS needed for MPI:" 0 $DLG_WIDTH_WIDE "$PAR_CPPFLAGS" 3>&1 1>&2 2>&3) 
                    PAR_CPPFLAGS="$result"
                else
                    tryagain=0
                fi
            done

            PAR_INCLUDE=$PAR_CPPFLAGS

            # We have suggestions from the user or mpicc as to where mpi might
            # be located. See what the user thinks of the options.
            tryagain=1
            while [[ $tryagain == 1 ]]; do
                $DLG --backtitle "$DLG_BACKTITLE" --yesno \
"The LDFLAGS for MPI are:\n\n$PAR_LDFLAGS\n\nDo these look right?" 15 $DLG_WIDTH 3>1& 1>&2 2>&3
                if [[ $? == 1 ]] ; then
                    tryagain=1
                    result=$($DLG --backtitle "$DLG_BACKTITLE" \
                    --nocancel --inputbox \
"Enter LDFLAGS needed for MPI:" 0 $DLG_WIDTH_WIDE "$PAR_LDFLAGS"  3>&1 1>&2 2>&3) 
                    PAR_LDFLAGS="$result"
                else
                    tryagain=0
                fi
            done

            PAR_LIBS=$PAR_LDFLAGS
        fi

        # The script pretty much assumes that you *must* have some flags 
        # and libs to do a parallel build.  If that is *not* true, 
        # i.e. mpi.h is in your include path, then, congratulations, 
        # you are working on a better configured system than I have 
        # ever encountered.
        if [[ "$PAR_INCLUDE" == "" || "$PAR_LIBRARY_NAMES" == "" || "$PAR_LINKER_FLAGS" == "" ]] ; then
            warn \
"To configure parallel VisIt you must satisfy one of the following conditions:
    The PAR_COMPILER env var provides a path to a mpi compiler wrapper (such as mpicc).
    A mpi compiler wrapper (such as mpicc) to exists in your path.
    The PAR_INCLUDE & PAR_LIBS env vars provide necessary CXX & LDFLAGS to use mpi.

 To build ICE-T the PAR_INCLUDE env var must provide the include path to your mpi headers.
    "
            rv=1
        fi

        if [[ $rv != 0 ]] ; then
           return 1
        fi
    fi

    return 0
}

# *************************************************************************** #
#                         Function 2.2, check_variables                       #
# --------------------------------------------------------------------------- #
# This function will display variables and optionally allow changing          #
# *************************************************************************** #

function check_variables_dialog
{
    local var="$1"
    local input="$2"

    result=$($DLG --backtitle "$DLG_BACKTITLE" \
                           --nocancel --inputbox \
"Enter $var value:" 0 $DLG_WIDTH_WIDE "$input"  3>&1 1>&2 2>&3)
    echo "$result"
}

function check_variables
{

    # Override variable settings dialog
    #
    if [[ "$verify" == "yes" ]] ; then
        if [[ "$GRAPHICAL" == "yes" ]] ; then
            result=$($DLG --backtitle "$DLG_BACKTITLE" \
            --title "Variable settings" \
            --checklist \
"These variables use these system dependent defaults, but can be overridden "\
"through this interface or using environment variables.\n\n"\
"OPSYS: the default value returned from 'uname -s'\n"\
"ARCH: architecure info (Darwin, linux, aix, irix64, ...)\n"\
"C_COMPILER and CXX_COMPILER: the C and C++ compiler, respectively\n"\
"CFLAGS and CXXFLAGS: the flags to use for all compiles (e.g. -fPIC)\n"\
"C_OPT_FLAGS and CXX_OPT_FLAGS: the optimization flags to use for C and C++\n"\
"VISITARCH: unique architecture info, appended to library path installation\n"\
"REVISION: checkout a cwspecific SVN revision using supplied argument\n\n"\
"Select the variables you wish to modify:" 28 $DLG_WIDTH 8 \
           "OPSYS"            "$OPSYS"             "off" \
           "ARCH"             "$ARCH"              "off" \
           "C_COMPILER"       "$C_COMPILER"        "off" \
           "CXX_COMPILER"     "$CXX_COMPILER"      "off" \
           "CFLAGS"           "$CFLAGS"       "off" \
           "CXXFLAGS"         "$CXXFLAGS"     "off" \
           "C_OPT_FLAGS"      "$C_OPT_FLAGS"       "off" \
           "CXX_OPT_FLAGS"    "$CXX_OPT_FLAGS"     "off" \
           "FC_COMPILER"      "$FC_COMPILER"       "off" \
           "FCFLAGS"          "$FCFLAGS"       "off" \
           "VISITARCH"        "$VISITARCHTMP"      "off" \
           "REVISION"         "$SVNREVISION"       "off"   3>&1 1>&2 2>&3) 
           retval=$?

           # Remove the extra quoting, new dialog has --single-quoted
           choice="$(echo $result | sed 's/"//g' )"
           tmp_var=0
           case $retval in
             0)
               for OPTION in $choice
               do

                   #this code uses the name to get and set the option value
                   #please use this convention, otherwise you will have to create
                   #exception as the ones below..
                   [[ $OPTION == "VISITARCH" ]] && OPTION="VISITARCHTMP"
                   [[ $OPTION == "REVISION" ]] && OPTION="SVNREVISION"

                   eval "tmp_var=\"\$$OPTION\""
                   tmp_var=$(check_variables_dialog $OPTION "$tmp_var")
                   eval "$OPTION=\"$tmp_var\""

                   if [[ $OPTION == "SVNREVISION" ]]; then
                        echo "Revision set to $SVNREVISION"
                        DO_SVN="yes"
                        DO_REVISION="yes"
                   fi
               done
               ;;
             1)
               warn "Cancel pressed."
               ;;
             255)
               warn "ESC pressed.";;
             *)
               warn "Unexpected return code: $retval";;
           esac
       fi
    fi

    return 0
}


# *************************************************************************** #
#                          Function 9, build_hostconf                         #
#                                                                             #
# Mark C. Miller, Wed Oct 27 19:29:19 PDT 2010                                #
# Adjusted ordering of database lib variables to ensure LIBDEP gets processed #
# correctly. Added comments to host conf file regarding ordering issue.       #
#                                                                             #
# Kathleen Bonnell, Wed Feb 16 08:35:40 PST 2011                              #
# Remove setting of CMAKE_BUILD_TYPE                                          #
#                                                                             #
# Kathleen Biagas, Mon Aug 8 08:12:37 MST 2011                                #
# Use FILEPATH type for compilers, STRING type for libdep.                    # 
# *************************************************************************** #
hostconf_library_success=""
function hostconf_library
 {
    local build_lib=$1
    local depends_on=""

    # if already in success list then ignore..
    if [[ "$hostconf_library_success" == *$build_lib* ]]; then
        return
    fi

    depends_on=$("bv_${build_lib}_depends_on")

    #replace commas with spaces if there are any..
    depends_on=${depends_on//,/ }

    for depend_lib in `echo $depends_on`;
    do
        hostconf_library $depend_lib
    done

    #build ..
    $"bv_${build_lib}_host_profile"
    hostconf_library_success="${hostconf_library_success} ${build_lib}"
}


function build_hostconf
{
    #
    # Set up environment variables for the configure step.
    #
    PARFLAGS=""
    if [[ "$parallel" == "yes" ]] ; then
       PARFLAGS="--enable-parallel"
    fi

    #
    # Set up the config-site file, which gives configure the information it
    # needs about the third party libraries.

    export HOSTCONF="$(hostname).cmake"

    if [[ "${VISIT_HOSTNAME}" != "" ]]; then
        info "VISIT_HOSTNAME env variable found: Using ${VISIT_HOSTNAME}.cmake"
        HOSTCONF="${VISIT_HOSTNAME}.cmake"
    fi

    if [[ "${EXTERNAL_HOSTNAME}" != "" ]]; then
        info "External Hostname variable found: Using ${EXTERNAL_HOSTNAME}"
        HOSTCONF="${EXTERNAL_HOSTNAME}"
    fi

    info "Creating $HOSTCONF"

    # First line of config-site file provides a hint to the location
    # of cmake.

    THIRD_PARTY_ABS_PATH=$(pushd $THIRD_PARTY_PATH 1,2>/dev/null; pwd; popd 1,2>/dev/null)
    if [[ "$CMAKE_INSTALL" != "" ]]; then
        echo "#$CMAKE_INSTALL/cmake" > $HOSTCONF
    else
        echo "#$THIRD_PARTY_ABS_PATH/cmake/$CMAKE_VERSION/$VISITARCH/bin/cmake" > $HOSTCONF
    fi
    echo "##" >> $HOSTCONF
    echo "## $0 generated host.cmake" >> $HOSTCONF
    echo "## created: $(date)" >> $HOSTCONF
    echo "## system: $(uname -a)" >> $HOSTCONF
    echo "## by: $(whoami)" >> $HOSTCONF
    echo >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "## Setup VISITHOME & VISITARCH variables." >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "SET(VISITHOME $VISITDIR)" >> $HOSTCONF
    echo "SET(VISITARCH $VISITARCH)" >> $HOSTCONF
    echo >> $HOSTCONF

#####
    echo "## Compiler flags." >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "VISIT_OPTION_DEFAULT(VISIT_C_COMPILER $C_COMPILER TYPE FILEPATH)">> $HOSTCONF
    echo "VISIT_OPTION_DEFAULT(VISIT_CXX_COMPILER $CXX_COMPILER TYPE FILEPATH)" >> $HOSTCONF

    if [[ "$USE_VISIBILITY_HIDDEN" == "yes" ]] ; then
        echo "VISIT_OPTION_DEFAULT(VISIT_C_FLAGS \"$CFLAGS -fvisibility=hidden\" TYPE STRING)" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_CXX_FLAGS \"$CXXFLAGS -fvisibility=hidden\" TYPE STRING)" >> $HOSTCONF
    else
        if test -n "$CFLAGS" ; then
            echo "VISIT_OPTION_DEFAULT(VISIT_C_FLAGS \"$CFLAGS\" TYPE STRING)" >> $HOSTCONF
        fi
        if test -n "$CXXFLAGS" ; then
            echo "VISIT_OPTION_DEFAULT(VISIT_CXX_FLAGS \"$CXXFLAGS\" TYPE STRING)" >> $HOSTCONF
        fi
    fi

    if [[ "${DO_JAVA}" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## VisIt Java Option." >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_JAVA ON TYPE BOOL)" >> $HOSTCONF
    fi

    if [[ "$BUILD_VISIT_BGQ" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## BG/Q-specific settings" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "SET(CMAKE_CROSSCOMPILING    ON)" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_USE_X            OFF TYPE BOOL)" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_USE_GLEW         OFF TYPE BOOL)" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_SLIVR            OFF TYPE BOOL)" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_DISABLE_SELECT   ON  TYPE BOOL)" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_USE_NOSPIN_BCAST OFF TYPE BOOL)" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_OPENGL_DIR       \${VISITHOME}/mesa/$MESA_VERSION/\${VISITARCH})" >> $HOSTCONF
        echo "ADD_DEFINITIONS(-DVISIT_BLUE_GENE_Q)" >> $HOSTCONF
        echo >> $HOSTCONF
    fi

    if [[ "$parallel" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## Parallel Build Setup." >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_PARALLEL ON TYPE BOOL)" >> $HOSTCONF
        # we either set an mpi wrapper compiler in the host conf
        if [[ "$VISIT_MPI_COMPILER" != "" ]] ; then
            if [[ "$BUILD_VISIT_BGQ" == "yes" ]] ; then
                echo "## (inserted by build_visit for BG/Q. Configuration as of 10/8/2014.)" >> $HOSTCONF
                echo "## (LC rolled back this ppcfloor configuration from V1R2M2 to V1R2M0 10/16/2014.)" >> $HOSTCONF
                echo "#SET(BLUEGENEQ /bgsys/drivers/ppcfloor)" >> $HOSTCONF
                echo "#VISIT_OPTION_DEFAULT(VISIT_PARALLEL ON TYPE BOOL)" >> $HOSTCONF
                echo "#VISIT_OPTION_DEFAULT(VISIT_MPI_CXX_FLAGS \"-I\${BLUEGENEQ} -I\${BLUEGENEQ}/comm/include -I\${BLUEGENEQ}/spi/include -I\${BLUEGENEQ}/spi/include/kernel/cnk\" TYPE STRING)" >> $HOSTCONF
                echo "#VISIT_OPTION_DEFAULT(VISIT_MPI_C_FLAGS   \"-I\${BLUEGENEQ} -I\${BLUEGENEQ}/comm/include -I\${BLUEGENEQ}/spi/include -I\${BLUEGENEQ}/spi/include/kernel/cnk\" TYPE STRING)" >> $HOSTCONF
                echo "#VISIT_OPTION_DEFAULT(VISIT_MPI_LD_FLAGS  \"-L\${BLUEGENEQ}/spi/lib -L\${BLUEGENEQ}/comm/lib -R/opt/ibmcmp/lib64/bg/bglib64\" TYPE STRING)" >> $HOSTCONF
                echo "#VISIT_OPTION_DEFAULT(VISIT_MPI_LIBS     mpich-xl opa-xl mpl-xl pami-gcc SPI SPI_cnk rt pthread stdc++ pthread TYPE STRING)" >> $HOSTCONF
                echo "" >> $HOSTCONF
                echo "## (inserted by build_visit for BG/Q. Configuration as of 10/15/2014.)" >> $HOSTCONF
                echo "SET(BLUEGENEQ /bgsys/drivers/V1R2M0/ppc64)" >> $HOSTCONF
                echo "VISIT_OPTION_DEFAULT(VISIT_MPI_CXX_FLAGS \"-I\${BLUEGENEQ} -I\${BLUEGENEQ}/comm/sys/include -I\${BLUEGENEQ}/spi/include -I\${BLUEGENEQ}/spi/include/kernel/cnk -I\${BLUEGENEQ}/comm/xl/include\" TYPE STRING)" >> $HOSTCONF
                echo "VISIT_OPTION_DEFAULT(VISIT_MPI_C_FLAGS   \"-I\${BLUEGENEQ} -I\${BLUEGENEQ}/comm/sys/include -I\${BLUEGENEQ}/spi/include -I\${BLUEGENEQ}/spi/include/kernel/cnk -I\${BLUEGENEQ}/comm/xl/include\" TYPE STRING)" >> $HOSTCONF
                echo "VISIT_OPTION_DEFAULT(VISIT_MPI_LD_FLAGS  \"-L\${BLUEGENEQ}/spi/lib -L\${BLUEGENEQ}/comm/sys/lib -L\${BLUEGENEQ}/spi/lib -L\${BLUEGENEQ}/comm/xl/lib -R/opt/ibmcmp/lib64/bg/bglib64\" TYPE STRING)" >> $HOSTCONF
                echo "VISIT_OPTION_DEFAULT(VISIT_MPI_LIBS     mpich opa mpl pami SPI SPI_cnk rt pthread stdc++ pthread TYPE STRING)" >> $HOSTCONF
            else
                echo "## (configured w/ mpi compiler wrapper)" >> $HOSTCONF
                echo "VISIT_OPTION_DEFAULT(VISIT_MPI_COMPILER $VISIT_MPI_COMPILER TYPE FILEPATH)"  >> $HOSTCONF
            fi
        else
            # or we just set the flags.
            echo "## (configured w/ user provided CXX (PAR_INCLUDE) & LDFLAGS (PAR_LIBS) flags)" \
             >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(VISIT_MPI_CXX_FLAGS \"$PAR_INCLUDE\" TYPE STRING)"     >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(VISIT_MPI_LD_FLAGS  \"$PAR_LINKER_FLAGS\" TYPE STRING)" >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(VISIT_MPI_LIBS        $PAR_LIBRARY_NAMES TYPE STRING)" >> $HOSTCONF
        fi
    fi

    if [[ "$DO_STATIC_BUILD" == "yes" ]] ; then
        echo >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "## Static build" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_STATIC ON TYPE BOOL)" >> $HOSTCONF
    fi

    echo >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "## VisIt Thread Option" >> $HOSTCONF
    echo "##" >> $HOSTCONF
    if [[ "$DO_THREAD_BUILD" == "yes" ]] ; then
        echo "VISIT_OPTION_DEFAULT(VISIT_THREAD ON TYPE BOOL)" >> $HOSTCONF
    else
        echo "VISIT_OPTION_DEFAULT(VISIT_THREAD OFF TYPE BOOL)" >> $HOSTCONF
    fi

    if [[ "${DO_PARADIS}" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## VisIt paraDIS Option." >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_PARADIS ON TYPE BOOL)" >> $HOSTCONF
    fi

    echo >> $HOSTCONF
    echo \
"##############################################################" >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "## Database reader plugin support libraries" >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "## The HDF4, HDF5 and NetCDF libraries must be first so that" >> $HOSTCONF
    echo "## their libdeps are defined for any plugins that need them." >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "## For libraries with LIBDEP settings, order matters." >> $HOSTCONF
    echo "## Libraries with LIBDEP settings that depend on other" >> $HOSTCONF
    echo "## Library's LIBDEP settings must come after them." >> $HOSTCONF
    echo \
"##############################################################" >> $HOSTCONF

    for (( bv_i=0; bv_i<${#reqlibs[*]}; ++bv_i ))
    do
        hostconf_library ${reqlibs[$bv_i]}
    done

    for (( bv_i=0; bv_i<${#optlibs[*]}; ++bv_i ))
    do
        hostconf_library ${optlibs[$bv_i]}
    done
    echo >> $HOSTCONF

    #
    # Patch for Ubuntu 11.04
    #
    #if test -d "/usr/lib/x86_64-linux-gnu" ; then
    #    numLibs=$(ls -1 /usr/lib/x86_64-linux-gnu | wc -l)
    #    if (( $numLibs > 10 )) ; then
    #       rm -f $HOSTCONF.tmp
    #       cat $HOSTCONF | sed "s/\/usr\/lib/\/usr\/lib\/x86_64-linux-gnu/" > $HOSTCONF.tmp
    #       rm $HOSTCONF
    #       mv $HOSTCONF.tmp $HOSTCONF
    #    fi
    #fi

    cd "$START_DIR"
    echo "Done creating $HOSTCONF"
    return 0
}

function printvariables  
{
  printf "The following is a list of user settable environment variables\n"
  printf "\n"
  printf "%s%s\n" "OPSYS=" "${OPSYS}"
  printf "%s%s\n" "PROC=" "${PROC}"
  printf "%s%s\n" "REL=" "${REL}"
  printf "%s%s\n" "ARCH=" "${ARCH}"
  printf "%s%s\n" "VISITARCH=" "${VISITARCHTMP}"

  printf "%s%s\n" "C_COMPILER=" "${C_COMPILER}"
  printf "%s%s\n" "CXX_COMPILER=" "${CXX_COMPILER}"
  printf "%s%s\n" "CFLAGS=" "${CFLAGS}"
  printf "%s%s\n" "CXXFLAGS=" "${CXXFLAGS}"
  printf "%s%s\n" "C_OPT_FLAGS=" "${C_OPT_FLAGS}"
  printf "%s%s\n" "CXX_OPT_FLAGS=" "${CXX_OPT_FLAGS}"
  printf "%s%s\n" "PAR_INCLUDE=" "${PAR_INCLUDE}"
  printf "%s%s\n" "PAR_LIBS=" "${PAR_LIBS}"

  printf "%s%s\n" "MAKE=" "${MAKE}"
  printf "%s%s\n" "THIRD_PARTY_PATH=" "${THIRD_PARTY_PATH}"
  printf "%s%s\n" "GROUP=" "${GROUP}"
  printf "%s%s\n" "LOG_FILE=" "${LOG_FILE}"
  printf "%s%s\n" "LOG_FILE=" "${LOG_FILE}"
  printf "%s%s\n" "WGET_OPTS=" "${WGET_OPTS}"
  printf "%s%s\n" "SVNREVISION=" "${SVNREVISION}"
  
  bv_visit_print
  for (( bv_i=0; bv_i<${#reqlibs[*]}; ++bv_i ))
  do
      initialize="bv_${reqlibs[$bv_i]}_print"
      $initialize
  done

  for (( bv_i=0; bv_i<${#optlibs[*]}; ++bv_i ))
  do
      initialize="bv_${optlibs[$bv_i]}_print"
      $initialize
  done
}

function usage  
{
  printf "Usage: %s [options]\n" $0
  printf "A download attempt will be made for all files which do not exist."
  printf "\n\n"
  printf "BOOLEAN FLAGS\n"
  printf "\tThese are used to enable or disable specific functionality.  They do not take option values.\n\n"
  printf "%-15s %s [%s]\n" "--dry-run"  "Dry run of the presented options" "false"
  printf "%-15s %s [%s]\n" "--build-mode" "VisIt build mode (Debug or Release)" "$VISIT_BUILD_MODE"
  printf "%-15s %s [%s]\n" "--console" "Do not use dialog ('graphical') interface" "!$GRAPHICAL"
  printf "%-15s %s [%s]\n" "--dbio-only" "Disables EVERYTHING but I/O." "$DO_DBIO_ONLY"
  printf "%-15s %s [%s]\n" "--engine-only" "Only build the compute engine." "$DO_ENGINE_ONLY"
  printf "%-15s %s [%s]\n" "--debug"   "Enable debugging for this script" "false"
  printf "%-15s %s [%s]\n" "--download-only" "Only download the specified packages" "false"
  printf "%-15s %s [%s]\n" "--flags-debug" "Add '-g' to C[XX]FLAGS" "false"
  printf "%-15s %s [%s]\n" "--group" "Group name of installed libraries" "$GROUP"
  printf "%-15s %s [%s]\n" "-h" "Display this help message." "false"
  printf "%-15s %s [%s]\n" "--help" "Display this help message." "false"
  printf "%-15s %s [%s]\n" "--java" "Build with the Java client library" "${DO_JAVA}"
  printf "%-15s %s [%s]\n" "--no-hostconf" "Do not create host.conf file." "$ON_HOSTCONF"
  printf "%-15s %s [%s]\n" "--parallel" "Enable parallel build, display MPI prompt" "$parallel"
  printf "%-15s %s [%s]\n" "--prefix" "The directory to which VisIt should be installed once it is built" "$VISIT_INSTALL_PREFIX"
  printf "%-15s %s [%s]\n" "--print-vars" "Display user settable environment variables" "false"
  printf "%-15s %s [%s]\n" "--server-components-only" "Only build VisIt's server components (mdserver,vcl,engine)." "$DO_SERVER_COMPONENTS_ONLY"
  printf "%-15s %s [%s]\n" "--slivr" "Build with SLIVR shader support" "$DO_SLIVR"
  printf "%-15s %s [%s]\n" "--paradis" "Build with the paraDIS client library" "${DO_PARADIS}"
  printf "%-15s %s [%s]\n" "--static" "Build using static linking" "$DO_STATIC_BUILD"
  printf "%-15s %s [%s]\n" "--stdout" "Write build log to stdout" "$LOG_FILE"
  printf "%-15s %s [%s]\n" "--xdb" "Enable FieldView XDB plugin." "$DO_XDB"

  for (( bv_i=0; bv_i<${#grouplibs_comment[*]}; ++bv_i ))
  do
        name=${grouplibs_name[$bv_i]}
        comment=${grouplibs_comment[$bv_i]}
        printf "%-15s %s [%s]\n" "--$name" "$comment" ""
  done

  bv_visit_print_usage

  for (( bv_i=0; bv_i<${#reqlibs[*]}; ++bv_i ))
  do
      initialize="bv_${reqlibs[$bv_i]}_print_usage"
      $initialize
  done

  for (( bv_i=0; bv_i<${#optlibs[*]}; ++bv_i ))
  do
      initialize="bv_${optlibs[$bv_i]}_print_usage"
      $initialize
  done

  printf "%s\n" ""
  printf "OPTIONS\n"
  printf "These values all take a special value.  If given, they require an associated value to be provided as well.\n\n"
  printf "%-15s \n\t%s [%s]\n" "--installation-build-dir"  "Specify the directory visit will use for building" "output-filename"
  printf "%-15s \n\t%s [%s]\n" "--write-unified-file"  "Write single unified build_visit file" "output-filename"
  printf "%s <%s> %s [%s]\n" "--arch" "architecture" "Set architecture" "$VISITARCHTMP"
  printf "\t  %s\n" "   This variable is used in constructing the 3rd party"
  printf "\t  %s\n" "   library path; usually set to something like"
  printf "\t  %s\n" "   'linux_gcc-3.4.6' or 'Darwin_gcc-4.0.1'"
  printf "%-11s %s [%s]\n" "--cflag"   "Append a flag to CFLAGS" "${CFLAGS}"
  printf "%-11s %s [%s]\n" "--cxxflag" "Append a flag to CXXFLAGS" "$CXXFLAGS"
  printf "%-11s %s [%s]\n" "--cflags"  "Explicitly set CFLAGS" "$CFLAGS"
  printf "%-11s %s [%s]\n" "--cxxflags" "Explicitly set CXXFLAGS" "$CXXFLAGS"
  printf "%-11s %s [%s]\n" "--cc"  "Explicitly set C_COMPILER" "$C_COMPILER"
  printf "%-11s %s [%s]\n" "--cxx" "Explicitly set CXX_COMPILER" "$CXX_COMPILER"
  printf "%-11s <%s> %s [%s]\n" "--makeflags" "flags" "Flags to 'make'" "$MAKE_OPT_FLAGS"
  printf "%s <%s> %s\n" "--svn" \
    "Obtain VisIt source code and third party libraries from the SVN server"
  printf "\t%s\n" "    [svn co $SVN_REPO_ROOT_PATH/$SVN_SOURCE_PATH]"
  printf "%s <%s> %s\n" "--svn-anonymous" \
    "Obtain VisIt source code and third party libraries using the anonymous SVN mirror."
  printf "\t%s\n" "    [svn co $SVN_ANON_ROOT_PATH/$SVN_SOURCE_PATH]"
  printf "%s <%s> %s\n" "--svn-revision" "revision" \
    "Specify the SVN revision of the VisIt source code and third party libraries to download.  Used in conjunction with --svn or --svn-anonymous."
  printf "%s <%s> %s [%s]\n" "--tarball" "file" "tarball to extract VisIt from" "$VISIT_FILE"
  printf "%-11s <%s> \n%s [%s]\n" "--thirdparty-path" "/path/to/directory" \
    "             Specify the root directory name under which the 3rd party
             libraries have been installed.  If defined, it would typically
             mean the 3rd party libraries are pre-built and are installed
             somewhere like /usr/gapps/visit." "${THIRD_PARTY_PATH}"
  printf "%s <%s> %s [%s]\n" "--version" "version" "The VisIt version to build" "$VISIT_VERSION"
}


#TODO: pass these two variables from command line..
mangle_src="VTK"
mangle_dest="MTK"
uc_mangled_src=`echo $mangle_src | tr '[a-z]' '[A-Z]'`
uc_mangled_dest=`echo $mangle_dest | tr '[a-z]' '[A-Z]'`
lc_mangled_src=`echo $mangle_src | tr '[A-Z]' '[a-z]'`
lc_mangled_dest=`echo $mangle_dest | tr '[A-Z]' '[a-z]'`

function mangle_file
{
    local input_file="$1"
    local output_file="$2"

    cat "$input_file" | sed -e s/${lc_mangled_src}/${lc_mangled_dest}/g -e s/${uc_mangled_src}/${uc_mangled_dest}/g > "$output_file"
    
    #chmod --reference=$input_file $output_file
    if [[ -r "$input_file" ]]; then
        chmod u+r "$output_file"
    fi
    if [[ -w "$input_file" ]]; then
        chmod u+r "$output_file"
    fi
    if [[ -x "$input_file" ]]; then
        chmod u+x "$output_file"
    fi
}

function mangle_libraries
{
    local input_dir="$1"
    local mangled_dir="$2"

    if [[ ! -d "$input_dir" ]]; then
        info "Input directory $input_dir does not exist"
        return 1
    fi

    if [[ -d "$mangled_dir" ]]; then

        #check if we have completely mangled the library before..
        if [[ -e "$mangled_dir/done_mangling_library" ]]; then
            info "library was mangled earlier, skipping (please exit if this is not true)"
            return 0
        fi
        info "Found pre-existing mangled directory $mangled_dir, removing"
        rm -fR "$mangled_dir"
    fi

    info "mangling $input_dir $mangled_dir"
    #get all files from directory..
    local args=`find "${input_dir}" -name "*"`
    local i=0
    for i in `echo $args`
    do
        #replace all occurrences of $mangled_src with mangled_dest
        newpath=${i/${input_dir}/}
        newpath=${newpath//${uc_mangled_src}/${uc_mangled_dest}}
        newpath=${newpath//${lc_mangled_src}/${lc_mangled_dest}}
        mangled_path="${mangled_dir}/${newpath}"
        newdir=`dirname "${mangled_path}"`
    
        #create new dir
        mkdir -p "$newdir"
        #cat old file replace ${mangled_src} with ${mangled_dest}
        if [[ ! -d $i ]]; then
            mangle_file "$i" "${mangled_path}" 
        else
            #chmod --reference=$i $newdir
            if [[ -r "$i" ]]; then
                chmod u+r "$newdir"
            fi
            if [[ -w "$i" ]]; then
                chmod u+r "$newdir"
            fi
            if [[ -x "$i" ]]; then
                chmod u+x "$newdir"
            fi
        fi
    done
    touch "$mangled_dir"/done_mangling_library
    return 0
}
#!/bin/bash

declare -a xmlp_filecontents
declare -a xmlp_licenses
declare -a xmlp_licenses_range
declare -a xmlp_alllibs
declare -a xmlp_tmp_array
declare -a xmlp_reqlibs
declare -a xmlp_optlibs
declare -a xmlp_grouplibs_name
declare -a xmlp_grouplibs_deps
declare -a xmlp_grouplibs_comment

function xmlp_removeSingleLineComment
{
    if [[ "$1" == *\<\!--*--\>* ]]; then
        echo "${1//\<\!--*--\>}"
    else
        echo "$1"
    fi
}

function xmlp_isCommentStart
{
    if [[ $1 == *\<\!--* ]]; then
        return 1
    fi
    return 0
}

function xmlp_isCommentEnd
{
    if [[ $1 == *--\>* ]]; then 
        return 1
    fi
    return 0
}

function readXmlModuleFile
{
    local filename=$1
    local i=0
    local isComment=0
    local range_index=0
    local addlibs=""

    if [[ ! -e $filename ]]; then 
        echo "File $filename does not exist"
        return 0
    fi

    while read line
    do
        line=$(xmlp_removeSingleLineComment "$line")
        xmlp_isCommentStart "$line"
        
        if [[ $? == 1 ]]; then
            isComment=1
        fi

        #remove comments and empty lines..
        if [[ $isComment == 0 && ! -z "$line" ]]; then
            #record which license the files go to..
            if [[ $line == *\<license* ]]; then 
                tmp=`echo $line | sed -e s/^.*=\"// -e s/\".*$//`
                range_index=${#xmlp_licenses[*]}
                xmlp_licenses[$range_index]="$tmp" 
                xmlp_licenses_range[$range_index]="$i"
            fi

            if [[ $line == *\</license\>* ]]; then 
                xmlp_licenses_range[$range_index]="${xmlp_licenses_range[$range_index]} $i"
            fi

            if [[ $line == *\<lib* ]]; then
                addlib=`echo ${line/no-} | sed -e s/^.*=\"// -e s/\".*$//`
                addlibs="${addlibs} $addlib"
            fi
            #trim white space
            xmlp_filecontents[$i]=`echo $line`
            let i++
        fi 

        xmlp_isCommentEnd "$line"

        if [[ $? == 1 ]]; then
            isComment=0
        fi
    done < $filename

    if [[ ${#xmlp_licenses[*]} == 0 ]]; then
        echo "No valid licenses found"
        return 0
    fi

    #get list of all libs, sort and get unique set..
    uniq_libs=`echo $addlibs | sed -e s/\ /\\\\n/g | sort | uniq`
    for lib in $uniq_libs;
    do
        xmlp_alllibs[${#xmlp_alllibs[*]}]="$lib"
    done

    return 1
}

function parseXmlModules
{
    local startReading=0
    local x=0
    local startPattern=$1
    local endPattern=$2
    local lstart=$3
    local lend=$4

    xmlp_tmp_array=()
    #find required tag and parse all its parameters..
    for (( i=$lstart; i < $lend; ++i ))
    do
        if [[ ${xmlp_filecontents[$i]} == *$endPattern* ]]; then
            startReading=0
        fi

        if [[ $startReading == 1 ]]; then
            #remove everything to first string..
            local tmp="${xmlp_filecontents[$i]}"
            tmp=`echo $tmp | sed -e s/^.*=\"// -e s/\".*$//`
            xmlp_tmp_array[$x]="$tmp"
            let x++
        fi

        if [[ ${xmlp_filecontents[$i]} == *$startPattern* ]]; then
            startReading=1
        fi
    done
}

function parseXmlGroupModules
{
    local startReading=0
    local startPattern="<group"
    local endPattern="</group>"
    local lstart=$1
    local lend=$2
    local title=""
    local deps=""
    local comment=""
    #find required tag and parse all its parameters..
    for (( i=$lstart; i < $lend; ++i ))
    do
        if [[ ${xmlp_filecontents[$i]} == *$endPattern* ]]; then
            startReading=0
            #remove whitespace with echo
            #echo "Title: $title Comment: $comment Deps $deps"
            xmlp_grouplibs_name[${#xmlp_grouplibs_name[*]}]=`echo $title`
            xmlp_grouplibs_deps[${#xmlp_grouplibs_deps[*]}]=`echo $deps`
            xmlp_grouplibs_comment[${#xmlp_grouplibs_comment[*]}]=`echo $comment`
            title=""
            deps=""
        fi

        if [[ $startReading == 1 ]]; then
            #remove everything to first string..
            local tmp="${xmlp_filecontents[$i]}"
            tmp=`echo $tmp | sed -e s/^.*=\"// -e s/\".*$//`
            deps="$deps $tmp"
        fi

        if [[ ${xmlp_filecontents[$i]} == *$startPattern* ]]; then
            startReading=1
            local tmp="${xmlp_filecontents[$i]}"
            #has comment
            if [[ "$tmp" == *comment* ]]; then
                tmp_comment=${tmp/*comment}
                tmp_comment=`echo $tmp | sed -e s/^.*=\"// -e s/\".*$//`
                comment="$tmp_comment"
                tmp=${tmp/comment*}
                tmp=`echo $tmp | sed -e s/^.*=\"// -e s/\".*$//`
                title="$tmp"
            else
                tmp=`echo $tmp | sed -e s/^.*=\"// -e s/\".*$//`
                title="$tmp"
                comment=""
            fi
        fi
    done
}


#check if input argument is actually a license
function xmlp_licenseMatch
{
    local license=${1/--}
    local bv_i=0

    for (( bv_i=0; bv_i < ${#xmlp_licenses[*]}; ++bv_i ))
    do
        local xmlp_lic=${xmlp_licenses[$bv_i]//\|/ }
        for lic in `echo $xmlp_lic`;
        do
            if [[ "$lic" == "$license" ]]; then
                return 1
            fi
        done
    done 
    return 0
}

#loop through argument list and extract license
function xmlp_get_license
{
    local defaultLicense="" 
    for arg in "$@" ; do
        #potential input license..
        xmlp_licenseMatch "${arg/--}"
        if [[ $? == 1 ]]; then
            defaultLicense="$defaultLicense ${arg/--}"
        fi
    done

    if [[ "$defaultLicense" == "" ]]; then
        defaultLicense="${xmlp_licenses[0]/\|*}"
    fi

    echo "$defaultLicense"
}

function parseXmlModuleContents
{
    local license=$1
    local lstart=-1
    local lend=-1
    local i=0

    xmlp_reqlibs=()
    xmlp_optlibs=()
    xmlp_grouplibs_name=()
    xmlp_grouplibs_deps=()
    xmlp_grouplibs_comment=()

    for (( i=0; i < ${#xmlp_licenses[*]}; ++i ))
    do
        local range=${xmlp_licenses_range[$i]}
        local xmlp_lic=${xmlp_licenses[$i]//\|/ }
        for lic in `echo $xmlp_lic`;
        do
            if [[ "$lic" == "$license" ]]; then
                lstart=${range/ *}
                lend=${range/* }
            fi
        done
    done

    if [[ $lstart == -1 || $lend == -1 ]]; then
        echo "License $license not found"
        return 0
    fi

    len=${#xmlp_filecontents[*]}
    if [[ $len -lt 2 ]]; then 
        echo "Incomplete Module file"
        return 0
    fi

    if [[   ${xmlp_filecontents[0]} != *\<modules* || 
            ${xmlp_filecontents[${#xmlp_filecontents[*]}-1]} != *\</modules\>* ]]; then
        echo "Module file not formatted properly must start and end with <module> </module> tag"
        return 0
    fi

    #echo "parsing license $license, start=$lstart, end=$lend"

    #parse required
    parseXmlModules "<required>" "</required>" $lstart $lend
    xmlp_reqlibs=( "${xmlp_tmp_array[@]}" )

    #parse optional
    parseXmlModules "<optional>" "</optional>" $lstart $lend
    xmlp_optlibs=( "${xmlp_tmp_array[@]}" )

    #parse any groups
    parseXmlGroupModules $lstart $lend

    if [[   ${#xmlp_reqlibs[*]} == 0 || 
            ${#xmlp_optlibs[*]} == 0 ]]; then
        echo "Required and Optional Modules not present in module files"
        return 0
    fi

    #for (( i = 0; i < ${#xmlp_reqlibs[*]}; ++i ))
    #do
    #    echo "required: ${xmlp_reqlibs[$i]}"
    #done

    #for (( i = 0; i < ${#xml_optlibs[*]}; ++i ))
    #do
    #    echo "optional: ${xmlp_optlibs[$i]}"
    #done

    #for (( i = 0; i < ${#xmlp_grouplibs_name[*]}; ++i ))
    #do
    #    echo "group names: ${xmlp_grouplibs_name[$i]}"
    #    echo "group deps: ${xmlp_grouplibs_deps[$i]}"
    #done
    return 1
}

#readXmlModuleFile "modules.xml"
##parseXmlModuleContents "lgpl"
# Module automatically read in from construct_build_visit
# Insert header and comments


#initialize all the variables
function bv_visit_initialize
{
    export DO_VISIT="yes"
    export ON_VISIT="on"
}

#enable the module for install
function bv_visit_enable
{ 
    DO_VISIT="yes"
    ON_VISIT="on"
}

#disable the module for install
function bv_visit_disable
{
    DO_VISIT="no"
    ON_VISIT="off"
}

#add any dependency with comma separation
function bv_visit_depends_on
{
    echo ""
}

#add information about how to get library..
function bv_visit_info
{
    echo "Setting VisIt info..."
}

#print variables used by this module
function bv_visit_print
{
    printf "%s%s\n" "VISIT_FILE=" "${VISIT_FILE}"
    printf "%s%s\n" "VISIT_VERSION=" "${VISIT_VERSION}"
    #printf "%s%s\n" "VISIT_COMPATIBILITY_VERSION=" "${VISIT_COMPATIBILITY_VERSION}"
    #printf "%s%s\n" "VISIT_BUILD_DIR=" "${VISIT_BUILD_DIR}"
}

#print how to install and uninstall module..
function bv_visit_print_usage
{
    printf "%-15s %s [%s]\n" "--visit"   "Build VisIt" "$DO_VISIT"
}

#how to show information for graphical editor
function bv_visit_graphical
{
    local graphical_out="VISIT    $VISIT_VERSION($VISIT_FILE)    $ON_VISIT"
    echo $graphical_out
}

#values to add to host profile, write to $HOSTCONF
function bv_visit_host_profile
{
    #Add code to write values to variable $HOSTCONF
    if [[ "$DO_VISIT" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## VISIT" >> $HOSTCONF
    fi
}

#prepare the module and check whether it is built or is ready to be built.
function bv_visit_ensure_built_or_ready
{
    # Check-out the latest svn sources, before building VisIt
    if [[ "$DO_SVN" == "yes" && "$USE_VISIT_FILE" == "no" ]] ; then
        if [[ -d src ]] ; then
           info "Found existing VisIt SVN src directory, using that . . ."
        else
           # Print a dialog screen
           info "SVN check-out of VisIt ($SVN_ROOT_PATH/$SVN_SOURCE_PATH) . . ."
           if [[ "$DO_REVISION" == "yes" && "$SVNREVISION" != "" ]] ; then
               svn co --quiet --non-interactive --revision "$SVNREVISION" \
                  $SVN_ROOT_PATH/$SVN_SOURCE_PATH
           else
               svn co --quiet --non-interactive $SVN_ROOT_PATH/$SVN_SOURCE_PATH
           fi
           if [[ $? != 0 ]] ; then
               warn "Unable to build VisIt. SVN download failed."
               return 1
           fi
        fi

    # Build using (the assumed) existing VisIt svn "src" directory
    elif [[ -d src ]] ; then
           info "Found VisIt SVN src directory found, using it."
           #resetting any values that have mixup the build between Trunk and RC
           VISIT_FILE="" #erase any accidental setting of these values
           USE_VISIT_FILE="no"
           ON_USE_VISIT_FILE="off"
           DO_SVN="yes" #if src directory exists it may have come from svn..

    # Build using a VisIt source tarball
    else
        if [[ -e ${VISIT_FILE%.gz} || -e ${VISIT_FILE} ]] ; then
            info \
"Got VisIt source code. Lets look for 3rd party libraries."
        else
            download_file $VISIT_FILE
            if [[ $? != 0 ]] ; then
               warn \
"Unable to build VisIt.  Can't find source code: ${VISIT_FILE}."
               return 1
            fi
        fi
    fi
}

function bv_visit_dry_run
{
  if [[ "$DO_VISIT" == "yes" ]] ; then
    echo "Dry run option not set for VisIt"
  fi
}


#print what the module will do for building
function bv_visit_print_build_command
{
   #print the build command..
   echo "visit has no build commands set"
}

# Modify the makefiles that cmake generated.
function bv_visit_modify_makefiles
{
    # NOTE: We are inside the VisIt src directory when this function is called.

    if [[ "$OPSYS" == "Darwin" ]]; then
        # Check for version < 8.0.0 (MacOS 10.4, Tiger) for gcc < 4.x
        VER=$(uname -r)
        if (( ${VER%%.*} > 8 )) ; then
           cat databases/Shapefile/Makefile | \
              sed '/LDFLAGS/s/$/ -Wl,-dylib_file,\/System\/Library\/Frameworks\/OpenGL.framework\/Versions\/A\/Libraries\/libGLU.dylib:\/System\/Library\/Frameworks\/OpenGL.framework\/Versions\/A\/Libraries\/libGLU.dylib/' > Make.tmp
           mv -f databases/Shapefile/Makefile databases/Shapefile/Makefile.orig
           mv -f Make.tmp databases/Shapefile/Makefile
           if [[ "$DO_CCMIO" == "yes" ]] ; then
              cat databases/CCM/Makefile | \
                 sed '/LDFLAGS/s/$/ -Wl,-dylib_file,\/System\/Library\/Frameworks\/OpenGL.framework\/Versions\/A\/Libraries\/libGLU.dylib:\/System\/Library\/Frameworks\/OpenGL.framework\/Versions\/A\/Libraries\/libGLU.dylib/' > Make.tmp
              mv -f databases/CCM/Makefile databases/CCM/Makefile.orig
              mv -f Make.tmp databases/CCM/Makefile
           fi
        fi 
        if (( ${VER%%.*} < 8 )) ; then
           info "Patching VisIt . . ."
           cat databases/Fluent/Makefile | sed '/CXXFLAGS/s/$/ -O0/g' > Make.tmp
           mv -f databases/Fluent/Makefile databases/Fluent/Makefile.orig
           mv -f Make.tmp databases/Fluent/Makefile
           cat avt/Pipeline/Data/avtCommonDataFunctions.C | \
              sed '/isfinite/s/isfinite/__isfinited/g' > C.tmp
           mv -f avt/Pipeline/Data/avtCommonDataFunctions.C \
              avt/Pipeline/Data/avtCommonDataFunctions.C.orig
           mv -f C.tmp avt/Pipeline/Data/avtCommonDataFunctions.C
           cat avt/Expressions/Abstract/avtExpressionFilter.C | \
              sed '/isfinite/s/isfinite/__isfinited/g' > C.tmp
           mv -f avt/Expressions/Abstract/avtExpressionFilter.C \
              avt/Expressions/Abstract/avtExpressionFilter.C.orig
           mv -f C.tmp avt/Expressions/Abstract/avtExpressionFilter.C
        fi
        if (( ${VER%%.*} < 7 )) ; then
           cat third_party_builtin/mesa_stub/Makefile | \
              sed 's/glx.c glxext.c//' > Make.tmp
           mv -f third_party_builtin/mesa_stub/Makefile \
              third_party_builtin/mesa_stub/Makefile.orig
           mv -f Make.tmp third_party_builtin/mesa_stub/Makefile
        fi
        if (( ${VER%%.*} > 6 )) ; then
           cat databases/SimV1/Makefile | \
              sed '/LDFLAGS/s/$/ -Wl,-undefined,dynamic_lookup/g' > Make.tmp
           mv -f databases/SimV1/Makefile databases/SimV1/Makefile.orig
           mv -f Make.tmp databases/SimV1/Makefile
           cat databases/SimV1Writer/Makefile | \
              sed '/LDFLAGS/s/$/ -Wl,-undefined,dynamic_lookup/g' > Make.tmp
           mv -f databases/SimV1Writer/Makefile \
             databases/SimV1Writer/Makefile.orig
           mv -f Make.tmp databases/SimV1Writer/Makefile
           cat avt/Expressions/Makefile | \
              sed '/LDFLAGS/s/$/ -Wl,-undefined,dynamic_lookup/g' > Make.tmp
           mv -f avt/Expressions/Makefile \
             avt/Expressions/Makefile.orig
           mv -f Make.tmp avt/Expressions/Makefile
        else
           cat databases/SimV1/Makefile | \
              sed '/LDFLAGS/s/$/ -Wl,-flat_namespace,-undefined,suppress/g' > \
              Make.tmp
           mv -f databases/SimV1/Makefile databases/SimV1/Makefile.orig
           mv -f Make.tmp databases/SimV1/Makefile
           cat databases/SimV1Writer/Makefile | \
              sed '/LDFLAGS/s/$/ -Wl,-flat_namespace,-undefined,suppress/g' > \
              Make.tmp
           mv -f databases/SimV1Writer/Makefile \
             databases/SimV1Writer/Makefile.orig
           mv -f Make.tmp databases/SimV1Writer/Makefile
           cat avt/Expressions/Makefile | \
              sed '/LDFLAGS/s/$/ -Wl,-flat_namespace,-undefined,suppress/g' > \
              Make.tmp
           mv -f avt/Expressions/Makefile \
             avt/Expressions/Makefile.orig
           mv -f Make.tmp avt/Expressions/Makefile
        fi
    elif [[ "$OPSYS" == "SunOS" ]]; then
        # Some Solaris systems hang when compiling Fluent when optimizations
        # are on.  Turn optimizations off.
        info "Patching VisIt . . ."
        cat databases/Fluent/Makefile | sed '/CXXFLAGS/s/$/ -O0/g' > Make.tmp
        mv -f databases/Fluent/Makefile databases/Fluent/Makefile.orig
        mv -f Make.tmp databases/Fluent/Makefile
    fi

    if [[ "$BUILD_VISIT_BGQ" == "yes" ]] ; then
        # Filter the engine link line so it will not include X11 libraries. CMake is adding
        # them even though we don't want them. Also get rid of extra static/dynamic 
        # link keywords that prevent the linker from making a good static executable.
        for target in engine_ser_exe.dir engine_par_exe.dir
        do
            edir="engine/main/CMakeFiles/$target"
            if test -e "$edir/link.txt" ; then
                sed "s/-lX11//g" $edir/link.txt > $edir/link1.txt
                sed "s/-lXext//g" $edir/link1.txt > $edir/link2.txt
                sed "s/-Wl,-Bstatic//g" $edir/link2.txt > $edir/link3.txt
                sed "s/-Wl,-Bdynamic//g" $edir/link3.txt > $edir/link4.txt
                rm -f $edir/link1.txt $edir/link2.txt $edir/link3.txt
                mv $edir/link4.txt $edir/link.txt
            else
                echo "***** DID NOT SEE: $edir/link.txt   pwd=`pwd`"
            fi
            if test -e "$edir/relink.txt" ; then
                sed "s/-lX11//g" $edir/relink.txt > $edir/relink1.txt
                sed "s/-lXext//g" $edir/relink1.txt > $edir/relink2.txt
                sed "s/-Wl,-Bstatic//g" $edir/relink2.txt > $edir/relink3.txt
                sed "s/-Wl,-Bdynamic//g" $edir/relink3.txt > $edir/relink4.txt
                rm -f $edir/relink1.txt $edir/relink2.txt $edir/relink3.txt
                mv $edir/relink4.txt $edir/relink.txt
            else
                echo "***** DID NOT SEE: $edir/relink.txt   pwd=`pwd`"
            fi
        done
        # Filter the visitconvert link line so it will not include X11 libraries. CMake 
        # is adding them even though we don't want them. Also get rid of extra static/dynamic 
        # link keywords that prevent the linker from making a good static executable.
        for target in visitconvert_ser.dir visitconvert_par.dir
        do
            edir="tools/convert/CMakeFiles/$target"
            if test -e "$edir/link.txt" ; then
                sed "s/-lX11//g" $edir/link.txt > $edir/link1.txt
                sed "s/-lXext//g" $edir/link1.txt > $edir/link2.txt
                sed "s/-Wl,-Bstatic//g" $edir/link2.txt > $edir/link3.txt
                sed "s/-Wl,-Bdynamic//g" $edir/link3.txt > $edir/link4.txt
                rm -f $edir/link1.txt $edir/link2.txt $edir/link3.txt
                mv $edir/link4.txt $edir/link.txt
            else
                echo "***** DID NOT SEE: $edir/link.txt   pwd=`pwd`"
            fi
            if test -e "$edir/relink.txt" ; then
                sed "s/-lX11//g" $edir/relink.txt > $edir/relink1.txt
                sed "s/-lXext//g" $edir/relink1.txt > $edir/relink2.txt
                sed "s/-Wl,-Bstatic//g" $edir/relink2.txt > $edir/relink3.txt
                sed "s/-Wl,-Bdynamic//g" $edir/relink3.txt > $edir/relink4.txt
                rm -f $edir/relink1.txt $edir/relink2.txt $edir/relink3.txt
                mv $edir/relink4.txt $edir/relink.txt
            else
                echo "***** DID NOT SEE: $edir/relink.txt   pwd=`pwd`"
            fi
        done
    fi

    return 0
}

# *************************************************************************** #
#                          Function 9.1, build_visit                          #
# *************************************************************************** #

function build_visit
{
    if [[ "$DO_SVN" != "yes" || "$USE_VISIT_FILE" == "yes" ]] ; then
        #
        # Unzip the file, provided a gzipped file exists.
        #
        if [[ -f ${VISIT_FILE} ]] ; then
           info "Unzipping/untarring ${VISIT_FILE} . . ."
           uncompress_untar ${VISIT_FILE}
           if [[ $? != 0 ]] ; then
              warn \
"Unable to untar ${VISIT_FILE}.  Corrupted file or out of space on device?"
              return 1
           fi
        elif [[ -f ${VISIT_FILE%.*} ]] ; then
           info "Unzipping ${VISIT_FILE%.*} . . ."
           $TAR xf ${VISIT_FILE%.*}
           if [[ $? != 0 ]] ; then
              warn  \
"Unable to untar ${VISIT_FILE%.*}.  Corrupted file or out of space on device?"
              return 1
           fi
        fi
    fi

    #
    # Set up the config-site file, which gives configure the information it
    # needs about the third party libraries.
    #
    local VISIT_DIR="${VISIT_FILE%.tar*}/src"
    if [[ "$DO_SVN" == "yes" && "$USE_VISIT_FILE" == "no" ]] ; then
        VISIT_DIR="src" 
    else
        #visit2.5.0 needs a patch for ModelFit operator
        if [[ "${VISIT_FILE%.tar*}" == "visit2.5.0" ]]; then
            bv_patch_2_5_0
        fi
    fi
    
    cd $VISIT_DIR
    #cp $START_DIR/$(hostname).cmake config-site

    #
    # Call cmake
    # 
    info "Configuring VisIt . . ."
    FEATURES="-DVISIT_CONFIG_SITE:FILEPATH=${START_DIR}/${HOSTCONF}"
    FEATURES="${FEATURES} -DVISIT_INSTALL_THIRD_PARTY:BOOL=ON"
    if [[ "$parallel" == "yes" ]] ; then
        FEATURES="${FEATURES} -DVISIT_PARALLEL:BOOL=ON"
    fi
    FEATURES="${FEATURES} -DCMAKE_BUILD_TYPE:STRING=${VISIT_BUILD_MODE}"
    FEATURES="${FEATURES} -DVISIT_C_COMPILER:FILEPATH=${C_COMPILER}"
    FEATURES="${FEATURES} -DVISIT_CXX_COMPILER:FILEPATH=${CXX_COMPILER}"

    if test -n "${CFLAGS}" || test -n "${C_OPT_FLAGS}" ; then
        FEATURES="${FEATURES} -DVISIT_C_FLAGS:STRING=\"${CFLAGS} ${C_OPT_FLAGS}\""
    fi
    if [[ "$parallel" == "yes" ]] ; then
        CXXFLAGS="$CXXFLAGS $PAR_INCLUDE"
    fi
    if test -n "${CXXFLAGS}" || test -n "${CXX_OPT_FLAGS}" ; then
        FEATURES="${FEATURES} -DVISIT_CXX_FLAGS:STRING=\"${CXXFLAGS} ${CXX_OPT_FLAGS}\""
    fi
    if [[ "${DO_JAVA}" == "yes" ]] ; then
       FEATURES="${FEATURES} -DVISIT_JAVA:BOOL=ON"
    fi
    if [[ "${DO_SLIVR}" == "no" ]] ; then
       FEATURES="${FEATURES} -DVISIT_SLIVR:BOOL=OFF"
    fi
    if [[ "${VISIT_INSTALL_PREFIX}" != "" ]] ; then
       FEATURES="${FEATURES} -DCMAKE_INSTALL_PREFIX:PATH=${VISIT_INSTALL_PREFIX}"
    fi
    # Select a specialized build mode.
    if [[ "${DO_DBIO_ONLY}" == "yes" ]] ; then
       FEATURES="${FEATURES} -DVISIT_DBIO_ONLY:BOOL=ON"
    elif [[ "${DO_ENGINE_ONLY}" = "yes" ]] ; then
       FEATURES="${FEATURES} -DVISIT_ENGINE_ONLY:BOOL=ON"
    elif [[ "${DO_SERVER_COMPONENTS_ONLY}" = "yes" ]] ; then
       FEATURES="${FEATURES} -DVISIT_SERVER_COMPONENTS_ONLY:BOOL=ON"
    fi

    # Let the user turn on XDB.
    if [[ "${DO_XDB}" == "yes" ]] ; then
       FEATURES="${FEATURES} -DVISIT_ENABLE_XDB:BOOL=ON"
    fi

    # Let the user pick a subset of plugins.
    if [[ "${VISIT_SELECTED_DATABASE_PLUGINS}" != "" ]] ; then
       FEATURES="${FEATURES} -DVISIT_SELECTED_DATABASE_PLUGINS:STRING=${VISIT_SELECTED_DATABASE_PLUGINS}"
    fi

    CMAKE_INSTALL=${CMAKE_INSTALL:-"$VISITDIR/cmake/${CMAKE_VERSION}/$VISITARCH/bin"}
    CMAKE_BIN="${CMAKE_INSTALL}/cmake"
    rm -f CMakeCache.txt
    issue_command "${CMAKE_BIN}" ${FEATURES} . 
    if [[ $? != 0 ]] ; then
       echo "VisIt configure failed.  Giving up"
       return 1
    fi

    #
    # Some platforms like to modify the generated Makefiles.
    #
    bv_visit_modify_makefiles

    #
    # Build VisIt
    #
    info "Building VisIt . . . (~50 minutes)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "VisIt build failed.  Giving up"
       return 1
    fi
    warn "All indications are that VisIt successfully built."

    #
    # Install VisIt
    #
    if [[ "${VISIT_INSTALL_PREFIX}" != "" ]] ; then
        $MAKE $MAKE_OPT_FLAGS install
        if [[ $? != 0 ]] ; then
            warn "VisIt installation failed.  Giving up"
            return 1
        fi
        warn "All indications are that VisIt successfully installed."
    fi

    #
    # Major hack here. Mark M. should really pull this total hack out of
    # this script. It is here to make the visitconvert tool be called
    # imeshio to satisfy needs of ITAPS SciDAC project.
    #
    if [[ "${DO_DBIO_ONLY}" == "yes" && "$0" == "build_imeshio" ]] ; then
        if [[ -e exe/visitconvert_ser_lite ]]; then
            cp exe/visitconvert_ser_lite exe/imeshioconvert
            cp bin/visitconvert bin/imeshioconvert
        fi
    fi
}

function bv_visit_is_enabled
{
    if [[ $DO_VISIT == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_visit_is_installed
{
    #always return false?
    return 0
}

function bv_patch_2_5_0
{

  if [[ -e visit2.5.0 ]]; then
    info "apply patch to ModelFit operator"
patch -f -p0 visit2.5.0/src/operators/ModelFit/CMakeLists.txt <<\EOF
24d23
< QT_WRAP_CPP(GModelFitOperator LIBG_SOURCES ${LIBG_MOC_SOURCES})
94a94
>     QT_WRAP_CPP(GModelFitOperator LIBG_SOURCES ${LIBG_MOC_SOURCES})
EOF
  fi

}

#the build command..
function bv_visit_build
{

    #
    # Build the actual VisIt code
    #

    if [[ "$DO_VISIT" == "yes" ]] ; then
        cd "$START_DIR"
        info "Building VisIt (~50 minutes)"
        build_visit
        if [[ $? != 0 ]] ; then
            error "Unable to build or install VisIt.  Bailing out."
        fi

        if [[ "$DO_SVN" == "yes" && "$USE_VISIT_FILE" == "no" ]] ; then
            VISIT_SRC_DIR="src"
        else
            VISIT_SRC_DIR="${VISIT_FILE%.tar*}/src"
        fi

    FINISHED_MSG="Finished building VisIt.\n\n\
    You many now try to run VisIt by cd'ing into the \
    $VISIT_SRC_DIR/bin directory and invoking \"visit\".\n\n\
    To create a binary distribution tarball from this build, cd to \
    ${START_DIR}/${VISIT_SRC_DIR}\n\
    then enter: \"make package\"\n\n\
    This will produce a tarball called visitVERSION.ARCH.tar.gz, where \
    VERSION is the version number, and ARCH is the OS architecure.\n\n\
    To install the above tarball in a directory called \"INSTALL_DIR_PATH\",\
    enter: svn_bin/visit-install VERSION ARCH INSTALL_DIR_PATH\n\n\
    If you run into problems, contact visit-users@ornl.gov."

        #
        # Output the message indicating that we are finished. I couldn't get
        # the imbedded newlines in the FINISHED_MSG to display properly so I
        # am treating the graphical and console interfaces differently.
        #
        if test "${GRAPHICAL}" = "yes" ; then
            info_box_large "$FINISHED_MSG"
            log "Finished building VisIt."
            log
            log "You many now try to run VisIt by cd'ing into the"
            log "$VISIT_SRC_DIR/bin directory and invoking \"visit\""
            log
            log "To create a binary distribution tarball from this build, cd to"
            log "${START_DIR}/${VISIT_SRC_DIR}"
            log "then enter: \"make package\""
            log
            log "This will produce a tarball called visitVERSION.ARCH.tar.gz, where"
            log "VERSION is the version number, and ARCH is the OS architecure."
            log
            log "To install the above tarball in a directory called \"INSTALL_DIR_PATH\""
            log "enter: svn_bin/visit-install VERSION ARCH INSTALL_DIR_PATH"
            log
            log "If you run into problems, contact visit-users@ornl.gov."
        else
            info "Finished building VisIt."
            info
            info "You many now try to run VisIt by cd'ing into the"
            info "$VISIT_SRC_DIR/bin directory and invoking \"visit\""
            info
            info "To create a binary distribution tarball from this build, cd to"
            info "${START_DIR}/${VISIT_SRC_DIR}"
            info "then enter: \"make package\""
            info
            info "This will produce a tarball called visitVERSION.ARCH.tar.gz, where"
            info "VERSION is the version number, and ARCH is the OS architecure."
            info
            info "To install the above tarball in a directory called \"INSTALL_DIR_PATH\""
            info "enter: svn_bin/visit-install VERSION ARCH INSTALL_DIR_PATH"
            info
            info "If you run into problems, contact visit-users@ornl.gov."
        fi
    else
        if [[ $ANY_ERRORS == "no" ]] ; then
            info "Finished!"
        else
            info "Finished with Errors"
        fi
    fi

}
function bv_R_initialize
{
export DO_R="no"
export ON_R="off"
export USE_SYSTEM_R="no"
add_extra_commandline_args "R" "alt-R-dir" 1 "Use alternative directory for R" 
}

function bv_R_enable
{
DO_R="yes"
ON_R="on"
}

function bv_R_disable
{
DO_R="no"
ON_R="off"
}

function bv_R_alt_R_dir
{
    bv_R_enable
    USE_SYSTEM_R="yes"
    R_INSTALL_DIR="$1"
}

function bv_R_depends_on
{
echo ""
}

function bv_R_initialize_vars
{
    if [[ "$USE_SYSTEM_R" == "no" ]]; then
        R_INSTALL_DIR="${VISITDIR}/R/$R_VERSION/${VISITARCH}/"
    fi
}

function bv_R_info
{
export R_FILE=${R_FILE:-"R-2.13.2.tar.gz"}
export R_VERSION=${R_VERSION:-"2.13.2"}
export R_COMPATIBILITY_VERSION=${R_COMPATIBILITY_VERSION:-"2.13.2"}
export R_BUILD_DIR=${R_BUILD_DIR:-"R-2.13.2"}
export R_MD5_CHECKSUM="fbad74f6415385f86425d0f3968dd684"
export R_SHA256_CHECKSUM=""
}

function bv_R_print
{
  printf "%s%s\n" "R_FILE=" "${R_FILE}"
  printf "%s%s\n" "R_VERSION=" "${R_VERSION}"
  printf "%s%s\n" "R_COMPATIBILITY_VERSION=" "${R_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "R_BUILD_DIR=" "${R_BUILD_DIR}"
}

function bv_R_print_usage
{
printf "%-15s %s [%s]\n" "--R"   "Build R" "$DO_R"
}

function bv_R_graphical
{
local graphical_out="R    $R_VERSION($R_FILE)    $ON_R"
echo $graphical_out
}

function bv_R_host_profile
{
    if [[ "$DO_R" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## R" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        if [[ "$USE_SYSTEM_R" == "yes" ]]; then
            echo \
            "VISIT_OPTION_DEFAULT(VISIT_R_DIR $R_INSTALL_DIR/lib/R)" \
            >> $HOSTCONF
        else
            echo \
            "VISIT_OPTION_DEFAULT(VISIT_R_DIR \${VISITHOME}/R/$R_VERSION/\${VISITARCH}/lib/R)" \
            >> $HOSTCONF
        fi
    fi
}

function bv_R_ensure
{
    if [[ "$DO_R" == "yes" && "$USE_SYSTEM_R" == "no" ]] ; then
        ensure_built_or_ready "R" $R_VERSION $R_BUILD_DIR $R_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_R="no"
            error "Unable to build R.  ${R_FILE} not found."
        fi
    fi
}

function bv_R_dry_run
{
  if [[ "$DO_R" == "yes" ]] ; then
    echo "Dry run option not set for R."
  fi
}

# ***************************************************************************
#                         Function 8.22, build_R
#
# Modifications:
#
# ***************************************************************************

function build_R
{
    #
    # Prepare build dir
    #
    prepare_build_dir $R_BUILD_DIR $R_FILE
    untarred_R=$?
    if [[ $untarred_R == -1 ]] ; then
       warn "Unable to prepare R Build Directory. Giving Up"
       return 1
    fi

    #
    info "Configuring R . . ."
    cd $R_BUILD_DIR || error "Can't cd to R build dir."

    R_INSTALL_DIR="$VISITDIR/R/$R_VERSION/$VISITARCH"
    info "Invoking command to configure R"
    if [[ "$OPSYS" == "Darwin" ]]; then
        RFLAG_ARCH=`uname -m`
        RFLAG="32"
        if [[ "$RFLAG_ARCH" == "x86_64" ]]; then
            RFLAG="64"
        fi
        if [[ $MACOSX_DEPLOYMENT_TARGET == "10.6" || $MACOSX_DEPLOYMENT_TARGET == "10.7" || $MACOSX_DEPLOYMENT_TARGET == "10.8" ]]; then
        ./configure FFLAGS="-m64" CFLAGS="-std=gnu99 -g -O2" CXXFLAGS="-std=gnu99 -g -O2" --without-jpeglib --disable-R-framework --enable-R-shlib --disable-openmp --without-cairo --without-ICU --without-libpng --without-system-xz --without-aqua --without-tcltk --without-readline --prefix="$R_INSTALL_DIR"
        else
        ./configure FFLAGS="-m$RFLAG" CFLAGS="-std=gnu99 -g -O2" CXXFLAGS="-std=gnu99 -g -O2" --without-jpeglib --disable-R-framework --enable-R-shlib --disable-openmp --without-cairo --without-ICU --without-libpng --without-system-xz --without-aqua --without-tcltk --without-readline --prefix="$R_INSTALL_DIR"
        fi
    else
        env LIBnn=lib ./configure ${OPTIONAL} CXX="$CXX_COMPILER" \
            CC="$C_COMPILER" CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
            --without-readline --enable-R-shlib \
            --prefix="$R_INSTALL_DIR"
        if [[ $? != 0 ]] ; then
            warn "R configure failed.  Giving up"
            return 1
        fi
    fi

    #
    # Build R
    #
    info "Building R . . . (~5 minutes)"

    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "R build failed.  Giving up"
       exit 1
    fi

    info "Installing R . . ."
    #$MAKE $MAKE_OPT_FLAGS install
    $MAKE -j1 install
    if [[ $? != 0 ]] ; then
       warn "R install failed.  Giving up"
       exit 1
    fi

    info "Installing package ismev . . ."
    $R_INSTALL_DIR/bin/R -e "r = getOption(\"repos\"); r[\"CRAN\"] = \"http://cran.us.r-project.org\"; options(repos = r); rm(r); install.packages(\"ismev\")"

    #
    # TODO, install name tool for OSX
    #
    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
        INSTALLNAMEPATH="$VISITDIR/R/${R_VERSION}/$VISITARCH/lib/R/lib"
        R_LIB_NAMES="libR libRblas libRlapack"

        for i in $R_LIB_NAMES
        do
            install_name_tool -id \
                $INSTALLNAMEPATH/$i.$SO_EXT \
                $VISITDIR/R/${R_VERSION}/${VISITARCH}/lib/R/lib/$i.$SO_EXT
        done

        #
        # Next change the dependent libraries names and paths
        for i in $R_LIB_NAMES
        do
            for j in $R_LIB_NAMES
            do
                install_name_tool -change \
                    $j.$SO_EXT \
                    $INSTALLNAMEPATH/$j.$SO_EXT \
                    $VISITDIR/R/${R_VERSION}/${VISITARCH}/lib/R/lib/$i.$SO_EXT
            done
        done
    fi
    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/R"
       chgrp -R ${GROUP} "$VISITDIR/R"
    fi
    cd "$START_DIR"
    return 0
}

function bv_R_is_enabled
{
    if [[ $DO_R == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_R_is_installed
{
    if [[ "$USE_SYSTEM_R" == "yes" ]]; then
        return 1
    fi

    check_if_installed "R" $R_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_R_build
{
cd "$START_DIR"
if [[ "$DO_R" == "yes" && "$USE_SYSTEM_R" == "no" ]] ; then
    check_if_installed "R" $R_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping R build.  R is already installed."
    else
        info "Building R (~10 minutes)"
        build_R
        if [[ $? != 0 ]] ; then
            error "Unable to build or install R.  Bailing out."
        fi
        info "Done building R"
   fi
fi
}

function bv_adios_initialize
{
    export FORCE_ADIOS="no"
    export DO_ADIOS="no"
    export ON_ADIOS="off"
    export USE_SYSTEM_ADIOS="no"
    add_extra_commandline_args "adios" "alt-adios-dir" 1 "Use alternative directory for adios"

}

function bv_adios_enable
{
    if [[ "$1" == "force" ]]; then
        FORCE_ADIOS="yes"
    fi

    DO_ADIOS="yes"
    ON_ADIOS="on"
}

function bv_adios_disable
{
    DO_ADIOS="no"
    ON_ADIOS="off"
}

function bv_adios_alt_adios_dir
{
    echo "Using alternate Adios directory"

    # Check to make sure the directory or a particular include file exists.
#    [ ! -e "$1" ] && error "Adios not found in $1"

    bv_adios_enable
    USE_SYSTEM_ADIOS="yes"
    ADIOS_INSTALL_DIR="$1"
}

function bv_adios_depends_on
{
    if [[ "$USE_SYSTEM_ADIOS" == "yes" ]]; then
        echo ""
        return 0;
    fi

    if [[ "$DO_MPICH" == "yes" ]] ; then
        echo "mxml mpich"
    else
        echo "mxml"
    fi
}

function bv_adios_initialize_vars
{
    if [[ "$FORCE_ADIOS" == "no" && "$parallel" == "no" ]]; then
        bv_adios_disable
        warn "Adios requested by default but the parallel flag has not been set. Adios will not be built."
        return
    fi

    if [[ "$USE_SYSTEM_ADIOS" == "no" ]]; then
        ADIOS_INSTALL_DIR="${VISITDIR}/adios/$ADIOS_VERSION/$VISITARCH"
    fi
}

function bv_adios_info
{
export ADIOS_FILE=${ADIOS_FILE:-"adios-1.9.0.tar.gz"}
export ADIOS_VERSION=${ADIOS_VERSION:-"1.9.0"}
export ADIOS_COMPATIBILITY_VERSION=${ADIOS_COMPATIBILITY_VERSION:-"1.9.0"}
export ADIOS_BUILD_DIR=${ADIOS_BUILD_DIR:-"adios-1.9.0"}
export ADIOS_MD5_CHECKSUM="dbf5cb10e32add2f04c9b4052b7ffa76"
export ADIOS_SHA256_CHECKSUM=""
}

function bv_adios_print
{
  printf "%s%s\n" "ADIOS_FILE=" "${ADIOS_FILE}"
  printf "%s%s\n" "ADIOS_VERSION=" "${ADIOS_VERSION}"
  printf "%s%s\n" "ADIOS_COMPATIBILITY_VERSION=" "${ADIOS_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "ADIOS_BUILD_DIR=" "${ADIOS_BUILD_DIR}"
}

function bv_adios_print_usage
{
printf "%-15s %s [%s]\n" "--adios"   "Build ADIOS" "$DO_ADIOS"
}

function bv_adios_graphical
{
local graphical_out="ADIOS    $ADIOS_VERSION($ADIOS_FILE)    $ON_ADIOS"
echo $graphical_out
}

function bv_adios_host_profile
{
    if [[ "$DO_ADIOS" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## ADIOS" >> $HOSTCONF
        if [[ "$VISIT_MPI_COMPILER" != "" ]] ; then
            echo "## (configured w/ mpi compiler wrapper)" >> $HOSTCONF
        fi
        echo "##" >> $HOSTCONF

        if [[ "$USE_SYSTEM_ADIOS" == "yes" ]]; then
            echo "VISIT_OPTION_DEFAULT(VISIT_ADIOS_DIR $ADIOS_INSTALL_DIR)" >> $HOSTCONF 
        else
            echo \
            "VISIT_OPTION_DEFAULT(VISIT_ADIOS_DIR \${VISITHOME}/adios/$ADIOS_VERSION/\${VISITARCH})" \
            >> $HOSTCONF 
        fi
    fi
}

function bv_adios_ensure
{
    if [[ "$DO_ADIOS" == "yes" && "$USE_SYSTEM_ADIOS" == "no" ]] ; then
        ensure_built_or_ready "adios" $ADIOS_VERSION $ADIOS_BUILD_DIR $ADIOS_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_ADIOS="no"
            error "Unable to build ADIOS.  ${ADIOS_FILE} not found."
        fi
    fi
}

function bv_adios_dry_run
{
  if [[ "$DO_ADIOS" == "yes" ]] ; then
    echo "Dry run option not set for adios."
  fi
}

# ***************************************************************************
#                         Function 8.22, build_ADIOS
#
# Modifications:
#
# ***************************************************************************

function apply_ADIOS_1_6_0_patch
{
# fix for osx -- malloc.h doesn't exist (examples/C/schema includes this file)
    info "Patching ADIOS"
    patch -p0 << \EOF
diff -rcN adios-1.6.0-orig/examples/C/schema/rectilinear2d.c adios-1.6.0/examples/C/schema/rectilinear2d.c
*** adios-1.6.0-orig/examples/C/schema/rectilinear2d.c	2013-12-05 08:15:37.000000000 -0800
--- adios-1.6.0/examples/C/schema/rectilinear2d.c	2014-06-02 15:27:23.000000000 -0700
***************
*** 10,16 ****
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
! #include <malloc.h>
  #include <unistd.h>
  #include <fcntl.h>
  #include <errno.h>
--- 10,18 ----
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
! #if !defined(__APPLE__)
!  #include <malloc.h>
! #endif
  #include <unistd.h>
  #include <fcntl.h>
  #include <errno.h>
diff -rcN adios-1.6.0-orig/examples/C/schema/structured2d.c adios-1.6.0/examples/C/schema/structured2d.c
*** adios-1.6.0-orig/examples/C/schema/structured2d.c	2013-12-05 08:15:37.000000000 -0800
--- adios-1.6.0/examples/C/schema/structured2d.c	2014-06-02 15:27:23.000000000 -0700
***************
*** 10,16 ****
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
! #include <malloc.h>
  #include <unistd.h>
  #include <fcntl.h>
  #include <errno.h>
--- 10,18 ----
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
! #if !defined(__APPLE__)
!  #include <malloc.h>
! #endif
  #include <unistd.h>
  #include <fcntl.h>
  #include <errno.h>
diff -rcN adios-1.6.0-orig/examples/C/schema/tri2d.c adios-1.6.0/examples/C/schema/tri2d.c
*** adios-1.6.0-orig/examples/C/schema/tri2d.c	2013-12-05 08:15:37.000000000 -0800
--- adios-1.6.0/examples/C/schema/tri2d.c	2014-06-02 15:27:23.000000000 -0700
***************
*** 10,16 ****
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
! #include <malloc.h>
  #include <unistd.h>
  #include <fcntl.h>
  #include <errno.h>
--- 10,18 ----
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
! #if !defined(__APPLE__)
!  #include <malloc.h>
! #endif
  #include <unistd.h>
  #include <fcntl.h>
  #include <errno.h>
diff -rcN adios-1.6.0-orig/examples/C/schema/uniform2d.c adios-1.6.0/examples/C/schema/uniform2d.c
*** adios-1.6.0-orig/examples/C/schema/uniform2d.c	2013-12-05 08:15:37.000000000 -0800
--- adios-1.6.0/examples/C/schema/uniform2d.c	2014-06-02 15:27:23.000000000 -0700
***************
*** 10,16 ****
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
! #include <malloc.h>
  #include <unistd.h>
  #include <fcntl.h>
  #include <errno.h>
--- 10,18 ----
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
! #if !defined(__APPLE__)
!  #include <malloc.h>
! #endif
  #include <unistd.h>
  #include <fcntl.h>
  #include <errno.h>

EOF
    if [[ $? != 0 ]] ; then
      warn "ADIOS patch failed."
      return 1
    fi

    return 0;
}

function apply_ADIOS_patch
{
    if [[ ${ADIOS_VERSION} == 1.6.0 ]] ; then
        apply_ADIOS_1_6_0_patch
        if [[ $? != 0 ]] ; then
            return 1
        fi
    fi

    return 0
}


function build_ADIOS
{
    #
    # Prepare build dir
    #
    prepare_build_dir $ADIOS_BUILD_DIR $ADIOS_FILE
    untarred_ADIOS=$?
    if [[ $untarred_ADIOS == -1 ]] ; then
       warn "Unable to prepare ADIOS Build Directory. Giving Up"
       return 1
    fi
    apply_ADIOS_patch
    if [[ $? != 0 ]] ; then
        if [[ $untarred_ADIOS == 1 ]] ; then
            warn "Giving up on ADIOS build because the patch failed."
            return 1
        else
            warn "Patch failed, but continuing.  I believe that this script\n" \
                 "tried to apply a patch to an existing directory which had " \
                 "already been patched ... that is, that the patch is " \
                 "failing harmlessly on a second application."
        fi
    fi
    #
    info "Configuring ADIOS . . ."
    cd $ADIOS_BUILD_DIR || error "Can't cd to ADIOS build dir."
    
    
    
    info "Invoking command to configure ADIOS"
    if [[ "$VISIT_MPI_COMPILER" != "" ]] ; then
        ADIOS_MPI_OPTS="MPICC=\"$VISIT_MPI_COMPILER\"  MPICXX=\"$VISIT_MPI_COMPILER_CXX\" LDFLAGS=\"$PAR_LINKER_FLAGS\""
        ADIOS_MPI_INC="$PAR_INCLUDE"

    else
        ADIOS_MPI_OPTS="--without-mpi"
    fi
       info     ./configure ${OPTIONAL} CXX="$CXX_COMPILER" \
                  CC="$C_COMPILER" CFLAGS=\"$CFLAGS $C_OPT_FLAGS $ADIOS_MPI_INC\" \
                  CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS $ADIOS_MPI_INC\" \
                  $ADIOS_MPI_OPTS \
                  --disable-fortran \
	              --without-netcdf --without-nc4par --without-hdf5 --without-phdf5 \
                  --with-mxml="$VISITDIR/mxml/$MXML_VERSION/$VISITARCH" \
                  --prefix="$VISITDIR/adios/$ADIOS_VERSION/$VISITARCH"
        
        sh -c "./configure ${OPTIONAL} CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" \
                CFLAGS=\"$CFLAGS $C_OPT_FLAGS $ADIOS_MPI_INC\" CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS $ADIOS_MPI_INC\" \
                $ADIOS_MPI_OPTS \
                --disable-fortran \
	            --without-netcdf --without-nc4par --without-hdf5 --without-phdf5 \
                --with-mxml=\"$VISITDIR/mxml/$MXML_VERSION/$VISITARCH\" \
                --prefix=\"$VISITDIR/adios/$ADIOS_VERSION/$VISITARCH\""
           
        
    if [[ $? != 0 ]] ; then
       warn "ADIOS configure failed.  Giving up"
       return 1
    fi

    #
    # Build ADIOS
    #
    info "Building ADIOS . . . (~2 minutes)"

    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "ADIOSbuild failed.  Giving up"
       return 1
    fi
    info "Installing ADIOS . . ."

    $MAKE install
    if [[ $? != 0 ]] ; then
       warn "ADIOS build (make install) failed.  Giving up"
       return 1
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/ADIOS"
       chgrp -R ${GROUP} "$VISITDIR/ADIOS"
    fi
    cd "$START_DIR"
    info "Done with ADIOS"
    return 0
}

function bv_adios_is_enabled
{
    if [[ $DO_ADIOS == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_adios_is_installed
{
    if [[ "$USE_SYSTEM_ADIOS" == "yes" ]]; then
        return 1
    fi

    check_if_installed "adios" $ADIOS_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_adios_build
{
cd "$START_DIR"

if [[ "$DO_ADIOS" == "yes" && "$USE_SYSTEM_ADIOS" == "no" ]] ; then
    check_if_installed "adios" $ADIOS_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping ADIOS build.  ADIOS is already installed."
    else
        info "Building ADIOS (~1 minutes)"
        build_ADIOS
        if [[ $? != 0 ]] ; then
            error "Unable to build or install ADIOS.  Bailing out."
        fi
        info "Done building ADIOS"
   fi
fi
}
function bv_advio_initialize
{
export DO_ADVIO="no"
export ON_ADVIO="off"
}

function bv_advio_enable
{
DO_ADVIO="yes"
ON_ADVIO="on"
}

function bv_advio_disable
{
DO_ADVIO="no"
ON_ADVIO="off"
}

function bv_advio_depends_on
{
echo ""
}

function bv_advio_info
{
export ADVIO_FILE=${ADVIO_FILE:-"AdvIO-1.2.tar.gz"}
export ADVIO_VERSION=${ADVIO_VERSION:-"1.2"}
export ADVIO_COMPATIBILITY_VERSION=${ADVIO_COMPATIBILITY_VERSION:-"1.2"}
export ADVIO_BUILD_DIR=${ADVIO_BUILD_DIR:-AdvIO-1.2}
export ADVIO_MD5_CHECKSUM="db6def939a2d5dd4d3d6203ba5d3ec7e"
export ADVIO_SHA256_CHECKSUM=""
}

function bv_advio_print
{
  printf "%s%s\n" "ADVIO_FILE=" "${ADVIO_FILE}"
  printf "%s%s\n" "ADVIO_VERSION=" "${ADVIO_VERSION}"
  printf "%s%s\n" "ADVIO_COMPATIBILITY_VERSION=" "${ADVIO_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "ADVIO_BUILD_DIR=" "${ADVIO_BUILD_DIR}"
}

function bv_advio_print_usage
{
printf "%-15s %s [%s]\n" "--advio"   "Build AdvIO" "$DO_ADVIO"
}

function bv_advio_graphical
{
local graphical_out="AdvIO    $ADVIO_VERSION($ADVIO_FILE)     $ON_ADVIO"
echo $graphical_out
}

function bv_advio_host_profile
{
    if [[ "$DO_ADVIO" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## AdvIO" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_ADVIO_DIR \${VISITHOME}/AdvIO/$ADVIO_VERSION/\${VISITARCH})"\
        >> $HOSTCONF
    fi

}

function bv_advio_ensure
{
    if [[ "$DO_ADVIO" == "yes" ]] ; then
        ensure_built_or_ready "AdvIO" $ADVIO_VERSION $ADVIO_BUILD_DIR $ADVIO_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_ADVIO="no"
            error "Unable to build AdvIO. ${ADVIO_FILE} not found. You can register and download it from: http://adventure.sys.t.u-tokyo.ac.jp/download/IO.html"
        fi
    fi
}

function bv_advio_dry_run
{
  if [[ "$DO_ADVIO" == "yes" ]] ; then
    echo "Dry run option not set for advio."
  fi
}

function apply_advio_12_mavericks_patch
{
   patch -p0 << \EOF
diff -c AdvIO-1.2/Base/AdvTypes.h.orig AdvIO-1.2/Base/AdvTypes.h
*** AdvIO-1.2/Base/AdvTypes.h.orig	2014-11-19 17:29:43.000000000 -0800
--- AdvIO-1.2/Base/AdvTypes.h	2014-11-19 17:30:32.000000000 -0800
***************
*** 30,53 ****
  #error  c++ support is disabled. Please recompile AdvIO!!
  #endif
  
- #if SIZEOF_BOOL != 0
- 
- /* use C++-builtin boolean (do nothing) */
- 
- #elif USE_STL
- 
- /* use stl's boolean */
- #include <stl.h>
- 
- #else
- 
- /* use own boolean */
- typedef int bool;
- const bool false = 0;
- const bool true = !false;
- 
- #endif
- 
  #else
  /*---------- C ----------*/
  
--- 30,35 ----

EOF
   if [[ $? != 0 ]] ; then
      return 1
   fi

   return 0 
}

function apply_advio_12_patch
{
   if [[ "$OPSYS" == "Darwin" ]] ; then
      if [[ `sw_vers -productVersion` == 10.9.[0-9]* ]] ; then
         info "Applying OS X 10.9 Mavericks patch . . ."
         apply_advio_12_mavericks_patch
      fi
   fi

   return $?
}

function apply_advio_patch
{
   if [[ ${ADVIO_VERSION} == 1.2 ]] ; then
      apply_advio_12_patch
      if [[ $? != 0 ]] ; then
         return 1
      fi
   fi

   return 0
}

# *************************************************************************** #
#                         Function 8.18, build_advio                          #
#                                                                             #
# Kevin Griffin, Tue Nov 18 18:25:38 PST 2014                                 #
# Added patch for OS X 10.9 Mavericks.                                        #
# *************************************************************************** #

function build_advio
{
    #
    # Prepare build dir
    #
    prepare_build_dir $ADVIO_BUILD_DIR $ADVIO_FILE
    untarred_ADVIO=$?
    if [[ $untarred_ADVIO == -1 ]] ; then
       warn "Unable to prepare AdvIO Build Directory. Giving up"
       return 1
    fi

    #
    # Apply patches
    #
    info "Patching AdvIO . . ."
    apply_advio_patch
    if [[ $? != 0 ]] ; then
       if [[ $untarred_ADVIO == 1 ]] ; then
          warn "Giving up on AdvIO build because the patch failed."
          return 1
       else 
          warn "Patch failed, but continuing.  I believe that this script\n" \
          warn "tried to apply a patch to an existing directory which had\n" \
          warn "already been patched ... that is, that the patch is\n" \
          warn "failing harmlessly on a second application."
       fi
    fi

    # Configure AdvIO
    info "Configuring AdvIO . . ."
    cd $ADVIO_BUILD_DIR || error "Can't cd to AdvIO build dir."
    # Remove IDL dependencies from the build process
    sed "s%@idldir@%%g" Makefile.in > m2
    mv m2 Makefile.in
    sed "s%FileIO IDL DocIO%FileIO DocIO%g" configure > c2
    mv c2 configure
    chmod 750 ./configure
    info "Invoking command to configure AdvIO"
    ADVIO_DARWIN=""
    if [[ "$OPSYS" == "Darwin" ]]; then
        ADVIO_DARWIN="--host=darwin"
    fi
    env CXX="$CXX_COMPILER" CC="$C_COMPILER" \
       CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
       ./configure --prefix="$VISITDIR/AdvIO/$ADVIO_VERSION/$VISITARCH" --disable-gtktest $ADVIO_DARWIN
    if [[ $? != 0 ]] ; then
       warn "AdvIO configure failed.  Giving up"
       return 1
    fi

    #
    # Build AdvIO
    #
    info "Building AdvIO . . . (~1 minute)"

    $MAKE
    if [[ $? != 0 ]] ; then
       warn "AdvIO build failed.  Giving up"
       return 1
    fi

    # Install AdvIO
    info "Installing AdvIO"
    $MAKE install
    if [[ $? != 0 ]] ; then
       warn "AdvIO install failed.  Giving up"
       return 1
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/AdvIO"
       chgrp -R ${GROUP} "$VISITDIR/AdvIO"
    fi

    cd "$START_DIR"
    info "Done with AdvIO"
    return 0
}

function bv_advio_is_enabled
{
    if [[ $DO_ADVIO == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_advio_is_installed
{
    check_if_installed "AdvIO" $ADVIO_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_advio_build
{
cd "$START_DIR"
if [[ "$DO_ADVIO" == "yes" ]] ; then
    check_if_installed "AdvIO" $ADVIO_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping AdvIO build.  AdvIO is already installed."
    else
        info "Building AdvIO (~1 minutes)"
        build_advio
        if [[ $? != 0 ]] ; then
            error "Unable to build or install AdvIO.  Bailing out."
        fi
        info "Done building AdvIO"
    fi
fi
}
function bv_boost_initialize
{
export DO_BOOST="no"
export ON_BOOST="off"
export USE_SYSTEM_BOOST="no"
add_extra_commandline_args "boost" "alt-boost-dir" 1 "Use alternative directory for boost"
}

function bv_boost_enable
{
DO_BOOST="yes"
ON_BOOST="on"
}

function bv_boost_disable
{
DO_BOOST="no"
ON_BOOST="off"
}

function bv_boost_alt_boost_dir
{
    bv_boost_enable
    USE_SYSTEM_BOOST="yes"
    BOOST_INSTALL_DIR="$1"
}

function bv_boost_depends_on
{
    if [[ "$USE_SYSTEM_BOOST" == "yes" ]]; then
        echo ""
    else
        echo ""
    fi
}

function bv_boost_initialize_vars
{
    if [[ "$USE_SYSTEM_BOOST" == "no" ]]; then
        BOOST_INSTALL_DIR="${VISITDIR}/boost/$BOOST_VERSION/${VISITARCH}"
    fi
}

function bv_boost_info
{
export BOOST_VERSION=${BOOST_VERSION:-"1_57_0"}
export BOOST_FILE=${BOOST_FILE:-"boost_${BOOST_VERSION}.tar.gz"}
export BOOST_COMPATIBILITY_VERSION=${BOOST_COMPATIBILITY_VERSION:-"1_57"}
export BOOST_BUILD_DIR=${BOOST_BUILD_DIR:-"boost_${BOOST_VERSION}"}
export BOOST_URL=${BOOST_URL:-"http://sourceforge.net/projects/boost/files/boost/1.57.0"}
}

function bv_boost_print
{
  printf "%s%s\n" "BOOST_FILE=" "${BOOST_FILE}"
  printf "%s%s\n" "BOOST_VERSION=" "${BOOST_VERSION}"
  printf "%s%s\n" "BOOST_COMPATIBILITY_VERSION=" "${BOOST_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "BOOST_BUILD_DIR=" "${BOOST_BUILD_DIR}"
}

function bv_boost_print_usage
{
printf "%-15s %s [%s]\n" "--boost" "Build BOOST" "${DO_BOOST}"
}

function bv_boost_graphical
{
local graphical_out="BOOST     $BOOST_VERSION($BOOST_FILE)      $ON_BOOST"
echo $graphical_out
}

function bv_boost_host_profile
{
    if [[ "$DO_BOOST" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## BOOST" >> $HOSTCONF
        echo "##" >> $HOSTCONF

        echo "SETUP_APP_VERSION(BOOST $BOOST_VERSION)" >> $HOSTCONF
        if [[ "$USE_SYSTEM_BOOST" == "yes" ]]; then
            echo \
            "VISIT_OPTION_DEFAULT(VISIT_BOOST_DIR $BOOST_INSTALL_DIR)" \
            >> $HOSTCONF 
        else
            echo \
            "VISIT_OPTION_DEFAULT(VISIT_BOOST_DIR \${VISITHOME}/boost/$BOOST_VERSION/\${VISITARCH})" \
            >> $HOSTCONF 
        fi
    fi
}

function bv_boost_ensure
{
    if [[ "$DO_BOOST" == "yes" && "$USE_SYSTEM_BOOST" == "no" ]] ; then
        ensure_built_or_ready "boost" $BOOST_VERSION $BOOST_BUILD_DIR $BOOST_FILE $BOOST_URL 
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_BOOST="no"
            error "Unable to build BOOST.  ${BOOST_FILE} not found."
        fi
    fi
}

function bv_boost_dry_run
{
  if [[ "$DO_BOOST" == "yes" ]] ; then
    echo "Dry run option not set for boost."
  fi
}

function apply_boost_patch
{
    return 0
}

# *************************************************************************** #
#                          Function 8.1, build_boost                           #
# *************************************************************************** #

function build_boost
{
    #
    # Prepare build dir
    #
    prepare_build_dir $BOOST_BUILD_DIR $BOOST_FILE
    untarred_boost=$?
    if [[ $untarred_boost == -1 ]] ; then
       warn "Unable to prepare BOOST Build Directory. Giving Up"
       return 1
    fi

    #
    cd $BOOST_BUILD_DIR || error "Can't cd to BOOST build dir."
    apply_boost_patch
    if [[ $? != 0 ]]; then
        warn "Patch failed, but continuing."
    fi

    libs=""
    build_libs=""

    if [[ "$DO_NEKTAR_PLUS_PLUS" == "yes" ]] ; then
	libs="$libs \
              chrono iostreams thread date_time filesystem \
              system program_options regex timer"

        build_libs="chrono,iostreams,thread,date_time,filesystem,system,program_options,regex,timer"
    fi

    if [[ "$DO_DAMARIS" == "yes" ]] ; then
        libs="$libs \
              date_time system filesystem"
        if [[ "$build_libs" != ""  ]] ; then
          build_libs="$build_libs,date_time,system,filesystem"
        else
          build_libs="date_time,system,filesystem"
        fi
    fi

    if [[ "$build_libs" != ""  ]] ; then

        build_libs=" --with-libraries=\"$build_libs\" "

        info "Configuring BOOST . . . $build_libs"

#        if [[ "$DO_STATIC_BUILD" == "yes" ]]; then
#            cf_build_type="--disable-shared --enable-static"
#        else
#            cf_build_type="--enable-shared --disable-static"
#        fi

#        if [[ "$DO_THREAD_BUILD" == "yes" ]]; then
#            cf_build_thread="--enable-threadsafe --with-pthread"
#        else
#            cf_build_thread=""
#        fi

        # In order to ensure $FORTRANARGS is expanded to build the arguments to
        # configure, we wrap the invokation in 'sh -c "..."' syntax
        info "Invoking command to configure BOOST"
#        info  "./bootstrap.sh $build_libs \
#            --prefix=\"$VISITDIR/boost/$BOOST_VERSION/$VISITARCH\" "

        sh -c "./bootstrap.sh $build_libs \
            --prefix=\"$VISITDIR/boost/$BOOST_VERSION/$VISITARCH\" "

        if [[ $? != 0 ]] ; then
           warn "BOOST configure failed.  Giving up"
           return 1
        fi

        #
        # Build BOOST
        #
        info "Making BOOST . . ."

        sh -c "./b2"
        if [[ $? != 0 ]] ; then
           warn "BOOST build failed.  Giving up"
           return 1
        fi

        #
        # Install into the VisIt third party location.
        #
        info "Installing BOOST . . ."
        sh -c "./b2 install \
              --prefix=\"$VISITDIR/boost/$BOOST_VERSION/$VISITARCH\" "

        if [[ $? != 0 ]] ; then
           warn "BOOST install failed.  Giving up"
           return 1
        fi

        if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
            #
            # Make dynamic executable, need to patch up the install path and
            # version information.
            #
            info "Creating dynamic libraries for BOOST . . ."
            INSTALLNAMEPATH="$VISITDIR/boost/${BOOST_VERSION}/$VISITARCH/lib"

	    for lib in $libs;
	    do
                install_name_tool \
		    -id $INSTALLNAMEPATH/libboost_${lib}.${SO_EXT} \
                    $INSTALLNAMEPATH/libboost_${lib}.${SO_EXT}

		# The filesystem, thread, and chrono libraries depend
		# on the system library so fix up those paths as well
		if [[ $lib == "filesystem" || $lib == "thread" || $lib == "chrono" ]] ; then
		    install_name_tool -change \
			libboost_system.${SO_EXT} $INSTALLNAMEPATH/libboost_system.${SO_EXT} \
			$INSTALLNAMEPATH/libboost_${lib}.${SO_EXT}
		fi

		# The timer library depends on the system and chrono
		# library so fix up those paths as well
		if [[ $lib == "timer" ]] ; then
		    install_name_tool -change \
			libboost_system.${SO_EXT} $INSTALLNAMEPATH/libboost_system.${SO_EXT} \
			$INSTALLNAMEPATH/libboost_${lib}.${SO_EXT}
		    install_name_tool -change \
			libboost_chrono.${SO_EXT} $INSTALLNAMEPATH/libboost_chrono.${SO_EXT} \
			$INSTALLNAMEPATH/libboost_${lib}.${SO_EXT}
		fi
            done
        fi

    else
        info "Installing BOOST . . . headers only"

	mkdir "$VISITDIR/boost"
	mkdir "$VISITDIR/boost/$BOOST_VERSION"
	mkdir "$VISITDIR/boost/$BOOST_VERSION/$VISITARCH"
	mkdir "$VISITDIR/boost/$BOOST_VERSION/$VISITARCH/include"

	cp -r boost $VISITDIR/boost/$BOOST_VERSION/$VISITARCH/include

        if [[ $? != 0 ]] ; then
           warn "BOOST install failed.  Giving up"
           return 1
        fi
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/boost"
       chgrp -R ${GROUP} "$VISITDIR/boost"
    fi
    cd "$START_DIR"
    info "Done with BOOST"
    return 0
}

function bv_boost_is_enabled
{
    if [[ $DO_BOOST == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_boost_is_installed
{

    if [[ "$USE_SYSTEM_BOOST" == "yes" ]]; then
        return 1
    fi

    check_if_installed "boost" $BOOST_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_boost_build
{
cd "$START_DIR"

if [[ "$DO_BOOST" == "yes" && "$USE_SYSTEM_BOOST" == "no" ]] ; then
    check_if_installed "boost" $BOOST_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping BOOST build.  BOOST is already installed."
    else
        info "Building BOOST (~15 minutes)"
        build_boost
        if [[ $? != 0 ]] ; then
            error "Unable to build or install BOOST.  Bailing out."
        fi
        info "Done building BOOST"
    fi
fi
}



# Notes to Windows developers on building boost:
# grab the .zip or .7z tarball and extract
# Open command prompt in the extracted boost_<version> directory
# To build everything and install to default C:\Boost location:
#   .\bootstrap
#   .\b2
#   .\b2 install
#
# To change install location, add --prefix="\path\to\boost" to
# all commands. (All might be overkill, but I experienced problems
# when specified for only bootrap or b2, so I added it to all).
#
# If you want shared libs only, linked with shared CRT, release only, 64-bit:
#
#   .\boostrap --prefix="C:\path\to\where\you\want\boost"
#   .\b2 --prefix="C:\path\to\where\you\want\boost" link=shared runtime-link=shared variant=release threading=multi address-model=64
#   .\b2 --prefix="C:\path\to\where\you\want\boost" link=shared runtime-link=shared variant=release threading=multi address-model=64 install
#
# If you only want a subset of the libraries add a '--with-<lib>' for each 
# library you want:
#   .\boostrap --prefix="C:\path\to\where\you\want\boost"
#   .\b2 --with-system --prefix="C:\path\to\where\you\want\boost" link=shared runtime-link=shared variant=release threading=multi address-model=64
#   .\b2 --with-system --prefix="C:\path\to\where\you\want\boost" link=shared runtime-link=shared variant=release threading=multi address-model=64 install
#
# Still not certain that all the arguments are needed for the 'install' step
# of running b2, but I ran into problems without using them, so ...
#
# I found the following links helpful, as well as running '.\b2 --help'
# once I had bootstrapped.
#
# http://www.boost.org/doc/libs/1_57_0/more/getting_started/windows.html#simplified-build-from-source
# 
# http://www.boost.org/build/doc/html/bbv2/overview/invocation.html
function bv_boxlib_initialize
{
export DO_BOXLIB="no"
export ON_BOXLIB="off"
}

function bv_boxlib_enable
{
DO_BOXLIB="yes"
ON_BOXLIB="on"
}

function bv_boxlib_disable
{
DO_BOXLIB="no"
ON_BOXLIB="off"
}

function bv_boxlib_depends_on
{
echo ""
}

function bv_boxlib_info
{
export BOXLIB_VERSION=${BOXLIB_VERSION:-"1.0.7"}
export BOXLIB_FILE=${BOXLIB_FILE:-"ccse-${BOXLIB_VERSION}.tar.gz"}
export BOXLIB_COMPATIBILITY_VERSION=${BOXLIB_COMPATIBILITY_VERSION:-"1.0.7"}
export BOXLIB_URL=${BOXLIB_URL:-"https://ccse.lbl.gov/Software/tarfiles/"}
export BOXLIB_BUILD_DIR=${BOXLIB_BUILD_DIR:-"ccse-${BOXLIB_VERSION}/Src/C_BaseLib"}
export BOXLIB_MD5_CHECKSUM="d1a8d2c5095e674ddc1dcae8719dff16"
export BOXLIB_SHA256_CHECKSUM="14cb019874ca17092fb8c01500be5c1ed5ad082a95e855dd3c97cabaa244bebc"
}

function bv_boxlib_print
{
  printf "%s%s\n" "BOXLIB_FILE=" "${BOXLIB_FILE}"
  printf "%s%s\n" "BOXLIB_VERSION=" "${BOXLIB_VERSION}"
  printf "%s%s\n" "BOXLIB_COMPATIBILITY_VERSION=" "${BOXLIB_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "BOXLIB_BUILD_DIR=" "${BOXLIB_BUILD_DIR}"
}

function bv_boxlib_print_usage
{
printf "%-15s %s [%s]\n" "--boxlib"  "Build Boxlib" "$DO_BOXLIB" 
}

function bv_boxlib_graphical
{
  local graphical_output="Boxlib   $BOXLIB_VERSION($BOXLIB_FILE)    $ON_BOXLIB"
  echo $graphical_output
}

function bv_boxlib_host_profile
{
    if [[ "$DO_BOXLIB" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## Boxlib" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_BOXLIB_DIR \${VISITHOME}/boxlib/$BOXLIB_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
    fi

}

function bv_boxlib_ensure
{
    if [[ "$DO_BOXLIB" == "yes" ]] ; then
        ensure_built_or_ready "boxlib" $BOXLIB_VERSION $BOXLIB_BUILD_DIR $BOXLIB_FILE $BOXLIB_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_BOXLIB="no"
            error "Unable to build Boxlib.  ${BOXLIB_FILE} not found."
        fi
    fi
}

function bv_boxlib_dry_run
{
  if [[ "$DO_BOXLIB" == "yes" ]] ; then
    echo "Dry run option not set for boxlib."
  fi
}
# *************************************************************************** #
#                         Function 8.8, build_boxlib                          #
# *************************************************************************** #

function build_boxlib
{
    #
    # Prepare build dir
    #
    prepare_build_dir $BOXLIB_BUILD_DIR $BOXLIB_FILE
    untarred_boxlib=$?
    if [[ $untarred_boxlib == -1 ]] ; then
       warn "Unable to prepare Boxlib Build Directory. Giving Up"
       return 1
    fi

    cd $BOXLIB_BUILD_DIR || error "Can't cd to BoxLib build dir."

    #
    # Build BoxLib
    #
    info "Building Boxlib. . . (~4 minutes)"

    if [[ "$OPSYS" == "AIX" ]]; then
        $MAKE -f GNUmakefile CXX="$CXX_COMPILER" CC="$C_COMPILER" \
           CCFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
           DEBUG="FALSE" DIM=3 COMP="xlC" USE_MPI="FALSE" \
           BL_NO_FORT="TRUE" || error "Boxlib build failed. Giving up"

        $MAKE -f GNUmakefile CXX="$CXX_COMPILER" CC="$C_COMPILER" \
           CCFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
           DEBUG="FALSE" DIM=2 COMP="xlC" USE_MPI="FALSE" \
           BL_NO_FORT="TRUE" || error "Boxlib build failed. Giving up"
    elif [[ "$OPSYS" == "Darwin" ]]; then
        $MAKE -f GNUmakefile CXX="$CXX_COMPILER" CC="$C_COMPILER" \
           CCFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
           DEBUG="FALSE" DIM=3 USE_MPI="FALSE" BL_MANGLE_SYMBOLS_WITH_DIM="TRUE" \
           BL_NO_FORT="TRUE" || error "Boxlib build failed. Giving up"

        $MAKE -f GNUmakefile CXX="$CXX_COMPILER" CC="$C_COMPILER" \
           CCFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
           DEBUG="FALSE" DIM=2 USE_MPI="FALSE" BL_MANGLE_SYMBOLS_WITH_DIM="TRUE" \
           BL_NO_FORT="TRUE" || error "Boxlib build failed. Giving up"
    else
        $MAKE -f GNUmakefile CXX="$CXX_COMPILER" CC="$C_COMPILER" \
           CCFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
           DEBUG="FALSE" DIM=3 USE_MPI="FALSE" \
           BL_NO_FORT="TRUE" || error "Boxlib build failed. Giving up"

        $MAKE -f GNUmakefile CXX="$CXX_COMPILER" CC="$C_COMPILER" \
           CCFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
           DEBUG="FALSE" DIM=2 USE_MPI="FALSE" \
           BL_NO_FORT="TRUE" || error "Boxlib build failed. Giving up"
    fi

    #
    # Create dynamic library for Darwin
    #
    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
        INSTALLNAMEPATH="$VISITDIR/boxlib/$BOXLIB_VERSION/$VISITARCH/lib"

        $CXX_COMPILER -dynamiclib -o libbox3D.$SO_EXT o/3d.Darwin.*/*.o \
          -lSystem -Wl,-headerpad_max_install_names \
          -Wl,-install_name,$INSTALLNAMEPATH/libbox3D.$SO_EXT \
          -Wl,-compatibility_version,$BOXLIB_COMPATIBILITY_VERSION \
          -Wl,-current_version,$BOXLIB_VERSION || \
          error "Creation of dynamic 3D Boxlib library failed. Giving up!"
        $CXX_COMPILER -dynamiclib -o libbox2D.$SO_EXT o/2d.Darwin.*/*.o \
          -lSystem -Wl,-headerpad_max_install_names \
          -Wl,-install_name,$INSTALLNAMEPATH/libbox2D.$SO_EXT \
          -Wl,-compatibility_version,$BOXLIB_COMPATIBILITY_VERSION \
          -Wl,-current_version,$BOXLIB_VERSION || \
          error "Creation of dynamic 2D Boxlib library failed. Giving up!"
        boxlib_ext=$SO_EXT
    else
        mv libbox3d.*.a libbox3D.a
        mv libbox2d.*.a libbox2D.a
        boxlib_ext=a
    fi

    #
    # Install into the VisIt third party location.
    #
    info "Installing Boxlib . . ."

    mkdir "$VISITDIR/boxlib"
    mkdir "$VISITDIR/boxlib/$BOXLIB_VERSION"
    mkdir "$VISITDIR/boxlib/$BOXLIB_VERSION/$VISITARCH"
    mkdir "$VISITDIR/boxlib/$BOXLIB_VERSION/$VISITARCH/include"
    mkdir "$VISITDIR/boxlib/$BOXLIB_VERSION/$VISITARCH/lib"

    cp libbox3D.$boxlib_ext \
       "$VISITDIR/boxlib/$BOXLIB_VERSION/$VISITARCH/lib/" || \
       error "Boxlib install failed. Giving up!"

    cp libbox2D.$boxlib_ext \
       "$VISITDIR/boxlib/$BOXLIB_VERSION/$VISITARCH/lib/" || \
       error "Boxlib install failed. Giving up!"

    cp *.H "$VISITDIR/boxlib/$BOXLIB_VERSION/$VISITARCH/include" || \
       error "Boxlib install failed. Giving up!"

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/boxlib"
       chgrp -R ${GROUP} "$VISITDIR/boxlib"
    fi

    cd "$START_DIR"
    info "Done with BoxLib"
    return 0
}

function bv_boxlib_is_enabled
{
    if [[ $DO_BOXLIB == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_boxlib_is_installed
{
    check_if_installed "boxlib" $BOXLIB_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_boxlib_build
{
cd "$START_DIR"
if [[ "$DO_BOXLIB" == "yes" ]] ; then
    check_if_installed "boxlib" $BOXLIB_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping Boxlib build.  Boxlib is already installed."
    else
        info "Building Boxlib (~2 minutes)"
        build_boxlib
        if [[ $? != 0 ]] ; then
            error "Unable to build or install Boxlib.  Bailing out."
        fi
        info "Done building Boxlib"
    fi
fi
}
function bv_ccmio_initialize
{
export DO_CCMIO="no"
export ON_CCMIO="off"
}

function bv_ccmio_enable
{
DO_CCMIO="yes"
ON_CCMIO="on"
}

function bv_ccmio_disable
{
DO_CCMIO="no"
ON_CCMIO="off"
}

function bv_ccmio_depends_on
{
echo ""
}

function bv_ccmio_info
{
export CCMIO_FILE=${CCMIO_FILE:-"libccmio-2.6.1.tar.gz"}
export CCMIO_VERSION=${CCMIO_VERSION:-"2.6.1"}
export CCMIO_COMPATIBILITY_VERSION=${CCMIO_COMPATIBILITY_VERSION:-"2.0"}
export CCMIO_BUILD_DIR=${CCMIO_BUILD_DIR:-"libccmio-2.6.1"}
export CCMIO_MD5_CHECKSUM="f81fbdfb960b1a4f3bcc7feee491efe4"
export CCMIO_SHA256_CHECKSUM=""

}

function bv_ccmio_print
{
  printf "%s%s\n" "CCMIO_FILE=" "${CCMIO_FILE}"
  printf "%s%s\n" "CCMIO_VERSION=" "${CCMIO_VERSION}"
  printf "%s%s\n" "CCMIO_COMPATIBILITY_VERSION=" "${CCMIO_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "CCMIO_BUILD_DIR=" "${CCMIO_BUILD_DIR}"
}

function bv_ccmio_print_usage
{
printf "%-15s %s [%s]\n" "--ccmio"   "Build Star-CD support" "$DO_CCMIO"
}

function bv_ccmio_graphical
{
local graphical_out="CCMIO    $CCMIO_VERSION($CCMIO_FILE) $ON_CCMIO"
echo $graphical_out
}

function bv_ccmio_host_profile
{
    if [[ "$DO_CCMIO" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## CCMIO" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_CCMIO_DIR \${VISITHOME}/ccmio/$CCMIO_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
    fi
}

function bv_ccmio_ensure
{
    if [[ "$DO_CCMIO" == "yes" ]] ; then
        ensure_built_or_ready "ccmio"  $CCMIO_VERSION $CCMIO_BUILD_DIR  $CCMIO_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_CCMIO="no"
            error "Unable to build CCMIO.  ${CCMIO_FILE} not found."
        fi
    fi
}

function bv_ccmio_dry_run
{
  if [[ "$DO_CCMIO" == "yes" ]] ; then
    echo "Dry run option not set for ccmio."
  fi
}

function apply_ccmio_261_darwin_patch
{
   patch -p0 << \EOF
diff -c a/config/config.gnu.to.star libccmio-2.6.1/config/config.gnu.to.star
*** a/config/config.gnu.to.star
--- libccmio-2.6.1/config/config.gnu.to.star
*************** case ${1:-null}-${2:-null} in
*** 34,39 ****
--- 34,40 ----
      x86_64-unknown-linux-gnu-null)     echo linux64_2.4-x86-glibc_2.2.5     ;;
      ppc64-unknown-linux-gnu-null)      echo linux64_2.6-pwr4-glibc_2.3.3    ;;
      i386-apple-darwin8-null)           echo i386-apple-darwin8              ;;
+     powerpc-apple-darwin7-null)        echo powerpc-apple-darwin7           ;;
      *)                                 echo unknown                         ;;
  esac
  
diff -c a/config/config.system libccmio-2.6.1/config/config.system 
*** a/config/config.system
--- libccmio-2.6.1/config/config.system
*************** case ${SYSTEM} in
*** 85,93 ****
      ppc64-unknown-linux-gnu)
  	echo ppc64-unknown-linux-gnu ;;
  
!     i386-apple-darwin8.11.1)
  	echo i386-apple-darwin8 ;;
  
      *)
          echo unknown
          echo System type ${SYSTEM} not supported! 1>&2 ;;
--- 85,96 ----
      ppc64-unknown-linux-gnu)
  	echo ppc64-unknown-linux-gnu ;;
  
!     i386-apple-darwin8* | i386-apple-darwin9* | i386-apple-darwin10* | i386-apple-darwin11* | i386-apple-darwin12* | i386-apple-darwin13*)
  	echo i386-apple-darwin8 ;;
  
+     powerpc-apple-darwin7* | powerpc-apple-darwin8* | powerpc-apple-darwin9* )
+ 	echo powerpc-apple-darwin7 ;;
+ 
      *)
          echo unknown
          echo System type ${SYSTEM} not supported! 1>&2 ;;
EOF
   if [[ $? != 0 ]] ; then
       warn "Unable to patch CCMIO. Wrong version?"
       return 1
   fi

   return 0
}

function apply_ccmio_261_linux_ppc_patch
{
  patch -p1 << \EOF
--- visit-build-old/libccmio-2.6.1/config/linux64_2.6-pwr4-glibc_2.3.3/qmake.conf	2009-03-19 21:31:31.207392275 -0400
+++ visit-build/libccmio-2.6.1/config/linux64_2.6-pwr4-glibc_2.3.3/qmake.conf	2009-03-19 21:31:54.522915173 -0400
@@ -72,7 +72,7 @@
 QMAKE_UIC		= $(QTDIR)/bin/uic
 
 QMAKE_AR		= ar cq
-QMAKE_RANLIB		= ranlib -X64
+QMAKE_RANLIB		= ranlib
 
 QMAKE_TAR		= tar -cf
 QMAKE_GZIP		= gzip -9f
EOF
   if [[ $? != 0 ]] ; then
        warn "Unable to apply linux ppc patch to CCMIO 2.6.1."
        return 1
   else
        return 0
   fi
}

function apply_ccmio_261_aix_patch
{
  patch -p0 <<\EOF
diff -c a/config/aix64_5.1-pwr4/qmake.conf libccmio-2.6.1/config/aix64_5.1-pwr4/qmake.conf
*** a/config/aix64_5.1-pwr4/qmake.conf
--- libccmio-2.6.1/config/aix64_5.1-pwr4/qmake.conf
***************
*** 15,21 ****
  QMAKE_LEXFLAGS		= 
  QMAKE_YACC		= yacc
  QMAKE_YACCFLAGS		= -d
! QMAKE_CFLAGS		= -q64 -ma -qrndsngl -qnomaf -qstrict -DLARGE_FILES
  # -qwarn64 turns on too many bogus warnings and shadows real warnings
  #QMAKE_CFLAGS_WARN_ON	= -qwarn64
  QMAKE_CFLAGS_WARN_ON    =
--- 15,21 ----
  QMAKE_LEXFLAGS		= 
  QMAKE_YACC		= yacc
  QMAKE_YACCFLAGS		= -d
! QMAKE_CFLAGS		= -ma -qrndsngl -qnomaf -qstrict -DLARGE_FILES
  # -qwarn64 turns on too many bogus warnings and shadows real warnings
  #QMAKE_CFLAGS_WARN_ON	= -qwarn64
  QMAKE_CFLAGS_WARN_ON    =
***************
*** 49,61 ****
  QMAKE_LINK		= xlC
  QMAKE_LINK_THREAD	= xlC_r
  QMAKE_LINK_SHLIB	= ld
! QMAKE_LINK_SHLIB_CMD	= makeC++SharedLib -p 0 -X64 \
  			    -o $(TARGETD) \
  			    $(LFLAGS) $(OBJECTS) $(OBJMOC) $(LIBS); \
  			  $(AR) lib$(QMAKE_TARGET).a $(TARGETD); \
  			  $(RANLIB) lib$(QMAKE_TARGET).a; \
  			  mv lib$(QMAKE_TARGET).a $(DESTDIR)
! QMAKE_LFLAGS		= -q64 -qnotempinc
  QMAKE_LFLAGS_RELEASE	=
  QMAKE_LFLAGS_DEBUG	=
  QMAKE_LFLAGS_SHLIB	=
--- 49,61 ----
  QMAKE_LINK		= xlC
  QMAKE_LINK_THREAD	= xlC_r
  QMAKE_LINK_SHLIB	= ld
! QMAKE_LINK_SHLIB_CMD	= makeC++SharedLib -p 0 \
  			    -o $(TARGETD) \
  			    $(LFLAGS) $(OBJECTS) $(OBJMOC) $(LIBS); \
  			  $(AR) lib$(QMAKE_TARGET).a $(TARGETD); \
  			  $(RANLIB) lib$(QMAKE_TARGET).a; \
  			  mv lib$(QMAKE_TARGET).a $(DESTDIR)
! QMAKE_LFLAGS		= -qnotempinc
  QMAKE_LFLAGS_RELEASE	=
  QMAKE_LFLAGS_DEBUG	=
  QMAKE_LFLAGS_SHLIB	=
***************
*** 77,84 ****
  QMAKE_MOC		= $(QTDIR)/bin/moc
  QMAKE_UIC		= $(QTDIR)/bin/uic
  
! QMAKE_AR		= ar -X64 cq
! QMAKE_RANLIB		= ranlib -X64
  
  QMAKE_TAR		= tar -cf
  QMAKE_GZIP		= gzip -9f
--- 77,84 ----
  QMAKE_MOC		= $(QTDIR)/bin/moc
  QMAKE_UIC		= $(QTDIR)/bin/uic
  
! QMAKE_AR		= ar cq
! QMAKE_RANLIB		= ranlib
  
  QMAKE_TAR		= tar -cf
  QMAKE_GZIP		= gzip -9f
EOF
   if [[ $? != 0 ]] ; then
        warn "Unable to apply aix patch to CCMIO 2.6.1."
        return 1
   else
        return 0
   fi
}

function apply_ccmio_261_patch
{
   if [[ "$OPSYS" == "Darwin" ]]; then
       apply_ccmio_261_darwin_patch
       if [[ $? != 0 ]] ; then
           return 1
       fi
   fi
   if [[ `uname -m` == "ppc64" ]]; then
       apply_ccmio_261_linux_ppc_patch
       if [[ $? != 0 ]] ; then
           return 1
       fi
   fi
   apply_ccmio_261_aix_patch
   if [[ $? != 0 ]] ; then
       return 1
   fi

   return 0
}

function apply_ccmio_patch
{
   if [[ ${CCMIO_VERSION} == 2.6.1 ]] ; then
       apply_ccmio_261_patch
       if [[ $? != 0 ]] ; then
           return 1
       fi
   fi

   return 0
}

# *************************************************************************** #
#                         Function 8.11, build_ccmio                          #
#                                                                             #
# Kevin Griffin, Thu Nov 13 18:20:10 PST 2014                                 #
# Added additional option (i386-apple-darwin13*) to patch                     #
# apply_ccmio_261_darwin_patch to support OS X 10.9 Mavericks.                #
# *************************************************************************** #

function build_ccmio
{
    #
    # Prepare build dir
    #
    prepare_build_dir $CCMIO_BUILD_DIR $CCMIO_FILE
    untarred_ccmio=$?
    if [[ $untarred_ccmio == -1 ]] ; then
       warn "Unable to prepare CCMIO Build Directory. Giving Up"
       return 1
    fi

    #
    # Apply patches
    #
    info "Patching CCMIO . . ."
    apply_ccmio_patch
    if [[ $? != 0 ]] ; then
       if [[ $untarred_ccmio == 1 ]] ; then
          warn "Giving up on CCMIO build because the patch failed."
          return 1
       else
          warn "Patch failed, but continuing.  I believe that this script" \
               "tried to apply a patch to an existing directory which had" \
               "already been patched ... that is, that the patch is" \
               "failing harmlessly on a second application."
       fi
    fi

    #
    # Do some extra copies
    #
    if [[ ${CCMIO_VERSION} == 2.6.1 ]] ; then
       if [[ "$OPSYS" == "Darwin" ]]; then
           # Check for PPC
           MACH=$(uname -m)
           if [[ "$MACH" == "Power Macintosh" ]] ; then
               mkdir ${CCMIO_BUILD_DIR}/config/powerpc-apple-darwin7
               cp ${QT_BUILD_DIR}/bin/qmake \
	           ${CCMIO_BUILD_DIR}/config/powerpc-apple-darwin7
               cp ${CCMIO_BUILD_DIR}/config/i386-apple-darwin8/qmake.conf \
                   ${CCMIO_BUILD_DIR}/config/powerpc-apple-darwin7
               cp ${QT_BUILD_DIR}/mkspecs/${QT_PLATFORM}/qplatformdefs.h \
                   ${CCMIO_BUILD_DIR}/config/powerpc-apple-darwin7
           fi
       fi
    fi
    #
    info "Configuring CCMIO . . ."
    cd $CCMIO_BUILD_DIR || error "Can't cd to CCMIO build dir."

    #
    # Build CCMIO
    #
    info "Building CCMIO . . . (~1 minutes)"

    if [[ "$OPSYS" == "Darwin" ]]; then
        env RELEASE=1 SHARED=1 $MAKE CXX="$CXX_COMPILER" CC="$C_COMPILER" \
           CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS"
    else
        env RELEASE=1 STATIC=1 $MAKE CXX="$CXX_COMPILER" CC="$C_COMPILER" \
           CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS"
    fi
    if [[ $? != 0 ]] ; then
       echo "CCMIO build failed.  Giving up"
       return 1
    fi
    info "Installing CCMIO . . ."

    mkdir $VISITDIR/ccmio
    mkdir $VISITDIR/ccmio/${CCMIO_VERSION}
    mkdir $VISITDIR/ccmio/${CCMIO_VERSION}/$VISITARCH
    mkdir $VISITDIR/ccmio/${CCMIO_VERSION}/$VISITARCH/lib
    mkdir $VISITDIR/ccmio/${CCMIO_VERSION}/$VISITARCH/include
    ln -s $VISITDIR/ccmio/${CCMIO_VERSION}/$VISITARCH/include \
        $VISITDIR/ccmio/${CCMIO_VERSION}/$VISITARCH/include/libccmio
    cp libccmio/ccmio*.h $VISITDIR/ccmio/${CCMIO_VERSION}/$VISITARCH/include

    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
        #
        # Make dynamic executable
        #
        info "Creating dynamic libraries for CCMIO . . ."

        INSTALLNAMEPATH="$VISITDIR/ccmio/${CCMIO_VERSION}/$VISITARCH/lib"

        cp lib/release-shared/libadf.dylib .
        cp lib/release-shared/libccmio.dylib .
        install_name_tool -id \
          "$INSTALLNAMEPATH/libadf.$SO_EXT" "libadf.$SO_EXT"
        install_name_tool -id \
          "$INSTALLNAMEPATH/libccmio.$SO_EXT" "libccmio.$SO_EXT"
        install_name_tool -change \
          libadf.dylib.5.01.000 "$INSTALLNAMEPATH/libadf.$SO_EXT" \
         "libccmio.$SO_EXT"
        cp "libadf.$SO_EXT" \
          "$VISITDIR/ccmio/${CCMIO_VERSION}/$VISITARCH/lib/libadf.$SO_EXT"
        cp "libccmio.$SO_EXT" \
          "$VISITDIR/ccmio/${CCMIO_VERSION}/$VISITARCH/lib/libccmio.$SO_EXT"
    else
        cp `ls lib/*/release-static/libadf.a` \
           $VISITDIR/ccmio/${CCMIO_VERSION}/$VISITARCH/lib
        cp `ls lib/*/release-static/libccmio.a` \
           $VISITDIR/ccmio/${CCMIO_VERSION}/$VISITARCH/lib
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/ccmio"
       chgrp -R ${GROUP} "$VISITDIR/ccmio"
    fi
    cd "$START_DIR"
    info "Done with CCMIO"
    return 0
}

function bv_ccmio_is_enabled
{
    if [[ $DO_CCMIO == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_ccmio_is_installed
{
    check_if_installed "ccmio" $CCMIO_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_ccmio_build
{
cd "$START_DIR"
if [[ "$DO_CCMIO" == "yes" ]] ; then
    check_if_installed "ccmio" $CCMIO_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping CCMIO build.  CCMIO is already installed."
    else
        info "Building CCMIO (~1 minutes)"
        build_ccmio
        if [[ $? != 0 ]] ; then
            error "Unable to build or install CCMIO.  Bailing out."
        fi
        info "Done building CCMIO"
    fi
fi
}
function bv_cfitsio_initialize
{
export DO_CFITSIO="no"
export ON_CFITSIO="off"
}

function bv_cfitsio_enable
{
DO_CFITSIO="yes"
ON_CFITSIO="on"
}

function bv_cfitsio_disable
{
DO_CFITSIO="no"
ON_CFITSIO="off"
}

function bv_cfitsio_depends_on
{
echo ""
}

function bv_cfitsio_info
{
export CFITSIO_FILE=${CFITSIO_FILE:-"cfitsio3006.tar.gz"}
export CFITSIO_VERSION=${CFITSIO_VERSION:-"3006"}
export CFITSIO_COMPATIBILITY_VERSION=${CFITSIO_COMPATIBILITY_VERSION:-"3.0"}
export CFITSIO_BUILD_DIR=${CFITSIO_BUILD_DIR:-"cfitsio"}
export CFITSIO_MD5_CHECKSUM="4aacb54dcf833c8075d1f6515ba069ca"
export CFITSIO_SHA256_CHECKSUM=""
}

function bv_cfitsio_print
{
  printf "%s%s\n" "CFITSIO_FILE=" "${CFITSIO_FILE}"
  printf "%s%s\n" "CFITSIO_VERSION=" "${CFITSIO_VERSION}"
  printf "%s%s\n" "CFITSIO_COMPATIBILITY_VERSION=" "${CFITSIO_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "CFITSIO_BUILD_DIR=" "${CFITSIO_BUILD_DIR}"
}

function bv_cfitsio_print_usage
{
printf "%-15s %s [%s]\n" "--cfitsio" "Build CFITSIO" "$DO_CFITSIO"
}

function bv_cfitsio_graphical
{
local graphical_out="CFITSIO  $CFITSIO_VERSION($CFITSIO_FILE)   $ON_CFITSIO"
echo $graphical_out
}

function bv_cfitsio_host_profile
{
    if [[ "$DO_CFITSIO" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## CFITSIO" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_CFITSIO_DIR \${VISITHOME}/cfitsio/$CFITSIO_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
    fi

}
function bv_cfitsio_ensure
{
    if [[ "$DO_CFITSIO" == "yes" ]] ; then
        ensure_built_or_ready "cfitsio" $CFITSIO_VERSION $CFITSIO_BUILD_DIR $CFITSIO_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_CFITSIO="no"
            error "Unable to build CFITSIO.  ${CFITSIO_FILE} not found."
        fi
    fi
}

function bv_cfitsio_dry_run
{
  if [[ "$DO_CFITSIO" == "yes" ]] ; then
    echo "Dry run option not set for cfitsio."
  fi
}
# *************************************************************************** #
#                         Function 8.9, build_cfitsio                         #
# *************************************************************************** #

function build_cfitsio
{
    #
    # Prepare build dir
    #
    prepare_build_dir $CFITSIO_BUILD_DIR $CFITSIO_FILE
    untarred_cfitsio=$?
    if [[ $untarred_cfitsio == -1 ]] ; then
       warn "Unable to prepare CFITSIO Build Directory. Giving Up"
       return 1
    fi

    #
    info "Configuring CFITSIO . . ."
    cd $CFITSIO_BUILD_DIR || error "Can't cd to cfits IO build dir."

    env CXX="$CXX_COMPILER" CC="$C_COMPILER" \
       CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
       ./configure \
       --prefix="$VISITDIR/cfitsio/$CFITSIO_VERSION/$VISITARCH"
    if [[ $? != 0 ]] ; then
       warn "CFITSIO configure failed.  Giving up"
       return 1
    fi

    #
    # Build CFITSIO
    #
    info "Building CFITSIO . . . (~2 minutes)"

    $MAKE
    if [[ $? != 0 ]] ; then
       warn "CFITSIO build failed.  Giving up"
       return 1
    fi

    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
        #
        # Make dynamic executable
        #
        info "Creating dynamic libraries for CFITSIO . . ."

        INSTALLNAMEPATH="$VISITDIR/cfitsio/${CFITSIO_VERSION}/$VISITARCH/lib"
## switch back to gcc "external relocation entries" restFP saveFP
##      /usr/bin/libtool -o libcfitsio.$SO_EXT -dynamic libcfitsio.a -lSystem \
##      -headerpad_max_install_names \
##      -install_name $INSTALLNAMEPATH/libcfitsio.$SO_EXT \
##      -compatibility_version $CFITSIO_COMPATIBILITY_VERSION \
##      -current_version $CFITSIO_VERSION
        gcc -o libcfitsio.$SO_EXT -dynamiclib *.o -lSystem \
           -Wl,-headerpad_max_install_names \
           -Wl,-install_name,$INSTALLNAMEPATH/libcfitsio.$SO_EXT \
           -Wl,-compatibility_version,$CFITSIO_COMPATIBILITY_VERSION \
           -Wl,-current_version,$CFITSIO_VERSION
        if [[ $? != 0 ]] ; then
           warn "Creating dynamic CFITSIO library failed.  Giving up"
           return 1
        fi
#       cp libcfitsio.$SO_EXT "$VISITDIR/cfitsio/$CFITSIO_VERSION/$VISITARCH/lib"
    fi
    #
    # Install into the VisIt third party location.
    #
    info "Installing CFITSIO . . ."

    mkdir "$VISITDIR/cfitsio"
    mkdir "$VISITDIR/cfitsio/$CFITSIO_VERSION"
    mkdir "$VISITDIR/cfitsio/$CFITSIO_VERSION/$VISITARCH"
    $MAKE install
    if [[ $? != 0 ]] ; then
       warn "CFITSIO install failed.  Giving up"
       return 1
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/cfitsio"
       chgrp -R ${GROUP} "$VISITDIR/cfitsio"
    fi
    cd "$START_DIR"
    info "Done with CFITSIO"
    return 0
}

function bv_cfitsio_is_enabled
{
    if [[ $DO_CFITSIO == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_cfitsio_is_installed
{
    check_if_installed "cfitsio" $CFITSIO_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_cfitsio_build
{
cd "$START_DIR"
if [[ "$DO_CFITSIO" == "yes" ]] ; then
    check_if_installed "cfitsio" $CFITSIO_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping CFITSIO build.  CFITSIO is already installed."
    else
        info "Building CFITSIO (~2 minutes)"
        build_cfitsio
        if [[ $? != 0 ]] ; then
            error "Unable to build or install CFITSIO.  Bailing out."
        fi
        info "Done building CFITSIO"
    fi
fi
}
function bv_cgns_initialize
{
export DO_CGNS="no"
export ON_CGNS="off"
}

function bv_cgns_enable
{
DO_CGNS="yes"
ON_CGNS="on"
}

function bv_cgns_disable
{
DO_CGNS="no"
ON_CGNS="off"
}

function bv_cgns_depends_on
{
    local depends=""
    if [[ "$DO_HDF5" == "yes" ]] ; then
        depends="hdf5"
        if [[ "$DO_SZIP" == "yes" ]] ; then
            depends="szip hdf5"
        fi
    fi
    
    echo $depends
}

function bv_cgns_info
{
export CGNS_FILE=${CGNS_FILE:-"cgnslib_3.2.1.tar.gz"}
export CGNS_VERSION=${CGNS_VERSION:-"3.2.1"}
export CGNS_COMPATIBILITY_VERSION=${CGNS_COMPATIBILITY_VERSION:-"3.2"}
export CGNS_BUILD_DIR=${CGNS_BUILD_DIR:-"cgnslib_3.2.1/src"}
export CGNS_MD5_CHECKSUM="2d26f88b2058dcd0ee5ce58f483bfccb"
export CGNS_SHA256_CHECKSUM="34306316f04dbf6484343a4bc611b3bf912ac7dbc3c13b581defdaebbf6c1fc3"

}

function bv_cgns_print
{
  printf "%s%s\n" "CGNS_FILE=" "${CGNS_FILE}"
  printf "%s%s\n" "CGNS_VERSION=" "${CGNS_VERSION}"
  printf "%s%s\n" "CGNS_COMPATIBILITY_VERSION=" "${CGNS_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "CGNS_BUILD_DIR=" "${CGNS_BUILD_DIR}"
}

function bv_cgns_print_usage
{
printf "%-15s %s [%s]\n" "--cgns"    "Build CGNS" "$DO_CGNS" 
}

function bv_cgns_graphical
{
local graphical_out="CGNS     $CGNS_VERSION($CGNS_FILE)      $ON_CGNS"
echo $graphical_out
}

function bv_cgns_host_profile
{
    if [[ "$DO_CGNS" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## CGNS" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_CGNS_DIR \${VISITHOME}/cgns/$CGNS_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
        if [[ "$DO_HDF5" == "yes" ]] ; then
            echo \
            "VISIT_OPTION_DEFAULT(VISIT_CGNS_LIBDEP HDF5_LIBRARY_DIR hdf5 \${VISIT_HDF5_LIBDEP} TYPE STRING)" \
            >> $HOSTCONF
        fi
    fi

}

function bv_cgns_ensure
{
    if [[ "$DO_CGNS" == "yes" ]] ; then
        ensure_built_or_ready "cgns" $CGNS_VERSION $CGNS_BUILD_DIR $CGNS_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_CGNS="no"
            error "Unable to build CGNS.  ${CGNS_FILE} not found."
        fi
    fi
}

function bv_cgns_dry_run
{
  if [[ "$DO_CGNS" == "yes" ]] ; then
    echo "Dry run option not set for cgns."
  fi
}

function apply_cgns_321_darwin_patch
{
   patch -p0 << \EOF
diff -c cgnslib_3.2.1/src/configure.orig cgnslib_3.2.1/src/configure
*** cgnslib_3.2.1/src/configure.orig	2015-04-27 15:11:36.000000000 -0700
--- cgnslib_3.2.1/src/configure	2015-04-27 14:24:48.000000000 -0700
***************
*** 2324,2333 ****
  echo "$ac_t""$shared" 1>&6
  
  if test $shared = all; then
!   exts="so sl a"
    shared=yes
  else
!   exts="a so sl"
  fi
  if test $shared = yes; then
    cgnsdir=`pwd`
--- 2324,2333 ----
  echo "$ac_t""$shared" 1>&6
  
  if test $shared = all; then
!   exts="dylib so sl a"
    shared=yes
  else
!   exts="dylib a so sl"
  fi
  if test $shared = yes; then
    cgnsdir=`pwd`
***************
*** 2352,2363 ****
        shared=no
      else
        CFGFLAGS="-fPIC $CFGFLAGS"
!       AR_LIB="\$(CC) -shared $SYSCFLAGS -Wl,-rpath,$LIBDIR:$cgnsdir/$BUILDDIR -o"
!       EXT_LIB=so
      fi
    fi
    if test $shared = yes; then
!     RAN_LIB="\$(STRIP)"
    fi
  fi
  
--- 2352,2363 ----
        shared=no
      else
        CFGFLAGS="-fPIC $CFGFLAGS"
!       AR_LIB="\$(CC) -shared $SYSCFLAGS -Wl,-L$with_hdf5/lib -Wl,-lhdf5 -o"
!       EXT_LIB=dylib
      fi
    fi
    if test $shared = yes; then
!     RAN_LIB="\$(STRIP) -x"
    fi
  fi

EOF
   if [[ $? != 0 ]] ; then
      return 1
   fi

   return 0
}

function apply_cgns_321_zlib_patch
{
   patch -p0 << \EOF
diff -c cgnslib_3.2.1/src/configure.orig cgnslib_3.2.1/src/configure
*** cgnslib_3.2.1/src/configure.orig	2013-06-19 21:04:00.000000000 -0700
--- cgnslib_3.2.1/src/configure	2015-04-27 15:03:16.000000000 -0700
***************
*** 2490,2495 ****
--- 2490,2496 ----
  if test "${with_zlib+set}" = set; then
    withval="$with_zlib"
    withzlib=$withval
+   ZLIBLIB=$withval
  else
    withzlib="no"
  fi
***************
*** 2499,2504 ****
--- 2500,2506 ----
    else
      H5NEEDZLIB=1
      if test -z "$withzlib" || test "$withzlib" = "yes"; then
+       ZLIBLIB=""
        zlibdir=""
        echo "$ac_t""yes" 1>&6
        ac_safe=`echo "zlib.h" | sed 'y%./+-%__p_%'`
EOF
   if [[ $? != 0 ]] ; then
      return 1
   fi

   return 0
}

function apply_cgns_321_patch
{

   if [[ "$OPSYS" == "Darwin" ]] ; then
       info "Applying OS X patch . . ."
       apply_cgns_321_darwin_patch
       apply_cgns_321_zlib_patch
   else 
       info "Applying patch . . ."
       apply_cgns_321_zlib_patch
   fi

   return $?
}

function apply_cgns_patch
{
   if [[ ${CGNS_VERSION} == 3.2.1 ]] ; then
      apply_cgns_321_patch
      if [[ $? != 0 ]] ; then
         return 1
      fi
   fi

   return 0
}

# *************************************************************************** #
#                         Function 8.5, build_cgns                            #
#                                                                             #
# Kevin Griffin, Tue Dec 30 11:39:02 PST 2014                                 #
# Added a patch for the configure script to correctly locate and use the      #
# the dylib for hdf5 and szip. Added the correct linker options to the        #
# dynamic library creation.                                                   #
#                                                                             #
# Kevin Griffin, Fri Jan 16 10:28:21 PST 2015                                 #
# Fixed the --with-szip and --with-zlib to specify the full path to the       #
# library for both OSX and linux                                              #
#                                                                             #
# Kevin Griffin, Mon Apr 27 15:20:43 PDT 2015                                 #
# Patched the configure file to use the zlib library specified in the         #
# --with-zlib option.                                                         #
#                                                                             #
# *************************************************************************** #

function build_cgns
{
    #
    # Prepare build dir
    #
    prepare_build_dir $CGNS_BUILD_DIR $CGNS_FILE
    untarred_cgns=$?
    if [[ $untarred_cgns == -1 ]] ; then
       warn "Unable to prepare CGNS Build Directory. Giving Up"
       return 1
    fi

    #
    # Apply patches
    #
    apply_cgns_patch
    if [[ $? != 0 ]] ; then
       if [[ $untarred_cgns == 1 ]] ; then
          warn "Giving up on CGNS build because the patch failed."
          return 1
       else
          warn "Patch failed, but continuing.  I believe that this script\n" \
          warn "tried to apply a patch to an existing directory which had\n" \
          warn "already been patched ... that is, that the patch is\n" \
          warn "failing harmlessly on a second application."
       fi
    fi

    info "Configuring CGNS . . ."
    cd $CGNS_BUILD_DIR || error "Can't cd to CGNS build dir."
    info "Invoking command to configure CGNS"
    LIBEXT=""
    if [[ "$DO_STATIC_BUILD" == "yes" ]]; then
        cf_build_type=""
        LIBEXT="a"
    else
        cf_build_type="--enable-shared=all"
        if [[ "$OPSYS" == "Darwin" ]] ; then
            LIBEXT="dylib"
        else
            LIBEXT="so"
        fi
    fi
    # optionally add HDF5 and szip to the configure.
    H5ARGS=""
    if [[ "$DO_HDF5" == "yes" ]] ; then
        H5ARGS="--with-hdf5=$VISITDIR/hdf5/$HDF5_VERSION/$VISITARCH"
        if [[ "$DO_SZIP" == "yes" ]] ; then
            if [[ "$OPSYS" == "Darwin" ]] ; then
               H5ARGS="$H5ARGS --with-szip=$VISITDIR/szip/$SZIP_VERSION/$VISITARCH/lib/libsz.$LIBEXT"
            else
               H5ARGS="$H5ARGS --with-szip=$VISITDIR/szip/$SZIP_VERSION/$VISITARCH/lib/libsz.$LIBEXT"
            fi
        fi
        if [[ "$DO_ZLIB" == "yes" ]] ; then
            if [[ "$OPSYS" == "Darwin" ]] ; then
               H5ARGS="$H5ARGS --with-zlib=$VISITDIR/zlib/$ZLIB_VERSION/$VISITARCH/lib/libz.$LIBEXT"
            else
               H5ARGS="$H5ARGS --with-zlib=$VISITDIR/zlib/$ZLIB_VERSION/$VISITARCH/lib/libz.$LIBEXT"
            fi
        fi
    fi
    if [[ "$OPSYS" == "Darwin" ]] ; then
       info "    env CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" \
       CFLAGS=\"$C_OPT_FLAGS\" CXXFLAGS=\"$CXX_OPT_FLAGS\" \
       ./configure --enable-64bit ${cf_build_type} $H5ARGS --prefix=\"$VISITDIR/cgns/$CGNS_VERSION/$VISITARCH\""

       env CXX="$CXX_COMPILER" CC="$C_COMPILER" \
       CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
       ./configure --enable-64bit ${cf_build_type} $H5ARGS --prefix=\"$VISITDIR/cgns/$CGNS_VERSION/$VISITARCH\"
    else
       info "    env CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" \
       CFLAGS=\"$C_OPT_FLAGS\" CXXFLAGS=\"$CXX_OPT_FLAGS\" \
       ./configure --enable-64bit ${cf_build_type} $H5ARGS --prefix=\"$VISITDIR/cgns/$CGNS_VERSION/$VISITARCH\""

       env CXX="$CXX_COMPILER" CC="$C_COMPILER" \
       CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
       ./configure --enable-64bit ${cf_build_type} $H5ARGS --prefix=\"$VISITDIR/cgns/$CGNS_VERSION/$VISITARCH\"
    fi

    if [[ $? != 0 ]] ; then
       warn "CGNS configure failed.  Giving up"
       return 1
    fi

    #
    # Build CGNS
    #
    info "Building CGNS . . . (~2 minutes)"

    $MAKE
    if [[ $? != 0 ]] ; then
       warn "CGNS build failed.  Giving up"
       return 1
    fi
    #
    # Install into the VisIt third party location.
    #
    info "Installing CGNS . . ."

    mkdir "$VISITDIR/cgns"
    mkdir "$VISITDIR/cgns/$CGNS_VERSION"
    mkdir "$VISITDIR/cgns/$CGNS_VERSION/$VISITARCH"
    mkdir "$VISITDIR/cgns/$CGNS_VERSION/$VISITARCH/include"
    mkdir "$VISITDIR/cgns/$CGNS_VERSION/$VISITARCH/lib"
    $MAKE install
    if [[ $? != 0 ]] ; then
       warn "CGNS install failed.  Giving up"
       return 1
    fi

    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
        #
        # Make dynamic executable
        #
        info "Creating dynamic libraries for CGNS . . ."

        INSTALLNAMEPATH="$VISITDIR/cgns/${CGNS_VERSION}/$VISITARCH/lib"

        $C_COMPILER -dynamiclib -o libcgns.${SO_EXT} lib/*.o \
           -Wl,-headerpad_max_install_names \
	   -Wl,-twolevel_namespace,-undefined,dynamic_lookup \
           -Wl,-install_name,$INSTALLNAMEPATH/libcgns.${SO_EXT} \
           -Wl,-compatibility_version,$CGNS_COMPATIBILITY_VERSION \
           -Wl,-current_version,$CGNS_VERSION -lSystem 
        if [[ $? != 0 ]] ; then
           warn "CGNS dynamic library creation failed.  Giving up"
           return 1
        fi
        rm -f "$VISITDIR/cgns/$CGNS_VERSION/$VISITARCH/lib/libcgns.${SO_EXT}"
        cp libcgns.${SO_EXT} "$VISITDIR/cgns/$CGNS_VERSION/$VISITARCH/lib"
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/cgns"
       chgrp -R ${GROUP} "$VISITDIR/cgns"
    fi
    cd "$START_DIR"
    info "Done with CGNS"
    return 0
}

function bv_cgns_is_enabled
{
    if [[ $DO_CGNS == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_cgns_is_installed
{
    check_if_installed "cgns" $CGNS_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_cgns_build
{
cd "$START_DIR"
if [[ "$DO_CGNS" == "yes" ]] ; then
    check_if_installed "cgns" $CGNS_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping CGNS build.  CGNS is already installed."
    else
        info "Building CGNS (~2 minutes)"
        build_cgns
        if [[ $? != 0 ]] ; then
            error "Unable to build or install CGNS.  Bailing out."
        fi
        info "Done building CGNS"
   fi
fi
}

function bv_cmake_initialize
{
    export DO_CMAKE="yes"
    export ON_CMAKE="on"
    export FORCE_CMAKE="no"
    export USE_SYSTEM_CMAKE="no"
    add_extra_commandline_args "cmake" "system-cmake" 0 "Use cmake found on system"
    add_extra_commandline_args "cmake" "alt-cmake-dir" 1 "Use cmake found in alternative directory"
    add_extra_commandline_args "cmake" "cmake-bin-dir" 1 "Use cmake found in alternative directory"
}

function bv_cmake_enable
{
DO_CMAKE="yes"
ON_CMAKE="on"
FORCE_CMAKE="yes"
}

function bv_cmake_disable
{
DO_CMAKE="no"
ON_CMAKE="off"
FORCE_CMAKE="no"
}

function bv_cmake_depends_on
{
echo ""
}

function bv_cmake_force
{
  if [[ "$FORCE_CMAKE" == "yes" ]]; then
     return 0;
  fi
  return 1;
}

function cmake_set_vars_helper
{
   CMAKE_VERSION=`"${CMAKE_COMMAND}" --version`
   CMAKE_VERSION=${CMAKE_VERSION/cmake version }
   CMAKE_BUILD_DIR=`"${CMAKE_COMMAND}" --system-information 2>& 1 | grep _CMAKE_INSTALL_DIR | grep -v _CMAKE_INSTALL_DIR:INTERNAL | sed -e s/\"//g -e s/_CMAKE_INSTALL_DIR//g`
   CMAKE_BUILD_DIR=`echo $CMAKE_BUILD_DIR`
   CMAKE_INSTALL="$CMAKE_BUILD_DIR/bin"
   CMAKE_ROOT=`"$CMAKE_COMMAND" --system-information 2>&1 | grep CMAKE_ROOT | grep -v CMAKE_ROOT:INTERNAL | sed -e s/\"//g -e s/CMAKE_ROOT//g` 
   CMAKE_ROOT=`echo "$CMAKE_ROOT"`
   CMAKE_ROOT=`echo $CMAKE_ROOT`

   echo "version: $CMAKE_VERSION build: $CMAKE_BUILD_DIR bin: $CMAKE_INSTALL root: $CMAKE_ROOT"
}

function bv_cmake_system_cmake
{
   echo "using system cmake"

   TEST=`which cmake`
   [ $? != 0 ] && error "System CMake not found"

   bv_cmake_enable

   USE_SYSTEM_CMAKE="yes"

   CMAKE_COMMAND="cmake"
   CMAKE_FILE=""
   cmake_set_vars_helper #set vars..
}

function bv_cmake_alt_cmake_dir
{
    CMAKE_ALT_DIR="$1"
    echo "Using cmake from alternative directory $1"

    [ ! -e "$CMAKE_ALT_DIR/bin/cmake" ] && error "cmake was not found in directory: $1/bin"

    bv_cmake_enable
    USE_SYSTEM_CMAKE="yes"

    CMAKE_COMMAND="$CMAKE_ALT_DIR/bin/cmake"
    CMAKE_FILE=""
    cmake_set_vars_helper #set vars..
}

function bv_cmake_cmake_bin_dir
{
    CMAKE_BIN_DIR="$1"
    echo "Using cmake from bin directory $1"

    [ ! -e "$CMAKE_BIN_DIR/cmake" ] && error "cmake was not found in directory: $1/"

    bv_cmake_enable
    USE_SYSTEM_CMAKE="yes"

    CMAKE_COMMAND="$CMAKE_BIN_DIR/cmake"
    CMAKE_FILE=""
    cmake_set_vars_helper #set vars..
}


function bv_cmake_info
{
export CMAKE_FILE=${CMAKE_FILE:-"cmake-3.0.2.tar.gz"}
export CMAKE_VERSION=${CMAKE_VERSION:-"3.0.2"}
export CMAKE_BUILD_DIR=${CMAKE_BUILD_DIR:-"cmake-3.0.2"}
export CMAKE_MD5_CHECKSUM="db4c687a31444a929d2fdc36c4dfb95f"
export CMAKE_SHA256_CHECKSUM=""
}

function bv_cmake_print
{
 printf "%s%s\n" "CMAKE_FILE=" "${CMAKE_FILE}"
 printf "%s%s\n" "CMAKE_VERSION=" "${CMAKE_VERSION}"
 printf "%s%s\n" "CMAKE_BUILD_DIR=" "${CMAKE_BUILD_DIR}"
}

function bv_cmake_print_usage
{
printf "%-15s %s [%s]\n" "--cmake"   "Build CMake" "built by default unless --no-thirdparty flag is used"
printf "%-15s %s [%s]\n" "--system-cmake"   "Use CMake" "Use system cmake"
printf "%-15s %s [%s]\n" "--alt-cmake-dir"  "Use CMake" "Use cmake from alternative directory"
}

function bv_cmake_host_profile
{
#nothing to be done for cmake in cmake host profile..
echo "##" >> $HOSTCONF
}

function bv_cmake_initialize_vars
{
    if [[ "$USE_SYSTEM_CMAKE" != "yes" ]]; then 
        if [[ "$DO_CMAKE" == "yes" || "$DO_VTK" == "yes" ]] ; then
            #initialize variables where cmake should exist..
            CMAKE_INSTALL=${CMAKE_INSTALL:-"$VISITDIR/cmake/${CMAKE_VERSION}/${VISITARCH}/bin"}
            CMAKE_ROOT=${CMAKE_ROOT:-"$VISITDIR/cmake/${CMAKE_VERSION}/${VISITARCH}/share/cmake-${CMAKE_VERSION%.*}"}
            CMAKE_COMMAND="${CMAKE_INSTALL}/cmake"
        fi
    fi

}

function bv_cmake_ensure
{
    if [[ "$USE_SYSTEM_CMAKE" != "yes" ]]; then 
        if [[ "$DO_CMAKE" == "yes" || "$DO_VTK" == "yes" ]] ; then
            ensure_built_or_ready "cmake"  $CMAKE_VERSION  $CMAKE_BUILD_DIR  $CMAKE_FILE
            if [[ $? != 0 ]] ; then
                return 1
            fi
        fi
    fi
}

function bv_cmake_dry_run
{
  if [[ "$DO_CMAKE" == "yes" ]] ; then
    echo "Dry run option not set for cmake."
  fi
}

# *************************************************************************** #
#                          Function 5, build_cmake                            #
# *************************************************************************** #

function apply_cmake_patch_4
{
   patch -p0 <<\EOF
--- cmake-3.0.2/Source/cmMakefileTargetGenerator.cxx
+++ cmake-3.0.2-new/Source/cmMakefileTargetGenerator.cxx
@@ -306,6 +306,11 @@ std::string cmMakefileTargetGenerator::G
     // Add target-specific flags.
     this->LocalGenerator->AddCompileOptions(flags, this->Target,
                                             lang, this->ConfigName);
+#if 1
+    for(size_t j = 0; j < flags.size(); ++j)
+        if(flags[j] == '"') 
+            flags[j] = ' ';
+#endif
 
     ByLanguageMap::value_type entry(l, flags);
     i = this->FlagsByLanguage.insert(entry).first;
@@ -1773,6 +1778,19 @@ cmMakefileTargetGenerator
     // shell no-op ":".
     if(!cmd->empty() && (*cmd)[0] != ':')
       {
+#if 1
+      // Work around a problem with random quotes being inserted into the link line.
+      std::string::size_type pos = cmd->find("\"");
+      if(pos != std::string::npos)
+      {
+          std::string cp(*cmd);
+          for(size_t j = 0; j < cp.size(); ++j)
+              if(cp[j] == '"')
+                  cp[j] = ' ';
+          linkScriptStream << cp << "\n";
+          continue;
+      }
+#endif
       linkScriptStream << *cmd << "\n";
       }
     }
EOF
   if [[ $? != 0 ]] ; then
        warn "Unable to apply patch 4 to cmake."
        return 1
   else
        return 0
   fi
}

function apply_cmake_patch_3
{
   patch -p0 <<\EOF
*** cmake-2.8.12.2/Modules/Platform/Darwin.cmake
--- cmake-2.8.12.2/Modules/Platform/Darwin.cmake.patched
***************
*** 201,208 ****
    endif()
  endif()
  
  # Make sure the combination of SDK and Deployment Target are allowed
! if(CMAKE_OSX_DEPLOYMENT_TARGET)
    if("${_CMAKE_OSX_SYSROOT_PATH}" MATCHES "^.*/MacOSX([0-9]+\\.[0-9]+)[^/]*\\.sdk")
      set(_sdk_ver "${CMAKE_MATCH_1}")
    elseif("${_CMAKE_OSX_SYSROOT_ORIG}" MATCHES "^macosx([0-9]+\\.[0-9]+)$")
--- 201,213 ----
    endif()
  endif()
  
+ #
+ # This sanity check fails on OS X 10.8 regardless of how values are
+ # set. It has been disabled for this installation of VisIt by using
+ # 'FALSE' as the triggering condition.
+ #
  # Make sure the combination of SDK and Deployment Target are allowed
! if(FALSE)
    if("${_CMAKE_OSX_SYSROOT_PATH}" MATCHES "^.*/MacOSX([0-9]+\\.[0-9]+)[^/]*\\.sdk")
      set(_sdk_ver "${CMAKE_MATCH_1}")
    elseif("${_CMAKE_OSX_SYSROOT_ORIG}" MATCHES "^macosx([0-9]+\\.[0-9]+)$")
EOF
   if [[ $? != 0 ]] ; then
        warn "Unable to apply patch 3 to cmake."
        return 1
   else
        return 0
   fi
}

function apply_cmake_patch_2
{
   patch -p0 <<\EOF
*** cmake-2.8.10.2/Modules/Platform/Darwin.cmake
--- cmake-2.8.10.2/Modules/Platform/Darwin.cmake.patched
***************
*** 180,187 ****
    endif()
  endif()
  
  # Make sure the combination of SDK and Deployment Target are allowed
! if(CMAKE_OSX_DEPLOYMENT_TARGET)
    if("${_CMAKE_OSX_SYSROOT_PATH}" MATCHES "^.*/MacOSX([0-9]+\\.[0-9]+)[^/]*\\.sdk")
      set(_sdk_ver "${CMAKE_MATCH_1}")
    elseif("${_CMAKE_OSX_SYSROOT_ORIG}" MATCHES "^macosx([0-9]+\\.[0-9]+)$")
--- 180,192 ----
    endif()
  endif()
  
+ #
+ # This sanity check fails on OS X 10.8 regardless of how values are
+ # set. It has been disabled for this installation of VisIt by using
+ # 'FALSE' as the triggering condition.
+ #
  # Make sure the combination of SDK and Deployment Target are allowed
! if(FALSE)
    if("${_CMAKE_OSX_SYSROOT_PATH}" MATCHES "^.*/MacOSX([0-9]+\\.[0-9]+)[^/]*\\.sdk")
      set(_sdk_ver "${CMAKE_MATCH_1}")
    elseif("${_CMAKE_OSX_SYSROOT_ORIG}" MATCHES "^macosx([0-9]+\\.[0-9]+)$")
EOF
   if [[ $? != 0 ]] ; then
        warn "Unable to apply patch 2 to cmake."
        return 1
   else
        return 0
   fi
}

function apply_cmake_patch_1
{
   patch -p0 <<\EOF
diff -c a/Modules/Platform/UnixPaths.cmake cmake-2.8.8/Modules/Platform/UnixPaths.cmake
*** a/Modules/Platform/UnixPaths.cmake
--- cmake-2.8.8/Modules/Platform/UnixPaths.cmake
***************
*** 67,72 ****
--- 67,75 ----
    /usr/pkg/lib
    /opt/csw/lib /opt/lib
    /usr/openwin/lib
+
+   # Ubuntu 11.04
+   /usr/lib/x86_64-linux-gnu
    )

  LIST(APPEND CMAKE_SYSTEM_PROGRAM_PATH
***************
*** 75,80 ****
--- 78,86 ----

  LIST(APPEND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
    /lib /usr/lib /usr/lib32 /usr/lib64
+
+   # Ubuntu 11.04
+   /usr/lib/x86_64-linux-gnu
    )

  LIST(APPEND CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES
EOF
   if [[ $? != 0 ]] ; then
        warn "Unable to apply patch 1 to cmake."
        return 1
   else
        return 0
   fi
}

function apply_cmake_patch
{
   info "Patching CMake . . ."

   if [[ "${CMAKE_VERSION}" == "2.8.0" ]]; then
       apply_cmake_patch_1
       if [[ $? != 0 ]] ; then
          return 1
       fi
   fi

   if [[ "${CMAKE_VERSION}" == "2.8.10.2" ]]; then
       apply_cmake_patch_2
       if [[ $? != 0 ]] ; then
          return 1
       fi
   fi

   if [[ "${CMAKE_VERSION}" == "2.8.12.2" ]]; then
       apply_cmake_patch_3
       if [[ $? != 0 ]] ; then
          return 1
       fi
   fi

   if [[ "${CMAKE_VERSION}" == "3.0.2" && "$BUILD_VISIT_BGQ" == "yes" ]]; then
       apply_cmake_patch_4
       if [[ $? != 0 ]] ; then
          return 1
       fi
   fi

   return 0
}


function build_cmake
{
    #
    # Prepare cmake build directory
    #
    prepare_build_dir $CMAKE_BUILD_DIR $CMAKE_FILE
    untarred_cmake=$?
    if [[ $untarred_cmake == -1 ]] ; then
       warn "Unable to prepare CMake build directory. Giving Up!"
       return 1
    fi

    #
    # Patch cmake
    #
    apply_cmake_patch
    if [[ $? != 0 ]] ; then
       if [[ $untarred_cmake == 1 ]] ; then
          warn "Giving up on CMake build because the patch failed."
          return 1
       else
          warn "Patch failed, but continuing.  I believe that this script\n"\
               "tried to apply a patch to an existing directory which had\n"\
               "already been patched ... that is, that the patch is\n"\
               "failing harmlessly on a second application."
       fi
    fi

    #
    # Issue "bootstrap", which takes the place of configure for CMake.
    #
    info "Bootstrapping CMake . . ."
    cd $CMAKE_BUILD_DIR || error "Can't cd to CMake build dir."
    if [[ "$OPSYS" == "AIX" ]]; then
        env CXX=xlC CC=xlc CXXFLAGS="" CFLAGS="" ./bootstrap --prefix="$VISITDIR/cmake/${CMAKE_VERSION}/$VISITARCH"
    elif [[ "$OPSYS" == "Linux" && "$C_COMPILER" == "xlc" ]]; then
        env CXX=xlC CC=xlc CXXFLAGS="" CFLAGS="" ./bootstrap --prefix="$VISITDIR/cmake/${CMAKE_VERSION}/$VISITARCH"
    else
        env CC=${C_COMPILER} CXX=${CXX_COMPILER} CXXFLAGS="" CFLAGS="" ./bootstrap --prefix="$VISITDIR/cmake/${CMAKE_VERSION}/$VISITARCH"
    fi
    if [[ $? != 0 ]] ; then
       warn "Bootstrap for cmake failed, giving up."
       return 1
    fi

    #
    # Build the CMake program.
    #
    info "Building CMake . . ."
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "Cannot build cmake, giving up."
       return 1
    fi

    info "Installing CMake . . ."
    $MAKE install
    info "Successfully built CMake"
    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/cmake"
       chgrp -R ${GROUP} "$VISITDIR/cmake"
    fi
    cd "$START_DIR"
    info "Done with CMake"
}

function bv_cmake_is_enabled
{
    if [[ $DO_CMAKE == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_cmake_is_installed
{
    if [[ "$USE_SYSTEM_CMAKE" == "yes" ]]; then
        return 1
    fi

    check_if_installed "cmake" $CMAKE_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_cmake_build
{
#
# Build CMake
#
cd "$START_DIR"
if [[ "$DO_CMAKE" == "yes" && "$USE_SYSTEM_CMAKE" == "no" ]]; then
    check_if_installed "cmake" $CMAKE_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping CMake build.  CMake is already installed."
    else
        info "Building CMake (~2 minutes)"
        build_cmake
        if [[ $? != 0 ]] ; then
            error "Unable to build or install CMake.  Bailing out."
        fi
        info "Done building CMake"
    fi
fi
}

function bv_damaris_initialize
{
    export DO_DAMARIS="no"
    export ON_DAMARIS="off"
}

function bv_damaris_enable
{ 
    DO_DAMARIS="yes"
    ON_DAMARIS="on"
}

function bv_damaris_disable
{
    DO_DAMARIS="no"
    ON_DAMARIS="off"
}

function bv_damaris_depends_on
{
    if [[ "$DO_MPICH" == "yes" ]] ; then
        echo "cmake xsd xercesc boost mpich"
    else
        echo "cmake xsd xercesc boost"        
    fi

}

function bv_damaris_info
{
    export DAMARIS_VERSION=${DAMARIS_VERSION:-"1.0.1"}
    export DAMARIS_FILE=${DAMARIS_FILE:-"damaris-${DAMARIS_VERSION}.tgz"}
    export DAMARIS_COMPATIBILITY_VERSION=${DAMARIS_COMPATIBILITY_VERSION:-"1.0"}
    export DAMARIS_URL=${DAMARIS_URL:-"https://gforge.inria.fr/frs/download.php/file/34263"}
    export DAMARIS_BUILD_DIR=${DAMARIS_BUILD_DIR:-"damaris-${DAMARIS_VERSION}"}
    export DAMARIS_MD5_CHECKSUM=""
    export DAMARIS_SHA256_CHECKSUM=""
}

function bv_damaris_print
{
    printf "%s%s\n" "DAMARIS_FILE=" "${DAMARIS_FILE}"
    printf "%s%s\n" "DAMARIS_VERSION=" "${DAMARIS_VERSION}"
    printf "%s%s\n" "DAMARIS_COMPATIBILITY_VERSION=" "${DAMARIS_COMPATIBILITY_VERSION}"
    printf "%s%s\n" "DAMARIS_BUILD_DIR=" "${DAMARIS_BUILD_DIR}"
}

function bv_damaris_print_usage
{
    printf "%-15s %s [%s]\n" "--damaris"   "Build DAMARIS" "$DO_DAMARIS"
}

function bv_damaris_graphical
{
    local graphical_out="DAMARIS    $DAMARIS_VERSION($DAMARIS_FILE)    $ON_DAMARIS"
    echo $graphical_out
}

function bv_damaris_host_profile
{
    if [[ "$DO_DAMARIS" == "yes" ]] ; then
        echo "##" >> $HOSTCONF
        echo "## DAMARIS" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_DAMARIS_DIR \${VISITHOME}/damaris/$DAMARIS_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
    fi
}

function bv_damaris_ensure
{
    if [[ "$DO_DAMARIS" == "yes" ]] ; then
        ensure_built_or_ready "damaris" $DAMARIS_VERSION $DAMARIS_BUILD_DIR $DAMARIS_FILE $DAMARIS_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_DAMARIS="no"
            error "Unable to build DAMARIS.  ${DAMARIS_FILE} not found."
        fi
    fi
}

function bv_damaris_dry_run
{
    if [[ "$DO_DAMARIS" == "yes" ]] ; then
        echo "Dry run option not set for Damaris."
    fi
}

function apply_damaris_patch
{
   return 0
}

function build_damaris
{
    # Checking that we have a parallel compiler
    if [ -z ${PAR_COMPILER+x} ]; then 
        warn "Damaris requires PAR_COMPILER to be set."
        warn "For instance, PAR_COMPILER=mpicxx"
        warn "Giving up."
        return 1
    fi 


    
    export PAR_CXX_COMPILER="${PAR_COMPILER}"
    

    #
    # The build dir of VisIt is required to get the headers of libsimV2
    # so we create it now. This is pretty much a copy-past of some
    # content from bv_visit.sh.
    #
    if [[ "$DO_SVN" != "yes" || "$USE_VISIT_FILE" == "yes" ]] ; then
    #
    # Unzip the file, provided a gzipped file exists.
    #
    if [[ -f ${VISIT_FILE} ]] ; then
        info "Unzipping/untarring ${VISIT_FILE} because Damaris needs it . . ."
        uncompress_untar ${VISIT_FILE}
        if [[ $? != 0 ]] ; then
        warn "Unable to untar ${VISIT_FILE}.  Corrupted file or out of space on device?"
        return 1
        fi
    elif [[ -f ${VISIT_FILE%.*} ]] ; then
        info "Unzipping ${VISIT_FILE%.*} because Damaris needs it . . ."
        $TAR xf ${VISIT_FILE%.*}
        if [[ $? != 0 ]] ; then
        warn "Unable to untar ${VISIT_FILE%.*}.  Corrupted file or out of space on device?"
        return 1
        fi
    fi
    fi

    local LIBSIMV2_INCLUDE="../${VISIT_FILE%.tar*}/src/sim/V2/lib"
    if [[ "$DO_SVN" == "yes" && "$USE_VISIT_FILE" == "no" ]] ; then
    LIBSIMV2_INCLUDE="../src/sim/V2/lib"
    fi
    
    #
    # Prepare build dir for Damaris
    #
    prepare_build_dir $DAMARIS_BUILD_DIR $DAMARIS_FILE
    untarred_damaris=$?
    if [[ $untarred_damaris == -1 ]] ; then
       warn "Unable to prepare Damaris build directory. Giving Up!"
    fi
    cd $DAMARIS_BUILD_DIR

    #
    # Applying Patches
    #
    apply_damaris_patch
    if [[ $? != 0 ]] ; then
       warn "Unable to prepare Damaris build directory. Giving Up"
       return 1
    fi

    #
    # Calling Cmake
    #
    
    sh -c "$CMAKE_COMMAND -G \"Unix Makefiles\" \
    -DPAR_CXX_COMPILER:PATH=$PAR_CXX_COMPILER \
    -DCMAKE_INSTALL_PREFIX:PATH=$VISITDIR/damaris/$DAMARIS_VERSION/$VISITARCH \
    -DVISIT_INCLUDE:PATH=$LIBSIMV2_INCLUDE \
    -DXERCESC_ROOT:PATH=$VISITDIR/xerces-c/$XERCESC_VERSION/$VISITARCH \
    -DXSD_ROOT:PATH=$VISITDIR/xsd/$XSD_VERSION/$VISITARCH \
    -DXSD_INCLUDE_DIR:PATH=$VISITDIR/xsd/$XSD_VERSION/$VISITARCH/include \
    -DBOOST_ROOT=$VISITDIR/boost/$BOOST_VERSION/$VISITARCH \
    -DBOOST_INCLUDEDIR=$VISITDIR/boost/$BOOST_VERSION/$VISITARCH/include \
    -DENABLE_EXAMPLES:BOOL=false \
    -DENABLE_TESTS:BOOL=false"

    if [[ $? != 0 ]] ; then
    warn "Cmake failed to create build files for Damaris.  Giving up."
    return 1
    fi

    #
    # Building Damaris
    #
    $MAKE

    if [[ $? != 0 ]] ; then
        warn "Failed to build Damaris.  Giving up."
        return 1
    fi

    #
    # Installing Damaris
    #
    $MAKE install

    if [[ $? != 0 ]] ; then
        warn "Failed to install Damaris.  Giving up."
        return 1
    fi

    return 0
}

function bv_damaris_is_enabled
{
    if [[ $DO_DAMARIS == "yes" ]]; then
        return 1
    fi
    return 0
}

function bv_damaris_is_installed
{
    check_if_installed "damaris" $DAMARIS_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_damaris_build
{
    if [[ "$DO_DAMARIS" == "yes" ]] ; then
        check_if_installed "damaris" $DAMARIS_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping Damaris build.  Damaris is already installed."
        else
            info "Building Damaris (~6 minutes)"

            build_damaris
            if [[ $? != 0 ]] ; then
                error "Unable to build or install Damaris.  Bailing out."
            fi
            info "Done building Damaris"
       fi
    fi
}


function bv_eavl_initialize
{
export DO_EAVL="no"
export ON_EAVL="off"
export USE_SYSTEM_EAVL="no"
add_extra_commandline_args "eavl" "alt-eavl-dir" 1 "Use alternative directory for EAVL"
}

function bv_eavl_enable
{
DO_EAVL="yes"
ON_EAVL="on"
}

function bv_eavl_disable
{
DO_EAVL="no"
ON_EAVL="off"
}

function bv_eavl_alt_eavl_dir
{
    bv_eavl_enable
    USE_SYSTEM_EAVL="yes"
    EAVL_INSTALL_DIR="$1"
}

function bv_eavl_depends_on
{
    if [[ "$USE_SYSTEM_EAVL" == "yes" ]]; then
        echo ""
    else
        local depends_on=""

        echo $depends_on
    fi
}

function bv_eavl_initialize_vars
{
    if [[ "$USE_SYSTEM_EAVL" == "no" ]]; then
        EAVL_INSTALL_DIR="\${VISITHOME}/eavl/$EAVL_VERSION/\${VISITARCH}"
    fi
}

function bv_eavl_info
{
export EAVL_VERSION=${EAVL_VERSION:-"4593630"}
export EAVL_FILE=${EAVL_FILE:-"EAVL-${EAVL_VERSION}.tar.gz"}
export EAVL_BUILD_DIR=${EAVL_BUILD_DIR:-"EAVL-${EAVL_VERSION}"}
export EAVL_MD5_CHECKSUM="3528aec602573baa6da327594eb7d061"
export EAVL_SHA256_CHECKSUM="c6a94b503d6800c4875af8dc3235a510e9564efcb524a04bd07d1e295c45f9fe"
}

function bv_eavl_print
{
  printf "%s%s\n" "EAVL_FILE=" "${EAVL_FILE}"
  printf "%s%s\n" "EAVL_VERSION=" "${EAVL_VERSION}"
  printf "%s%s\n" "EAVL_BUILD_DIR=" "${EAVL_BUILD_DIR}"
}

function bv_eavl_print_usage
{
printf "%-15s %s [%s]\n" "--eavl" "Build eavl support" "$DO_EAVL"
}

function bv_eavl_graphical
{
local graphical_out="eavl     $EAVL_VERSION($EAVL_FILE)      $ON_EAVL"
echo "$graphical_out"
}

function bv_eavl_host_profile
{
    if [[ "$DO_EAVL" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## EAVL" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_EAVL_DIR ${EAVL_INSTALL_DIR})" \
        >> $HOSTCONF
    fi
}

function bv_eavl_ensure
{
    if [[ "$DO_EAVL" == "yes" && "$USE_SYSTEM_EAVL" == "no" ]] ; then
        ensure_built_or_ready "eavl" $EAVL_VERSION $EAVL_BUILD_DIR $EAVL_FILE $EAVL_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_EAVL="no"
            error "Unable to build eavl.  ${EAVL_FILE} not found."
        fi
    fi
}

function bv_eavl_dry_run
{
  if [[ "$DO_EAVL" == "yes" ]] ; then
    echo "Dry run option not set for eavl."
  fi
}

# *************************************************************************** #
#                            Function 8, build_EAVL
#
#
# *************************************************************************** #

function apply_EAVL_5f53629eed_patch
{
   patch -p0 <<\EOF
diff -c a/configure EAVL-5f53629eed/configure
*** a/configure	Tue Aug 12 16:25:47 2014
--- EAVL-5f53629eed/configure	Tue Aug 12 16:26:02 2014
***************
*** 4435,4444 ****
  
  # don't use everything -- we only need enough to do data set conversion.
  VTK_ALL_LIBS="
!     vtkIOLegacy-6.0
!     vtkIOCore-6.0
!     vtkCommonDataModel-6.0
!     vtkCommonCore-6.0
      "
  
  VTK_CPPFLAGS=""
--- 4435,4444 ----
  
  # don't use everything -- we only need enough to do data set conversion.
  VTK_ALL_LIBS="
!     vtkIOLegacy-6.1
!     vtkIOCore-6.1
!     vtkCommonDataModel-6.1
!     vtkCommonCore-6.1
      "
  
  VTK_CPPFLAGS=""
***************
*** 4454,4460 ****
  
  if test "$VTK" != "yes" -a "$VTK" != "no"; then
     # specified path
!    VTK_CPPFLAGS="-I""$VTK""/include/vtk-6.0 -I""$VTK""/include"
     VTK_LDFLAGS="-L""$VTK""/lib"
     if test "$UNAME" = "Darwin"; then
               VTK_LDFLAGS="$VTK_LDFLAGS"
--- 4454,4460 ----
  
  if test "$VTK" != "yes" -a "$VTK" != "no"; then
     # specified path
!    VTK_CPPFLAGS="-I""$VTK""/include/vtk-6.1 -I""$VTK""/include"
     VTK_LDFLAGS="-L""$VTK""/lib"
     if test "$UNAME" = "Darwin"; then
               VTK_LDFLAGS="$VTK_LDFLAGS"
EOF
   if [[ $? != 0 ]] ; then
        warn "Unable to apply patch to EAVL 5f53629eed"
        return 1
   else
        return 0
   fi
}

function apply_EAVL_patch
{
   info "Patching EAVL . . ."
   if [[ ${EAVL_VERSION} == "5f53629eed" ]] ; then
      apply_EAVL_5f53629eed_patch
      if [[ $? != 0 ]] ; then
        return 1
      fi
   fi

   return 0
}

function build_EAVL
{
    #
    # Prepare build dir
    #
    prepare_build_dir $EAVL_BUILD_DIR $EAVL_FILE
    untarred_EAVL=$?
    if [[ $untarred_EAVL == -1 ]] ; then
       warn "Unable to prepare eavl build directory. Giving Up!"
       return 1
    fi
    
    apply_EAVL_patch

    #
    # Call configure
    #
    info "Configuring eavl . . ."
    cd $EAVL_BUILD_DIR || error "Can't cd to eavl build dir."
    
    #
    # expedient hack: use VISIT_CUDA_TOOLKIT env var to select cuda
    #
    if [[ "${VISIT_CUDA_TOOLKIT}" == "" ]] ; then
        export EAVL_EXTRA_ARGS=""
    else
        export EAVL_CUDA_TOOLKIT_ARGS=" --with-cuda=$VISIT_CUDA_TOOLKIT"
    fi

    if [[ "${SYSTEM_VTK_DIR}" == "" ]] ; then
        if [[ "${VTK_INSTALL_DIR}" == "" ]] ; then
            export EAVL_VTK_ARGS=""
        else
            export EAVL_VTK_ARGS=" --with-vtk=$VISITDIR/$VTK_INSTALL_DIR/$VTK_VERSION/$VISITARCH"
        fi
    else
        export EAVL_VTK_ARGS=" --with-vtk=$SYSTEM_VTK_DIR"
    fi
        
    #info ./configure CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" \
    #                 CFLAGS=\"$CFLAGS $C_OPT_FLAGS\" \
    #                 CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS\" \
    #                 $EAVL_CUDA_TOOLKIT_ARGS \
    #                 --prefix="$VISITDIR/eavl/$EAVL_VERSION/$VISITARCH"

    #./configure CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" \
    #                 CFLAGS=\"$CFLAGS $C_OPT_FLAGS\" \
    #                 CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS\" \
    #                 $EAVL_CUDA_TOOLKIT_ARGS \
    #                 --prefix="$VISITDIR/eavl/$EAVL_VERSION/$VISITARCH"
    # avoid passing flags for now
    info ./configure $EAVL_CUDA_TOOLKIT_ARGS $EAVL_VTK_ARGS --with-openmp \
                     --prefix="$VISITDIR/eavl/$EAVL_VERSION/$VISITARCH"

    ./configure $EAVL_CUDA_TOOLKIT_ARGS $EAVL_VTK_ARGS --with-openmp \
                 --prefix="$VISITDIR/eavl/$EAVL_VERSION/$VISITARCH"

    #
    # Build eavl
    #
    info "Building eavl . . . (~2 minutes)"
    env CXX="$CXX_COMPILER" CC="$C_COMPILER" \
       CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
       $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "eavl build failed.  Giving up"
       return 1
    fi

    #
    # Install into the VisIt third party location.
    #
    info "Installing eavl"
    #$MAKE $MAKE_OPT_FLAGS install
    # eavl doesn't yet support make install ...
    mkdir "$VISITDIR/eavl"
    mkdir "$VISITDIR/eavl/$EAVL_VERSION"
    mkdir "$VISITDIR/eavl/$EAVL_VERSION/$VISITARCH"
    mkdir "$VISITDIR/eavl/$EAVL_VERSION/$VISITARCH/include"
    mkdir "$VISITDIR/eavl/$EAVL_VERSION/$VISITARCH/lib"

    cp lib/libeavl.a         "$VISITDIR/eavl/$EAVL_VERSION/$VISITARCH/lib"
    cp config/eavlConfig.h   "$VISITDIR/eavl/$EAVL_VERSION/$VISITARCH/include"
    cp config/eavlPlatform.h "$VISITDIR/eavl/$EAVL_VERSION/$VISITARCH/include"
    cp src/common/*.h        "$VISITDIR/eavl/$EAVL_VERSION/$VISITARCH/include"
    cp src/exporters/*.h     "$VISITDIR/eavl/$EAVL_VERSION/$VISITARCH/include"
    cp src/importers/*.h     "$VISITDIR/eavl/$EAVL_VERSION/$VISITARCH/include"
    cp src/rendering/*.h     "$VISITDIR/eavl/$EAVL_VERSION/$VISITARCH/include"
    cp src/filters/*.h       "$VISITDIR/eavl/$EAVL_VERSION/$VISITARCH/include"
    cp src/math/*.h          "$VISITDIR/eavl/$EAVL_VERSION/$VISITARCH/include"
    cp src/fonts/*.h         "$VISITDIR/eavl/$EAVL_VERSION/$VISITARCH/include"
    cp src/operations/*.h    "$VISITDIR/eavl/$EAVL_VERSION/$VISITARCH/include"
    cp src/vtk/*.h           "$VISITDIR/eavl/$EAVL_VERSION/$VISITARCH/include"


    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/eavl"
       chgrp -R ${GROUP} "$VISITDIR/eavl"
    fi
    cd "$START_DIR"
    info "Done with eavl"
    return 0
}

function bv_eavl_is_enabled
{
    if [[ $DO_EAVL == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_eavl_is_installed
{
    if [[ "$USE_SYSTEM_EAVL" == "yes" ]]; then
        return 1
    fi

    check_if_installed "eavl" $EAVL_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_eavl_build
{
cd "$START_DIR"
if [[ "$DO_EAVL" == "yes" && "$USE_SYSTEM_EAVL" == "no" ]] ; then
    check_if_installed "eavl" $EAVL_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping eavl build.  eavl is already installed."
    else
        info "Building eavl (~2 minutes)"
        build_EAVL
        if [[ $? != 0 ]] ; then
            error "Unable to build or install eavl.  Bailing out."
        fi
        info "Done building eavl"
    fi
fi
}

function bv_fastbit_initialize
{
export DO_FASTBIT="no"
export ON_FASTBIT="off"
}

function bv_fastbit_enable
{
DO_FASTBIT="yes"
ON_FASTBIT="on"
}

function bv_fastbit_disable
{
DO_FASTBIT="no"
ON_FASTBIT="off"
}

function bv_fastbit_depends_on
{
echo ""
}

function bv_fastbit_info
{
export FASTBIT_VERSION=${FASTBIT_VERSION:-"1.2.0"}
export FASTBIT_FILE=${FASTBIT_FILE:-"fastbit-ibis${FASTBIT_VERSION}.tar.gz"}
# Note: last 3-digit field in URL changes with version.
export FASTBIT_URL=${FASTBIT_URL:-"https://codeforge.lbl.gov/frs/download.php/208"}
export FASTBIT_BUILD_DIR=${FASTBIT_BUILD_DIR:-"fastbit-ibis${FASTBIT_VERSION}"}
export FASTBIT_MD5_CHECKSUM="380de470b856ecaf19d296aab6406811"
export FASTBIT_SHA256_CHECKSUM=""
}

function bv_fastbit_print
{
  printf "%s%s\n" "FASTBIT_FILE=" "${FASTBIT_FILE}"
  printf "%s%s\n" "FASTBIT_VERSION=" "${FASTBIT_VERSION}"
  printf "%s%s\n" "FASTBIT_BUILD_DIR=" "${FASTBIT_BUILD_DIR}"
}

function bv_fastbit_print_usage
{
printf "%-15s %s [%s]\n" "--fastbit" "Build FastBit" "$DO_FASTBIT"
}

function bv_fastbit_graphical
{
local graphical_out="FastBit  $FASTBIT_VERSION($FASTBIT_FILE)   $ON_FASTBIT"
echo $graphical_out
}

function bv_fastbit_host_profile
{
    if [[ "$DO_FASTBIT" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## FastBit" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_FASTBIT_DIR \${VISITHOME}/fastbit/$FASTBIT_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
    fi

}

function bv_fastbit_ensure
{
    if [[ "$DO_FASTBIT" == "yes" ]] ; then
        ensure_built_or_ready "fastbit" $FASTBIT_VERSION $FASTBIT_BUILD_DIR $FASTBIT_FILE $FASTBIT_URL
        if [[ $? != 0 ]] ; then
            warn "Unable to build FastBit.  ${FASTBIT_FILE} not found."
            warn "FastBit is not available for download from the VisIt build site"
            ANY_ERRORS="yes"
            DO_FASTBIT="no"
            error "Try going to https://codeforge.lbl.gov/frs/?group_id=44"
        fi
    fi
}

function bv_fastbit_dry_run
{
  if [[ "$DO_FASTBIT" == "yes" ]] ; then
    echo "Dry run option not set for fastbit."
  fi
}

# *************************************************************************** #
#                         Function 8.14, build_fastbit                        #
# *************************************************************************** #

function build_fastbit
{
    #
    # Unzip the file, provided a gzipped file exists.
    #
    if [[ -d ${FASTBIT_BUILD_DIR} ]] ; then
       info_box "Found ${FASTBIT_BUILD_DIR} . . ." 1>&3
    elif [[ -f ${FASTBIT_FILE} ]] ; then
       info_box "Unzipping/Tarring ${FASTBIT_FILE} . . ." 1>&3
       uncompress_untar ${FASTBIT_FILE}
       if [[ $? != 0 ]] ; then
          echo \
"Unable to untar ${FASTBIT_FILE}.  Corrupted file or out of space on device?"
          return 1
       fi
    elif [[ -f ${FASTBIT_FILE%.*} ]] ; then
       info_box "Tarring ${FASTBIT_FILE%.*} . . ." 1>&3
       $TAR xf ${FASTBIT_FILE%.*}
       if [[ $? != 0 ]] ; then
          echo \
"Unable to untar ${FASTBIT_FILE%.*}.  Corrupted file or out of space on device?"
          return 1
       fi
    fi

    #
    info_box "Configuring FastBit . . ." 1>&3
    cd ${FASTBIT_BUILD_DIR} || error "Can't cd to fastbit build dir."
    echo "Invoking command to configure FastBit"
    ./configure \
       CXX="$CXX_COMPILER" CC="$C_COMPILER" \
       CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
       --prefix="$VISITDIR/fastbit/$FASTBIT_VERSION/$VISITARCH" \
       --disable-shared --with-java=no
    if [[ $? != 0 ]] ; then
       echo "FastBit configure failed.  Giving up"
       return 1
    fi

    #
    # Build FastBit
    #
    info_box "Building FastBit . . . (~7 minutes)" 1>&3
    echo "Building FastBit"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       echo "FastBit build failed.  Giving up"
       return 1
    fi
    info_box "Installing FastBit . . ." 1>&3
    echo "Installing FastBit"
    $MAKE install
    if [[ $? != 0 ]] ; then
       echo "FastBit build (make install) failed.  Giving up"
       return 1
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/fastbit"
       chgrp -R ${GROUP} "$VISITDIR/fastbit"
    fi
    cd "$START_DIR"
    echo "Done with FastBit"
    return 0
}

function bv_fastbit_is_enabled
{
    if [[ $DO_FASTBIT == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_fastbit_is_installed
{
    check_if_installed "fastbit" $FASTBIT_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_fastbit_build
{
cd "$START_DIR"
if [[ "$DO_FASTBIT" == "yes" ]] ; then
    check_if_installed "fastbit" $FASTBIT_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping FastBit build.  FastBit is already installed."
    else
        info "Building FastBit (~7 minutes)"
        build_fastbit
        if [[ $? != 0 ]] ; then
            error "Unable to build or install FastBit.  Bailing out."
        fi
        info "Done building FastBit"
    fi
fi
}
function bv_gdal_initialize
{
export DO_GDAL="no"
export ON_GDAL="off"
}

function bv_gdal_enable
{
DO_GDAL="yes"
ON_GDAL="on"
}

function bv_gdal_disable
{
DO_GDAL="no"
ON_GDAL="off"
}

function bv_gdal_depends_on
{
echo ""
}

function bv_gdal_info
{
export GDAL_FILE=${GDAL_FILE:-"gdal-1.10.0.tar.gz"}
export GDAL_VERSION=${GDAL_VERSION:-"1.10.0"}
export GDAL_COMPATIBILITY_VERSION=${GDAL_COMPATIBILITY_VERSION:-"1.10"}
export GDAL_BUILD_DIR=${GDAL_BUILD_DIR:-"gdal-1.10.0"}
export GDAL_URL=${GDAL_URL:-"http://download.osgeo.org/gdal/${GDAL_VERSION}"}
export GDAL_MD5_CHECKSUM="a2062d6ad09250e2ade40064bcd1a384"
export GDAL_SHA256_CHECKSUM=""
}

function bv_gdal_print
{
  printf "%s%s\n" "GDAL_FILE=" "${GDAL_FILE}"
  printf "%s%s\n" "GDAL_VERSION=" "${GDAL_VERSION}"
  printf "%s%s\n" "GDAL_COMPATIBILITY_VERSION=" "${GDAL_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "GDAL_BUILD_DIR=" "${GDAL_BUILD_DIR}"
}

function bv_gdal_print_usage
{
 printf "%-15s %s [%s]\n" "--gdal" "Build GDAL" "$DO_GDAL"
}

function bv_gdal_graphical
{
local graphical_out="GDAL     $GDAL_VERSION($GDAL_FILE)      $ON_GDAL"
echo $graphical_out
}

function bv_gdal_host_profile
{
    if [[ "$DO_GDAL" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## GDAL" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_GDAL_DIR \${VISITHOME}/gdal/$GDAL_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
    fi

}

function bv_gdal_ensure
{
    if [[ "$DO_GDAL" == "yes" ]] ; then
        ensure_built_or_ready "gdal" $GDAL_VERSION $GDAL_BUILD_DIR $GDAL_FILE $GDAL_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_GDAL="no"
            error "Unable to build GDAL.  ${GDAL_FILE} not found."
        fi
    fi
}

function bv_gdal_dry_run
{
  if [[ "$DO_GDAL" == "yes" ]] ; then
    echo "Dry run option not set for gdal."
  fi
}

# *************************************************************************** #
#                         Function 8.6, build_gdal                            #
# *************************************************************************** #

function apply_gdal_linux_x86_64_patch
{
    mv configure configure.old
    sed "s/expat_prefix\/lib -lexpat/expat_prefix\/lib64 -lexpat/g" configure.old > configure
    chmod 700 configure
}

function apply_gdal_mac6_patch
{
    cat frmts/gtiff/libtiff/GNUmakefile | \
       sed 's/tif_zip.o/tif_zip.o lfind.o/' > tmp.make
    mv frmts/gtiff/libtiff/GNUmakefile \
       frmts/gtiff/libtiff/GNUmakefile.orig
    mv tmp.make frmts/gtiff/libtiff/GNUmakefile

    echo > frmts/gtiff/libtiff/lfind.c
    cat >> frmts/gtiff/libtiff/lfind.c << EOF
#include <sys/types.h>
#include <string.h>
#include <unistd.h>

static char *linear_base();

char *
lfind(key, base, nelp, width, compar)
      char *key, *base;
      u_int *nelp, width;
      int (*compar)();
{
      return(linear_base(key, base, nelp, width, compar, 0));
}

static char *
linear_base(key, base, nelp, width, compar, add_flag)
      char *key, *base;
      u_int *nelp, width;
      int (*compar)(), add_flag;
{
      register char *element, *end;

      end = base + *nelp * width;
      for (element = base; element < end; element += width)
              if (!compar(element, key))              /* key found */
                      return(element);

      if (!add_flag)                                  /* key not found */
              return(NULL);

      ++*nelp;
      bcopy(key, end, (int)width);
      return(end);
}
EOF
}

function build_gdal
{
    #
    # Prepare build dir
    #
    prepare_build_dir $GDAL_BUILD_DIR $GDAL_FILE
    untarred_gdal=$?
    if [[ $untarred_gdal == -1 ]] ; then
       warn "Unable to prepare GDAL Build Directory. Giving Up"
       return 1
    fi

    #
    info "Configuring GDAL . . ."
    cd $GDAL_BUILD_DIR || error "Can't cd to GDAL build dir."
    info "Invoking command to configure GDAL"
    if [[ "$OPSYS" == "Darwin" ]]; then
       if [[ "$DO_STATIC_BUILD" == "no" ]]; then
           EXTRA_FLAGS="F77=\"\" --enable-shared --disable-static --without-libtool --without-expat"
       else
           EXTRA_FLAGS="F77=\"\" --enable-static --without-ld-shared  --without-libtool --without-expat"
       fi
    else
       EXTRA_FLAGS="--enable-static --disable-shared --with-hide-internal-symbols"
    fi

    if [[ "$OPSYS" == "Darwin" ]]; then
        # Check for version 6.x.x (MacOS 10.2, Jaguar)
        VER=$(uname -r)
        if (( ${VER%%.*} < 7 )) ; then
             apply_gdal_mac6_patch
        fi
    fi
    if [[ "$OPSYS" == "Linux" ]] ; then
        if [[ "$(uname -m)" == "x86_64" ]] ; then
             apply_gdal_linux_x86_64_patch
        fi
    fi

    ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" $EXTRA_FLAGS \
       CFLAGS="$CFLAGS $C_OPT_FLAGS -DH5_USE_16_API" \
       CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS -DH5_USE_16_API" \
       --prefix="$VISITDIR/gdal/$GDAL_VERSION/$VISITARCH" \
       --with-libtiff=internal --with-gif=internal \
       --with-png=internal --with-jpeg=internal \
       --with-libz=internal --with-netcdf=no \
       --with-hdf5=no --with-pg=no --with-curl=no \
       --without-jasper --without-python \
       --without-sqlite3 --without-xml2
    if [[ $? != 0 ]] ; then
       warn "GDAL configure failed.  Giving up"
       return 1
    fi

    #
    # Build GDAL
    #
    info "Building GDAL . . . (~7 minutes)"

    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "GDAL build failed.  Giving up"
       return 1
    fi
    #
    # Install into the VisIt third party location.
    #
    info "Installing GDAL . . ."

    $MAKE install
    if [[ $? != 0 ]] ; then
       warn "GDAL install failed.  Giving up"
       return 1
    fi

    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
        #
        # Make dynamic executable
        #
        info "Fixing install_name of dynamic libraries for GDAL . . ."

        cp .libs/libgdal.1.10.0.${SO_EXT} libgdal.${SO_EXT}
        INSTALLNAMEPATH="$VISITDIR/gdal/${GDAL_VERSION}/$VISITARCH/lib"

        install_name_tool -id \
           $INSTALLNAMEPATH/libgdal.${SO_EXT} \
           libgdal.${SO_EXT}
        rm "$VISITDIR/gdal/$GDAL_VERSION/$VISITARCH/lib/libgdal.${SO_EXT}"
        cp libgdal.${SO_EXT} \
        "$VISITDIR/gdal/$GDAL_VERSION/$VISITARCH/lib/libgdal.${SO_EXT}"
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/gdal"
       chgrp -R ${GROUP} "$VISITDIR/gdal"
    fi
    cd "$START_DIR"
    info "Done with GDAL"
    return 0
}

function bv_gdal_is_enabled
{
    if [[ $DO_GDAL == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_gdal_is_installed
{
    check_if_installed "gdal" $GDAL_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_gdal_build
{
cd "$START_DIR"
if [[ "$DO_GDAL" == "yes" ]] ; then
    if [[ "$OPSYS" == "AIX" ]]; then
        info "Skipping GDAL build.  AIX build is not supported."
        DO_GDAL="no"
    else
        check_if_installed "gdal" $GDAL_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping GDAL build.  GDAL is already installed."
        else
            info "Building GDAL (~2 minutes)"
            build_gdal
            if [[ $? != 0 ]] ; then
                error "Unable to build or install GDAL.  Bailing out."
            fi
            info "Done building GDAL"
        fi
    fi
fi
}
function bv_h5part_initialize
{
export DO_H5PART="no"
export ON_H5PART="off"
}

function bv_h5part_enable
{
DO_H5PART="yes"
ON_H5PART="on"
DO_HDF5="yes"
ON_HDF5="on"
DO_SZIP="yes" 
ON_SZIP="on"
}

function bv_h5part_disable
{
DO_H5PART="no"
ON_H5PART="off"
}

function bv_h5part_depends_on
{
echo "szip hdf5"
}

function bv_h5part_info
{
export H5PART_VERSION=${H5PART_VERSION:-"1.6.6"}
export H5PART_FILE=${H5PART_FILE:-"H5Part-${H5PART_VERSION}.tar.gz"}
export H5PART_COMPATIBILITY_VERSION=${H5PART_COMPATIBILITY_VERSION:-"1.6"}
export H5PART_URL=${H5PART_URL:-"https://codeforge.lbl.gov/frs/download.php/387"}
export H5PART_BUILD_DIR=${H5PART_BUILD_DIR:-"H5Part-${H5PART_VERSION}"}
export H5PART_MD5_CHECKSUM="327c63d198e38a12565b74cffdf1f9d7"
export H5PART_SHA256_CHECKSUM="10347e7535d1afbb08d51be5feb0ae008f73caf889df08e3f7dde717a99c7571"
}

function bv_h5part_print
{
  printf "%s%s\n" "H5PART_FILE=" "${H5PART_FILE}"
  printf "%s%s\n" "H5PART_VERSION=" "${H5PART_VERSION}"
  printf "%s%s\n" "H5PART_COMPATIBILITY_VERSION=" "${H5PART_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "H5PART_BUILD_DIR=" "${H5PART_BUILD_DIR}"
}

function bv_h5part_print_usage
{
printf "%-15s %s [%s]\n" "--h5part" "Build H5Part" "$DO_H5PART"
}

function bv_h5part_graphical
{
local graphical_out="H5Part   $H5PART_VERSION($H5PART_FILE)    $ON_H5PART"
echo $graphical_out
}

function bv_h5part_host_profile
{
    if [[ "$DO_H5PART" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## H5Part" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_H5PART_DIR \${VISITHOME}/h5part/$H5PART_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_H5PART_LIBDEP HDF5_LIBRARY_DIR hdf5 \${VISIT_HDF5_LIBDEP} TYPE STRING)" \
        >> $HOSTCONF

    fi

}

function bv_h5part_ensure
{
   if [[ "$DO_H5PART" == "yes" ]] ; then
        ensure_built_or_ready "h5part" $H5PART_VERSION $H5PART_BUILD_DIR $H5PART_FILE $H5PART_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_H5PART="no"
            error "Unable to build H5Part.  ${H5PART_FILE} not found."
        fi
    fi
}

function bv_h5part_dry_run
{
  if [[ "$DO_H5PART" == "yes" ]] ; then
    echo "Dry run option not set for h5part."
  fi
}

# ***************************************************************************
#                         Function 8.10, build_h5part
#
# Modifications:
#
#  Mark C. Miller, Tue Oct 28 11:10:36 PDT 2008
#  Added -DH5_USE_16_API to CFLAGS for configuring H5Part. This should be
#  harmless when building H5Part against versions of HDF5 before 1.8 and
#  necessary when building against versions of HDF5 1.8 or later. It tells
#  HDF5 which version of the HDF5 API H5Part was implemented with.
#
#  Gunther H. Weber, Wed Jul 27 14:48:12 PDT 2011
#  Adapted to H5Part 1.6.3 which can correctly build shared libraries, does
#  not require -DH5_USE_16_API in CFLAGS and has a new way to pass path to
#  HDF5.
#
# ***************************************************************************

function build_h5part
{
    #
    # Prepare build dir
    #
    prepare_build_dir $H5PART_BUILD_DIR $H5PART_FILE
    untarred_h5part=$?
    if [[ $untarred_h5part == -1 ]] ; then
       warn "Unable to prepare H5Part Build Directory. Giving Up"
       return 1
    fi

    #
    info "Configuring H5Part . . ."
    cd $H5PART_BUILD_DIR || error "Can't cd to h5part build dir."
    if [[ "$DO_HDF5" == "yes" ]] ; then
       export HDF5ROOT="$VISITDIR/hdf5/$HDF5_VERSION/$VISITARCH"
       export SZIPROOT="$VISITDIR/szip/$SZIP_VERSION/$VISITARCH"
       WITHHDF5ARG="--with-hdf5=$HDF5ROOT"
       HDF5DYLIB="-L$HDF5ROOT/lib -L$SZIPROOT/lib -lhdf5 -lsz -lz"
    else
       WITHHDF5ARG="--with-hdf5"
       HDF5DYLIB=""
    fi
    if [[ "$OPSYS" == "Darwin" ]]; then
       export DYLD_LIBRARY_PATH="$VISITDIR/hdf5/$HDF5_VERSION/$VISITARCH/lib":\
"$VISITDIR/szip/$SZIP_VERSION/$VISITARCH/lib":\
$DYLD_LIBRARY_PATH
       SOARG="--enable-shared"
    else
       export LD_LIBRARY_PATH="$VISITDIR/hdf5/$HDF5_VERSION/$VISITARCH/lib":\
"$VISITDIR/szip/$SZIP_VERSION/$VISITARCH/lib":\
$LD_LIBRARY_PATH
       SOARG=""
    fi
    if [[ "$FC_COMPILER" == "no" ]] ; then
        FORTRANARGS=""
    else
        FORTRANARGS="FC=\"$FC_COMPILER\" F77=\"$FC_COMPILER\" FCFLAGS=\"$FCFLAGS\" FFLAGS=\"$FCFLAGS\" --enable-fortran"
    fi

    info "Invoking command to configure H5Part"
    # In order to ensure $FORTRANARGS is expanded to build the arguments to
    # configure, we wrap the invokation in 'sh -c "..."' syntax
    sh -c "./configure ${WITHHDF5ARG} ${OPTIONAL} CXX=\"$CXX_COMPILER\" \
       CC=\"$C_COMPILER\" CFLAGS=\"$CFLAGS $C_OPT_FLAGS\" CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS\" \
       $FORTRANARGS \
       --prefix=\"$VISITDIR/h5part/$H5PART_VERSION/$VISITARCH\""
    if [[ $? != 0 ]] ; then
       warn "H5Part configure failed.  Giving up"
       return 1
    fi

    #
    # Build H5Part
    #
    info "Building H5Part . . . (~1 minutes)"

    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "H5Part build failed.  Giving up"
       return 1
    fi
    info "Installing H5Part . . ."

    $MAKE install
    if [[ $? != 0 ]] ; then
       warn "H5Part build (make install) failed.  Giving up"
       return 1
    fi

    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
        #
        # Make dynamic executable, need to patch up the install path and
        # version information.
        #
        info "Creating dynamic libraries for H5Part . . ."
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/h5part"
       chgrp -R ${GROUP} "$VISITDIR/h5part"
    fi
    cd "$START_DIR"
    info "Done with H5Part"
    return 0
}

function bv_h5part_is_enabled
{
    if [[ $DO_H5PART == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_h5part_is_installed
{
    check_if_installed "h5part" $H5PART_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_h5part_build
{
cd "$START_DIR"
if [[ "$DO_H5PART" == "yes" ]] ; then
    check_if_installed "h5part" $H5PART_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping H5Part build.  H5Part is already installed."
    else
        info "Building H5Part (~1 minutes)"
        build_h5part
        if [[ $? != 0 ]] ; then
            error "Unable to build or install H5Part.  Bailing out."
        fi
        info "Done building H5Part"
    fi
fi

}

function bv_hdf4_initialize
{
export DO_HDF4="no"
export ON_HDF4="off"
}

function bv_hdf4_enable
{
DO_HDF4="yes"
ON_HDF4="on"
DO_SZIP="yes"
ON_SZIP="on"
}

function bv_hdf4_disable
{
DO_HDF4="no"
ON_HDF4="off"
}

function bv_hdf4_depends_on
{
echo "szip"
}

function bv_hdf4_info
{
export HDF4_FILE=${HDF4_FILE:-"hdf-4.2.5.tar.gz"}
export HDF4_VERSION=${HDF4_VERSION:-"4.2.5"}
export HDF4_COMPATIBILITY_VERSION=${HDF4_COMPATIBILITY_VERSION:-"4.2"}
export HDF4_BUILD_DIR=${HDF4_BUILD_DIR:-"hdf-4.2.5"}
export HDF4_URL=${HDF4_URL:-"http://www.hdfgroup.org/ftp/HDF/HDF_Current/src"}
export HDF4_MD5_CHECKSUM="7241a34b722d29d8561da0947c06069f"
export HDF4_SHA256_CHECKSUM=""
}

function bv_hdf4_initialize_vars
{
    info "testing hdf4 requirements"
    local lexv=`which lex`
    local yaccv=`which yacc`

    if [[ "$lexv" == "" || "$yaccv" == "" ]]; then
        error "HDF4 is enabled, but lex and yacc have not been found in system path."
    fi 
}

function bv_hdf4_print
{
  printf "%s%s\n" "HDF4_FILE=" "${HDF4_FILE}"
  printf "%s%s\n" "HDF4_VERSION=" "${HDF4_VERSION}"
  printf "%s%s\n" "HDF4_COMPATIBILITY_VERSION=" "${HDF4_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "HDF4_BUILD_DIR=" "${HDF4_BUILD_DIR}"
}

function bv_hdf4_print_usage
{
printf "%-15s %s [%s]\n" "--hdf4" "Build HDF4" "${DO_HDF4}"
}

function bv_hdf4_graphical
{
local graphical_out="HDF4     $HDF4_VERSION($HDF4_FILE)      $ON_HDF4"
echo $graphical_out
}

function bv_hdf4_host_profile
{
    if [[ "$DO_HDF4" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## HDF4" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_HDF4_DIR \${VISITHOME}/hdf4/$HDF4_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
        if [[ "$DO_SZIP" == "yes" ]] ; then
            echo \
            "VISIT_OPTION_DEFAULT(VISIT_HDF4_LIBDEP \${VISITHOME}/szip/$SZIP_VERSION/\${VISITARCH}/lib sz \${VISITHOME}/${VTK_INSTALL_DIR}/\${VTK_VERSION}/\${VISITARCH}/lib vtkjpeg-\${VTK_MAJOR_VERSION}.\${VTK_MINOR_VERSION} TYPE STRING)" \
            >> $HOSTCONF
          else
            echo \
            "VISIT_OPTION_DEFAULT(VISIT_HDF4_LIBDEP \${VISITHOME}/${VTK_INSTALL_DIR}/\${VTK_VERSION}/\${VISITARCH}/lib vtkjpeg-\${VTK_MAJOR_VERSION}.\${VTK_MINOR_VERSION} TYPE STRING)" \
            >> $HOSTCONF
        fi
    fi
}

function bv_hdf4_ensure
{
    if [[ "$DO_HDF4" == "yes" ]] ; then
        ensure_built_or_ready "hdf4" $HDF4_VERSION $HDF4_BUILD_DIR $HDF4_FILE $HDF4_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_HDF4="no"
            error "Unable to build HDF4.  ${HDF4_FILE} not found."
        fi
    fi
}

function bv_hdf4_dry_run
{
  if [[ "$DO_HDF4" == "yes" ]] ; then
    echo "Dry run option not set for hdf4."
  fi
}


# *************************************************************************** #
#                          Function 8.3, build_hdf4                           #
# *************************************************************************** #
function apply_hdf4_421_darwin_patch
{
   patch -p0 << \EOF
*** HDF4.2r1.orig/configure	Tue Feb  8 10:29:27 2005
--- HDF4.2r1/configure	Thu Apr 26 13:30:56 2007
*************** done
*** 5656,5711 ****
  
  echo "$as_me:$LINENO: checking for jpeg_start_decompress in -ljpeg" >&5
  echo $ECHO_N "checking for jpeg_start_decompress in -ljpeg... $ECHO_C" >&6
! if test "${ac_cv_lib_jpeg_jpeg_start_decompress+set}" = set; then
!   echo $ECHO_N "(cached) $ECHO_C" >&6
! else
!   ac_check_lib_save_LIBS=$LIBS
! LIBS="-ljpeg  $LIBS"
! cat >conftest.$ac_ext <<_ACEOF
! #line $LINENO "configure"
! /* confdefs.h.  */
! _ACEOF
! cat confdefs.h >>conftest.$ac_ext
! cat >>conftest.$ac_ext <<_ACEOF
! /* end confdefs.h.  */
! 
! /* Override any gcc2 internal prototype to avoid an error.  */
! #ifdef __cplusplus
! extern "C"
! #endif
! /* We use char because int might match the return type of a gcc2
!    builtin and then its argument prototype would still apply.  */
! char jpeg_start_decompress ();
! int
! main ()
! {
! jpeg_start_decompress ();
!   ;
!   return 0;
! }
! _ACEOF
! rm -f conftest.$ac_objext conftest$ac_exeext
! if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
!   (eval $ac_link) 2>&5
!   ac_status=$?
!   echo "$as_me:$LINENO: \$? = $ac_status" >&5
!   (exit $ac_status); } &&
!          { ac_try='test -s conftest$ac_exeext'
!   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
!   (eval $ac_try) 2>&5
!   ac_status=$?
!   echo "$as_me:$LINENO: \$? = $ac_status" >&5
!   (exit $ac_status); }; }; then
!   ac_cv_lib_jpeg_jpeg_start_decompress=yes
! else
!   echo "$as_me: failed program was:" >&5
! sed 's/^/| /' conftest.$ac_ext >&5
! 
! ac_cv_lib_jpeg_jpeg_start_decompress=no
! fi
! rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
! LIBS=$ac_check_lib_save_LIBS
! fi
  echo "$as_me:$LINENO: result: $ac_cv_lib_jpeg_jpeg_start_decompress" >&5
  echo "${ECHO_T}$ac_cv_lib_jpeg_jpeg_start_decompress" >&6
  if test $ac_cv_lib_jpeg_jpeg_start_decompress = yes; then
--- 5656,5712 ----
  
  echo "$as_me:$LINENO: checking for jpeg_start_decompress in -ljpeg" >&5
  echo $ECHO_N "checking for jpeg_start_decompress in -ljpeg... $ECHO_C" >&6
! #if test "${ac_cv_lib_jpeg_jpeg_start_decompress+set}" = set; then
! #  echo $ECHO_N "(cached) $ECHO_C" >&6
! #else
! #  ac_check_lib_save_LIBS=$LIBS
! #LIBS="-ljpeg  $LIBS"
! #cat >conftest.$ac_ext <<_ACEOF
! ##line $LINENO "configure"
! #/* confdefs.h.  */
! #_ACEOF
! #cat confdefs.h >>conftest.$ac_ext
! #cat >>conftest.$ac_ext <<_ACEOF
! #/* end confdefs.h.  */
! #
! #/* Override any gcc2 internal prototype to avoid an error.  */
! ##ifdef __cplusplus
! #extern "C"
! ##endif
! #/* We use char because int might match the return type of a gcc2
! #   builtin and then its argument prototype would still apply.  */
! #char jpeg_start_decompress ();
! #int
! #main ()
! #{
! #jpeg_start_decompress ();
! #  ;
! #  return 0;
! #}
! #_ACEOF
! #rm -f conftest.$ac_objext conftest$ac_exeext
! #if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
! #  (eval $ac_link) 2>&5
! #  ac_status=$?
! #  echo "$as_me:$LINENO: \$? = $ac_status" >&5
! #  (exit $ac_status); } &&
! #         { ac_try='test -s conftest$ac_exeext'
! #  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
! #  (eval $ac_try) 2>&5
! #  ac_status=$?
! #  echo "$as_me:$LINENO: \$? = $ac_status" >&5
! #  (exit $ac_status); }; }; then
! #  ac_cv_lib_jpeg_jpeg_start_decompress=yes
! #else
! #  echo "$as_me: failed program was:" >&5
! #sed 's/^/| /' conftest.$ac_ext >&5
! #
! #ac_cv_lib_jpeg_jpeg_start_decompress=no
! #fi
! #rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
! #LIBS=$ac_check_lib_save_LIBS
! #fi
! ac_cv_lib_jpeg_jpeg_start_decompress=yes
  echo "$as_me:$LINENO: result: $ac_cv_lib_jpeg_jpeg_start_decompress" >&5
  echo "${ECHO_T}$ac_cv_lib_jpeg_jpeg_start_decompress" >&6
  if test $ac_cv_lib_jpeg_jpeg_start_decompress = yes; then
*************** echo "${ECHO_T}$ac_cv_type_intp" >&6
*** 6874,7183 ****
  
  echo "$as_me:$LINENO: checking size of int*" >&5
  echo $ECHO_N "checking size of int*... $ECHO_C" >&6
! if test "${ac_cv_sizeof_intp+set}" = set; then
!   echo $ECHO_N "(cached) $ECHO_C" >&6
! else
!   if test "$ac_cv_type_intp" = yes; then
!   # The cast to unsigned long works around a bug in the HP C Compiler
!   # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
!   # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
!   # This bug is HP SR number 8606223364.
!   if test "$cross_compiling" = yes; then
!   # Depending upon the size, compute the lo and hi bounds.
! cat >conftest.$ac_ext <<_ACEOF
! #line $LINENO "configure"
! /* confdefs.h.  */
! _ACEOF
! cat confdefs.h >>conftest.$ac_ext
! cat >>conftest.$ac_ext <<_ACEOF
! /* end confdefs.h.  */
! $ac_includes_default
! int
! main ()
! {
! static int test_array [1 - 2 * !(((long) (sizeof (int*))) >= 0)];
! test_array [0] = 0
! 
!   ;
!   return 0;
! }
! _ACEOF
! rm -f conftest.$ac_objext
! if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
!   (eval $ac_compile) 2>&5
!   ac_status=$?
!   echo "$as_me:$LINENO: \$? = $ac_status" >&5
!   (exit $ac_status); } &&
!          { ac_try='test -s conftest.$ac_objext'
!   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
!   (eval $ac_try) 2>&5
!   ac_status=$?
!   echo "$as_me:$LINENO: \$? = $ac_status" >&5
!   (exit $ac_status); }; }; then
!   ac_lo=0 ac_mid=0
!   while :; do
!     cat >conftest.$ac_ext <<_ACEOF
! #line $LINENO "configure"
! /* confdefs.h.  */
! _ACEOF
! cat confdefs.h >>conftest.$ac_ext
! cat >>conftest.$ac_ext <<_ACEOF
! /* end confdefs.h.  */
! $ac_includes_default
! int
! main ()
! {
! static int test_array [1 - 2 * !(((long) (sizeof (int*))) <= $ac_mid)];
! test_array [0] = 0
! 
!   ;
!   return 0;
! }
! _ACEOF
! rm -f conftest.$ac_objext
! if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
!   (eval $ac_compile) 2>&5
!   ac_status=$?
!   echo "$as_me:$LINENO: \$? = $ac_status" >&5
!   (exit $ac_status); } &&
!          { ac_try='test -s conftest.$ac_objext'
!   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
!   (eval $ac_try) 2>&5
!   ac_status=$?
!   echo "$as_me:$LINENO: \$? = $ac_status" >&5
!   (exit $ac_status); }; }; then
!   ac_hi=$ac_mid; break
! else
!   echo "$as_me: failed program was:" >&5
! sed 's/^/| /' conftest.$ac_ext >&5
! 
! ac_lo=`expr $ac_mid + 1`
!                     if test $ac_lo -le $ac_mid; then
!                       ac_lo= ac_hi=
!                       break
!                     fi
!                     ac_mid=`expr 2 '*' $ac_mid + 1`
! fi
! rm -f conftest.$ac_objext conftest.$ac_ext
!   done
! else
!   echo "$as_me: failed program was:" >&5
! sed 's/^/| /' conftest.$ac_ext >&5
! 
! cat >conftest.$ac_ext <<_ACEOF
! #line $LINENO "configure"
! /* confdefs.h.  */
! _ACEOF
! cat confdefs.h >>conftest.$ac_ext
! cat >>conftest.$ac_ext <<_ACEOF
! /* end confdefs.h.  */
! $ac_includes_default
! int
! main ()
! {
! static int test_array [1 - 2 * !(((long) (sizeof (int*))) < 0)];
! test_array [0] = 0
! 
!   ;
!   return 0;
! }
! _ACEOF
! rm -f conftest.$ac_objext
! if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
!   (eval $ac_compile) 2>&5
!   ac_status=$?
!   echo "$as_me:$LINENO: \$? = $ac_status" >&5
!   (exit $ac_status); } &&
!          { ac_try='test -s conftest.$ac_objext'
!   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
!   (eval $ac_try) 2>&5
!   ac_status=$?
!   echo "$as_me:$LINENO: \$? = $ac_status" >&5
!   (exit $ac_status); }; }; then
!   ac_hi=-1 ac_mid=-1
!   while :; do
!     cat >conftest.$ac_ext <<_ACEOF
! #line $LINENO "configure"
! /* confdefs.h.  */
! _ACEOF
! cat confdefs.h >>conftest.$ac_ext
! cat >>conftest.$ac_ext <<_ACEOF
! /* end confdefs.h.  */
! $ac_includes_default
! int
! main ()
! {
! static int test_array [1 - 2 * !(((long) (sizeof (int*))) >= $ac_mid)];
! test_array [0] = 0
! 
!   ;
!   return 0;
! }
! _ACEOF
! rm -f conftest.$ac_objext
! if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
!   (eval $ac_compile) 2>&5
!   ac_status=$?
!   echo "$as_me:$LINENO: \$? = $ac_status" >&5
!   (exit $ac_status); } &&
!          { ac_try='test -s conftest.$ac_objext'
!   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
!   (eval $ac_try) 2>&5
!   ac_status=$?
!   echo "$as_me:$LINENO: \$? = $ac_status" >&5
!   (exit $ac_status); }; }; then
!   ac_lo=$ac_mid; break
! else
!   echo "$as_me: failed program was:" >&5
! sed 's/^/| /' conftest.$ac_ext >&5
! 
! ac_hi=`expr '(' $ac_mid ')' - 1`
!                        if test $ac_mid -le $ac_hi; then
!                          ac_lo= ac_hi=
!                          break
!                        fi
!                        ac_mid=`expr 2 '*' $ac_mid`
! fi
! rm -f conftest.$ac_objext conftest.$ac_ext
!   done
! else
!   echo "$as_me: failed program was:" >&5
! sed 's/^/| /' conftest.$ac_ext >&5
! 
! ac_lo= ac_hi=
! fi
! rm -f conftest.$ac_objext conftest.$ac_ext
! fi
! rm -f conftest.$ac_objext conftest.$ac_ext
! # Binary search between lo and hi bounds.
! while test "x$ac_lo" != "x$ac_hi"; do
!   ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo`
!   cat >conftest.$ac_ext <<_ACEOF
! #line $LINENO "configure"
! /* confdefs.h.  */
! _ACEOF
! cat confdefs.h >>conftest.$ac_ext
! cat >>conftest.$ac_ext <<_ACEOF
! /* end confdefs.h.  */
! $ac_includes_default
! int
! main ()
! {
! static int test_array [1 - 2 * !(((long) (sizeof (int*))) <= $ac_mid)];
! test_array [0] = 0
! 
!   ;
!   return 0;
! }
! _ACEOF
! rm -f conftest.$ac_objext
! if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
!   (eval $ac_compile) 2>&5
!   ac_status=$?
!   echo "$as_me:$LINENO: \$? = $ac_status" >&5
!   (exit $ac_status); } &&
!          { ac_try='test -s conftest.$ac_objext'
!   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
!   (eval $ac_try) 2>&5
!   ac_status=$?
!   echo "$as_me:$LINENO: \$? = $ac_status" >&5
!   (exit $ac_status); }; }; then
!   ac_hi=$ac_mid
! else
!   echo "$as_me: failed program was:" >&5
! sed 's/^/| /' conftest.$ac_ext >&5
! 
! ac_lo=`expr '(' $ac_mid ')' + 1`
! fi
! rm -f conftest.$ac_objext conftest.$ac_ext
! done
! case $ac_lo in
! ?*) ac_cv_sizeof_intp=$ac_lo;;
! '') { { echo "$as_me:$LINENO: error: cannot compute sizeof (int*), 77
! See \`config.log' for more details." >&5
! echo "$as_me: error: cannot compute sizeof (int*), 77
! See \`config.log' for more details." >&2;}
!    { (exit 1); exit 1; }; } ;;
! esac
! else
!   if test "$cross_compiling" = yes; then
!   { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
! See \`config.log' for more details." >&5
! echo "$as_me: error: cannot run test program while cross compiling
! See \`config.log' for more details." >&2;}
!    { (exit 1); exit 1; }; }
! else
!   cat >conftest.$ac_ext <<_ACEOF
! #line $LINENO "configure"
! /* confdefs.h.  */
! _ACEOF
! cat confdefs.h >>conftest.$ac_ext
! cat >>conftest.$ac_ext <<_ACEOF
! /* end confdefs.h.  */
! $ac_includes_default
! long longval () { return (long) (sizeof (int*)); }
! unsigned long ulongval () { return (long) (sizeof (int*)); }
! #include <stdio.h>
! #include <stdlib.h>
! int
! main ()
! {
! 
!   FILE *f = fopen ("conftest.val", "w");
!   if (! f)
!     exit (1);
!   if (((long) (sizeof (int*))) < 0)
!     {
!       long i = longval ();
!       if (i != ((long) (sizeof (int*))))
! 	exit (1);
!       fprintf (f, "%ld\n", i);
!     }
!   else
!     {
!       unsigned long i = ulongval ();
!       if (i != ((long) (sizeof (int*))))
! 	exit (1);
!       fprintf (f, "%lu\n", i);
!     }
!   exit (ferror (f) || fclose (f) != 0);
! 
!   ;
!   return 0;
! }
! _ACEOF
! rm -f conftest$ac_exeext
! if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
!   (eval $ac_link) 2>&5
!   ac_status=$?
!   echo "$as_me:$LINENO: \$? = $ac_status" >&5
!   (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
!   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
!   (eval $ac_try) 2>&5
!   ac_status=$?
!   echo "$as_me:$LINENO: \$? = $ac_status" >&5
!   (exit $ac_status); }; }; then
!   ac_cv_sizeof_intp=`cat conftest.val`
! else
!   echo "$as_me: program exited with status $ac_status" >&5
! echo "$as_me: failed program was:" >&5
! sed 's/^/| /' conftest.$ac_ext >&5
! 
! ( exit $ac_status )
! { { echo "$as_me:$LINENO: error: cannot compute sizeof (int*), 77
! See \`config.log' for more details." >&5
! echo "$as_me: error: cannot compute sizeof (int*), 77
! See \`config.log' for more details." >&2;}
!    { (exit 1); exit 1; }; }
! fi
! rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
! fi
! fi
! rm -f conftest.val
! else
!   ac_cv_sizeof_intp=0
! fi
! fi
  echo "$as_me:$LINENO: result: $ac_cv_sizeof_intp" >&5
  echo "${ECHO_T}$ac_cv_sizeof_intp" >&6
  cat >>confdefs.h <<_ACEOF
--- 6875,7185 ----
  
  echo "$as_me:$LINENO: checking size of int*" >&5
  echo $ECHO_N "checking size of int*... $ECHO_C" >&6
! #if test "${ac_cv_sizeof_intp+set}" = set; then
! #  echo $ECHO_N "(cached) $ECHO_C" >&6
! #else
! #  if test "$ac_cv_type_intp" = yes; then
! #  # The cast to unsigned long works around a bug in the HP C Compiler
! #  # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
! #  # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
! #  # This bug is HP SR number 8606223364.
! #  if test "$cross_compiling" = yes; then
! #  # Depending upon the size, compute the lo and hi bounds.
! #cat >conftest.$ac_ext <<_ACEOF
! ##line $LINENO "configure"
! #/* confdefs.h.  */
! #_ACEOF
! #cat confdefs.h >>conftest.$ac_ext
! #cat >>conftest.$ac_ext <<_ACEOF
! #/* end confdefs.h.  */
! #$ac_includes_default
! #int
! #main ()
! #{
! #static int test_array [1 - 2 * !(((long) (sizeof (int*))) >= 0)];
! #test_array [0] = 0
! #
! #  ;
! #  return 0;
! #}
! #_ACEOF
! #rm -f conftest.$ac_objext
! #if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
! #  (eval $ac_compile) 2>&5
! #  ac_status=$?
! #  echo "$as_me:$LINENO: \$? = $ac_status" >&5
! #  (exit $ac_status); } &&
! #         { ac_try='test -s conftest.$ac_objext'
! #  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
! #  (eval $ac_try) 2>&5
! #  ac_status=$?
! #  echo "$as_me:$LINENO: \$? = $ac_status" >&5
! #  (exit $ac_status); }; }; then
! #  ac_lo=0 ac_mid=0
! #  while :; do
! #    cat >conftest.$ac_ext <<_ACEOF
! ##line $LINENO "configure"
! #/* confdefs.h.  */
! #_ACEOF
! #cat confdefs.h >>conftest.$ac_ext
! #cat >>conftest.$ac_ext <<_ACEOF
! #/* end confdefs.h.  */
! #$ac_includes_default
! #int
! #main ()
! #{
! #static int test_array [1 - 2 * !(((long) (sizeof (int*))) <= $ac_mid)];
! #test_array [0] = 0
! #
! #  ;
! #  return 0;
! #}
! #_ACEOF
! #rm -f conftest.$ac_objext
! #if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
! #  (eval $ac_compile) 2>&5
! #  ac_status=$?
! #  echo "$as_me:$LINENO: \$? = $ac_status" >&5
! #  (exit $ac_status); } &&
! #         { ac_try='test -s conftest.$ac_objext'
! #  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
! #  (eval $ac_try) 2>&5
! #  ac_status=$?
! #  echo "$as_me:$LINENO: \$? = $ac_status" >&5
! #  (exit $ac_status); }; }; then
! #  ac_hi=$ac_mid; break
! #else
! #  echo "$as_me: failed program was:" >&5
! #sed 's/^/| /' conftest.$ac_ext >&5
! #
! #ac_lo=`expr $ac_mid + 1`
! #                    if test $ac_lo -le $ac_mid; then
! #                      ac_lo= ac_hi=
! #                      break
! #                    fi
! #                    ac_mid=`expr 2 '*' $ac_mid + 1`
! #fi
! #rm -f conftest.$ac_objext conftest.$ac_ext
! #  done
! #else
! #  echo "$as_me: failed program was:" >&5
! #sed 's/^/| /' conftest.$ac_ext >&5
! #
! #cat >conftest.$ac_ext <<_ACEOF
! ##line $LINENO "configure"
! #/* confdefs.h.  */
! #_ACEOF
! #cat confdefs.h >>conftest.$ac_ext
! #cat >>conftest.$ac_ext <<_ACEOF
! #/* end confdefs.h.  */
! #$ac_includes_default
! #int
! #main ()
! #{
! #static int test_array [1 - 2 * !(((long) (sizeof (int*))) < 0)];
! #test_array [0] = 0
! #
! #  ;
! #  return 0;
! #}
! #_ACEOF
! #rm -f conftest.$ac_objext
! #if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
! #  (eval $ac_compile) 2>&5
! #  ac_status=$?
! #  echo "$as_me:$LINENO: \$? = $ac_status" >&5
! #  (exit $ac_status); } &&
! #         { ac_try='test -s conftest.$ac_objext'
! #  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
! #  (eval $ac_try) 2>&5
! #  ac_status=$?
! #  echo "$as_me:$LINENO: \$? = $ac_status" >&5
! #  (exit $ac_status); }; }; then
! #  ac_hi=-1 ac_mid=-1
! #  while :; do
! #    cat >conftest.$ac_ext <<_ACEOF
! ##line $LINENO "configure"
! #/* confdefs.h.  */
! #_ACEOF
! #cat confdefs.h >>conftest.$ac_ext
! #cat >>conftest.$ac_ext <<_ACEOF
! #/* end confdefs.h.  */
! #$ac_includes_default
! #int
! #main ()
! #{
! #static int test_array [1 - 2 * !(((long) (sizeof (int*))) >= $ac_mid)];
! #test_array [0] = 0
! #
! #  ;
! #  return 0;
! #}
! #_ACEOF
! #rm -f conftest.$ac_objext
! #if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
! #  (eval $ac_compile) 2>&5
! #  ac_status=$?
! #  echo "$as_me:$LINENO: \$? = $ac_status" >&5
! #  (exit $ac_status); } &&
! #         { ac_try='test -s conftest.$ac_objext'
! #  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
! #  (eval $ac_try) 2>&5
! #  ac_status=$?
! #  echo "$as_me:$LINENO: \$? = $ac_status" >&5
! #  (exit $ac_status); }; }; then
! #  ac_lo=$ac_mid; break
! #else
! #  echo "$as_me: failed program was:" >&5
! #sed 's/^/| /' conftest.$ac_ext >&5
! #
! #ac_hi=`expr '(' $ac_mid ')' - 1`
! #                       if test $ac_mid -le $ac_hi; then
! #                         ac_lo= ac_hi=
! #                         break
! #                       fi
! #                       ac_mid=`expr 2 '*' $ac_mid`
! #fi
! #rm -f conftest.$ac_objext conftest.$ac_ext
! #  done
! #else
! #  echo "$as_me: failed program was:" >&5
! #sed 's/^/| /' conftest.$ac_ext >&5
! #
! #ac_lo= ac_hi=
! #fi
! #rm -f conftest.$ac_objext conftest.$ac_ext
! #fi
! #rm -f conftest.$ac_objext conftest.$ac_ext
! ## Binary search between lo and hi bounds.
! #while test "x$ac_lo" != "x$ac_hi"; do
! #  ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo`
! #  cat >conftest.$ac_ext <<_ACEOF
! ##line $LINENO "configure"
! #/* confdefs.h.  */
! #_ACEOF
! #cat confdefs.h >>conftest.$ac_ext
! #cat >>conftest.$ac_ext <<_ACEOF
! #/* end confdefs.h.  */
! #$ac_includes_default
! #int
! #main ()
! #{
! #static int test_array [1 - 2 * !(((long) (sizeof (int*))) <= $ac_mid)];
! #test_array [0] = 0
! #
! #  ;
! #  return 0;
! #}
! #_ACEOF
! #rm -f conftest.$ac_objext
! #if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
! #  (eval $ac_compile) 2>&5
! #  ac_status=$?
! #  echo "$as_me:$LINENO: \$? = $ac_status" >&5
! #  (exit $ac_status); } &&
! #         { ac_try='test -s conftest.$ac_objext'
! #  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
! #  (eval $ac_try) 2>&5
! #  ac_status=$?
! #  echo "$as_me:$LINENO: \$? = $ac_status" >&5
! #  (exit $ac_status); }; }; then
! #  ac_hi=$ac_mid
! #else
! #  echo "$as_me: failed program was:" >&5
! #sed 's/^/| /' conftest.$ac_ext >&5
! #
! #ac_lo=`expr '(' $ac_mid ')' + 1`
! #fi
! #rm -f conftest.$ac_objext conftest.$ac_ext
! #done
! #case $ac_lo in
! #?*) ac_cv_sizeof_intp=$ac_lo;;
! #'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (int*), 77
! #See \`config.log' for more details." >&5
! #echo "$as_me: error: cannot compute sizeof (int*), 77
! #See \`config.log' for more details." >&2;}
! #   { (exit 1); exit 1; }; } ;;
! #esac
! #else
! #  if test "$cross_compiling" = yes; then
! #  { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
! #See \`config.log' for more details." >&5
! #echo "$as_me: error: cannot run test program while cross compiling
! #See \`config.log' for more details." >&2;}
! #   { (exit 1); exit 1; }; }
! #else
! #  cat >conftest.$ac_ext <<_ACEOF
! ##line $LINENO "configure"
! #/* confdefs.h.  */
! #_ACEOF
! #cat confdefs.h >>conftest.$ac_ext
! #cat >>conftest.$ac_ext <<_ACEOF
! #/* end confdefs.h.  */
! #$ac_includes_default
! #long longval () { return (long) (sizeof (int*)); }
! #unsigned long ulongval () { return (long) (sizeof (int*)); }
! ##include <stdio.h>
! ##include <stdlib.h>
! #int
! #main ()
! #{
! #
! #  FILE *f = fopen ("conftest.val", "w");
! #  if (! f)
! #    exit (1);
! #  if (((long) (sizeof (int*))) < 0)
! #    {
! #      long i = longval ();
! #      if (i != ((long) (sizeof (int*))))
! #	exit (1);
! #      fprintf (f, "%ld\n", i);
! #    }
! #  else
! #    {
! #      unsigned long i = ulongval ();
! #      if (i != ((long) (sizeof (int*))))
! #	exit (1);
! #      fprintf (f, "%lu\n", i);
! #    }
! #  exit (ferror (f) || fclose (f) != 0);
! #
! #  ;
! #  return 0;
! #}
! #_ACEOF
! #rm -f conftest$ac_exeext
! #if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
! #  (eval $ac_link) 2>&5
! #  ac_status=$?
! #  echo "$as_me:$LINENO: \$? = $ac_status" >&5
! #  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
! #  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
! #  (eval $ac_try) 2>&5
! #  ac_status=$?
! #  echo "$as_me:$LINENO: \$? = $ac_status" >&5
! #  (exit $ac_status); }; }; then
! #  ac_cv_sizeof_intp=`cat conftest.val`
! #else
! #  echo "$as_me: program exited with status $ac_status" >&5
! #echo "$as_me: failed program was:" >&5
! #sed 's/^/| /' conftest.$ac_ext >&5
! #
! #( exit $ac_status )
! #{ { echo "$as_me:$LINENO: error: cannot compute sizeof (int*), 77
! #See \`config.log' for more details." >&5
! #echo "$as_me: error: cannot compute sizeof (int*), 77
! #See \`config.log' for more details." >&2;}
! #   { (exit 1); exit 1; }; }
! #fi
! #rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
! #fi
! #fi
! #rm -f conftest.val
! #else
! #  ac_cv_sizeof_intp=0
! #fi
! #fi
! ac_cv_sizeof_intp=4
  echo "$as_me:$LINENO: result: $ac_cv_sizeof_intp" >&5
  echo "${ECHO_T}$ac_cv_sizeof_intp" >&6
  cat >>confdefs.h <<_ACEOF
*** HDF4.2r1.orig/hdf/src/hdfi.h	Mon Jan 24 19:36:44 2005
--- HDF4.2r1/hdf/src/hdfi.h	Thu Apr 26 13:39:53 2007
***************
*** 10,16 ****
   *                                                                          *
   ****************************************************************************/
  
! /* $Id: hdfi.h,v 1.156 2005/01/25 03:36:44 epourmal Exp $ */
  
  #ifndef HDFI_H
  #define HDFI_H
--- 10,16 ----
   *                                                                          *
   ****************************************************************************/
  
! /* $Id: hdfi.h 4798 2006-12-06 20:51:13Z epourmal $ */
  
  #ifndef HDFI_H
  #define HDFI_H
***************
*** 62,67 ****
--- 62,68 ----
  #define     DFMT_MIPSEL         0x4441
  #define     DFMT_PC             0x4441
  #define     DFMT_APPLE          0x1111
+ #define     DFMT_APPLE_INTEL    0x4441
  #define     DFMT_MAC            0x1111
  #define     DFMT_SUN386         0x4441
  #define     DFMT_NEXT           0x1111
*************** typedef int               hdf_pint_t;   
*** 607,612 ****
--- 608,626 ----
  
  #endif /* CRAYMPP */
  
+ /* CRAY XT3
+  * Note from RedStorm helpdesk,
+  * When I compile a C code with the '-v' option, it indicates that the compile
+  * is done with the macros __QK_USER__ and __LIBCATAMOUNT__ defined.  In
+  * addition, there are other macros like __x86_64__ defined as well, to
+  * indicate processor type.  __QK_USER__ might be a good check for Catamount,
+  * and __x86_64__ might be good for Opteron node.  You might try something
+  * like the following in a header file:
+  */
+ #if ((defined(__QK_USER__)) && (defined(__x86_64__)))
+ #define __CRAY_XT3__
+ #endif
+ 
  #if defined(VMS) || defined(vms)
  
  #ifdef GOT_MACHINE
*************** Please check your Makefile.
*** 736,742 ****
  #include <sys/types.h>
  #include <sys/file.h>               /* for unbuffered i/o stuff */
  #include <sys/stat.h>
! #define DF_MT   DFMT_APPLE 
  typedef void            VOID;
  typedef void            *VOIDP;
  typedef char            *_fcd;
--- 750,764 ----
  #include <sys/types.h>
  #include <sys/file.h>               /* for unbuffered i/o stuff */
  #include <sys/stat.h>
! #ifdef __i386
! #ifndef INTEL86
! #define INTEL86   /* we need this Intel define or bad things happen later */
! #endif /* INTEL86 */
! #define DF_MT   DFMT_APPLE_INTEL
! #else
! #define DF_MT   DFMT_APPLE
! #endif /* __i386 */
! 
  typedef void            VOID;
  typedef void            *VOIDP;
  typedef char            *_fcd;
*************** void exit(int status);
*** 886,892 ****
  #endif /*MAC*/
  
  /* Metrowerks Mac compiler defines some PC stuff so need to exclude this on the Mac */
! #if !(defined(macintosh) || defined(MAC))
  
  #if defined _M_ALPHA || defined _M_IX86 || defined INTEL86 || defined M_I86 || defined M_I386 || defined DOS386 || defined __i386 || defined UNIX386 || defined i386
  #ifndef INTEL86
--- 908,914 ----
  #endif /*MAC*/
  
  /* Metrowerks Mac compiler defines some PC stuff so need to exclude this on the Mac */
! #if !(defined(macintosh) || defined(MAC) || defined (__APPLE__))
  
  #if defined _M_ALPHA || defined _M_IX86 || defined INTEL86 || defined M_I86 || defined M_I386 || defined DOS386 || defined __i386 || defined UNIX386 || defined i386
  #ifndef INTEL86
EOF
   if [[ $? != 0 ]] ; then
      warn "Unable to patch HDF4. Wrong version?"
      return 1
   fi
}

# Sets up defines so that HDF4 can build on Linux-ppc64.
function apply_hdf4_421_ppc_patch
{
    patch -p0 << \EOF
--- HDF4.2r1/hdf/src/hdfi.h.bak	2004-06-11 21:28:20.763821223 +0200
+++ HDF4.2r1/hdf/src/hdfi.h	2004-06-11 21:43:34.853673152 +0200
@@ -1318,6 +1318,55 @@
 
 #endif /* IA-64 */
 
+#if defined(__powerpc__)
+
+#ifdef GOT_MACHINE
+#error If you get an error on this line more than one machine type has been defined. Please check your Makefile.
+#endif
+#define GOT_MACHINE
+
+#include <sys/file.h>               /* for unbuffered i/o stuff */
+#include <sys/stat.h>
+#define DF_MT           DFMT_MAC
+typedef void            VOID;
+typedef void *          VOIDP;
+typedef char *          _fcd;
+typedef char            char8;
+typedef unsigned char   uchar8;
+typedef char            int8;
+typedef unsigned char   uint8;
+typedef short int       int16;
+typedef unsigned short  uint16;
+typedef int             int32;
+typedef unsigned int    uint32;
+typedef int             intn;
+typedef unsigned int    uintn;
+typedef long            intf;       /* size of INTEGERs in Fortran compiler  */
+typedef float           float32;
+typedef double          float64;
+typedef int             hdf_pint_t; /* an integer the same size as a pointer */
+#define FNAME_POST_UNDERSCORE
+#define _fcdtocp(desc) (desc)
+#ifdef  HAVE_FMPOOL
+#define FILELIB PAGEBUFIO  /* enable page buffering */
+#else
+#define FILELIB UNIXBUFIO
+#endif
+
+/* JPEG #define's - Look in the JPEG docs before changing - (Q) */
+
+/* Determine the memory manager we are going to use. Valid values are: */
+/*  MEM_DOS, MEM_ANSI, MEM_NAME, MEM_NOBS.  See the JPEG docs for details on */
+/*  what each does */
+#define JMEMSYS         MEM_ANSI
+
+#ifdef __GNUC__
+#define HAVE_STDC
+#define INCLUDES_ARE_ANSI
+#endif
+
+#endif /* ppc */
+
 #ifndef GOT_MACHINE
 #error No machine type has been defined.  Your Makefile needs to have someing like -DSUN or -DUNICOS in order for the HDF internal structures to be defined correctly.
 #endif
EOF
}

# Switches a define for the endianness on PPC systems.
function apply_hdf4_421_ppc_patch_endianness
{
  patch -p0 << \EOF
--- HDF4.2r1/hdf/fmpool/config/fmplinux.h.orig	2009-03-17 21:10:59.240084436 -0700
+++ HDF4.2r1/hdf/fmpool/config/fmplinux.h	2009-03-17 21:11:24.868152481 -0700
@@ -36,7 +36,7 @@
 #define HAVE_STAT
 #define HAVE_MIN_MAX
 #define HAVE_CDEFS_H
-#define	BYTE_ORDER  LITTLE_ENDIAN	
+#define	BYTE_ORDER  BIG_ENDIAN	
 
 #endif /* _FMPCONF_H */
EOF
}

function apply_hdf4_421_patch
{
   if [[ "$OPSYS" == "Darwin" ]]; then
       apply_hdf4_421_darwin_patch
       if [[ $? != 0 ]] ; then
           return 1
       fi
   fi

   return 0
}

function apply_hdf4_425_patch
{
   patch -p0 << \EOF
diff -c a/configure hdf-4.2.5/configure
*** a/configure
--- hdf-4.2.5/configure
***************
*** 6770,6782 ****

  done

!     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for jpeg_start_decompress in -ljpeg" >&5
! $as_echo_n "checking for jpeg_start_decompress in -ljpeg... " >&6; }
! if test "${ac_cv_lib_jpeg_jpeg_start_decompress+set}" = set; then :
    $as_echo_n "(cached) " >&6
  else
    ac_check_lib_save_LIBS=$LIBS
! LIBS="-ljpeg  $LIBS"
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  /* end confdefs.h.  */

--- 6770,6782 ----

  done

!     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for vtk_jpeg_start_decompress in -lvtkjpeg-${VTK_SHORT_VERSION}" >&5
! $as_echo_n "checking for vtk_jpeg_start_decompress in -lvtkjpeg-${VTK_SHORT_VERSION}... " >&6; }
! if test "${ac_cv_lib_jpeg_vtk_jpeg_start_decompress+set}" = set; then :
    $as_echo_n "(cached) " >&6
  else
    ac_check_lib_save_LIBS=$LIBS
! LIBS="-lvtkjpeg-${VTK_SHORT_VERSION}  $LIBS"
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  /* end confdefs.h.  */

***************
*** 6786,6792 ****
  #ifdef __cplusplus
  extern "C"
  #endif
! char jpeg_start_decompress ();
  #ifdef F77_DUMMY_MAIN

  #  ifdef __cplusplus
--- 6786,6792 ----
  #ifdef __cplusplus
  extern "C"
  #endif
! char vtk_jpeg_start_decompress ();
  #ifdef F77_DUMMY_MAIN

  #  ifdef __cplusplus
***************
*** 6798,6825 ****
  int
  main ()
  {
! return jpeg_start_decompress ();
    ;
    return 0;
  }
  _ACEOF
  if ac_fn_c_try_link "$LINENO"; then :
!   ac_cv_lib_jpeg_jpeg_start_decompress=yes
  else
!   ac_cv_lib_jpeg_jpeg_start_decompress=no
  fi
  rm -f core conftest.err conftest.$ac_objext \
      conftest$ac_exeext conftest.$ac_ext
  LIBS=$ac_check_lib_save_LIBS
  fi
! { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_jpeg_jpeg_start_decompress" >&5
! $as_echo "$ac_cv_lib_jpeg_jpeg_start_decompress" >&6; }
! if test "x$ac_cv_lib_jpeg_jpeg_start_decompress" = x""yes; then :
    cat >>confdefs.h <<_ACEOF
  #define HAVE_LIBJPEG 1
  _ACEOF

!   LIBS="-ljpeg $LIBS"

  else
    unset HAVE_JPEG
--- 6798,6825 ----
  int
  main ()
  {
! return vtk_jpeg_start_decompress ();
    ;
    return 0;
  }
  _ACEOF
  if ac_fn_c_try_link "$LINENO"; then :
!   ac_cv_lib_jpeg_vtk_jpeg_start_decompress=yes
  else
!   ac_cv_lib_jpeg_vtk_jpeg_start_decompress=no
  fi
  rm -f core conftest.err conftest.$ac_objext \
      conftest$ac_exeext conftest.$ac_ext
  LIBS=$ac_check_lib_save_LIBS
  fi
! { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_jpeg_vtk_jpeg_start_decompress" >&5
! $as_echo "$ac_cv_lib_jpeg_vtk_jpeg_start_decompress" >&6; }
! if test "x$ac_cv_lib_jpeg_vtk_jpeg_start_decompress" = x""yes; then :
    cat >>confdefs.h <<_ACEOF
  #define HAVE_LIBJPEG 1
  _ACEOF

!   LIBS="-lvtkjpeg-${VTK_SHORT_VERSION} $LIBS"

  else
    unset HAVE_JPEG
***************
*** 6878,6890 ****
        LDFLAGS="$LDFLAGS -L$jpeg_lib"
      fi

!     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for jpeg_start_decompress in -ljpeg" >&5
! $as_echo_n "checking for jpeg_start_decompress in -ljpeg... " >&6; }
! if test "${ac_cv_lib_jpeg_jpeg_start_decompress+set}" = set; then :
    $as_echo_n "(cached) " >&6
  else
    ac_check_lib_save_LIBS=$LIBS
! LIBS="-ljpeg  $LIBS"
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  /* end confdefs.h.  */

--- 6878,6890 ----
        LDFLAGS="$LDFLAGS -L$jpeg_lib"
      fi

!     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for vtk_jpeg_start_decompress in -lvtkjpeg-${VTK_SHORT_VERSION}" >&5
! $as_echo_n "checking for vtk_jpeg_start_decompress in -lvtkjpeg-${VTK_SHORT_VERSION}... " >&6; }
! if test "${ac_cv_lib_jpeg_vtk_jpeg_start_decompress+set}" = set; then :
    $as_echo_n "(cached) " >&6
  else
    ac_check_lib_save_LIBS=$LIBS
! LIBS="-lvtkjpeg-${VTK_SHORT_VERSION}  $LIBS"
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  /* end confdefs.h.  */

***************
*** 6894,6900 ****
  #ifdef __cplusplus
  extern "C"
  #endif
! char jpeg_start_decompress ();
  #ifdef F77_DUMMY_MAIN

  #  ifdef __cplusplus
--- 6894,6900 ----
  #ifdef __cplusplus
  extern "C"
  #endif
! char vtk_jpeg_start_decompress ();
  #ifdef F77_DUMMY_MAIN

  #  ifdef __cplusplus
***************
*** 6906,6933 ****
  int
  main ()
  {
! return jpeg_start_decompress ();
    ;
    return 0;
  }
  _ACEOF
  if ac_fn_c_try_link "$LINENO"; then :
!   ac_cv_lib_jpeg_jpeg_start_decompress=yes
  else
!   ac_cv_lib_jpeg_jpeg_start_decompress=no
  fi
  rm -f core conftest.err conftest.$ac_objext \
      conftest$ac_exeext conftest.$ac_ext
  LIBS=$ac_check_lib_save_LIBS
  fi
! { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_jpeg_jpeg_start_decompress" >&5
! $as_echo "$ac_cv_lib_jpeg_jpeg_start_decompress" >&6; }
! if test "x$ac_cv_lib_jpeg_jpeg_start_decompress" = x""yes; then :
    cat >>confdefs.h <<_ACEOF
  #define HAVE_LIBJPEG 1
  _ACEOF

!   LIBS="-ljpeg $LIBS"

  else
    unset HAVE_JPEG
--- 6906,6933 ----
  int
  main ()
  {
! return vtk_jpeg_start_decompress ();
    ;
    return 0;
  }
  _ACEOF
  if ac_fn_c_try_link "$LINENO"; then :
!   ac_cv_lib_jpeg_vtk_jpeg_start_decompress=yes
  else
!   ac_cv_lib_jpeg_vtk_jpeg_start_decompress=no
  fi
  rm -f core conftest.err conftest.$ac_objext \
      conftest$ac_exeext conftest.$ac_ext
  LIBS=$ac_check_lib_save_LIBS
  fi
! { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_jpeg_vtk_jpeg_start_decompress" >&5
! $as_echo "$ac_cv_lib_jpeg_vtk_jpeg_start_decompress" >&6; }
! if test "x$ac_cv_lib_jpeg_vtk_jpeg_start_decompress" = x""yes; then :
    cat >>confdefs.h <<_ACEOF
  #define HAVE_LIBJPEG 1
  _ACEOF

!   LIBS="-lvtkjpeg-${VTK_SHORT_VERSION} $LIBS"

  else
    unset HAVE_JPEG
EOF
   if [[ $? != 0 ]] ; then
      warn "HDF4 patch failed."
      return 1
   fi

   return 0
}

function apply_hdf4_patch
{
   if [[ ${HDF4_VERSION} == 4.2.1 ]] ; then
       apply_hdf4_421_patch
       if [[ $? != 0 ]] ; then
           return 1
       fi
   fi
   if [[ ${HDF4_VERSION} == 4.2.5 ]] ; then
       apply_hdf4_425_patch
       if [[ $? != 0 ]] ; then
           return 1
       fi
   fi
   if [[ `uname -m` == "ppc64" ]]; then
       apply_hdf4_421_ppc_patch
       apply_hdf4_421_ppc_patch_endianness
   fi

   return 0
}

function build_hdf4
{
    #
    # Prepare build dir
    #
    prepare_build_dir $HDF4_BUILD_DIR $HDF4_FILE
    untarred_hdf4=$?
    if [[ $untarred_hdf4 == -1 ]] ; then
       warn "Unable to prepare HDF4 Build Directory. Giving Up"
       return 1
    fi
    #
    # Apply patches
    #
    info "Patching HDF . . ." 
    apply_hdf4_patch
    if [[ $? != 0 ]] ; then
       if [[ $untarred_hdf4 == 1 ]] ; then
          warn "Giving up on HDF4 build because the patch failed."
          return 1
       else
          warn "Patch failed, but continuing.  I believe that this script\n" \
               "tried to apply a patch to an existing directory which had\n" \
               "already been patched ... that is, that the patch is\n" \
               "failing harmlessly on a second application."
       fi
    fi

    if [[ "$FC_COMPILER" == "no" ]] ; then
        FORTRANARGS="--disable-fortran"
    else
        FORTRANARGS="FC=\"$FC_COMPILER\" F77=\"$FC_COMPILER\" FCFLAGS=\"$FCFLAGS\" FFLAGS=\"$FCFLAGS\" --enable-fortran"
    fi

    info "Configuring HDF4 . . ."
    cd $HDF4_BUILD_DIR || error "Can't cd to hdf4 build dir."
    info "Invoking command to configure HDF4"
    MAKEOPS=""
    if [[ "$OPSYS" == "Darwin" || "$OPSYS" == "AIX" ]]; then
        export DYLD_LIBRARY_PATH="$VISITDIR/szip/$SZIP_VERSION/$VISITARCH/lib":$DYLD_LIBRARY_PATH
        # In order to ensure $FORTRANARGS is expanded to build the arguments to
        # configure, we wrap the invokation in 'sh -c "..."' syntax
        sh -c "./configure CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" \
        CFLAGS=\"$CFLAGS $C_OPT_FLAGS\" \
        CPPFLAGS=\"-I$VISITDIR/${VTK_INSTALL_DIR}/${VTK_VERSION}/$VISITARCH/include/vtk-${VTK_SHORT_VERSION} \
        -I$VISITDIR/${VTK_INSTALL_DIR}/${VTK_VERSION}/$VISITARCH/include/vtk-${VTK_SHORT_VERSION}/vtkjpeg\" \
        $FORTRANARGS \
        --prefix=\"$VISITDIR/hdf4/$HDF4_VERSION/$VISITARCH\" \
        --with-jpeg=\"$VISITDIR/${VTK_INSTALL_DIR}/${VTK_VERSION}/$VISITARCH/include/vtk-${VTK_SHORT_VERSION}/vtkjpeg\",\"$VISITDIR/${VTK_INSTALL_DIR}/${VTK_VERSION}/$VISITARCH/lib\" \
        --with-szlib=\"$VISITDIR/szip/$SZIP_VERSION/$VISITARCH\" \
        --disable-dependency-tracking"
        if [[ $? != 0 ]] ; then
           warn "HDF4 configure failed.  Giving up"\
                "You can see the details of the build failure at $HDF4_BUILD_DIR/config.log\n"
           return 1
        fi
        MAKEOPS="-i"
    else
        export LD_LIBRARY_PATH="$VISITDIR/${VTK_INSTALL_DIR}/${VTK_VERSION}/$VISITARCH/lib":"$VISITDIR/szip/$SZIP_VERSION/$VISITARCH/lib":$LD_LIBRARY_PATH
        # In order to ensure $FORTRANARGS is expanded to build the arguments to
        # configure, we wrap the invokation in 'sh -c "..."' syntax
        issue_command sh -c "./configure CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" \
        CFLAGS=\"$CFLAGS $C_OPT_FLAGS\" LIBS=\"-lm\" \
        CPPFLAGS=\"-I$VISITDIR/${VTK_INSTALL_DIR}/${VTK_VERSION}/$VISITARCH/include/vtk-${VTK_SHORT_VERSION} \
        -I$VISITDIR/${VTK_INSTALL_DIR}/${VTK_VERSION}/$VISITARCH/include/vtk-${VTK_SHORT_VERSION}/vtkjpeg\" \
        $FORTRANARGS \
        --prefix=\"$VISITDIR/hdf4/$HDF4_VERSION/$VISITARCH\" \
        --with-jpeg=\"$VISITDIR/${VTK_INSTALL_DIR}/${VTK_VERSION}/$VISITARCH/include/vtk-${VTK_SHORT_VERSION}/vtkjpeg\",\"$VISITDIR/${VTK_INSTALL_DIR}/${VTK_VERSION}/$VISITARCH/lib\" \
        --with-szlib=\"$VISITDIR/szip/$SZIP_VERSION/$VISITARCH\""
        if [[ $? != 0 ]] ; then
           warn "HDF4 configure failed.  Giving up.\n"\
                "You can see the details of the build failure at $HDF4_BUILD_DIR/config.log\n"
           return 1
        fi
    fi

    #
    # Build HDF4
    #
    info "Building HDF4 . . . (~2 minutes)"

    $MAKE $MAKEOPS
    if [[ $? != 0 ]] ; then
       warn "HDF4 build failed.  Giving up"
       return 1
    fi
    #
    # Install into the VisIt third party location.
    #
    info "Installing HDF4 . . ."
    $MAKE $MAKEOPS install
    if [[ $? != 0 ]] ; then
       warn "HDF4 install failed.  Giving up"
       return 1
    fi

    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
        #
        # Make dynamic executable
        #
        info "Creating dynamic libraries for HDF4 . . ."
        # Relink libdf.
        INSTALLNAMEPATH="$VISITDIR/hdf4/${HDF4_VERSION}/$VISITARCH/lib"

        ${C_COMPILER} -dynamiclib -o libdf.${SO_EXT} hdf/src/*.o \
           -Wl,-headerpad_max_install_names \
           -Wl,-install_name,$INSTALLNAMEPATH/libdf.${SO_EXT} \
           -Wl,-compatibility_version,$HDF4_COMPATIBILITY_VERSION \
           -Wl,-current_version,$HDF4_VERSION \
           -L"$VISITDIR/${VTK_INSTALL_DIR}/${VTK_VERSION}/$VISITARCH/lib" \
           -L"$VISITDIR/szip/$SZIP_VERSION/$VISITARCH/lib" \
           -lvtkjpeg-${VTK_SHORT_VERSION} -lsz -lz
        if [[ $? != 0 ]] ; then
           warn \
"HDF4 dynamic library build failed for libdf.${SO_EXT}.  Giving up"
           return 1
        fi
        cp libdf.${SO_EXT} "$VISITDIR/hdf4/$HDF4_VERSION/$VISITARCH/lib"

        # Relink libmfhdf.
        ${C_COMPILER} -dynamiclib -o libmfhdf.${SO_EXT} mfhdf/libsrc/*.o \
           -Wl,-headerpad_max_install_names \
           -Wl,-install_name,$INSTALLNAMEPATH/libmfhdf.${SO_EXT} \
           -Wl,-compatibility_version,$HDF4_COMPATIBILITY_VERSION \
           -Wl,-current_version,$HDF4_VERSION \
           -L"$VISITDIR/${VTK_INSTALL_DIR}/${VTK_VERSION}/$VISITARCH/lib" \
           -L"$VISITDIR/szip/$SZIP_VERSION/$VISITARCH/lib" \
           -L"$VISITDIR/hdf4/$HDF4_VERSION/$VISITARCH/lib" \
           -lvtkjpeg-${VTK_SHORT_VERSION} -ldf -lsz -lz
        if [[ $? != 0 ]] ; then
           warn \
"HDF4 dynamic library build failed for libmfhdf.${SO_EXT}.  Giving up"
           return 1
        fi
        cp libmfhdf.${SO_EXT} "$VISITDIR/hdf4/$HDF4_VERSION/$VISITARCH/lib"
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/hdf4"
       chgrp -R ${GROUP} "$VISITDIR/hdf4"
    fi
    cd "$START_DIR"
    info "Done with HDF4"
    return 0
}

function bv_hdf4_is_enabled
{
    if [[ $DO_HDF4 == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_hdf4_is_installed
{
    check_if_installed "hdf4" $HDF4_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_hdf4_build
{
cd "$START_DIR"
if [[ "$DO_HDF4" == "yes" ]] ; then
    check_if_installed "hdf4" $HDF4_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping HDF4 build.  HDF4 is already installed."
    else
        info "Building HDF4 (~2 minutes)"
        build_hdf4
        if [[ $? != 0 ]] ; then
            error "Unable to build or install HDF4.  Bailing out."
        fi
        info "Done building HDF4"
    fi
fi
}

function bv_hdf5_initialize
{
export DO_HDF5="no"
export ON_HDF5="off"
export USE_SYSTEM_HDF5="no"
add_extra_commandline_args "hdf5" "alt-hdf5-dir" 1 "Use alternative directory for hdf5"
}

function bv_hdf5_enable
{
DO_HDF5="yes"
ON_HDF5="on"
}

function bv_hdf5_disable
{
DO_HDF5="no"
ON_HDF5="off"
}

function bv_hdf5_alt_hdf5_dir
{
    bv_hdf5_enable
    USE_SYSTEM_HDF5="yes"
    HDF5_INSTALL_DIR="$1"
}

function bv_hdf5_depends_on
{
    if [[ "$USE_SYSTEM_HDF5" == "yes" ]]; then
        echo ""
    else
        local depends_on="szip"

        if [[ "$DO_ZLIB" == "yes" ]] ; then
           depends_on="$depends_on zlib"    
        fi

        echo $depends_on
    fi
}

function bv_hdf5_initialize_vars
{
    if [[ "$USE_SYSTEM_HDF5" == "no" ]]; then
        HDF5_INSTALL_DIR="${VISITDIR}/hdf5/$HDF5_VERSION/${VISITARCH}"
    fi
}

function bv_hdf5_info
{
export HDF5_VERSION=${HDF5_VERSION:-"1.8.14"}
export HDF5_FILE=${HDF5_FILE:-"hdf5-${HDF5_VERSION}.tar.gz"}
export HDF5_COMPATIBILITY_VERSION=${HDF5_COMPATIBILITY_VERSION:-"1.8"}
export HDF5_BUILD_DIR=${HDF5_BUILD_DIR:-"hdf5-${HDF5_VERSION}"}
# Note: Versions of HDF5 1.6.5 and earlier DO NOT have last path component
export HDF5_URL=${HDF5_URL:-"http://www.hdfgroup.org/ftp/HDF5/prev-releases/hdf5-${HDF5_VERSION}/src"}
export HDF5_MD5_CHECKSUM="a482686e733514a51cde12d6fe5c5d95"
export HDF5_SHA256_CHECKSUM="1dbefeeef7f591897c632b2b090db96bb8d35ad035beaa36bc39cb2bc67e0639"
}

function bv_hdf5_print
{
  printf "%s%s\n" "HDF5_FILE=" "${HDF5_FILE}"
  printf "%s%s\n" "HDF5_VERSION=" "${HDF5_VERSION}"
  printf "%s%s\n" "HDF5_COMPATIBILITY_VERSION=" "${HDF5_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "HDF5_BUILD_DIR=" "${HDF5_BUILD_DIR}"
}

function bv_hdf5_print_usage
{
printf "%-15s %s [%s]\n" "--hdf5" "Build HDF5" "${DO_HDF5}"
}

function bv_hdf5_graphical
{
local graphical_out="HDF5     $HDF5_VERSION($HDF5_FILE)      $ON_HDF5"
echo $graphical_out
}

function bv_hdf5_host_profile
{
    if [[ "$DO_HDF5" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## HDF5" >> $HOSTCONF
        echo "##" >> $HOSTCONF

        if [[ "$USE_SYSTEM_HDF5" == "yes" ]]; then
            echo \
            "VISIT_OPTION_DEFAULT(VISIT_HDF5_DIR $HDF5_INSTALL_DIR)" \
            >> $HOSTCONF 
        else
            echo \
            "VISIT_OPTION_DEFAULT(VISIT_HDF5_DIR \${VISITHOME}/hdf5/$HDF5_VERSION/\${VISITARCH})" \
            >> $HOSTCONF 

            if [[ "$DO_ZLIB" == "yes" ]] ; then
               ZLIB_LIBDEP="\${VISITHOME}/zlib/$ZLIB_VERSION/\${VISITARCH}/lib z"
            else
               ZLIB_LIBDEP="/usr/lib z"
               #moving global patch to have limited effect
               if [[ -d /usr/lib/x86_64-linux-gnu ]]; then
                ZLIB_LIBDEP="/usr/lib/x86_64-linux-gnu z"
               fi
            fi

            if [[ "$DO_SZIP" == "yes" ]] ; then
                echo \
                "VISIT_OPTION_DEFAULT(VISIT_HDF5_LIBDEP \${VISITHOME}/szip/$SZIP_VERSION/\${VISITARCH}/lib sz $ZLIB_LIBDEP TYPE STRING)" \
                >> $HOSTCONF
            else
                echo \
                "VISIT_OPTION_DEFAULT(VISIT_HDF5_LIBDEP $ZLIB_LIBDEP TYPE STRING)" \
                >> $HOSTCONF
            fi
        fi
    fi
}

function bv_hdf5_ensure
{
    if [[ "$DO_HDF5" == "yes" && "$USE_SYSTEM_HDF5" == "no" ]] ; then
        ensure_built_or_ready "hdf5" $HDF5_VERSION $HDF5_BUILD_DIR $HDF5_FILE $HDF5_URL 
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_HDF5="no"
            error "Unable to build HDF5.  ${HDF5_FILE} not found."
        fi
    fi
}

function bv_hdf5_dry_run
{
  if [[ "$DO_HDF5" == "yes" ]] ; then
    echo "Dry run option not set for hdf5."
  fi
}

function apply_hdf5_187_188_patch
{
    info "Patching hdf5"
    patch -p0 << \EOF
diff -c tools/lib/h5diff.c.orig tools/lib/h5diff.c
*** tools/lib/h5diff.c.orig     2013-11-13 08:14:48.924716921 -0800
--- tools/lib/h5diff.c  2013-11-13 08:15:28.066716686 -0800
***************
*** 635,641 ****
      char         filenames[2][MAX_FILENAME];
      hsize_t      nfound = 0;
      int i;
!     //int i1, i2;
      int l_ret;
      const char * obj1fullname = NULL;
      const char * obj2fullname = NULL;
--- 635,641 ----
      char         filenames[2][MAX_FILENAME];
      hsize_t      nfound = 0;
      int i;
!     /* int i1, i2; */
      int l_ret;
      const char * obj1fullname = NULL;
      const char * obj2fullname = NULL;
EOF
    if [[ $? != 0 ]] ; then
      warn "HDF5 patch failed."
      return 1
    fi

    return 0
}

function apply_hdf5_187_thread_patch
{
    info "Patching thread hdf5"
    patch -p0 << \EOF
diff -c src/H5private.h.orig src/H5private.h
*** src/H5private.h.orig    2014-07-28 10:46:54.821807839 -0700
--- src/H5private.h 2014-07-08 13:00:12.562002468 -0700
***************
*** 30,40 ****
  
  /* include the pthread header */
  #ifdef H5_HAVE_THREADSAFE
- #ifdef H5_HAVE_PTHREAD_H
  #include <pthread.h>
- #else /* H5_HAVE_PTHREAD_H */
- #define H5_HAVE_WIN_THREADS
- #endif /* H5_HAVE_PTHREAD_H */
  #endif /* H5_HAVE_THREADSAFE */
  
  /*
--- 30,36 ----
EOF
    if [[ $? != 0 ]] ; then
      warn "HDF5 thread patch failed."
      return 1
    fi

    return 0;
}

function apply_hdf5_1814_static_patch
{
    info "Patching hdf5 for static build"
    patch -p0 << \EOF
*** src/H5PL.c.orig	2015-10-23 11:51:35.000000000 -0700
--- src/H5PL.c	2015-10-23 11:56:48.000000000 -0700
***************
*** 159,165 ****
      char        *preload_path;
  
      FUNC_ENTER_STATIC_NOERR
! 
      /* Retrieve pathnames from HDF5_PLUGIN_PRELOAD if the user sets it
       * to tell the library to load plugin libraries without search.
       */
--- 159,165 ----
      char        *preload_path;
  
      FUNC_ENTER_STATIC_NOERR
! #ifdef H5_SUPPORT_DYNAMIC_LOADING
      /* Retrieve pathnames from HDF5_PLUGIN_PRELOAD if the user sets it
       * to tell the library to load plugin libraries without search.
       */
***************
*** 168,174 ****
          if(!HDstrcmp(preload_path, H5PL_NO_PLUGIN))
              H5PL_no_plugin_g = TRUE;
      } /* end if */
! 
      FUNC_LEAVE_NOAPI(SUCCEED)
  } /* end H5PL__init_interface() */
  
--- 168,174 ----
          if(!HDstrcmp(preload_path, H5PL_NO_PLUGIN))
              H5PL_no_plugin_g = TRUE;
      } /* end if */
! #endif
      FUNC_LEAVE_NOAPI(SUCCEED)
  } /* end H5PL__init_interface() */
  
***************
*** 193,201 ****
      htri_t ret_value;
  
      FUNC_ENTER_NOAPI(FAIL)
! 
      ret_value = (htri_t)H5PL_no_plugin_g;
! 
  done:
      FUNC_LEAVE_NOAPI(ret_value)
  } /* end H5PL_no_plugin() */
--- 193,201 ----
      htri_t ret_value;
  
      FUNC_ENTER_NOAPI(FAIL)
! #ifdef H5_SUPPORT_DYNAMIC_LOADING
      ret_value = (htri_t)H5PL_no_plugin_g;
! #endif
  done:
      FUNC_LEAVE_NOAPI(ret_value)
  } /* end H5PL_no_plugin() */
***************
*** 224,230 ****
      int  i = 0;
      
      FUNC_ENTER_NOAPI_NOINIT_NOERR
! 
      if(H5_interface_initialize_g) {
          size_t u;       /* Local index variable */
  
--- 224,230 ----
      int  i = 0;
      
      FUNC_ENTER_NOAPI_NOINIT_NOERR
! #ifdef H5_SUPPORT_DYNAMIC_LOADING
      if(H5_interface_initialize_g) {
          size_t u;       /* Local index variable */
  
***************
*** 246,252 ****
  	H5_interface_initialize_g = 0;
          i = 1;
      } /* end if */
! 
      FUNC_LEAVE_NOAPI(i)
  } /* end H5PL_term_interface() */
  
--- 246,252 ----
  	H5_interface_initialize_g = 0;
          i = 1;
      } /* end if */
! #endif
      FUNC_LEAVE_NOAPI(i)
  } /* end H5PL_term_interface() */
  
***************
*** 273,279 ****
      const void  *ret_value = NULL;
  
      FUNC_ENTER_NOAPI(NULL)
! 
      /* Check for "no plugins" indicated" */
      if(H5PL_no_plugin_g)
          HGOTO_ERROR(H5E_PLUGIN, H5E_CANTLOAD, NULL, "required dynamically loaded plugin filter '%d' is not available", id)
--- 273,279 ----
      const void  *ret_value = NULL;
  
      FUNC_ENTER_NOAPI(NULL)
! #ifdef H5_SUPPORT_DYNAMIC_LOADING
      /* Check for "no plugins" indicated" */
      if(H5PL_no_plugin_g)
          HGOTO_ERROR(H5E_PLUGIN, H5E_CANTLOAD, NULL, "required dynamically loaded plugin filter '%d' is not available", id)
***************
*** 308,314 ****
      /* Check if we found the plugin */
      if(found)
          ret_value = plugin_info;
! 
  done:
      FUNC_LEAVE_NOAPI(ret_value)
  } /* end H5PL_load() */
--- 308,314 ----
      /* Check if we found the plugin */
      if(found)
          ret_value = plugin_info;
! #endif
  done:
      FUNC_LEAVE_NOAPI(ret_value)
  } /* end H5PL_load() */
***************
*** 335,341 ****
      herr_t      ret_value = SUCCEED;    /* Return value */
  
      FUNC_ENTER_STATIC
! 
      /* Retrieve paths from HDF5_PLUGIN_PATH if the user sets it
       * or from the default paths if it isn't set.
       */
--- 335,341 ----
      herr_t      ret_value = SUCCEED;    /* Return value */
  
      FUNC_ENTER_STATIC
! #ifdef H5_SUPPORT_DYNAMIC_LOADING
      /* Retrieve paths from HDF5_PLUGIN_PATH if the user sets it
       * or from the default paths if it isn't set.
       */
***************
*** 360,366 ****
      } /* end while */
  
      H5PL_path_found_g = TRUE;
! 
  done:
      if(dl_path)
          dl_path = (char *)H5MM_xfree(dl_path);
--- 360,366 ----
      } /* end while */
  
      H5PL_path_found_g = TRUE;
! #endif
  done:
      if(dl_path)
          dl_path = (char *)H5MM_xfree(dl_path);
***************
*** 396,402 ****
      htri_t         ret_value = FALSE;
  
      FUNC_ENTER_STATIC
! 
      /* Open the directory */  
      if(!(dirp = HDopendir(dir)))
          HGOTO_ERROR(H5E_PLUGIN, H5E_OPENERROR, FAIL, "can't open directory")
--- 396,402 ----
      htri_t         ret_value = FALSE;
  
      FUNC_ENTER_STATIC
! #ifdef H5_SUPPORT_DYNAMIC_LOADING
      /* Open the directory */  
      if(!(dirp = HDopendir(dir)))
          HGOTO_ERROR(H5E_PLUGIN, H5E_OPENERROR, FAIL, "can't open directory")
***************
*** 438,444 ****
                  pathname = (char *)H5MM_xfree(pathname);
          } /* end if */
      } /* end while */
! 
  done:
      if(dirp) 
          if(HDclosedir(dirp) < 0)
--- 438,444 ----
                  pathname = (char *)H5MM_xfree(pathname);
          } /* end if */
      } /* end while */
! #endif
  done:
      if(dirp) 
          if(HDclosedir(dirp) < 0)
***************
*** 459,465 ****
      htri_t          ret_value = FALSE;
  
      FUNC_ENTER_STATIC
! 
      /* Specify a file mask. *.* = We want everything! */
      sprintf(service, "%s\\*.dll", dir);
      if((hFind = FindFirstFile(service, &fdFile)) == INVALID_HANDLE_VALUE)
--- 459,465 ----
      htri_t          ret_value = FALSE;
  
      FUNC_ENTER_STATIC
! #ifdef H5_SUPPORT_DYNAMIC_LOADING
      /* Specify a file mask. *.* = We want everything! */
      sprintf(service, "%s\\*.dll", dir);
      if((hFind = FindFirstFile(service, &fdFile)) == INVALID_HANDLE_VALUE)
***************
*** 494,500 ****
                  pathname = (char *)H5MM_xfree(pathname);
          } /* end if */
      } while(FindNextFile(hFind, &fdFile)); /* Find the next file. */
! 
  done:
      if(hFind) 
          FindClose(hFind);
--- 494,500 ----
                  pathname = (char *)H5MM_xfree(pathname);
          } /* end if */
      } while(FindNextFile(hFind, &fdFile)); /* Find the next file. */
! #endif
  done:
      if(hFind) 
          FindClose(hFind);
***************
*** 529,535 ****
      htri_t         ret_value = FALSE;
  
      FUNC_ENTER_STATIC
! 
      /* There are different reasons why a library can't be open, e.g. wrong architecture.
       * simply continue if we can't open it.
       */
--- 529,535 ----
      htri_t         ret_value = FALSE;
  
      FUNC_ENTER_STATIC
! #ifdef H5_SUPPORT_DYNAMIC_LOADING
      /* There are different reasons why a library can't be open, e.g. wrong architecture.
       * simply continue if we can't open it.
       */
***************
*** 588,594 ****
                      HGOTO_ERROR(H5E_PLUGIN, H5E_CLOSEERROR, FAIL, "can't close dynamic library")
          } /* end if */
      } /* end else */
! 
  done:
      FUNC_LEAVE_NOAPI(ret_value)
  } /* end H5PL__open() */
--- 588,594 ----
                      HGOTO_ERROR(H5E_PLUGIN, H5E_CLOSEERROR, FAIL, "can't close dynamic library")
          } /* end if */
      } /* end else */
! #endif
  done:
      FUNC_LEAVE_NOAPI(ret_value)
  } /* end H5PL__open() */
***************
*** 615,621 ****
      htri_t         ret_value = FALSE;
  
      FUNC_ENTER_STATIC
! 
      /* Search in the table of already opened dynamic libraries */
      if(H5PL_table_used_g > 0) {
          size_t         i;
--- 615,621 ----
      htri_t         ret_value = FALSE;
  
      FUNC_ENTER_STATIC
! #ifdef H5_SUPPORT_DYNAMIC_LOADING
      /* Search in the table of already opened dynamic libraries */
      if(H5PL_table_used_g > 0) {
          size_t         i;
***************
*** 636,642 ****
              } /* end if */
          } /* end for */
      } /* end if */
! 
  done:
      FUNC_LEAVE_NOAPI(ret_value)
  } /* end H5PL__search_table() */
--- 636,642 ----
              } /* end if */
          } /* end for */
      } /* end if */
! #endif
  done:
      FUNC_LEAVE_NOAPI(ret_value)
  } /* end H5PL__search_table() */
***************
*** 658,666 ****
  H5PL__close(H5PL_HANDLE handle)
  {
      FUNC_ENTER_STATIC_NOERR
! 
      H5PL_CLOSE_LIB(handle);
!    
      FUNC_LEAVE_NOAPI(SUCCEED)
  } /* end H5PL__close() */
  #endif /*H5_VMS*/
--- 658,666 ----
  H5PL__close(H5PL_HANDLE handle)
  {
      FUNC_ENTER_STATIC_NOERR
! #ifdef H5_SUPPORT_DYNAMIC_LOADING
      H5PL_CLOSE_LIB(handle);
! #endif
      FUNC_LEAVE_NOAPI(SUCCEED)
  } /* end H5PL__close() */
  #endif /*H5_VMS*/
EOF
    if [[ $? != 0 ]] ; then
      warn "HDF5 static patch failed."
      return 1
    fi

    return 0;
}

function apply_hdf5_patch
{
    if [[ "${HDF5_VERSION}" == 1.8.7 ]] ; then
        apply_hdf5_187_188_patch
        if [[ $? != 0 ]]; then
            return 1
        fi
        if [[ "$DO_THREAD_BUILD" == "yes" ]]; then
            apply_hdf5_187_thread_patch
            if [[ $? != 0 ]]; then
                return 1
            fi
        fi
    else
        if [[ "${HDF5_VERSION}" == 1.8.8 ]] ; then
            apply_hdf5_187_188_patch
            if [[ $? != 0 ]]; then
                return 1
            fi
        else
            # Latest HDF5.

            # Apply a patch for static if we build statically.
            if [[ "$DO_STATIC_BUILD" == "yes" ]] ; then
                apply_hdf5_1814_static_patch
                if [[ $? != 0 ]]; then
                    return 1
                fi
            fi
        fi
    fi

    return 0
}

# *************************************************************************** #
#                          Function 8.1, build_hdf5                           #
# *************************************************************************** #

function build_hdf5
{
    #
    # Prepare build dir
    #
    prepare_build_dir $HDF5_BUILD_DIR $HDF5_FILE
    untarred_hdf5=$?
    if [[ $untarred_hdf5 == -1 ]] ; then
       warn "Unable to prepare HDF5 Build Directory. Giving Up"
       return 1
    fi

    #
    cd $HDF5_BUILD_DIR || error "Can't cd to HDF5 build dir."
    apply_hdf5_patch
    if [[ $? != 0 ]]; then
        warn "Patch failed, but continuing."
    fi
    info "Configuring HDF5 . . ."
    if [[ "$OPSYS" == "Darwin" ]]; then
        export DYLD_LIBRARY_PATH="$VISITDIR/szip/$SZIP_VERSION/$VISITARCH/lib":$DYLD_LIBRARY_PATH
    else
        export LD_LIBRARY_PATH="$VISITDIR/szip/$SZIP_VERSION/$VISITARCH/lib":$LD_LIBRARY_PATH
    fi
    if [[ "$DO_STATIC_BUILD" == "yes" ]]; then
            cf_build_type="--disable-shared --enable-static"
        else
            cf_build_type="--enable-shared --disable-static"
    fi
    cf_szip=""
    if test "x${DO_SZIP}" = "xyes"; then
        info "SZip requested.  Configuring HDF5 with SZip support."
        sz_dir="${VISITDIR}/szip/${SZIP_VERSION}/${VISITARCH}"
        cf_szip="--with-szlib=${sz_dir}"
    fi

    if [[ "$FC_COMPILER" == "no" ]] ; then
        FORTRANARGS=""
    else
        FORTRANARGS="FC=\"$FC_COMPILER\" F77=\"$FC_COMPILER\" FCFLAGS=\"$FCFLAGS\" FFLAGS=\"$FCFLAGS\" --enable-fortran"
    fi

    cf_build_thread=""
    if [[ "$DO_THREAD_BUILD" == "yes" ]]; then
        cf_build_thread="--enable-threadsafe --with-pthread"
    fi

    # In order to ensure $FORTRANARGS is expanded to build the arguments to
    # configure, we wrap the invokation in 'sh -c "..."' syntax
    info "Invoking command to configure HDF5"
    info "./configure CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" \
        CFLAGS=\"$CFLAGS $C_OPT_FLAGS\" CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS\" \
        $FORTRANARGS \
        --prefix=\"$VISITDIR/hdf5/$HDF5_VERSION/$VISITARCH\" \
        ${cf_szip} ${cf_build_type} ${cf_build_thread}"
    sh -c "./configure CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" \
        CFLAGS=\"$CFLAGS $C_OPT_FLAGS\" CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS\" \
        $FORTRANARGS \
        --prefix=\"$VISITDIR/hdf5/$HDF5_VERSION/$VISITARCH\" \
        ${cf_szip} ${cf_build_type} ${cf_build_thread}"
    if [[ $? != 0 ]] ; then
       warn "HDF5 configure failed.  Giving up"
       return 1
    fi

    #
    # Build HDF5
    #
    info "Making HDF5 . . ."
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "HDF5 build failed.  Giving up"
       return 1
    fi
    #
    # Install into the VisIt third party location.
    #
    info "Installing HDF5 . . ."

    $MAKE install
    if [[ $? != 0 ]] ; then
       warn "HDF5 install failed.  Giving up"
       return 1
    fi

    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
        #
        # Make dynamic executable, need to patch up the install path and
        # version information.
        #
        info "Creating dynamic libraries for HDF5 . . ."
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/hdf5"
       chgrp -R ${GROUP} "$VISITDIR/hdf5"
    fi
    cd "$START_DIR"
    info "Done with HDF5"
    return 0
}

function bv_hdf5_is_enabled
{
    if [[ $DO_HDF5 == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_hdf5_is_installed
{

    if [[ "$USE_SYSTEM_HDF5" == "yes" ]]; then
        return 1
    fi

    check_if_installed "hdf5" $HDF5_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_hdf5_build
{
cd "$START_DIR"

if [[ "$DO_HDF5" == "yes" && "$USE_SYSTEM_HDF5" == "no" ]] ; then
    check_if_installed "hdf5" $HDF5_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping HDF5 build.  HDF5 is already installed."
    else
        info "Building HDF5 (~15 minutes)"
        build_hdf5
        if [[ $? != 0 ]] ; then
            error "Unable to build or install HDF5.  Bailing out."
        fi
        info "Done building HDF5"
    fi
fi
}
function bv_icet_initialize
{
export DO_ICET="no"
export ON_ICET="off"
}

function bv_icet_enable
{
DO_ICET="yes"
ON_ICET="on"
}

function bv_icet_disable
{
DO_ICET="no"
ON_ICET="off"
}

function bv_icet_depends_on
{
echo "cmake"
}

function bv_icet_info
{
export ICET_FILE=${ICET_FILE:-"IceT-1-0-0.tar.gz"}
export ICET_VERSION=${ICET_VERSION:-"1.0.0"}
export ICET_COMPATIBILITY_VERSION=${ICET_COMPATIBILITY_VERSION:-"1.0.0"}
export ICET_BUILD_DIR=${ICET_BUILD_DIR:-"IceT-1-0-0"}
export ICET_MD5_CHECKSUM="90a93507b8fdc88f46b9a8d7ed651c6c"
export ICET_SHA256_CHECKSUM=""
}

function bv_icet_print
{
  printf "%s%s\n" "ICET_FILE=" "${ICET_FILE}"
  printf "%s%s\n" "ICET_VERSION=" "${ICET_VERSION}"
  printf "%s%s\n" "ICET_COMPATIBILITY_VERSION=" "${ICET_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "ICET_BUILD_DIR=" "${ICET_BUILD_DIR}"
}

function bv_icet_print_usage
{
printf "%-15s %s [%s]\n" "--icet" "Build Ice-T (parallel rendering lib)" "$DO_ICET"
printf "%-15s %s [%s]\n" "--no-icet" "Ice-T is automatically built with --enable-parallel.  Prevent it from being built" "$PREVENT_ICET"
}

function bv_icet_graphical
{
local graphical_out="IceT     $ICET_VERSION($ICET_FILE)      $ON_ICET"
echo $graphical_out
}

function bv_icet_host_profile
{
    if [[ "$DO_ICET" == "yes" && "$PREVENT_ICET" != "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## Ice-T" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_ICET_DIR \${VISITHOME}/icet/$ICET_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
    fi
}

function bv_icet_ensure
{
    if [[ "$DO_ICET" == "yes" && "$PREVENT_ICET" != "yes" ]] ; then
        ensure_built_or_ready "icet" $ICET_VERSION $ICET_BUILD_DIR $ICET_FILE "http://www.cs.unm.edu/~kmorel/IceT"
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_ICET="no"
            error "Unable to build Ice-T.  ${ICET_FILE} not found."
        fi
    fi
}

function bv_icet_dry_run
{
  if [[ "$DO_ICET" == "yes" ]] ; then
    echo "Dry run option not set for icet."
  fi
}

# *************************************************************************** #
#                           Function 8.13, build_icet                         #
# *************************************************************************** #

function apply_icet_100_patch
{
   patch -p0 <<\EOF
diff -c a/src/CMakeLists.txt IceT-1-0-0/src/CMakeLists.txt
*** a/src/CMakeLists.txt
--- IceT-1-0-0/src/CMakeLists.txt
***************
*** 18,35 ****
        "${CMAKE_CURRENT_SOURCE_DIR}/communication"
        "${CMAKE_CURRENT_SOURCE_DIR}/strategies")
    SET(filesToInstall)
!   FOREACH(p IN ${resPath})
        SET(tmpFilesToInstall)
        SET(exts "${p}/*.h;${p}/*.hxx;${p}/*.txx")
!       FOREACH(ext IN ${exts})
            FILE(GLOB tmpFilesToInstall
            RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
            "${ext}")
            IF(tmpFilesToInstall)
                SET(filesToInstall "${filesToInstall};${tmpFilesToInstall}")
            ENDIF(tmpFilesToInstall)
!       ENDFOREACH(ext IN ${exts})
!   ENDFOREACH(p IN ${resPath})
    INSTALL(
        FILES ${filesToInstall}
        DESTINATION "${ICET_INSTALL_INCLUDE_DIR}/ice-t"
--- 18,35 ----
        "${CMAKE_CURRENT_SOURCE_DIR}/communication"
        "${CMAKE_CURRENT_SOURCE_DIR}/strategies")
    SET(filesToInstall)
!   FOREACH(p ${resPath})
        SET(tmpFilesToInstall)
        SET(exts "${p}/*.h;${p}/*.hxx;${p}/*.txx")
!       FOREACH(ext ${exts})
            FILE(GLOB tmpFilesToInstall
            RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
            "${ext}")
            IF(tmpFilesToInstall)
                SET(filesToInstall "${filesToInstall};${tmpFilesToInstall}")
            ENDIF(tmpFilesToInstall)
!       ENDFOREACH(ext)
!   ENDFOREACH(p)
    INSTALL(
        FILES ${filesToInstall}
        DESTINATION "${ICET_INSTALL_INCLUDE_DIR}/ice-t"
EOF
   if [[ $? != 0 ]] ; then
        warn "Unable to apply patch to IceT 1.0.0."
        return 1
   else
        return 0
   fi
}

function apply_icet_patch
{
   info "Patching IceT . . ."
   if [[ ${ICET_VERSION} == "1.0.0" ]] ; then
      apply_icet_100_patch
      if [[ $? != 0 ]] ; then
        return 1
      fi
   fi

   return 0
}

function build_icet
{
    PAR_INCLUDE_STRING=""
    if [[ "$PAR_INCLUDE" != "" ]] ; then
        PAR_INCLUDE_STRING=$PAR_INCLUDE
    fi

    if [[ "$PAR_COMPILER" != "" ]] ; then
        if [[ "$OPSYS" == "Darwin" && "$PAR_COMPILER" == "/usr/bin/mpicc" ]]; then
            PAR_INCLUDE_STRING="-I/usr/include/"
        elif [[ "$OPSYS" == "Linux" && "$PAR_COMPILER" == "mpixlc" ]]; then
            PAR_INCLUDE_STRING=`$PAR_COMPILER -show`
        else
            if [[ -z "$PAR_INCLUDE_STRING" ]]; then
                PAR_INCLUDE_STRING=`$PAR_COMPILER --showme:compile`
                if [[ $? != 0 ]] ; then
                    PAR_INCLUDE_STRING=`$PAR_COMPILER -show`
                fi
            fi
        fi
    fi

    if [[ "$PAR_INCLUDE_STRING" == "" ]] ; then
       warn "You must set either the PAR_COMPILER or PAR_INCLUDE environment variable to be Ice-T."
       warn "PAR_COMPILER should be of the form \"/path/to/mpi/bin/mpicc\""
       warn "PAR_INCLUDE should be of the form \"-I/path/to/mpi/include\""
       warn "Giving Up!"
       return 1
    fi

    # IceT's CMake config doesn't take the compiler options, but rather the
    # paths to certain files, and then it tries to build all of the appropriate
    # options itself.  Since we only have the former, we need to guess at the
    # latter.
    # Our current guess is to take the first substring in PAR_INCLUDE, assume
    # it's the appropriate -I option, and use it with the "-I" removed.  This
    # is certainly not ideal -- for example, it will break if the user's
    # MPI setup requires multiple include directories.

    # Search all of the -I directories and take the first one containing mpi.h
    PAR_INCLUDE_DIR=""
    for arg in $PAR_INCLUDE_STRING ; do
        if [[ "$arg" != "${arg#-I}" ]] ; then
            if test -e "${arg#-I}/mpi.h" ; then
                PAR_INCLUDE_DIR=${arg#-I}
                break
            fi
        fi
    done
    # If we did not get a valid include directory, take the first -I directory.
    if test -z "${PAR_INCLUDE_DIR}"  ; then
        for arg in $PAR_INCLUDE_STRING ; do
            if [[ "$arg" != "${arg#-I}" ]] ; then
                PAR_INCLUDE_DIR=${arg#-I}
                break
            fi
        done
    fi

    if test -z "${PAR_INCLUDE_DIR}"  ; then
        if test -n "${PAR_INCLUDE}" ; then
            warn "This script believes you have defined PAR_INCLUDE as: $PAR_INCLUDE"
            warn "However, to build Ice-T, this script expects to parse a -I/path/to/mpi out of PAR_INCLUDE"
        fi
        warn "Could not determine the MPI include information which is needed to compile IceT."
        if test -n "${PAR_INCLUDE}" ; then
            error "Please re-run with the required \"-I\" option included in PAR_INCLUDE"
        else
            error "You need to specify either PAR_COMPILER or PAR_INCLUDE variable.  On many "
                  " systems, the output of \"mpicc -showme\" is good enough."
            error ""
        fi
    fi

    #
    # CMake is the build system for IceT.  We already required CMake to be
    # built, so it should be there.
    #
    CMAKE_BIN="${CMAKE_COMMAND}"

    prepare_build_dir $ICET_BUILD_DIR $ICET_FILE
    untarred_icet=$?
    if [[ $untarred_icet == -1 ]] ; then
       warn "Unable to prepare Ice-T build directory. Giving Up!"
       return 1
    fi

    apply_icet_patch

    info "Executing CMake on Ice-T"
    cd $ICET_BUILD_DIR || error "Can't cd to IceT build dir."
    if [[ "$DO_STATIC_BUILD" == "no" ]]; then
        LIBEXT="${SO_EXT}"
    else
        LIBEXT="a"
    fi
    touch fakempi.${LIBEXT}
    rm -f CMakeCache.txt

    ${CMAKE_BIN} \
        -DCMAKE_C_COMPILER:STRING=${C_COMPILER} \
        -DCMAKE_CXX_COMPILER:STRING=${CXX_COMPILER} \
        -DCMAKE_BUILD_TYPE:STRING="${VISIT_BUILD_MODE}" \
        -DCMAKE_C_FLAGS:STRING="${CFLAGS} ${C_OPT_FLAGS}" \
        -DCMAKE_CXX_FLAGS:STRING="${CXXFLAGS} ${CXX_OPT_FLAGS}" \
        -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
        -DCMAKE_INSTALL_PREFIX:PATH="$VISITDIR/icet/${ICET_VERSION}/${VISITARCH}"\
        -DOPENGL_INCLUDE_DIR:PATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/include"\
        -DOPENGL_gl_LIBRARY:FILEPATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/lib/libOSMesa.${LIBEXT}"\
        -DCMAKE_C_FLAGS:STRING="-fPIC ${CFLAGS} ${C_OPT_FLAGS}"\
        -DMPI_INCLUDE_PATH:PATH="${PAR_INCLUDE_DIR}"\
        -DMPI_LIBRARY:FILEPATH="./fakempi.${LIBEXT}"\
        -DBUILD_TESTING:BOOL=OFF\
        .

    rm fakempi.${LIBEXT}

    if [[ $? != 0 ]] ; then
       warn "Cannot get CMAKE to create the makefiles.  Giving up."
       return 1
    fi

    #
    # Now build Ice-T.
    #
    info "Building Ice-T . . . (~2 minutes)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "Ice-T did not build correctly.  Giving up."
       return 1
    fi

    info "Installing Ice-T . . ."

    $MAKE install
    if [[ $? != 0 ]] ; then
       warn "Ice-T: 'make install' failed.  Giving up"
       return 1
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/icet"
       chgrp -R ${GROUP} "$VISITDIR/icet"
    fi

    cd "$START_DIR"
    echo "Done with Ice-T"
    return 0
}

function bv_icet_is_enabled
{
    if [[ $DO_ICET == "yes" ]]; then
        return 1
    fi
    return 0
}

function bv_icet_is_installed
{
    check_if_installed "icet" $ICET_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_icet_build
{
cd "$START_DIR"
if [[ "$DO_ICET" == "yes" && "$PREVENT_ICET" != "yes" ]] ; then
    check_if_installed "icet" $ICET_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping Ice-T build.  Ice-T is already installed."
    else
        info "Building Ice-T (~2 minutes)"
        build_icet
        if [[ $? != 0 ]] ; then
            error "Unable to build or install Ice-T.  Bailing out."
        fi
        info "Done building Ice-T"
    fi
fi
}
function bv_itaps_initialize
{
export DO_ITAPS="no"
export ON_ITAPS="off"
}

function bv_itaps_enable
{
DO_ITAPS="yes"
ON_ITAPS="on"
}

function bv_itaps_disable
{
DO_ITAPS="no"
ON_ITAPS="off"
}

function bv_itaps_depends_on
{
    local depends_on=""

    if [[ "$DO_HDF5" == "yes" ]] ; then
        depends_on="hdf5"
    fi

    if [[ "$DO_SZIP" == "yes" ]] ; then
        depends_on="$depends_on szip"
    fi

    if [[ "$DO_NETCDF" == "yes" ]] ; then
        depends_on="$depends_on netcdf"    
    fi

    echo $depends_on
}

function bv_itaps_print
{
  printf "%s%s\n" "ITAPS_FMDB_FILE=" "${ITAPS_FMDB_FILE}"
  printf "%s%s\n" "ITAPS_FMDB_VERSION=" "${ITAPS_FMDB_VERSION}"
  printf "%s%s\n" "ITAPS_FMDB_BUILD_DIR=" "${ITAPS_FMDB_BUILD_DIR}"

  printf "%s%s\n" "ITAPS_GRUMMP_FILE=" "${ITAPS_GRUMMP_FILE}"
  printf "%s%s\n" "ITAPS_GRUMMP_VERSION=" "${ITAPS_GRUMMP_VERSION}"
  printf "%s%s\n" "ITAPS_GRUMMP_BUILD_DIR=" "${ITAPS_GRUMMP_BUILD_DIR}"

  printf "%s%s\n" "ITAPS_MOAB_FILE=" "${ITAPS_MOAB_FILE}"
  printf "%s%s\n" "ITAPS_MOAB_VERSION=" "${ITAPS_MOAB_VERSION}"
  printf "%s%s\n" "ITAPS_MOAB_BUILD_DIR=" "${ITAPS_MOAB_BUILD_DIR}"

}

function bv_itaps_print_usage
{
printf "%-15s %s [%s]\n" "--itaps" "Build ITAPS" "${DO_ITAPS}"
}

function bv_itaps_graphical
{
local graphical_out="ITAPS    $ITAPS_VERSION(GRUMMP/FMDB/MOAB) $ON_ITAPS"
echo "$graphical_out"
}

function bv_itaps_host_profile
{
    if [[ "$DO_ITAPS" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## ITAPS" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## MOAB implementation" >> $HOSTCONF
        echo "ITAPS_INCLUDE_DIRECTORIES(MOAB \${VISITHOME}/itaps/$ITAPS_VERSION/MOAB/$ITAPS_MOAB_VERSION/\${VISITARCH}/include)" \
        >> $HOSTCONF
        echo "ITAPS_FILE_PATTERNS(MOAB *.cub)" >> $HOSTCONF
        local hdf5_libs=""
        local hdf5_libdir=""
        local szip_libs=""
        local szip_libdir=""
        local netcdf_libs=""
        local netcdf_libdir=""
        if [[ "$DO_HDF5" == "yes" ]] ; then
            hdf5_libs="hdf5_hl hdf5"
            hdf5_libdir="\${VISITHOME}/hdf5/${HDF5_VERSION}/\${VISITARCH}/lib "
        fi
        if [[ "$DO_SZIP" == "yes" ]] ; then
            szip_libs="sz"
            szip_libdir="\${VISITHOME}/szip/${SZIP_VERSION}/\${VISITARCH}/lib "
        fi
        if [[ "$DO_NETCDF" == "yes" ]] ; then
            netcdf_libs="netcdf_c++ netcdf"
            netcdf_libdir="\${VISITHOME}/netcdf/${NETCDF_VERSION}/\${VISITARCH}/lib "
        fi
        echo "ITAPS_LINK_LIBRARIES(MOAB iMesh MOAB $hdf5_libs $szip_libs z $netcdf_libs )" \
        >> $HOSTCONF
        echo "ITAPS_LINK_DIRECTORIES(MOAB " \
             "\${VISITHOME}/itaps/$ITAPS_VERSION/MOAB/$ITAPS_MOAB_VERSION/\${VISITARCH}/lib " \
             "$hdf5_libdir" \
             "$szip_libdir" \
             "$netcdf_libdir)" >> $HOSTCONF
        echo "## FMDB implementation" >> $HOSTCONF
        echo "ITAPS_INCLUDE_DIRECTORIES(FMDB \${VISITHOME}/itaps/$ITAPS_VERSION/FMDB/$ITAPS_FMDB_VERSION/\${VISITARCH}/include)" \
        >> $HOSTCONF
        echo "ITAPS_FILE_PATTERNS(FMDB *.sms)" >> $HOSTCONF
        echo "ITAPS_LINK_LIBRARIES(FMDB FMDB SCORECModel SCORECUtil )" >> $HOSTCONF
        echo "ITAPS_LINK_DIRECTORIES(FMDB \${VISITHOME}/itaps/$ITAPS_VERSION/FMDB/$ITAPS_FMDB_VERSION/\${VISITARCH}/lib)" >> $HOSTCONF
        echo "## GRUMMP implementation" >> $HOSTCONF
        echo "ITAPS_INCLUDE_DIRECTORIES(GRUMMP \${VISITHOME}/itaps/$ITAPS_VERSION/GRUMMP/$ITAPS_GRUMMP_VERSION/\${VISITARCH}/include)" \
        >> $HOSTCONF
        echo "ITAPS_FILE_PATTERNS(GRUMMP *.bdry *.smesh *.vmesh)" >> $HOSTCONF
        echo "ITAPS_LINK_LIBRARIES(GRUMMP iMesh_GRUMMP GR_3D GR_surf GR_2D GR_geom GR_base SUMAAlog_lite OptMS cgm dl)" \
        >> $HOSTCONF
        echo "ITAPS_LINK_DIRECTORIES(GRUMMP \${VISITHOME}/itaps/$ITAPS_VERSION/GRUMMP/$ITAPS_GRUMMP_VERSION/\${VISITARCH}/lib)" \
        >> $HOSTCONF
    fi
}



function bv_itaps_info
{
export ITAPS_VERSION=${ITAPS_VERSION:-"1.4"}
export ITAPS_MOAB_VERSION=${ITAPS_MOAB_VERSION:-"4.8.1"}
export ITAPS_MOAB_FILE=${ITAPS_MOAB_FILE:-"moab-${ITAPS_MOAB_VERSION}.tar.gz"}
export ITAPS_MOAB_URL=${ITAPS_MOAB_URL:-http://ftp.mcs.anl.gov/pub/fathom}
export ITAPS_MOAB_BUILD_DIR=${ITAPS_MOAB_BUILD_DIR:-"moab-${ITAPS_MOAB_VERSION}"}

export ITAPS_FMDB_VERSION=${ITAPS_FMDB_VERSION:-"1.4.0"}
export ITAPS_FMDB_FILE=${ITAPS_FMDB_FILE:-"FMDB-${ITAPS_FMDB_VERSION}.tar.gz"}
export ITAPS_FMDB_URL=${ITAPS_FMDB_URL:-http://www.scorec.rpi.edu/FMDB/source}
export ITAPS_FMDB_BUILD_DIR=${ITAPS_FMDB_BUILD_DIR:-"${ITAPS_FMDB_FILE%.tar*}"}

# CGM is an indirect dependency introduced by ITAPS_GRUMMP. No other part
# of VisIt uses CGM, presently. That is likely to change in the future
# if we add an iGeom reader to VisIt.
export ITAPS_GRUMMP_CGM_VERSION=${ITAPS_GRUMMP_CGM_VERSION:-"12.2.0b1"}
export ITAPS_GRUMMP_CGM_FILE=${ITAPS_GRUMMP_CGM_FILE:-"cgm-${ITAPS_GRUMMP_CGM_VERSION}.tar.gz"}
export ITAPS_GRUMMP_CGM_URL=${ITAPS_GRUMMP_CGM_URL:-http://ftp.mcs.anl.gov/pub/fathom}
export ITAPS_GRUMMP_CGM_BUILD_DIR=${ITAPS_GRUMMP_CGM_BUILD_DIR:-"cgma-${ITAPS_GRUMMP_CGM_VERSION}"}

export ITAPS_GRUMMP_VERSION=${ITAPS_GRUMMP_VERSION:-"0.6.5"}
export ITAPS_GRUMMP_FILE=${ITAPS_GRUMMP_FILE:-"GRUMMP-${ITAPS_GRUMMP_VERSION}.tar.gz"}
#export ITAPS_GRUMMP_URL=${ITAPS_GRUMMP_URL:-ftp://tetra.mech.ubc.ca/pub/GRUMMP}
export ITAPS_GRUMMP_BUILD_DIR=${ITAPS_GRUMMP_BUILD_DIR:-"GRUMMP-${ITAPS_GRUMMP_VERSION}"}
export ITAPS_MD5_CHECKSUM=""
export ITAPS_SHA256_CHECKSUM=""
}

function bv_itaps_ensure
{
    if [[ "$DO_ITAPS" == "yes" ]] ; then
        ensure_built_or_ready "itaps"/$ITAPS_VERSION/MOAB $ITAPS_MOAB_VERSION $ITAPS_MOAB_BUILD_DIR  $ITAPS_MOAB_FILE $ITAPS_MOAB_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_ITAPS="no"
            error "Unable to build ITAPS_MOAB.  ${ITAPS_MOAB_FILE} not found."
        fi
        ensure_built_or_ready "itaps"/$ITAPS_VERSION/FMDB $ITAPS_FMDB_VERSION $ITAPS_FMDB_BUILD_DIR  $ITAPS_FMDB_FILE $ITAPS_FMDB_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_ITAPS="no"
            error "Unable to build ITAPS_FMDB.  ${ITAPS_FMDB_FILE} not found."
        fi
        ensure_built_or_ready "itaps"/$ITAPS_VERSION/GRUMMP $ITAPS_GRUMMP_VERSION $ITAPS_GRUMMP_CGM_BUILD_DIR  $ITAPS_GRUMMP_CGM_FILE $ITAPS_GRUMMP_CGM_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_ITAPS="no"
            error "Unable to build ITAPS_GRUMMP_CGM.  ${ITAPS_GRUMMP_CGM_FILE} not found."
        fi
        ensure_built_or_ready "itaps"/$ITAPS_VERSION/GRUMMP $ITAPS_GRUMMP_VERSION $ITAPS_GRUMMP_BUILD_DIR  $ITAPS_GRUMMP_FILE $ITAPS_GRUMMP_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_ITAPS="no"
            error "Unable to build ITAPS_GRUMMP.  ${ITAPS_GRUMMP_FILE} not found."
        fi
    fi
}


function bv_itaps_dry_run
{
  if [[ "$DO_ITAPS" == "yes" ]] ; then
    echo "Dry run option not set for itaps."
  fi
}

# *************************************************************************** #
#                          Function 8.15, build_itaps_moab                    #
# *************************************************************************** #

function build_itaps_moab
{
    #
    # Prepare build dir
    #
    prepare_build_dir $ITAPS_MOAB_BUILD_DIR $ITAPS_MOAB_FILE
    untarred_itaps_moab=$?
    if [[ $untarred_itaps_moab == -1 ]] ; then
       warn "Unable to prepare ITAPS_MOAB build directory. Giving Up!"
       return 1
    fi
    
    #
    # Call configure
    #
    info "Configuring ITAPS_MOAB. . ."
    cd $ITAPS_MOAB_BUILD_DIR || error "Cannot cd to $ITAPS_MOAB_BUILD_DIR build dir."
    info "Invoking command to configure ITAPS_MOAB"
    if [[ "$DO_HDF5" == "yes" ]] ; then
       WITHHDF5ARG="--with-hdf5=$HDF5_INSTALL_DIR --with-hdf5-ldflags=-lz"
    else
       WITHHDF5ARG="--without-hdf5"
    fi
    if [[ "$DO_SZIP" == "yes" ]] ; then
       WITHSZIPARG="--with-szip=$VISITDIR/szip/$SZIP_VERSION/$VISITARCH"
    else
       WITHSZIPARG="--without-szip"
    fi
    if [[ "$DO_NETCDF" == "yes" ]] ; then
       WITHNETCDFARG="--with-netcdf=$NETCDF_INSTALL_DIR"
    else
       WITHNETCDFARG="--without-netcdf"
    fi
    ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" \
        CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
        --prefix="$VISITDIR/itaps/$ITAPS_VERSION/MOAB/$ITAPS_MOAB_VERSION/$VISITARCH" \
        --with-zlib \
        $WITHHDF5ARG "$WITHSZIPARG" "$WITHNETCDFARG"
    if [[ $? != 0 ]] ; then
       warn "ITAPS_MOAB configure failed.  Giving up"
       return 1
    fi

    #
    # Build ITAPS_MOAB
    #
    info "Building ITAPS_MOAB. . . (~10 minutes)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "ITAPS_MOAB build failed.  Giving up"
       return 1
    fi

    #
    # Install into the VisIt third party location.
    #
    info "Installing ITAPS_MOAB"

    if [[ "$OPSYS" == "Darwin" ]]; then
        warn "I do not know how to install ITAPS_MOAB on a Mac. Giving up"
    else
        $MAKE install
        if [[ $? != 0 ]] ; then
           warn "ITAPS_MOAB install failed.  Giving up"
           return 1
        fi
        # To make it easier to package this build up, ensure we don't wind up
        # liking to shared libraries.
        find $VISITDIR/itaps/$ITAPS_VERSION/MOAB/$ITAPS_MOAB_VERSION/$VISITARCH -name 'lib*.so*' -exec rm -f {} \;
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/itaps/$ITAPS_VERSION/MOAB"
       chgrp -R ${GROUP} "$VISITDIR/itaps/$ITAPS_VERSION/MOAB"
    fi
    cd "$START_DIR"
    info "Done with ITAPS_MOAB"
    return 0
}

# *************************************************************************** #
#                          Function 8.16, build_itaps_fmdb                    #
# *************************************************************************** #

function build_itaps_fmdb
{
    #
    # Prepare build dir
    #
    prepare_build_dir $ITAPS_FMDB_BUILD_DIR $ITAPS_FMDB_FILE
    untarred_itaps_fmdb=$?
    if [[ $untarred_itaps_fmdb == -1 ]] ; then
       warn "Unable to prepare ITAPS_FMDB build directory. Giving Up!"
       return 1
    fi

    cd $ITAPS_FMDB_BUILD_DIR
    abs_itaps_fmdb_build_dir=$(pwd)

    if [[ ! -e GMI-1.0.1.tar.gz ]]; then
        download_file GMI-1.0.1.tar.gz $ITAPS_FMDB_URL
        [[ $? -eq 0 ]] || { error "Unable to download GMI-1.0.1.tar.gz for ITAPS_FMDB" && return 1; }
    fi
    gunzip < GMI-1.0.1.tar.gz | tar xf -
    [[ $? -eq 0 ]] || { error "Unable to untar GMI-1.0.1.tar.gz for ITAPS_FMDB" && return 1; }
    if [[ ! -e SCUtil.tar.gz ]]; then
        download_file SCUtil.tar.gz $ITAPS_FMDB_URL
        [[ $? -eq 0 ]] || { error "Unable to download SCUtil.tar.gz for ITAPS_FMDB" && return 1; }
    fi
    gunzip < SCUtil.tar.gz | tar xf -
    [[ $? -eq 0 ]] || { error "Unable to untar SCUtil.tar.gz for ITAPS_FMDB" && return 1; }
    pushd SCUtil >/dev/null 2>&1
    gunzip < siter.tar.gz | tar xf -
    [[ $? -eq 0 ]] || { error "Unable to untar siter.tar.gz for ITAPS_FMDB" && return 1; }
    gunzip < SCORECUtil-0.1.tar.gz | tar xf -
    [[ $? -eq 0 ]] || { error "Unable to untar SCORECUtil-0.1.tar.gz for ITAPS_FMDB" && return 1; }
    popd >/dev/null 2>&1

    #
    # Configure GMI
    #
    info "Configuring GMI for ITAPS_FMDB. . ."
    pushd GMI-1.0.1 >/dev/null 2>&1
    ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" \
        CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
        --with-fmdb=$abs_itaps_fmdb_build_dir \
        --with-scorecutil=$abs_itaps_fmdb_build_dir/SCUtil/SCORECUtil-0.1 \
        --with-iterators=$abs_itaps_fmdb_build_dir/SCUtil/siter \
        --prefix="$VISITDIR/itaps/$ITAPS_VERSION/FMDB/$ITAPS_FMDB_VERSION/$VISITARCH"
    if [[ $? != 0 ]] ; then
       warn "ITAPS_FMBD configure failed.  Giving up"
       return 1
    fi
    info "Building GMI for ITAPS_FMDB. . ."
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "ITAPS_FMDB build failed.  Giving up"
       return 1
    fi
    if [[ "$OPSYS" == "Darwin" ]]; then
        warn "I do not know how to install ITAPS_FMDB on a Mac. Giving up"
    else
        $MAKE install
        if [[ $? != 0 ]] ; then
           warn "ITAPS_FMDB install failed.  Giving up"
           return 1
        fi
    fi
    popd >/dev/null 2>&1

    #
    # Configure SCORECUtil
    #
    info "Configuring SCORECUtil for ITAPS_FMDB. . ."
    pushd SCUtil/SCORECUtil-0.1 >/dev/null 2>&1
    ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" \
        CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
        --with-gmi=$VISITDIR/itaps/$ITAPS_VERSION/FMDB/$ITAPS_FMDB_VERSION/$VISITARCH \
        --with-fmdb=$abs_itaps_fmdb_build_dir \
        --with-iterators=$abs_itaps_fmdb_build_dir/SCUtil/siter \
        --prefix="$VISITDIR/itaps/$ITAPS_VERSION/FMDB/$ITAPS_FMDB_VERSION/$VISITARCH"
    if [[ $? != 0 ]] ; then
       warn "ITAPS_FMBD configure failed.  Giving up"
       return 1
    fi
    info "Building SCORECUtil for ITAPS_FMDB. . ."
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "ITAPS_FMDB build failed.  Giving up"
       return 1
    fi
    if [[ "$OPSYS" == "Darwin" ]]; then
        warn "I do not know how to install ITAPS_FMDB on a Mac. Giving up"
    else
        $MAKE install
        if [[ $? != 0 ]] ; then
           warn "ITAPS_FMDB install failed.  Giving up"
           return 1
        fi
    fi
    popd >/dev/null 2>&1
    
    #
    # Configure FMDB
    #
    info "Invoking command to configure ITAPS_FMDB"
    ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" \
        CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
        --with-scorecutil=$VISITDIR/itaps/$ITAPS_VERSION/FMDB/$ITAPS_FMDB_VERSION/$VISITARCH \
        --with-gmi=$VISITDIR/itaps/$ITAPS_VERSION/FMDB/$ITAPS_FMDB_VERSION/$VISITARCH \
        --with-iterators=$abs_itaps_fmdb_build_dir/SCUtil/siter \
        --prefix="$VISITDIR/itaps/$ITAPS_VERSION/FMDB/$ITAPS_FMDB_VERSION/$VISITARCH" \
        --enable-imesh
    if [[ $? != 0 ]] ; then
       warn "ITAPS_FMBD configure failed.  Giving up"
       return 1
    fi

    #
    # Build ITAPS_FMDB
    #
    info "Building ITAPS_FMDB. . . (~10 minutes)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "ITAPS_FMDB build failed.  Giving up"
       return 1
    fi

    #
    # Install into the VisIt third party location.
    #
    info "Installing ITAPS_FMDB"

    if [[ "$OPSYS" == "Darwin" ]]; then
        warn "I do not know how to install ITAPS_FMDB on a Mac. Giving up"
    else
        $MAKE install
        if [[ $? != 0 ]] ; then
           warn "ITAPS_FMDB install failed.  Giving up"
           return 1
        fi
        # To make it easier to package this build up, ensure we don't wind up
        # liking to shared libraries.
        find $VISITDIR/itaps/$ITAPS_VERSION/FMDB/$ITAPS_FMDB_VERSION/$VISITARCH -name 'lib*.so*' -exec rm -f {} \;
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/itaps/$ITAPS_VERSION/FMDB"
       chgrp -R ${GROUP} "$VISITDIR/itaps/$ITAPS_VERSION/FMDB"
    fi
    cd "$START_DIR"
    info "Done with ITAPS_FMDB"
    return 0
}

# *************************************************************************** #
#                       Function 8.16, build_itaps_grummp                     #
# *************************************************************************** #

function build_itaps_grummp
{
    #
    # Prepare build dir for CGM
    #
    prepare_build_dir $ITAPS_GRUMMP_CGM_BUILD_DIR $ITAPS_GRUMMP_CGM_FILE
    untarred_itaps_cgm_grummp=$?
    if [[ $untarred_itaps_cgm_grummp == -1 ]] ; then
       warn "Unable to prepare ITAPS_GRUMMP_CGM build directory. Giving Up!"
       return 1
    fi

    #
    # Call configure for CGM
    #
    info "Configuring ITAPS_GRUMMP_CGM. . ."
    cd $ITAPS_GRUMMP_CGM_BUILD_DIR || error "Cannot cd to $ITAPS_GRUMMP_CGM_BUILD_DIR build dir."
    info "Invoking command to configure ITAPS_GRUMMP_CGM"
    ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" \
        CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
        --prefix="$VISITDIR/itaps/$ITAPS_VERSION/GRUMMP/$ITAPS_GRUMMP_VERSION/$VISITARCH"
    if [[ $? != 0 ]] ; then
       warn "ITAPS_GRUMMP_CGM configure failed.  Giving up"
       return 1
    fi

    #
    # Build ITAPS_GRUMMP_CGM
    #
    info "Building ITAPS_GRUMMP_CGM. . . (~10 minutes)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "ITAPS_GRUMMP_CGM build failed.  Giving up"
       return 1
    fi

    #
    # Install into the VisIt third party location.
    #
    info "Installing ITAPS_GRUMMP_CGM"

    if [[ "$OPSYS" == "Darwin" ]]; then
        warn "I do not know how to install ITAPS_GRUMMP_CGM on a Mac. Giving up"
    else
        $MAKE install
        if [[ $? != 0 ]] ; then
           warn "ITAPS_GRUMMP_CGM install failed.  Giving up"
           return 1
        fi
        # To make it easier to package this build up, ensure we don't wind up
        # liking to shared libraries.
        find $VISITDIR/itaps/$ITAPS_VERSION/GRUMMP/$ITAPS_GRUMMP_VERSION/$VISITARCH -name 'lib*.so*' -exec rm -f {} \;
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/itaps/$ITAPS_VERSION/GRUMMP"
       chgrp -R ${GROUP} "$VISITDIR/itaps/$ITAPS_VERSION/GRUMMP"
    fi
    cd "$START_DIR"
    info "Done with ITAPS_GRUMMP_CGM"

    #
    # Prepare build dir
    #
    prepare_build_dir $ITAPS_GRUMMP_BUILD_DIR $ITAPS_GRUMMP_FILE
    untarred_itaps_grummp=$?
    if [[ $untarred_itaps_grummp == -1 ]] ; then
       warn "Unable to prepare ITAPS_GRUMMP build directory. Giving Up!"
       return 1
    fi
    
    #
    # Call configure
    #
    info "Configuring ITAPS_GRUMMP. . ."
    cd $ITAPS_GRUMMP_BUILD_DIR || error "Cannot cd to $ITAPS_GRUMMP_BUILD_DIR build dir."
    info "Invoking command to configure ITAPS_GRUMMP"
    ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" \
        CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
        --prefix="$VISITDIR/itaps/$ITAPS_VERSION/GRUMMP/$ITAPS_GRUMMP_VERSION/$VISITARCH" \
        --with-CGM-path="$VISITDIR/itaps/$ITAPS_VERSION/GRUMMP/$ITAPS_GRUMMP_VERSION/$VISITARCH" \
        --enable-imesh
    if [[ $? != 0 ]] ; then
       warn "ITAPS_GRUMMP configure failed.  Giving up"
       return 1
    fi

    #
    # Build ITAPS_GRUMMP
    #
    info "Building ITAPS_GRUMMP. . . (~10 minutes)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "ITAPS_GRUMMP build failed.  Giving up"
       return 1
    fi

    #
    # Install into the VisIt third party location.
    #
    info "Installing ITAPS_GRUMMP"

    if [[ "$OPSYS" == "Darwin" ]]; then
        warn "I do not know how to install ITAPS_GRUMMP on a Mac. Giving up"
    else
        $MAKE install
        if [[ $? != 0 ]] ; then
           warn "ITAPS_GRUMMP install failed.  Giving up"
           return 1
        fi
        # To make it easier to package this build up, ensure we don't wind up
        # liking to shared libraries.
        find $VISITDIR/itaps/$ITAPS_VERSION/GRUMMP/$ITAPS_GRUMMP_VERSION/$VISITARCH -name 'lib*.so*' -exec rm -f {} \;
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/itaps/$ITAPS_VERSION/GRUMMP"
       chgrp -R ${GROUP} "$VISITDIR/itaps/$ITAPS_VERSION/GRUMMP"
    fi
    cd "$START_DIR"
    info "Done with ITAPS_GRUMMP"
    return 0
}

function bv_itaps_is_enabled
{
    if [[ $DO_ITAPS == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_itaps_is_installed
{
    #TODO: check other versions if necessary
    check_if_installed "itaps/$ITAPS_VERSION/MOAB" $ITAPS_MOAB_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_itaps_build
{
cd "$START_DIR"
if [[ "$DO_ITAPS" == "yes" ]] ; then

    # handle MOAB implementation of ITAPS
    check_if_installed "itaps/$ITAPS_VERSION/MOAB" $ITAPS_MOAB_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping ITAPS_MOAB build.  ITAPS_MOAB is already installed."
    else
        info "Building ITAPS_MOAB (~10 minutes)"
        build_itaps_moab
        if [[ $? != 0 ]] ; then
            error "Unable to build or install ITAPS_MOAB.  Bailing out."
        fi
        info "Done building ITAPS_MOAB"
    fi

    # handle FMDB implementation of ITAPS
    check_if_installed "itaps/$ITAPS_VERSION/FMDB" $ITAPS_FMDB_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping ITAPS_FMDB build.  ITAPS_FMDB is already installed."
    else
        info "Building ITAPS_FMDB (~10 minutes)"
        build_itaps_fmdb
        if [[ $? != 0 ]] ; then
            error "Unable to build or install ITAPS_FMDB.  Bailing out."
        fi
        info "Done building ITAPS_FMDB"
    fi

    # handle GRUMMP implementation ot ITAPS
    check_if_installed "itaps/$ITAPS_VERSION/GRUMMP" $ITAPS_GRUMMP_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping ITAPS_GRUMMP build.  ITAPS_GRUMMP is already installed."
    else
        info "Building ITAPS_GRUMMP (~10 minutes)"
        build_itaps_grummp
        if [[ $? != 0 ]] ; then
            error "Unable to build or install ITAPS_GRUMMP.  Bailing out."
        fi
        info "Done building ITAPS_GRUMMP"
    fi
fi

}
function bv_manta_initialize
{
export DO_MANTA="no"
export ON_MANTA="off"
}

function bv_manta_enable
{
DO_MANTA="yes"
ON_MANTA="on"
}

function bv_manta_disable
{
DO_MANTA="no"
ON_MANTA="off"
}

function bv_manta_depends_on
{
echo ""
}

function bv_manta_info
{
export MANTA_VERSION=${MANTA_VERSION:-"2540"}
export MANTA_FILE=${MANTA_FILE:-"manta-${MANTA_VERSION}.tar.gz"}
export MANTA_COMPATIBILITY_VERSION=${MANTA_COMPATIBILITY_VERSION:-"2540"}
export MANTA_BUILD_DIR=${MANTA_BUILD_DIR:-"manta-${MANTA_VERSION}"}
export MANTA_MD5_CHECKSUM=""
export MANTA_SHA256_CHECKSUM=""
}

function bv_manta_print
{
  printf "%s%s\n" "MANTA_FILE=" "${MANTA_FILE}"
  printf "%s%s\n" "MANTA_VERSION=" "${MANTA_VERSION}"
  printf "%s%s\n" "MANTA_COMPATIBILITY_VERSION=" "${MANTA_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "MANTA_BUILD_DIR=" "${MANTA_BUILD_DIR}"
}

function bv_manta_print_usage
{
printf "%-15s %s [%s]\n" "--manta" "Build Manta" "${DO_MANTA}"
}

function bv_manta_graphical
{
local graphical_out="MANTA    $MANTA_VERSION($MANTA_FILE)     $ON_MANTA"
echo $graphical_out
}

function bv_manta_host_profile
{
    if [[ "$DO_MANTA" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## MANTA" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_MANTA_DIR \${VISITHOME}/manta/$MANTA_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
    fi
}

function bv_manta_ensure
{
    if [[ "$DO_MANTA" == "yes" ]] ; then
        ensure_built_or_ready "manta" $MANTA_VERSION $MANTA_BUILD_DIR $MANTA_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_MANTA="no"
            error "Unable to build Manta.  ${MANTA_FILE} not found."
        fi
    fi
}

function bv_manta_dry_run
{
  if [[ "$DO_MANTA" == "yes" ]] ; then
    echo "Dry run option not set for manta."
  fi
}

# ***************************************************************************
#                         Function build_manta
#
# ***************************************************************************

function build_manta
{
    #
    # Prepare build dir
    #
    prepare_build_dir $MANTA_BUILD_DIR $MANTA_FILE
    untarred_manta=$?
    if [[ $untarred_manta == -1 ]] ; then
       warn "Unable to prepare Manta Build Directory. Giving Up"
       return 1
    fi

    #
    info "Configuring Manta . . ."
    cd ${MANTA_BUILD_DIR} || error "Can't cd to Manta build dir."
    #apply_manta_patch
    #if [[ $? != 0 ]] ; then
    #    warn "Patch failed, but continuing."
    #fi

    #
    # Call configure
    #
    CMAKE_BIN="${CMAKE_INSTALL}/cmake"
    cCompiler="${C_COMPILER}"
    cFlags="${CFLAGS} ${C_OPT_FLAGS}"
    cxxCompiler="${CXX_COMPILER}"
    cxxFlags="{$CXXFLAGS} ${CXX_OPT_FLAGS}"
    if [[ "$OPSYS" == "Linux" && "$C_COMPILER" == "xlc" ]]; then
        cCompiler="gxlc"
        cxxCompiler="gxlC"
        cFlags=`echo ${CFLAGS} ${C_OPT_FLAGS} | sed "s/-qpic/-fPIC/g"`
        cxxFlags=`echo $CXXFLAGS} ${CXX_OPT_FLAGS} | sed "s/-qpic/-fPIC/g"`
    fi
    MANTA_OPT="$cFlags"
    MANTA_LDFLAGS=""
    MANTA_PREFIX_DIR="$VISITDIR/manta/$MANTA_VERSION/$VISITARCH"
    if [[ "$DO_STATIC_BUILD" == "no" ]]; then
        MANTA_SHARED="--enable-shared"
        if [[ "$C_COMPILER" == "gcc" ]]; then
            #
            # python's --enable-shared configure flag doesn't link
            # the exes it builds correclty when installed to a non standard
            # prefix. To resolve this we need to add a rpath linker flags.
            #
            #mkdir -p ${MANTA_PREFIX_DIR}/build
            #cmake .
            ${CMAKE_BIN} -DCMAKE_INSTALL_PREFIX=$MANTA_PREFIX_DIR .
            if [[ $? != 0 ]] ; then
                 warn "Manta configure failed.  Giving up"
            return 1
            fi

            if [[ "$OPSYS" != "Darwin" || ${VER%%.*} -ge 9 ]]; then
                MANTA_LDFLAGS="-Wl,-rpath,${MANTA_PREFIX_DIR}/lib/ -pthread"
            fi
        fi
    fi
    #
    #  Manta CMake
    #
    if [[ $? != 0 ]] ; then
       warn "Manta cmake failed.  Giving up"
       return 1
    fi

    #
    # Build Manta.
    #
    info "Building Manta . . . (~2 minutes)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "Manta build failed.  Giving up"
       return 1
    fi
    info "Installing Manta . . ."
    $MAKE install
    if [[ $? != 0 ]] ; then
       warn "Manta build (make install) failed.  Giving up"
       return 1
    fi

    chmod -R ug+w,a+rX $VISITDIR/manta
    if [[ "$DO_GROUP" == "yes" ]] ; then
        chgrp -R ${GROUP} "$VISITDIR/manta"
    fi

    cd "$START_DIR"
    info "Done with Manta"

    return 0
}

function bv_manta_is_enabled
{
    if [[ $DO_MANTA == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_manta_is_installed
{
    check_if_installed "manta" $MANTA_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_manta_build
{
cd "$START_DIR"
if [[ "$DO_MANTA" == "yes" ]] ; then
    check_if_installed "manta" $MANTA_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping Manta build.  Manta is already installed."
    else
        info "Building Manta (~1 minutes)"
        build_manta
        if [[ $? != 0 ]] ; then
            error "Unable to build or install Manta.  Bailing out."
        fi
        info "Done building Manta"
    fi
fi
}
function bv_mesa_initialize
{
export DO_MESA="no"
export ON_MESA="off"
}

function bv_mesa_enable
{
DO_MESA="yes"
ON_MESA="on"
}

function bv_mesa_disable
{
DO_MESA="no"
ON_MESA="off"
}

function bv_mesa_depends_on
{
echo ""
}

function bv_mesa_info
{
export MESA_FILE=${MESA_FILE:-"MesaLib-7.10.2.tar.gz"}
export MESA_VERSION=${MESA_VERSION:-"7.10.2"}
export MESA_BUILD_DIR=${MESA_BUILD_DIR:-"Mesa-7.10.2"}
export MESA_MD5_CHECKSUM=""
export MESA_SHA256_CHECKSUM=""
}

function bv_mesa_print
{
printf "%s%s\n" "MESA_FILE=" "${MESA_FILE}"
printf "%s%s\n" "MESA_VERSION=" "${MESA_VERSION}"
printf "%s%s\n" "MESA_TARGET=" "${MESA_TARGET}"
printf "%s%s\n" "MESA_BUILD_DIR=" "${MESA_BUILD_DIR}"
}

function bv_mesa_print_usage
{
printf "\t\t%15s\n" "NOTE: not available for download from web"
printf "%-15s %s [%s]\n" "--mesa" "Build Mesa" "$DO_MESA"
}

function bv_mesa_graphical
{
local graphical_out="Mesa     $MESA_VERSION($MESA_FILE)      $ON_MESA"
echo $graphical_out
}

function bv_mesa_host_profile
{
    if [[ "$DO_MESA" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## Mesa" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_MESA_DIR \${VISITHOME}/mesa/$MESA_VERSION/\${VISITARCH})" >> $HOSTCONF
    fi
}

function bv_mesa_selected
{
    args=$@
    if [[ $args == "--mesa" ]]; then
        DO_MESA="yes"
        ON_MESA="on"
        return 1
    fi

    return 0
}

function bv_mesa_ensure
{
    if [[ "$DO_DBIO_ONLY" != "yes" ]]; then
        if [[ "$DO_MESA" == "yes" ]] ; then
            ensure_built_or_ready "mesa"   $MESA_VERSION   $MESA_BUILD_DIR   $MESA_FILE
            if [[ $? != 0 ]] ; then
                return 1
            fi
        fi
    fi
}

function bv_mesa_dry_run
{
    if [[ "$DO_MESA" == "yes" ]] ; then
        echo "Dry run option not set for mesa."
    fi
}

function apply_mesa_75_patch_1
{
   patch -f -p0 <<\EOF
diff -c a/src/mesa/main/config.h Mesa-7.5/src/mesa/main/config.h
*** a/src/mesa/main/config.h
--- Mesa-7.5/src/mesa/main/config.h
***************
*** 138,146 ****
  /** 
   * Maximum viewport/image width. Must accomodate all texture sizes too. 
   */
! #define MAX_WIDTH 4096
  /** Maximum viewport/image height */
! #define MAX_HEIGHT 4096
  
  /** Maxmimum size for CVA.  May be overridden by the drivers.  */
  #define MAX_ARRAY_LOCK_SIZE 3000
--- 138,146 ----
  /** 
   * Maximum viewport/image width. Must accomodate all texture sizes too. 
   */
! #define MAX_WIDTH 16384
  /** Maximum viewport/image height */
! #define MAX_HEIGHT 16384
  
  /** Maxmimum size for CVA.  May be overridden by the drivers.  */
  #define MAX_ARRAY_LOCK_SIZE 3000
EOF
   if [[ $? != 0 ]] ; then
        warn "Unable to apply patch 1 to Mesa 7.5."
        return 1
   else
        return 0
   fi
}

function apply_mesa_75_patch_2
{
    patch -f -p0 <<\EOF
diff -c a/configure.ac Mesa-7.5/configure.ac
*** a/configure.ac
--- Mesa-7.5/configure.ac
***************
*** 224,229 ****
--- 224,231 ----
          LIB_EXTENSION='dylib' ;;
      cygwin* )
          LIB_EXTENSION='dll' ;;
+     aix* )
+         LIB_EXTENSION='a' ;;
      * )
          LIB_EXTENSION='so' ;;
      esac
EOF

    if [[ $? != 0 ]] ; then
        warn "Unable to apply patch 2 to Mesa 7.5."
        return 1
    else
        return 0
   fi
}

function apply_mesa_75_patch_3
{
    patch -f -p0 <<\EOF
diff -c a/progs/Makefile Mesa-7.5/progs/Makefile
*** a/progs/Makefile
--- Mesa-7.5/progs/Makefile
***************
*** 4,10 ****
  
  include $(TOP)/configs/current
  
! SUBDIRS = $(PROGRAM_DIRS)
  
  
  default: message subdirs
--- 4,10 ----
  
  include $(TOP)/configs/current
  
! SUBDIRS ="$(PROGRAM_DIRS)"
  
  
  default: message subdirs
***************
*** 15,32 ****
  
  
  subdirs:
! 	@for dir in $(SUBDIRS) ; do \
! 		if [ -d $$dir ] ; then \
! 			(cd $$dir && $(MAKE)) || exit 1 ; \
! 		fi \
! 	done
  
  # Dummy install target
  install:
  
  clean:
! 	-@for dir in $(SUBDIRS) tests ; do \
! 		if [ -d $$dir ] ; then \
! 			(cd $$dir && $(MAKE) clean) ; \
! 		fi \
! 	done
--- 15,36 ----
  
  
  subdirs:
! 	@if test -n "$(SUBDIRS)" ; then \
! 		for dir in $(SUBDIRS) ; do \
! 			if [ -d $$dir ] ; then \
! 				(cd $$dir && $(MAKE)) || exit 1 ; \
! 			fi \
! 		done \
! 	fi
  
  # Dummy install target
  install:
  
  clean:
! 	-@if test -n "$(SUBDIRS)" ; then \
! 		for dir in $(SUBDIRS) tests ; do \
! 			if [ -d $$dir ] ; then \
! 				(cd $$dir && $(MAKE) clean) ; \
! 			fi \
! 		done \
! 	fi
EOF

    if [[ $? != 0 ]] ; then
        warn "Unable to apply patch 3 to Mesa 7.5."
        return 1
    else
        return 0
   fi
}


function apply_mesa_75_patch_4
{
    patch -f -p0 <<\EOF
diff -c a/src/mesa/main/compiler.h Mesa-7.5/src/mesa/main/compiler.h
*** a/src/mesa/main/compiler.h
--- Mesa-7.5/src/mesa/main/compiler.h
***************
*** 233,239 ****
  #elif defined(__APPLE__)
  #include <CoreFoundation/CFByteOrder.h>
  #define CPU_TO_LE32( x )	CFSwapInt32HostToLittle( x )
! #else /*__linux__ __APPLE__*/
  #include <sys/endian.h>
  #define CPU_TO_LE32( x )	bswap32( x )
  #endif /*__linux__*/
--- 233,244 ----
  #elif defined(__APPLE__)
  #include <CoreFoundation/CFByteOrder.h>
  #define CPU_TO_LE32( x )	CFSwapInt32HostToLittle( x )
! #elif defined(_AIX)
! #define CPU_TO_LE32( x )	x = ((x & 0x000000ff) << 24) | \
! 				    ((x & 0x0000ff00) <<  8) | \
! 				    ((x & 0x00ff0000) >>  8) | \
! 				    ((x & 0xff000000) >> 24);
! #else /*__linux__*/
  #include <sys/endian.h>
  #define CPU_TO_LE32( x )	bswap32( x )
  #endif /*__linux__*/
EOF

    if [[ $? != 0 ]] ; then
        warn "Unable to apply patch 4 to Mesa 7.5."
        return 1
    else
        return 0
   fi
}


function apply_mesa_782_patch_1
{
   patch -f -p0 <<\EOF
diff -c a/src/mesa/drivers/osmesa/osmesa.c Mesa-7.8.2/src/mesa/drivers/osmesa/osmesa.c
*** a/src/mesa/drivers/osmesa/osmesa.c
--- Mesa-7.8.2/src/mesa/drivers/osmesa/osmesa.c
***************
*** 1328,1336 ****
      * that converts rendering from CHAN_BITS to the user-requested channel
      * size.
      */
!    osmesa->rb = new_osmesa_renderbuffer(&osmesa->mesa, osmesa->format, type);
!    _mesa_add_renderbuffer(osmesa->gl_buffer, BUFFER_FRONT_LEFT, osmesa->rb);
!    assert(osmesa->rb->RefCount == 2);
  
     /* Set renderbuffer fields.  Set width/height = 0 to force 
      * osmesa_renderbuffer_storage() being called by _mesa_resize_framebuffer()
--- 1328,1339 ----
      * that converts rendering from CHAN_BITS to the user-requested channel
      * size.
      */
!    if (!osmesa->rb) {
!       osmesa->rb = new_osmesa_renderbuffer(&osmesa->mesa, osmesa->format, type);
!       _mesa_remove_renderbuffer(osmesa->gl_buffer, BUFFER_FRONT_LEFT);
!       _mesa_add_renderbuffer(osmesa->gl_buffer, BUFFER_FRONT_LEFT, osmesa->rb);
!       assert(osmesa->rb->RefCount == 2);
!    }
  
     /* Set renderbuffer fields.  Set width/height = 0 to force 
      * osmesa_renderbuffer_storage() being called by _mesa_resize_framebuffer()
EOF

   if [[ $? != 0 ]] ; then
      warn "Unable to apply patch 1 to Mesa 7.8.2."
      return 1
   else
      return 0
   fi
}


function apply_mesa_782_patch_2
{
   patch -f -p1 <<\EOF
From cc32ff741c5d32a66531a586b1f9268b94846c58 Mon Sep 17 00:00:00 2001
From: Tom Fogal <tfogal@alumni.unh.edu>
Date: Sun, 26 Sep 2010 18:57:59 -0600
Subject: [PATCH] Implement x86_64 atomics for compilers w/o intrinsics.

Really old gcc's (3.3, at least) don't have support for the
intrinsics we need.  This implements a fallback for that case.
---
 src/gallium/auxiliary/util/u_atomic.h |   47 +++++++++++++++++++++++++++++++++
 1 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_atomic.h b/Mesa-7.8.2/src/gallium/auxiliary/util/u_atomic.h
index a156823..8434491 100644
--- a/src/gallium/auxiliary/util/u_atomic.h
+++ b/Mesa-7.8.2/src/gallium/auxiliary/util/u_atomic.h
@@ -29,6 +29,8 @@
 #define PIPE_ATOMIC_ASM_MSVC_X86                
 #elif (defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86))
 #define PIPE_ATOMIC_ASM_GCC_X86
+#elif (defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86_64))
+#define PIPE_ATOMIC_ASM_GCC_X86_64
 #elif defined(PIPE_CC_GCC) && (PIPE_CC_GCC_VERSION >= 401)
 #define PIPE_ATOMIC_GCC_INTRINSIC
 #else
@@ -36,6 +38,51 @@
 #endif
 
 
+#if defined(PIPE_ATOMIC_ASM_GCC_X86_64)
+#define PIPE_ATOMIC "GCC x86_64 assembly"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define p_atomic_set(_v, _i) (*(_v) = (_i))
+#define p_atomic_read(_v) (*(_v))
+
+static INLINE boolean
+p_atomic_dec_zero(int32_t *v)
+{
+   unsigned char c;
+
+   __asm__ __volatile__("lock; decl %0; sete %1":"+m"(*v), "=qm"(c)
+			::"memory");
+
+   return c != 0;
+}
+
+static INLINE void
+p_atomic_inc(int32_t *v)
+{
+   __asm__ __volatile__("lock; incl %0":"+m"(*v));
+}
+
+static INLINE void
+p_atomic_dec(int32_t *v)
+{
+   __asm__ __volatile__("lock; decl %0":"+m"(*v));
+}
+
+static INLINE int32_t
+p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
+{
+   return __sync_val_compare_and_swap(v, old, _new);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PIPE_ATOMIC_ASM_GCC_X86_64 */
+
 
 #if defined(PIPE_ATOMIC_ASM_GCC_X86)
 
-- 
1.7.0.2
EOF

   if [[ $? != 0 ]] ; then
      warn "Unable to apply patch 2 to Mesa 7.8.2."
      return 1
   else
      return 0
   fi
}


function apply_mesa_7102_patch_1
{
   patch -f -p0 <<\EOF
diff -c a/src/mesa/main/APIspec.py Mesa-7.10.2/src/mesa/main/APIspec.py
*** a/src/mesa/main/APIspec.py
--- Mesa-7.10.2/src/mesa/main/APIspec.py
***************
*** 262,268 ****
          args = []
          if declaration:
              for param in self.params:
!                 sep = "" if param.type.endswith("*") else " "
                  args.append("%s%s%s" % (param.type, sep, param.name))
              if not args:
                  args.append("void")
--- 262,272 ----
          args = []
          if declaration:
              for param in self.params:
!                 #sep = "" if param.type.endswith("*") else " "
!                 if param.type.endswith("*"):
!                     sep = ""
!                 else:
!                     sep = " "
                  args.append("%s%s%s" % (param.type, sep, param.name))
              if not args:
                  args.append("void")
EOF

   if [[ $? != 0 ]] ; then
      warn "Unable to apply patch 1 to Mesa 7.10.2."
      return 1
   else
      return 0
   fi
}


function apply_mesa_7102_patch_2
{
   patch -f -p0 <<\EOF
diff -c a/src/mesa/main/APIspecutil.py Mesa-7.10.2/src/mesa/main/APIspecutil.py
*** a/src/mesa/main/APIspecutil.py
--- Mesa-7.10.2/src/mesa/main/APIspecutil.py
***************
*** 129,135 ****
              if dep_desc.checker.switches:
                  print >>sys.stderr, "%s: deep nested dependence" % func.name

!             convert = None if dep_desc.convert else "noconvert"
              for val in desc.values:
                  valid_values.append((val, dep_desc.size_str, dep_desc.name,
                                       dep_desc.values, dep_desc.error, convert))
--- 129,139 ----
              if dep_desc.checker.switches:
                  print >>sys.stderr, "%s: deep nested dependence" % func.name

!             #convert = None if dep_desc.convert else "noconvert"
!             if dep_desc.convert:
!                 convert = None
!             else:
!                 convert = "noconvert"
              for val in desc.values:
                  valid_values.append((val, dep_desc.size_str, dep_desc.name,
                                       dep_desc.values, dep_desc.error, convert))
***************
*** 241,247 ****
      """Return a C-style parameter declaration string."""
      string = []
      for p in params:
!         sep = "" if p[1].endswith("*") else " "
          string.append("%s%s%s" % (p[1], sep, p[0]))
      if not string:
          return "void"
--- 245,255 ----
      """Return a C-style parameter declaration string."""
      string = []
      for p in params:
!         #sep = "" if p[1].endswith("*") else " "
!         if p[1].endswith("*"):
!             sep = ""
!         else:
!             sep = " "
          string.append("%s%s%s" % (p[1], sep, p[0]))
      if not string:
          return "void"
***************
*** 257,269 ****
  def Alias(funcname):
      """Return the name of the function the named function is an alias of."""
      alias, need_conv = __aliases[funcname]
!     return alias.name if not need_conv else None


  def ConversionFunction(funcname):
      """Return the name of the function the named function converts to."""
      alias, need_conv = __aliases[funcname]
!     return alias.name if need_conv else None


  def Categories(funcname):
--- 265,285 ----
  def Alias(funcname):
      """Return the name of the function the named function is an alias of."""
      alias, need_conv = __aliases[funcname]
!     if need_conv:
!         return None
!     else:
!         return alias.name
!     #return alias.name if not need_conv else None


  def ConversionFunction(funcname):
      """Return the name of the function the named function converts to."""
      alias, need_conv = __aliases[funcname]
!     if need_conv:
!         return alias.name
!     else:
!         return None
!     #return alias.name if need_conv else None


  def Categories(funcname):
EOF

   if [[ $? != 0 ]] ; then
      warn "Unable to apply patch 2 to Mesa 7.10.2."
      return 1
   else
      return 0
   fi
}


function apply_mesa_7102_patch_3
{
   patch -f -p0 <<\EOF
diff -c a/src/mesa/main/es_generator.py Mesa-7.10.2/src/mesa/main/es_generator.py
*** a/src/mesa/main/es_generator.py
--- Mesa-7.10.2/src/mesa/main/es_generator.py
***************
*** 741,747 ****
  """ % (shortname, shortname, shortname, shortname)

  for func in keys:
!     prefix = "_es_" if func not in allSpecials else "_check_"
      for spec in apiutil.Categories(func):
          ext = spec.split(":")
          # version does not match
--- 741,751 ----
  """ % (shortname, shortname, shortname, shortname)

  for func in keys:
!     #prefix = "_es_" if func not in allSpecials else "_check_"
!     if func in allSpecials:
!         prefix = "_check_"
!     else:
!         prefix = "_es_"
      for spec in apiutil.Categories(func):
          ext = spec.split(":")
          # version does not match
EOF

   if [[ $? != 0 ]] ; then
      warn "Unable to apply patch 3 to Mesa 7.10.2."
      return 1
   else
      return 0
   fi
}


function apply_mesa_patch
{
    info "Patching Mesa . . ."
    if [[ ${MESA_VERSION} == "7.5" ]] ; then
        apply_mesa_75_patch_1
        if [[ $? != 0 ]] ; then
            return 1
        fi
        apply_mesa_75_patch_2
        if [[ $? != 0 ]] ; then
            return 1
        fi
        apply_mesa_75_patch_3
        if [[ $? != 0 ]] ; then
            return 1
        fi
        apply_mesa_75_patch_4
        if [[ $? != 0 ]] ; then
            return 1
        fi
    elif [[ ${MESA_VERSION} == "7.8.2" ]] ; then
        apply_mesa_782_patch_1
        if [[ $? != 0 ]] ; then
            return 1
        fi
        apply_mesa_782_patch_2
        if [[ $? != 0 ]] ; then
            return 1
        fi
    elif [[ ${MESA_VERSION} == "7.10.2" ]] ; then
        apply_mesa_7102_patch_1
        if [[ $? != 0 ]] ; then
            return 1
        fi
        apply_mesa_7102_patch_2
        if [[ $? != 0 ]] ; then
            return 1
        fi
        apply_mesa_7102_patch_3
        if [[ $? != 0 ]] ; then
            return 1
        fi
    else
        warn "Unsupported Mesa Version ${MESA_VERSION}"
        return 1
    fi

    return 0
}


function build_mesa
{
    #
    # prepare build dir
    #
    prepare_build_dir $MESA_BUILD_DIR $MESA_FILE
    untarred_mesa=$?

    if [[ $untarred_mesa == -1 ]] ; then
        warn "Unable to prepare Mesa build directory. Giving Up!"
        return 1
    fi

    #
    # Patch mesa
    #
    apply_mesa_patch
    if [[ $? != 0 ]] ; then
        if [[ $untarred_mesa == 1 ]] ; then
            warn "Giving up on Mesa build because the patch failed."
            return 1
         else
            warn "Patch failed, but continuing.  I believe that this script\n"\
                 "tried to apply a patch to an existing directory which had\n"\
                 "already been patched ... that is, that the patch is\n"\
                 "failing harmlessly on a second application."
        fi
    fi

    #
    # Build Mesa.
    #
    info "Building Mesa . . . (~2 minutes)"
    cd $MESA_BUILD_DIR || error "Couldn't cd to mesa build dir."
    PF="${VISITDIR}/mesa/${MESA_VERSION}/${VISITARCH}"

    # We do the build twice due to a VTK issue.  VTK can establish a
    # rendering context via the system's GL using glX, via mangled Mesa
    # using glX, and via offscreen mangled Mesa.  For VisIt, we use
    # either the system's GL, or offscreen mangled Mesa.  To placate
    # VTK, we'll build a mangled+glX version, but then we'll build the
    # offscreen one that we really want.  This ensures we have the 'MesaGL'
    # that VTK needs to link, but if we use 'OSMesa' we get a real, OSMesa
    # library with no glX dependency.
    #
    # Due to this issue, it is imperative that one links "-lOSMesa
    # -lMesaGL" when they want to render/link to an offscreen Mesa
    # context.  The two libraries will have a host of duplicate
    # symbols, and it is important that we pick up the ones from OSMesa.
    info "Configuring Mesa (glX) ..."
    if [[ "$OPSYS" == "AIX" ]]; then
        export AIX_MESA_CFLAGS="-qcpluscmt -qlanglvl=extc99"
        autoconf
        if [[ $? != 0 ]] ; then
            error "Mesa: AIX autoconf failed!"
        fi
    fi

    if [[ "$DO_STATIC_BUILD" == "yes" ]]; then
        MESA_STATIC_DYNAMIC="--disable-shared --enable-static"
    fi

    info 
    
    # Neither of these should be necessary, but we use them as a temporary
    # workaround for a mesa issue.
    if test `uname` = "Linux" ; then
        HACK_FLAGS="-fPIC -DGLX_USE_TLS"
    fi

    # Do not build libGLU unless we're on MacOS X
    DISABLE_GLU="--disable-glu"
    if [[ "$OPSYS" == "Darwin" ]]; then
        DISABLE_GLU=""
        # If we're on 10.4 or earlier, change the GLU exports file
        VER=$(uname -r)
        if [[ ${VER%%.*} -le 9 ]]; then
            rm src/glu/sgi/glu.exports.darwin.edit
            sed "s/_\*/_m/g" src/glu/sgi/glu.exports.darwin > src/glu/sgi/glu.exports.darwin.edit
            cp src/glu/sgi/glu.exports.darwin.edit src/glu/sgi/glu.exports.darwin
        fi
    fi

    ./configure \
      CC="${C_COMPILER}" \
      CXX="${CXX_COMPILER}" \
      CFLAGS="${C_OPT_FLAGS} ${CFLAGS} ${AIX_MESA_CFLAGS} ${HACK_FLAGS}" \
      CXXFLAGS="${CXX_OPT_FLAGS} ${CXXFLAGS} ${HACK_FLAGS}" \
      --prefix=${PF}                    \
      --without-demos                   \
      --with-driver=osmesa              \
      --disable-gallium                 \
      --with-max-width=16384            \
      --with-max-height=16384           \
      --enable-glx-tls                  \
      --disable-glw                     \
      ${DISABLE_GLU}                    \
      --disable-egl  ${MESA_STATIC_DYNAMIC}
    if [[ $? != 0 ]] ; then
        warn "Mesa: 'configure' for Offscreen failed.  Giving up"
        return 1
    fi

    info "Building Mesa (Offscreen) ..."
    ${MAKE} ${MAKE_OPT_FLAGS}
    if [[ $? != 0 ]] ; then
        warn "Mesa: 'make' for Offscreen failed.  Giving up"
        return 1
    fi
    info "Installing Mesa (Offscreen) ..."
    ${MAKE} install
    if [[ $? != 0 ]] ; then
        warn "Mesa: 'make install' for Offscreen failed.  Giving up"
        return 1
    fi

    # Some versions of Mesa erroneously install GLEW as well.  We need to make
    # sure we get VisIt's GLEW when we include it, so remove the ones Mesa
    # installs.
    rm -f ${PF}/include/GL/gl*ew.h

    if [[ $? != 0 ]] ; then
        warn "Mesa build failed.  Giving up"
        return 1
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
        chmod -R ug+w,a+rX "$VISITDIR/mesa"
        chgrp -R ${GROUP} "$VISITDIR/mesa"
    fi
    cd "$START_DIR"
    info "Done with Mesa"
    return 0
}

function bv_mesa_is_enabled
{
    if [[ $DO_MESA == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_mesa_is_installed
{
    check_if_installed "mesa" $MESA_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_mesa_build
{
    #
    # Build Mesa
    #
    cd "$START_DIR"
    if [[ "$DO_MESA" == "yes" ]] ; then
        check_if_installed "mesa" $MESA_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping Mesa build.  Mesa is already installed."
        else
            info "Building Mesa (~2 minutes)"
            build_mesa
            if [[ $? != 0 ]] ; then
                error "Unable to build or install Mesa.  Bailing out."
            fi
            info "Done building Mesa"
        fi
    fi
}

function bv_mfem_initialize
{
export DO_MFEM="no"
export ON_MFEM="off"
}

function bv_mfem_enable
{
DO_MFEM="yes"
ON_MFEM="on"
}

function bv_mfem_disable
{
DO_MFEM="no"
ON_MFEM="off"
}

function bv_mfem_depends_on
{
    local depends_on=""

    echo $depends_on
}

function bv_mfem_info
{
export MFEM_VERSION=${MFEM_VERSION:-"3.1"}
export MFEM_FILE=${MFEM_FILE:-"mfem-${MFEM_VERSION}.tgz"}
export MFEM_BUILD_DIR=${MFEM_BUILD_DIR:-"mfem-${MFEM_VERSION}"}
export MFEM_URL=${MFEM_URL:-"http://mfem.github.io/releases"}
}

function bv_mfem_print
{
  printf "%s%s\n" "MFEM_FILE=" "${MFEM_FILE}"
  printf "%s%s\n" "MFEM_VERSION=" "${MFEM_VERSION}"
  printf "%s%s\n" "MFEM_BUILD_DIR=" "${MFEM_BUILD_DIR}"
}

function bv_mfem_print_usage
{
printf "%-15s %s [%s]\n" "--mfem" "Build mfem support" "$DO_MFEM"
}

function bv_mfem_graphical
{
local graphical_out="mfem     $MFEM_VERSION($MFEM_FILE)      $ON_MFEM"
echo "$graphical_out"
}

function bv_mfem_host_profile
{
    if [[ "$DO_MFEM" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## MFEM " >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_MFEM_DIR \${VISITHOME}/mfem/$MFEM_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
    fi
}

function bv_mfem_ensure
{
    if [[ "$DO_MFEM" == "yes" ]] ; then
        ensure_built_or_ready "mfem" $MFEM_VERSION $MFEM_BUILD_DIR $MFEM_FILE $MFEM_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_MFEM="no"
            error "Unable to build mfem.  ${MFEM_FILE} not found."
        fi
    fi
}

function bv_mfem_dry_run
{
  if [[ "$DO_MFEM" == "yes" ]] ; then
    echo "Dry run option not set for mfem."
  fi
}

# *************************************************************************** #
#                            Function 8, build_mfem
# *************************************************************************** #
function build_mfem
{
    #
    # Prepare build dir
    #
    prepare_build_dir $MFEM_BUILD_DIR $MFEM_FILE
    untarred_mfem=$?
    if [[ $untarred_mfem == -1 ]] ; then
       warn "Unable to prepare mfem build directory. Giving Up!"
       return 1
    fi

    cd $MFEM_BUILD_DIR || error "Can't cd to mfem build dir."

    #
    # Call configure
    #
    info "Configuring mfem . . ."
    info $MAKE config CXX="$CXX_COMPILER" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS"
    $MAKE config CXX="$CXX_COMPILER" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS"

    #
    # Build mfem
    #

    info "Building mfem . . . (~2 minutes)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "mfem build failed.  Giving up"
       return 1
    fi

    #
    # Install into the VisIt third party location.
    #
    info "Installing mfem"
    $MAKE install PREFIX="$VISITDIR/mfem/$MFEM_VERSION/$VISITARCH/"

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/mfem"
       chgrp -R ${GROUP} "$VISITDIR/mfem"
    fi
    cd "$START_DIR"
    info "Done with mfem"
    return 0
}


function bv_mfem_is_enabled
{
    if [[ $DO_MFEM == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_mfem_is_installed
{
    check_if_installed "mfem" $MFEM_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_mfem_build
{
cd "$START_DIR"
if [[ "$DO_MFEM" == "yes" ]] ; then
    check_if_installed "mfem" $MFEM_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping mfem build.  mfem is already installed."
    else
        info "Building mfem (~2 minutes)"
        build_mfem
        if [[ $? != 0 ]] ; then
            error "Unable to build or install mfem.  Bailing out."
        fi
        info "Done building mfem"
    fi
fi
}

function bv_mili_initialize
{
export DO_MILI="no"
export ON_MILI="off"
}

function bv_mili_enable
{
DO_MILI="yes"
ON_MILI="on"
}

function bv_mili_disable
{
DO_MILI="no"
ON_MILI="off"
}

function bv_mili_depends_on
{
echo ""
}

function bv_mili_info
{
export MILI_FILE=${MILI_FILE:-"mili_15_1.tar.gz"}
export MILI_VERSION=${MILI_VERSION:-"15.1"}
export MILI_COMPATIBILITY_VERSION=${MILI_COMPATIBILITY_VERSION:-"15.1"}
export MILI_BUILD_DIR=${MILI_BUILD_DIR:-"mili"}
export MILI_MD5_CHECKSUM="115c6aaf742f151aea6c644d719ee067"
export MILI_SHA256_CHECKSUM="564c50b003aded7ec33977f8192fbf6ec2f5dc22a41c9551a8fa492c484031bf"
}

function bv_mili_print
{
  printf "%s%s\n" "MILI_FILE=" "${MILI_FILE}"
  printf "%s%s\n" "MILI_VERSION=" "${MILI_VERSION}"
  printf "%s%s\n" "MILI_COMPATIBILITY_VERSION=" "${MILI_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "MILI_BUILD_DIR=" "${MILI_BUILD_DIR}"
}

function bv_mili_print_usage
{
printf "\t\t%15s\n" "NOTE: not available for download from web"
printf "%-15s %s [%s]\n" "--mili" "Build Mili" "$DO_MILI"
}

function bv_mili_graphical
{
local graphical_out="MILI    $MILI_VERSION($MILI_FILE)     $ON_MILI"
echo "$graphical_out"
}

function bv_mili_host_profile
{
    if [[ "$DO_MILI" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## Mili" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_MILI_DIR \${VISITHOME}/mili/$MILI_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
    fi
}

function bv_mili_ensure
{
    if [[ "$DO_MILI" == "yes" ]] ; then
        ensure_built_or_ready "mili" $MILI_VERSION $MILI_BUILD_DIR $MILI_FILE
        if [[ $? != 0 ]] ; then
            warn "Unable to build Mili.  ${MILI_FILE} not found."
            ANY_ERRORS="yes"
            DO_MILI="no"
            if [[ "$DO_SVN" != "yes" ]] ; then
                warn "Note: You have requested to build the Mili library." 
                warn "Mili is not available for public download and" 
                warn "is only available through Subversion access." 
            fi
            error
        fi
    fi
}

function bv_mili_dry_run
{
  if [[ "$DO_MILI" == "yes" ]] ; then
    echo "Dry run option not set for mili."
  fi
}

# *************************************************************************** #
#                          Function 8.2, build_mili                           #
# *************************************************************************** #

function apply_mili_100_darwin_patch
{
    patch -p0 << \EOF
diff -c a/src/mili_internal.h mili/src/mili_internal.h
*** a/src/mili_internal.h
--- mili/src/mili_internal.h
***************
*** 54,59 ****
--- 54,60 ----
  #include <stdio.h>
  #include <stdlib.h>
  #include <dirent.h>
+ #include <sys/types.h>
  #include "list.h"
  #include "misc.h"
  #include "mili.h"
EOF
    if [[ $? != 0 ]] ; then
        warn "Unable to apply Darwin patch to Mili 1.10.0."
        return 1
    fi

    return 0
}

function apply_mili_100_patch
{
    if [[ "$OPSYS" == "Darwin" ]]; then
        apply_mili_100_darwin_patch
        if [[ $? != 0 ]] ; then
            return 1
        fi
    fi

    return 0
}

function apply_mili_111_patch_1
{
    patch -p0 << \EOF
diff -c a/src/mili.h mili/src/mili.h
*** a/src/mili.h
--- mili/src/mili.h
***************
*** 226,232 ****
  } ObjDef;

  /* Mili version */
! const char *mili_version;

  /*
                  * *                                      * *
--- 226,232 ----
  } ObjDef;

  /* Mili version */
! extern const char *mili_version;

  /*
                  * *                                      * *
EOF
    if [[ $? != 0 ]] ; then
        warn "Unable to apply patch 1 to Mili 1.11.1."
        return 1
    fi

    return 0
}

function apply_mili_111_patch_2
{
    patch -p0 << \EOF
diff -c a/src/mili.c mili/src/mili.c
*** a/src/mili.c
--- mili/src/mili.c
***************
*** 94,99 ****
--- 94,102 ----
                           && ( f->ti_directory[f->ti_file_count - 1].commit_count == 0\
                                || f->non_state_ready ) )

+ /* Mili version */
+ const char *mili_version;
+
  static void set_path( char *in_path, char **out_path, int *out_path_len );
  static void map_old_header( char header[CHAR_HEADER_SIZE] );
  static Return_value create_family( Mili_family * );
EOF
    if [[ $? != 0 ]] ; then
        warn "Unable to apply patch 2 to Mili 1.11.1."
        return 1
    fi

    return 0
}

function apply_mili_111_patch
{
    apply_mili_111_patch_1
    if [[ $? != 0 ]] ; then
        return 1
    fi
    apply_mili_111_patch_2
    if [[ $? != 0 ]] ; then
        return 1
    fi

    return 0
}

function apply_mili_151_darwin_patch1
{
    patch -p0 << \EOF
diff -c mili/src/mesh_u.c mili.patched/src/mesh_u.c
*** mili/src/mesh_u.c	2015-09-22 13:20:42.000000000 -0700
--- mili.patched/src/mesh_u.c	2015-10-19 12:44:52.000000000 -0700
***************
*** 14,20 ****
  
  #include <string.h>
  #ifndef _MSC_VER
! #include <values.h>
  #include <sys/time.h>
  #endif
  #include <time.h>
--- 14,20 ----
  
  #include <string.h>
  #ifndef _MSC_VER
! #include <limits.h>
  #include <sys/time.h>
  #endif
  #include <time.h>
EOF
    if [[ $? != 0 ]] ; then
        warn "Unable to apply Darwin patch 1 to Mili 15.1"
        return 1
    fi

    return 0
}

function apply_mili_151_darwin_patch2
{
    patch -p0 << \EOF
*** mili/Makefile.Library	2013-12-10 12:55:55.000000000 -0800
--- mili.patched/Makefile.Library	2015-10-20 13:37:27.000000000 -0700
***************
*** 386,393 ****
  	done
  
  uninstall:
- 
- ifneq ($(OS_NAME),Linux)
- include $(OBJS:.o=.d)
- endif
- 
--- 386,388 ----
EOF
    if [[ $? != 0 ]] ; then
        warn "Unable to apply Darwin patch 2 to Mili 15.1"
        return 1
    fi

    return 0
}

function apply_mili_151_darwin_patch3
{
    patch -p0 << \EOF
*** mili/src/mili_internal.h	2015-09-17 13:26:32.000000000 -0700
--- mili.patched/src/mili_internal.h	2015-10-20 16:57:21.000000000 -0700
***************
*** 534,542 ****
   * Library-private file family management routines and data.
   */
  
! int host_index;
! int internal_sizes[QTY_PD_ENTRY_TYPES + 1];
! int mili_verbose;
  Return_value validate_fam_id( Famid fam_id );
  Return_value parse_control_string( char *ctl_str, Mili_family *fam,
                                     Bool_type *p_create );
--- 534,542 ----
   * Library-private file family management routines and data.
   */
  
! extern int host_index;
! extern int internal_sizes[QTY_PD_ENTRY_TYPES + 1];
! extern int mili_verbose;
  Return_value validate_fam_id( Famid fam_id );
  Return_value parse_control_string( char *ctl_str, Mili_family *fam,
                                     Bool_type *p_create );
***************
*** 604,610 ****
  Return_value load_directories( Mili_family *fam );
  
  /* param.c - parameter management routines. */
! char *dtype_names[QTY_PD_ENTRY_TYPES + 1];
  Return_value read_scalar( Mili_family *fam, Param_ref *p_pr,  void *p_value );
  Return_value mili_read_string( Mili_family *fam, Param_ref *p_pr,
                                 char *p_value );
--- 604,610 ----
  Return_value load_directories( Mili_family *fam );
  
  /* param.c - parameter management routines. */
! extern char *dtype_names[QTY_PD_ENTRY_TYPES + 1];
  Return_value read_scalar( Mili_family *fam, Param_ref *p_pr,  void *p_value );
  Return_value mili_read_string( Mili_family *fam, Param_ref *p_pr,
                                 char *p_value );
***************
*** 647,653 ****
  /* dep.c - routines for handling architecture dependencies. */
  Return_value set_default_io_routines( Mili_family *fam );
  Return_value set_state_data_io_routines( Mili_family *fam );
! void (*write_funcs[QTY_PD_ENTRY_TYPES + 1])();
  
  /* svar.c - routines for managing state variables. */
  Bool_type valid_svar_data( Aggregate_type atype, char *name,
--- 647,653 ----
  /* dep.c - routines for handling architecture dependencies. */
  Return_value set_default_io_routines( Mili_family *fam );
  Return_value set_state_data_io_routines( Mili_family *fam );
! extern void (*write_funcs[QTY_PD_ENTRY_TYPES + 1])();
  
  /* svar.c - routines for managing state variables. */
  Bool_type valid_svar_data( Aggregate_type atype, char *name,
***************
*** 740,746 ****
  void mili_delete_mo_class_data( void *p_data );
  
  /* wrap_c.c - C-half of FORTRAN-to-C wrappers. */
! int fortran_api;
  /* write_db.c */
  Return_value
  write_state_data( int state_num, Mili_analysis *out_db );
--- 740,746 ----
  void mili_delete_mo_class_data( void *p_data );
  
  /* wrap_c.c - C-half of FORTRAN-to-C wrappers. */
! extern int fortran_api;
  /* write_db.c */
  Return_value
  write_state_data( int state_num, Mili_analysis *out_db );
EOF
    if [[ $? != 0 ]] ; then
        warn "Unable to apply Darwin patch 3 to Mili 15.1"
        return 1
    fi

    return 0
}

function apply_mili_patch
{
    if [[ ${MILI_VERSION} == 1.10.0 ]] ; then
        apply_mili_100_patch
        if [[ $? != 0 ]] ; then
            return 1
        fi
    elif [[ ${MILI_VERSION} == 1.11.1 ]] ; then
        apply_mili_111_patch
        if [[ $? != 0 ]] ; then
            return 1
        fi
    elif [[ ${MILI_VERSION} == 15.1 && "$OPSYS" == "Darwin" ]]; then
        apply_mili_151_darwin_patch1
        if [[ $? != 0 ]] ; then
            return 1
        fi
        apply_mili_151_darwin_patch2
        if [[ $? != 0 ]] ; then
            return 1
        fi
        apply_mili_151_darwin_patch3
        if [[ $? != 0 ]] ; then
            return 1
        fi
    fi

    return 0
}

function build_mili
{
    #
    # Prepare build dir
    #
    prepare_build_dir $MILI_BUILD_DIR $MILI_FILE
    untarred_mili=$?
    if [[ $untarred_mili == -1 ]] ; then
       warn "Unable to prepare Mili Build Directory. Giving Up"
       return 1
    fi

    #
    # Apply patches
    #
    info "Patching mili . . ."
    apply_mili_patch
    if [[ $? != 0 ]] ; then
       if [[ $untarred_mili == 1 ]] ; then
          warn "Giving up on Mili build because the patches failed."
          return 1
       else
          warn "Patch failed, but continuing.  I believe that this script " 
          warn "tried to apply a patch to an existing directory which had " 
          warn "already been patched ... that is, that the patch is "
          warn "failing harmlessly on a second application."
       fi
    fi

    info "Configuring Mili . . ."
    cd $MILI_BUILD_DIR || error "Can't cd to mili build dir."

    info "Invoking command to configure Mili"
    ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" \
        CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
        ac_cv_prog_FOUND_GMAKE=make \
        --prefix="$VISITDIR/mili/$MILI_VERSION/$VISITARCH"
    if [[ $? != 0 ]] ; then
       warn "Mili configure failed.  Giving up"
       return 1
    fi

    #
    # Build Mili
    #
    info "Building Mili . . . (~2 minutes)"

    if [[ ${MILI_VERSION} == 1.10.0 ]] ; then
        cd MILI-$OPSYS-*
        cd src
        $C_COMPILER $CFLAGS $C_OPT_FLAGS -D_LARGEFILE64_SOURCE -c \
            mili.c direc.c param.c io.c util.c dep.c svar.c \
            srec.c mesh_u.c wrap_c.c io_mem.c eprtf.c \
            sarray.c gahl.c util.c partition.c ti.c tidirc.c
        if [[ $? != 0 ]] ; then
            warn "Mili build failed.  Giving up"
            return 1
        fi
    elif [[ ${MILI_VERSION} == 1.11.1 ]] ; then
        cd MILI-*-*
        cd src
        $C_COMPILER $CFLAGS $C_OPT_FLAGS -D_LARGEFILE64_SOURCE -c \
            mili.c dep.c direc.c eprtf.c gahl.c io_mem.c \
            mesh_u.c mr_funcs.c param.c partition.c read_db.c sarray.c \
            srec.c svar.c taurus_db.c taurus_mesh_u.c taurus_srec.c \
            taurus_svars.c taurus_util.c ti.c tidirc.c util.c wrap_c.c \
            write_db.c
        if [[ $? != 0 ]] ; then
            warn "Mili build failed.  Giving up"
            return 1
        fi
    elif [[ ${MILI_VERSION} == 13.1.1-patch || ${MILI_VERSION} == 15.1 ]] ; then
        cd MILI-*-*
        make opt fortran=false
    fi

    #
    # Install into the VisIt third party location.
    #
    info "Installing Mili . . ." 

    mkdir "$VISITDIR/mili"
    mkdir "$VISITDIR/mili/$MILI_VERSION"
    mkdir "$VISITDIR/mili/$MILI_VERSION/$VISITARCH"
    mkdir "$VISITDIR/mili/$MILI_VERSION/$VISITARCH/lib"
    mkdir "$VISITDIR/mili/$MILI_VERSION/$VISITARCH/include"
    if [[ ${MILI_VERSION} == 1.10.0 ]] ; then
        cp mili.h mili_enum.h  "$VISITDIR/mili/$MILI_VERSION/$VISITARCH/include"
    elif [[ ${MILI_VERSION} == 1.11.1 ]] ; then
        cp mili.h mili_enum.h misc.h  "$VISITDIR/mili/$MILI_VERSION/$VISITARCH/include"
    elif [[ ${MILI_VERSION} == 13.1.1-patch || ${MILI_VERSION} == 15.1 ]] ; then
        cp src/{mili.h,mili_enum.h,misc.h}  "$VISITDIR/mili/$MILI_VERSION/$VISITARCH/include"
    fi
    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
        INSTALLNAMEPATH="$VISITDIR/mili/${MILI_VERSION}/$VISITARCH/lib"

        if [[ ${MILI_VERSION} != 15.1 ]] ; then
            $C_COMPILER -dynamiclib -o libmili.$SO_EXT *.o \
              -Wl,-headerpad_max_install_names \
              -Wl,-install_name,$INSTALLNAMEPATH/libmili.${SO_EXT} \
              -Wl,-compatibility_version,$MILI_COMPATIBILITY_VERSION \
              -Wl,-current_version,$MILI_VERSION
        else
            $C_COMPILER -dynamiclib -o libmili.$SO_EXT objs_opt/*.o \
              -Wl,-headerpad_max_install_names \
              -Wl,-install_name,$INSTALLNAMEPATH/libmili.${SO_EXT} \
              -Wl,-compatibility_version,$MILI_COMPATIBILITY_VERSION \
              -Wl,-current_version,$MILI_VERSION
        fi
        if [[ $? != 0 ]] ; then
          warn "Mili dynamic library build failed.  Giving up"
          return 1
        fi
        cp libmili.$SO_EXT "$VISITDIR/mili/$MILI_VERSION/$VISITARCH/lib"
    else
        if [[ ${MILI_VERSION} != 13.1.1-patch && ${MILI_VERSION} != 15.1 ]] ; then
            ar -rc libmili.a *.o 
            if [[ $? != 0 ]] ; then
              warn "Mili install failed.  Giving up"
              return 1
            fi
            cp libmili.a "$VISITDIR/mili/$MILI_VERSION/$VISITARCH/lib"
        else
            cp lib_opt/libmili.a "$VISITDIR/mili/$MILI_VERSION/$VISITARCH/lib"
        fi
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/mili"
       chgrp -R ${GROUP} "$VISITDIR/mili"
    fi
    cd "$START_DIR"
    info "Done with Mili"
    return 0
}

function bv_mili_is_enabled
{
    if [[ $DO_MILI == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_mili_is_installed
{
    check_if_installed "mili" $MILI_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_mili_build
{
cd "$START_DIR"
if [[ "$DO_MILI" == "yes" ]] ; then
    check_if_installed "mili" $MILI_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping Mili build.  Mili is already installed."
    else
        info "Building Mili (~2 minutes)"
        build_mili
        if [[ $? != 0 ]] ; then
            error "Unable to build or install Mili.  Bailing out."
        fi
        info "Done building Mili"
    fi
fi
}

function bv_mpich_initialize
{
export DO_MPICH="no"
export ON_MPICH="off"
}

function bv_mpich_enable
{
DO_MPICH="yes"
ON_MPICH="on"
}

function bv_mpich_disable
{
DO_MPICH="no"
ON_MPICH="off"
}

function bv_mpich_depends_on
{
    local depends_on=""

    echo $depends_on
}

function bv_mpich_info
{
export MPICH_VERSION=${MPICH_VERSION:-"3.0.4"}
export MPICH_FILE=${MPICH_FILE:-"mpich-${MPICH_VERSION}.tar.gz"}
export MPICH_COMPATIBILITY_VERSION=${MPICH_COMPATIBILITY_VERSION:-"3.0.0"}
export MPICH_BUILD_DIR=${MPICH_BUILD_DIR:-"mpich-${MPICH_VERSION}"}
export MPICH_URL=${MPICH_URL:-http://www.mpich.org/static/tarballs/3.0.4}
export MPICH_MD5_CHECKSUM="9c5d5d4fe1e17dd12153f40bc5b6dbc0"
export MPICH_SHA256_CHECKSUM="cf638c85660300af48b6f776e5ecd35b5378d5905ec5d34c3da7a27da0acf0b3"
}

function bv_mpich_print
{
  printf "%s%s\n" "MPICH_FILE=" "${MPICH_FILE}"
  printf "%s%s\n" "MPICH_VERSION=" "${MPICH_VERSION}"
  printf "%s%s\n" "MPICH_COMPATIBILITY_VERSION=" "${MPICH_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "MPICH_BUILD_DIR=" "${MPICH_BUILD_DIR}"
}

function bv_mpich_print_usage
{
printf "%-15s %s [%s]\n" "--mpich" "Build MPICH support" "$DO_MPICH"
}

function bv_mpich_graphical
{
local graphical_out="MPICH     $MPICH_VERSION($MPICH_FILE)      $ON_MPICH"
echo "$graphical_out"
}

function bv_mpich_host_profile
{
    if [[ "$DO_MPICH" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## MPICH" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "" >> $HOSTCONF
        echo "# Give VisIt information so it can install MPI into the binary distribution." >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_MPICH_DIR \${VISITHOME}/mpich/$MPICH_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_MPICH_INSTALL ON)" >> $HOSTCONF
        echo "" >> $HOSTCONF
        echo "# Tell VisIt the parallel compiler so it can deduce parallel flags" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_MPI_COMPILER \${VISIT_MPICH_DIR}/bin/mpicc)" \
        >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_PARALLEL ON)" >> $HOSTCONF
    fi
}

function bv_mpich_ensure
{
    if [[ "$DO_MPICH" == "yes" ]] ; then
        ensure_built_or_ready "mpich" $MPICH_VERSION $MPICH_BUILD_DIR $MPICH_FILE $MPICH_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_MPICH="no"
            error "Unable to build MPICH.  ${MPICH_FILE} not found."
        fi
    fi
}

function bv_mpich_dry_run
{
  if [[ "$DO_MPICH" == "yes" ]] ; then
    echo "Dry run option not set for mpich."
  fi
}

# *************************************************************************** #
#                            Function 8, build_mpich
#
# Modfications:
#
# *************************************************************************** #

function build_mpich
{
    #
    # Prepare build dir
    #
    prepare_build_dir $MPICH_BUILD_DIR $MPICH_FILE
    untarred_mpich=$?
    if [[ $untarred_mpich == -1 ]] ; then
       warn "Unable to prepare MPICH build directory. Giving Up!"
       return 1
    fi
    
    #
    # Call configure
    #
    info "Configuring MPICH . . ."
    cd $MPICH_BUILD_DIR || error "Can't cd to MPICH build dir."
    info "Invoking command to configure MPICH"

    mpich_opts=""
    if [[ "$OPSYS" == "Darwin" ]]; then
        mpich_opts="${mpich_opts} --enable-two-level-namespace"
    fi

    #
    # mpich will fail to build if we disable common blocks '-fno-common'
    # Screen the flags vars to make sure we don't use this option for mpich
    #

    MPICH_CFLAGS=`echo $CFLAGS | sed -e 's/-fno-common//g'`
    MPICH_C_OPT_FLAGS=`echo $C_OPT_FLAGS | sed -e 's/-fno-common//g'`
    MPICH_CXXFLAGS=`echo $CXXFLAGS | sed -e 's/-fno-common//g'`
    MPICH_CXX_OPT_FLAGS=`echo $CXX_OPT_FLAGS | sed -e 's/-fno-common//g'`
    MPICH_FCFLAGS=`echo $FCFLAGS | sed -e 's/-fno-common//g'`

    # disable fortran if we don't have a fortran compiler
        
    if [[ "$FC_COMPILER" == "no" ]] ; then
        mpich_opts="${mpich_opts} --disable-fc --disable-f77"
    fi

    issue_command env CXX="$CXX_COMPILER" \
                      CC="$C_COMPILER" \
                      CFLAGS="$MPICH_CFLAGS $MPICH_C_OPT_FLAGS" \
                      CXXFLAGS="$MPICH_CXXFLAGS $MPICH_CXX_OPT_FLAGS"\
                      FFLAGS="$MPICH_FCFLAGS"\
                      ./configure ${mpich_opts} \
                      --prefix="$VISITDIR/mpich/$MPICH_VERSION/$VISITARCH"

    if [[ $? != 0 ]] ; then
       warn "MPICH configure failed.  Giving up"
       return 1
    fi

    #
    # Build MPICH
    #
    info "Building MPICH . . . (~5 minutes)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "MPICH build failed.  Giving up"
       return 1
    fi
    #
    # Install into the VisIt third party location.
    #
    info "Installing MPICH"
    $MAKE install
    if [[ $? != 0 ]] ; then
        warn "MPICH install failed.  Giving up"
        return 1
    fi

    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
        info "Relinking MPICH into Mac shared libraries"
        #
        # This code relinks the static C libraries for MPICH into dynamic
        # libraries that let a bundle-contained mpich run. Enabling dynamic
        # linking on the configure command line did not result in all 
        # libraries being dynamically linked.
        #   
        # We kind of hack things further in order to make the libraries by 
        # combining the real contents of libmpl, libopa, libpmpich, and 
        # libmpich into a single new libmpich. The other libraries contain 
        # a stub function that does not get used. This avoids some linking 
        # problems when creating the dynamic libraries.
        #
        lastdir=`pwd`
        MPICH_LIBDIR="$VISITDIR/mpich/$MPICH_VERSION/$VISITARCH/lib"
        cd "$MPICH_LIBDIR"
        for f in libmpl libopa libpmpich libmpich libmpichcxx; do
            mkdir $f
            cd $f
            ar -x ../$f.a
            cd ..
        done

        rm -f *.dylib stub.c
        rm libpmpich/lib_libpmpich_la-comm_split_type.o
        echo "int STUB(void){return 0;}" > stub.c

        # Make fake stand-in libraries
        $C_COMPILER -dynamiclib -o libmpl.dylib -DSTUB=STUB_LIBMPL stub.c \
            -headerpad_max_install_names \
            -Wl,-install_name,"$MPICH_LIBDIR/libmpl.dylib" \
            -Wl,-compatibility_version,${MPICH_COMPATIBILITY_VERSION} \
            -Wl,-current_version,${MPICH_VERSION}

        $C_COMPILER -dynamiclib -o libopa.dylib -DSTUB=STUB_LIBOPA stub.c \
            -headerpad_max_install_names \
            -Wl,-install_name,"$MPICH_LIBDIR/libopa.dylib" \
            -Wl,-compatibility_version,${MPICH_COMPATIBILITY_VERSION} \
            -Wl,-current_version,${MPICH_VERSION}

        $C_COMPILER -dynamiclib -o libpmpich.dylib -DSTUB=STUB_LIBPMPICH stub.c \
            -headerpad_max_install_names \
            -Wl,-install_name,"$MPICH_LIBDIR/libpmpich.dylib" \
            -Wl,-compatibility_version,${MPICH_COMPATIBILITY_VERSION} \
            -Wl,-current_version,${MPICH_VERSION}

        # Combine the libaries into a new libmpich.
        $C_COMPILER -dynamiclib -o libmpich.dylib libmpl/*.o libopa/*.o libmpich/*.o libpmpich/lib_libpmpich*.o\
            -headerpad_max_install_names \
            -Wl,-install_name,"$MPICH_LIBDIR/libmpich.dylib" \
            -Wl,-compatibility_version,${MPICH_COMPATIBILITY_VERSION} \
            -Wl,-current_version,${MPICH_VERSION}

        # Clean up
        for f in libmpl libopa libpmpich libmpich libmpichcxx; do
            rm -rf $f
            rm -f $f.a $f.la
        done
        rm -rf stub.c pkgconfig
        cd "$lastdir"
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/mpich"
       chgrp -R ${GROUP} "$VISITDIR/mpich"
    fi
    cd "$START_DIR"
    info "Done with MPICH"
    return 0
}

function bv_mpich_is_enabled
{
    if [[ $DO_MPICH == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_mpich_is_installed
{
    check_if_installed "mpich" $MPICH_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_mpich_build
{
cd "$START_DIR"
if [[ "$DO_MPICH" == "yes" ]] ; then
    check_if_installed "mpich" $MPICH_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping MPICH build.  MPICH is already installed."
    else
        info "Building MPICH (~2 minutes)"
        build_mpich
        if [[ $? != 0 ]] ; then
            error "Unable to build or install MPICH.  Bailing out."
        fi
        info "Done building MPICH"
    fi
fi
}

function bv_mxml_initialize
{
export DO_MXML="no"
export ON_MXML="off"
}

function bv_mxml_enable
{
DO_MXML="yes"
ON_MXML="on"
}

function bv_mxml_disable
{
DO_MXML="no"
ON_MXML="off"
}

function bv_mxml_depends_on
{
echo ""
}

function bv_mxml_info
{
export MXML_FILE=${MXML_FILE:-"mxml-2.6.tar.gz"}
export MXML_VERSION=${MXML_VERSION:-"2.6"}
export MXML_COMPATIBILITY_VERSION=${MXML_COMPATIBILITY_VERSION:-"2.6"}
export MXML_BUILD_DIR=${MXML_BUILD_DIR:-"mxml-2.6"}
export MXML_MD5_CHECKSUM="68977789ae64985dddbd1a1a1652642e"
export MXML_SHA256_CHECKSUM=""
}

function bv_mxml_print
{
  printf "%s%s\n" "MXML_FILE=" "${MXML_FILE}"
  printf "%s%s\n" "MXML_VERSION=" "${MXML_VERSION}"
  printf "%s%s\n" "MXML_COMPATIBILITY_VERSION=" "${MXML_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "MXML_BUILD_DIR=" "${MXML_BUILD_DIR}"
}

function bv_mxml_host_profile
{
#nothing to be done for now..
echo "##" >> $HOSTCONF
}

function bv_mxml_print_usage
{
#mxml does not have an option, it is only dependent on mxml.
printf "%-15s %s [%s]\n" "--mxml" "Build Mxml" "$DO_MXML"
}

function bv_mxml_ensure
{
    if [[ "$DO_MXML" == "yes" ]] ; then
        ensure_built_or_ready "mxml" $MXML_VERSION $MXML_BUILD_DIR $MXML_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_MXML="no"
            error "Unable to build MXML.  ${MXML_FILE} not found."
        fi
    fi
}

function bv_mxml_dry_run
{
  if [[ "$DO_MXML" == "yes" ]] ; then
    echo "Dry run option not set for mxml."
  fi
}

function apply_mxml_26_darwin_patch
{
   patch -p0 << \EOF
diff -c mxml-2.6/Makefile.in mxml-2.6.new/Makefile.in
*** mxml-2.6/Makefile.in	2008-12-05 20:20:38.000000000 -0800
--- mxml-2.6.new/Makefile.in	2012-11-21 11:14:45.000000000 -0800
***************
*** 344,353 ****
--- 344,355 ----
  			--header doc/docset.header --intro doc/docset.intro \
  			--css doc/docset.css --title "Mini-XML API Reference" \
  			mxml.xml || exit 1; \
+         if test -e /Developer/usr/bin/docsetutil; then \
  		/Developer/usr/bin/docsetutil package --output org.minixml.xar \
  			--atom org.minixml.atom \
  			--download-url http://www.minixml.org/org.minixml.xar \
  			org.minixml.docset || exit 1; \
+         fi \
  	fi
EOF
   if [[ $? != 0 ]] ; then
       warn "Unable to patch MXML. Wrong version?"
       return 1
   fi

   return 0
}

function apply_mxml_26_patch
{
   if [[ "$OPSYS" == "Darwin" ]]; then
       apply_mxml_26_darwin_patch
       if [[ $? != 0 ]] ; then
           return 1
       fi
   fi

   return 0
}

function apply_mxml_patch
{
   if [[ ${MXML_VERSION} == 2.6 ]] ; then
       apply_mxml_26_patch
       if [[ $? != 0 ]] ; then
           return 1
       fi
   fi

   return 0
}

# ***************************************************************************
#                         Function 8.21, build_mxml
# Required by ADIOS.
#
# Modifications:
#
# ***************************************************************************

function build_mxml
{
    #
    # Prepare build dir
    #
    prepare_build_dir $MXML_BUILD_DIR $MXML_FILE
    untarred_mxml=$?
    if [[ $untarred_mxml == -1 ]] ; then
       warn "Unable to prepare mxml Build Directory. Giving Up"
       return 1
    fi

    #
    # Apply patches
    #
    info "Patching MXML . . ."
    apply_mxml_patch
    if [[ $? != 0 ]] ; then
       if [[ $untarred_mxml == 1 ]] ; then
          warn "Giving up on MXML build because the patch failed."
          return 1
       else
          warn "Patch failed, but continuing.  I believe that this script" \
               "tried to apply a patch to an existing directory which had" \
               "already been patched ... that is, that the patch is" \
               "failing harmlessly on a second application."
       fi
    fi
    
    #
    info "Configuring mxml . . ."
    cd $MXML_BUILD_DIR || error "Can't cd to mxml build dir."
    info "Invoking command to configure mxml"
    ./configure ${OPTIONAL} CXX="$CXX_COMPILER" \
       CC="$C_COMPILER" CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
       --prefix="$VISITDIR/mxml/$MXML_VERSION/$VISITARCH" --disable-threads
    if [[ $? != 0 ]] ; then
       warn "mxml configure failed.  Giving up"
       return 1
    fi

    #
    # Build mxml
    #
    info "Building mxml . . . (~1 minutes)"

    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "mxml build failed.  Giving up"
       return 1
    fi
    info "Installing ADIOS . . ."

    $MAKE install
    if [[ $? != 0 ]] ; then
       warn "mxml build (make install) failed.  Giving up"
       return 1
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/mxml"
       chgrp -R ${GROUP} "$VISITDIR/mxml"
    fi
    cd "$START_DIR"
    info "Done with mxml"
    return 0
}

function bv_mxml_is_enabled
{
    if [[ $DO_MXML == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_mxml_is_installed
{
    check_if_installed "mxml" $MXML_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_mxml_build
{
    if [[ "$DO_MXML" == "yes" ]] ; then
        check_if_installed "mxml" $MXML_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping build of MXML"
        else
            build_mxml
            if [[ $? != 0 ]] ; then
                 error "Unable to build or install mxml.  Bailing out."
            fi
            info "Done building mxml"
        fi
    fi
}

function bv_mxml_graphical
{
local graphical_out="MXML    $MXML_VERSION($MXML_FILE)     $ON_MXML"
#echo "$graphical_out"
echo ""
}

function bv_nektarpp_initialize
{
export DO_NEKTAR_PLUS_PLUS="no"
export ON_NEKTAR_PLUS_PLUS="off"
export USE_SYSTEM_NEKTAR_PLUS_PLUS="no"
add_extra_commandline_args "nektarpp" "alt-nektarpp-dir" 1 "Use alternative directory for nektar++"
}

function bv_nektarpp_enable
{
DO_NEKTAR_PLUS_PLUS="yes"
ON_NEKTAR_PLUS_PLUS="on"
}

function bv_nektarpp_disable
{
DO_NEKTAR_PLUS_PLUS="no"
ON_NEKTAR_PLUS_PLUS="off"
}

function bv_nektarpp_alt_nektarpp_dir
{
    bv_nektarpp_enable
    USE_SYSTEM_NEKTAR_PLUS_PLUS="yes"
    NEKTAR_PLUS_PLUS_INSTALL_DIR="$1"
}

function bv_nektarpp_depends_on
{
    depends_on="cmake boost zlib"

    if [[ "$USE_SYSTEM_NEKTAR_PLUS_PLUS" == "yes" ]]; then
        echo ""
    else
        if [[ "$DO_ZLIB" == "yes" ]] ; then
           depends_on="$depends_on zlib"    
        fi

        echo $depends_on
    fi
}

function bv_nektarpp_initialize_vars
{
    if [[ "$USE_SYSTEM_NEKTAR_PLUS_PLUS" == "no" ]]; then
        NEKTAR_PLUS_PLUS_INSTALL_DIR="${VISITDIR}/nektar++/$NEKTAR_PLUS_PLUS_VERSION/${VISITARCH}"
    fi
}

function bv_nektarpp_info
{
export NEKTAR_PLUS_PLUS_VERSION=${NEKTAR_PLUS_PLUS_VERSION:-"4.1.0"}
export NEKTAR_PLUS_PLUS_FILE=${NEKTAR_PLUS_PLUS_FILE:-"nektar++-${NEKTAR_PLUS_PLUS_VERSION}.tar.gz"}
export NEKTAR_PLUS_PLUS_COMPATIBILITY_VERSION=${NEKTAR_PLUS_PLUS_COMPATIBILITY_VERSION:-"1.8"}
export NEKTAR_PLUS_PLUS_BUILD_DIR=${NEKTAR_PLUS_PLUS_BUILD_DIR:-"nektar++-${NEKTAR_PLUS_PLUS_VERSION}"}
export NEKTAR_PLUS_PLUS_URL=${NEKTAR_PLUS_PLUS_URL:-"http://www.nektar.info/downloads/nektar++-${NEKTAR_PLUS_PLUS_VERSION}/src"}
export NEKTAR_PLUS_PLUS_MD5_CHECKSUM=""
export NEKTAR_PLUS_PLUS_SHA256_CHECKSUM=""
}

function bv_nektarpp_print
{
  printf "%s%s\n" "NEKTAR_PLUS_PLUS_FILE=" "${NEKTAR_PLUS_PLUS_FILE}"
  printf "%s%s\n" "NEKTAR_PLUS_PLUS_VERSION=" "${NEKTAR_PLUS_PLUS_VERSION}"
  printf "%s%s\n" "NEKTAR_PLUS_PLUS_COMPATIBILITY_VERSION=" "${NEKTAR_PLUS_PLUS_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "NEKTAR_PLUS_PLUS_BUILD_DIR=" "${NEKTAR_PLUS_PLUS_BUILD_DIR}"
}

function bv_nektarpp_print_usage
{
printf "%-15s %s [%s]\n" "--nektarpp" "Build NEKTAR_PLUS_PLUS" "${DO_NEKTAR_PLUS_PLUS}"
}

function bv_nektarpp_graphical
{
local graphical_out="NEKTAR_PLUS_PLUS     $NEKTAR_PLUS_PLUS_VERSION($NEKTAR_PLUS_PLUS_FILE)      $ON_NEKTAR_PLUS_PLUS"
echo $graphical_out
}

function bv_nektarpp_host_profile
{
    if [[ "$DO_NEKTAR_PLUS_PLUS" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## Nektar++" >> $HOSTCONF
        echo "##" >> $HOSTCONF

        echo "SETUP_APP_VERSION(NEKTAR++ $NEKTAR_PLUS_PLUS_VERSION)" >> $HOSTCONF 

        if [[ "$USE_SYSTEM_NEKTAR_PLUS_PLUS" == "yes" ]]; then
            echo \
            "VISIT_OPTION_DEFAULT(VISIT_NEKTAR++_DIR $NEKTAR_PLUS_PLUS_INSTALL_DIR)" \
            >> $HOSTCONF 
        else
            echo \
            "VISIT_OPTION_DEFAULT(VISIT_NEKTAR++_DIR \${VISITHOME}/nektar++/\${NEKTAR++_VERSION}/\${VISITARCH})" \
            >> $HOSTCONF 

            if [[ "$DO_ZLIB" == "yes" ]] ; then
               ZLIB_LIBDEP="\${VISITHOME}/zlib/$ZLIB_VERSION/\${VISITARCH}/lib z"
            else
               ZLIB_LIBDEP="/usr/lib z"
               #moving global patch to have limited effect
               if [[ -d /usr/lib/x86_64-linux-gnu ]]; then
                ZLIB_LIBDEP="/usr/lib/x86_64-linux-gnu z"
               fi
            fi

            echo \
            "VISIT_OPTION_DEFAULT(VISIT_NEKTAR++_LIBDEP $ZLIB_LIBDEP TYPE STRING)" \
            >> $HOSTCONF
        fi
    fi
}

function bv_nektarpp_ensure
{
    if [[ "$DO_NEKTAR_PLUS_PLUS" == "yes" && "$USE_SYSTEM_NEKTAR_PLUS_PLUS" == "no" ]] ; then
        ensure_built_or_ready "nektar++" $NEKTAR_PLUS_PLUS_VERSION $NEKTAR_PLUS_PLUS_BUILD_DIR $NEKTAR_PLUS_PLUS_FILE $NEKTAR_PLUS_PLUS_URL 
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_NEKTAR_PLUS_PLUS="no"
            error "Unable to build Netar++.  ${NEKTAR_PLUS_PLUS_FILE} not found."
        fi
    fi
}

function bv_nektarpp_dry_run
{
  if [[ "$DO_NEKTAR_PLUS_PLUS" == "yes" ]] ; then
    echo "Dry run option not set for nektar_PLUS_PLUS."
  fi
}

function apply_nektarpp_patch
{
#    if [[ "${NEKTAR_PLUS_PLUS_VERSION}" == 4.0.0 ]] ; then
#        apply_nektarpp_zlib_patch
#        if [[ $? != 0 ]]; then
#           return 1
#        fi
#    fi

    return 0
}

# *************************************************************************** #
#              Function 8.1, build_nektarpp                                   #
# *************************************************************************** #
function build_nektarpp
{
    #
    # CMake is the build system for VTK.  Call another script that will build
    # that program.
    #
    CMAKE_INSTALL=${CMAKE_INSTALL:-"$VISITDIR/cmake/${CMAKE_VERSION}/$VISITARCH/bin"}
    if [[ -e ${CMAKE_INSTALL}/cmake ]] ; then
        info "Nektar++: CMake found"
    else
        build_cmake
        if [[ $? != 0 ]] ; then
            warn "Unable to build cmake.  Giving up"
            return 1
        fi
    fi

    #
    # Prepare build dir
    #
    prepare_build_dir $NEKTAR_PLUS_PLUS_BUILD_DIR $NEKTAR_PLUS_PLUS_FILE
    untarred_nektar_plus_plus=$?
    if [[ $untarred_nektar_plus_plus == -1 ]] ; then
       warn "Unable to prepare Nektar++ Build Directory. Giving Up"
       return 1
    fi

    #
    cd $NEKTAR_PLUS_PLUS_BUILD_DIR || error "Can't cd to Nektar++ build dir." $NEKTAR_PLUS_PLUS_BUILD_DIR 
    apply_nektarpp_patch
    if [[ $? != 0 ]]; then
        warn "Patch failed, but continuing."
    fi

    ntopts=""
    nektar_plus_plus_build_mode="${VISIT_BUILD_MODE}"
    nektar_plus_plus_inst_path="${NEKTAR_PLUS_PLUS_INSTALL_DIR}"

    ntopts="${ntopts} -DCMAKE_BUILD_TYPE:STRING=${nektar_plus_plus_build_mode}"
    ntopts="${ntopts} -DCMAKE_INSTALL_PREFIX:PATH=${nektar_plus_plus_inst_path}"

    ntopts="${ntopts} -DCMAKE_C_COMPILER:STRING=${C_COMPILER}"
    ntopts="${ntopts} -DCMAKE_CXX_COMPILER:STRING=${CXX_COMPILER}"
    ntopts="${ntopts} -DCMAKE_C_FLAGS:STRING=\"${C_OPT_FLAGS}\""
    ntopts="${ntopts} -DCMAKE_CXX_FLAGS:STRING=\"${CXX_OPT_FLAGS}\""
    ntopts="${ntopts} -DCMAKE_EXE_LINKER_FLAGS:STRING=${lf}"
    ntopts="${ntopts} -DCMAKE_MODULE_LINKER_FLAGS:STRING=${lf}"
    ntopts="${ntopts} -DCMAKE_SHARED_LINKER_FLAGS:STRING=${lf}"

    # Nektar++ specific options for a faster build.
#    ntopts="${ntopts} -DTHIRDPARTY_BUILD_BOOST:BOOL=ON"
    ntopts="${ntopts} -DNEKTAR_BUILD_DEMOS:BOOL=OFF"
    ntopts="${ntopts} -DNEKTAR_BUILD_SOLVERS:BOOL=OFF"
    ntopts="${ntopts} -DNEKTAR_BUILD_UTILITIES:BOOL=OFF"
    ntopts="${ntopts} -DNEKTAR_BUILD_TESTS:BOOL=OFF"
    ntopts="${ntopts} -DNEKTAR_BUILD_UNIT_TESTS:BOOL=OFF"

#    if test "${OPSYS}" = "Darwin" ; then
#        ntopts="${ntopts} -DCMAKE_INSTALL_NAME_DIR:PATH=${nektar_plus_plus_inst_path}/lib"
#    fi

    if test "x${DO_BOOST}" = "xyes"; then
        info "boost requested.  Configuring NEKTAR++ with boost support."
        ntopts="${ntopts} -DBOOST_ROOT:PATH=${VISITDIR}/boost/${BOOST_VERSION}/${VISITARCH}"

        if [[ "$OPSYS" == "Darwin" ]]; then
            export DYLD_LIBRARY_PATH="$VISITDIR/boost/$BOOST_VERSION/$VISITARCH/lib":$DYLD_LIBRARY_PATH
        else
            export LD_LIBRARY_PATH="$VISITDIR/boost/$BOOST_VERSION/$VISITARCH/lib":$LD_LIBRARY_PATH
        fi
    fi


    if test "x${DO_ZLIB}" = "xyes"; then
        info "zlib requested.  Configuring NEKTAR++ with zlib support."
        ntopts="${ntopts} -DZLIB_ROOT:PATH=${VISITDIR}/zlib/${ZLIB_VERSION}/${VISITARCH}"

        if [[ "$OPSYS" == "Darwin" ]]; then
            export DYLD_LIBRARY_PATH="$VISITDIR/zlib/$ZLIB_VERSION/$VISITARCH/lib":$DYLD_LIBRARY_PATH
        else
            export LD_LIBRARY_PATH="$VISITDIR/zlib/$ZLIB_VERSION/$VISITARCH/lib":$LD_LIBRARY_PATH
        fi
    fi

#    if test "x${DO_MPICH}" = "xyes"; then
#        info "mpich requested.  Configuring NEKTAR++ with mpich support."
#        ntopts="${ntopts} -DMPI_ROOT:PATH=${VISITDIR}/mpich/${MPICH_VERSION}/${VISITARCH}"

#        if [[ "$OPSYS" == "Darwin" ]]; then
#            export DYLD_LIBRARY_PATH="$VISITDIR/mpich/$MPICH_VERSION/$VISITARCH/lib":$DYLD_LIBRARY_PATH
#        else
#            export LD_LIBRARY_PATH="$VISITDIR/mpich/$MPICH_VERSION/$VISITARCH/lib":$LD_LIBRARY_PATH
#        fi
#    fi

#    if test "x${DO_VTK}" = "xyes"; then
#        info "vtk requested.  Configuring NEKTAR++ with vtk support."
#        ntopts="${ntopts} -DNEKTAR_USE_VTK=ON -DVTK_DIR:PATH=${VISITDIR}/${VTK_INSTALL_DIR}/${VTK_VERSION}/${VISITARCH}/lib/cmake/vtk-${VTK_SHORT_VERSION}"

#        if [[ "$OPSYS" == "Darwin" ]]; then
#            export DYLD_LIBRARY_PATH="$VISITDIR/$VTK_INSTALL_DIR/$VTK_VERSION/$VISITARCH/lib":$DYLD_LIBRARY_PATH
#        else
#            export LD_LIBRARY_PATH="$VISITDIR/$VTK_INSTALL_DIR/$VTK_VERSION/$VISITARCH/lib":$LD_LIBRARY_PATH
#        fi
#    fi

    info "Configuring Nektar++ . . ."

    cd "$START_DIR"

    # Make a build directory for an out-of-source build.. Change the
    # VISIT_BUILD_DIR variable to represent the out-of-source build directory.
    NEKTAR_PLUS_PLUS_SRC_DIR=$NEKTAR_PLUS_PLUS_BUILD_DIR
    NEKTAR_PLUS_PLUS_BUILD_DIR="${NEKTAR_PLUS_PLUS_SRC_DIR}-build"
    if [[ ! -d $NEKTAR_PLUS_PLUS_BUILD_DIR ]] ; then
        echo "Making build directory $NEKTAR_PLUS_PLUS_BUILD_DIR"
        mkdir $NEKTAR_PLUS_PLUS_BUILD_DIR
    fi

    CMAKE_BIN="${CMAKE_INSTALL}/cmake"

    cd ${NEKTAR_PLUS_PLUS_BUILD_DIR}

    if test -e bv_run_cmake.sh ; then
        rm -f bv_run_cmake.sh
    fi

    #
    # Remove the CMakeCache.txt files ... existing files sometimes prevent
    # fields from getting overwritten properly.
    #
    rm -Rf ${NEKTAR_PLUS_PLUS_BUILD_DIR}/CMakeCache.txt ${NEKTAR_PLUS_PLUS_BUILD_DIR}/*/CMakeCache.txt

    echo "\"${CMAKE_BIN}\"" ${ntopts} ../${NEKTAR_PLUS_PLUS_SRC_DIR} > bv_run_cmake.sh
    cat bv_run_cmake.sh
    issue_command bash bv_run_cmake.sh || error "Nektar++ configuration failed."

    #
    # Build NEKTAR_PLUS_PLUS
    #
    info "Making Nektar++ . . ."
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "Nektar++ build failed.  Giving up"
       return 1
    fi

    #
    # Install into the VisIt third party location.
    #
    info "Installing Nektar++ . . ."
    $MAKE install
    if [[ $? != 0 ]] ; then
       warn "Nektar++ install failed.  Giving up"
       return 1
    fi

#    mv ${nektar_plus_plus_inst_path}/lib64/* ${nektar_plus_plus_inst_path}/lib

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/nektar++"
       chgrp -R ${GROUP} "$VISITDIR/nektar++"
    fi
    cd "$START_DIR"
    info "Done with Nektar++"
    return 0
}

function bv_nektarpp_is_enabled
{
    if [[ $DO_NEKTAR_PLUS_PLUS == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_nektarpp_is_installed
{

    if [[ "$USE_SYSTEM_NEKTAR_PLUS_PLUS" == "yes" ]]; then
        return 1
    fi

    check_if_installed "nektar++" $NEKTAR_PLUS_PLUS_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_nektarpp_build
{
cd "$START_DIR"

if [[ "$DO_NEKTAR_PLUS_PLUS" == "yes" && "$USE_SYSTEM_NEKTAR_PLUS_PLUS" == "no" ]] ; then
    check_if_installed "nektar++" $NEKTAR_PLUS_PLUS_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping Nektar++ build.  Nektar++ is already installed."
    else
        info "Building Nektar++ (~10 minutes)"
        build_nektarpp
        if [[ $? != 0 ]] ; then
            error "Unable to build or install Nektar++.  Bailing out."
        fi
        info "Done building Nektar++"
    fi
fi
}
function bv_netcdf_initialize
{
export DO_NETCDF="no"
export ON_NETCDF="off"
export USE_SYSTEM_NETCDF="no"
add_extra_commandline_args "netcdf" "alt-netcdf-dir" 1 "Use alternative directory for netcdf"
}

function bv_netcdf_enable
{
DO_NETCDF="yes"
ON_NETCDF="on"
}

function bv_netcdf_disable
{
DO_NETCDF="no"
ON_NETCDF="off"
}

function bv_netcdf_alt_netcdf_dir
{
    bv_netcdf_enable
    USE_SYSTEM_NETCDF="yes"
    NETCDF_INSTALL_DIR="$1"
}

function bv_netcdf_depends_on
{
    if [[ "$USE_SYSTEM_NETCDF" == "yes" ]]; then
        echo ""
    else
        local depends_on=""
        if [[ "$DO_HDF5" == "yes" ]] ; then
            depends_on="hdf5"        
            if [[ "$DO_SZIP" == "yes" ]] ; then
                depends_on="${depends_on} szip"        
            fi
        fi
        if [[ "$DO_ZLIB" == "yes" ]] ; then
            depends_on="zlib"        
        fi
        echo ${depends_on}
    fi
}

function bv_netcdf_initialize_vars
{
    if [[ "$USE_SYSTEM_NETCDF" == "no" ]]; then
            NETCDF_INSTALL_DIR="${VISITDIR}/netcdf/$NETCDF_VERSION/${VISITARCH}"
    fi
}

function bv_netcdf_info
{
export NETCDF_VERSION=${NETCDF_VERSION-"4.1.1"}
export NETCDF_FILE=${NETCDF_FILE-"netcdf-${NETCDF_VERSION}.tar.gz"}
export NETCDF_COMPATIBILITY_VERSION=${NETCDF_COMPATIBILITY_VERSION-"4.1"}
export NETCDF_BUILD_DIR=${NETCDF_BUILD_DIR-"netcdf-4.1.1"}
export NETCDF_MD5_CHECKSUM="79c5ff14c80d5e18dd8f1fceeae1c8e1"
export NETCDF_SHA256_CHECKSUM=""
}

function bv_netcdf_print
{
  printf "%s%s\n" "NETCDF_FILE=" "${NETCDF_FILE}"
  printf "%s%s\n" "NETCDF_VERSION=" "${NETCDF_VERSION}"
  printf "%s%s\n" "NETCDF_COMPATIBILITY_VERSION=" "${NETCDF_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "NETCDF_BUILD_DIR=" "${NETCDF_BUILD_DIR}"
}

function bv_netcdf_print_usage
{
printf "\t\t%15s\n" "NOTE: not available for download from web"
printf "%-15s %s [%s]\n" "--netcdf" "Build NetCDF" "${DO_NETCDF}"
}

function bv_netcdf_graphical
{
local graphical_out="NetCDF   $NETCDF_VERSION($NETCDF_FILE)    $ON_NETCDF"
echo "$graphical_out"
}

function bv_netcdf_host_profile
{
    if [[ "$DO_NETCDF" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## NetCDF" >> $HOSTCONF
        echo "##" >> $HOSTCONF

        if [[ "$USE_SYSTEM_NETCDF" == "yes" ]]; then
            echo \
            "VISIT_OPTION_DEFAULT(VISIT_NETCDF_DIR $NETCDF_INSTALL_DIR)" \
            >> $HOSTCONF
        else
            echo \
            "VISIT_OPTION_DEFAULT(VISIT_NETCDF_DIR \${VISITHOME}/netcdf/$NETCDF_VERSION/\${VISITARCH})" \
            >> $HOSTCONF
            if [[ "$DO_HDF5" == "yes" ]] ; then
                echo \
                "VISIT_OPTION_DEFAULT(VISIT_NETCDF_LIBDEP HDF5_LIBRARY_DIR hdf5_hl HDF5_LIBRARY_DIR hdf5 \${VISIT_HDF5_LIBDEP} TYPE STRING)" \
                >> $HOSTCONF
            fi
        fi
    fi
}

function bv_netcdf_ensure
{
    if [[ "$DO_NETCDF" == "yes" && "$USE_SYSTEM_NETCDF" == "no" ]] ; then
        ensure_built_or_ready "netcdf" $NETCDF_VERSION $NETCDF_BUILD_DIR \
          $NETCDF_FILE \
          http://www.unidata.ucar.edu/downloads/netcdf/ftp/
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_NETCDF="no"
            error "Unable to build NetCDF.  ${NETCDF_FILE} not found."
        fi
    fi
}

function bv_netcdf_dry_run
{
  if [[ "$DO_NETCDF" == "yes" ]] ; then
    echo "Dry run option not set for netcdf."
  fi
}

function apply_netcdf_411_darwin_patch
{
   patch -p0 << \EOF
diff -c netcdf-4.1.1/ncgen3/genlib.h.orig netcdf-4.1.1/ncgen3/genlib.h
*** netcdf-4.1.1/ncgen3/genlib.h.orig	2014-11-13 17:16:23.000000000 -0800
--- netcdf-4.1.1/ncgen3/genlib.h	2014-11-13 16:27:08.000000000 -0800
***************
*** 81,87 ****
  
  /* In case we are missing strlcat */
  #ifndef HAVE_STRLCAT
! extern size_t strlcat(char *dst, const char *src, size_t siz);
  #endif
  
  #ifdef __cplusplus
--- 81,87 ----
  
  /* In case we are missing strlcat */
  #ifndef HAVE_STRLCAT
! /* extern size_t strlcat(char *dst, const char *src, size_t siz); */
  #endif
  
  #ifdef __cplusplus
EOF

   if [[ $? == 0 ]] ; then
      return 0;
   fi

   return 1;
}

function apply_netcdf_patch_for_exodusii
{
    local retval=0
    pushd $NETCDF_BUILD_DIR 1>/dev/null 2>&1
    patch -p0 << \EOF
*** libsrc/netcdf.h	Wed Oct 27 11:50:22 2010
--- libsrc/netcdf.h.ex	Wed Oct 27 11:50:31 2010
***************
*** 141,151 ****
   * applications and utilities.  However, nothing is statically allocated to
   * these sizes internally.
   */
! #define NC_MAX_DIMS	1024	 /* max dimensions per file */
! #define NC_MAX_ATTRS	8192	 /* max global or per variable attributes */
! #define NC_MAX_VARS	8192	 /* max variables per file */
! #define NC_MAX_NAME	256	 /* max length of a name */
! #define NC_MAX_VAR_DIMS	NC_MAX_DIMS /* max per variable dimensions */
  
  /*
   * The netcdf version 3 functions all return integer error status.
--- 141,152 ----
   * applications and utilities.  However, nothing is statically allocated to
   * these sizes internally.
   */
! #define NC_MAX_DIMS	65536	 /* max dimensions per file */
! #define NC_MAX_ATTRS	8192	 /* max global or per variable attributes */
! #define NC_MAX_VARS	524288	 /* max variables per file */
! #define NC_MAX_NAME	256	 /* max length of a name */
! #define NC_MAX_VAR_DIMS 8      /* max per variable dimensions */
! 
  
  /*
   * The netcdf version 3 functions all return integer error status.
EOF
    retval1=$?
    patch -p0 << \EOF
*** libsrc4/netcdf.h	2010-04-12 11:48:02.000000000 -0700
--- libsrc4/netcdf.h.ex	2011-01-03 15:51:46.000000000 -0800
***************
*** 199,209 ****
   * applications and utilities.  However, nothing is statically allocated to
   * these sizes internally.
   */
! #define NC_MAX_DIMS	1024	 /* max dimensions per file */
  #define NC_MAX_ATTRS	8192	 /* max global or per variable attributes */
! #define NC_MAX_VARS	8192	 /* max variables per file */
  #define NC_MAX_NAME	256	 /* max length of a name */
! #define NC_MAX_VAR_DIMS	NC_MAX_DIMS /* max per variable dimensions */
  
  /* In HDF5 files you can set the endianness of variables with
   * nc_def_var_endian(). These defines are used there. */   
--- 199,209 ----
   * applications and utilities.  However, nothing is statically allocated to
   * these sizes internally.
   */
! #define NC_MAX_DIMS	65536	 /* max dimensions per file */
  #define NC_MAX_ATTRS	8192	 /* max global or per variable attributes */
! #define NC_MAX_VARS	524288	 /* max variables per file */
  #define NC_MAX_NAME	256	 /* max length of a name */
! #define NC_MAX_VAR_DIMS	8        /* max per variable dimensions */
  
  /* In HDF5 files you can set the endianness of variables with
   * nc_def_var_endian(). These defines are used there. */   
EOF
    retval2=$?
    patch -p0 << \EOF
*** libsrc4/netcdf_base.h	2010-01-21 08:00:18.000000000 -0800
--- libsrc4/netcdf_base.h.ex	2011-01-03 16:03:36.000000000 -0800
***************
*** 192,202 ****
   * applications and utilities.  However, nothing is statically allocated to
   * these sizes internally.
   */
! #define NC_MAX_DIMS	1024	 /* max dimensions per file */
  #define NC_MAX_ATTRS	8192	 /* max global or per variable attributes */
! #define NC_MAX_VARS	8192	 /* max variables per file */
  #define NC_MAX_NAME	256	 /* max length of a name */
! #define NC_MAX_VAR_DIMS	NC_MAX_DIMS /* max per variable dimensions */
  
  /* In HDF5 files you can set the endianness of variables with
   * nc_def_var_endian(). These defines are used there. */   
--- 192,202 ----
   * applications and utilities.  However, nothing is statically allocated to
   * these sizes internally.
   */
! #define NC_MAX_DIMS	65536	 /* max dimensions per file */
  #define NC_MAX_ATTRS	8192	 /* max global or per variable attributes */
! #define NC_MAX_VARS	524288	 /* max variables per file */
  #define NC_MAX_NAME	256	 /* max length of a name */
! #define NC_MAX_VAR_DIMS	8        /* max per variable dimensions */
  
  /* In HDF5 files you can set the endianness of variables with
   * nc_def_var_endian(). These defines are used there. */   
EOF
    retval3=$?
    popd 1>/dev/null 2>&1
    if [[ $retval1 -eq 0 && $retval2 -eq 0 && $retval3 -eq 0 ]]; then
        return 0
    fi
    return 1
}

function apply_netcdf_patch
{
   apply_netcdf_patch_for_exodusii

   if [[ ${NETCDF_VERSION} == 4.1.1 ]] ; then
      if [[ "$OPSYS" == "Darwin" ]] ; then
         if [[ `sw_vers -productVersion` == 10.9.[0-9]* ]] ; then
            info "Applying OS X 10.9 Mavericks patch . . ."
            apply_netcdf_411_darwin_patch
         fi
      fi
   fi

   return $?
}

# *************************************************************************** #
#                         Function 8.4, build_netcdf                          #
#                                                                             #
# Mark C. Miller, Wed Oct 27 19:25:09 PDT 2010                                #
# Added patch for exodusII. This way, a single netcdf installation should     #
# work for 'normal' netcdf operations as well as for ExodusII.                #
#                                                                             #
# Kevin Griffin, Mon Nov 17 11:31:52 PST 2014                                 #
# Added patch for OS X 10.9 Mavericks. HAVE_STRLCAT is not getting defined    #
# in this version so its trying to add a duplicate strlcat definition. This   #
# patch comments out the duplicate strlcat definition.                        #
# *************************************************************************** #
function build_netcdf
{
    # Prepare build dir
    #
    prepare_build_dir $NETCDF_BUILD_DIR $NETCDF_FILE
    untarred_netcdf=$?
    if [[ $untarred_netcdf == -1 ]] ; then
       warn "Unable to prepare NetCDF Build Directory. Giving Up"
       return 1
    fi

    #
    # Apply patches
    #
    info "Patching NetCDF . . ."
    apply_netcdf_patch
    if [[ $? != 0 ]] ; then
       if [[ $untarred_netcdf == 1 ]] ; then
          warn "Giving up on NetCDF build because the patch failed."
          return 1
       else
          warn "Patch failed, but continuing.  I believe that this script\n" \
          warn "tried to apply a patch to an existing directory which had\n" \
          warn "already been patched ... that is, that the patch is\n" \
          warn "failing harmlessly on a second application."
       fi
    fi

    info "Configuring NetCDF . . ."
    cd $NETCDF_BUILD_DIR || error "Can't cd to netcdf build dir."
    info "Invoking command to configure NetCDF"
    if [[ "$OPSYS" == "Darwin" ]]; then
        if [[ "$DO_STATIC_BUILD" == "no" ]]; then
            EXTRA_FLAGS="--enable-largefile --enable-shared --disable-static"
        else
            EXTRA_FLAGS="--enable-largefile"
        fi
    else
        EXTRA_FLAGS=""
    fi
    H5ARGS=""
    if [[ "$DO_HDF5" == "yes" ]] ; then
        H5ARGS="--enable-netcdf4"
        H5ARGS="$H5ARGS --with-hdf5=$HDF5_INSTALL_DIR"
        if [[ "$DO_SZIP" == "yes" ]] ; then
            H5ARGS="$H5ARGS --with-szlib=$VISITDIR/szip/$SZIP_VERSION/$VISITARCH"
        fi
    fi
    ZLIBARGS=""
    if [[ "$DO_ZLIB" == "yes" ]] ; then
        ZLIBARGS="--with-zlib=$VISITDIR/zlib/$ZLIB_VERSION/$VISITARCH"
    fi

    info "./configure CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" \
        CFLAGS=\"$C_OPT_FLAGS\" CXXFLAGS=\"$CXX_OPT_FLAGS\" \
        FC=\"\" $EXTRA_FLAGS --enable-cxx-4 $H5ARGS $ZLIBARGS\
        --disable-dap \
        --prefix=\"$VISITDIR/netcdf/$NETCDF_VERSION/$VISITARCH\""

    ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" \
        CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
        FC="" $EXTRA_FLAGS --enable-cxx-4 $H5ARGS $ZLIBARGS\
        --disable-dap \
        --prefix="$VISITDIR/netcdf/$NETCDF_VERSION/$VISITARCH"

    if [[ $? != 0 ]] ; then
        warn "NetCDF configure failed.  Giving up"
        return 1
    fi

    #
    # Build NetCDF
    #
    info "Building NetCDF . . . (~2 minutes)"
    $MAKE
    if [[ $? != 0 ]] ; then
        warn "NetCDF build failed.  Giving up"
        return 1
    fi

    #
    # Install into the VisIt third party location.
    #
    info "Installing NetCDF . . ."
    $MAKE install
    if [[ $? != 0 ]] ; then
        warn "NetCDF install failed.  Giving up"
        return 1
    fi

    #
    # Patch up the library names on Darwin.
    #
    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
        info "Creating dynamic libraries for NetCDF . . ."
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/netcdf"
       chgrp -R ${GROUP} "$VISITDIR/netcdf"
    fi
    cd "$START_DIR"
    info "Done with NetCDF"
    return 0
}

function bv_netcdf_is_enabled
{
    if [[ $DO_NETCDF == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_netcdf_is_installed
{
    if [[ "$USE_SYSTEM_NETCDF" == "yes" ]]; then
        return 1
    fi

    check_if_installed "netcdf" $NETCDF_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_netcdf_build
{
cd "$START_DIR"
if [[ "$DO_NETCDF" == "yes" && "$USE_SYSTEM_NETCDF" == "no" ]] ; then
    check_if_installed "netcdf" $NETCDF_VERSION
   if [[ $? == 0 ]] ; then
        info "Skipping NetCDF build.  NetCDF is already installed."
   else
        info "Building NetCDF (~5 minutes)"
        build_netcdf
        if [[ $? != 0 ]] ; then
            error "Unable to build or install NetCDF.  Bailing out."
        fi
        info "Done building NetCDF"
   fi
fi
}
function bv_pyqt_initialize
{
export DO_PYQT="no"
export ON_PYQT="off"
export USE_SYSTEM_PYQT="no"
add_extra_commandline_args "pyqt" "alt-pyqt-dir" 1 "Use alternative directory for PyQt" 
}

function bv_pyqt_enable
{
DO_PYQT="yes"
ON_PYQT="on"
}

function bv_pyqt_disable
{
DO_PYQT="no"
ON_PYQT="off"
}

function bv_pyqt_alt_pyqt_dir
{
    bv_pyqt_enable
    USE_SYSTEM_PYQT="yes"
    PYQT_INSTALL_DIR="$1"
}

function bv_pyqt_depends_on
{
echo ""
}

function bv_pyqt_info
{
export PYQT_FILE=${PYQT_FILE:-"pyqt"}
export PYQT_VERSION=${PYQT_VERSION:-"0"}
export PYQT_COMPATIBILITY_VERSION=${PYQT_COMPATIBILITY_VERSION:-"0"}
export PYQT_BUILD_DIR=${PYQT_BUILD_DIR:-"pyqt"}
export PYQT_MD5_CHECKSUM=""
export PYQT_SHA256_CHECKSUM=""
}

function bv_pyqt_print
{
  printf "%s%s\n" "PYQT_FILE=" "${PYQT_FILE}"
  printf "%s%s\n" "PYQT_VERSION=" "${PYQT_VERSION}"
  printf "%s%s\n" "PYQT_COMPATIBILITY_VERSION=" "${PYQT_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "PYQT_BUILD_DIR=" "${PYQT_BUILD_DIR}"
}

function bv_pyqt_print_usage
{
printf "%-15s %s [%s]\n" "--alt-pyqt-dir"   "Use alternative pyqt dir" "$DO_PYQT"
}

function bv_pyqt_graphical
{
local graphical_out="PyQt    $PYQT_VERSION($PYQT_FILE)    $ON_PYQT"
echo $graphical_out
}

function bv_pyqt_host_profile
{
    if [[ "$DO_PYQT" == "yes"  && "$USE_SYSTEM_PYQT" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## PYQT" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        if [[ "$USE_SYSTEM_PYQT" == "yes" ]]; then
            echo "VISIT_OPTION_DEFAULT(HAVE_PYQT ON TYPE BOOL)" >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(VISIT_SIP_DIR $PYQT_INSTALL_DIR)" >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(VISIT_PYQT_DIR $PYQT_INSTALL_DIR)" >> $HOSTCONF
        fi
    fi
}

function bv_pyqt_ensure
{
    #if [[ "$DO_PYQT" == "yes" && "$USE_SYSTEM_PYQT" == "no" ]] ; then
    #    ensure_built_or_ready "pyqt" $PYQT_VERSION $PYQT_BUILD_DIR $PYQT_FILE
    #    if [[ $? != 0 ]] ; then
    #        ANY_ERRORS="yes"
    #        DO_PYQT="no"
    #        error "Unable to build PyQt.  ${PYQT_FILE} not found."
    #    fi
    #fi
    info "nothing to ensure for PyQt"
}

function bv_pyqt_dry_run
{
  if [[ "$DO_PYQT" == "yes" ]] ; then
    echo "Dry run option not set for PyQt."
  fi
}

# ***************************************************************************
#                         Function 8.22, build_PYQT
#
# Modifications:
#
# ***************************************************************************

function build_pyqt
{
    info "nothing to build for PyQt"
}

function bv_pyqt_is_enabled
{
    if [[ $DO_PYQT == "yes" && "$USE_SYSTEM_PYQT" == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_pyqt_is_installed
{
    if [[ "$USE_SYSTEM_PYQT" == "yes" ]]; then
        return 1
    fi

    #check_if_installed "pyqt" $PYQT_VERSION
    #if [[ $? == 0 ]] ; then
    #    return 1
    #fi
    return 0
}

function bv_pyqt_build
{
cd "$START_DIR"
if [[ "$DO_PYQT" == "yes" && "$USE_SYSTEM_PYQT" == "no" ]] ; then
    check_if_installed "pyqt" $PYQT_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping PyQt build.  PyQt is already installed."
    else
        info "Building PyQt (~20 minutes)"
        build_pyqt
        if [[ $? != 0 ]] ; then
            error "Unable to build or install PyQt.  Bailing out."
        fi
        info "Done building PyQt"
   fi
fi
}

function bv_pyside_initialize
{
if [[ "$DO_STATIC_BUILD" == "no" ]]; then
    export DO_PYSIDE="yes"
    export ON_PYSIDE="on"
    export USE_SYSTEM_PYSIDE="no"
    add_extra_commandline_args "pyside" "alt-pyside-dir" 1 "Use alternative directory for pyside"
else
    export DO_PYSIDE="no"
    export ON_PYSIDE="off"
    export USE_SYSTEM_PYSIDE="no"
fi
}

function bv_pyside_enable
{
DO_PYSIDE="yes"
ON_PYSIDE="on"
DO_QT="yes"
ON_QT="on"
}

function bv_pyside_disable
{
DO_PYSIDE="no"
ON_PYSIDE="off"
}

function bv_pyside_alt_pyside_dir
{
    bv_pyside_enable 
    USE_SYSTEM_PYSIDE="yes"
    PYSIDE_INSTALL_DIR="$1"
    info "using alternative pyside directory: $PYSIDE_INSTALL_DIR" 
}

function bv_pyside_depends_on
{
    if [[ "$USE_SYSTEM_PYSIDE" == "yes" ]]; then
        echo ""
    else
        echo "cmake python qt"
    fi
}

function bv_pyside_initialize_vars
{
    info "initialize Qt vars"
    if [[ $IS_QT5 == "yes" && $DO_PYSIDE == "yes" ]]; then
        error "PySide is not supported with Qt5, please disable"
    fi
}

function bv_pyside_info
{
export PYSIDE_VERSION=${PYSIDE_VERSION:-"1.2.2"}
export PYSIDE_FILE=${PYSIDE_FILE:-"pyside-combined-${PYSIDE_VERSION}.tar.gz"}
export PYSIDE_BUILD_DIR=${PYSIDE_BUILD_DIR:-"${PYSIDE_FILE%.tar*}"}
export PYSIDE_MD5_CHECKSUM="b33dde999cc4eb13933be43f49c1e890"
export PYSIDE_SHA256_CHECKSUM=""
}

function bv_pyside_print
{
  printf "%s%s\n" "PYSIDE_FILE=" "${PYSIDE_FILE}"
  printf "%s%s\n" "PYSIDE_VERSION=" "${PYSIDE_VERSION}"
  printf "%s%s\n" "PYSIDE_PLATFORM=" "${PYSIDE_PLATFORM}"
  printf "%s%s\n" "PYSIDE_BUILD_DIR=" "${PYSIDE_BUILD_DIR}"
}

function bv_pyside_print_usage
{
printf "%-15s %s [%s]\n" "--pyside" "Build PySide" "$DO_PYSIDE"
}

function bv_pyside_graphical
{
local graphical_out="PySide    $PYSIDE_VERSION($PYSIDE_FILE)     $ON_PYSIDE"
echo "$graphical_out"
}

function bv_pyside_host_profile
{
    if [[ "$DO_PYSIDE" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## PySide" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        if [[ "$USE_SYSTEM_PYSIDE" == "yes" ]]; then
            echo "VISIT_OPTION_DEFAULT(VISIT_PYSIDE_DIR $PYSIDE_INSTALL_DIR)" >> $HOSTCONF
        else
            echo "VISIT_OPTION_DEFAULT(VISIT_PYSIDE_DIR \${VISITHOME}/pyside/$PYSIDE_VERSION/\${VISITARCH}/)" >> $HOSTCONF
        fi
    fi
}

function bv_pyside_ensure
{
    if [[ "$DO_PYSIDE" = "yes" && "$DO_SERVER_COMPONENTS_ONLY" == "no" && "$USE_SYSTEM_PYSIDE" == "no" ]] ; then
        ensure_built_or_ready "pyside"     $PYSIDE_VERSION    $PYSIDE_BUILD_DIR    $PYSIDE_FILE 
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_PYSIDE="no"
            error "Unable to build PySide.  ${PYSIDE_FILE} not found."
        fi
    fi
}

function bv_pyside_dry_run
{
  if [[ "$DO_PYSIDE" == "yes" ]] ; then
    echo "Dry run option not set for pyside."
  fi
}

# *************************************************************************** #
#                          Function 4.2, build_pyside                          #
# *************************************************************************** #

function build_pyside_component
{
    VISIT_PYSIDE_DIR="${VISITDIR}/pyside/${PYSIDE_VERSION}/${VISITARCH}/"

    export PATH=${QT_BIN_DIR}:$PATH
    export PATH=$VISIT_PYSIDE_DIR/bin:$VISIT_PYTHON_DIR/bin:$PATH
    export PYTHONPATH=$VISIT_PYSIDE_DIR/lib/python${PYTHON_COMPATIBILITY_VERSION}/site-packages:$PYTHONPATH
    export PKG_CONFIG_PATH=$VISIT_PYSIDE_DIR/lib/pkgconfig:$PKG_CONFIG_PATH

    ALTERNATIVE_QT_INCLUDE_DIR="$QT_INCLUDE_DIR"
    
    # There is a bug on mac that using system qt
    # where headers say they are in /usr/include
    # when in reality most of the headers are in
    # /Library/Frameworks (except for QtUiTools)
    if [[ "Darwin" == `uname` && 
          "$QT_LIB_DIR" == "/Library/Frameworks" &&
          "$QT_INCLUDE_DIR" == "/usr/include" ]]; then
        ALTERNATIVE_QT_INCLUDE_DIR="$QT_LIB_DIR"
    fi

    cd $1
    #
    # Make sure to pass compilers and compiler flags to cmake
    #
    mkdir -p build
    cd build #PySide fails during in source build..
    info "Configuring pyside/$1 . . ."
    $CMAKE_COMMAND .. \
        -DCMAKE_C_COMPILER:STRING=${C_COMPILER} \
        -DCMAKE_CXX_COMPILER:STRING=${CXX_COMPILER} \
        -DCMAKE_C_FLAGS:STRING="${CFLAGS} ${C_OPT_FLAGS}" \
        -DCMAKE_CXX_FLAGS:STRING="${CXXFLAGS} ${CXX_OPT_FLAGS}" \
        -DCMAKE_INSTALL_PREFIX:FILEPATH="$VISIT_PYSIDE_DIR" \
        -DCMAKE_SKIP_BUILD_RPATH:BOOL=FALSE\
        -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=FALSE\
        -DCMAKE_INSTALL_RPATH:FILEPATH="$VISIT_PYSIDE_DIR/lib" \
        -DCMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL=TRUE\
        -DCMAKE_INSTALL_NAME_DIR:FILEPATH="$VISIT_PYSIDE_DIR/lib" \
        -DCMAKE_BUILD_TYPE:STRING="${VISIT_BUILD_MODE}" \
        -DALTERNATIVE_QT_INCLUDE_DIR:FILEPATH="$ALTERNATIVE_QT_INCLUDE_DIR" \
        -DQT_QMAKE_EXECUTABLE:FILEPATH="$QT_QMAKE_COMMAND" \
        -DENABLE_ICECC:BOOL=0 \
        -DShiboken_DIR:FILEPATH="$VISIT_PYSIDE_DIR/lib/"\
        -DPYTHON_EXECUTABLE:FILEPATH="$PYTHON_COMMAND"\
        -DPYTHON_INCLUDE_PATH:FILEPATH="$PYTHON_INCLUDE_DIR"\
        -DPYTHON_LIBRARY:FILEPATH="$PYTHON_LIBRARY"\
        -DDISABLE_DOCSTRINGS:BOOL=True

    if [[ $? != 0 ]] ; then
       warn "Cannot configure pyside/$1, giving up."
       return 1
    fi

    info "Building pyside/$1 . . ."
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "Cannot build pyside/$1, giving up."
       return 1
    fi

    info "Installing pyside/$1 . . ."
    $MAKE install
    touch "${VISIT_PYSIDE_DIR}/$1_success"
    info "Successfully built pyside/$1"
    cd ../../
}


function build_pyside
{
    ##
    ## Prepare the build dir using src file.
    ##

    prepare_build_dir $PYSIDE_BUILD_DIR $PYSIDE_FILE
    untarred_pyside=$?
    ## 0, already exists, 1  untarred src, 2 error

    if [[ untarred_pyside == -1 ]] ; then
       warn "Unable to prepare PySide build directory. Giving Up!"
       return 1
    fi

    cd $PYSIDE_BUILD_DIR || error "Can't cd to PySide build dir."


    build_pyside_component shiboken-${PYSIDE_VERSION}
    if [[ $? != 0 ]] ; then
       return 1
    fi

    build_pyside_component pyside-qt4.8+${PYSIDE_VERSION}
    if [[ $? != 0 ]] ; then
       return 1
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/pyside"
       chgrp -R ${GROUP} "$VISITDIR/pyside"
    fi

    cd "$START_DIR"

    info "Done with PySide"

    return 0
}

function bv_pyside_is_enabled
{
    if [[ "$DO_SERVER_COMPONENTS_ONLY" == "yes" ]]; then
        return 0;
    fi 
    if [[ $DO_PYSIDE == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_pyside_is_installed
{
    if [[ "$USE_SYSTEM_PYSIDE" == "yes" ]]; then 
        return 1
    fi

    VISIT_PYSIDE_DIR="${VISITDIR}/pyside/${PYSIDE_VERSION}/${VISITARCH}/"
    check_if_installed "pyside" $PYSIDE_VERSION
    if [[ $? != 0 ]] ; then
        return 0
    fi

    if  [[ ! -e "${VISIT_PYSIDE_DIR}/shiboken-${PYSIDE_VERSION}_success" ||
           ! -e "${VISIT_PYSIDE_DIR}/pyside-qt4.8+${PYSIDE_VERSION}_success" ]]; then
       info "pyside not installed completely"
       return 0
    fi

    return 1
}

function bv_pyside_build
{
#
# Build PySide
#
cd "$START_DIR"
if [[ "$DO_PYSIDE" == "yes" && "$DO_SERVER_COMPONENTS_ONLY" == "no" && "$USE_SYSTEM_PYSIDE" == "no" ]] ; then
    bv_pyside_is_installed #this returns 1 for true, 0 for false
    if [[ $? != 0 ]] ; then
        info "Skipping PySide build.  PySide is already installed."
   else
      info "Building PySide (~10 minutes)"
      build_pyside
      if [[ $? != 0 ]] ; then
         error "Unable to build or install PySide.  Bailing out."
      fi
      info "Done building PySide"
   fi
fi
}
function bv_python_initialize
{
export DO_PYTHON="yes"
export ON_PYTHON="on"
export FORCE_PYTHON="no"
export USE_SYSTEM_PYTHON="no"
export VISIT_PYTHON_DIR=${VISIT_PYTHON_DIR:-""}
add_extra_commandline_args "python" "system-python" 0 "Using system python"
add_extra_commandline_args "python" "alt-python-dir" 1 "Using alternate python directory"
}

function bv_python_enable
{
DO_PYTHON="yes"
ON_PYTHON="on"
FORCE_PYTHON="yes"
}

function bv_python_disable
{
DO_PYTHON="no"
ON_PYTHON="off"
FORCE_PYTHON="no"
}

function bv_python_force
{
  if [[ "$FORCE_PYTHON" == "yes" ]]; then
     return 0;
  fi
  return 1;
}

function python_set_vars_helper
{
  VISIT_PYTHON_DIR=`"$PYTHON_CONFIG_COMMAND" --prefix`
  PYTHON_BUILD_DIR=`"$PYTHON_CONFIG_COMMAND" --prefix`
  PYTHON_VER=`"$PYTHON_COMMAND" --version 2>&1`
  PYTHON_VERSION=${PYTHON_VER#"Python "}
  PYTHON_COMPATIBILITY_VERSION=${PYTHON_VERSION%.*}
  ########################
  PYTHON_INCLUDE_PATH=`"$PYTHON_CONFIG_COMMAND" --includes`
  #remove -I from first include
  PYTHON_INCLUDE_PATH="${PYTHON_INCLUDE_PATH:2}"
  #remove any extra includes
  PYTHON_INCLUDE_PATH="${PYTHON_INCLUDE_PATH%%-I*}"
  PYTHON_INCLUDE_DIR="$PYTHON_INCLUDE_PATH"
  PYTHON_LIBRARY=`"$PYTHON_CONFIG_COMMAND" --libs`
  #remove all other libraries except for python..
  PYTHON_LIBRARY=`echo $PYTHON_LIBRARY | sed "s/.*\(python[^ ]*\).*/\1/g"`

  if [[ "$DO_STATIC_BUILD" == "yes" ]]; then
       PYTHON_LIBRARY="lib${PYTHON_LIBRARY}.a"
  else
      if [[ "$OPSYS" == "Darwin" ]]; then
           PYTHON_LIBRARY="lib${PYTHON_LIBRARY}.dylib"
      else
           PYTHON_LIBRARY="lib${PYTHON_LIBRARY}.so"
      fi
  fi
  PYTHON_LIBRARY_DIR="${VISIT_PYTHON_DIR}/lib"
  if [ ! -e "${PYTHON_LIBRARY_DIR}/${PYTHON_LIBRARY}" ]
  then
      # some systems eg fedora use lib64...
      PYTHON_LIBRARY_DIR="${VISIT_PYTHON_DIR}/lib64"
      if [ ! -e "${PYTHON_LIBRARY_DIR}/${PYTHON_LIBRARY}" ]
      then
          error "python library was not found, cannot configure python"
      fi
  fi
  PYTHON_LIBRARY="${PYTHON_LIBRARY_DIR}/${PYTHON_LIBRARY}"
  echo $PYTHON_BUILD_DIR $PYTHON_VERSION $VISIT_PYTHON_DIR

}

function bv_python_system_python
{
  echo "Using system python"
   TEST=`which python-config`
   [ $? != 0 ] && error "System python-config not found, cannot configure python"

  bv_python_enable
  USE_SYSTEM_PYTHON="yes"
  PYTHON_COMMAND="python"
  PYTHON_CONFIG_COMMAND="python-config"
  PYTHON_FILE=""
  python_set_vars_helper #set vars..
}

function bv_python_alt_python_dir
{
  echo "Using alternate python directory"

  [ ! -e "$1/bin/python-config" ] && error "Python not found in $1"

  bv_python_enable
  USE_SYSTEM_PYTHON="yes"
  PYTHON_ALT_DIR="$1"
  PYTHON_COMMAND="$PYTHON_ALT_DIR/bin/python"
  PYTHON_CONFIG_COMMAND="$PYTHON_ALT_DIR/bin/python-config"
  PYTHON_FILE=""
  python_set_vars_helper #set vars..

}


function bv_python_depends_on
{
echo ""
}

function bv_python_info
{
export PYTHON_FILE_SUFFIX="tgz"
export PYTHON_VERSION=${PYTHON_VERSION:-"2.7.11"}
export PYTHON_COMPATIBILITY_VERSION=${PYTHON_COMPATIBILITY_VERSION:-"2.7"}
export PYTHON_FILE="Python-$PYTHON_VERSION.$PYTHON_FILE_SUFFIX"
export PYTHON_BUILD_DIR="Python-$PYTHON_VERSION"
export PYTHON_MD5_CHECKSUM="6b6076ec9e93f05dd63e47eb9c15728b"
export PYTHON_SHA256_CHECKSUM=""

export PIL_URL=${PIL_URL:-"http://effbot.org/media/downloads"}
export PIL_FILE=${PIL_FILE:-"Imaging-1.1.7.tar.gz"}
export PIL_BUILD_DIR=${PIL_BUILD_DIR:-"Imaging-1.1.7"}

export PYPARSING_FILE=${PYPARSING_FILE:-"pyparsing-1.5.2.tar.gz"}
export PYPARSING_BUILD_DIR=${PYPARSING_BUILD_DIR:-"pyparsing-1.5.2"}

export PYREQUESTS_FILE=${PYREQUESTS_FILE:-"requests-2.5.1.tar.gz"}
export PYREQUESTS_BUILD_DIR=${PYREQUESTS_BUILD_DIR:-"requests-2.5.1"}

export SEEDME_URL=${SEEDME_URL:-"https://seedme.org/sites/seedme.org/files/downloads/clients/"}
export SEEDME_FILE=${SEEDME_FILE:-"seedme-python-client-v1.1.0.zip"}
export SEEDME_BUILD_DIR=${SEEDME_BUILD_DIR:-"seedme-python-client-v1.1.0"}

}

function bv_python_print
{
  printf "%s%s\n" "PYTHON_FILE=" "${PYTHON_FILE}"
  printf "%s%s\n" "PYTHON_VERSION=" "${PYTHON_VERSION}"
  printf "%s%s\n" "PYTHON_COMPATIBILITY_VERSION=" "${PYTHON_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "PYTHON_BUILD_DIR=" "${PYTHON_BUILD_DIR}"
}

function bv_python_print_usage
{
printf "%-15s %s [%s]\n" "--python" "Build Python" "built by default unless --no-thirdparty flag is used"
printf "%-15s %s [%s]\n" "--system-python" "Use System Python" "Used unless --no-thirdparty flag is used"
}

function bv_python_host_profile
{
    if [[ "$DO_PYTHON" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## Python" >> $HOSTCONF
        echo "##" >> $HOSTCONF

        if [[ "$USE_SYSTEM_PYTHON" == "yes" ]]; then
            echo "VISIT_OPTION_DEFAULT(VISIT_PYTHON_DIR $VISIT_PYTHON_DIR)" >> $HOSTCONF
            #incase the PYTHON_DIR does not find the include and library set it manually...
            echo "VISIT_OPTION_DEFAULT(PYTHON_INCLUDE_PATH $PYTHON_INCLUDE_PATH)" >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(PYTHON_LIBRARY ${PYTHON_LIBRARY})" >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(PYTHON_LIBRARY_DIR $PYTHON_LIBRARY_DIR)" >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(PYTHON_VERSION $PYTHON_COMPATIBILITY_VERSION)" >> $HOSTCONF
            echo "SET(VISIT_PYTHON_SKIP_INSTALL ON)" >> $HOSTCONF
        else
            echo "VISIT_OPTION_DEFAULT(VISIT_PYTHON_DIR \${VISITHOME}/python/$PYTHON_VERSION/\${VISITARCH})" \
		>> $HOSTCONF
#           echo "VISIT_OPTION_DEFAULT(VISIT_PYTHON_DIR $VISIT_PYTHON_DIR)" >> $HOSTCONF
        fi
    fi
}

function bv_python_initialize_vars
{
    if [[ "$USE_SYSTEM_PYTHON" == "no" ]]; then
    
        #assign any default values that other libraries should be aware of
        #when they build..
        #this is for when python is being built and system python was not selected..
        export VISIT_PYTHON_DIR=${VISIT_PYTHON_DIR:-"$VISITDIR/python/${PYTHON_VERSION}/${VISITARCH}"}
        export PYTHON_COMMAND="${VISIT_PYTHON_DIR}/bin/python"
        export PYTHON_LIBRARY_DIR="${VISIT_PYTHON_DIR}/bin/python"
        export PYTHON_INCLUDE_DIR="${VISIT_PYTHON_DIR}/include/python${PYTHON_COMPATIBILITY_VERSION}"
        export PYTHON_LIBRARY="${VISIT_PYTHON_DIR}/lib/libpython${PYTHON_COMPATIBILITY_VERSION}.${SO_EXT}"
    fi
}

function bv_python_ensure
{
    if [[ "$USE_SYSTEM_PYTHON" == "no" ]]; then
        if [[ "$DO_DBIO_ONLY" != "yes" ]]; then
            if [[ "$DO_PYTHON" == "yes" || "$DO_VTK" == "yes" ]] ; then
                ensure_built_or_ready "python" $PYTHON_VERSION $PYTHON_BUILD_DIR $PYTHON_FILE
                if [[ $? != 0 ]] ; then
                    return 1
                fi
            fi
        fi
    fi
}

function bv_python_dry_run
{
  if [[ "$DO_PYTHON" == "yes" ]] ; then
    echo "Dry run option not set for python."
  fi
}

function apply_python_osx104_patch
{
   info "Patching Python: fix _environ issue for OS X 10.4"
   patch -f -p0 << \EOF
diff -c Modules.orig/posixmodule.c Modules/posixmodule.c
*** Modules.orig/posixmodule.c  Mon May  3 12:17:59 2010
--- Modules/posixmodule.c       Mon May  3 12:19:31 2010
***************
*** 360,365 ****
--- 360,369 ----
  #endif
  #endif
  
+ /* On OS X 10.4, we need to use a function to get access to environ; 
+  * otherwise we get an unresolved "_environ" when linking shared libs */
+ #define WITH_NEXT_FRAMEWORK
+ 
  /* Return a dictionary corresponding to the POSIX environment table */
  #ifdef WITH_NEXT_FRAMEWORK
  /* On Darwin/MacOSX a shared library or framework has no access to
EOF
   if [[ $? != 0 ]] ; then
      warn "Python patch on OS X 10.4 failed."
      return 1
   fi

   return 0
}

function apply_python_icc_patch
{
   info "Patching Python: fix ffi64 issue for icc"
   patch -f -p0 << \EOF
diff -c Modules/_ctypes/libffi/src/x86/ffi64.c.orig Modules/_ctypes/libffi/src/x86/ffi64.c
*** Modules/_ctypes/libffi/src/x86/ffi64.c.orig	2013-11-12 15:02:51.585653535 -0800
--- Modules/_ctypes/libffi/src/x86/ffi64.c	2013-11-12 15:20:47.000000000 -0800
***************
*** 39,44 ****
--- 39,45 ----
  #define MAX_SSE_REGS 8
  
  #if defined(__INTEL_COMPILER)
+ #include "xmmintrin.h"
  #define UINT128 __m128
  #else
  #if defined(__SUNPRO_C)
EOF
    if [[ $? != 0 ]] ; then
        warn "Python patch for icc fialed."
        return 1
    fi

    return 0
}

function apply_python_patch
{
    if [[ "$OPSYS" == "Darwin" ]]; then
        VER=$(uname -r)
        if [[ ${VER%%.*} == 8 ]] ; then
            apply_python_osx104_patch
            if [[ $? != 0 ]] ; then
                return 1
            fi
        fi
    fi
    if [[ "${C_COMPILER}" == "icc" ]]; then
        apply_python_icc_patch
        if [[ $? != 0 ]] ; then
            return 1
        fi
    fi

    return 0
}


# *************************************************************************** #
#                         Function 7, build_python                            #
# *************************************************************************** #

function build_python
{
    prepare_build_dir $PYTHON_BUILD_DIR $PYTHON_FILE
    untarred_python=$?
    if [[ $untarred_python == -1 ]] ; then
       warn "Unable to prepare Python build directory. Giving Up!"
       return 1
    fi

    #
    # Do any python patches if necessary
    #
    cd $PYTHON_BUILD_DIR || error "Can't cd to Python build dir."
    apply_python_patch
    if [[ $? != 0 ]] ; then
        warn "Patch failed, but continuing."
    fi

    #
    # Call configure
    #
    cCompiler="${C_COMPILER}"
    cFlags="${CFLAGS} ${C_OPT_FLAGS}"
    cxxCompiler="${CXX_COMPILER}"
    cxxFlags="{$CXXFLAGS} ${CXX_OPT_FLAGS}"
    if [[ "$OPSYS" == "Linux" && "$C_COMPILER" == "xlc" ]]; then
        cCompiler="gxlc"
        cxxCompiler="gxlC"
        cFlags=`echo ${CFLAGS} ${C_OPT_FLAGS} | sed "s/-qpic/-fPIC/g"`
        cxxFlags=`echo $CXXFLAGS} ${CXX_OPT_FLAGS} | sed "s/-qpic/-fPIC/g"`
    fi
    PYTHON_OPT="$cFlags"
    PYTHON_LDFLAGS=""
    PYTHON_PREFIX_DIR="$VISITDIR/python/$PYTHON_VERSION/$VISITARCH"
    if [[ "$DO_STATIC_BUILD" == "no" ]]; then
        PYTHON_SHARED="--enable-shared"
        if [[ "$C_COMPILER" == "gcc" ]]; then
            #
            # python's --enable-shared configure flag doesn't link
            # the exes it builds correclty when installed to a non standard
            # prefix. To resolve this we need to add a rpath linker flags.
            #
            mkdir -p ${PYTHON_PREFIX_DIR}/lib/
            if [[ $? != 0 ]] ; then
                 warn "Python configure failed.  Giving up"
            return 1
            fi

            if [[ "$OPSYS" != "Darwin" || ${VER%%.*} -ge 9 ]]; then
                PYTHON_LDFLAGS="-Wl,-rpath,${PYTHON_PREFIX_DIR}/lib/ -pthread"
            fi
        fi
    fi
    if [[ "$OPSYS" == "AIX" ]]; then
        info "Configuring Python (AIX): ./configure OPT=\"$PYTHON_OPT\" CXX=\"$cxxCompiler\" CC=\"$cCompiler\"" \
             "--prefix=\"$PYTHON_PREFIX_DIR\" --disable-ipv6"
        ./configure OPT="$PYTHON_OPT" CXX="$cxxCompiler" CC="$cCompiler" \
                --prefix="$PYTHON_PREFIX_DIR" --disable-ipv6
    else
        info "Configuring Python : ./configure OPT=\"$PYTHON_OPT\" CXX=\"$cxxCompiler\" CC=\"$cCompiler\"" \
             "LDFLAGS=\"$PYTHON_LDFLAGS\""\
             "${PYTHON_SHARED} --prefix=\"$PYTHON_PREFIX_DIR\" --disable-ipv6"
        ./configure OPT="$PYTHON_OPT" CXX="$cxxCompiler" CC="$cCompiler" LDFLAGS="$PYTHON_LDFLAGS" \
                  ${PYTHON_SHARED} \
                --prefix="$PYTHON_PREFIX_DIR" --disable-ipv6
    fi
    if [[ $? != 0 ]] ; then
       warn "Python configure failed.  Giving up"
       return 1
    fi

    #
    # Build Python.
    #
    info "Building Python . . . (~3 minutes)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "Python build failed.  Giving up"
       return 1
    fi
    info "Installing Python . . ."
    $MAKE install
    if [[ $? != 0 ]] ; then
       warn "Python build (make install) failed.  Giving up"
       return 1
    fi


    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "AIX" ]]; then
        # configure flag --enable-shared doesn't work on llnl aix5 systems
        # we need to create the shared lib manually and place it in the
        # proper loc
        mv $VISITDIR/python/$PYTHON_VERSION/$VISITARCH/lib/libpython$PYTHON_COMPATIBILITY_VERSION.$SO_EXT \
           $VISITDIR/python/$PYTHON_VERSION/$VISITARCH/lib/libpython$PYTHON_COMPATIBILITY_VERSION.static.a

        $C_COMPILER -qmkshrobj -lm \
             $VISITDIR/python/$PYTHON_VERSION/$VISITARCH/lib/libpython$PYTHON_COMPATIBILITY_VERSION.static.a \
          -o $VISITDIR/python/$PYTHON_VERSION/$VISITARCH/lib/libpython$PYTHON_COMPATIBILITY_VERSION.$SO_EXT

        if [[ $? != 0 ]] ; then
          warn "Python dynamic library build failed.  Giving up"
          return 1
        fi

        # we can safely remove this version of the static lib b/c it also exists under python2.6/config/
        rm -f $VISITDIR/python/$PYTHON_VERSION/$VISITARCH/lib/libpython$PYTHON_COMPATIBILITY_VERSION.static.a
    fi


    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/python"
       chgrp -R ${GROUP} "$VISITDIR/python"
    fi
    cd "$START_DIR"
    info "Done with Python"

    return 0
}


# *************************************************************************** #
# The PIL module's detection logic doesn't include /usr/lib64/                #
# On some systems zlib & libjpeg only exist in /usr/lib64, so we patch the    #
# module build script to add /usr/lib64.
# *************************************************************************** #
function apply_python_pil_patch
{
   info "Patching PIL: Add /usr/lib64/ to lib search path."
   patch -f -p0 << \EOF
diff -c Imaging-1.1.7.orig/setup.py  Imaging-1.1.7/setup.py
*** Imaging-1.1.7.orig/setup.py Wed Jan  6 11:39:52 2016
--- Imaging-1.1.7/setup.py      Wed Jan  6 11:41:13 2016
***************
*** 211,216 ****
--- 211,220 ----
          add_directory(library_dirs, "/usr/local/lib")
          add_directory(include_dirs, "/usr/local/include")

+         add_directory(library_dirs, "/usr/lib/x86_64-linux-gnu")
+         add_directory(library_dirs, "/usr/lib64")
+         add_directory(include_dirs, "/usr/include")
+
          add_directory(library_dirs, "/usr/lib")
          add_directory(include_dirs, "/usr/include")
EOF
   if [[ $? != 0 ]] ; then
      warn "Python PIL patch adding /usr/lib64/ to lib search path failed."
      return 1
   fi

   return 0
}

# *************************************************************************** #
#                            Function 7.1, build_pil                          #
# *************************************************************************** #
function build_pil
{
    if ! test -f ${PIL_FILE} ; then
        download_file ${PIL_FILE} \
            "${PIL_URL}"
        if [[ $? != 0 ]] ; then
            warn "Could not download ${PIL_FILE}"
            return 1
        fi
    fi
    if ! test -d ${PIL_BUILD_DIR} ; then
        info "Extracting PIL ..."
        uncompress_untar ${PIL_FILE}
        if test $? -ne 0 ; then
            warn "Could not extract ${PIL_FILE}"
            return 1
        fi
    fi

    # apply PIL patches
    apply_python_pil_patch
    if [[ $? != 0 ]] ; then
            warn "Patch failed, but continuing."
    fi

    # NOTE:
    # we need to compose both XFLAGS and X_OPT_FLAGS to get the correct
    # settings from build_visit command line opts
    # see:https://visitbugs.ornl.gov/issues/1443
    #

    PYEXT_CFLAGS="${CFLAGS} ${C_OPT_FLAGS}"
    PYEXT_CXXFLAGS="${CXXFLAGS} ${CXX_OPT_FLAGS}"

    PYHOME="${VISITDIR}/python/${PYTHON_VERSION}/${VISITARCH}"
    pushd $PIL_BUILD_DIR > /dev/null
        info "Building PIL ...\n" \
        "CC=${C_COMPILER} CXX=${CXX_COMPILER} CFLAGS=${PYEXT_CFLAGS} CXXFLAGS=${PYEXT_CXXFLAGS}" \
        "  ${PYHOME}/bin/python ./setup.py build "
        CC=${C_COMPILER} CXX=${CXX_COMPILER} CFLAGS=${PYEXT_CFLAGS} CXXFLAGS=${PYEXT_CXXFLAGS} \
            ${PYHOME}/bin/python ./setup.py build 
        info "Installing PIL ..."
        ${PYHOME}/bin/python ./setup.py install --prefix="${PYHOME}"
    popd > /dev/null

    # PIL installs into site-packages dir of Visit's Python.
    # Simply re-execute the python perms command.
    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/python"
       chgrp -R ${GROUP} "$VISITDIR/python"
    fi

    info "Done with PIL."
    return 0
}

# *************************************************************************** #
#                            Function 7.2, build_pyparsing                    #
# *************************************************************************** #
function build_pyparsing
{
    if ! test -f ${PYPARSING_FILE} ; then
        download_file ${PYPARSING_FILE}
        if [[ $? != 0 ]] ; then
            warn "Could not download ${PYPARSING_FILE}"
            return 1
        fi
    fi
    if ! test -d ${PYPARSING_BUILD_DIR} ; then
        info "Extracting pyparsing ..."
        uncompress_untar ${PYPARSING_FILE}
        if test $? -ne 0 ; then
            warn "Could not extract ${PYPARSING_FILE}"
            return 1
        fi
    fi

    PYHOME="${VISITDIR}/python/${PYTHON_VERSION}/${VISITARCH}"
    pushd $PYPARSING_BUILD_DIR > /dev/null
        info "Installing pyparsing ..."
        ${PYHOME}/bin/python ./setup.py install --prefix="${PYHOME}"
    popd > /dev/null

    # pyparsing installs into site-packages dir of Visit's Python.
    # Simply re-execute the python perms command.
    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/python"
       chgrp -R ${GROUP} "$VISITDIR/python"
    fi

    info "Done with pyparsing."
    return 0
}

# *************************************************************************** #
#                            Function 7.3, build_requests                     #
# *************************************************************************** #
function build_requests
{
    if ! test -f ${PYREQUESTS_FILE} ; then
        download_file ${PYREQUESTS_FILE}
        if [[ $? != 0 ]] ; then
            warn "Could not download ${PYREQUESTS_FILE}"
            return 1
        fi
    fi
    if ! test -d ${PYREQUESTS_BUILD_DIR} ; then
        info "Extracting python requests module ..."
        uncompress_untar ${PYREQUESTS_FILE}
        if test $? -ne 0 ; then
            warn "Could not extract ${PYREQUESTS_FILE}"
            return 1
        fi
    fi

    PYHOME="${VISITDIR}/python/${PYTHON_VERSION}/${VISITARCH}"
    pushd $PYREQUESTS_BUILD_DIR > /dev/null
        info "Installing python requests module ..."
        ${PYHOME}/bin/python ./setup.py install --prefix="${PYHOME}"
    popd > /dev/null

    # installs into site-packages dir of VisIt's Python.
    # Simply re-execute the python perms command.
    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/python"
       chgrp -R ${GROUP} "$VISITDIR/python"
    fi

    info "Done with python requests module."
    return 0
}

# *************************************************************************** #
#                            Function 7.4, build_seedme                       #
# *************************************************************************** #
function build_seedme
{
    if ! test -f ${SEEDME_FILE} ; then
        download_file ${SEEDME_FILE}
        if [[ $? != 0 ]] ; then
            warn "Could not download ${SEEDME_FILE}"
            return 1
        fi
    fi
    if ! test -d ${SEEDME_BUILD_DIR} ; then
        info "Extracting seedme python module ..."
        uncompress_untar ${SEEDME_FILE}
        if test $? -ne 0 ; then
            warn "Could not extract ${SEEDME_FILE}"
            return 1
        fi
    fi

    PYHOME="${VISITDIR}/python/${PYTHON_VERSION}/${VISITARCH}"
    pushd $SEEDME_BUILD_DIR > /dev/null
        info "Installing seedme python module ..."
        ${PYHOME}/bin/python ./setup.py install --prefix="${PYHOME}"
    popd > /dev/null

    # installs into site-packages dir of VisIt's Python.
    # Simply re-execute the python perms command.
    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/python"
       chgrp -R ${GROUP} "$VISITDIR/python"
    fi

    info "Done with seedme python module."
    return 0
}

function bv_python_is_enabled
{
    if [[ $DO_PYTHON == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_python_is_installed
{
    if [[ $USE_SYSTEM_PYTHON == "yes" ]]; then
        return 1
    fi
    check_if_installed "python" $PYTHON_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_python_build
{
#
# Build Python
#
cd "$START_DIR"
if [[ "$DO_PYTHON" == "yes" && "$USE_SYSTEM_PYTHON" == "no" ]] ; then
    check_if_installed "python" $PYTHON_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping Python build.  Python is already installed."
    else
        info "Building Python (~3 minutes)"
        build_python
        if [[ $? != 0 ]] ; then
            error "Unable to build or install Python.  Bailing out."
        fi
        info "Done building Python"

        info "Building the Python Imaging Library"
        build_pil
        if [[ $? != 0 ]] ; then
            warn "PIL build failed."
        fi
        info "Done building the Python Imaging Library"

        build_pyparsing
        if [[ $? != 0 ]] ; then
            warn "pyparsing build failed."
        fi
        info "Done building the pyparsing module."

        build_requests
        if [[ $? != 0 ]] ; then
            warn "requests python module build failed."
        fi
        info "Done building the requests python module."

        build_seedme
        if [[ $? != 0 ]] ; then
            warn "seedme python module build failed."
        fi
        info "Done building the seedme python module."

    fi
fi
}

function bv_qt_initialize
{
    export DO_QT="yes"
    export ON_QT="on"
    export FORCE_QT="no"
    export USE_SYSTEM_QT="no"
    export IS_QT5="no"
    add_extra_commandline_args "qt" "qt5" 0 "Use qt found on system"
    add_extra_commandline_args "qt" "system-qt" 0 "Use qt found on system"
    add_extra_commandline_args "qt" "alt-qt-dir" 1 "Use qt found in alternative directory"
}

function bv_qt_enable
{
DO_QT="yes"
ON_QT="on"
FORCE_QT="yes"
}

function bv_qt_disable
{
DO_QT="no"
ON_QT="off"
FORCE_QT="no"
}

function bv_qt_force
{
  if [[ "$FORCE_QT" == "yes" ]]; then
     return 0;
  fi
  return 1;
}

function qt_set_vars_helper
{
    QT_VERSION=`$QT_QMAKE_COMMAND -query QT_VERSION`
    QT_INSTALL_DIR=`$QT_QMAKE_COMMAND -query QT_INSTALL_PREFIX`
    QT_BIN_DIR=`$QT_QMAKE_COMMAND -query QT_INSTALL_BINS`
    QT_INCLUDE_DIR=`$QT_QMAKE_COMMAND -query QT_INSTALL_HEADERS`
    QT_LIB_DIR=`"$QT_QMAKE_COMMAND" -query QT_INSTALL_LIBS`
    QT_QTUITOOLS_INCLUDE_DIR="$QT_INCLUDE_DIR/QtUiTools"

    IS_QT5="no"
    if [[ "${QT_VERSION%%.*}" == "5" ]]; then
        IS_QT5="yes"
    fi 
}
function bv_qt_system_qt
{
   echo "using system qt"

   QTEXEC="qmake"
   TEST=`which $QTEXEC`
   if [[ $? != 0 ]]; then
     QTEXEC="qmake-qt4"
     TEST=`which $QTEXEC`
     [ $? != 0 ] && error "System Qt not found"
   fi

   bv_qt_enable

   USE_SYSTEM_QT="yes"
   QT_QMAKE_COMMAND="$QTEXEC"
   qt_set_vars_helper #set vars..
   QT_FILE=""
}

function bv_qt_alt_qt_dir
{
    info "using qt from alternative directory $1"

   QTEXEC="qmake"
   if [[ ! -e "$1/bin/$QTEXEC" ]]; then
     QTEXEC="qmake-qt4"
     [ ! -e "$1/bin/$QTEXEC" ] && error "qmake was not found in directory: $1/bin"
   fi

    bv_qt_enable
    USE_SYSTEM_QT="yes"

    QT_ALT_DIR="$1"
    QT_QMAKE_COMMAND="$QT_ALT_DIR/bin/$QTEXEC"
    qt_set_vars_helper #set vars..
    QT_FILE=""
}

function bv_qt_qt5
{
    info "enabling Qt5.."
    bv_qt_enable

    QT_VERSION="5.2.1"
    QT_FILE="qt-everywhere-opensource-src-${QT_VERSION}.tar.gz"
    QT_BUILD_DIR="${QT_FILE%.tar*}"
    QT_BIN_DIR="${QT_BUILD_DIR}/bin"
    QT_MD5_CHECKSUM=""
    QT_SHA256_CHECKSUM=""
    IS_QT5="yes"
    bv_pyside_disable
}

function bv_qt_initialize_vars
{
    info "initalizing qt vars"
    if [[ $USE_SYSTEM_QT != "yes" ]]; then
      QT_INSTALL_DIR="${VISITDIR}/qt/${QT_VERSION}/${VISITARCH}"
      QT_QMAKE_COMMAND="${QT_INSTALL_DIR}/bin/qmake"
      if [[ -e "$QT_QMAKE_COMMAND" ]]; then
        QT_BIN_DIR=`$QT_QMAKE_COMMAND -query QT_INSTALL_BINS`
        QT_INCLUDE_DIR=`$QT_QMAKE_COMMAND -query QT_INSTALL_HEADERS`
        QT_LIB_DIR=`"$QT_QMAKE_COMMAND" -query QT_INSTALL_LIBS`
      else
        QT_BIN_DIR="$QT_INSTALL_DIR/bin"
        QT_INCLUDE_DIR="$QT_INSTALL_DIR/include"
        QT_LIB_DIR="$QT_INSTALL_DIR/lib"
      fi
      QT_QTUITOOLS_INCLUDE_DIR="$QT_INCLUDE_DIR/QtUiTools"
    fi
}

function bv_qt_depends_on
{
    echo ""
}

function bv_qt_info
{
# if we are on osx 10.8 or later, we need to use 4.8.6   
    if [[ "$OPSYS" == "Darwin" ]]; then
        if [[ "${MACOSX_DEPLOYMENT_TARGET}" == "10.8" ||
              "${MACOSX_DEPLOYMENT_TARGET}" == "10.9" ]]; then
            export QT_FILE=${QT_FILE:-"qt-everywhere-opensource-src-4.8.6.tar.gz"}
            export QT_VERSION=${QT_VERSION:-"4.8.6"}
            export QT_MD5_CHECKSUM="2edbe4d6c2eff33ef91732602f3518eb"
        fi
    fi
        
export QT_FILE=${QT_FILE:-"qt-everywhere-opensource-src-4.8.3.tar.gz"}
export QT_VERSION=${QT_VERSION:-"4.8.3"}
export QT_MD5_CHECKSUM=${QT_MD5_CHECKSUM:-"a663b6c875f8d7caa8ac9c30e4a4ec3b"}
export QT_BUILD_DIR=${QT_BUILD_DIR:-"${QT_FILE%.tar*}"}
export QT_BIN_DIR="${QT_BUILD_DIR}/bin"
export QT_SHA256_CHECKSUM=""
}

function bv_qt_print
{
  printf "%s%s\n" "QT_FILE=" "${QT_FILE}"
  printf "%s%s\n" "QT_VERSION=" "${QT_VERSION}"
  printf "%s%s\n" "QT_PLATFORM=" "${QT_PLATFORM}"
  printf "%s%s\n" "QT_BUILD_DIR=" "${QT_BUILD_DIR}"
  printf "%s%s\n" "QT_BIN_DIR=" "${QT_BIN_DIR}"
}

function bv_qt_print_usage
{
printf "%-15s %s [%s]\n" "--qt" "Build Qt" "built by default unless --no-thirdparty flag is used"
printf "%-15s %s [%s]\n" "--qt5" "Build Qt5" "built by default unless --no-thirdparty flag is used"
printf "%-15s %s [%s]\n" "--system-qt" "Use System Qt" "Used by default unless --no-thirdparty flag is used"
printf "%-15s %s [%s]\n" "--alt-qt-dir" "Use Qt from alternative directory" "Used by default unless --no-thirdparty flag is used"
}

function bv_qt_host_profile
{
if [[ "$DO_DBIO_ONLY" != "yes" ]]; then
    if [[ "$DO_ENGINE_ONLY" != "yes" ]]; then
        if [[ "$DO_SERVER_COMPONENTS_ONLY" != "yes" ]]; then 
            echo >> $HOSTCONF
            echo "##" >> $HOSTCONF
            echo "## Qt" >> $HOSTCONF
            echo "##" >> $HOSTCONF
            if [[ "$IS_QT5" == "yes" ]]; then
                echo "VISIT_OPTION_DEFAULT(VISIT_QT5 ON TYPE BOOL)" >> $HOSTCONF
                echo "VISIT_OPTION_DEFAULT(VISIT_QT_DIR ${QT_INSTALL_DIR})" >> $HOSTCONF
                echo "VISIT_OPTION_DEFAULT(VISIT_QT_BIN ${QT_BIN_DIR})" >> $HOSTCONF
            else 
                if [[ $USE_SYSTEM_QT == "yes" ]]; then
                    echo "VISIT_OPTION_DEFAULT(QT_QTUITOOLS_INCLUDE_DIR ${QT_QTUITOOLS_INCLUDE_DIR})" >> $HOSTCONF
                    echo "VISIT_OPTION_DEFAULT(VISIT_QT_BIN ${QT_BIN_DIR})" >> $HOSTCONF
                    echo "SET(VISIT_QT_SKIP_INSTALL ON)" >> $HOSTCONF
                else
                    echo "VISIT_OPTION_DEFAULT(VISIT_QT_BIN \${VISITHOME}/qt/$QT_VERSION/\${VISITARCH}/bin)" >> $HOSTCONF
                fi
            fi
        fi
    fi
fi    
}

function bv_qt_ensure
{
    if [[ "$DO_QT" == "yes"  && "$USE_SYSTEM_QT" == "no" && "$DO_SERVER_COMPONENTS_ONLY" == "no" ]] ; then
        ensure_built_or_ready "qt"     $QT_VERSION    $QT_BUILD_DIR    $QT_FILE
        if [[ $? != 0 ]] ; then
            return 1
        fi
    fi
}

function bv_qt_dry_run
{
  if [[ "$DO_QT" == "yes" ]] ; then
    echo "Dry run option not set for qt."
  fi
}

# *************************************************************************** #
#                          Function 4, build_qt                               #
# *************************************************************************** #

function qt_license_prompt
{


QT_LIC_MSG="During the build process this script will build Qt and confirm\
            that you accept Trolltech's license for the Qt Open Source\
            Edition. Please respond \"yes\" to accept (in advance) either\
            the Lesser GNU General Public License (LGPL) version 2.1 or \
            the GNU General Public License (GPL) version 3. Visit \
            http://www.qt.io/qt-licensing-terms to view these licenses."

QT_CONFIRM_MSG="VisIt requires Qt: Please respond with \"yes\" to accept\
                Qt licensing under the terms of the Lesser GNU General \
                Public License (LGPL) version 2.1 or \
                the GNU General Public License (GPL) version 3"
if [[ "$GRAPHICAL" == "yes" ]] ; then
    if [[ "$REDIRECT_ACTIVE" == "yes" ]] ; then
        $DLG --backtitle "$DLG_BACKTITLE" --yesno "$QT_LIC_MSG" 0 0 1>&3
    else
        $DLG --backtitle "$DLG_BACKTITLE" --yesno "$QT_LIC_MSG" 0 0 
    fi
    if [[ $? == 1 ]] ; then
        if [[ "$REDIRECT_ACTIVE" == "yes" ]] ; then
            $DLG --backtitle "$DLG_BACKTITLE" --yesno "$QT_CONFIRM_MSG" 0 0 1>&3
        else
            $DLG --backtitle "$DLG_BACKTITLE" --yesno "$QT_CONFIRM_MSG" 0 0 
        fi
        if [[ $? == 1 ]] ; then
            return 1
        fi
    fi
else
    info $QT_LIC_MSG
    read RESPONSE
    if [[ "$RESPONSE" != "yes" ]] ; then
        info $QT_CONFIRM_MSG
        read RESPONSE
        if [[ $RESPONSE != "yes" ]] ; then
            return 1
        fi
    fi
fi

return 0
}


function apply_qt_patch
{
   return 0
}

function build_qt
{
    #
    # Prepare the build dir using src file.
    #

    prepare_build_dir $QT_BUILD_DIR $QT_FILE
    untarred_qt=$?
    # 0, already exists, 1  untarred src, 2 error

    if [[ untarred_qt == -1 ]] ; then
       warn "Unable to prepare Qt build directory. Giving Up!"
       return 1
    fi

    #
    # Apply patches
    #
    info "Patching qt . . ."
    apply_qt_patch
    if [[ $? != 0 ]] ; then
       if [[ $untarred_qt == 1 ]] ; then
          warn "Giving up on Qt build because the patch failed."
          return 1
       else
          warn "Patch failed, but continuing.  I believe that this script\n" \
               "tried to apply a patch to an existing directory which had " \
               "already been patched ... that is, that the patch is " \
               "failing harmlessly on a second application."
       fi
    fi

    cd $QT_BUILD_DIR || error "Can't cd to Qt build dir."

    #
    # Platform specific configuration
    #
    if [[ "$OPSYS" == "Darwin" ]] ; then
        # Determine if we build with Cocoa
        VER=$(uname -r)
        if [[ ${VER%%.*} -ge 10 ]] ; then
            EXTRA_QT_FLAGS="$EXTRA_QT_FLAGS -cocoa"
        fi

        QT_PLATFORM=${QT_PLATFORM:-"macx-g++"}
        # webkit causes the linker on Hank's mac to run out of memory
        # Hari: for Qt5 I have disabled webkit all together
        if [[ "$IS_QT5" == "no" ]]; then
            EXTRA_QT_FLAGS="$EXTRA_QT_FLAGS -no-webkit -no-phonon -no-phonon-backend"
        fi
        # Figure out whether we need to build 64-bit version of Qt
        echo "int main() {}" >> arch_test.c
        ${C_COMPILER} arch_test.c -o arch_test
        GCC_BUILD_ARCH=$(lipo -info arch_test | sed -e 's/[^x]*//')
        rm arch_test.c arch_test
        if [[ "$GCC_BUILD_ARCH" == "x86_64" ]] ; then
            EXTRA_QT_FLAGS="$EXTRA_QT_FLAGS -arch x86_64"
        fi

    elif [[ "$OPSYS" == "Linux" ]] ; then
        # w/ Qt 4.8.3, these guys will on fail on linux
        # if gstreamer isn't installed ...
        EXTRA_QT_FLAGS="$EXTRA_QT_FLAGS -no-webkit -no-phonon -no-phonon-backend"
        # For OLD versions of linux, disable openssl
        VER=$(uname -r)
        if [[ "${VER:0:3}" == "2.4" ]] ; then
            EXTRA_QT_FLAGS="$EXTRA_QT_FLAGS -no-openssl"
        fi

        #
        # select the proper value for QT_PLATFORM 
        #
        # Most of the logic for QT_PLATFORM on various os flavors
        # is still in bv_main.sh, and should be detangled and placed here.
        #
        # For now add support for icc on linux.
        #

        # enable icc qt build on linux
        #
        # Question: could qt auto detect this via the CC and CXX env vars?
        #
        # For osx, and linux - we may also need clang support in the future.
        # We should try to see if we can avoid setting the platform, set
        # CC and CXX and see if that is enough to trigger qt's detection logic.
        #
        #
        if [[ "$(uname -m)" == "x86_64" ]] ; then
            if [[ "$C_COMPILER" == "icc" || "$CXX_COMPILER" == "icpc" ]]; then
                QT_PLATFORM="linux-icc-64"
            else
                QT_PLATFORM="linux-g++-64"
            fi
        else
          if [[ "$C_COMPILER" == "icc" || "$CXX_COMPILER" == "icpc" ]]; then
                QT_PLATFORM="linux-icc"
            else
                QT_PLATFORM="linux-g++"
            fi
        fi
    fi

    # We may be building statically.
    if [[ "$DO_STATIC_BUILD" == "yes" ]]; then
        # Protect the build by NOT using the system versions of the I/O libraries.
        EXTRA_QT_FLAGS="$EXTRA_QT_FLAGS -static -qt-libtiff -qt-libpng -qt-libmng -qt-libjpeg"
    fi

    #
    # Call configure
    #


    QT_CFLAGS="${CFLAGS} ${C_OPT_FLAGS}"
    QT_CXXFLAGS="${CXXFLAGS} ${CXX_OPT_FLAGS}"

    qt_flags=""
    qt_flags="${qt_flags} -no-dbus"
    qt_flags="${qt_flags} -no-sql-db2 -no-sql-ibase -no-sql-mysql -no-sql-oci"
    qt_flags="${qt_flags} -no-sql-odbc -no-sql-psql -no-sql-sqlite"
    qt_flags="${qt_flags} -no-sql-sqlite2 -no-sql-tds"
    qt_flags="${qt_flags} -no-libjpeg"
    qt_flags="${qt_flags} -opensource"
    qt_flags="${qt_flags} -confirm-license"

    QT_VER_MSG="Qt4"
    if [[ $IS_QT5 == "yes" ]]; then
        QT_VER_MSG="Qt5"
        qt_flags="${qt_flags} -skip webkit -skip webkit-examples"
        qt_flags="${qt_flags} -skip sensors"
        qt_flags="${qt_flags} -skip doc"
        qt_flags="${qt_flags} -skip serialport"
        qt_flags="${qt_flags} -skip quick1"
        qt_flags="${qt_flags} -skip quickcontrols"
        qt_flags="${qt_flags} -skip connectivity"
        qt_flags="${qt_flags} -nomake examples"
        qt_flags="${qt_flags} -nomake tests"
        qt_flags="${qt_flags} -no-qml-debug"
        qt_flags="${qt_flags} -no-javascript-jit"
        if [[ "$OPSYS" == "Linux" ]] ; then
            qt_flags="${qt_flags} -qt-xcb -qt-xkbcommon"
        fi
    else
        qt_flags="${qt_flags} -fast -no-libtiff -no-qt3support -nomake docs -nomake demos"
        qt_flags="${qt_flags} -nomake examples"
        qt_flags="${qt_flags} ${EXTRA_QT_FLAGS}"
    fi
    info "Configuring ${QT_VER_MSG}: CFLAGS=${QT_CFLAGS} CXXFLAGS=${QT_CXXFLAGS}" \
         "./configure --prefix=${QT_INSTALL_DIR}" \
         "-platform ${QT_PLATFORM}" \
         "-make libs -make tools -no-separate-debug-info" \
         "${qt_flags}" 

   (echo "o"; echo "yes") | CFLAGS="${QT_CFLAGS}" CXXFLAGS="${QT_CXXFLAGS}"  \
           ./configure --prefix=${QT_INSTALL_DIR} \
                    -platform ${QT_PLATFORM} \
                    -make libs -make tools -no-separate-debug-info \
                    ${qt_flags} | tee qt.config.out
    if [[ $? != 0 ]] ; then
       warn "${QT_VER_MSG} configure failed. Giving up."
       return 1
    fi

    #
    # Figure out if configure found the OpenGL libraries
    #
    if [[ "${DO_DBIO_ONLY}" != "yes" && "${DO_ENGINE_ONLY}" != "yes" && "${DO_SERVER_COMPONENTS_ONLY}" != "yes" ]] ; then
       HAS_OPENGL_SUPPORT=`grep "OpenGL support" qt.config.out | sed -e 's/.*\. //'  | cut -c 1-3`
       if [[ "$IS_QT5" == "no" && "$HAS_OPENGL_SUPPORT" != "yes" ]]; then
          warn "Qt4 configure did not find OpenGL." \
                "VisIt needs Qt4 with enabled OpenGL support. Giving up.\n" \
                "Here are some common reasons why Qt will not build with GL support.\n" \
                "\t- The OpenGL development environment is not installed.\n" \
                "\t  (You can check this by searching for /usr/include/GL/GL.h)\n" \
                "\t- libGLU is not available\n"\
                "\t- libGLU is available, but only as a shared library\n"\
                "You can learn more about exactly why Qt failed by doing the following:\n"\
                "\t- cd $QT_BUILD_DIR\n" \
                "\t- ./configure -opengl -verbose\n" \
                "\t  (this will produce the details of the failed OpenGL tests.)\n" \
                "\t  (also note you will need to respond with \"o\" to opt for\n" \
                "\t   the open source license and \"yes\" to accept.)\n"
          return 1
       fi
    fi

    #
    # Build Qt4. Config options above make sure we only build the libs & tools.
    #
    info "Building ${QT_VER_MSG} . . . (~60 minutes)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "${QT_VER_MSG} build failed.  Giving up"
       return 1
    fi

    info "Installing ${QT_VER_MSG} . . . "
    $MAKE install

    # Qt screws up permissions in some cases.  Try to fix that.
    chmod -R a+rX ${VISITDIR}/qt/${QT_VERSION}

    #
    # Visit expects .so suffix on qt libs but xlc uses .a suffixe even 
    # for shared libs (however subversioned qts libs end up with a .so suffix)
    #
    # Fix this by creating .so simlinks to the .a versions
    #

    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "AIX" ]]; then
        cd ${VISITDIR}/qt/${QT_VERSION}/${VISITARCH}/lib/
        for f in *.a; do ln -s $f ${f%\.*}.so; done

    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/qt"
       chgrp -R ${GROUP} "$VISITDIR/qt"
    fi

    cd "$START_DIR"
    info "Done with ${QT_VER_MSG}"

    return 0
}

function bv_qt_is_enabled
{
    if [[ "$DO_SERVER_COMPONENTS_ONLY" == "yes" ]]; then
        return 0
    fi 
    if [[ $DO_QT == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_qt_is_installed
{
    if [[ "$USE_SYSTEM_QT" == "yes" ]]; then
        return 1    
    fi

    check_if_installed "qt" $QT_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_qt_build
{
#
# Build Qt
#
cd "$START_DIR"
if [[ "$DO_QT" == "yes"  && "$USE_SYSTEM_QT" == "no" && "$DO_SERVER_COMPONENTS_ONLY" == "no" ]] ; then
        check_if_installed "qt" $QT_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping Qt build.  Qt4 is already installed."
   else
      info "Building Qt (~60 minutes)"
      build_qt
      if [[ $? != 0 ]] ; then
         error "Unable to build or install Qt.  Bailing out."
      fi
      info "Done building Qt"
   fi
fi
}

function bv_silo_initialize
{
    export DO_SILO="no"
    export ON_SILO="off"
    export DO_SILEX="no"
    add_extra_commandline_args "silo" "silex" 0 "Enable silex when building Silo"
}

function bv_silo_enable
{
    DO_SILO="yes"
    ON_SILO="on"
}

function bv_silo_disable
{
    DO_SILO="no"
    ON_SILO="off"
}

function bv_silo_silex
{
    info "Enabling silex in Silo build"
    DO_SILEX="yes"
    bv_silo_enable
}

function bv_silo_depends_on
{
    local depends_on=""

    if [[ "$DO_HDF5" == "yes" ]] ; then
        depends_on="hdf5"    
    fi
    
    if [[ "$DO_SZIP" == "yes" ]] ; then
        depends_on="$depends_on szip"    
    fi

    if [[ "$DO_ZLIB" == "yes" ]] ; then
        depends_on="$depends_on zlib"    
    fi

    echo $depends_on
}

function bv_silo_info
{
export SILO_VERSION=${SILO_VERSION:-"4.10.1"}
export SILO_FILE=${SILO_FILE:-"silo-${SILO_VERSION}.tar.gz"}
export SILO_COMPATIBILITY_VERSION=${SILO_COMPATIBILITY_VERSION:-"4.10.1"}
export SILO_BUILD_DIR=${SILO_BUILD_DIR:-"silo-${SILO_VERSION}"}
export SILO_URL=${SILO_URL:-https://wci.llnl.gov/codes/silo/silo-${SILO_VERSION}}
export SILO_MD5_CHECKSUM="29e6cdf25e98aef96e1f541167839c6f"
export SILO_SHA256_CHECKSUM="8549167d1315ab27d3752ee463c45a6919d68a3bdad4acc8389a1d5f73071028"
}

function bv_silo_print
{
  printf "%s%s\n" "SILO_FILE=" "${SILO_FILE}"
  printf "%s%s\n" "SILO_VERSION=" "${SILO_VERSION}"
  printf "%s%s\n" "SILO_COMPATIBILITY_VERSION=" "${SILO_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "SILO_BUILD_DIR=" "${SILO_BUILD_DIR}"
}

function bv_silo_print_usage
{
printf "%-15s %s [%s]\n" "--silo" "Build Silo support" "$DO_SILO"
printf "%-15s %s [%s]\n" "--silex" "Enable silex when building Silo" "$DO_SILEX"
}

function bv_silo_graphical
{
local graphical_out="Silo     $SILO_VERSION($SILO_FILE)      $ON_SILO"
echo "$graphical_out"
}

function bv_silo_host_profile
{
    if [[ "$DO_SILO" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## Silo" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_SILO_DIR \${VISITHOME}/silo/$SILO_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
        if [[ "$DO_HDF5" == "yes" ]] ; then
            echo \
            "VISIT_OPTION_DEFAULT(VISIT_SILO_LIBDEP HDF5_LIBRARY_DIR hdf5 \${VISIT_HDF5_LIBDEP} TYPE STRING)" \
            >> $HOSTCONF
        else
            if [[ "$DO_ZLIB" == "yes" ]] ; then
               echo \
               "VISIT_OPTION_DEFAULT(VISIT_SILO_LIBDEP ZLIB_LIBRARY_DIR z TYPE STRING)" \
               >> $HOSTCONF
            else
               if [[ -d /usr/lib/x86_64-linux-gnu ]]; then
                    echo \
                    "VISIT_OPTION_DEFAULT(VISIT_SILO_LIBDEP /usr/lib/x86_64-linux-gnu z TYPE STRING)" \
                    >> $HOSTCONF
               else
                    echo \
                    "VISIT_OPTION_DEFAULT(VISIT_SILO_LIBDEP /usr/lib z TYPE STRING)" \
                    >> $HOSTCONF
               fi
            fi
        fi
    fi
}

function bv_silo_ensure
{
    if [[ "$DO_SILO" == "yes" ]] ; then
        ensure_built_or_ready "silo" $SILO_VERSION $SILO_BUILD_DIR $SILO_FILE $SILO_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_SILO="no"
            error "Unable to build Silo.  ${SILO_FILE} not found."
        fi
    fi
}

function bv_silo_dry_run
{
  if [[ "$DO_SILO" == "yes" ]] ; then
    echo "Dry run option not set for silo."
  fi
}

# *************************************************************************** #
#                            Function 8, build_silo
#
# Modfications:
#   Mark C. Miller, Wed Feb 18 22:57:25 PST 2009
#   Added logic to build silex and copy bins on Mac. Removed disablement of
#   browser.
#
#   Mark C. Miller Mon Jan  7 10:31:46 PST 2013
#   PDB/SCORE lite headers are now handled in Silo and require additional
#   configure option to ensure they are installed.
#
#   Brad Whitlock, Tue Apr  9 12:20:22 PDT 2013
#   Add support for custom zlib.
#
#   Kathleen Biagas, Tue Jun 10 08:21:33 MST 2014
#   Disable silex for static builds.
#
# *************************************************************************** #

function build_silo
{
    #
    # Prepare build dir
    #
    prepare_build_dir $SILO_BUILD_DIR $SILO_FILE
    untarred_silo=$?
    if [[ $untarred_silo == -1 ]] ; then
       warn "Unable to prepare Silo build directory. Giving Up!"
       return 1
    fi
    
    #
    # Call configure
    #
    info "Configuring Silo . . ."
    cd $SILO_BUILD_DIR || error "Can't cd to Silo build dir."
    info "Invoking command to configure Silo"
    SILO_LINK_OPT=""
    if [[ "$DO_HDF5" == "yes" ]] ; then
       export HDF5INCLUDE="$VISITDIR/hdf5/$HDF5_VERSION/$VISITARCH/include"
       export HDF5LIB="$VISITDIR/hdf5/$HDF5_VERSION/$VISITARCH/lib"
       WITHHDF5ARG="--with-hdf5=$HDF5INCLUDE,$HDF5LIB"
       SILO_LINK_OPT="-L$HDF5LIB -lhdf5"
    else
       WITHHDF5ARG="--without-hdf5"
    fi
    SILO_LINK_OPT="$SILO_LINK_OPT -lz"
    if [[ "$DO_SZIP" == "yes" ]] ; then
       export SZIPDIR="$VISITDIR/szip/$SZIP_VERSION/$VISITARCH"
       WITHSZIPARG="--with-szlib=$SZIPDIR"
       SILO_LINK_OPT="$SILO_LINK_OPT -L$SZIPDIR/lib -lsz"
    else
       WITHSZIPARG="--without-szlib"
    fi
    WITHSHAREDARG="--enable-shared"
    if [[ "$DO_STATIC_BUILD" == "yes" ]] ; then
        WITHSHAREDARG="--disable-shared"
    fi
    if [[ "$DO_SILEX" == "no" || "$DO_QT" != "yes" || "$DO_STATIC_BUILD" == "yes" || "$IS_QT5" == "yes" ]] ; then
       WITHSILOQTARG='--disable-silex'
    else
       export SILOQTDIR="$QT_INSTALL_DIR" #"${VISITDIR}/qt/${QT_VERSION}/${VISITARCH}"
       if [[ "$OPSYS" == "Darwin" ]] ; then
           WITHSILOQTARG='--enable-silex --with-Qt-dir=$SILOQTDIR --with-Qt-lib="m -F${SILOQTDIR}/lib -framework QtGui -framework QtCore"'
       else
           WITHSILOQTARG='--enable-silex --with-Qt-dir=$SILOQTDIR --with-Qt-lib="QtGui -lQtCore"'
       fi
    fi

    if [[ "$DO_ZLIB" == "yes" ]] ; then
       ZLIBARGS="--with-zlib=${VISITDIR}/zlib/${ZLIB_VERSION}/${VISITARCH}/include,${VISITDIR}/zlib/${ZLIB_VERSION}/${VISITARCH}/lib"
    fi

    if [[ "$FC_COMPILER" == "no" ]] ; then
        FORTRANARGS="--disable-fortran"
    else
        FORTRANARGS="FC=\"$FC_COMPILER\" F77=\"$FC_COMPILER\" FCFLAGS=\"$FCFLAGS\" FFLAGS=\"$FCFLAGS\""
    fi

    info "./configure CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" \
        CFLAGS=\"$CFLAGS $C_OPT_FLAGS\" CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS\" \
        $FORTRANARGS \
        --prefix=\"$VISITDIR/silo/$SILO_VERSION/$VISITARCH\" \
        $WITHHDF5ARG $WITHSZIPARG $WITHSILOQTARG $WITHSHAREDARG \
        --enable-install-lite-headers --without-readline \
        $ZLIBARGS $SILO_EXTRA_OPTIONS"

    # In order to ensure $FORTRANARGS is expanded to build the arguments to
    # configure, we wrap the invokation in 'sh -c "..."' syntax
    sh -c "./configure CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" \
        CFLAGS=\"$CFLAGS $C_OPT_FLAGS\" CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS\" \
        $FORTRANARGS \
        --prefix=\"$VISITDIR/silo/$SILO_VERSION/$VISITARCH\" \
        $WITHHDF5ARG $WITHSZIPARG $WITHSILOQTARG $WITHSHAREDARG \
        --enable-install-lite-headers --without-readline \
        $ZLIBARGS $SILO_EXTRA_OPTIONS"

    if [[ $? != 0 ]] ; then
       warn "Silo configure failed.  Giving up"
       return 1
    fi

    #
    # Build Silo
    #
    info "Building Silo . . . (~2 minutes)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "Silo build failed.  Giving up"
       return 1
    fi
    #
    # Install into the VisIt third party location.
    #
    info "Installing Silo"

    $MAKE install
    if [[ $? != 0 ]] ; then
        warn "Silo install failed.  Giving up"
        return 1
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/silo"
       chgrp -R ${GROUP} "$VISITDIR/silo"
    fi
    cd "$START_DIR"
    info "Done with Silo"
    return 0
}

function bv_silo_is_enabled
{
    if [[ $DO_SILO == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_silo_is_installed
{
    check_if_installed "silo" $SILO_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_silo_build
{
cd "$START_DIR"
if [[ "$DO_SILO" == "yes" ]] ; then
    check_if_installed "silo" $SILO_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping Silo build.  Silo is already installed."
    else
        info "Building Silo (~2 minutes)"
        build_silo
        if [[ $? != 0 ]] ; then
            error "Unable to build or install Silo.  Bailing out."
        fi
        info "Done building Silo"
    fi
fi
}

function bv_szip_initialize
{
export DO_SZIP="no"
export ON_SZIP="off"
}

function bv_szip_enable
{
DO_SZIP="yes"
ON_SZIP="on"
}

function bv_szip_disable
{
DO_SZIP="no"
ON_SZIP="off"
}

function bv_szip_depends_on
{
echo ""
}

function bv_szip_info
{
export SZIP_FILE=${SZIP_FILE:-"szip-2.1.tar.gz"}
export SZIP_VERSION=${SZIP_VERSION:-"2.1"}
export SZIP_COMPATIBILITY_VERSION=${SZIP_COMPATIBILITY_VERSION:-"2.0"}
export SZIP_BUILD_DIR=${SZIP_BUILD_DIR:-"szip-2.1"}
export SZIP_MD5_CHECKSUM="9cc9125a58b905a4148e4e2fda3fabc6"
export SZIP_SHA256_CHECKSUM=""
}

function bv_szip_print
{
  printf "%s%s\n" "SZIP_FILE=" "${SZIP_FILE}"
  printf "%s%s\n" "SZIP_VERSION=" "${SZIP_VERSION}"
  printf "%s%s\n" "SZIP_COMPATIBILITY_VERSION=" "${SZIP_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "SZIP_BUILD_DIR=" "${SZIP_BUILD_DIR}"
}

function bv_szip_print_usage
{
printf "%-15s %s [%s]\n" "--szip" "Build with SZIP" "$DO_SZIP"  
}

function bv_szip_graphical
{
local graphical_out="SZip     $SZIP_VERSION($SZIP_FILE)      $ON_SZIP"
echo "$graphical_out"
}

function bv_szip_host_profile
{
    if [[ "$DO_SZIP" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## SZIP" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_SZIP_DIR \${VISITHOME}/szip/$SZIP_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
    fi
}

function bv_szip_ensure
{    
    if [[ "$DO_SZIP" == "yes" ]] ; then
        ensure_built_or_ready "szip" $SZIP_VERSION $SZIP_BUILD_DIR $SZIP_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_SZIP="no"
            error "Unable to build SZIP.  ${SZIP_FILE} not found."
        fi
    fi
}

function bv_szip_dry_run
{
  if [[ "$DO_SZIP" == "yes" ]] ; then
    echo "Dry run option not set for szip."
  fi
}

# *************************************************************************** #
#                          Function 8.0, build_szip                           #
# *************************************************************************** #

function build_szip
{
    #
    # Prepare build dir
    #
    prepare_build_dir $SZIP_BUILD_DIR $SZIP_FILE
    untarred_szip=$?
    if [[ $untarred_szip == -1 ]] ; then
       warn "Unable to prepare SZip build directory. Giving Up!"
       return 1
    fi

    #
    info "Configuring SZIP . . ."
    cd ${SZIP_BUILD_DIR} || error "Can't cd to szip build dir."
    info "Invoking command to configure SZIP"
    cf_szip=""
    if [[ "$DO_STATIC_BUILD" == "yes" ]]; then
        cf_szip="--disable-shared --enable-static"
    fi

    info "./configure CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" LIBS=\"-lm\" \
        CFLAGS=\"$CFLAGS $C_OPT_FLAGS\" CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS\" \
        --prefix=\"$VISITDIR/szip/$SZIP_VERSION/$VISITARCH\" ${cf_szip}"

    ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" LIBS="-lm" \
        CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
        --prefix="$VISITDIR/szip/$SZIP_VERSION/$VISITARCH" ${cf_szip}

    if [[ $? != 0 ]] ; then
       warn "SZIP configure failed.  Giving up"
       return 1
    fi

    #
    # Build SZIP
    #
    info "Building SZIP . . . (~1 minutes)"

    $MAKE
    if [[ $? != 0 ]] ; then
       warn "SZIP build failed.  Giving up"
       return 1
    fi
    #
    # Install into the VisIt third party location.
    #
    info "Installing SZIP . . ."

    $MAKE install
    if [[ $? != 0 ]] ; then
       warn "SZIP install failed.  Giving up"
       return 1
    fi

    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
        #
        # Make dynamic executable, need to patch up the install path and
        # version information.
        #
        info "Creating dynamic libraries for SZIP . . ."
        INSTALLNAMEPATH="$VISITDIR/szip/${SZIP_VERSION}/$VISITARCH/lib"

## go back to gcc bacause if "external relocation entries" restFP saveFP
##      /usr/bin/libtool -o libsz.${SO_EXT} -dynamic src/.libs/libsz.a \
##      -lSystem -lz -headerpad_max_install_names \
##      -install_name $INSTALLNAMEPATH/libsz.${SO_EXT} \
##      -compatibility_version $SZIP_COMPATIBILITY_VERSION \
##      -current_version $SZIP_VERSION
        $C_COMPILER -dynamiclib -o libsz.${SO_EXT} src/*.o \
           -Wl,-headerpad_max_install_names \
           -Wl,-twolevel_namespace,-undefined,dynamic_lookup \
           -Wl,-install_name,$INSTALLNAMEPATH/libsz.${SO_EXT} \
           -Wl,-compatibility_version,$SZIP_COMPATIBILITY_VERSION \
           -Wl,-current_version,$SZIP_VERSION -lSystem 
        if [[ $? != 0 ]] ; then
           warn "SZIP dynamic library build failed.  Giving up"
           return 1
        fi
        rm -f "$VISITDIR/szip/$SZIP_VERSION/$VISITARCH/lib/libsz.${SO_EXT}"
        cp libsz.${SO_EXT} "$VISITDIR/szip/$SZIP_VERSION/$VISITARCH/lib"
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/szip"
       chgrp -R ${GROUP} "$VISITDIR/szip"
    fi
    cd "$START_DIR"
    info "Done with SZIP"
    return 0
}

function bv_szip_is_enabled
{
    if [[ $DO_SZIP == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_szip_is_installed
{
    check_if_installed "szip" $SZIP_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_szip_build
{
cd "$START_DIR"
if [[ "$DO_SZIP" == "yes" ]] ; then
    check_if_installed "szip" $SZIP_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping SZIP build.  SZIP is already installed."
    else
        info "Building SZIP (~2 minutes)"
        build_szip
        if [[ $? != 0 ]] ; then
            error "Unable to build or install SZIP.  Bailing out."
        fi
        info "Done building SZIP"
    fi
fi
}
function bv_tcmalloc_initialize
{
export DO_TCMALLOC="no"
export ON_TCMALLOC="off"
}

function bv_tcmalloc_enable
{
DO_TCMALLOC="yes"
ON_TCMALLOC="on"
}

function bv_tcmalloc_disable
{
DO_TCMALLOC="no"
ON_TCMALLOC="off"
}

function bv_tcmalloc_depends_on
{
echo ""
}

function bv_tcmalloc_info
{
export TCMALLOC_FILE=${TCMALLOC_FILE:-"google-perftools-0.97.tar.gz"}
export TCMALLOC_VERSION=${TCMALLOC_VERSION:-"0.97"}
export TCMALLOC_COMPATIBILITY_VERSION=${TCMALLOC_COMPATIBILITY_VERSION:-"0.97"}
export TCMALLOC_BUILD_DIR=${TCMALLOC_BUILD_DIR:-"google-perftools-0.97"}
export TCMALLOC_MD5_CHECKSUM="5168bdca5557bc5630a866f132f8f7c1"
export TCMALLOC_SHA256_CHECKSUM=""
}

function bv_tcmalloc_print
{
  printf "%s%s\n" "TCMALLOC_FILE=" "${TCMALLOC_FILE}"
  printf "%s%s\n" "TCMALLOC_VERSION=" "${TCMALLOC_VERSION}"
  printf "%s%s\n" "TCMALLOC_COMPATIBILITY_VERSION=" "${TCMALLOC_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "TCMALLOC_BUILD_DIR=" "${TCMALLOC_BUILD_DIR}"
}

function bv_tcmalloc_print_usage
{
printf "%-15s %s [%s]\n" "--tcmalloc" "Build tcmalloc from Google's perftools" "$DO_TCMALLOC"  
}

function bv_tcmalloc_graphical
{
local graphical_out="TCMALLOC    $TCMALLOC_VERSION($TCMALLOC_FILE)     $ON_TCMALLOC"
echo "$graphical_out"
}

function bv_tcmalloc_host_profile
{
    if [[ "$DO_TCMALLOC" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## Tcmalloc" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_TCMALLOC_DIR \${VISITHOME}/google-perftools/$TCMALLOC_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
    fi
}

function bv_tcmalloc_ensure
{
    if [[ "$DO_TCMALLOC" == "yes" ]] ; then
        ensure_built_or_ready "google-perftools" $TCMALLOC_VERSION $TCMALLOC_BUILD_DIR $TCMALLOC_FILE
        if [[ $? != 0 ]] ; then
            warn "Unable to build google perftools.  ${TCMALLOC_FILE} not found."
            ANY_ERRORS="yes"
            DO_TCMALLOC="no"
            if [[ "$DO_SVN" != "yes" ]] ; then
                warn "You have requested to build the google perftools library."
                warn "This is not currently available for download from the VisIt website and" 
                warn "is only available through Subversion access."
            fi
            error
        fi
    fi
}

function bv_tcmalloc_dry_run
{
  if [[ "$DO_TCMALLOC" == "yes" ]] ; then
    echo "Dry run option not set for tcmalloc."
  fi
}
# *************************************************************************** #
#                         Function 8.12, build_tcmalloc                       #
# *************************************************************************** #

function build_tcmalloc
{
    #
    # Prepare build dir
    #
    prepare_build_dir $TCMALLOC_BUILD_DIR $TCMALLOC_FILE
    untarred_tcmalloc=$?
    if [[ $untarred_tcmalloc == -1 ]] ; then
       warn "Unable to prepare google-perftools Build Directory. Giving Up"
       return 1
    fi


    info "Configuring google-perftools . . ."
    cd $TCMALLOC_BUILD_DIR || error "Can't cd to tcmalloc build dir."

    #
    # Build TCMALLOC
    #
    info "Building google-perftools . . . (~1 minutes)"
    if [[ "$DO_STATIC_BUILD" == "no" ]]; then 
        ./configure
    else
        ./configure --enable-static --disable-shared
    fi
    make

    info "Installing google-perftools . . ."
    mkdir $VISITDIR/google-perftools
    mkdir $VISITDIR/google-perftools/${TCMALLOC_VERSION}
    mkdir $VISITDIR/google-perftools/${TCMALLOC_VERSION}/$VISITARCH
    mkdir $VISITDIR/google-perftools/${TCMALLOC_VERSION}/$VISITARCH/lib
    cp .libs/libtcmalloc.* $VISITDIR/google-perftools/${TCMALLOC_VERSION}/$VISITARCH/lib

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/google-perftools"
       chgrp -R ${GROUP} "$VISITDIR/google-perftools"
    fi

    cd "$START_DIR"
    echo "Done with google-perftools"
    return 0
}

function bv_tcmalloc_is_enabled
{
    if [[ $DO_TCMALLOC == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_tcmalloc_is_installed
{
    check_if_installed "google-perftools"
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_tcmalloc_build
{
cd "$START_DIR"
if [[ "$DO_TCMALLOC" == "yes" ]] ; then
    check_if_installed "google-perftools"
    if [[ $? == 0 ]] ; then
        info "Skipping google-perftools build.  google-perftools is already installed."
    else
        info "Building google-perftools (~2 minutes)"
        build_tcmalloc
        if [[ $? != 0 ]] ; then
            error "Unable to build or install google-perftools.  Bailing out."
        fi
        info "Done building google-perftools"
    fi
fi
}

function bv_uintah_initialize
{
export FORCE_UINTAH="no"
export DO_UINTAH="no"
export ON_UINTAH="off"
export USE_SYSTEM_UINTAH="no"
add_extra_commandline_args "uintah" "alt-uintah-dir" 1 "Use alternative directory for uintah"
}

function bv_uintah_enable
{
    if [[ "$1" == "force" ]]; then
        FORCE_UINTAH="yes"
    fi

    DO_UINTAH="yes"
    ON_UINTAH="on"
}

function bv_uintah_disable
{
    DO_UINTAH="no"
    ON_UINTAH="off"
}

function bv_uintah_alt_uintah_dir
{
    echo "Using alternate Uintah directory"

    # Check to make sure the directory or a particular include file exists.
    [ ! -e "$1/../src/StandAlone/tools/uda2vis/udaData.h" ] && error "Uintah not found in $1"

    bv_uintah_enable
    USE_SYSTEM_UINTAH="yes"
    UINTAH_INSTALL_DIR="$1"
}

function bv_uintah_depends_on
{
    if [[ "$USE_SYSTEM_UINTAH" == "yes" ]]; then
        echo ""
    else
        echo ""
    fi
}

function bv_uintah_initialize_vars
{
    if [[ "$FORCE_UINTAH" == "no" && "$parallel" == "no" ]]; then
        bv_uintah_disable
        warn "Uintah requested by default but the parallel flag has not been set. Uintah will not be built."
        return
    fi

    if [[ "$USE_SYSTEM_UINTAH" == "no" ]]; then
        UINTAH_INSTALL_DIR="${VISITDIR}/uintah/$UINTAH_VERSION/$VISITARCH"
    fi
}

function bv_uintah_info
{
export UINTAH_VERSION=${UINTAH_VERSION:-"1.6.0"}
export UINTAH_FILE=${UINTAH_FILE:-"Uintah-${UINTAH_VERSION}.tar.gz"}
export UINTAH_COMPATIBILITY_VERSION=${UINTAH_COMPATIBILITY_VERSION:-"1.6"}
export UINTAH_BUILD_DIR=${UINTAH_BUILD_DIR:-"Uintah-${UINTAH_VERSION}/optimized"}
#export UINTAH_URL=${UINTAH_URL:-"http://www.sci.utah.edu/releases/uintah_v${UINTAH_VERSION}/${UINTAH_FILE}"}
export UINTAH_URL=${UINTAH_URL:-"http://www.sci.utah.edu/devbuilds/icse/uintah/${UINTAH_VERSION}"}

export UINTAH_MD5_CHECKSUM=""
export UINTAH_SHA256_CHECKSUM=""
}

function bv_uintah_print
{
  printf "%s%s\n" "UINTAH_FILE=" "${UINTAH_FILE}"
  printf "%s%s\n" "UINTAH_VERSION=" "${UINTAH_VERSION}"
  printf "%s%s\n" "UINTAH_COMPATIBILITY_VERSION=" "${UINTAH_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "UINTAH_BUILD_DIR=" "${UINTAH_BUILD_DIR}"
}

function bv_uintah_print_usage
{
printf "%-15s %s [%s]\n" "--uintah" "Build UINTAH" "${DO_UINTAH}"
printf "%-15s %s [%s]\n" "--alt-uintah-dir"  "Use Uintah" "Use Uintah from alternative directory"
}

function bv_uintah_graphical
{
local graphical_out="UINTAH     $UINTAH_VERSION($UINTAH_FILE)      $ON_UINTAH"
echo $graphical_out
}

function bv_uintah_host_profile
{
    if [[ "$DO_UINTAH" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## Uintah" >> $HOSTCONF
        echo "##" >> $HOSTCONF

        if [[ "$USE_SYSTEM_UINTAH" == "yes" ]]; then
            echo "VISIT_OPTION_DEFAULT(VISIT_UINTAH_DIR $UINTAH_INSTALL_DIR)" >> $HOSTCONF 
            echo "SET(VISIT_USE_SYSTEM_UINTAH TRUE)" >> $HOSTCONF
        else
            echo "SETUP_APP_VERSION(UINTAH $UINTAH_VERSION)" >> $HOSTCONF
            echo \
            "VISIT_OPTION_DEFAULT(VISIT_UINTAH_DIR \${VISITHOME}/uintah/$UINTAH_VERSION/\${VISITARCH})" \
            >> $HOSTCONF 
        fi
    fi
}

function bv_uintah_ensure
{
    if [[ "$DO_UINTAH" == "yes" && "$USE_SYSTEM_UINTAH" == "no" ]] ; then
        ensure_built_or_ready "uintah" $UINTAH_VERSION $UINTAH_BUILD_DIR $UINTAH_FILE $UINTAH_URL 
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_UINTAH="no"
            error "Unable to build UINTAH.  ${UINTAH_FILE} not found."
        fi
    fi
}

function bv_uintah_dry_run
{
  if [[ "$DO_UINTAH" == "yes" ]] ; then
    echo "Dry run option not set for uintah."
  fi
}

# **************************************************************************** #
#                          Function 8.1, build_uintah                          #
#                                                                              #
# Kevin Griffin, Mon Nov 24 12:33:02 PST 2014                                  #
# Changed the -showme:compile to -show for OS X Mavericks. The -showme:compile #
# was being reported as an invalid option.                                     #
# **************************************************************************** #

function build_uintah
{
    if [[ "$OPSYS" == "Linux"  ]]; then
	if [[ "$PAR_COMPILER" == "" || "$PAR_COMPILER_CXX" == "" || "$PAR_INCLUDE" == "" ]]; then
	    warn "For Linux builds the PAR_COMPILER, PAR_COMPILER_CXX, and PAR_INCLUDE environment variables must be set."
	    if [[ "$PAR_COMPILER" == "" ]]; then
		warn "PAR_COMPILER should be of the form \"/path/to/mpi/bin/mpicc\""
	    fi
	    if [[ "$PAR_COMPILER_CXX" == "" ]]; then
		warn "PAR_COMPILER_CXX should be of the form \"/path/to/mpi/bin/mpicxx\""
	    fi
	    if [[ "$PAR_INCLUDE" == "" ]]; then
		warn "PAR_INCLUDE should be of the form \"-I/path/to/mpi/include\""
	    fi
	    warn "Giving Up!"
	    return 1
	fi
    fi

    PAR_INCLUDE_STRING=""
    if [[ "$PAR_INCLUDE" != "" ]] ; then
        PAR_INCLUDE_STRING=$PAR_INCLUDE
    fi

    if [[ "$PAR_COMPILER" != "" ]] ; then
        if [[ "$OPSYS" == "Darwin" && "$PAR_COMPILER" == "/usr/bin/mpicc" ]]; then
            PAR_INCLUDE_STRING="-I/usr/include/"
        elif [[ "$OPSYS" == "Linux" && "$PAR_COMPILER" == "mpixlc" ]]; then
            PAR_INCLUDE_STRING=`$PAR_COMPILER -show`
        else
            if [[ -z "$PAR_INCLUDE_STRING" ]]; then
                if [[ "$OPSYS" == "Darwin" && `sw_vers -productVersion` == 10.9.[0-9]* ]] ; then
                   PAR_INCLUDE_STRING=`$PAR_COMPILER -show`
                else
                    PAR_INCLUDE_STRING=`$PAR_COMPILER -showme:compile`
                    if [[ $? != 0 ]] ; then
                       PAR_INCLUDE_STRING=`$PAR_COMPILER -show`
                    fi
                fi
            fi
        fi
    fi

    if [[ "$PAR_INCLUDE_STRING" == "" ]] ; then
       warn "You must set either the PAR_COMPILER or PAR_INCLUDE environment variables."
       warn "PAR_COMPILER should be of the form \"/path/to/mpi/bin/mpicc\""
       warn "PAR_INCLUDE should be of the form \"-I/path/to/mpi/include\""
       warn "Giving Up!"
       return 1
    fi

    # Uintah's config doesn't take the compiler options, but rather the
    # paths to the root, and then it tries to build all of the appropriate
    # options itself.  Because we only have the former, we need to guess at the
    # latter.
    # Our current guess is to take the first substring in PAR_INCLUDE, assume
    # it's the appropriate -I option, and use it with the "-I" removed.  This
    # is certainly not ideal -- for example, it will break if the user's
    # MPI setup requires multiple include directories.

    # Search all of the -I directories and take the first one containing mpi.h
    PAR_INCLUDE_DIR=""
    for arg in $PAR_INCLUDE_STRING ; do
        if [[ "$arg" != "${arg#-I}" ]] ; then
            if test -e "${arg#-I}/mpi.h" ; then
                PAR_INCLUDE_DIR=${arg#-I}
                break
            fi
        fi
    done
    # If we did not get a valid include directory, take the first -I directory.
    if test -z "${PAR_INCLUDE_DIR}"  ; then
        for arg in $PAR_INCLUDE_STRING ; do
            if [[ "$arg" != "${arg#-I}" ]] ; then
                PAR_INCLUDE_DIR=${arg#-I}
                break
            fi
        done
    fi

    if test -z "${PAR_INCLUDE_DIR}"  ; then
        if test -n "${PAR_INCLUDE}" ; then
            warn "This script believes you have defined PAR_INCLUDE as: $PAR_INCLUDE"
            warn "However, to build Uintah, this script expects to parse a -I/path/to/mpi out of PAR_INCLUDE"
        fi
        warn "Could not determine the MPI include information which is needed to compile Uintah."
        if test -n "${PAR_INCLUDE}" ; then
            error "Please re-run with the required \"-I\" option included in PAR_INCLUDE"
        else
            error "You need to specify either PAR_COMPILER or PAR_INCLUDE variable.  On many "
                  " systems, the output of \"mpicc -showme\" is good enough."
            error ""
        fi
    fi

    if [[ "$FC_COMPILER" == "no" ]] ; then

        warn "Uintah may require fortran to be enabled. It does not appear that the --fortran "
        warn "agrument was set. If Uintah fails to build try adding the --fortran argument"
        FORTRANARGS="--without-fortran"
        #return 1

    else
        FORTRANARGS="FC=\"$FC_COMPILER\" F77=\"$FC_COMPILER\" FCFLAGS=\"$FCFLAGS\" FFLAGS=\"$FCFLAGS\" --enable-fortran"
    fi

    #
    # Prepare build dir
    #
    prepare_build_dir $UINTAH_BUILD_DIR $UINTAH_FILE
    untarred_uintah=$?
    if [[ $untarred_uintah == -1 ]] ; then
       warn "Unable to prepare UINTAH Build Directory. Giving Up"
       return 1
    fi

    #
    mkdir $UINTAH_BUILD_DIR
    cd $UINTAH_BUILD_DIR || error "Can't cd to UINTAH build dir."

    info "Configuring UINTAH . . ."
    cf_darwin=""
    if [[ "$DO_STATIC_BUILD" == "yes" ]]; then
            cf_build_type="--disable-shared --enable-static"
        else
            cf_build_type="--enable-shared --disable-static"
    fi

    # In order to ensure $FORTRANARGS is expanded to build the arguments to
    # configure, we wrap the invokation in 'sh -c "..."' syntax

    if [[ "$OPSYS" == "Darwin" ]]; then

      info "Invoking command to configure UINTAH"
      info "../src/configure CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" \
        CFLAGS=\"$CFLAGS $C_OPT_FLAGS\" CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS\" \
        MPI_EXTRA_LIB_FLAG=\"$PAR_LIBRARY_NAMES\" \
        $FORTRANARGS \
        --prefix=\"$VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH\" \
        ${cf_darwin} \
        ${cf_build_type} \
        --enable-optimize \
        --with-mpi="${PAR_INCLUDE_DIR}/.." "

#        --with-mpi-include="${PAR_INCLUDE_DIR}/" \
#        --with-mpi-lib="${PAR_INCLUDE_DIR}/../lib" "

      sh -c "../src/configure CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" \
        CFLAGS=\"$CFLAGS $C_OPT_FLAGS\" CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS\" \
        MPI_EXTRA_LIB_FLAG=\"$PAR_LIBRARY_NAMES\" \
        $FORTRANARGS \
        --prefix=\"$VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH\" \
        ${cf_darwin} \
        ${cf_build_type} \
        --enable-optimize \
        --with-mpi="${PAR_INCLUDE_DIR}/.." "

#        --with-mpi-include="${PAR_INCLUDE_DIR}/" \
#        --with-mpi-lib="${PAR_INCLUDE_DIR}/../lib" "

    else

      info "Invoking command to configure UINTAH"
      info "../src/configure CXX=\"$PAR_COMPILER_CXX\" CC=\"$PAR_COMPILER\" \
        CFLAGS=\"$CFLAGS $C_OPT_FLAGS\" CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS\" \
        MPI_EXTRA_LIB_FLAG=\"$PAR_LIBRARY_NAMES\" \
        $FORTRANARGS \
        --prefix=\"$VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH\" \
        ${cf_build_type} \
        --enable-optimize"

      sh -c "../src/configure CXX=\"$PAR_COMPILER_CXX\" CC=\"$PAR_COMPILER\" \
        CFLAGS=\"$CFLAGS $C_OPT_FLAGS\" CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS\" \
        MPI_EXTRA_LIB_FLAG=\"$PAR_LIBRARY_NAMES\" \
        $FORTRANARGS \
        --prefix=\"$VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH\" \
        ${cf_build_type} \
        --enable-optimize"
    fi


    if [[ $? != 0 ]] ; then
       warn "UINTAH configure failed.  Giving up"
       return 1
    fi

    #
    # Build UINTAH
    #
    info "Making UINTAH . . ."
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "UINTAH build failed.  Giving up"
       return 1
    fi
    #
    # Install into the VisIt third party location.
    #
    info "Installing UINTAH . . ."

    if [[ ! -e $VISITDIR/uintah ]] ; then
        mkdir $VISITDIR/uintah || error "Can't make UINTAH install dir."
    fi

    if [[ -e $VISITDIR/uintah/$UINTAH_VERSION ]] ; then
        rm -rf $VISITDIR/uintah/$UINTAH_VERSION || error "Can't remove old UINTAH install dir."
    fi

    mkdir $VISITDIR/uintah/$UINTAH_VERSION/ || error "Can't make UINTAH install dir."
    mkdir $VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH || error "Can't make UINTAH install dir."
    mkdir $VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH/lib || error "Can't make UINTAH install dir."
    mkdir $VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH/include || error "Can't make UINTAH install dir."
    mkdir $VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH/include/StandAlone || error "Can't make UINTAH install dir."
    mkdir $VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH/include/StandAlone/tools || error "Can't make UINTAH install dir."
    mkdir $VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH/include/StandAlone/tools/uda2vis || error "Can't make UINTAH install dir."

    cp lib/* $VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH/lib
    cp ../src/StandAlone/tools/uda2vis/udaData.h $VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH/include/StandAlone/tools/uda2vis

#    $MAKE install
    if [[ $? != 0 ]] ; then
       warn "UINTAH install failed.  Giving up"
       return 1
    fi

    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
        #
        # Make dynamic executable, need to patch up the install path and
        # version information.
        #
        info "Creating dynamic libraries for UINTAH . . ."
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/uintah"
       chgrp -R ${GROUP} "$VISITDIR/uintah"
    fi
    cd "$START_DIR"
    info "Done with UINTAH"
    return 0
}

function bv_uintah_is_enabled
{
    if [[ $DO_UINTAH == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_uintah_is_installed
{
    if [[ "$USE_SYSTEM_UINTAH" == "yes" ]]; then
        return 1
    fi

    check_if_installed "uintah" $UINTAH_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_uintah_build
{
cd "$START_DIR"

if [[ "$DO_UINTAH" == "yes" && "$USE_SYSTEM_UINTAH" == "no" ]] ; then
    check_if_installed "uintah" $UINTAH_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping UINTAH build.  UINTAH is already installed."
    else
        info "Building UINTAH (~10 minutes)"
        build_uintah
        if [[ $? != 0 ]] ; then
            error "Unable to build or install UINTAH.  Bailing out."
        fi
        info "Done building UINTAH"
    fi
fi
}

function bv_visus_initialize
{
    export DO_VISUS="no"
    export ON_VISUS="off"
    export USE_SYSTEM_VISUS="no"
    add_extra_commandline_args "visus" "alt-visus-dir" 1 "Use alternative directory for ViSUS"
}

function bv_visus_alt_visus_dir
{
    bv_visus_enable
    USE_SYSTEM_VISUS="yes"
    VISUS_INSTALL_DIR="$1"
    VISUS_INSTALL_DIR_cmake="$1"
}

function bv_visus_enable
{
    DO_VISUS="yes"
    ON_VISUS="on"
}

function bv_visus_disable
{
    DOVISUS_="no"
    ON_VISUS="off"
}

function bv_visus_depends_on
{
    if [[ "$USE_SYSTEM_VISUS" == "yes" ]]; then
        echo ""
    fi
}

function bv_visus_initialize_vars
{
    if [[ "$USE_SYSTEM_VISUS" == "no" ]]; then
        VISUS_INSTALL_DIR="${VISITDIR}/visus/$VISUS_VERSION/${VISITARCH}"
    fi
}

function bv_visus_info
{
    #todo: add query system info to be used here to determine which file to download, and change build_dir to install_dir or something
    export VISUS_OS=`uname`
    export VISUS_VERSION=${VISUS_VERSION:-"ad09cb8"}
    export VISUS_FILE=${VISUS_FILE:-"ViSUS-${VISUS_VERSION}-${VISUS_OS}.tgz"}
    export VISUS_BUILD_DIR=${VISUS_BUILD_DIR:-"ViSUS"}
    export VISUS_URL=${VISUS_URL:-"http://atlantis.sci.utah.edu/builds/visit-plugin"}
}

function bv_visus_print
{
    printf "%s%s\n" "VISUS_FILE=" "${VISUS_FILE}"
    printf "%s%s\n" "VISUS_VERSION=" "${VISUS_VERSION}"
    printf "%s%s\n" "VISUS_BUILD_DIR=" "${VISUS_BUILD_DIR}"
}

function bv_visus_print_usage
{
    printf "%-15s %s [%s]\n" "--visus" "Build ViSUS support" "$DO_VISUS"
    printf "%-15s %s [%s]\n" "--alt-visus-dir"  "Use ViSUS" "Use ViSUS from alternative directory"
}

function bv_visus_graphical
{
    local graphical_out="visus     $VISUS_VERSION($VISUS_FILE)      $ON_VISUS"
    echo "$graphical_out"
}

function bv_visus_host_profile
{
    if [[ "$DO_VISUS" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## VISUS " >> $HOSTCONF
        echo "##" >> $HOSTCONF
        if [[ "$USE_SYSTEM_VISUS" == "yes" ]]; then
            echo "VISIT_OPTION_DEFAULT(VISIT_VISUS_DIR ${VISUS_INSTALL_DIR_cmake})" >> $HOSTCONF
        else
            echo "VISIT_OPTION_DEFAULT(VISIT_VISUS_DIR \${VISITHOME}/visus/$VISUS_VERSION/\${VISITARCH})" >> $HOSTCONF
        fi
    fi
}

function bv_visus_ensure
{
    if [[ "$DO_VISUS" == "yes" && "$USE_SYSTEM_VISUS" == "no" ]] ; then
        ensure_built_or_ready "visus" $VISUS_VERSION $VISUS_BUILD_DIR $VISUS_FILE $VISUS_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_VISUS="no"
            error "Unable to build ViSUS.  ${VISUS_FILE} not found."
        fi
    fi
}

function bv_visus_dry_run
{
    if [[ "$DO_VISUS" == "yes" ]] ; then
        echo "Dry run option not set for ViSUS."
    fi
}

function install_visus
{
    #
    # Prepare install dir
    #
    prepare_build_dir $VISUS_BUILD_DIR $VISUS_FILE
    untarred_visus=$?
    if [[ $untarred_visus == -1 ]] ; then
        warn "Unable to prepare visus install directory. Giving Up!"
        return 1
    fi
    
    #
    # install
    #
    info "Installing ViSUS . . . (a few seconds)"
    mkdir -p $VISUS_INSTALL_DIR
    mv $VISUS_BUILD_DIR/* $VISUS_INSTALL_DIR
    rmdir $VISUS_BUILD_DIR
    copied_visus=$?
    if [[ $copied_visus == -1 ]] ; then
        warn "Unable to install ViSUS. Giving Up!"
        return 1
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
        chmod -R ug+w,a+rX "$VISITDIR/visus"
        chgrp -R ${GROUP} "$VISITDIR/visus"
    fi

    cd "$START_DIR"
    info "Done installing ViSUS"
    return 0
}

function bv_visus_is_enabled
{
    if [[ $DO_VISUS == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_visus_is_installed
{
    if [[ "$USE_SYSTEM_VISUS" == "yes" ]]; then
        return 1
    fi

    check_if_installed "visus" $VISUS_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_visus_build
{
    cd "$START_DIR"
    if [[ "$DO_VISUS" == "yes" && "$USE_SYSTEM_VISUS" == "no" ]] ; then
        check_if_installed "visus" $VISUS_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping ViSUS install. ViSUS is already installed."
        else
            install_visus
            if [[ $? != 0 ]] ; then
                error "Unable to install ViSUS.  Bailing out."
            fi
        fi
    fi
}

function bv_vtk_initialize
{
    export DO_VTK="yes"
    export ON_VTK="on"
    export FORCE_VTK="no"
    export USE_SYSTEM_VTK="no"
    add_extra_commandline_args "vtk" "alt-vtk-dir" 1 "Use alternate VTK (exp)"
}

function bv_vtk_enable
{
DO_VTK="yes"
ON_VTK="on"
FORCE_VTK="yes"
}

function bv_vtk_disable
{
DO_VTK="no"
ON_VTK="off"
FORCE_VTK="no"
}

function bv_vtk_alt_vtk_dir
{
    bv_vtk_enable
    USE_SYSTEM_VTK="yes"
    SYSTEM_VTK_DIR="$1"
    info "Using Alternate VTK: $SYSTEM_VTK_DIR"
}

function bv_vtk_depends_on
{
 depends_on="cmake"

 if [[ "$DO_PYTHON" == "yes" ]]; then
      depends_on="${depends_on} python"
 fi

 if [[ "$DO_R" == "yes" ]]; then
      depends_on="${depends_on} R"
 fi

 # Only depend on Qt if we're not doing server-only builds.
 if [[ "$DO_DBIO_ONLY" != "yes" ]]; then
     if [[ "$DO_ENGINE_ONLY" != "yes" ]]; then
         if [[ "$DO_SERVER_COMPONENTS_ONLY" != "yes" ]]; then 
             depends_on="${depends_on} qt"
         fi
     fi
 fi

 echo ${depends_on}
}

function bv_vtk_force
{
  if [[ "$FORCE_VTK" == "yes" ]]; then
     return 0;
  fi
  return 1;
}

function bv_vtk_info
{
export VTK_FILE=${VTK_FILE:-"VTK-6.1.0.tar.gz"}
export VTK_VERSION=${VTK_VERSION:-"6.1.0"}
export VTK_SHORT_VERSION=${VTK_SHORT_VERSION:-"6.1"}
export VTK_COMPATIBILITY_VERSION=${VTK_SHORT_VERSION}
export VTK_BUILD_DIR=${VTK_BUILD_DIR:-"VTK-6.1.0"}
export VTK_INSTALL_DIR=${VTK_INSTALL_DIR:-"vtk"}
export VTK_URL=${VTK_URL:-"http://www.vtk.org/files/release/6.1"}
export VTK_MD5_CHECKSUM=""
export VTK_SHA256_CHECKSUM=""
}

function bv_vtk_print
{
printf "%s%s\n" "VTK_FILE=" "${VTK_FILE}"
printf "%s%s\n" "VTK_VERSION=" "${VTK_VERSION}"
printf "%s%s\n" "VTK_BUILD_DIR=" "${VTK_BUILD_DIR}"
}

function bv_vtk_print_usage
{
printf "\t\t%15s\n" "NOTE: not available for download from web"
printf "%-15s %s [%s]\n" "--vtk" "Build VTK" "built by default unless --no-thirdparty flag is used"
}

function bv_vtk_host_profile
{
    echo >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "## VTK" >> $HOSTCONF
    echo "##" >> $HOSTCONF

    echo "SETUP_APP_VERSION(VTK $VTK_VERSION)" >> $HOSTCONF
    if [[ "$USE_SYSTEM_VTK" == "yes" ]]; then
            echo "VISIT_OPTION_DEFAULT(VISIT_VTK_DIR $SYSTEM_VTK_DIR)" >> $HOSTCONF
    else
            echo "VISIT_OPTION_DEFAULT(VISIT_VTK_DIR \${VISITHOME}/${VTK_INSTALL_DIR}/\${VTK_VERSION}/\${VISITARCH})" >> $HOSTCONF
    fi
}

function bv_vtk_initialize_vars
{
    info "initalizing vtk vars"
    if [[ $DO_R == "yes" ]]; then
        VTK_INSTALL_DIR="vtk-r"
    fi
}

function bv_vtk_ensure
{
    if [[ "$DO_VTK" == "yes" && "$USE_SYSTEM_VTK" == "no" ]] ; then
        ensure_built_or_ready $VTK_INSTALL_DIR $VTK_VERSION $VTK_BUILD_DIR $VTK_FILE $VTK_URL
        if [[ $? != 0 ]] ; then
            return 1
        fi
    fi
}

function bv_vtk_dry_run
{
    if [[ "$DO_VTK" == "yes" ]] ; then
        echo "Dry run option not set for vtk"
    fi
}

# *************************************************************************** #
#                            Function 6, build_vtk                            #
# *************************************************************************** #

function apply_vtk_600_patch
{
# fix for 10.9 -- this fix is already in newer versions of VTK
    info "Patching vtk-6"
    patch -p0 << \EOF
diff -c CMakeLists.txt.orig CMakeLists.txt
*** CMakeLists.txt.orig	2014-05-30 15:54:16.000000000 -0700
--- CMakeLists.txt	2014-05-30 15:54:25.000000000 -0700
***************
*** 4,13 ****
  
  # Objective-C++ compile flags, future CMake versions might make this obsolete
  IF(APPLE)
!   # Being a library, VTK may be linked in either GC (garbage collected)
!   # processes or non-GC processes.  Default to "GC supported" so that both
!   # GC and MRR (manual reference counting) are supported.
!   SET(VTK_OBJCXX_FLAGS_DEFAULT "-fobjc-gc")
    SET(VTK_REQUIRED_OBJCXX_FLAGS ${VTK_OBJCXX_FLAGS_DEFAULT} CACHE STRING "Extra flags for Objective-C++ compilation")
    MARK_AS_ADVANCED(VTK_REQUIRED_OBJCXX_FLAGS)
  ENDIF(APPLE)
--- 4,10 ----
  
  # Objective-C++ compile flags, future CMake versions might make this obsolete
  IF(APPLE)
!   SET(VTK_OBJCXX_FLAGS_DEFAULT "")
    SET(VTK_REQUIRED_OBJCXX_FLAGS ${VTK_OBJCXX_FLAGS_DEFAULT} CACHE STRING "Extra flags for Objective-C++ compilation")
    MARK_AS_ADVANCED(VTK_REQUIRED_OBJCXX_FLAGS)
  ENDIF(APPLE)

EOF
    if [[ $? != 0 ]] ; then
      warn "vtk6 patch failed."
      return 1
    fi

    return 0;
}

function apply_vtk_610_patch
{
   patch -p0 << \EOF
diff -c Rendering/OpenGL/vtkXOpenGLRenderWindow.cxx.orig Rendering/OpenGL/vtkXOpenGLRenderWindow.cxx
*** Rendering/OpenGL/vtkXOpenGLRenderWindow.cxx.orig	2015-01-29 15:59:05.000000000 -0800
--- Rendering/OpenGL/vtkXOpenGLRenderWindow.cxx	2015-01-29 16:00:02.000000000 -0800
***************
*** 27,33 ****
  
  // define GLX_GLXEXT_LEGACY to prevent glx.h to include glxext.h provided by
  // the system
! //#define GLX_GLXEXT_LEGACY
  #include "GL/glx.h"
  
  #include "vtkgl.h"
--- 27,33 ----
  
  // define GLX_GLXEXT_LEGACY to prevent glx.h to include glxext.h provided by
  // the system
! #define GLX_GLXEXT_LEGACY
  #include "GL/glx.h"
  
  #include "vtkgl.h"

EOF
    if [[ $? != 0 ]] ; then
      warn "vtk6 patch failed."
      return 1
    fi

    return 0;
}

function apply_vtk_610_patch_2
{
   patch -p0 << \EOF
diff -c Rendering/Core/vtkMapper.cxx.orig Rendering/Core/vtkMapper.cxx
*** Rendering/Core/vtkMapper.cxx.orig	2015-03-19 18:46:17.000000000 -0700
--- Rendering/Core/vtkMapper.cxx	2015-03-19 18:44:43.000000000 -0700
***************
*** 18,23 ****
--- 18,24 ----
  #include "vtkExecutive.h"
  #include "vtkLookupTable.h"
  #include "vtkFloatArray.h"
+ #include "vtkDoubleArray.h"
  #include "vtkImageData.h"
  #include "vtkPointData.h"
  #include "vtkMath.h"
***************
*** 517,523 ****
  template<class T>
  void vtkMapperCreateColorTextureCoordinates(T* input, float* output,
                                              vtkIdType num, int numComps,
!                                             int component, double* range)
  {
    double tmp, sum;
    double k = 1.0 / (range[1]-range[0]);
--- 518,524 ----
  template<class T>
  void vtkMapperCreateColorTextureCoordinates(T* input, float* output,
                                              vtkIdType num, int numComps,
!                                             int component, double* range, bool isLogScale)
  {
    double tmp, sum;
    double k = 1.0 / (range[1]-range[0]);
***************
*** 529,540 ****
      for (i = 0; i < num; ++i)
        {
        sum = 0;
!       for (j = 0; j < numComps; ++j)
!         {
!         tmp = static_cast<double>(*input);
!         sum += (tmp * tmp);
!         ++input;
!         }
        output[i] = k * (sqrt(sum) - range[0]);
        if (output[i] > 1.0)
          {
--- 530,545 ----
      for (i = 0; i < num; ++i)
        {
        sum = 0;
!       for (j = 0; j < numComps; ++j) {
!           if(!isLogScale) {
!               tmp = static_cast<double>(*input);
!           } else {
!               tmp = static_cast<double>(log10(*input));
!           }
!           
!           sum += (tmp * tmp);
!           ++input;
!       }
        output[i] = k * (sqrt(sum) - range[0]);
        if (output[i] > 1.0)
          {
***************
*** 551,557 ****
      input += component;
      for (i = 0; i < num; ++i)
        {
!       output[i] = k * (static_cast<double>(*input) - range[0]);
        if (output[i] > 1.0)
          {
          output[i] = 1.0;
--- 556,570 ----
      input += component;
      for (i = 0; i < num; ++i)
        {
!           if(!isLogScale) {
!               output[i] = k * (static_cast<double>(*input) - range[0]);
!           } else {
!               if(*input > 0) {
!                   output[i] = k * (static_cast<double>(log10(*input)) - range[0]);
!               } else {
!                   output[i] = 0;
!               }
!           }
        if (output[i] > 1.0)
          {
          output[i] = 1.0;
***************
*** 565,571 ****
      }
  }
  
- 
  #define ColorTextureMapSize 256
  // a side effect of this is that this->ColorCoordinates and
  // this->ColorTexture are set.
--- 578,583 ----
***************
*** 583,588 ****
--- 595,604 ----
      this->Colors = 0;
      }
  
+     double minRange = range[0];
+     double maxRange = range[1];
+     bool isLogScale = this->LookupTable->UsingLogScale() == 1;
+     
    // If the lookup table has changed, the recreate the color texture map.
    // Set a new lookup table changes this->MTime.
    if (this->ColorTextureMap == 0 ||
***************
*** 599,618 ****
      // Get the texture map from the lookup table.
      // Create a dummy ramp of scalars.
      // In the future, we could extend vtkScalarsToColors.
!     double k = (range[1]-range[0]) / (ColorTextureMapSize-1);
!     vtkFloatArray* tmp = vtkFloatArray::New();
      tmp->SetNumberOfTuples(ColorTextureMapSize);
!     float* ptr = tmp->GetPointer(0);
      for (int i = 0; i < ColorTextureMapSize; ++i)
!       {
!       *ptr = range[0] + i * k;
!       ++ptr;
!       }
      this->ColorTextureMap = vtkImageData::New();
      this->ColorTextureMap->SetExtent(0,ColorTextureMapSize-1,
                                       0,0, 0,0);
!     this->ColorTextureMap->GetPointData()->SetScalars(
!          this->LookupTable->MapScalars(tmp, this->ColorMode, 0));
      this->LookupTable->SetAlpha(orig_alpha);
      // Do we need to delete the scalars?
      this->ColorTextureMap->GetPointData()->GetScalars()->Delete();
--- 615,643 ----
      // Get the texture map from the lookup table.
      // Create a dummy ramp of scalars.
      // In the future, we could extend vtkScalarsToColors.
!     if(isLogScale) {
!         double logRange[2];
!         vtkLookupTable::GetLogRange(range, logRange);
!         minRange = logRange[0];
!         maxRange = logRange[1];
!     }
! 
!     double k = (maxRange - minRange) / (double)(ColorTextureMapSize-1);
!     vtkDoubleArray* tmp = vtkDoubleArray::New();
      tmp->SetNumberOfTuples(ColorTextureMapSize);
!     double* ptr = tmp->GetPointer(0);
!     
      for (int i = 0; i < ColorTextureMapSize; ++i)
!     {
!         double tmpVal = minRange + i * k;
!         *ptr = !isLogScale ? tmpVal : (double)pow(10., tmpVal);
!         ++ptr;
!     }
!         
      this->ColorTextureMap = vtkImageData::New();
      this->ColorTextureMap->SetExtent(0,ColorTextureMapSize-1,
                                       0,0, 0,0);
!     this->ColorTextureMap->GetPointData()->SetScalars(this->LookupTable->MapScalars(tmp, this->ColorMode, 0));
      this->LookupTable->SetAlpha(orig_alpha);
      // Do we need to delete the scalars?
      this->ColorTextureMap->GetPointData()->GetScalars()->Delete();
***************
*** 635,641 ****
        this->ColorCoordinates->UnRegister(this);
        this->ColorCoordinates = 0;
        }
! 
      // Now create the color texture coordinates.
      int numComps = scalars->GetNumberOfComponents();
      void* input = scalars->GetVoidPointer(0);
--- 660,671 ----
        this->ColorCoordinates->UnRegister(this);
        this->ColorCoordinates = 0;
        }
!         
!     if(isLogScale) {
!         range[0] = minRange;
!         range[1] = maxRange;
!     }
!         
      // Now create the color texture coordinates.
      int numComps = scalars->GetNumberOfComponents();
      void* input = scalars->GetVoidPointer(0);
***************
*** 660,666 ****
        vtkTemplateMacro(
          vtkMapperCreateColorTextureCoordinates(static_cast<VTK_TT*>(input),
                                                 output, num, numComps,
!                                                scalarComponent, range)
          );
        case VTK_BIT:
          vtkErrorMacro("Cannot color by bit array.");
--- 690,696 ----
        vtkTemplateMacro(
          vtkMapperCreateColorTextureCoordinates(static_cast<VTK_TT*>(input),
                                                 output, num, numComps,
!                                                scalarComponent, range, isLogScale)
          );
        case VTK_BIT:
          vtkErrorMacro("Cannot color by bit array.");

EOF
    if [[ $? != 0 ]] ; then
      warn "vtk610_2 patch failed."
      return 1
    fi

    return 0;
}

function apply_vtk_patch
{  
    # also apply objc flag patch to 6.1.0
    
    if [[ ${VTK_VERSION} == 6.1.0 ]] ; then
        apply_vtk_600_patch
        apply_vtk_610_patch_2
        if [[ "$OPSYS" == "Linux" ]] ; then
	   apply_vtk_610_patch
        fi
        if [[ $? != 0 ]] ; then
            return 1
        fi
    fi

    if [[ ${VTK_VERSION} == 6.2.0 ]] ; then
        apply_vtk_600_patch
        if [[ $? != 0 ]] ; then
            return 1
        fi
    fi

    return 0
}

function build_vtk
{
    #
    # CMake is the build system for VTK.  Call another script that will build
    # that program.
    #
    CMAKE_INSTALL=${CMAKE_INSTALL:-"$VISITDIR/cmake/${CMAKE_VERSION}/$VISITARCH/bin"}
    if [[ -e ${CMAKE_INSTALL}/cmake ]] ; then
        info "VTK: CMake found"
    else
        build_cmake
        if [[ $? != 0 ]] ; then
            warn "Unable to build cmake.  Giving up"
            return 1
        fi
    fi

    #
    # We need python to build the vtk python bindings.
    #
    PYTHON_INSTALL="${VISIT_PYTHON_DIR}/bin"
    if [[ "$DO_PYTHON" == "yes" ]] ; then
        if [[ -e ${PYTHON_INSTALL}/python ]] ; then
            info "VTK: Python found"
        else
            if [[ "$DO_DBIO_ONLY" != "yes" ]]; then
                build_python
                if [[ $? != 0 ]] ; then
                    warn "Unable to build python. Giving up"
                    return 1
                fi
            fi
        fi
    fi

    #
    # We need Qt to build the vtk Qt support. Only do Qt if we're not doing
    # a server-only build.
    #
    if [[ "$DO_DBIO_ONLY" != "yes" ]]; then
        if [[ "$DO_ENGINE_ONLY" != "yes" ]]; then
            if [[ "$DO_SERVER_COMPONENTS_ONLY" != "yes" ]]; then
                if [[ -e ${QT_BIN_DIR}/qmake ]] ; then
                    info "VTK: Qt found"
                else
                    build_qt
                    if [[ $? != 0 ]] ; then
                        warn "Unable to build Qt. Giving up"
                        return 1
                    fi
                fi
            fi
        fi
    fi

    # Extract the sources
    if [[ -d $VTK_BUILD_DIR ]] ; then
        if [[ ! -f $VTK_FILE ]] ; then
            warn "The directory VTK exists, deleting before uncompressing"
            rm -Rf $VTK_BUILD_DIR
            ensure_built_or_ready $VTK_INSTALL_DIR    $VTK_VERSION    $VTK_BUILD_DIR    $VTK_FILE
        fi
    fi
    prepare_build_dir $VTK_BUILD_DIR $VTK_FILE
    untarred_vtk=$?
    if [[ $untarred_vtk == -1 ]] ; then
        warn "Unable to prepare VTK build directory. Giving Up!"
        return 1
    fi

    #
    # Apply patches
    #
    info "Patching VTK . . ."
    cd $VTK_BUILD_DIR || error "Can't cd to VTK build dir."
    apply_vtk_patch
    if [[ $? != 0 ]] ; then
        if [[ $untarred_vtk == 1 ]] ; then
            warn "Giving up on VTK build because the patch failed."
            return 1
        else
            warn "Patch failed, but continuing.  I believe that this script\n" \
                 "tried to apply a patch to an existing directory which had " \
                 "already been patched ... that is, that the patch is " \
                 "failing harmlessly on a second application."
        fi
    fi
    # move back up to the start dir 
    cd "$START_DIR"

    info "Configuring VTK . . ."

    # Make a build directory for an out-of-source build.. Change the
    # VISIT_BUILD_DIR variable to represent the out-of-source build directory.
    VTK_SRC_DIR=$VTK_BUILD_DIR
    VTK_BUILD_DIR="${VTK_SRC_DIR}-build"
    if [[ ! -d $VTK_BUILD_DIR ]] ; then
        echo "Making build directory $VTK_BUILD_DIR"
        mkdir $VTK_BUILD_DIR
    fi

    #
    # Remove the CMakeCache.txt files ... existing files sometimes prevent
    # fields from getting overwritten properly.
    #
    rm -Rf ${VTK_BUILD_DIR}/CMakeCache.txt ${VTK_BUILD_DIR}/*/CMakeCache.txt

    #
    # Setup paths and libs for python for the VTK build.
    #

    if [[ "$OPSYS" == "Darwin" ]]; then
        if [[ "${VISIT_PYTHON_DIR}/lib" != "/usr/lib" ]]; then
            export DYLD_LIBRARY_PATH="${VISIT_PYTHON_DIR}/lib/:$DYLD_LIBRARY_PATH"
        fi
    else
        export LD_LIBRARY_PATH="${VISIT_PYTHON_DIR}/lib/:$LD_LIBRARY_PATH"
    fi

    export VTK_PY_LIBS="-lpthread"
    if [[ "$OPSYS" == "Linux" ]]; then
        export VTK_PY_LIBS="$VTK_PY_LIBS -ldl -lutil -lm"
    fi

    vopts=""
    vtk_build_mode="${VISIT_BUILD_MODE}"
    vtk_inst_path="${VISITDIR}/${VTK_INSTALL_DIR}/${VTK_VERSION}/${VISITARCH}"
    vtk_debug_leaks="false"

    # Some linker flags.
    lf=""
    if test "${OPSYS}" = "Darwin" ; then
        lf="-Wl,-headerpad_max_install_names"
        lf="${lf},-compatibility_version,${VTK_COMPATIBILITY_VERSION}"
        lf="${lf},-current_version,${VTK_VERSION}"
    fi

    # Add some extra arguments to the VTK cmake command line via the 
    # VTK_EXTRA_OPTIONS environment variable.
    if test -n "$VTK_EXTRA_OPTIONS" ; then
        vopts="${vopts} $VTK_EXTRA_OPTIONS"
    fi

    # normal stuff
    vopts="${vopts} -DCMAKE_BUILD_TYPE:STRING=${vtk_build_mode}"
    vopts="${vopts} -DCMAKE_INSTALL_PREFIX:PATH=${vtk_inst_path}"
    if test "x${DO_STATIC_BUILD}" = "xyes" ; then
        vopts="${vopts} -DBUILD_SHARED_LIBS:BOOL=OFF"
    else
        vopts="${vopts} -DBUILD_SHARED_LIBS:BOOL=ON"
    fi
    vopts="${vopts} -DVTK_DEBUG_LEAKS:BOOL=${vtk_debug_leaks}"
    vopts="${vopts} -DBUILD_TESTING:BOOL=false"
    vopts="${vopts} -DBUILD_DOCUMENTATION:BOOL=false"
    vopts="${vopts} -DCMAKE_C_COMPILER:STRING=${C_COMPILER}"
    vopts="${vopts} -DCMAKE_CXX_COMPILER:STRING=${CXX_COMPILER}"
    vopts="${vopts} -DCMAKE_C_FLAGS:STRING=\"${C_OPT_FLAGS}\""
    vopts="${vopts} -DCMAKE_CXX_FLAGS:STRING=\"${CXX_OPT_FLAGS}\""
    vopts="${vopts} -DCMAKE_EXE_LINKER_FLAGS:STRING=${lf}"
    vopts="${vopts} -DCMAKE_MODULE_LINKER_FLAGS:STRING=${lf}"
    vopts="${vopts} -DCMAKE_SHARED_LINKER_FLAGS:STRING=${lf}"
    vopts="${vopts} -DVTK_REPORT_OPENGL_ERRORS:BOOL=false"
    if test "${OPSYS}" = "Darwin" ; then
        vopts="${vopts} -DVTK_USE_COCOA:BOOL=ON"
        vopts="${vopts} -DCMAKE_INSTALL_NAME_DIR:PATH=${vtk_inst_path}/lib"
        if test "${MACOSX_DEPLOYMENT_TARGET}" = "10.10"; then
            # If building on 10.10 (Yosemite) check if we are building with Xcode 7 ...
            XCODE_VER=$(xcodebuild -version | head -n 1 | awk '{print $2}')
            if test ${XCODE_VER%.*} == 7; then
                # Workaround for Xcode 7 not having a 10.10 SDK: Prevent CMake from linking to 10.11 SDK
                # by using Frameworks installed in root directory.
                echo "Xcode 7 on MacOS 10.10 detected: Enabling CMake workaround"
                vopts="${vopts} -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=\"\" -DCMAKE_OSX_SYSROOT:STRING=/"
            fi
        fi
    fi

    # allow VisIt to override any of vtk's classes
    vopts="${vopts} -DVTK_ALL_NEW_OBJECT_FACTORY:BOOL=true"

    # Turn off module groups
    vopts="${vopts} -DVTK_Group_Imaging:BOOL=false"
    vopts="${vopts} -DVTK_Group_MPI:BOOL=false"
    vopts="${vopts} -DVTK_Group_Qt:BOOL=false"
    vopts="${vopts} -DVTK_Group_Rendering:BOOL=false"
    vopts="${vopts} -DVTK_Group_StandAlone:BOOL=false"
    vopts="${vopts} -DVTK_Group_Tk:BOOL=false"
    vopts="${vopts} -DVTK_Group_Views:BOOL=false"

    # Turn on individual modules. dependent modules are turned on automatically
    vopts="${vopts} -DModule_vtkCommonCore:BOOL=true"
    vopts="${vopts} -DModule_vtkFiltersFlowPaths:BOOL=true"
    vopts="${vopts} -DModule_vtkFiltersHybrid:BOOL=true"
    vopts="${vopts} -DModule_vtkFiltersModeling:BOOL=true"
    vopts="${vopts} -DModule_vtkGeovisCore:BOOL=true"
    vopts="${vopts} -DModule_vtkIOEnSight:BOOL=true"
    vopts="${vopts} -DModule_vtkIOGeometry:BOOL=true"
    vopts="${vopts} -DModule_vtkIOLegacy:BOOL=true"
    vopts="${vopts} -DModule_vtkIOPLY:BOOL=true"
    vopts="${vopts} -DModule_vtkIOXML:BOOL=true"
    vopts="${vopts} -DModule_vtkInteractionStyle:BOOL=true"
    vopts="${vopts} -DModule_vtkRenderingAnnotation:BOOL=true"
    vopts="${vopts} -DModule_vtkRenderingFreeType:BOOL=true"
    vopts="${vopts} -DModule_vtkRenderingFreeTypeOpenGL:BOOL=true"
    vopts="${vopts} -DModule_vtkRenderingOpenGL:BOOL=true"
    vopts="${vopts} -DModule_vtklibxml2:BOOL=true"

    # Tell VTK where to locate qmake if we're building graphical support. We
    # do not add graphical support for server-only builds.
    if [[ "$DO_DBIO_ONLY" != "yes" ]]; then
        if [[ "$DO_ENGINE_ONLY" != "yes" ]]; then
            if [[ "$DO_SERVER_COMPONENTS_ONLY" != "yes" ]]; then
                vopts="${vopts} -DModule_vtkGUISupportQtOpenGL:BOOL=true"
                vopts="${vopts} -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_BIN_DIR}/qmake"
                if [[ ${IS_QT5} == "yes" ]]; then
                    vopts="${vopts} -DVTK_QT_VERSION=5"
                    vopts="${vopts} -DCMAKE_PREFIX_PATH=${QT_INSTALL_DIR}/lib/cmake"
                fi
            fi
        fi
    fi

    # Add python wrapping
    if [[ "$DO_DBIO_ONLY" != "yes" ]]; then
        # python... but static libs and python filters are incompatible.
        if [[ "$DO_STATIC_BUILD" != "yes" ]]; then
            py="${PYTHON_COMMAND}"
            pyinc="${PYTHON_INCLUDE_DIR}"
            pylib="${PYTHON_LIBRARY}"

            vopts="${vopts} -DVTK_WRAP_PYTHON:BOOL=true"
            vopts="${vopts} -DPYTHON_EXECUTABLE:FILEPATH=${py}"
            vopts="${vopts} -DPYTHON_EXTRA_LIBS:STRING=${VTK_PY_LIBS}"
            vopts="${vopts} -DPYTHON_INCLUDE_DIR:PATH=${pyinc}"
            vopts="${vopts} -DPYTHON_LIBRARY:FILEPATH=${pylib}"
#            vopts="${vopts} -DPYTHON_UTIL_LIBRARY:FILEPATH="
        else
            warn "Forgetting python filters because we are doing a static build."
        fi
    fi

    # Add R support
    if test "$DO_R" = "yes" ; then
        vopts="${vopts} -DModule_vtkFiltersStatisticsGnuR:BOOL=true"
        vopts="${vopts} -DR_COMMAND:PATH=${R_INSTALL_DIR}/bin/R"
        vopts="${vopts} -DVTK_R_HOME:PATH=${R_INSTALL_DIR}/lib/R"
        vopts="${vopts} -DR_INCLUDE_DIR:PATH=${R_INSTALL_DIR}/lib/R/include"
        vopts="${vopts} -DR_LIBRARY_BASE:PATH=${R_INSTALL_DIR}/lib/R/lib/libR.${SO_EXT}"
        vopts="${vopts} -DR_LIBRARY_LAPACK:PATH=${R_INSTALL_DIR}/lib/R/lib/libRlapack.${SO_EXT}"
        vopts="${vopts} -DR_LIBRARY_BLAS:PATH=${R_INSTALL_DIR}/lib/R/lib/libRblas.${SO_EXT}"
    fi

    CMAKE_BIN="${CMAKE_INSTALL}/cmake"
    cd ${VTK_BUILD_DIR}

    #
    # Several platforms have had problems with the VTK cmake configure command
    # issued simply via "issue_command".  This was first discovered on 
    # BGQ and then showed up in random cases for both OSX and Linux machines. 
    # Brad resolved this on BGQ  with a simple work around - we write a simple 
    # script that we invoke with bash which calls cmake with all of the properly
    # arguments. We are now using this strategy for all platforms.
    #

    if test -e bv_run_cmake.sh ; then
        rm -f bv_run_cmake.sh
    fi
    echo "\"${CMAKE_BIN}\"" ${vopts} ../${VTK_SRC_DIR} > bv_run_cmake.sh
    cat bv_run_cmake.sh
    issue_command bash bv_run_cmake.sh || error "VTK configuration failed."


    #
    # Now build VTK.
    #
    info "Building VTK . . . (~20 minutes)"
    env DYLD_LIBRARY_PATH=`pwd`/bin $MAKE $MAKE_OPT_FLAGS || \
      error "VTK did not build correctly.  Giving up."

    info "Installing VTK . . . "
    $MAKE install || error "VTK did not install correctly."

    # Filter out an include that references the user's VTK build directory
    configdir="${vtk_inst_path}/lib/cmake/vtk-${VTK_SHORT_VERSION}"
    cat ${configdir}/VTKConfig.cmake | grep -v "vtkTestingMacros" > ${configdir}/VTKConfig.cmake.new
    mv ${configdir}/VTKConfig.cmake.new ${configdir}/VTKConfig.cmake

    chmod -R ug+w,a+rX ${VISITDIR}/${VTK_INSTALL_DIR}
    if [[ "$DO_GROUP" == "yes" ]] ; then
        chgrp -R ${GROUP} "$VISITDIR/${VTK_INSTALL_DIR}"
    fi
    cd "$START_DIR"
    info "Done with VTK"
    return 0
}

function bv_vtk_is_enabled
{
    if [[ $DO_VTK == "yes" ]]; then
        return 1
    fi
    return 0
}

function bv_vtk_is_installed
{
    if [[ "$USE_SYSTEM_VTK" == "yes" ]]; then
        return 1
    fi

    check_if_installed "$VTK_INSTALL_DIR" $VTK_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_vtk_build
{
    #
    # Build VTK
    #
    cd "$START_DIR"
    if [[ "$DO_VTK" == "yes" && "$USE_SYSTEM_VTK" == "no" ]] ; then
        check_if_installed $VTK_INSTALL_DIR $VTK_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping VTK build.  VTK is already installed."
        else
            info "Building VTK (~20 minutes)"
            build_vtk
            if [[ $? != 0 ]] ; then
                error "Unable to build or install VTK.  Bailing out."
            fi
        fi
        info "Done building VTK"
    fi
}

function bv_xdmf_initialize
{
export DO_XDMF="no"
export ON_XDMF="off"
}

function bv_xdmf_enable
{
DO_XDMF="yes"
ON_XDMF="on"

#xdmf is dependent on HDF5
DO_HDF5="yes"
ON_HDF5="on"
}

function bv_xdmf_disable
{
DO_XDMF="no"
ON_XDMF="off"
}

function bv_xdmf_depends_on
{
echo "cmake vtk hdf5"
}

function bv_xdmf_info
{
export XDMF_FILE=${XDMF_FILE:-"Xdmf-2.1.1.tar.gz"}
export XDMF_VERSION=${XDMF_VERSION:-"2.1.1"}
export XDMF_COMPATIBILITY_VERSION=${XDMF_COMPATIBILITY_VERSION:-"2.1.1"}
export XDMF_BUILD_DIR=${XDMF_BUILD_DIR:-"Xdmf"}
export XDMF_MD5_CHECKSUM="09e2afd3a1b7b3e7d650b860212a95d1"
export XDMF_SHA256_CHECKSUM=""
}

function bv_xdmf_print
{
  printf "%s%s\n" "XDMF_FILE=" "${XDMF_FILE}"
  printf "%s%s\n" "XDMF_VERSION=" "${XDMF_VERSION}"
  printf "%s%s\n" "XDMF_COMPATIBILITY_VERSION=" "${XDMF_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "XDMF_BUILD_DIR=" "${XDMF_BUILD_DIR}"
}

function bv_xdmf_print_usage
{
printf "\t\t%15s\n" "NOTE: not available for download from web" 
printf "%-15s %s [%s]\n" "--xdmf" "Build Xdmf" "$DO_XDMF"
}

function bv_xdmf_graphical
{
local graphical_out="Xdmf     $XDMF_VERSION($XDMF_FILE)    $ON_XDMF"
echo "$graphical_out"
}

function bv_xdmf_host_profile
{
    if [[ "$DO_XDMF" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## Xdmf" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_XDMF_DIR \${VISITHOME}/Xdmf/$XDMF_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_XDMF_LIBDEP HDF5_LIBRARY_DIR hdf5 ${VISIT_HDF5_LIBDEP} VTK_LIBRARY_DIRS vtklibxml2-\${VTK_MAJOR_VERSION}.\${VTK_MINOR_VERSION} ${VISIT_VTK_LIBDEP} TYPE STRING)"\
        >> $HOSTCONF
    fi
}

function bv_xdmf_ensure
{
    if [[ "$DO_XDMF" == "yes" ]] ; then
        ensure_built_or_ready "Xdmf" $XDMF_VERSION $XDMF_BUILD_DIR $XDMF_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_XDMF="no"
            error "Unable to build XDMF.  ${XDMF_FILE} not found."
        fi
    fi
}

function bv_xdmf_dry_run
{
  if [[ "$DO_XDMF" == "yes" ]] ; then
    echo "Dry run option not set for xdmf."
  fi
}


# *************************************************************************** #
#                         Function 8.19, build_xdmf                           #
# *************************************************************************** #

function build_xdmf
{
    CMAKE_BIN="${CMAKE_COMMAND}"

    #
    # Prepare build dir
    #
    prepare_build_dir $XDMF_BUILD_DIR $XDMF_FILE
    untarred_XDMF=$?
    if [[ $untarred_XDMF == -1 ]] ; then
       warn "Unable to prepare Xdmf Build Directory. Giving up"
       return 1
    fi

    # We need to patch the CMakeLists.txt so it uses our HDF5 by default
    # when we tell it to use the system versions.
    cd $XDMF_BUILD_DIR || error "Can't cd to Xdmf build dir."
    rm -f CMakeCache.txt #remove any CMakeCache that may have existed 
    # Configure Xdmf
    info "Executing CMake on Xdmf"
    if [[ "$DO_STATIC_BUILD" == "yes" ]]; then
        XDMF_SHARED_LIBS="OFF"
        LIBEXT="a"
    else
        XDMF_SHARED_LIBS="ON"
        LIBEXT="${SO_EXT}"
    fi

    ${CMAKE_BIN} -DCMAKE_INSTALL_PREFIX:PATH="$VISITDIR/Xdmf/${XDMF_VERSION}/${VISITARCH}"\
        -DCMAKE_BUILD_TYPE:STRING="${VISIT_BUILD_MODE}" \
        -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON \
        -DBUILD_SHARED_LIBS:BOOL=${XDMF_SHARED_LIBS}\
        -DCMAKE_CXX_FLAGS:STRING="${CXXFLAGS} ${CXX_OPT_FLAGS}"\
        -DCMAKE_CXX_COMPILER:STRING=${CXX_COMPILER}\
        -DCMAKE_C_FLAGS:STRING="${CFLAGS} ${C_OPT_FLAGS}"\
        -DCMAKE_C_COMPILER:STRING=${C_COMPILER}\
        -DBUILD_TESTING:BOOL=OFF \
        -DXDMF_BUILD_MPI:BOOL=OFF \
        -DXDMF_BUILD_VTK:BOOL=OFF \
        -DXDMF_BUILD_UTILS:BOOL=OFF \
        -DXDMF_SYSTEM_HDF5:BOOL=ON \
        -DHDF5_INCLUDE_PATH:PATH="$VISITDIR/hdf5/$HDF5_VERSION/$VISITARCH/include" \
        -DHDF5_LIBRARY:PATH="$VISITDIR/hdf5/$HDF5_VERSION/$VISITARCH/lib/libhdf5.${SO_EXT}" \
        -DXDMF_SYSTEM_ZLIB:BOOL=ON \
        -DZLIB_INCLUDE_PATH:PATH="$VISITDIR/${VTK_INSTALL_DIR}/$VTK_VERSION/$VISITARCH/include/vtk-${VTK_SHORT_VERSION}/vtklibz" \
        -DZLIB_LIBRARY:PATH="$VISITDIR/${VTK_INSTALL_DIR}/$VTK_VERSION/$VISITARCH/lib/libvtkzlib-${VTK_SHORT_VERSION}.${SO_EXT}" \
        -DXDMF_SYSTEM_LIBXML2:BOOL=ON \
        -DLIBXML2_INCLUDE_PATH:PATH="$VISITDIR/${VTK_INSTALL_DIR}/$VTK_VERSION/$VISITARCH/include/vtk-${VTK_SHORT_VERSION}/vtklibxml2" \
        -DLIBXML2_LIBRARY="$VISITDIR/${VTK_INSTALL_DIR}/$VTK_VERSION/$VISITARCH/lib/libvtklibxml2-${VTK_SHORT_VERSION}.${SO_EXT}" \
        .

    if [[ $? != 0 ]] ; then
       warn "Xdmf configure failed.  Giving up"
       return 1
    fi

    #
    # Build Xdmf
    #
    info "Building Xdmf . . . (~3 minutes)"

    $MAKE
    if [[ $? != 0 ]] ; then
       warn "Xdmf build failed.  Giving up"
       return 1
    fi

    # Install Xdmf
    info "Installing Xdmf"
    $MAKE install
    if [[ $? != 0 ]] ; then
       warn "Xdmf install failed.  Giving up"
       return 1
    fi

    if [[ "$DO_STATIC_BUILD" != "yes" && "$OPSYS" == "Darwin" ]]; then
        LIBDIR="$VISITDIR/Xdmf/${XDMF_VERSION}/${VISITARCH}/lib"
        install_name_tool -id $LIBDIR/libXdmf.dylib $LIBDIR/libXdmf.dylib
    fi


    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/Xdmf"
       chgrp -R ${GROUP} "$VISITDIR/Xdmf"
    fi

    cd "$START_DIR"
    info "Done with Xdmf"
    return 0
}

function bv_xdmf_is_enabled
{
    if [[ $DO_XDMF == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_xdmf_is_installed
{
    check_if_installed "Xdmf" $XDMF_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_xdmf_build
{
cd "$START_DIR"
if [[ "$DO_XDMF" == "yes" ]] ; then
    check_if_installed "Xdmf" $XDMF_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping Xdmf build.  Xdmf is already installed."
    else
        info "Building Xdmf (~2 minutes)"
        build_xdmf
        if [[ $? != 0 ]] ; then
            error "Unable to build or install Xdmf.  Bailing out."
        fi
        info "Done building Xdmf"
   fi
fi
}
function bv_xercesc_initialize
{
    export DO_XERCESC="no"
    export ON_XERCESC="off"
}

function bv_xercesc_enable
{
    DO_XERCESC="yes"
    ON_XERCESC="on"
}

function bv_xercesc_disable
{
    DO_XERCESC="no"
    ON_XERCESC="off"
}

function bv_xercesc_depends_on
{
    echo ""
}

function bv_xercesc_info
{
    export XERCESC_FILE=${XERCESC_FILE:-"xerces-c-3.1.2.tar.gz"}
    export XERCESC_VERSION=${XERCESC_VERSION:-"3.1.2"}
    export XERCESC_COMPATIBILITY_VERSION=${XERCESC_COMPATIBILITY_VERSION:-"3.1"}
    export XERCESC_BUILD_DIR=${XERCESC_BUILD_DIR:-"xerces-c-${XERCESC_VERSION}"}
    export XERCESC_URL=${XERCESC_URL:-"http://www.webhostingjams.com/mirror/apache//xerces/c/3/sources"}
    export XERCESC_MD5_CHECKSUM="9eb1048939e88d6a7232c67569b23985"
}

function bv_xercesc_print
{
    printf "%s%s\n" "XERCESC_FILE=" "${XERCESC_FILE}"
    printf "%s%s\n" "XERCESC_VERSION=" "${XERCESC_VERSION}"
    printf "%s%s\n" "XERCESC_COMPATIBILITY_VERSION=" "${XERCESC_COMPATIBILITY_VERSION}"
    printf "%s%s\n" "XERCESC_BUILD_DIR=" "${XERCESC_BUILD_DIR}"
    printf "%s%s\n" "XERCESC_URL=" "${XERCESC_URL}"
    printf "%s%s\n" "XERCESC_MD5_CHECKSUM=" "${XERCESC_MD5_CHECKSUM}"
}

function bv_xercesc_print_usage
{
    printf "%-15s %s [%s]\n" "--xercesc"   "Build XERCESC" "$DO_XERCESC"
}

function bv_xercesc_graphical
{
    local graphical_out="XERCESC    $XERCESC_VERSION($XERCESC_FILE)    $ON_XERCESC"
    echo $graphical_out
}

function bv_xercesc_host_profile
{
    if [[ "$DO_XERCESC" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## XERCESC" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_XERCESC_DIR \${VISITHOME}/xerces-c/$XERCESC_VERSION/\${VISITARCH})" \
    >> $HOSTCONF
    fi
}

function bv_xercesc_ensure
{
    if [[ "$DO_XERCESC" == "yes" ]] ; then
        ensure_built_or_ready "xerces-c" $XERCESC_VERSION $XERCESC_BUILD_DIR $XERCESC_FILE $XERCESC_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_XERCESC="no"
            error "Unable to build XERCESC.  ${XERCESC_FILE} not found."
        fi
    fi
}

function bv_xercesc_dry_run
{
   if [[ "$DO_XERCESC" == "yes" ]] ; then
     echo "Dry run option not set for Xerces-C"
   fi
}

function build_xercesc
{

    #
    # Prepare build dir
    #
    prepare_build_dir $XERCESC_BUILD_DIR $XERCESC_FILE
    untarred_xc=$?
    if [[ $untarred_xc == -1 ]] ; then
       warn "Unable to prepare Xerces-C build directory. Giving Up!"
       return 1
    fi

    #
    # Call configure
    #
    info "Configuring Xerces-C . . ."
    cd $XERCESC_BUILD_DIR || error "Can't cd to Xerces-C build dir."

    info "env CXX=$CXX_COMPILER CC=$C_COMPILER ./configure \
    --prefix=$VISITDIR/xerces-c/$XERCESC_VERSION/$VISITARCH \
    --disable-threads --disable-network --disable-shared \
    --enable-transcoder-iconv"
    
    env CXX=$CXX_COMPILER CC=$C_COMPILER ./configure \
    --prefix=$VISITDIR/xerces-c/$XERCESC_VERSION/$VISITARCH \
    --disable-threads --disable-network --disable-shared \
    --enable-transcoder-iconv

    if [[ $? != 0 ]] ; then
    warn "Xerces-C configuration failed. Giving up"
    return 1
    fi

    #
    # Build Xerces-C
    #
    info "Building Xerces-C . . . (~10 minute)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "Xerces-C build failed.  Giving up"
       return 1
    fi

    #
    # Install into the VisIt third party location
    #
    info "Installing Xerces-C"
    $MAKE install
    if [[ $? != 0 ]] ; then
       warn "Xerces-C install failed.  Giving up"
       return 1
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
     chmod -R ug+w,a+rX "$VISITDIR/xerces-c"
     chgrp -R ${GROUP} "$VISITDIR/xerces-c"
    fi
    cd "$START_DIR"
    return 0
}

function bv_xercesc_is_enabled
{
    if [[ $DO_XERCESC == "yes" ]]; then
        return 1
    fi
    return 0
}

function bv_xercesc_is_installed
{
    check_if_installed "xerces-c" $XERCESC_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_xercesc_build
{

    if [[ "$DO_XERCESC" == "yes" ]] ; then
        check_if_installed "xerces-c" $XERCESC_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping Xerces-C build.  Xerces-C is already installed."
        else
            build_xercesc
            if [[ $? != 0 ]] ; then
                error "Unable to build or install Xerces-C.  Bailing out."
            fi
            info "Done building Xerces-C"
       fi
    fi
}
function bv_xsd_initialize
{
    export DO_XSD="no"
    export ON_XSD="off"
}

function bv_xsd_enable
{ 
    DO_XSD="yes"
    ON_XSD="on"
}

function bv_xsd_disable
{
    DO_XSD="no"
    ON_XSD="off"
}

function bv_xsd_depends_on
{
    echo "xercesc"
}

function bv_xsd_info
{
    export XSD_FILE=${XSD_FILE:-"xsd-4.0.0+dep.tar.bz2"}
    export XSD_VERSION=${XSD_VERSION:-"4.0.0"}
    export XSD_COMPATIBILITY_VERSION=${XSD_COMPATIBILITY_VERSION:-"4.0"}
    export XSD_BUILD_DIR=${XSD_BUILD_DIR:-"xsd-${XSD_VERSION}+dep"}
    export XSD_URL=${XSD_URL:-"http://www.codesynthesis.com/download/xsd/4.0"}
    export XSD_SHA1_CHECKSUM="ad3de699eb140e747a0a214462d95fc81a21b494"
}

function bv_xsd_print
{
    printf "%s%s\n" "XSD_FILE=" "${XSD_FILE}"
    printf "%s%s\n" "XSD_VERSION=" "${XSD_VERSION}"
    printf "%s%s\n" "XSD_COMPATIBILITY_VERSION=" "${XSD_COMPATIBILITY_VERSION}"
    printf "%s%s\n" "XSD_BUILD_DIR=" "${XSD_BUILD_DIR}"
}

function bv_xsd_print_usage
{
    printf "%-15s %s [%s]\n" "--xsd"   "Build XSD" "$DO_XSD"
}

function bv_xsd_graphical
{
    local graphical_out="XSD    $XSD_VERSION($XSD_FILE)    $ON_XSD"
    echo $graphical_out
}

function bv_xsd_host_profile
{
    if [[ "$DO_XSD" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## XSD" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_XSD_DIR \${VISITHOME}/xsd/$XSD_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
    fi
}

function bv_xsd_ensure
{
    if [[ "$DO_XSD" == "yes" ]] ; then
        ensure_built_or_ready "XSD" $XSD_VERSION $XSD_BUILD_DIR $XSD_FILE $XSD_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_XSD="no"
            error "Unable to build XSD.  ${XSD_FILE} not found."
        fi
    fi
}

function bv_xsd_dry_run
{
  if [[ "$DO_XSD" == "yes" ]] ; then
    echo "Dry run option not set for XSD."
  fi
}

function  apply_xsd_patch
{  
    #for any future patches
    return 0
}


function build_xsd
{
    #
    # Prepare build dir
    #
    prepare_build_dir $XSD_BUILD_DIR $XSD_FILE
    untarred_xsd=$?
    if [[ $untarred_xsd == -1 ]] ; then
      warn "Unable to prepare XSD build directory. Giving Up!"
      return 1
    fi
    cd $XSD_BUILD_DIR/xsd

    #
    # For Damaris, we only need to install the XSD headers
    #
    mkdir -p $VISITDIR/xsd/$XSD_VERSION/$VISITARCH/include
    cp -r libxsd/xsd $VISITDIR/xsd/$XSD_VERSION/$VISITARCH/include/

    if [[ "$DO_GROUP" == "yes" ]] ; then
    chmod -R ug+w,a+rX "$VISITDIR/xsd"
    chgrp -R ${GROUP} "$VISITDIR/xsd"
    fi
    cd "$START_DIR"
    return 0
}

function bv_xsd_is_enabled
{
    if [[ $DO_XSD == "yes" ]]; then
        return 1
    fi
    return 0
}

function bv_xsd_is_installed
{
    check_if_installed "xsd" $XSD_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_xsd_build
{

    if [[ "$DO_XSD" == "yes" ]] ; then
        check_if_installed "xsd" $XSD_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping XSD build.  XSD is already installed."
        else
            build_xsd
            if [[ $? != 0 ]] ; then
                error "Unable to build or install XSD.  Bailing out."
            fi
            info "Done building XSD"
       fi
    fi
}
function bv_zlib_initialize
{
export DO_ZLIB="no"
export ON_ZLIB="off"
}

function bv_zlib_enable
{
DO_ZLIB="yes"
ON_ZLIB="on"
}

function bv_zlib_disable
{
DO_ZLIB="no"
ON_ZLIB="off"
}

function bv_zlib_depends_on
{
    local depends_on=""

    echo $depends_on
}

function bv_zlib_info
{
export ZLIB_VERSION=${ZLIB_VERSION:-"1.2.7"}
export ZLIB_FILE=${ZLIB_FILE:-"zlib-${ZLIB_VERSION}.tar.gz"}
export ZLIB_COMPATIBILITY_VERSION=${ZLIB_COMPATIBILITY_VERSION:-"1.2"}
export ZLIB_BUILD_DIR=${ZLIB_BUILD_DIR:-"zlib-${ZLIB_VERSION}"}
export ZLIB_URL=${ZLIB_URL:-https://wci.llnl.gov/codes/zlib/zlib-${ZLIB_VERSION}}
export ZLIB_MD5_CHECKSUM=""
export ZLIB_SHA256_CHECKSUM=""
}

function bv_zlib_print
{
  printf "%s%s\n" "ZLIB_FILE=" "${ZLIB_FILE}"
  printf "%s%s\n" "ZLIB_VERSION=" "${ZLIB_VERSION}"
  printf "%s%s\n" "ZLIB_COMPATIBILITY_VERSION=" "${ZLIB_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "ZLIB_BUILD_DIR=" "${ZLIB_BUILD_DIR}"
}

function bv_zlib_print_usage
{
printf "%-15s %s [%s]\n" "--zlib" "Build ZLIB support" "$DO_ZLIB"
}

function bv_zlib_graphical
{
local graphical_out="ZLIB     $ZLIB_VERSION($ZLIB_FILE)      $ON_ZLIB"
echo "$graphical_out"
}

function bv_zlib_host_profile
{
    if [[ "$DO_ZLIB" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## ZLIB" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_ZLIB_DIR \${VISITHOME}/zlib/$ZLIB_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
    fi
}

function bv_zlib_ensure
{
    if [[ "$DO_ZLIB" == "yes" ]] ; then
        ensure_built_or_ready "zlib" $ZLIB_VERSION $ZLIB_BUILD_DIR $ZLIB_FILE $ZLIB_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_ZLIB="no"
            error "Unable to build ZLIB.  ${ZLIB_FILE} not found."
        fi
    fi
}

function bv_zlib_dry_run
{
  if [[ "$DO_ZLIB" == "yes" ]] ; then
    echo "Dry run option not set for zlib."
  fi
}

# *************************************************************************** #
#                            Function 8, build_zlib
#
# Modfications:
#
# *************************************************************************** #

function build_zlib
{
    #
    # Prepare build dir
    #
    prepare_build_dir $ZLIB_BUILD_DIR $ZLIB_FILE
    untarred_zlib=$?
    if [[ $untarred_zlib == -1 ]] ; then
       warn "Unable to prepare ZLIB build directory. Giving Up!"
       return 1
    fi
    
    #
    # Call configure
    #
    info "Configuring ZLIB . . ."
    cd $ZLIB_BUILD_DIR || error "Can't cd to ZLIB build dir."
    info "Invoking command to configure ZLIB"

    STATICARGS="--static"
    if [[ "$DO_STATIC_BUILD" == "no" ]] ; then
        STATICARGS=""
    fi

    info "env CXX=$CXX_COMPILER CC=$C_COMPILER ./configure \
        --prefix=$VISITDIR/zlib/$ZLIB_VERSION/$VISITARCH $STATICARGS"

    # Call configure
    env CXX=$CXX_COMPILER CC=$C_COMPILER ./configure \
        --prefix=$VISITDIR/zlib/$ZLIB_VERSION/$VISITARCH $STATICARGS

    if [[ $? != 0 ]] ; then
       warn "ZLIB configure failed.  Giving up"
       return 1
    fi

    #
    # Build ZLIB
    #
    info "Building ZLIB . . . (~1 minute)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "ZLIB build failed.  Giving up"
       return 1
    fi
    #
    # Install into the VisIt third party location.
    #
    info "Installing ZLIB"
    $MAKE install
    if [[ $? != 0 ]] ; then
        warn "ZLIB install failed.  Giving up"
        return 1
    fi

    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/zlib"
       chgrp -R ${GROUP} "$VISITDIR/zlib"
    fi
    cd "$START_DIR"
    info "Done with ZLIB"
    return 0
}

function bv_zlib_is_enabled
{
    if [[ $DO_ZLIB == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_zlib_is_installed
{
    check_if_installed "zlib" $ZLIB_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_zlib_build
{
cd "$START_DIR"
if [[ "$DO_ZLIB" == "yes" ]] ; then
    check_if_installed "zlib" $ZLIB_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping ZLIB build.  ZLIB is already installed."
    else
        info "Building ZLIB (~1 minute)"
        build_zlib
        if [[ $? != 0 ]] ; then
            error "Unable to build or install ZLIB.  Bailing out."
        fi
        info "Done building ZLIB"
    fi
fi
}

xmlp_filecontents[0]="<modules>"
xmlp_filecontents[1]="<license name=\"bsd|mit|lgpl\">"
xmlp_filecontents[2]="<required>"
xmlp_filecontents[3]="<lib name=\"cmake\"/>"
xmlp_filecontents[4]="<lib name=\"python\"/>"
xmlp_filecontents[5]="<lib name=\"mesa\"/>"
xmlp_filecontents[6]="<lib name=\"vtk\"/>"
xmlp_filecontents[7]="<lib name=\"qt\"/>"
xmlp_filecontents[8]="</required>"
xmlp_filecontents[9]="<optional>"
xmlp_filecontents[10]="<lib name=\"adios\"/>"
xmlp_filecontents[11]="<lib name=\"advio\"/>"
xmlp_filecontents[12]="<lib name=\"boost\"/>"
xmlp_filecontents[13]="<lib name=\"boxlib\"/>"
xmlp_filecontents[14]="<lib name=\"ccmio\"/>"
xmlp_filecontents[15]="<lib name=\"cfitsio\"/>"
xmlp_filecontents[16]="<lib name=\"cgns\"/>"
xmlp_filecontents[17]="<lib name=\"eavl\"/>"
xmlp_filecontents[18]="<lib name=\"visus\"/>"
xmlp_filecontents[19]="<lib name=\"fastbit\"/>"
xmlp_filecontents[20]="<lib name=\"gdal\"/>"
xmlp_filecontents[21]="<lib name=\"h5part\"/>"
xmlp_filecontents[22]="<lib name=\"hdf4\"/>"
xmlp_filecontents[23]="<lib name=\"hdf5\"/>"
xmlp_filecontents[24]="<lib name=\"icet\"/>"
xmlp_filecontents[25]="<lib name=\"itaps\"/>"
xmlp_filecontents[26]="<lib name=\"mfem\"/>"
xmlp_filecontents[27]="<lib name=\"mili\"/>"
xmlp_filecontents[28]="<lib name=\"manta\"/>"
xmlp_filecontents[29]="<lib name=\"mpich\"/>"
xmlp_filecontents[30]="<lib name=\"mxml\"/>"
xmlp_filecontents[31]="<lib name=\"nektarpp\"/>"
xmlp_filecontents[32]="<lib name=\"netcdf\"/>"
xmlp_filecontents[33]="<lib name=\"pyside\"/>"
xmlp_filecontents[34]="<lib name=\"uintah\"/>"
xmlp_filecontents[35]="<lib name=\"silo\"/>"
xmlp_filecontents[36]="<lib name=\"szip\"/>"
xmlp_filecontents[37]="<lib name=\"tcmalloc\"/>"
xmlp_filecontents[38]="<lib name=\"xdmf\"/>"
xmlp_filecontents[39]="<lib name=\"zlib\"/>"
xmlp_filecontents[40]="</optional>"
xmlp_filecontents[41]="<group name=\"required\" comment=\"All required libraries\">"
xmlp_filecontents[42]="<lib name=\"cmake\"/>"
xmlp_filecontents[43]="<lib name=\"python\"/>"
xmlp_filecontents[44]="<lib name=\"mesa\"/>"
xmlp_filecontents[45]="<lib name=\"vtk\"/>"
xmlp_filecontents[46]="<lib name=\"qt\"/>"
xmlp_filecontents[47]="</group>"
xmlp_filecontents[48]="<group name=\"optional\" comment=\"All optional libraries\">"
xmlp_filecontents[49]="<lib name=\"adios\"/>"
xmlp_filecontents[50]="<lib name=\"advio\"/>"
xmlp_filecontents[51]="<lib name=\"boost\"/>"
xmlp_filecontents[52]="<lib name=\"boxlib\"/>"
xmlp_filecontents[53]="<lib name=\"ccmio\"/>"
xmlp_filecontents[54]="<lib name=\"cfitsio\"/>"
xmlp_filecontents[55]="<lib name=\"cgns\"/>"
xmlp_filecontents[56]="<lib name=\"gdal\"/>"
xmlp_filecontents[57]="<lib name=\"fastbit\"/>"
xmlp_filecontents[58]="<lib name=\"hdf5\"/>"
xmlp_filecontents[59]="<lib name=\"h5part\"/>"
xmlp_filecontents[60]="<lib name=\"mpich\"/>"
xmlp_filecontents[61]="<lib name=\"mxml\"/>"
xmlp_filecontents[62]="<lib name=\"netcdf\"/>"
xmlp_filecontents[63]="<lib name=\"nektarpp\"/>"
xmlp_filecontents[64]="<lib name=\"pyside\"/>"
xmlp_filecontents[65]="<lib name=\"silo\"/>"
xmlp_filecontents[66]="<lib name=\"szip\"/>"
xmlp_filecontents[67]="<lib name=\"visus\"/>"
xmlp_filecontents[68]="<lib name=\"uintah\"/>"
xmlp_filecontents[69]="<lib name=\"xdmf\"/>"
xmlp_filecontents[70]="<lib name=\"zlib\"/>"
xmlp_filecontents[71]="</group>"
xmlp_filecontents[72]="<group name=\"no-thirdparty\" comment=\"Do not build required 3rd party libraries\">"
xmlp_filecontents[73]="<lib name=\"no-cmake\"/>"
xmlp_filecontents[74]="<lib name=\"no-python\"/>"
xmlp_filecontents[75]="<lib name=\"no-pyside\"/>"
xmlp_filecontents[76]="<lib name=\"no-qt\" />"
xmlp_filecontents[77]="<lib name=\"no-vtk\"/>"
xmlp_filecontents[78]="</group>"
xmlp_filecontents[79]="<group name=\"all-io\" comment=\"Build all available I/O libraries\">"
xmlp_filecontents[80]="<lib name=\"adios\"/>"
xmlp_filecontents[81]="<lib name=\"boxlib\"/>"
xmlp_filecontents[82]="<lib name=\"ccmio\"/>"
xmlp_filecontents[83]="<lib name=\"cfitsio\"/>"
xmlp_filecontents[84]="<lib name=\"cgns\"/>"
xmlp_filecontents[85]="<lib name=\"fastbit\"/>"
xmlp_filecontents[86]="<lib name=\"gdal\"/>"
xmlp_filecontents[87]="<lib name=\"h5part\"/>"
xmlp_filecontents[88]="<lib name=\"hdf5\"/>"
xmlp_filecontents[89]="<lib name=\"mxml\"/>"
xmlp_filecontents[90]="<lib name=\"netcdf\"/>"
xmlp_filecontents[91]="<lib name=\"nektarpp\"/>"
xmlp_filecontents[92]="<lib name=\"silo\"/>"
xmlp_filecontents[93]="<lib name=\"szip\"/>"
xmlp_filecontents[94]="<lib name=\"visus\"/>"
xmlp_filecontents[95]="<lib name=\"uintah\"/>"
xmlp_filecontents[96]="<lib name=\"xdmf\"/>"
xmlp_filecontents[97]="</group>"
xmlp_filecontents[98]="<group name=\"dbio-only\" comment=\"Disables EVERYTHING but I/O.\">"
xmlp_filecontents[99]="<lib name=\"adios\"/>"
xmlp_filecontents[100]="<lib name=\"advio\"/>"
xmlp_filecontents[101]="<lib name=\"boxlib\"/>"
xmlp_filecontents[102]="<lib name=\"ccmio\"/>"
xmlp_filecontents[103]="<lib name=\"cfitsio\"/>"
xmlp_filecontents[104]="<lib name=\"cgns\"/>"
xmlp_filecontents[105]="<lib name=\"fastbit\"/>"
xmlp_filecontents[106]="<lib name=\"gdal\"/>"
xmlp_filecontents[107]="<lib name=\"h5part\"/>"
xmlp_filecontents[108]="<lib name=\"hdf5\"/>"
xmlp_filecontents[109]="<lib name=\"mxml\"/>"
xmlp_filecontents[110]="<lib name=\"netcdf\"/>"
xmlp_filecontents[111]="<lib name=\"nektarpp\"/>"
xmlp_filecontents[112]="<lib name=\"silo\"/>"
xmlp_filecontents[113]="<lib name=\"szip\"/>"
xmlp_filecontents[114]="<lib name=\"visus\"/>"
xmlp_filecontents[115]="<lib name=\"uintah\"/>"
xmlp_filecontents[116]="<lib name=\"xdmf\"/>"
xmlp_filecontents[117]="<lib name=\"no-mesa\"/>"
xmlp_filecontents[118]="<lib name=\"no-qt\"/>"
xmlp_filecontents[119]="<lib name=\"no-python\"/>"
xmlp_filecontents[120]="</group>"
xmlp_filecontents[121]="<group name=\"nonio\" comment=\"Build non I/O libraries\">"
xmlp_filecontents[122]="<lib name=\"icet\"/>"
xmlp_filecontents[123]="<lib name=\"mesa\"/>"
xmlp_filecontents[124]="</group>"
xmlp_filecontents[125]="<group name=\"advanced\" comment=\"Must be manually downloaded\">"
xmlp_filecontents[126]="<lib name=\"hdf4\"/>"
xmlp_filecontents[127]="<lib name=\"itaps\"/>"
xmlp_filecontents[128]="<lib name=\"mili\"/>"
xmlp_filecontents[129]="<lib name=\"tcmalloc\"/>"
xmlp_filecontents[130]="</group>"
xmlp_filecontents[131]="</license>"
xmlp_filecontents[132]="<license name=\"gpl\">"
xmlp_filecontents[133]="<required>"
xmlp_filecontents[134]="<lib name=\"cmake\"/>"
xmlp_filecontents[135]="<lib name=\"python\"/>"
xmlp_filecontents[136]="<lib name=\"mesa\"/>"
xmlp_filecontents[137]="<lib name=\"R\"/>"
xmlp_filecontents[138]="<lib name=\"vtk\"/>"
xmlp_filecontents[139]="<lib name=\"qt\"/>"
xmlp_filecontents[140]="</required>"
xmlp_filecontents[141]="<optional>"
xmlp_filecontents[142]="<lib name=\"boost\"/>"
xmlp_filecontents[143]="<lib name=\"szip\"/>"
xmlp_filecontents[144]="<lib name=\"netcdf\"/>"
xmlp_filecontents[145]="<lib name=\"hdf5\"/>"
xmlp_filecontents[146]="<lib name=\"icet\"/>"
xmlp_filecontents[147]="<lib name=\"mpich\"/>"
xmlp_filecontents[148]="<lib name=\"pyqt\"/>"
xmlp_filecontents[149]="<lib name=\"uintah\"/>"
xmlp_filecontents[150]="<lib name=\"damaris\"/>"
xmlp_filecontents[151]="<lib name=\"xercesc\"/>"
xmlp_filecontents[152]="<lib name=\"xsd\"/>"
xmlp_filecontents[153]="</optional>"
xmlp_filecontents[154]="<group name=\"required\" comment=\"All required libraries\">"
xmlp_filecontents[155]="<lib name=\"cmake\"/>"
xmlp_filecontents[156]="<lib name=\"python\"/>"
xmlp_filecontents[157]="<lib name=\"mesa\"/>"
xmlp_filecontents[158]="<lib name=\"R\"/>"
xmlp_filecontents[159]="<lib name=\"vtk\"/>"
xmlp_filecontents[160]="<lib name=\"qt\"/>"
xmlp_filecontents[161]="</group>"
xmlp_filecontents[162]="<group name=\"optional\" comment=\"All optional libraries\">"
xmlp_filecontents[163]="<lib name=\"boost\"/>"
xmlp_filecontents[164]="<lib name=\"hdf5\"/>"
xmlp_filecontents[165]="<lib name=\"netcdf\"/>"
xmlp_filecontents[166]="<lib name=\"mpich\"/>"
xmlp_filecontents[167]="<lib name=\"szip\"/>"
xmlp_filecontents[168]="<lib name=\"uintah\"/>"
xmlp_filecontents[169]="<lib name=\"damaris\"/>"
xmlp_filecontents[170]="<lib name=\"xercesc\"/>"
xmlp_filecontents[171]="<lib name=\"xsd\"/>"
xmlp_filecontents[172]="</group>"
xmlp_filecontents[173]="<group name=\"no-thirdparty\" comment=\"Do not build required 3rd party libraries\">"
xmlp_filecontents[174]="<lib name=\"no-cmake\"/>"
xmlp_filecontents[175]="<lib name=\"no-python\"/>"
xmlp_filecontents[176]="<lib name=\"no-qt\" />"
xmlp_filecontents[177]="<lib name=\"no-vtk\"/>"
xmlp_filecontents[178]="</group>"
xmlp_filecontents[179]="<group name=\"dbio-only\" comment=\"Disables EVERYTHING but I/O.\">"
xmlp_filecontents[180]="<lib name=\"hdf5\"/>"
xmlp_filecontents[181]="<lib name=\"netcdf\"/>"
xmlp_filecontents[182]="<lib name=\"szip\"/>"
xmlp_filecontents[183]="<lib name=\"uintah\"/>"
xmlp_filecontents[184]="<lib name=\"no-mesa\"/>"
xmlp_filecontents[185]="<lib name=\"no-python\"/>"
xmlp_filecontents[186]="<lib name=\"no-qt\"/>"
xmlp_filecontents[187]="</group>"
xmlp_filecontents[188]="<group name=\"all-io\" comment=\"Build all available I/O libraries\">"
xmlp_filecontents[189]="<lib name=\"hdf5\"/>"
xmlp_filecontents[190]="<lib name=\"netcdf\"/>"
xmlp_filecontents[191]="<lib name=\"szip\"/>"
xmlp_filecontents[192]="<lib name=\"uintah\"/>"
xmlp_filecontents[193]="</group>"
xmlp_filecontents[194]="<group name=\"nonio\" comment=\"Build non I/O libraries\">"
xmlp_filecontents[195]="<lib name=\"icet\"/>"
xmlp_filecontents[196]="<lib name=\"mesa\"/>"
xmlp_filecontents[197]="</group>"
xmlp_filecontents[198]="</license>"
xmlp_filecontents[199]="</modules>"
xmlp_licenses[0]="bsd|mit|lgpl"
xmlp_licenses_range[0]="1 131"
xmlp_licenses[1]="gpl"
xmlp_licenses_range[1]="132 198"
defaultLicenses=$(xmlp_get_license "$@")
for license in `echo $defaultLicenses`
do
  info "Processing $license license."
  parseXmlModuleContents $license
  reqlibs=(`echo "${reqlibs[@]} ${xmlp_reqlibs[@]}" | xargs -n 1 | sort -u | xargs`)
  optlibs=(`echo "${optlibs[@]} ${xmlp_optlibs[@]}" | xargs -n 1 | sort -u | xargs`)
for (( bv_i = 0; bv_i < ${#xmlp_grouplibs_name[*]}; ++bv_i ))
do
  match=0
  for (( bv_j = 0; bv_j < ${#grouplibs_name[*]}; ++bv_j ))
  do
    if [[ "${grouplibs_name[$bv_j]}" == "${xmlp_grouplibs_name[$bv_i]}" ]]; then
      match=1
      grouplibs_deps[$bv_j]=`echo "${grouplibs_deps[$bv_j]} ${xmlp_grouplibs_deps[$bv_i]}" | xargs -n 1 | sort -u | xargs`
      break
    fi
  done
  if [[ match -eq 0 ]]; then
    grouplibs_name[${#grouplibs_name[*]}]="${xmlp_grouplibs_name[$bv_i]}"
    grouplibs_deps[${#grouplibs_deps[*]}]="${xmlp_grouplibs_deps[$bv_i]}"
    grouplibs_comment[${#grouplibs_comment[*]}]="${xmlp_grouplibs_comment[$bv_i]}"
  fi
  done
done
check_default_args () 
{ 
    for arg in "$@";
    do
        if [[ "$arg" == "-h" || "$arg" == "--help" ]]; then
            usage;
            exit 2;
        fi;
        if [[ "$arg" == "--write-unified-file" ]]; then
            next_arg="write-unified-file";
        else
            if [[ "$next_arg" == "write-unified-file" ]]; then
                bv_write_unified_file "$arg";
                exit 0;
            fi;
        fi;
    done
}
function bv_write_unified_file
{
  echo "Writing to File: $@"
  cat $0 > $@
  cat $0 > $@
  chmod 755 $@
}
check_for_versioning "$@"
if [[ "$build_version" != "" ]]; then
    call_build_visit
fi
check_default_args "$@"
initialize_build_visit
run_build_visit "$@"
