#!/bin/bash
export VISIT_VERSION=${VISIT_VERSION:-"3.1.0"}
export TRUNK_BUILD="no"
export RC_BUILD="no"
export TAGGED_BUILD="yes"
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/tools/dev/scripts/bv_support/"
export nerscroot="http://portal.nersc.gov/project/visit/releases"
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/tools/dev/scripts/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;
        bv_PREFIX=$PWD/bv_support;
        webaddr="$webroot/tags/$build_version/src/tools/dev/scripts/bv_support/";
        echo "rerouting support from $webaddr";
        configure_support_files;
        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
}
# --------------------------------------------------------------------------- #
#   checking compiler minimum version                                         #
# --------------------------------------------------------------------------- #
function vercomp ()
{
    if [[ $1 == $2 ]]
    then
        return 0
    fi
    local IFS=.
    local i ver1=($1) ver2=($2)
    # fill empty fields in ver1 with zeros
    for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
    do
        ver1[i]=0
    done
    for ((i=0; i<${#ver1[@]}; i++))
    do
        if [[ -z ${ver2[i]} ]]
        then
            # fill empty fields in ver2 with zeros
            ver2[i]=0
        fi
        if [[ 10#${ver1[i]} > 10#${ver2[i]} ]]
        then
            return 1
        fi
        if [[ 10#${ver1[i]} < 10#${ver2[i]} ]]
        then
            return 2
        fi
    done
    return 0
}

function testvercomp ()
{
    vercomp $1 $2
    case $? in
        0) op='=';;
        1) op='>';;
        2) op='<';;
    esac
    if [[ $op != $3 ]]
    then
        return 1
    else
        return 0
    fi
}

function check_minimum_compiler_version()
{
   if [[ "$CXX_COMPILER" == "g++" ]] ; then
        VERSION=$(g++ -v 2>&1 | grep "gcc version" | cut -d' ' -f3 )
        echo "g++ version $VERSION"
        testvercomp $VERSION 4.8 '<'
        if [[ $? == 0 ]] ; then
            echo "Need g++ version >= 4.8"
            exit 1
        fi
    elif [[ "$OPSYS" == "Darwin"  &&  "$CXX_COMPILER" == "clang++" ]] ; then 
        VERSION=$(clang++ -v 2>&1 | grep "clang version" | cut -d' ' -f3 )
        echo "apple clang version $VERSION"
        testvercomp $VERSION 5.0 '<'
        if [[ $? == 0 ]] ; then
            echo "Need clang++ version >= 0.0"
            exit 1
        fi
    elif [[ "$CXX_COMPILER" == "clang++" ]] ; then 
        VERSION=$(clang++ -v 2>&1 | grep "clang version" | cut -d' ' -f3 )
        echo "clang version $VERSION"
        testvercomp $VERSION 3.3 '<'
        if [[ $? == 0 ]] ; then
            echo "Need clang++ version >= 3.3"
            exit 1
        fi
    elif [[ "$CXX_COMPILER" == "icpc" ]] ; then 
        VERSION=$(icpc -v 2>&1 | grep "icpc version" | cut -d' ' -f3 )
        if [[ $VERSION == "" ]] ; then
            VERSION=$(icpc -v 2>&1 | grep "icpc.orig version" | cut -d' ' -f3 )
        fi
        echo "icpc version $VERSION"
        testvercomp $VERSION 14.0 '<'
        if [[ $? == 0 ]] ; then
            echo "Need icpc version >= 14.0"
            exit 1
        fi
    fi
}

# --------------------------------------------------------------------------- #
#   checking opengl context creation (minimum required is 3.2)
# --------------------------------------------------------------------------- #

function check_opengl_context()
{
    # Check if we can create a 3.2 context with system gl
    echo "#include <GL/gl.h>" >> checkogl.cpp
    echo "#include <GL/glx.h>" >> checkogl.cpp
    echo "#include <cstring>" >> checkogl.cpp
    echo "#include <cstdlib>" >> checkogl.cpp
    echo "#define GLX_CONTEXT_MAJOR_VERSION_ARB       0x2091" >> checkogl.cpp
    echo "#define GLX_CONTEXT_MINOR_VERSION_ARB       0x2092" >> checkogl.cpp
    echo "typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);" >> checkogl.cpp
    echo "static bool isExtensionSupported(const char *extList, const char *extension) {" >> checkogl.cpp
    echo "  const char *start;" >> checkogl.cpp
    echo "  const char *where, *terminator;" >> checkogl.cpp
    echo "  where = strchr(extension, ' ');" >> checkogl.cpp
    echo "  if (where || *extension == '\0')" >> checkogl.cpp
    echo "    return false;" >> checkogl.cpp
    echo "  for (start=extList;;) {" >> checkogl.cpp
    echo "    where = strstr(start, extension);" >> checkogl.cpp
    echo "    if (!where)" >> checkogl.cpp
    echo "      break;" >> checkogl.cpp
    echo "    terminator = where + strlen(extension);" >> checkogl.cpp
    echo "    if ( where == start || *(where - 1) == ' ' )" >> checkogl.cpp
    echo "      if ( *terminator == ' ' || *terminator == '\0' )" >> checkogl.cpp
    echo "        return true;" >> checkogl.cpp
    echo "    start = terminator;" >> checkogl.cpp
    echo "  }" >> checkogl.cpp
    echo "  return false;" >> checkogl.cpp
    echo "}" >> checkogl.cpp
    echo "static bool ctxErrorOccurred = false;" >> checkogl.cpp
    echo "static int ctxErrorHandler( Display *dpy, XErrorEvent *ev )" >> checkogl.cpp
    echo "{" >> checkogl.cpp
    echo "    ctxErrorOccurred = true;" >> checkogl.cpp
    echo "    return 0;" >> checkogl.cpp
    echo "}" >> checkogl.cpp
    echo "int main(int argc, char* argv[])" >> checkogl.cpp
    echo "{" >> checkogl.cpp
    echo "  Display *display = XOpenDisplay(NULL);" >> checkogl.cpp
    echo "  if (!display)" >> checkogl.cpp
    echo " {" >> checkogl.cpp
    echo "    exit(1);" >> checkogl.cpp
    echo "  }" >> checkogl.cpp
    echo "  static int visual_attribs[] =" >> checkogl.cpp
    echo "    {" >> checkogl.cpp
    echo "      GLX_X_RENDERABLE    , True," >> checkogl.cpp
    echo "      GLX_DRAWABLE_TYPE   , GLX_WINDOW_BIT," >> checkogl.cpp
    echo "      GLX_RENDER_TYPE     , GLX_RGBA_BIT," >> checkogl.cpp
    echo "      GLX_X_VISUAL_TYPE   , GLX_TRUE_COLOR," >> checkogl.cpp
    echo "      GLX_RED_SIZE        , 8," >> checkogl.cpp
    echo "      GLX_GREEN_SIZE      , 8," >> checkogl.cpp
    echo "      GLX_BLUE_SIZE       , 8," >> checkogl.cpp
    echo "      GLX_ALPHA_SIZE      , 8," >> checkogl.cpp
    echo "      GLX_DEPTH_SIZE      , 24," >> checkogl.cpp
    echo "      GLX_STENCIL_SIZE    , 8," >> checkogl.cpp
    echo "      GLX_DOUBLEBUFFER    , True," >> checkogl.cpp
    echo "      //GLX_SAMPLE_BUFFERS  , 1," >> checkogl.cpp
    echo "      //GLX_SAMPLES         , 4," >> checkogl.cpp
    echo "      None" >> checkogl.cpp
    echo "    };" >> checkogl.cpp
    echo "  int glx_major, glx_minor;" >> checkogl.cpp
    echo "  if ( !glXQueryVersion( display, &glx_major, &glx_minor ) || ( ( glx_major == 1 ) && ( glx_minor < 3 ) ) || ( glx_major < 1 ) )" >> checkogl.cpp
    echo "  {" >> checkogl.cpp
    echo "    exit(1);" >> checkogl.cpp
    echo "  }" >> checkogl.cpp
    echo "  int fbcount;" >> checkogl.cpp
    echo "  GLXFBConfig* fbc = glXChooseFBConfig(display, DefaultScreen(display), visual_attribs, &fbcount);" >> checkogl.cpp
    echo "  if (!fbc)" >> checkogl.cpp
    echo "  {" >> checkogl.cpp
    echo "    exit(1);" >> checkogl.cpp
    echo "  }" >> checkogl.cpp
    echo "  int best_fbc = -1, worst_fbc = -1, best_num_samp = -1, worst_num_samp = 999;" >> checkogl.cpp
    echo "  int i;" >> checkogl.cpp
    echo "  for (i=0; i<fbcount; ++i)" >> checkogl.cpp
    echo "  {" >> checkogl.cpp
    echo "    XVisualInfo *vi = glXGetVisualFromFBConfig( display, fbc[i] );" >> checkogl.cpp
    echo "    if ( vi )" >> checkogl.cpp
    echo "    {" >> checkogl.cpp
    echo "      int samp_buf, samples;" >> checkogl.cpp
    echo "      glXGetFBConfigAttrib( display, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf );" >> checkogl.cpp
    echo "      glXGetFBConfigAttrib( display, fbc[i], GLX_SAMPLES       , &samples  );" >> checkogl.cpp
    echo "      if ( best_fbc < 0 || samp_buf && samples > best_num_samp )" >> checkogl.cpp
    echo "        best_fbc = i, best_num_samp = samples;" >> checkogl.cpp
    echo "      if ( worst_fbc < 0 || !samp_buf || samples < worst_num_samp )" >> checkogl.cpp
    echo "        worst_fbc = i, worst_num_samp = samples;" >> checkogl.cpp
    echo "    }" >> checkogl.cpp
    echo "    XFree( vi );" >> checkogl.cpp
    echo "  }" >> checkogl.cpp
    echo "  GLXFBConfig bestFbc = fbc[ best_fbc ];" >> checkogl.cpp
    echo "  XFree( fbc );" >> checkogl.cpp
    echo "  XVisualInfo *vi = glXGetVisualFromFBConfig( display, bestFbc );" >> checkogl.cpp
    echo "  XSetWindowAttributes swa;" >> checkogl.cpp
    echo "  Colormap cmap;" >> checkogl.cpp
    echo "  swa.colormap = cmap = XCreateColormap( display, RootWindow( display, vi->screen ), vi->visual, AllocNone );" >> checkogl.cpp
    echo "  swa.background_pixmap = None ;" >> checkogl.cpp
    echo "  swa.border_pixel      = 0;" >> checkogl.cpp
    echo "  swa.event_mask        = StructureNotifyMask;" >> checkogl.cpp
    echo "  Window win = XCreateWindow( display, RootWindow( display, vi->screen ), 0, 0, 100, 100, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel|CWColormap|CWEventMask, &swa );" >> checkogl.cpp
    echo "  if ( !win )" >> checkogl.cpp
    echo "  {" >> checkogl.cpp
    echo "    exit(1);" >> checkogl.cpp
    echo " }" >> checkogl.cpp
    echo "  XFree( vi );" >> checkogl.cpp
    echo "  XStoreName( display, win, \"GL 3.0 Window\" );" >> checkogl.cpp
    echo "  XMapWindow( display, win );" >> checkogl.cpp
    echo "  const char *glxExts = glXQueryExtensionsString( display, DefaultScreen( display ) );" >> checkogl.cpp
    echo "  glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;" >> checkogl.cpp
    echo "  glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) \"glXCreateContextAttribsARB\" );" >> checkogl.cpp
    echo "  GLXContext ctx = 0;" >> checkogl.cpp
    echo "  ctxErrorOccurred = false;" >> checkogl.cpp
    echo "  int (*oldHandler)(Display*, XErrorEvent*) = XSetErrorHandler(&ctxErrorHandler);" >> checkogl.cpp
    echo "  if ( !isExtensionSupported( glxExts, \"GLX_ARB_create_context\" ) || !glXCreateContextAttribsARB )" >> checkogl.cpp
    echo "  {" >> checkogl.cpp
    echo "      exit(1);" >> checkogl.cpp
    echo "  }" >> checkogl.cpp
    echo "  else" >> checkogl.cpp
    echo "  {" >> checkogl.cpp
    echo "    int context_attribs[] =" >> checkogl.cpp
    echo "      {" >> checkogl.cpp
    echo "        GLX_CONTEXT_MAJOR_VERSION_ARB, 3," >> checkogl.cpp
    echo "        GLX_CONTEXT_MINOR_VERSION_ARB, 2," >> checkogl.cpp
    echo "        //GLX_CONTEXT_FLAGS_ARB        , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB," >> checkogl.cpp
    echo "        None};" >> checkogl.cpp
    echo "    ctx = glXCreateContextAttribsARB( display, bestFbc, 0, True, context_attribs );" >> checkogl.cpp
    echo "    XSync( display, False );" >> checkogl.cpp
    echo "    if ( ctxErrorOccurred || !ctx ){" >> checkogl.cpp
    echo "        exit(1);" >> checkogl.cpp
    echo "    }" >> checkogl.cpp
    echo "  }" >> checkogl.cpp
    echo "  XCloseDisplay( display );" >> checkogl.cpp
    echo "  return 0;" >> checkogl.cpp
    echo "}" >> checkogl.cpp

    $CXX_COMPILER checkogl.cpp -Wl,-lGL -lSM -lICE -lX11 -lXext
    if [[ $? != 0 ]]; then
        echo "failed to compile checkogl.cpp"
        rm -f checkogl.cpp
        rm -f a.out
        exit 1
    fi
    ./a.out 
    if [[ $? != 0 ]]; then
        echo "Could not obtain a 3.2 context with system GL."
        echo "You may want to add --mesagl to the command line."
        echo "To disable this check use --skip-opengl-context-check"
        rm -f checkogl.cpp
        rm -f a.out
        exit 1
    fi
    rm -f checkogl.cpp
    rm -f a.out
}


# ************************************************************************** #
#                       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.          #
# *************************************************************************** #


function initialize_build_visit()
{
    # 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

	VER_MAJOR=${VER%%.*}

	# bash script educational note:
	# The less than sign "<" is an arithmetic expression and
	# as such one must use parenthesis (( .. )) and not square brackets.
	# i.e. if (( ${VER_MAJOR} < 8 )) ; then

	# Square brackets are for contionals only. To make it a
	# conditional one must use "-lt"
        # i.e. if [[ ${VER_MAJOR} -lt 8 ]] ; then
	    
        if [[ ${VER_MAJOR} -lt 8 ]] ; then
            export MACOSX_DEPLOYMENT_TARGET=10.3
        elif [[ ${VER_MAJOR} == 8 ]] ; then
            export MACOSX_DEPLOYMENT_TARGET=10.4
        elif [[ ${VER_MAJOR} == 9 ]] ; then
            export MACOSX_DEPLOYMENT_TARGET=10.5
        elif [[ ${VER_MAJOR} == 10 ]] ; then
            export MACOSX_DEPLOYMENT_TARGET=10.6
        elif [[ ${VER_MAJOR} == 11 ]] ; then
            export MACOSX_DEPLOYMENT_TARGET=10.7
        elif [[ ${VER_MAJOR} == 12 ]] ; then
            export MACOSX_DEPLOYMENT_TARGET=10.8
        elif [[ ${VER_MAJOR} == 13 ]] ; then
            export MACOSX_DEPLOYMENT_TARGET=10.9
            export C_COMPILER=${C_COMPILER:-"clang"}
            export CXX_COMPILER=${CXX_COMPILER:-"clang++"}
        elif [[ ${VER_MAJOR} == 14 ]] ; then
            export MACOSX_DEPLOYMENT_TARGET=10.10
            export C_COMPILER=${C_COMPILER:-"clang"}
            export CXX_COMPILER=${CXX_COMPILER:-"clang++"}
        elif [[ ${VER_MAJOR} == 15 ]] ; then
            export MACOSX_DEPLOYMENT_TARGET=10.11
            export C_COMPILER=${C_COMPILER:-"clang"}
            export CXX_COMPILER=${CXX_COMPILER:-"clang++"}
        elif [[ ${VER_MAJOR} == 16 ]] ; then
            export MACOSX_DEPLOYMENT_TARGET=10.12
            export C_COMPILER=${C_COMPILER:-"clang"}
            export CXX_COMPILER=${CXX_COMPILER:-"clang++"}
        elif [[ ${VER_MAJOR} == 17 ]] ; then
            export MACOSX_DEPLOYMENT_TARGET=10.13
            export C_COMPILER=${C_COMPILER:-"clang"}
            export CXX_COMPILER=${CXX_COMPILER:-"clang++"}
        else
            export MACOSX_DEPLOYMENT_TARGET=10.13
            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++"}
        export FC_COMPILER=${FC_COMPILER:-$GFORTRAN}
        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"}
	
    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"}
        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"}
            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"}
            fi
        elif [[ "$(uname -m)" == "ppc64le" ]] ; 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"
            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
        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"}
    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"}
    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"}
    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
        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
        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"}
    fi

    export MAKE=${MAKE:-"make"}
    export THIRD_PARTY_PATH=${THIRD_PARTY_PATH:-"./third_party"}
    export GROUP=${GROUP:-"visit"}
    #export LOG_FILE=${LOG_FILE:-"${0##*/}_log"}
    export GITREVISION=${GITREVISION:-"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 DO_QT_SILENT="yes"

    export DO_DEBUG="no"
    export DO_GROUP="no"
    export DO_LOG="no"
    parallel="no"
    export DO_GIT="no"
    export DO_GIT_ANON="no"
    export DO_REVISION="no"
    USE_VISIT_FILE="no"
    export DO_PATH="no"
    export DO_VERSION="no"
    export DO_VERBOSE="no"
    export DO_JAVA="no"
    export DO_FORTRAN="no"
    export DO_PARADIS="no"
    export PREVENT_ICET="no"
    verify="no"
    export DO_OPTIONAL="yes"
    export DO_OPTIONAL2="no"
    export DO_MORE="no"
    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"
    export CREATE_RPM="no"
    export DO_CONTEXT_CHECK="yes"
    export VISIT_INSTALL_NETWORK=""
    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


    # Setup git path
    export GIT_ANON_ROOT_PATH="http://github.com/visit-dav/visit.git"
    export GIT_REPO_ROOT_PATH="ssh://git@github.com/visit-dav/visit.git"


    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"
    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


    WRITE_UNIFIED_FILE=""
    VISIT_INSTALLATION_BUILD_DIR=""
    VISIT_DRY_RUN="no"
    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"
                if [[ "$group" == "dbio-only" ]]; then
                    DO_DBIO_ONLY="yes"
                fi
                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}";;
                fc) FC_COMPILER="${arg}"; DO_FORTRAN="yes";;
                log-file) LOG_FILE="${arg}";;
                makeflags) MAKE_OPT_FLAGS="${arg}";;
                prefix) VISIT_INSTALL_PREFIX="${arg}";;
                install-network) VISIT_INSTALL_NETWORK="${arg}";;
                group) GROUP="${arg}";;
                git) GITREVISION="${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="yes";;
            --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";;
            --create-rpm) CREATE_RPM="yes";;
            --log-file) next_arg="log-file";;
            --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";;
            --fc) next_arg="fc";;
            --fortran) DO_FORTRAN="yes";;
            --group) next_arg="group"; DO_GROUP="yes";;
            -h|--help) next_action="help";;
            --install-network) next_arg="install-network";;
            --java) DO_JAVA="yes";;
            --makeflags) next_arg="makeflags";;
            --no-hostconf) DO_HOSTCONF="no";;
            --no-boost) DO_BOOST="no";;
            --no-qt-silent) DO_QT_SILENT="no";;
            --parallel) parallel="yes"; DO_ICET="yes";;
            --prefix) next_arg="prefix";;
            --print-vars) next_action="print-vars";;
            --server-components-only) DO_SERVER_COMPONENTS_ONLY="yes";;
            --paradis) DO_PARADIS="yes";;
            --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";;
            --git) DO_GIT="yes"; export GIT_ROOT_PATH=$GIT_REPO_ROOT_PATH;;
            --git-anon) DO_GIT="yes"; DO_GIT_ANON="yes" ; export GIT_ROOT_PATH=$GIT_ANON_ROOT_PATH ;;
            --git-anonymous) DO_GIT="yes"; DO_GIT_ANON="yes" ; export GIT_ROOT_PATH=$GIT_ANON_ROOT_PATH ;;
            --git-revision) next_arg="git"; DO_GIT="yes"; DO_REVISION="yes"; DO_GIT_ANON="yes" ; export GIT_ROOT_PATH=$GIT_ANON_ROOT_PATH ;;
            --tarball) next_arg="tarball"
                       USE_VISIT_FILE="yes";;
            --thirdparty-path) next_arg="thirdparty-path";;
            --version) next_arg="version";;
            --xdb) DO_XDB="yes";;
            --console) ;;
            --skip-opengl-context-check) DO_CONTEXT_CHECK="no";;
            *)
                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 or RC build then make sure we are using GIT
    #
    if [[ "$TRUNK_BUILD" == "yes" || "$RC_BUILD" == "yes" ]]; then
        if [[ "$DO_GIT" == "no" ]]; then
            DO_GIT="yes"
            DO_GIT_ANON="yes"
            export GIT_ROOT_PATH=$GIT_ANON_ROOT_PATH
        fi
    fi

    check_minimum_compiler_version

    if [[ "$OPSYS" != "Darwin" && $DO_MESAGL == "no" && $DO_CONTEXT_CHECK != "no"  && $DO_DBIO_ONLY == "no" ]] ; then 
        if [[ $DO_VTK == "yes" || $DO_VISIT == "yes" ]] ; then
            check_opengl_context
        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

    # 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

    #
    # 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_GIT" == "yes" ]] ; then
        check_git_client
        if [[ $? != 0 ]]; then
            error "Fatal Error: GIT mode selected, but git 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 == "yes" ]]; 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
                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

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

    if [[ $VISITARCH == "" ]] ; then
        C_COMPILER_BASENAME=$(basename ${C_COMPILER})
        CXX_COMPILER_BASENAME=$(basename ${CXX_COMPILER})
        export VISITARCH=${ARCH}_${C_COMPILER_BASENAME}
        if [[ "$CXX_COMPILER_BASENAME" == "g++" ]] ; then
            VERSION=$(${CXX_COMPILER} -v 2>&1 | grep "gcc version" | cut -d' ' -f3 | cut -d'.' -f1-2)
            if [[ ${#VERSION} == 3 ]] ; then
                VISITARCH=${VISITARCH}-${VERSION}
            fi
        elif [[ "$CXX_COMPILER_BASENAME" == "icpc" ]] ; then
            VERSION=$(${CXX_COMPILER} --version | cut -d' ' -f3 | head -n1)
            VISITARCH=${VISITARCH}-${VERSION}
        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

    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

    #
    # Disable qt,qwt if it is not needed
    #
    if [[ "$DO_ENGINE_ONLY" == "yes" || "$DO_DBIO_ONLY" == "yes" || "$DO_SERVER_COMPONENTS_ONLY" == "yes" ]] ; then
        if [[ "$DO_ENGINE_ONLY" == "yes" ]] ; then
           info "disabling qt, qwt because --engine-only used"
        elif [[ "$DO_DBIO_ONLY" == "yes" ]] ; then
           info "disabling qt, qwt because --dbio-only used"
        elif [[ "$DO_SERVER_COMPONENTS_ONLY" == "yes" ]] ; then
           info "disabling qt, qwt because --server-components-only used"
        fi
        bv_qt_disable
        bv_qwt_disable
    fi

    #
    # 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" ]]; 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}_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                                                              #
#                                                                             #
# 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
        echo "$@" 1>&3
    else
        echo "$@"
    fi

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

# *************************************************************************** #
# 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"
    elif [[ $(echo $1 | egrep "\.xz$" ) != "" ]] ; then
        COMPRESSTYPE="xz"
    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;;
            xz) $TAR xf $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 the given file                              #
#                                                                             #
#          verify_md5_checksum: checks md5                                    #
#          verify_sha_checksum: checks sha (256,512)                          #
#          verfiy_checksum_by_lookup: pick which checksum method to use       #
#                                     based on if they are defined giving     #
#                                     preference to the strongest checksums.  #
#                                                                             #
# Programmer: Hari Krishnan                                                   #
#                                                                             #
# Modifications:                                                              #
#   Eric Brugger, Thu Apr 11 15:51:25 PDT 2019                                #
#   Modified verify_checksum_by_lookup to also check that the checksum is     #
#   not blank in addition to being defined before using it.                   #
#                                                                             #
# *************************************************************************** #

function verify_md5_checksum
{
    checksum=$1
    dfile=$2
    md5cmd=md5sum

    tmp=`which $md5cmd`
    if [[ $? != 0 ]]; then
        tmp=`which md5`
        if [[ $? != 0 ]]; then
            info "could not find md5sum or md5 commands, disabling check"
            return 0
        fi
        md5cmd=md5
    fi
    tmp=`$md5cmd $dfile | tr ' ' '\n' | grep '^[0-9a-f]\{32\}'`
    if [[ $tmp == ${checksum} ]]; then
        info "verified"
        return 0
    fi

    info "md5 checksum 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

    set -x

    if [[ $checksum_algo == 512 ]]; then
        tmp=`shasum -a $checksum_algo $dfile | tr ' ' '\n' | grep '^[0-9a-f]\{128\}'`
    else
        tmp=`shasum -a $checksum_algo $dfile | tr ' ' '\n' | grep '^[0-9a-f]\{64\}'`
    fi
    if [[ "$tmp" == "$checksum" ]]; then
        info "verified"
        return 0
    else
        info "shasum -a $checksum_algo failed: looking for $checksum got $tmp"
        return 1
    fi

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

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

    info "verifying $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 verify_checksum_by_lookup
{
    dlfile=$(basename $1) # the downloaded file name

    # search for all shell vars with name of the form XXX_FILE defined
    # that have a value that is this file. The +-o posix stuff is to cull
    # out function names and definitions from the search
    for var in $(set -o posix; set | grep _FILE=; set +o posix); do
        var=$(echo $var | cut -d '=' -f1)
        if [ ${!var} = $dlfile ]; then
            varbase=$(echo $var | sed -e 's/_FILE$//')
            md5sum_varname=${varbase}_MD5_CHECKSUM
            sha256_varname=${varbase}_SHA256_CHECKSUM
            sha512_varname=${varbase}_SHA512_CHECKSUM
            if [ ! -z ${!sha512_varname} ]; then
                verify_checksum SHA512 ${!sha512_varname} $dlfile
                return $?
            elif [ ! -z ${!sha256_varname} ]; then
                verify_checksum SHA256 ${!sha256_varname} $dlfile
                return $?
            elif [ ! -z ${!md5sum_varname} ]; then
                verify_checksum MD5 ${!md5sum_varname} $dlfile
                return $?
            fi
        fi
    done

    # since this is an optional check, all cases should pass if it gets here.
    info "unable to find a MD5, SHA256, or SHA512, checksum associated with $dlfile; 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.                                               #
#                                                                             #
#   Eric Brugger, Fri Feb  1 14:56:58 PST 2019
#   I modified it to work post git transition.
#
# *************************************************************************** #

function download_file
{
    # $1 is the file name to download
    # $2...$* [OPTIONAL] list of sites to obtain the file from

    typeset dfile=$1
    info "Downloading $dfile . . ."
    shift

    # If the visit source code is requested, handle that now.
    site="${nerscroot}/${VISIT_VERSION}"
    if [[ "$dfile" == "$VISIT_FILE" ]] ; then
        try_download_file $site/$dfile $dfile
        if [[ $? == 0 ]] ; then
            return 0
        fi
    fi

    # It must be a third party library, handle that now.
    #
    # First try NERSC.
    site="${nerscroot}/${VISIT_VERSION}/third_party"
    try_download_file $site/$dfile $dfile
    if [[ $? == 0 ]] ; then
        return 0
    fi

    # Now try the various places listed.
    if [[ "$1" != "" ]] ; then
        for site in $* ; do
            # check if we have a google shortened url that won't accept
            # the actual file name (we need this for mfem's urls)
            if [[ $site == *goo.gl* ]] ; then
                try_download_file_from_shortened_url $site $dfile
                if [[ $? == 0 ]] ; then
                    return 0
                fi
            else
                try_download_file $site/$dfile $dfile
                if [[ $? == 0 ]] ; then
                    return 0
                fi
            fi
        done
    fi

    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

    verify_checksum_by_lookup `basename $1`
    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: try_download_file_from_shortened_url
#
# Purpose: DONT USE THIS FUNCTION. USE download_file.
#
# New variant of try_download_file, downloads a file using wget or curl
# using an explicit file name. This is necessary for shortened urls.
#
# Programmer: Cyrus Harrison
# Creation: June 1, 2016
#
# ***************************************************************************

function try_download_file_from_shortened_url
{
    if [[ "$OPSYS" == "Darwin" ]]; then
        # MaxOS X comes with curl
        /usr/bin/curl -o $2 -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 $2 -o /dev/null $1
    fi

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



# *************************************************************************** #
# Function: check_git_client                                                  #
#                                                                             #
# Purpose: Helper that checks if a git client is available.                    #
#                                                                             #
# Programmer: Cyrus Harrison                                                  #
# Date:  Mon Nov 17 14:52:37 PST 2008                                         #
#                                                                             #
# Modifications:
#   Eric Brugger, Fri Feb  1 14:56:58 PST 2019
#   I modified it to work post git transition.
#
# *************************************************************************** #

function check_git_client
{
    # check for git client
    GIT_CLIENT=$(which git)
    if [[ $GIT_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
{
    echo "prepare_build_dir:" $1 $2
    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
}


# *************************************************************************** #
#                          process_parallel_ldflags                           #
# --------------------------------------------------------------------------- #
# This routine processes the PAR_LIBS variable into three other variables.    #
#   PAR_LINKER_FLAGS :        Any linker flags that aren't libraries (don't   #
#                             start with "-l".                                #
#   PAR_LIBRARY_NAMES:        The library names with the "-l" stripped out.   #
#   PAR_LIBRARY_LINKER_FLAGS: The library names with the "-l".                #
# *************************************************************************** #
function process_parallel_ldflags
{
    export PAR_LINKER_FLAGS=""
    export PAR_LIBRARY_NAMES=""
    export PAR_LIBRARY_LINKER_FLAGS=""

    for arg in $1; do
        pos=`echo "$arg" | awk '{ printf "%d", index($1,"-l"); }'`
        if [[ "$pos" != "0" ]] ; then
            # We have a library.
            # Add it to the running list of library names with the "-l".
            export PAR_LIBRARY_LINKER_FLAGS="$PAR_LIBRARY_LINKER_FLAGS$arg "
            # Remove the "-l" prefix & add it to the running list of library
            # names without the "-l".
            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_LINKER_FLAGS, PAR_LIBRARY_NAMES & PAR_LIBRARY_LINKER_FLAGS
    process_parallel_ldflags "$PAR_LIBS"

    # If we are using PAR_INCLUDE, store the directory name without the
    # "-I"
    export PAR_INCLUDE_PATH=`echo "$PAR_INCLUDE" | sed "s/-I//"`

    #
    # 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"
                info \
                    "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"
            export PAR_INCLUDE="-I${VISITDIR}/mpich/$MPICH_VERSION/${VISITARCH}/include"
            info  "Configuring parallel with mpich build: "
            info  "  PAR_COMPILER: $PAR_COMPILER"
            info  "  PAR_COMPILER_CXX: $PAR_COMPILER_CXX"
            info  "  PAR_INCLUDE: $PAR_INCLUDE"
            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
            if [[ "$CRAY_MPICH_DIR" != "" ]] ; then
                warn "Unable to find mpicc..."
            fi
        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

        #
        # Try and use the Cray wrapper compiler to get MPI options.
        #
        if [[ "$CRAY_MPICH_DIR" != "" ]] ; then
             # NOTE: Unload darshan and cray-libsci. Otherwise keep the
             #       programming environment that is in effect.
             CCOUT=$(module unload darshan; module unload cray-libsci; CC --cray-print-opts=all)
             ingroup="no"
             arg_rpath=""
             for arg in $CCOUT ;
             do
                 # NOTE: adding the -Wl,-Bstatic/-Wl,-Bdynamic around the group is
                 # a workaround to linking with the "darshan" libraries that come
                 # in via CCOUT on cori.nersc.gov
                 if [[ "$arg" == "-Wl,--start-group" ]] ; then
                     ingroup="yes"
                     if [[ "$DO_STATIC_BUILD" == "yes" ]] ; then
                         PAR_LIBRARY_NAMES="$PAR_LIBRARY_NAMES $arg"
                     else
                         PAR_LIBRARY_NAMES="$PAR_LIBRARY_NAMES -Wl,-Bstatic $arg"
                     fi
                 elif [[ "$arg" == "-Wl,--end-group" ]] ; then
                     ingroup="no"
                     if [[ "$DO_STATIC_BUILD" == "yes" ]] ; then
                         PAR_LIBRARY_NAMES="$PAR_LIBRARY_NAMES $arg"
                     else
                         PAR_LIBRARY_NAMES="$PAR_LIBRARY_NAMES -Wl,-Bdynamic $arg"
                     fi
                 elif [[ "$ingroup" == "yes" ]] ; then
                     PAR_LIBRARY_NAMES="$PAR_LIBRARY_NAMES $arg"
                 else
                     A2=$(echo $arg | cut -c 1-2)
                     A3=$(echo $arg | cut -c 1-3)
                     if [[ "$A2" == "-I" ]] ; then
                         PAR_INCLUDE="$PAR_INCLUDE $arg"
                     elif [[ "$A2" == "-L" ]] ; then
                         arg_rpath="$arg_rpath -Wl,-rpath,$(echo $arg | cut -c 3-)"
                         PAR_LINKER_FLAGS="$PAR_LINKER_FLAGS $arg"
                     elif [[ "$A3" == "-Wl" ]] ; then
                         PAR_LINKER_FLAGS="$PAR_LINKER_FLAGS $arg"
                     elif [[ "$A2" == "-l" ]] ; then
                         PAR_LIBRARY_NAMES="$PAR_LIBRARY_NAMES $(echo $arg | cut -c 3-)"
                     fi
                 fi
             done
             if [[ "$DO_STATIC_BUILD" == "no" ]] ; then
                 PAR_LINKER_FLAGS="$PAR_LINKER_FLAGS$arg_rpath"
             fi
        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 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                                                    #
#                                                                             #
# Purpose: builds the config-site file for this host                          #
#                                                                             #
# Modifications:                                                              #
#   Kathleen Biagas, Thu Mar 14 11:28:38 PDT 2019                             #
#   Don't put the C or CXX OPT_FLAGS in the host file. These will be handled  #
#   by CMake when CMAKE_BUILD_TYPE is selected.                               #
#                                                                             #
# *************************************************************************** #

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 [[ "$FC_COMPILER" != "" ]] ; then
        echo "VISIT_OPTION_DEFAULT(VISIT_FORTRAN_COMPILER $FC_COMPILER TYPE FILEPATH)" >> $HOSTCONF
    fi

    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 [[ "$VISIT_INSTALL_PREFIX" != "" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## VisIt install location." >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(CMAKE_INSTALL_PREFIX $VISIT_INSTALL_PREFIX TYPE FILEPATH)" >> $HOSTCONF
    fi
    if [[ "$VISIT_INSTALL_NETWORK" != "" ]] ; then
        echo "VISIT_OPTION_DEFAULT(VISIT_INSTALL_PROFILES_TO_HOSTS \"$VISIT_INSTALL_NETWORK\" TYPE STRING)" >> $HOSTCONF
    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_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_C_FLAGS   \"$PAR_INCLUDE\" TYPE STRING)"     >> $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
        if [[ "$CRAY_MPICH_DIR" != "" ]] ; then
            echo "# Force static executables on Cray to be 100% statically linked." >> $HOSTCONF
            echo "SET(VISIT_EXE_LINKER_FLAGS \"-static -static-libgcc -static-libstdc++ -pthread -Wl,-Bstatic\")" >> $HOSTCONF
        fi
    fi
    if [[ "$DO_SERVER_COMPONENTS_ONLY" == "yes" ]]; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## Server components only" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_SERVER_COMPONENTS_ONLY ON TYPE BOOL)" >> $HOSTCONF
    fi
    if [[ "$DO_ENGINE_ONLY" == "yes" ]]; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## Engine components only" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_ENGINE_ONLY ON TYPE BOOL)" >> $HOSTCONF
    fi

    if [[ "$DO_STATIC_BUILD" == "yes"  && $DO_OSMESA == "yes" ]] ; then
        if [[ "$DO_SERVER_COMPONENTS_ONLY" == "yes" || "$DO_ENGINE_ONLY" == "yes" ]] ; then
            # Turn off VisIt's use of X
            echo "VISIT_OPTION_DEFAULT(VISIT_USE_X OFF TYPE BOOL)" >> $HOSTCONF
        fi
    fi
    # Are we on Cray? We might need the socket relay.
    if [[ "$CRAY_MPICH_DIR" != "" ]] ; then
        echo "VISIT_OPTION_DEFAULT(VISIT_CREATE_SOCKET_RELAY_EXECUTABLE ON)" >> $HOSTCONF
    fi

    if [[ "$DO_XDB" == "yes" ]]; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## XDB" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_ENABLE_XDB 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
}

# *************************************************************************** #
#
# Modifications:
#   Eric Brugger, Fri Feb  1 14:56:58 PST 2019
#   I modified it to work post git transition.
#
# *************************************************************************** #

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" "FC_COMPILER=" "${FC_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}"

    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
{
    initialize_build_visit

    printf "Usage: %s [options]\n" $0
    printf "%-15s %s [%s]\n" "--skip-opengl-context-check" "Skip check for minimum OpenGL context." "false"

    printf "\n"
    printf "BUILD OPTIONS\n"
    printf "\n"

    printf "%-20s %s [%s]\n" "--build-mode" "VisIt build mode (Debug or Release)" "$VISIT_BUILD_MODE"
    printf "%-20s %s [%s]\n" "--create-rpm" "Enable creation of RPM packages" "$CREATE_RPM"
    printf "%-20s %s [%s]\n" "--cflag"   "Append a flag to CFLAGS" "${CFLAGS}"
    printf "%-20s %s [%s]\n" "--cxxflag" "Append a flag to CXXFLAGS" "$CXXFLAGS"
    printf "%-20s %s [%s]\n" "--cflags"  "Explicitly set CFLAGS" "$CFLAGS"
    printf "%-20s %s [%s]\n" "--cxxflags" "Explicitly set CXXFLAGS" "$CXXFLAGS"
    printf "%-20s %s [%s]\n" "--cc"  "Explicitly set C_COMPILER" "$C_COMPILER"
    printf "%-20s %s [%s]\n" "--cxx" "Explicitly set CXX_COMPILER" "$CXX_COMPILER"
    printf "%-20s %s [%s]\n" "--debug" "Add '-g' to C[XX]FLAGS" "no"
    printf "%s <%s>  %s [%s]\n" "--makeflags" "flags" "Flags to 'make'" "$MAKE_OPT_FLAGS"
    printf "%-20s %s [%s]\n" "--fortran" "Enable compilation of Fortran sources" "no"
    printf "%-20s %s\n"      "--fc" "Explicitly set FC_COMPILER"
    printf "%-20s [%s]\n"    ""     "$FC_COMPILER"
    printf "%-20s %s [%s]\n" "--no-qt-silent" "Disable make silent operation for QT." "no"
    printf "%-20s %s [%s]\n" "--parallel" "Enable parallel build, display MPI prompt" "$parallel"
    printf "%-20s %s [%s]\n" "--static" "Build using static linking" "$DO_STATIC_BUILD"
    printf "%-20s <%s> %s\n" "--installation-build-dir" "path"
    printf "%-20s %s [%s]\n" "" "Specify the directory visit will use for building" "$VISIT_INSTALLATION_BUILD_DIR"

    printf "\n"
    printf "INSTALLATION OPTIONS\n"
    printf "\n"

    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" "--group" "Group name of installed libraries" "$GROUP"
    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 "\n"
    printf "GROUPING\n"
    printf "\n"

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

    printf "\n"
    printf "VISIT-SPECIFIC OPTIONS\n"
    printf "\n"
    printf "%-20s %s [%s]\n" "--install-network" "Install specific network config files." "${VISIT_INSTALL_NETWORK}"
    printf "%s <%s>    %s [%s]\n" "--prefix" "prefix" "The directory to which VisIt should be installed once it is built" "$VISIT_INSTALL_PREFIX"
    printf "%s <%s>     %s [%s]\n" "--tarball" "file" "tarball to extract VisIt from" "$VISIT_FILE"
    printf "%s <%s>  %s [%s]\n" "--version" "version" "The VisIt version to build" "$VISIT_VERSION"
    printf "%-20s %s [%s]\n" "--no-hostconf" "Do not create host.conf file." "$DO_HOSTCONF"
    printf "%-20s %s [%s]\n" "--java" "Build with the Java client library" "${DO_JAVA}"
    printf "%-20s %s [%s]\n" "--paradis" "Build with the paraDIS client library" "$DO_PARADIS"
    printf "%-20s %s [%s]\n" "--xdb" "Enable FieldView XDB plugin." "$DO_XDB"
    bv_visit_initialize
    bv_visit_print_usage

    printf "\n"
    printf "THIRD-PARTY LIBRARIES\n"
    printf "  A download attempt will be made for all files which do not exist.\n"
    printf "\n"
    printf "  REQUIRED -- These are built by default unless --no-thirdparty flag is used.\n"
    printf "\n"

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

    printf "\n"
    printf "  OPTIONAL\n"
    printf "\n"

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

    printf "\n"
    printf "GIT OPTIONS\n"
    printf "\n"

    printf "%-26s %s\n"      "--git" "Obtain the VisIt source code"
    printf "%-26s %s [%s]\n" "" "from the GIT server" "$DO_GIT"

    printf "\n"
    printf "MISC OPTIONS\n"
    printf "\n"

    printf "%-20s %s [%s]\n" "--bv-debug"   "Enable debugging for this script" "no"
    printf "%-20s %s [%s]\n" "--dry-run"  "Dry run of the presented options" "no"
    printf "%-20s %s [%s]\n" "--download-only" "Only download the specified packages" "no"
    printf "%-20s %s [%s]\n" "--engine-only" "Only build the compute engine." "$DO_ENGINE_ONLY"
    printf "%-20s %s [%s]\n" "-h, --help" "Display this help message." "no"
    printf "%-20s %s [%s]\n" "--print-vars" "Display user settable environment variables" "no"
    printf "%-20s %s\n" "--server-components-only" ""
    printf "%-20s %s\n" "" "Only build VisIt's server components"
    printf "%-20s %s [%s]\n" "" "(mdserver,vcl,engine)." "$DO_SERVER_COMPONENTS_ONLY"
    printf "%-20s %s [%s]\n" "--stdout" "Write build log to stdout" "no"
    printf "%-20s <%s>\n" "--write-unified-file"  "filename"
    printf "%-20s %s [%s]\n" ""  "Write single unified build_visit file using the provided filename" "$WRITE_UNIFIED_FILE"
}


#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
declare -a xmlp_grouplibs_enabled

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 | tr ' ' '\n' | 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=""
    local enabled=""

    #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 Enabled: $enabled 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`
            xmlp_grouplibs_enabled[${#xmlp_grouplibs_enabled[*]}]=`echo $enabled`
            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 enabled
            if [[ "$tmp" == *enabled* ]]; then
                tmp_enabled=${tmp/*enabled}
                tmp_enabled=`echo $tmp | sed -e s/^.*=\"// -e s/\".*$//`
                enabled="$tmp_enabled"

		tmp=${tmp/enabled*}

		#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
            #has comment
            elif [[ "$tmp" == *comment* ]]; then
                tmp_comment=${tmp/*comment}
                tmp_comment=`echo $tmp | sed -e s/^.*=\"// -e s/\".*$//`
                comment="$tmp_comment"
                enabled=""

                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=""
                enabled=""
            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=()
    xmlp_grouplibs_enabled=()

    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"
function bv_visit_initialize
{
    export DO_VISIT="yes"
}

function bv_visit_enable
{ 
    DO_VISIT="yes"
}

function bv_visit_disable
{
    DO_VISIT="no"
}

function bv_visit_depends_on
{
    echo ""
}

function bv_visit_info
{
    if [[ "$USE_VISIT_FILE" == "yes" ]] ; then
        export VISIT_MD5_CHECKSUM=""
        export VISIT_SHA256_CHECKSUM=""
    else
        export VISIT_MD5_CHECKSUM="edccd6d6c289356ac1462b1606b10ef9"
        export VISIT_SHA256_CHECKSUM="40c33f08de7a048fb436b8a72156b9e5303434e8e52d5d8590c7dc3ce8ac607d"
    fi
}

function bv_visit_print
{
    printf "%s%s\n" "VISIT_FILE=" "${VISIT_FILE}"
    printf "%s%s\n" "VISIT_VERSION=" "${VISIT_VERSION}"
}

function bv_visit_print_usage
{
    printf "%-20s %s [%s]\n" "--visit"   "Build VisIt" "$DO_VISIT"
}

function bv_visit_host_profile
{
    if [[ "$DO_VISIT" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## VISIT" >> $HOSTCONF
    fi
}

function bv_visit_ensure_built_or_ready
{
    # Check-out the latest git sources, before building VisIt
    if [[ "$DO_GIT" == "yes" && "$USE_VISIT_FILE" == "no" ]] ; then
        if [[ -d visit ]] ; then
            info "Found existing GIT visit directory, using that . . ."
        else
            # Print a dialog screen
            info "GIT clone of visit ($GIT_ROOT_PATH) . . ."
            if [[ "$DO_REVISION" == "yes" && "$GITREVISION" != "" ]] ; then
                # Get the specified revision.
                git clone $GIT_ROOT_PATH
                cd visit
                git checkout $GITREVISION
                cd ..
            elif [[ "$TRUNK_BUILD" == "yes" ]] ; then
                # Get the trunk version
                git clone $GIT_ROOT_PATH
            elif [[ "$RC_BUILD" == "yes" ]] ; then
                # Get the RC version
                git clone $GIT_ROOT_PATH
                cd visit
                git checkout ${VISIT_VERSION:0:3}RC
                cd ..
            elif [[ "$TAGGED_BUILD" == "yes" ]] ; then
                # Get the tagged version
                git clone $GIT_ROOT_PATH
                cd visit
                git checkout v${VISIT_VERSION}
                cd ..
            fi
            if [[ $? != 0 ]] ; then
                warn "Unable to build VisIt. GIT clone failed."
                return 1
            fi
        fi

    # Build using (the assumed) existing GIT "visit" directory
    elif [[ -d visit ]] ; then
        info "Found existing GIT visit directory, using that . . ."
        #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"
        DO_GIT="yes" #if visit directory exists it may have come from git.

    # Build using a VisIt source tarball
    else
        if [[ -e ${VISIT_FILE%.gz} || -e ${VISIT_FILE} ]] ; then
            info \
                "Got VisIt source code. Let's 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
}


function bv_visit_print_build_command
{
    echo "visit has no build commands set"
}

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
        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 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 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
    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_GIT" != "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 VisIt build dir which is a sibling to the VisIt src dir
    #
    if [[ "$DO_GIT" == "yes" && "$USE_VISIT_FILE" == "no" ]] ; then
        VISIT_BUILD_DIR="visit/build"
    else
        VISIT_BUILD_DIR="${VISIT_FILE%.tar*}/build"
    fi

    if [[ ! -e $VISIT_BUILD_DIR ]] ; then
        mkdir $VISIT_BUILD_DIR || error "Can't make VisIt build dir."
    else
        rm -rf $VISIT_BUILD_DIR/* || error "Can't clean VisIt build dir."
    fi

    info "Building VisIt in ${VISIT_BUILD_DIR} . . ."
    
    cd $VISIT_BUILD_DIR

    #
    # Create the GIT_VERSION file.
    #
    if [[ "$DO_GIT" == "yes" && "$USE_VISIT_FILE" == "no" ]] ; then
        git log -1 | grep "^commit" | cut -d' ' -f2 | head -c 7 > ../src/GIT_VERSION
    fi

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

    # No real need to do this as it is defined on the cmake line BUT
    # Users may rebuild visit with updated git
    cp ${START_DIR}/${HOSTCONF} 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 [[ "${VISIT_INSTALL_PREFIX}" != "" ]] ; then
        FEATURES="${FEATURES} -DCMAKE_INSTALL_PREFIX:PATH=${VISIT_INSTALL_PREFIX}"
        FEATURES="${FEATURES} -DCPACK_INSTALL_PREFIX:PATH=${VISIT_INSTALL_PREFIX}"
        FEATURES="${FEATURES} -DCPACK_PACKAGING_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

    if [[ "${CREATE_RPM}" == "yes" ]]; then
        sed -i "s/SET(CPACK_GENERATOR \"TGZ\")/#SET(CPACK_GENERATOR \"TGZ\")/" CMakeLists.txt
        FEATURES="${FEATURES} -DCPACK_BINARY_RPM:BOOL=ON -DCPACK_GENERATOR:STRING=\"RPM;TGZ\""
        FEATURES="${FEATURES} -DCPACK_RPM_SPEC_MORE_DEFINE:STRING=\"%global_python_bytecompile_errors_terminate_build 0\""
    fi

    issue_command "${CMAKE_BIN}" ${FEATURES} ../src

    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_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

        #
        # Output the message indicating that we are finished.
        #
        info "Finished building VisIt."
        info
        info "You many now try to run VisIt by cd'ing into the"
        info "$VISIT_BUILD_DIR/bin directory and invoking \"visit\""
        info
        info "To create a binary distribution tarball from this build, cd to"
        info "${START_DIR}/${VISIT_BUILD_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: tools/dev/scripts/visit-install VERSION ARCH INSTALL_DIR_PATH"
        info
        info "If you run into problems, contact visit-users@ornl.gov."
    else
        if [[ $ANY_ERRORS == "no" ]] ; then
            info "Finished!"
        else
            info "Finished with Errors"
        fi
    fi
}
function bv_adios_initialize
{
    export FORCE_ADIOS="no"
    export DO_ADIOS="no"
    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"
}

function bv_adios_disable
{
    DO_ADIOS="no"
}

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 ""
    else
        depends_on=""

        if [[ "$DO_MPICH" == "yes" ]] ; then
            depends_on="$depends_on mpich"
        fi

        if [[ "$DO_HDF5" == "yes" ]] ; then
            depends_on="$depends_on hdf5"
        fi

        echo $depends_on
    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_VERSION=${ADIOS_VERSION:-"1.13.1"}
    export ADIOS_FILE=${ADIOS_FILE:-"adios-${ADIOS_VERSION}.tar.gz"}
    export ADIOS_COMPATIBILITY_VERSION=${ADIOS_COMPATIBILITY_VERSION:-"${ADIOS_VERSION}"}
    export ADIOS_URL=${ADIOS_URL:-"http://users.nccs.gov/~pnorbert"}
    export ADIOS_BUILD_DIR=${ADIOS_BUILD_DIR:-"adios-${ADIOS_VERSION}"}
    export ADIOS_MD5_CHECKSUM="6e9eb73953231aebbbc8788f39f08618"
    export ADIOS_SHA256_CHECKSUM="684096cd7e5a7f6b8859601d4daeb1dfaa416dfc2d9d529158a62df6c5bcd7a0"
}

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 "%-20s %s [%s]\n" "--adios" "Build ADIOS" "$DO_ADIOS"
    printf "%-20s %s [%s]\n" "--alt-adios-dir" "Use ADIOS from an alternative directory"
}

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
            warn "Assuming version 1.11.0 for Adios"
            echo "SETUP_APP_VERSION(ADIOS 1.11.0)" >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(VISIT_ADIOS_DIR $ADIOS_INSTALL_DIR)" >> $HOSTCONF
        else
            echo "SETUP_APP_VERSION(ADIOS $ADIOS_VERSION)" >> $HOSTCONF
            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=$?
    # 0, already exists, 1 untarred src, 2 error

    if [[ $untarred_ADIOS == -1 ]] ; then
        warn "Unable to prepare ADIOS Build Directory. Giving Up"
        return 1
    fi

    #
    # Apply patches
    #
    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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi

    #
    # Apply configure
    #
    info "Configuring ADIOS . . ."
    cd $ADIOS_BUILD_DIR || error "Can't cd to ADIOS build dir."

    info "Invoking command to configure ADIOS"

    # MPI support
    if [[ "$VISIT_MPI_COMPILER" != "" ]] ; then
        WITH_MPI_ARGS="MPICC=\"$VISIT_MPI_COMPILER\" MPICXX=\"$VISIT_MPI_COMPILER_CXX\" LDFLAGS=\"-lpthread $PAR_LINKER_FLAGS\""
        WITH_MPI_INC="$PAR_INCLUDE"

    else
        WITH_MPI_ARGS="--without-mpi"
    fi

    # HDF5 support
    if [[ "$DO_HDF5" == "yes" ]] ; then
        export HDF5ROOT="$VISITDIR/hdf5/$HDF5_VERSION/$VISITARCH"
        export SZIPROOT="$VISITDIR/szip/$SZIP_VERSION/$VISITARCH"
        WITH_HDF5_ARGS="--with-hdf5=$HDF5ROOT"
        #HDF5_DYLIB="-L$HDF5ROOT/lib -L$SZIPROOT/lib -lhdf5 -lsz -lz"
    else
        WITH_HDF5_ARGS="--without-hdf5"
        #HDF5_DYLIB=""
    fi

    info   ./configure ${OPTIONAL} CXX="$CXX_COMPILER" CC="$C_COMPILER" \
           CFLAGS=\"$CFLAGS $C_OPT_FLAGS $WITH_MPI_INC\" \
           CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS $WITH_MPI_INC\" \
           $WITH_MPI_ARGS $WITH_HDF5_ARGS \
           --disable-fortran \
           --without-netcdf --without-nc4par --without-phdf5 --without-mxml \
           --prefix="$VISITDIR/adios/$ADIOS_VERSION/$VISITARCH"

    sh -c "./configure ${OPTIONAL} CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" \
           CFLAGS=\"$CFLAGS $C_OPT_FLAGS $WITH_MPI_INC\" \
           CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS $WITH_MPI_INC\" \
           $WITH_MPI_ARGS $WITH_HDF5_ARGS \
           --disable-fortran \
           --without-netcdf --without-nc4par --without-phdf5 --without-mxml \
           --prefix=\"$VISITDIR/adios/$ADIOS_VERSION/$VISITARCH\""

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

    #
    # Apply patches
    #
    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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi

    #
    # Build ADIOS
    #
    info "Building ADIOS . . . (~2 minutes)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
        warn "ADIOS build 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_adios2_initialize
{
    export FORCE_ADIOS2="no"
    export DO_ADIOS2="no"
    export USE_SYSTEM_ADIOS2="no"
    add_extra_commandline_args "adios2" "alt-adios2-dir" 1 "Use alternative directory for adios"

}

function bv_adios2_enable
{
    if [[ "$1" == "force" ]]; then
        FORCE_ADIOS2="yes"
    fi

    DO_ADIOS2="yes"
}

function bv_adios2_disable
{
    DO_ADIOS2="no"
}

function bv_adios2_alt_adios2_dir
{
    echo "Using alternate Adios2 directory"

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

    bv_adios2_enable
    USE_SYSTEM_ADIOS2="yes"
    ADIOS2_INSTALL_DIR="$1"
}

function bv_adios2_depends_on
{
    if [[ "$USE_SYSTEM_ADIOS2" == "yes" ]]; then
        echo ""
    else
        depends_on=""

        if [[ "$DO_MPICH" == "yes" ]] ; then
            depends_on="$depends_on mpich"
        fi

        if [[ "$DO_HDF5" == "yes" ]] ; then
            depends_on="$depends_on hdf5"
        fi

        echo $depends_on
    fi
}

function bv_adios2_initialize_vars
{
    if [[ "$USE_SYSTEM_ADIOS2" == "no" ]]; then
        ADIOS2_INSTALL_DIR="${VISITDIR}/adios2/$ADIOS2_VERSION/$VISITARCH"
    fi
}

function bv_adios2_info
{
    export ADIOS2_VERSION=${ADIOS2_VERSION:-"2.5.0"}
    export ADIOS2_FILE=${ADIOS2_FILE:-"adios2-${ADIOS2_VERSION}.tar.gz"}
    export ADIOS2_COMPATIBILITY_VERSION=${ADIOS2_COMPATIBILITY_VERSION:-"${ADIOS2_VERSION}"}
    export ADIOS2_URL=${ADIOS2_URL:-"https://github.com/ornladios/ADIOS2/archive/v2.5.0"}
    export ADIOS2_BUILD_DIR=${ADIOS2_BUILD_DIR:-"ADIOS2-"${ADIOS2_VERSION}}
    export ADIOS2_MD5_CHECKSUM="a50a6bcd02a0a296484a213dca7f9a11"
    export ADIOS2_MD5_CHECKSUM=""
    export ADIOS2_SHA256_CHECKSUM=""
}

function bv_adios2_print
{
    printf "%s%s\n" "ADIOS2_FILE=" "${ADIOS2_FILE}"
    printf "%s%s\n" "ADIOS2_VERSION=" "${ADIOS2_VERSION}"
    printf "%s%s\n" "ADIOS2_COMPATIBILITY_VERSION=" "${ADIOS2_COMPATIBILITY_VERSION}"
    printf "%s%s\n" "ADIOS2_BUILD_DIR=" "${ADIOS2_BUILD_DIR}"
}

function bv_adios2_print_usage
{
    printf "%-20s %s [%s]\n" "--adios2" "Build ADIOS2" "$DO_ADIOS2"
    printf "%-20s %s [%s]\n" "--alt-adios2-dir" "Use ADIOS2 from an alternative directory"
}

function bv_adios2_host_profile
{
    if [[ "$DO_ADIOS2" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## ADIOS2" >> $HOSTCONF
        echo "##" >> $HOSTCONF

        if [[ "$USE_SYSTEM_ADIOS2" == "yes" ]]; then
            echo "SETUP_APP_VERSION(ADIOS2 $ADIOS2_VERSION)" >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(VISIT_ADIOS2_DIR $ADIOS2_INSTALL_DIR)" >> $HOSTCONF
        else
            echo "SETUP_APP_VERSION(ADIOS2 $ADIOS2_VERSION)" >> $HOSTCONF
            echo \
                "VISIT_OPTION_DEFAULT(VISIT_ADIOS2_DIR \${VISITHOME}/adios2-ser/\${ADIOS2_VERSION}/\${VISITARCH})" \
                >> $HOSTCONF

            if [[ "$parallel" == "yes" ]] ; then
                echo "## (configured w/ mpi compiler wrapper)" >> $HOSTCONF
                echo "VISIT_OPTION_DEFAULT(VISIT_ADIOS2_PAR_DIR \${VISITHOME}/adios2-par/\${ADIOS2_VERSION}/\${VISITARCH})" \
                >> $HOSTCONF
            fi
        fi
    fi
}

function bv_adios2_ensure
{
    if [[ "$DO_ADIOS2" == "yes" && "$USE_SYSTEM_ADIOS2" == "no" ]] ; then
        ensure_built_or_ready "adios" $ADIOS2_VERSION $ADIOS2_BUILD_DIR $ADIOS2_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_ADIOS2="no"
            error "Unable to build ADIOS2.  ${ADIOS2_FILE} not found."
        fi
    fi
}

function bv_adios2_dry_run
{
    if [[ "$DO_ADIOS2" == "yes" ]] ; then
        echo "Dry run option not set for adios2."
    fi
}

function build_adios2
{
    #
    # ADIOS2 uses CMake  -- make sure we have it built.
    #
    CMAKE_INSTALL=${CMAKE_INSTALL:-"$VISITDIR/cmake/${CMAKE_VERSION}/$VISITARCH/bin"}
    if [[ -e ${CMAKE_INSTALL}/cmake ]] ; then
        info "ADIOS2: 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 $ADIOS2_BUILD_DIR $ADIOS2_FILE
    untarred_ADIOS2=$?
    if [[ $untarred_ADIOS2 == -1 ]] ; then
        warn "Unable to prepare ADIOS2 Build Directory. Giving Up"
        return 1
    fi
    #### begin parallel

    par_build_types="ser"
    if [[ "$parallel" == "yes" ]]; then
        par_build_types="$par_build_types par"
    fi

    ADIOS2_SRC_DIR=$ADIOS2_BUILD_DIR

    for bt in $par_build_types; do

        # Configure.
        cd $ADIOS2_SRC_DIR || error "Can't cd to $ADIOS2_SRC_DIR"
        info "Configuring ADIOS2-$bt (~1 minute)"

        if [[ "$bt" == "par" ]]; then

            SED_CMD="sed -i "

            # sed for OSX is different then most Linux distros in that you have
            # to use a few extra characters to get it to do the same command (see
            # https://ed.gs/2016/01/26/os-x-sed-invalid-command-code/).
            if [[ "$OPSYS" == "Darwin" ]]; then
                SED_CMD="sed -i \"\" "
            fi

            # Change all references from adios2 to adios2_mpi.
            find . -name "CMakeLists.txt" -exec sed -i "s/adios2/adios2_mpi/g" {} \;
            # This changes too many things, now we need to change specific things back.

            ${SED_CMD} "s/adios2_mpi/adios2/g" source/CMakeLists.txt
            find . -name "CMakeLists.txt" -exec ${SED_CMD} "s/adios2_mpi.h/adios2.h/g" {} \;
            find . -name "CMakeLists.txt" -exec ${SED_CMD} "s/adios2_mpi\//adios2\//g" {} \;
            find . -name "CMakeLists.txt" -exec ${SED_CMD} "s/adios2_mpi_/adios2_/g" {} \;
            find . -name "CMakeLists.txt" -exec ${SED_CMD} "s/adios2_mpi-/adios2-/g" {} \;
            find . -name "CMakeLists.txt" -exec ${SED_CMD} "s/adios2_mpi::/adios2::/g" {} \;
            find . -name "CMakeLists.txt" -exec ${SED_CMD} "s/adios2_mpisys/adios2sys/g" {} \;
            find . -name "CMakeLists.txt" -exec ${SED_CMD} "s/\/adios2_mpi/\/adios2/g" {} \;
            find . -name "CMakeLists.txt" -exec ${SED_CMD} "s/adios2_mpiExports/adios2Exports/g" {} \;
            ${SED_CMD} "s/adios2.helper/adios2\/helper/g" source/adios2/toolkit/sst/CMakeLists.txt
            ${SED_CMD} "s/find_package(adios2_mpi/find_package(adios2/g" cmake/install/post/adios2-config-dummy/CMakeLists.txt
        fi

        # Make a build directory for an out-of-source build.. Change the
        # VISIT_BUILD_DIR variable to represent the out-of-source build directory.
        ADIOS2_BUILD_DIR="${ADIOS2_SRC_DIR}-$bt-build"

        if [[ ! -d $ADIOS2_BUILD_DIR ]] ; then
            echo "Making build directory $ADIOS2_BUILD_DIR"
            mkdir $ADIOS2_BUILD_DIR
        fi

        cd $ADIOS2_BUILD_DIR || error "Can't cd to $ADIOS2_BUILD_DIR"

        #
        # Remove the CMakeCache.txt files ... existing files sometimes prevent
        # fields from getting overwritten properly.
        #
        rm -Rf $ADIOS2_BUILD_DIR/CMakeCache.txt $ADIOS2_BUILD_DIR/*/CMakeCache.txt

        adios2_build_mode="${VISIT_BUILD_MODE}"
        adios2_install_path="${VISITDIR}/adios2-$bt/${ADIOS2_VERSION}/${VISITARCH}"

        cfg_opts=""
        cfg_opts="${cfg_opts} -DADIOS2_BUILD_EXAMPLES:BOOL=OFF"
        cfg_opts="${cfg_opts} -DADIOS2_BUILD_TESTING:BOOL=OFF"
        cfg_opts="${cfg_opts} -DADIOS2_USE_ZeroMQ:BOOL=OFF"
        cfg_opts="${cfg_opts} -DADIOS2_USE_Fortran:BOOL=OFF"

        if test "x${DO_STATIC_BUILD}" = "xyes" ; then
            cfg_opts="${cfg_opts} -DBUILD_SHARED_LIBS:BOOL=OFF"
        else
            cfg_opts="${cfg_opts} -DBUILD_SHARED_LIBS:BOOL=ON"
        fi
        cfg_opts="${cfg_opts} -DCMAKE_BUILD_TYPE:STRING=${adios2_build_mode}"
        cfg_opts="${cfg_opts} -DCMAKE_INSTALL_PREFIX:PATH=${adios2_install_path}"
        cfg_opts="${cfg_opts} -DCMAKE_C_FLAGS:STRING=\"${C_OPT_FLAGS}\""
        cfg_opts="${cfg_opts} -DCMAKE_CXX_FLAGS:STRING=\"${CXX_OPT_FLAGS}\""
        cfg_opts="${cfg_opts} -DADIOS2_USE_SST:BOOL=ON"

        if [[ "$bt" == "ser" ]]; then
            cfg_opts="${cfg_opts} -DADIOS2_USE_MPI:BOOL=OFF"
            cfg_opts="${cfg_opts} -DCMAKE_C_COMPILER:STRING=${C_COMPILER}"
            cfg_opts="${cfg_opts} -DCMAKE_CXX_COMPILER:STRING=${CXX_COMPILER}"
        elif [[ "$bt" == "par" ]]; then
            cfg_opts="${cfg_opts} -DADIOS2_USE_MPI:BOOL=ON"
            cfg_opts="${cfg_opts} -DCMAKE_C_COMPILER:STRING=${PAR_COMPILER}"
            cfg_opts="${cfg_opts} -DCMAKE_CXX_COMPILER:STRING=${PAR_COMPILER_CXX}"
        fi

        # call configure.
        CMAKE_BIN="${CMAKE_INSTALL}/cmake"
        if test -e bv_run_cmake.sh ; then
            rm -f bv_run_cmake.sh
        fi

        echo "\"${CMAKE_BIN}\"" ${cfg_opts} ../ > bv_run_cmake.sh
        cat bv_run_cmake.sh
        issue_command bash bv_run_cmake.sh

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

        #
        # Build ADIOS2
        #
        info "Building ADIOS2-$bt . . . (~5 minutes)"
        $MAKE $MAKE_OPT_FLAGS
        if [[ $? != 0 ]] ; then
            warn "ADIOS2 build failed.  Giving up"
            return 1
        fi

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

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

        cd "$START_DIR"
    done

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

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

function bv_adios2_is_installed
{
    if [[ "$USE_SYSTEM_ADIOS2" == "yes" ]]; then
        return 1
    fi

    check_if_installed "adios2" $ADIOS2_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_adios2_build
{
    cd "$START_DIR"

    if [[ "$DO_ADIOS2" == "yes" && "$USE_SYSTEM_ADIOS2" == "no" ]] ; then
        ser_installed="no"
        par_installed="no"
        check_if_installed "adios2-ser" $ADIOS2_VERSION
        if [[ $? == 0 ]] ; then ser_installed="yes"; fi
        if [[ "$parallel" == "yes" ]]; then
            check_if_installed "adios2-par" $ADIOS2_VERSION
            if [[ $? == 0 ]] ; then par_installed="yes"; fi
        fi

        if [ "$ser_installed" == "yes" ] && ([ "$parallel" == "no" ] || [ "$par_installed" == "yes" ]) ; then
            info "ADIOS2 already installed, skipping"
        else
            build_adios2
            if [[ $? != 0 ]] ; then
                error "Unable to build or install ADIOS2.  Bailing out."
            fi
            info "Done building ADIOS2"
        fi
    fi
}
function bv_advio_initialize
{
    export DO_ADVIO="no"
}

function bv_advio_enable
{
    DO_ADVIO="yes"
}

function bv_advio_disable
{
    DO_ADVIO="no"
}

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="cd89d8a7f1fe94c1bd2d04888028d8b2b98a37853c4a8d5b2b7417b83ea1e803"
}

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 "%-20s %s [%s]\n" "--advio"   "Build AdvIO" "$DO_ADVIO"
}

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]* || `sw_vers -productVersion` == 10.1*.[0-9]* ]] ; then
            info "Applying OS X 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.                                        #
#                                                                             #
# Kevin Griffin, Mon Aug 8 17:34:52 PDT 2016                                  #
# Updated patch for OS X 10.1*.                                                 #
# *************************************************************************** #

function build_advio
{
    #
    # Prepare build dir
    #
    prepare_build_dir $ADVIO_BUILD_DIR $ADVIO_FILE
    untarred_ADVIO=$?
    # 0, already exists, 1 untarred src, 2 error

    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" \
                 "tried to apply a patch to an existing directory that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "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 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"
}

function bv_boost_disable
{
    DO_BOOST="no"
}

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_67_0"}
    export BOOST_FILE=${BOOST_FILE:-"boost_${BOOST_VERSION}.tar.gz"}
    export BOOST_COMPATIBILITY_VERSION=${BOOST_COMPATIBILITY_VERSION:-"1_67"}
    export BOOST_URL=${BOOST_URL:-"http://sourceforge.net/projects/boost/files/boost/1.67.0"}
    export BOOST_BUILD_DIR=${BOOST_BUILD_DIR:-"boost_${BOOST_VERSION}"}
    export BOOST_MD5_CHECKSUM="4850fceb3f2222ee011d4f3ea304d2cb"
    export BOOST_SHA256_CHECKSUM="8aa4e330c870ef50a896634c931adf468b21f8a69b77007e45c444151229f665"
}

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 "%-20s %s [%s]\n" "--boost" "Build BOOST" "${DO_BOOST}"
    printf "%-20s %s [%s]\n" "--alt-boost-dir" "Use Boost from an alternative directory"
}

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=$?
    # 0, already exists, 1 untarred src, 2 error

    if [[ $untarred_boost == -1 ]] ; then
        warn "Unable to prepare BOOST Build Directory. Giving Up"
        return 1
    fi

    #
    # Apply patches
    #
    cd $BOOST_BUILD_DIR || error "Can't cd to BOOST build dir."
    apply_boost_patch
    if [[ $? != 0 ]] ; then
        if [[ $untarred_boost == 1 ]] ; then
            warn "Giving up on Boost 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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi

    # Get a list of libraries to build. This list of libraries is used
    # for the OS X name fix up.

    # This list must include dependent libraries also. For instance,
    # the serialization library requires the wserialization
    # library. So it too must be listed. However, it can not be in the
    # build_libs list otherwise boost barfs.
    libs=""

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

    if [[ "$DO_NEKTAR_PLUS_PLUS" == "yes" ]] ; then
        libs="$libs \
              chrono iostreams thread date_time filesystem \
              system program_options regex timer"
    fi
    
#    if [[ "$DO_UINTAH" == "yes" ]] ; then
#        libs="$libs \
#              chrono filesystem wserialization serialization system thread signals date_time program_options"
#    fi

    # Remove all of the duplicate libs.
    libs=`echo $libs | tr ' ' '\n' | sort -u | tr '\n' ' ' | sed s'/.$//'`

    # Note: the library name 'wserialization' can not be in the list
    # of build libraries but must be part of the name fixup for OS X.
    build_libs=`echo $libs | sed s'/ wserialization//' | tr ' ' ','`

    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="${BOOST_INSTALL_DIR}/lib"

            for lib in $libs;
            do
                fulllibname=$INSTALLNAMEPATH/libboost_${lib}.${SO_EXT}

                install_name_tool -id $fulllibname $fulllibname

                # Find all the dependent libraries (more or less)
                deplibs=`otool -L $fulllibname | sed "s/(.*)//g"`

                for deplib in $deplibs;
                do
                    # Only get the libraries related to boost and not itself.
                    if [[ `echo $deplib | grep -c libboost_` == 1 && \
                                `echo $deplib | grep -c libboost_${lib}` == 0 ]] ; then

                        # Get the library name sans the directory path
                        deplibname=`echo $deplib | sed "s/.*\///"`
                        
                        # Set the library path
                        install_name_tool -change $deplib \
                                          ${INSTALLNAMEPATH}/$deplibname \
                                          $fulllibname

                    fi
                done            
            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"
}

function bv_boxlib_enable
{
    DO_BOXLIB="yes"
}

function bv_boxlib_disable
{
    DO_BOXLIB="no"
}

function bv_boxlib_depends_on
{
    echo ""
}

function bv_boxlib_info
{
    export BOXLIB_VERSION=${BOXLIB_VERSION:-"1.3.5"}
    export BOXLIB_FILE=${BOXLIB_FILE:-"ccse-${BOXLIB_VERSION}.tar.gz"}
    export BOXLIB_COMPATIBILITY_VERSION=${BOXLIB_COMPATIBILITY_VERSION:-"1.3.5"}
    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="263214a8b7f6046f99186601afc90144"
    export BOXLIB_SHA256_CHECKSUM="2dd2496d27dc84d9171be06b44e3968fa481867d936174e7d49a547da5f6f755"
}

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 "%-20s %s [%s]\n" "--boxlib"  "Build Boxlib" "$DO_BOXLIB" 
}

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 apply_boxlib_patch
{
    patch -p0 << \EOF
diff -c a/Src/C_BaseLib/FArrayBox.cpp ccse-1.3.5/Src/C_BaseLib/FArrayBox.cpp
*** a/Src/C_BaseLib/FArrayBox.cpp
--- ccse-1.3.5/Src/C_BaseLib/FArrayBox.cpp
***************
*** 21,30 ****
  #include <BL_CXX11.H>
  #include <MemPool.H>
  
- #ifdef BL_Darwin
  using std::isinf;
  using std::isnan;
- #endif
  
  #if defined(DEBUG) || defined(BL_TESTING)
  bool FArrayBox::do_initval = true;
--- 21,28 ----
EOF
    if [[ $? != 0 ]] ; then
        warn "boxlib patch failed."
        return 1
    fi

    return 0;

}

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

    #
    # Apply patches
    #
    info "Patching Boxlib . . ."
    apply_boxlib_patch
    if [[ $? != 0 ]] ; then
        if [[ $untarred_boxlib == 1 ]] ; then
            warn "Giving up on Boxlib 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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    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_cfitsio_initialize
{
    export DO_CFITSIO="no"
}

function bv_cfitsio_enable
{
    DO_CFITSIO="yes"
}

function bv_cfitsio_disable
{
    DO_CFITSIO="no"
}

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="c156ee0becee8987a14229e705f0f9f39dd2b73bbc9e73bc5d69f43896cb9a63"
}

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 "%-20s %s [%s]\n" "--cfitsio" "Build CFITSIO" "$DO_CFITSIO"
}

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"
}

function bv_cgns_enable
{
    DO_CGNS="yes"
}

function bv_cgns_disable
{
    DO_CGNS="no"
}

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 "%-20s %s [%s]\n" "--cgns"    "Build CGNS" "$DO_CGNS" 
}

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=$?
    # 0, already exists, 1 untarred src, 2 error

    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" \
                 "tried to apply a patch to an existing directory that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi

    #
    # Configure CGNS
    #
    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
            H5ARGS="$H5ARGS --with-szip=$VISITDIR/szip/$SZIP_VERSION/$VISITARCH/lib/libsz.$LIBEXT"
        fi
        H5ARGS="$H5ARGS --with-zlib=$VISITDIR/zlib/$ZLIB_VERSION/$VISITARCH/lib/libz.$LIBEXT"
    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 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" "bin-cmake-dir" 1 "Use cmake found in alternative binary directory"
}

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

function bv_cmake_disable
{
    DO_CMAKE="no"
    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_bin_cmake_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_URL=${CMAKE_URL:-"https://cmake.org/files/v3.9/"}
    export CMAKE_VERSION=${CMAKE_VERSION:-"3.9.3"}
    export CMAKE_FILE=${CMAKE_FILE:-"cmake-${CMAKE_VERSION}.tar.gz"}
    export CMAKE_BUILD_DIR=${CMAKE_BUILD_DIR:-"cmake-${CMAKE_VERSION}"}
    export CMAKE_MD5_CHECKSUM="cb0f19828461904c72ed6a1e55459d03"
    export CMAKE_SHA256_CHECKSUM="8eaf75e1e932159aae98ab5e7491499545554be62a08cbcbc7c75c84b999f28a"
}

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 "%-20s %s\n" "--cmake" "Build CMake"
    printf "%-20s %s [%s]\n" "--system-cmake"  "Use the system installed CMake"
    printf "%-20s %s [%s]\n" "--alt-cmake-dir" "Use CMake from an alternative directory"
    printf "%-20s %s [%s]\n" "--bin-cmake-dir" "Use CMake from an alternative binary 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 $CMAKE_URL
            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_5
{
    patch -p0 <<\EOF
*** cmake-3.8.1/Source/kwsys/SystemInformation.cxx	Tue May  2 05:59:43 2017
--- cmake-3.8.1-new/Source/kwsys/SystemInformation.cxx	Thu Jun 29 11:18:38 2017
***************
*** 4805,4811 ****
    std::string lastArg = command.substr(start + 1, command.size() - start - 1);
    args.push_back(lastArg.c_str());
  
!   args.push_back(0);
  
    std::string buffer = this->RunProcess(args);
  
--- 4805,4811 ----
    std::string lastArg = command.substr(start + 1, command.size() - start - 1);
    args.push_back(lastArg.c_str());
  
!   args.push_back(nullptr);
  
    std::string buffer = this->RunProcess(args);
EOF
    if [[ $? != 0 ]] ; then
        warn "Unable to apply patch 5 to cmake."
        return 1
    else
        return 0
    fi
}

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 ${CMAKE_VERSION} 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

    CXX_COMPILER_BASENAME=$(basename ${CXX_COMPILER})
    if [[ "${CMAKE_VERSION}" == "3.8.1" &&  "${CXX_COMPILER_BASENAME}" == "icpc" ]]; then
        apply_cmake_patch_5
        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=$?
    # 0, already exists, 1 untarred src, 2 error

    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 that had\n" \
                 "already been patched ... that is, 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 (~5 minutes)"
            build_cmake
            if [[ $? != 0 ]] ; then
                error "Unable to build or install CMake.  Bailing out."
            fi
            info "Done building CMake"
        fi
    fi
}
function bv_conduit_initialize
{
    export DO_CONDUIT="no"
}

function bv_conduit_enable
{
    DO_CONDUIT="yes"
}

function bv_conduit_disable
{
    DO_CONDUIT="no"
}

function bv_conduit_depends_on
{
    local depends_on=""

    if [[ "$DO_HDF5" == "yes" ]] ; then
        depends_on="hdf5"
    fi
    
    if [[ "$DO_MPICH" == "yes" ]] ; then
        depends_on="$depends_on mpich"
    fi
    
    echo $depends_on
}

function bv_conduit_info
{
    export CONDUIT_VERSION=${CONDUIT_VERSION:-"v0.4.0"}
    export CONDUIT_FILE=${CONDUIT_FILE:-"conduit-${CONDUIT_VERSION}-src-with-blt.tar.gz"}
    export CONDUIT_COMPATIBILITY_VERSION=${CONDUIT_COMPATIBILITY_VERSION:-"v0.4.0"}
    export CONDUIT_BUILD_DIR=${CONDUIT_BUILD_DIR:-"conduit-${CONDUIT_VERSION}"}
    export CONDUIT_MD5_CHECKSUM="49c107c076ecd4e8ae6eb4ffe28198aa"
    export CONDUIT_SHA256_CHECKSUM="c228e6f0ce5a9c0ffb98e0b3d886f2758ace1a4b40d00f3f118542c0747c1f52"
}

function bv_conduit_print
{
    printf "%s%s\n" "CONDUIT_FILE=" "${CONDUIT_FILE}"
    printf "%s%s\n" "CONDUIT_VERSION=" "${CONDUIT_VERSION}"
    printf "%s%s\n" "CONDUIT_COMPATIBILITY_VERSION=" "${CONDUIT_COMPATIBILITY_VERSION}"
    printf "%s%s\n" "CONDUIT_BUILD_DIR=" "${CONDUIT_BUILD_DIR}"
}

function bv_conduit_print_usage
{
    printf "%-20s %s [%s]\n" "--conduit"   "Build Conduit" "$DO_CONDUIT"
}

function bv_conduit_host_profile
{
    if [[ "$DO_CONDUIT" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## Conduit" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
            "VISIT_OPTION_DEFAULT(VISIT_CONDUIT_DIR \${VISITHOME}/conduit/$CONDUIT_VERSION/\${VISITARCH})" \
            >> $HOSTCONF
        if [[ "$DO_HDF5" == "yes" ]] ; then
            echo \
                "VISIT_OPTION_DEFAULT(VISIT_CONDUIT_LIBDEP HDF5_LIBRARY_DIR hdf5 \${VISIT_HDF5_LIBDEP} TYPE STRING)" \
                >> $HOSTCONF
        fi
    fi
}

function bv_conduit_ensure
{
    if [[ "$DO_CONDUIT" == "yes" ]] ; then
        ensure_built_or_ready "conduit" $CONDUIT_VERSION $CONDUIT_BUILD_DIR $CONDUIT_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_CONDUIT="no"
            error "Unable to build Conduit.  ${CONDUIT_FILE} not found."
        fi
    fi
}

function bv_conduit_dry_run
{
    if [[ "$DO_CONDUIT" == "yes" ]] ; then
        echo "Dry run option not set for Conduit."
    fi
}

# *************************************************************************** #
# build_conduit
# *************************************************************************** #

function build_conduit
{
    #
    # Conduit uses CMake  -- make sure we have it built.
    #
    CMAKE_INSTALL=${CMAKE_INSTALL:-"$VISITDIR/cmake/${CMAKE_VERSION}/$VISITARCH/bin"}
    if [[ -e ${CMAKE_INSTALL}/cmake ]] ; then
        info "Conduit: 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 $CONDUIT_BUILD_DIR $CONDUIT_FILE
    untarred_conduit=$?
    if [[ $untarred_conduit == -1 ]] ; then
        warn "Unable to prepare Conduit build directory. Giving Up!"
        return 1
    fi
    
    #
    # Call configure
    #
    info "Configuring Conduit . . ."

    # Make a build directory for an out-of-source build.. Change the
    # VISIT_BUILD_DIR variable to represent the out-of-source build directory. 
    CONDUIT_SRC_DIR=$CONDUIT_BUILD_DIR
    CONDUIT_BUILD_DIR="${CONDUIT_SRC_DIR}-build"
    if [[ ! -d $CONDUIT_BUILD_DIR ]] ; then
        echo "Making build directory $CONDUIT_BUILD_DIR"
        mkdir $CONDUIT_BUILD_DIR
    fi

    #
    # Remove the CMakeCache.txt files ... existing files sometimes prevent
    # fields from getting overwritten properly.
    #
    rm -Rf $CONDUIT_BUILD_DIR}/CMakeCache.txt $CONDUIT_BUILD_DIR/*/CMakeCache.txt


    conduit_build_mode="${VISIT_BUILD_MODE}"
    conduit_install_path="${VISITDIR}/conduit/${CONDUIT_VERSION}/${VISITARCH}"


    cfg_opts=""
    # normal stuff
    cfg_opts="${cfg_opts} -DCMAKE_BUILD_TYPE:STRING=${conduit_build_mode}"
    cfg_opts="${cfg_opts} -DCMAKE_INSTALL_PREFIX:PATH=${conduit_install_path}"
    if test "x${DO_STATIC_BUILD}" = "xyes" ; then
        cfg_opts="${cfg_opts} -DBUILD_SHARED_LIBS:BOOL=OFF"
    else
        cfg_opts="${cfg_opts} -DBUILD_SHARED_LIBS:BOOL=ON"
    fi
    
    cfg_opts="${cfg_opts} -DENABLE_TESTS:BOOL=false"
    cfg_opts="${cfg_opts} -DENABLE_DOCS:BOOL=false"
    cfg_opts="${cfg_opts} -DCMAKE_C_COMPILER:STRING=${C_COMPILER}"
    cfg_opts="${cfg_opts} -DCMAKE_CXX_COMPILER:STRING=${CXX_COMPILER}"
    cfg_opts="${cfg_opts} -DCMAKE_C_FLAGS:STRING=\"${C_OPT_FLAGS} ${PAR_LINKER_FLAGS}\""
    cfg_opts="${cfg_opts} -DCMAKE_CXX_FLAGS:STRING=\"${CXX_OPT_FLAGS} ${PAR_LINKER_FLAGS}\""
    if test "${OPSYS}" = "Darwin" ; then
        cfg_opts="${cfg_opts} -DCMAKE_INSTALL_NAME_DIR:PATH=${conduit_install_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"
                cfg_opts="${cfg_opts} -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=\"\" -DCMAKE_OSX_SYSROOT:STRING=/"
            fi
        fi
    fi
    
    
    if [[ "$DO_HDF5" == "yes" ]] ; then
        cfg_opts="${cfg_opts} -DHDF5_DIR:STRING=$VISITDIR/hdf5/$HDF5_VERSION/$VISITARCH/"
    fi

    if [[ "$FC_COMPILER" == "yes" ]] ; then
        cfg_opts="${cfg_opts} -DENABLE_FORTRAN:BOOL=ON"
        cfg_opts="${cfg_opts} -DCMAKE_Fortran_COMPILER:STRING=${FC_COMPILER}"
    fi
    
    #
    # Conduit Relay MPI Support
    #

    if [[ "$PAR_COMPILER" != "" ]] ; then
        cfg_opts="${cfg_opts} -DENABLE_MPI:BOOL=ON"
        cfg_opts="${cfg_opts} -DMPI_C_COMPILER:STRING=${PAR_COMPILER}"
        cfg_opts="${cfg_opts} -DMPI_CXX_COMPILER:STRING=${PAR_COMPILER}"
    fi
    
    if [[ "$PAR_INCLUDE" != "" ]] ; then
        cfg_opts="${cfg_opts} -DMPI_C_INCLUDE_PATH:STRING=${PAR_INCLUDE_PATH}"
        cfg_opts="${cfg_opts} -DMPI_CXX_INCLUDE_PATH:STRING=${PAR_INCLUDE_PATH}"
    fi
    
    if [[ "$PAR_LIBS" != "" ]] ; then
        cfg_opts="${cfg_opts} -DMPI_C_LINK_FLAGS:STRING=${PAR_LINKER_FLAGS}"
        cfg_opts="${cfg_opts} -DMPI_C_LIBRARIES:STRING=${PAR_LIBRARY_LINKER_FLAGS}"
        cfg_opts="${cfg_opts} -DMPI_CXX_LINK_FLAGS:STRING=${PAR_LINKER_FLAGS}"
        cfg_opts="${cfg_opts} -DMPI_CXX_LIBRARIES:STRING=${PAR_LIBRARY_LINKER_FLAGS}"
    fi
    
    CMAKE_BIN="${CMAKE_INSTALL}/cmake"
    cd ${CONDUIT_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}\"" ${cfg_opts} ../${CONDUIT_SRC_DIR}/src > bv_run_cmake.sh
    cat bv_run_cmake.sh
    issue_command bash bv_run_cmake.sh

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

    #
    # Build Conduit
    #
    info "Building Conduit . . . (~5 minutes)"
    $MAKE # don't use -j b/c gfortran can has issues with intermediate files
    if [[ $? != 0 ]] ; then
        warn "Conduit build failed.  Giving up"
        return 1
    fi
    
    #
    # Install into the VisIt third party location.
    #
    info "Installing Conduit"
    $MAKE install
    if [[ $? != 0 ]] ; then
        warn "Conduit install failed.  Giving up"
        return 1
    fi

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

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

function bv_conduit_is_installed
{
    check_if_installed "conduit" $CONDUIT_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_conduit_build
{
    cd "$START_DIR"
    if [[ "$DO_CONDUIT" == "yes" ]] ; then
        check_if_installed "conduit" $CONDUIT_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping Conduit build.  Conduit is already installed."
        else
            info "Building Conduit (~5 minutes)"
            build_conduit
            if [[ $? != 0 ]] ; then
                error "Unable to build or install Conduit.  Bailing out."
            fi
            info "Done building Conduit"
        fi
    fi
}
function bv_damaris_initialize
{
    export DO_DAMARIS="no"
}

function bv_damaris_enable
{ 
    DO_DAMARIS="yes"
}

function bv_damaris_disable
{
    DO_DAMARIS="no"
}

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/35204"}
    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 "%-20s %s [%s]\n" "--damaris"   "Build DAMARIS" "$DO_DAMARIS"
}

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_GIT" != "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_GIT" == "yes" && "$USE_VISIT_FILE" == "no" ]] ; then
        LIBSIMV2_INCLUDE="../visit/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_embree_initialize
{
    export DO_EMBREE="no"
    export USE_SYSTEM_EMBREE="no"
    add_extra_commandline_args "embree" "alt-embree-dir" 1 "Use alternative directory for embree"
}

function bv_embree_enable
{
    DO_EMBREE="yes"
}

function bv_embree_disable
{
    DO_EMBREE="no"
}

function bv_embree_alt_embree_dir
{
    echo "Using alternate embree directory"
    bv_embree_enable
    USE_SYSTEM_EMBREE="yes"
    EMBREE_INSTALL_DIR="$1"
}

function bv_embree_depends_on
{
    echo "tbb"
}

function bv_embree_initialize_vars
{
    info "initializing embree vars"
    if [[ "$DO_EMBREE" == "yes" ]] ; then
        if [[ "$USE_SYSTEM_EMBREE" == "no" ]]; then
            EMBREE_INSTALL_DIR=$VISITDIR/embree/$EMBREE_VERSION/$VISITARCH
        fi
    fi
}

function bv_embree_info
{
    export EMBREE_VERSION=${EMBREE_VERSION:-"3.2.0"}
    if [[ "$OPSYS" == "Darwin" ]] ; then
        export EMBREE_FILE=${EMBREE_FILE:-"embree-${EMBREE_VERSION}.x86_64.macosx.tar.gz"}
        export EMBREE_INSTALL_DIR_NAME=embree-$EMBREE_VERSION.x86_64.macosx
        # these are binary builds, not source tarballs so the mdf5s and shas differ 
        # between platforms 
        export EMBREE_MD5_CHECKSUM="8a3874975f1883d8df1714b3ba3eacba"
        export EMBREE_SHA256_CHECKSUM="31cbbe96c6f19bb9c5463e181070bd667d3dbb93e702671e8406ce26be259109"
    else
        export EMBREE_FILE=${EMBREE_FILE:-"embree-${EMBREE_VERSION}.x86_64.linux.tar.gz"}
        export EMBREE_INSTALL_DIR_NAME=embree-$EMBREE_VERSION.x86_64.linux
        # these are binary builds, not source tarballs so the mdf5s and shas differ 
        # between platforms 
        export EMBREE_MD5_CHECKSUM="7a1c3d12e8732cfee7d389f81d008798"
        export EMBREE_SHA256_CHECKSUM="7671cc37c4dc4e3da00b2b299b906b35816f058efea92701e7b89574b15e652d"
    fi
    export EMBREE_COMPATIBILITY_VERSION=${EMBREE_COMPATIBILITY_VERSION:-"${EMBREE_VERSION}"}
    export EMBREE_URL=${EMBREE_URL:-"https://github.com/embree/embree/releases/download/v${EMBREE_VERSION}/"}
    export EMBREE_BUILD_DIR=${EMBREE_BUILD_DIR:-"${EMBREE_VERSION}"}
}

function bv_embree_print
{
    printf "%s%s\n" "EMBREE_FILE=" "${EMBREE_FILE}"
    printf "%s%s\n" "EMBREE_VERSION=" "${EMBREE_VERSION}"
    printf "%s%s\n" "EMBREE_COMPATIBILITY_VERSION=" "${EMBREE_COMPATIBILITY_VERSION}"
    printf "%s%s\n" "EMBREE_BUILD_DIR=" "${EMBREE_BUILD_DIR}"
}

function bv_embree_host_profile
{
    if [[ "$DO_EMBREE" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## EMBREE" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        if [[ "$USE_SYSTEM_EMBREE" == "no" ]]; then
            echo "SETUP_APP_VERSION(EMBREE ${EMBREE_VERSION})" >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(VISIT_EMBREE_DIR \${VISITHOME}/embree/\${EMBREE_VERSION}/\${VISITARCH})" >> $HOSTCONF
        else
            echo "VISIT_OPTION_DEFAULT(VISIT_EMBREE_DIR ${EMBREE_INSTALL_DIR})" >> $HOSTCONF
        fi
    fi
}

function bv_embree_print_usage
{
    #embree does not have an option, it is only dependent on embree.
    printf "%-20s %s [%s]\n" "--embree" "Build embree" "$DO_EMBREE"
}

function bv_embree_ensure
{
    if [[ "$DO_EMBREE" == "yes" && "$USE_SYSTEM_EMBREE" == "no" ]] ; then
        ensure_built_or_ready "embree" $EMBREE_VERSION $EMBREE_BUILD_DIR $EMBREE_FILE $EMBREE_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_EMBREE="no"
            error "Unable to build embree.  ${EMBREE_FILE} not found."
        fi
    elif [[ "$USE_SYSTEM_EMBREE" == "yes" ]] ; then
        if [[ ! -d $EMBREE_INSTALL_DIR/include/embree3 ]]; then
            error "Unable to find embree v3.+ in the alternative path, perhaps a wrong embree version is provided."
        fi
    fi
}

function bv_embree_dry_run
{
    if [[ "$DO_EMBREE" == "yes" ]] ; then
        echo "Dry run option not set for embree."
    fi
}

# ***************************************************************************
# build_embree
#
# Modifications:
#
# ***************************************************************************

function build_embree
{
    # Unzip the EMBREE tarball and copy it to the VisIt installation.
    info "Installing prebuilt embree"    
    tar zxvf $EMBREE_FILE
    rm $EMBREE_INSTALL_DIR_NAME/lib/libtbb*
    mkdir -p $VISITDIR/embree/$EMBREE_VERSION/$VISITARCH || error "Cannot create embree install directory"
    cp -R $EMBREE_INSTALL_DIR_NAME/* $VISITDIR/embree/$EMBREE_VERSION/$VISITARCH || error "Cannot copy to embree install directory"
    if [[ "$DO_GROUP" == "yes" ]] ; then
        chmod -R ug+w,a+rX "$VISITDIR/embree/$EMBREE_VERSION/$VISITARCH"
        chgrp -R ${GROUP} "$VISITDIR/embree/$EMBREE_VERSION/$VISITARCH"
    fi
    cd "$START_DIR"
    info "Done with embree"
    return 0
}

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

function bv_embree_is_installed
{
    if [[ "$USE_SYSTEM_EMBREE" == "yes" ]]; then   
        return 1
    fi

    check_if_installed "embree" $EMBREE_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_embree_build
{
    if [[ "$DO_EMBREE" == "yes" && "$USE_SYSTEM_EMBREE" == "no" ]] ; then
        check_if_installed "embree" $EMBREE_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping build of embree"
        else
            build_embree
            if [[ $? != 0 ]] ; then
                error "Unable to build or install embree.  Bailing out."
            fi
            info "Done building embree"
        fi
    fi
}

function bv_fastbit_initialize
{
    export DO_FASTBIT="no"
}

function bv_fastbit_enable
{
    DO_FASTBIT="yes"
}

function bv_fastbit_disable
{
    DO_FASTBIT="no"
}

function bv_fastbit_depends_on
{
    echo ""
}

function bv_fastbit_info
{
    export FASTBIT_VERSION=${FASTBIT_VERSION:-"2.0.3"}
    export FASTBIT_FILE=${FASTBIT_FILE:-"fastbit-${FASTBIT_VERSION}.tar.gz"}
    # Note: last 3-digit field in URL changes with version.
    export FASTBIT_URL=${FASTBIT_URL:-"https://code.lbl.gov/frs/download.php/file/426"}
    export FASTBIT_BUILD_DIR=${FASTBIT_BUILD_DIR:-"fastbit-${FASTBIT_VERSION}"}
    export FASTBIT_MD5_CHECKSUM="54825b1d19f6c6a3844b368facc26a9e"
    export FASTBIT_SHA256_CHECKSUM="1ddb16d33d869894f8d8cd745cd3198974aabebca68fa2b83eb44d22339466ec"
}

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 "%-20s %s [%s]\n" "--fastbit" "Build FastBit" "$DO_FASTBIT"
    printf "%-20s %s\n" "" "NOTE: FastBit not available for download from web" 
}

function bv_fastbit_host_profile
{
    if [[ "$DO_FASTBIT" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## FastBit" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "SETUP_APP_VERSION(FASTBIT $FASTBIT_VERSION)" >> $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 apply_fastbit_2_0_3_patch
{
    info "Patching FastBit"
    patch -p0 << \EOF
diff -rcN fastbit-2.0.3/configure-orig.ac fastbit-2.0.3/configure.ac
*** fastbit-2.0.3/configure-orig.ac	2016-12-14 08:57:26.000000000 -0700
--- fastbit-2.0.3/configure.ac	2016-12-14 08:58:42.000000000 -0700
***************
*** 916,922 ****
  AC_SUBST(BUILD_CONTRIB)
  
  AC_DEFINE_UNQUOTED(FASTBIT_IBIS_INT_VERSION,
!  `echo $PACKAGE_VERSION | awk 'BEGIN { FS="." } { printf("0x%d%.2d%.2d%.2d\n", substr($1, 5), $2, $3, $4); }'`,
  [Define an integer version of FastBit IBIS version number])
  OBJDIR=$objdir
  AC_SUBST(BUILD_JAVA_INTERFACE)
--- 916,922 ----
  AC_SUBST(BUILD_CONTRIB)
  
  AC_DEFINE_UNQUOTED(FASTBIT_IBIS_INT_VERSION,
!  `echo $PACKAGE_VERSION | awk 'BEGIN { FS="." } { printf("0x%d%.2d%.2d%.2d\n", $1, $2, $3, $4); }'`,
  [Define an integer version of FastBit IBIS version number])
  OBJDIR=$objdir
  AC_SUBST(BUILD_JAVA_INTERFACE)

diff -rcN fastbit-2.0.3/configure-orig fastbit-2.0.3/configure
*** fastbit-2.0.3/configure-orig	2016-12-14 09:00:26.000000000 -0700
--- fastbit-2.0.3/configure	2016-12-14 08:54:49.000000000 -0700
***************
*** 17350,17356 ****
  
  
  cat >>confdefs.h <<_ACEOF
! #define FASTBIT_IBIS_INT_VERSION `echo $PACKAGE_VERSION | awk 'BEGIN { FS="." } { printf("0x%d%.2d%.2d%.2d\n", substr($1, 5), $2, $3, $4); }'`
  _ACEOF
  
  OBJDIR=$objdir
--- 17350,17356 ----
  
  
  cat >>confdefs.h <<_ACEOF
! #define FASTBIT_IBIS_INT_VERSION `echo $PACKAGE_VERSION | awk 'BEGIN { FS="." } { printf("0x%d%.2d%.2d%.2d\n", $1, $2, $3, $4); }'`
  _ACEOF
  
  OBJDIR=$objdir

EOF
}

function apply_fastbit_patch
{
    if [[ ${FASTBIT_VERSION} == 2.0.3 ]] ; then
        apply_fastbit_2_0_3_patch
        if [[ $? != 0 ]] ; then
            return 1
        fi
    fi

    return 0
}

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

function build_fastbit
{
    #
    # Prepare build dir
    #
    prepare_build_dir $FASTBIT_BUILD_DIR $FASTBIT_FILE
    untarred_fastbit=$?
    # 0, already exists, 1 untarred src, 2 error

    if [[ $untarred_fastbit == -1 ]] ; then
        warn "Unable to prepare FastBit Build Directory. Giving Up"
        return 1
    fi

    #
    # Apply patches
    #
    apply_fastbit_patch
    if [[ $? != 0 ]] ; then
        if [[ $untarred_fastbit == 1 ]] ; then
            warn "Giving up on FastBit 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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi

    #
    # Apply configure
    #
    info "Configuring FastBit . . ."
    cd $FASTBIT_BUILD_DIR || error "Can't cd to FastBit build dir."
    
    info "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 "Building FastBit . . . (~7 minutes)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
        warn "FastBit build failed.  Giving up"
        return 1
    fi
    
    info "Installing FastBit . . ."
    $MAKE install
    if [[ $? != 0 ]] ; then
        warn "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"
    info "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_fastquery_initialize
{
    export DO_FASTQUERY="no"
}

function bv_fastquery_enable
{
    DO_FASTQUERY="yes"
}

function bv_fastquery_disable
{
    DO_FASTQUERY="no"
}

function bv_fastquery_depends_on
{
    depends_on="fastbit"

    if [[ "$DO_ADIOS" == "yes" ]] ; then
        depends_on="$depends_on adios"
    fi

    if [[ "$DO_HDF5" == "yes" ]] ; then
        depends_on="$depends_on hdf5"
    fi

    if [[ "$DO_NETCDF" == "yes" ]] ; then
        depends_on="$depends_on netcdf"
    fi

    if [[ "$depends_on" == "fastquery" ]] ; then
        error "FastQuery must be built with either ADIOS, HDF5, or NetCDF."
    fi
}

function bv_fastquery_info
{
    export FASTQUERY_VERSION=${FASTQUERY_VERSION:-"0.8.4.3"}
    export FASTQUERY_FILE=${FASTQUERY_FILE:-"fastquery-${FASTQUERY_VERSION}.tar.gz"}
    # Note: last 3-digit field in URL changes with version.
    export FASTQUERY_URL=${FASTQUERY_URL:-"https://code.lbl.gov/frs/download.php/file/428"}
    export FASTQUERY_BUILD_DIR=${FASTQUERY_BUILD_DIR:-"fastquery-${FASTQUERY_VERSION}"}
    export FASTQUERY_MD5_CHECKSUM="de6b6ed6a17e861e23b0349254a13ea9"
    export FASTQUERY_SHA256_CHECKSUM="452c778eedd9956410393acbc44aae49505b48b821cc575b168bd05501578f16"
}

function bv_fastquery_print
{
    printf "%s%s\n" "FASTQUERY_FILE=" "${FASTQUERY_FILE}"
    printf "%s%s\n" "FASTQUERY_VERSION=" "${FASTQUERY_VERSION}"
    printf "%s%s\n" "FASTQUERY_BUILD_DIR=" "${FASTQUERY_BUILD_DIR}"
}

function bv_fastquery_print_usage
{
    printf "%-20s %s [%s]\n" "--fastquery" "Build FastQuery" "$DO_FASTQUERY"
    printf "%-20s %s\n" "" "NOTE: FastQuery not available for download from web" 
}

function bv_fastquery_host_profile
{
    if [[ "$DO_FASTQUERY" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## FastQuery" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "SETUP_APP_VERSION(FASTQUERY $FASTQUERY_VERSION)" >> $HOSTCONF
        echo \
            "VISIT_OPTION_DEFAULT(VISIT_FASTQUERY_DIR \${VISITHOME}/fastquery/\${FASTQUERY_VERSION}/\${VISITARCH})" \
            >> $HOSTCONF
    fi

}

function bv_fastquery_ensure
{
    if [[ "$DO_FASTQUERY" == "yes" ]] ; then
        ensure_built_or_ready "fastquery" $FASTQUERY_VERSION $FASTQUERY_BUILD_DIR $FASTQUERY_FILE $FASTQUERY_URL
        if [[ $? != 0 ]] ; then
            warn "Unable to build FastQuery.  ${FASTQUERY_FILE} not found."
            warn "FastQuery is not available for download from the VisIt build site"
            ANY_ERRORS="yes"
            DO_FASTQUERY="no"
            error "Try going to https://codeforge.lbl.gov/frs/?group_id=44"
        fi
    fi
}

function bv_fastquery_dry_run
{
    if [[ "$DO_FASTQUERY" == "yes" ]] ; then
        echo "Dry run option not set for fastquery."
    fi
}

function apply_fastquery_patch
{
#    if [[ ${FASTQUERY_VERSION} == 2.0.3 ]] ; then
#        apply_fastquery_2_0_3_patch
#        if [[ $? != 0 ]] ; then
#            return 1
#        fi
#    fi

    return 0
}

# *************************************************************************** #
#                         Function 8.14, build_fastquery                        #
# *************************************************************************** #

function build_fastquery
{
    #
    # Prepare build dir
    #
    prepare_build_dir $FASTQUERY_BUILD_DIR $FASTQUERY_FILE
    untarred_fastquery=$?
    # 0, already exists, 1 untarred src, 2 error

    if [[ $untarred_fastquery == -1 ]] ; then
        warn "Unable to prepare FastQuery Build Directory. Giving Up"
        return 1
    fi

    #
    # Apply patches
    #
    apply_fastquery_patch
    if [[ $? != 0 ]] ; then
        if [[ $untarred_fastquery == 1 ]] ; then
            warn "Giving up on FastQuery 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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi

    # MPI support
    if [[ "$VISIT_MPI_COMPILER" != "" ]] ; then
        FASTQUERY_MPI_OPTS="MPICC=\"$VISIT_MPI_COMPILER\" MPICXX=\"$VISIT_MPI_COMPILER_CXX\" LDFLAGS=\"$PAR_LINKER_FLAGS\""
        FASTQUERY_MPI_INC="$PAR_INCLUDE"
    else
        FASTQUERY_MPI_OPTS="--disable-parallel"
        FASTQUERY_MPI_INC=""
    fi

    FASTQUERY_MPI_OPTS="--disable-parallel"
    FASTQUERY_MPI_INC=""
    
    # FastBit support
    if [[ "$DO_FASTBIT" == "yes" ]] ; then
        info "FastBit requested.  Configuring FastQuery with FastBit support."
        export FASTBITROOT="$VISITDIR/fastbit/$FASTBIT_VERSION/$VISITARCH"
        WITH_FASTBIT_ARG="--with-fastbit=$FASTBITROOT"
    else
        WITH_FASTBIT_ARG=""
    fi

    # ADIOS support
    if [[ "$DO_ADIOS" == "yes" ]] ; then
        info "ADIOS requested.  Configuring FastQuery with ADIOS support."
        export ADIOSROOT="$VISITDIR/adios/$ADIOS_VERSION/$VISITARCH"
        WITH_ADIOS_ARG="--with-adios=$ADIOSROOT"
    else
        WITH_ADIOS_ARG="--without-adios"
    fi

    # HDF5 support
    if [[ "$DO_HDF5" == "yes" ]] ; then
        info "HDF5 requested.  Configuring FastQuery with HDF5 support."
        export HDF5ROOT="$VISITDIR/hdf5/$HDF5_VERSION/$VISITARCH"
        export SZIPROOT="$VISITDIR/szip/$SZIP_VERSION/$VISITARCH"
        WITH_HDF5_ARG="--with-hdf5=$HDF5ROOT"
        #HDF5_DYLIB="-L$HDF5ROOT/lib -L$SZIPROOT/lib -lhdf5 -lsz -lz"
    else
        WITH_HDF5_ARG="--without-hdf5"
        #HDF5_DYLIB=""
    fi

    # NETCDF support
    if [[ "$DO_NETCDF" == "yes" ]] ; then
        info "NetCDF requested.  Configuring FastQuery with NetCDF support."
        export NETCDFROOT="$VISITDIR/netcdf/$NETCDF_VERSION/$VISITARCH"
        WITH_NETCDF_ARG="--with-netcdf=$NETCDFROOT"
    else
        WITH_NETCDF_ARG="--without-netcdf"
    fi

    #
    # Apply configure
    #
    info "Configuring FastQuery . . ."
    cd $FASTQUERY_BUILD_DIR || error "Can't cd to FastQuery build dir."
    
    info "Invoking command to configure FastQuery"

    info ./configure \
	CC="$C_COMPILER" CXX="$CXX_COMPILER" \
	CFLAGS=\"$CFLAGS $C_OPT_FLAGS $FASTQUERY_MPI_INC\" \
        CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS $FASTQUERY_MPI_INC\" \
	$FASTQUERY_MPI_OPTS $WITH_FASTBIT_ARG \
	$WITH_ADIOS_ARG $WITH_HDF5_ARG $WITH_NETCDF_ARG \
        --prefix="$VISITDIR/fastquery/$FASTQUERY_VERSION/$VISITARCH"

    ./configure \
	CC="$C_COMPILER" CXX="$CXX_COMPILER" \
        CFLAGS="$CFLAGS $C_OPT_FLAGS $FASTQUERY_MPI_INC" \
        CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS $FASTQUERY_MPI_INC" \
        CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS $FASTQUERY_MPI_INC" \
	$FASTQUERY_MPI_OPTS $WITH_FASTBIT_ARG \
	$WITH_ADIOS_ARG $WITH_HDF5_ARG $WITH_NETCDF_ARG \
        --prefix="$VISITDIR/fastquery/$FASTQUERY_VERSION/$VISITARCH"

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

    #
    # Build FastQuery
    #
    info "Building FastQuery . . . (~7 minutes)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
        warn "FastQuery build failed.  Giving up"
        return 1
    fi
    
    info "Installing FastQuery . . ."
    $MAKE install
    if [[ $? != 0 ]] ; then
        warn "FastQuery build (make install) failed.  Giving up"
        return 1
    fi

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

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

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

function bv_fastquery_is_installed
{
    check_if_installed "fastquery" $FASTQUERY_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_fastquery_build
{
    cd "$START_DIR"
    if [[ "$DO_FASTQUERY" == "yes" ]] ; then
        check_if_installed "fastquery" $FASTQUERY_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping FastQuery build.  FastQuery is already installed."
        else
            info "Building FastQuery (~7 minutes)"
            build_fastquery
            if [[ $? != 0 ]] ; then
                error "Unable to build or install FastQuery.  Bailing out."
            fi
            info "Done building FastQuery"
        fi
    fi
}
function bv_gdal_initialize
{
    export DO_GDAL="no"
}

function bv_gdal_enable
{
    DO_GDAL="yes"
}

function bv_gdal_disable
{
    DO_GDAL="no"
}

function bv_gdal_depends_on
{
    echo ""
}

function bv_gdal_info
{
    export GDAL_FILE=${GDAL_FILE:-"gdal-2.2.4.tar.gz"}
    export GDAL_VERSION=${GDAL_VERSION:-"2.2.4"}
    export GDAL_COMPATIBILITY_VERSION=${GDAL_COMPATIBILITY_VERSION:-"2.2"}
    export GDAL_URL=${GDAL_URL:-"http://download.osgeo.org/gdal/${GDAL_VERSION}"}
    export GDAL_BUILD_DIR=${GDAL_BUILD_DIR:-"gdal-2.2.4"}
    export GDAL_MD5_CHECKSUM="798c66cc8df26f204f6248358fe4fceb"
    export GDAL_SHA256_CHECKSUM="b9d5a723787f3006a82cb276db171c721187b048b866c0e20e6df464d671a1a4"
}

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 "%-20s %s [%s]\n" "--gdal" "Build GDAL" "$DO_GDAL"
}

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 --with-geos=no
    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.2.2.4.${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_glu_initialize
{
    if [[ "$DO_MESAGL" == "yes" ]] ; then
        export DO_GLU="yes"
    else 
        export DO_GLU="no"
    fi
}

function bv_glu_enable
{
    if [[ "$DO_MESAGL" == "yes" ]] ; then
        DO_GLU="yes"
    fi
}

function bv_glu_disable
{
    DO_GLU="no"
}

function bv_glu_depends_on
{
    # We install into the mesagl directory so it needs to be on.

    if [[ "$DO_MESAGL" == "yes" ]] ; then
        echo "mesagl"
    fi
}

function bv_glu_info
{
    export GLU_FILE=${GLU_FILE:-"glu-9.0.0.tar.gz"}
    export GLU_VERSION=${GLU_VERSION:-"9.0.0"}
    export GLU_BUILD_DIR=${GLU_BUILD_DIR:-"glu-9.0.0"}
    export GLU_MD5_CHECKSUM="bbc57d4fe3bd3fb095bdbef6fcb977c4"
    export GLU_SHA256_CHECKSUM="4387476a1933f36fec1531178ea204057bbeb04cc2d8396c9ea32720a1f7e264"
    export GLU_URL=${GLU_URL:-"ftp://ftp.freedesktop.org/pub/mesa/glu"}
}

function bv_glu_print
{
    printf "%s%s\n" "GLU_FILE=" "${GLU_FILE}"
    printf "%s%s\n" "GLU_VERSION=" "${GLU_VERSION}"
    printf "%s%s\n" "GLU_TARGET=" "${GLU_TARGET}"
    printf "%s%s\n" "GLU_BUILD_DIR=" "${GLU_BUILD_DIR}"
}

function bv_glu_print_usage
{
    printf "%-20s %s [%s]\n" "--glu" "Build GLU" "$DO_GLU"
}

function bv_glu_host_profile
{
#    if [[ "$DO_GLU" == "yes" ]] ; then
#        echo >> $HOSTCONF
#        echo "##" >> $HOSTCONF
#        echo "## GLU" >> $HOSTCONF
#        echo "##" >> $HOSTCONF
#        echo "VISIT_OPTION_DEFAULT(VISIT_GLU_DIR \${VISITHOME}/glu/$GLU_VERSION/\${VISITARCH})" >> $HOSTCONF
#    fi
     return 0
}

function bv_glu_selected
{
    args=$@
    if [[ $args == "--glu" ]]; then
        DO_GLU="yes"
        return 1
    fi

    return 0
}

function bv_glu_initialize_vars
{
    info "initalizing glu vars"
    if [[ "$DO_GLU" == "yes" ]]; then
        if [[ "$DO_MESAGL" == "yes" ]] ; then
            GLU_INSTALL_DIR="${MESAGL_INSTALL_DIR}"
        else
            GLU_INSTALL_DIR="${VISITDIR}/glu/${GLU_VERSION}/${VISITARCH}"
        fi
        GLU_INCLUDE_DIR="${GLU_INSTALL_DIR}/include"
        GLU_LIB_DIR="${GLU_INSTALL_DIR}/lib"
        if [[ "$DO_STATIC_BUILD" == "yes" ]]; then
            GLU_LIB="${GLU_LIB_DIR}/libGLU.a"
        else
            GLU_LIB="${GLU_LIB_DIR}/libGLU.${SO_EXT}"
        fi
    fi
}

function bv_glu_ensure
{
    if [[ "$DO_DBIO_ONLY" != "yes" ]]; then
        if [[ "$DO_GLU" == "yes" ]] ; then
            ensure_built_or_ready "glu"   $GLU_VERSION   $GLU_BUILD_DIR   $GLU_FILE
            if [[ $? != 0 ]] ; then
                return 1
            fi
        fi
    fi
}

function bv_glu_dry_run
{
    if [[ "$DO_GLU" == "yes" ]] ; then
        echo "Dry run option not set for glu."
    fi
}

function apply_glu_ppc64le_config_patch
{
  # patch glu's config.guess to allow it to recognize ppc64le
  patch -p0 << \EOF
*** ./glu-9.0.0/config.guess.orig 2018-03-22 11:22:30.000000000 
--- ./glu-9.0.0/config.guess 2018-03-22 11:23:23.000000000 
***************
*** 984,995 ****
--- 984,998 ----
  	  *)    echo hppa-unknown-linux-${LIBC} ;;
  	esac
  	exit ;;
      ppc64:Linux:*:*)
  	echo powerpc64-unknown-linux-${LIBC}
  	exit ;;
+     ppc64le:Linux:*:*)
+ 	echo powerpc64-unknown-linux-${LIBC}
+ 	exit ;;
      ppc:Linux:*:*)
  	echo powerpc-unknown-linux-${LIBC}
  	exit ;;
      s390:Linux:*:* | s390x:Linux:*:*)
  	echo ${UNAME_MACHINE}-ibm-linux
  	exit ;;

EOF

    if [[ $? != 0 ]] ; then
      warn "glu patch for config.guess failed."
      return 1
    fi
    return 0;
}

function apply_glu_patch
{
    apply_glu_ppc64le_config_patch
    if [[ $? != 0 ]] ; then
        return 1
    fi

    return 0
}


function build_glu
{
    #
    # prepare build dir
    #
    prepare_build_dir $GLU_BUILD_DIR $GLU_FILE
    untarred_glu=$?
    # 0, already exists, 1 untarred src, 2 error

    if [[ $untarred_glu == -1 ]] ; then
        warn "Unable to prepare GLU build directory. Giving Up!"
        return 1
    fi

    #
    # Patch glu
    #
    apply_glu_patch
    if [[ $? != 0 ]] ; then
        if [[ $untarred_glu == 1 ]] ; then
            warn "Giving up on GLU 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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi

    #
    # Build GLU.
    #
    info "Building GLU . . . (~2 minutes)"
    cd $GLU_BUILD_DIR || error "Couldn't cd to glu build dir."

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

    # NOTE: we install the library into the MesaGL directories.
    if [[ "$DO_MESAGL" == "yes" ]] ; then
        issue_command env GL_LIBS="-L${MESAGL_INSTALL_DIR}/lib" GL_CFLAGS="-I${MESAGL_INSTALL_DIR}/include" \
            CC=${C_COMPILER} CFLAGS="${C_OPT_FLAGS}" \
            CXX=${CXX_COMPILER} CXXFLAGS="${CXX_OPT_FLAGS}" \
           ./configure --prefix=${MESAGL_INSTALL_DIR} ${GLU_STATIC_DYNAMIC}
        if [[ $? != 0 ]] ; then
            warn "GLU: 'configure' failed.  Giving up"
            return 1
        fi
    else
        warn "GLU: 'configure' failed.  Giving up"
        return 1
    fi

    ${MAKE} ${MAKE_OPT_FLAGS}
    if [[ $? != 0 ]] ; then
        warn "GLU: 'make' failed.  Giving up"
        return 1
    fi
    info "Installing GLU ..."
    ${MAKE} install
    if [[ $? != 0 ]] ; then
        warn "GLU: 'make install' failed.  Giving up"
        return 1
    fi

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

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

function bv_glu_is_installed
{
    EXT=${SO_EXT}
    if [[ "$DO_STATIC_BUILD" == "yes" ]]; then
        EXT="a"
    fi
    if [[ "$DO_MESAGL" == "yes" ]] ; then
        if [[ -e $VISITDIR/mesagl/$MESAGL_VERSION/$VISITARCH/lib/libGLU.${EXT} ]] ; then
            return 1
        fi
    fi
    return 0
}

function bv_glu_build
{
    #
    # Build GLU
    #
    cd "$START_DIR"
    if [[ "$DO_GLU" == "yes" ]] ; then
        bv_glu_is_installed
        if [[ $? == 1 ]] ; then
            info "Skipping GLU build.  GLU is already installed."
        else
            info "Building GLU (~2 minutes)"
            build_glu
            if [[ $? != 0 ]] ; then
                error "Unable to build or install GLU.  Bailing out."
            fi
            info "Done building GLU"
        fi
    fi
}
function bv_h5part_initialize
{
    export DO_H5PART="no"
}

function bv_h5part_enable
{
    DO_H5PART="yes"
    DO_HDF5="yes"
    DO_SZIP="yes"
}

function bv_h5part_disable
{
    DO_H5PART="no"
}

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 "%-20s %s [%s]\n" "--h5part" "Build H5Part" "$DO_H5PART"
}

function bv_h5part_host_profile
{
    if [[ "$DO_H5PART" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## H5Part" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "SETUP_APP_VERSION(H5PART $H5PART_VERSION)" >> $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 apply_h5part_1_6_6_patch
{
    info "Patching H5Part"
    patch -p0 << \EOF
diff -rcN H5Part-1.6.6/src/H5PartTypes-orig.h  H5Part-1.6.6/src/H5PartTypes.h 
*** H5Part-1.6.6/src/H5PartTypes-orig.h	2016-12-14 14:04:41.000000000 -0700
--- H5Part-1.6.6/src/H5PartTypes.h	2016-12-14 14:00:57.000000000 -0700
***************
*** 19,28 ****
  #endif
   ;
  
- #ifndef PARALLEL_IO
- typedef unsigned long		MPI_Comm;
- #endif
- 
  #define H5PART_STEPNAME_LEN	64
  #define H5PART_DATANAME_LEN	64
  
--- 19,24 ----
***************
*** 86,93 ****
  	/**
  	   MPI communicator
  	*/
  	MPI_Comm comm;
! 
  	int throttle;
  
  	struct H5BlockStruct *block;
--- 82,90 ----
  	/**
  	   MPI communicator
  	*/
+ #ifdef PARALLEL_IO
  	MPI_Comm comm;
! #endif
  	int throttle;
  
  	struct H5BlockStruct *block;

diff -rcN H5Part-1.6.6/src/H5Part-orig.h  H5Part-1.6.6/src/H5Part.h
*** H5Part-1.6.6/src/H5Part-orig.h	2016-12-14 14:04:41.000000000 -0700
--- H5Part-1.6.6/src/H5Part.h	        2016-12-14 14:00:57.000000000 -0700
***************
*** 160,165 ****
--- 160,193 ----
  	const h5part_int32_t *array
  	);
  
+ h5part_int64_t
+ H5PartAppendDataFloat64 (
+ 	H5PartFile *f,
+ 	const char *name,
+ 	const h5part_float64_t *array
+ 	);
+ 
+ h5part_int64_t
+ H5PartAppendDataFloat32 (
+ 	H5PartFile *f,
+ 	const char *name,
+ 	const h5part_float32_t *array
+ 	);
+ 
+ h5part_int64_t
+ H5PartAppendDataInt64 (
+ 	H5PartFile *f,
+ 	const char *name,
+ 	const h5part_int64_t *array
+ 	);
+ 
+ h5part_int64_t
+ H5PartAppendDataInt32 (
+ 	H5PartFile *f,
+ 	const char *name,
+ 	const h5part_int32_t *array
+ 	);
+ 
  /*================== File Reading Routines =================*/
  h5part_int64_t
  H5PartSetStep (

diff -rcN H5Part-1.6.6/src/H5Part-orig.c  H5Part-1.6.6/src/H5Part.c
*** H5Part-1.6.6/src/H5Part-orig.c	2016-12-14 14:04:41.000000000 -0700
--- H5Part-1.6.6/src/H5Part.c	        2016-12-14 14:00:57.000000000 -0700
***************
*** 140,146 ****
--- 140,148 ----
  _H5Part_open_file (
  	const char *filename,	/*!< [in] The name of the data file to open. */
  	const char flags,	/*!< [in] The access mode for the file. */
+ #ifdef PARALLEL_IO
  	MPI_Comm comm,		/*!< [in] MPI communicator */
+ #endif	
  	int f_parallel,		/*!< [in] 0 for serial io otherwise parallel */
  	h5part_int64_t align	/*!< [in] Number of bytes for setting alignment,
  					  metadata block size, etc.
***************
*** 166,171 ****
--- 168,175 ----
  	f->xfer_prop = f->dcreate_prop = f->fcreate_prop = H5P_DEFAULT;
  
  	f->access_prop = H5Pcreate (H5P_FILE_ACCESS);
+         H5Pset_fclose_degree(f->access_prop, H5F_CLOSE_SEMI);
+ 	
  	if (f->access_prop < 0) {
  		HANDLE_H5P_CREATE_ERR;
  		goto error_cleanup;
***************
*** 282,288 ****
--- 286,294 ----
  #endif // PARALLEL_IO
  	} else {
  		_is_root_proc = 1;
+ #ifdef PARALLEL_IO
  		f->comm = 0;
+ #endif		
  		f->nprocs = 1;
  		f->myproc = 0;
  		f->pnparticles = 
***************
*** 481,491 ****
  	INIT
  	SET_FNAME ( "H5PartOpenFile" );
  
! 	MPI_Comm comm = 0;	/* dummy */
  	int f_parallel = 0;	/* serial open */
  	int align = 0;		/* no tuning parameters */
  
! 	return _H5Part_open_file ( filename, flags, comm, f_parallel, align );
  }
  
  /*!
--- 487,497 ----
  	INIT
  	SET_FNAME ( "H5PartOpenFile" );
  
! 	/* MPI_Comm comm = 0;	/\* dummy *\/ */
  	int f_parallel = 0;	/* serial open */
  	int align = 0;		/* no tuning parameters */
  
! 	return _H5Part_open_file ( filename, flags, /*comm,*/ f_parallel, align );
  }
  
  /*!
***************
*** 519,528 ****
  	INIT
  	SET_FNAME ( "H5PartOpenFileAlign" );
  
! 	MPI_Comm comm = 0;	/* dummy */
  	int f_parallel = 0;	/* serial open */
  
! 	return _H5Part_open_file ( filename, flags, comm, f_parallel, align );
  }
  
  /*!
--- 525,534 ----
  	INIT
  	SET_FNAME ( "H5PartOpenFileAlign" );
  
! 	/* MPI_Comm comm = 0;	/\* dummy *\/ */
  	int f_parallel = 0;	/* serial open */
  
! 	return _H5Part_open_file ( filename, flags, /*comm,*/ f_parallel, align );
  }
  
  /*!
***************
*** 1277,1282 ****
--- 1283,1487 ----
  	return H5PART_SUCCESS;
  }
  
+ static h5part_int64_t
+ _append_data (
+         H5PartFile *f,          /*!< IN: Handle to open file */
+         const char *name,       /*!< IN: Name to associate array with */
+         const void *array,      /*!< IN: Array to commit to disk */
+         const hid_t type        /*!< IN: Type of data */
+         ) {
+ 
+         herr_t herr;
+         hid_t dataset_id;
+ 
+         char name2[H5PART_DATANAME_LEN];
+         _normalize_dataset_name ( name, name2 );
+ 
+         _H5Part_print_debug (
+                      "Create a dataset[%s] mounted on "
+                      "timestep %lld",
+                      name2, (long long)f->timestep );
+ 
+         if ( f->shape == H5S_ALL ) {
+                 _H5Part_print_warn (
+                      "The view is unset or invalid: please "
+                      "set the view or specify a number of particles." );
+                 return HANDLE_H5PART_BAD_VIEW_ERR ( f->viewstart, f->viewend );
+           return -1;
+         }
+ 
+         H5E_BEGIN_TRY
+         dataset_id = H5Dopen ( f->timegroup, name2
+ #ifndef H5_USE_16_API
+                 , H5P_DEFAULT
+ #endif
+                 );
+         H5E_END_TRY
+ 
+         hid_t dataspace_id, filespace_id;
+ 
+         if ( dataset_id > 0 ) {
+ 
+           hsize_t dims[1] = {f->nparticles}; // dataset dimensions
+           hsize_t dims_in[1] = {0};          // incoming dimensions
+           hsize_t dims_out[1] = {0};         // outgoing dimensions
+ 
+           // Get the original dataspace.
+           dataspace_id = H5Dget_space(dataset_id);
+           if ( dataspace_id < 0 )
+             return HANDLE_H5D_CREATE_ERR ( name2, f->timestep );
+           herr = H5Sget_simple_extent_dims(dataspace_id, dims_in, NULL);
+ 
+           // Extend the dataset
+           dims_out[0] = dims_in[0] + dims[0];
+           herr = H5Dset_extent(dataset_id, dims_out);
+ 
+           // Create the hyperslab
+           filespace_id = H5Dget_space(dataset_id);
+           if ( filespace_id < 0 )
+             return HANDLE_H5D_CREATE_ERR ( name2, f->timestep );
+           herr = H5Sselect_hyperslab(filespace_id, H5S_SELECT_SET,
+                                      dims_in, NULL, dims, NULL);
+ 
+           // Define the memory space
+           dataspace_id = H5Screate_simple(1, dims, NULL);
+           if ( dataspace_id < 0 )
+             return HANDLE_H5D_CREATE_ERR ( name2, f->timestep );
+           
+           if ( herr < 0 )
+             return HANDLE_H5D_CREATE_ERR ( name2, f->timestep );
+         } else {          
+                 dataset_id = H5Dcreate (
+                         f->timegroup,
+                         name2,
+                         type,
+ 			// Use the memshape because it has unlimited bounds
+                         f->memshape, //f->shape,
+ #ifndef H5_USE_16_API
+                         H5P_DEFAULT,
+                         f->dcreate_prop,
+                         H5P_DEFAULT
+ #else
+                         f->dcreate_prop
+ #endif
+                );
+                 if ( dataset_id < 0 )
+                         return HANDLE_H5D_CREATE_ERR ( name2, f->timestep );
+ 
+                 // Create the hyperslab
+                 dataspace_id = f->memshape;
+                 filespace_id = f->diskshape;
+         }
+ 
+ #ifdef PARALLEL_IO
+         herr = _H5Part_start_throttle ( f );
+         if ( herr < 0 ) return herr;
+ #endif
+ 
+         herr = H5Dwrite(dataset_id,
+                         type,
+                         dataspace_id,   // f->memshape,
+                         filespace_id,   // f->diskshape,
+                         f->xfer_prop,
+                         array);
+ 
+ #ifdef PARALLEL_IO
+         herr = _H5Part_end_throttle ( f );
+         if ( herr < 0 ) return herr;
+ #endif
+ 
+         if ( herr < 0 ) return HANDLE_H5D_WRITE_ERR ( name2, f->timestep );
+ 
+         herr = H5Dclose ( dataset_id );
+         if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR;
+ 
+         f->empty = 0;
+ 
+         return H5PART_SUCCESS;
+ }
+ 
+ h5part_int64_t
+ H5PartAppendDataFloat32 (
+         H5PartFile *f,          /*!< [in] Handle to open file */
+         const char *name,       /*!< [in] Name to associate array with */
+         const h5part_float32_t *array   /*!< [in] Array to commit to disk */
+         ) {
+ 
+         SET_FNAME ( "H5PartWriteDataFloat64" );
+         h5part_int64_t herr;
+ 
+         CHECK_FILEHANDLE ( f );
+         CHECK_WRITABLE_MODE( f );
+         CHECK_TIMEGROUP( f );
+ 
+         herr = _append_data ( f, name, (void*)array, H5T_NATIVE_FLOAT );
+         if ( herr < 0 ) return herr;
+ 
+         return H5PART_SUCCESS;
+ }
+ 
+ h5part_int64_t
+ H5PartAppendDataFloat64 (
+         H5PartFile *f,          /*!< [in] Handle to open file */
+         const char *name,       /*!< [in] Name to associate array with */
+         const h5part_float64_t *array   /*!< [in] Array to commit to disk */
+         ) {
+ 
+         SET_FNAME ( "H5PartWriteDataFloat64" );
+         h5part_int64_t herr;
+ 
+         CHECK_FILEHANDLE ( f );
+         CHECK_WRITABLE_MODE( f );
+         CHECK_TIMEGROUP( f );
+ 
+         herr = _append_data ( f, name, (void*)array, H5T_NATIVE_DOUBLE );
+         if ( herr < 0 ) return herr;
+ 
+         return H5PART_SUCCESS;
+ }
+ 
+ 
+ h5part_int64_t
+ H5PartAppendDataInt32 (
+         H5PartFile *f,          /*!< [in] Handle to open file */
+         const char *name,       /*!< [in] Name to associate array with */
+         const h5part_int32_t *array   /*!< [in] Array to commit to disk */
+         ) {
+ 
+         SET_FNAME ( "H5PartWriteDataInt64" );
+         h5part_int64_t herr;
+ 
+         CHECK_FILEHANDLE ( f );
+         CHECK_WRITABLE_MODE( f );
+         CHECK_TIMEGROUP( f );
+ 
+         herr = _append_data ( f, name, (void*)array, H5T_NATIVE_INT32 );
+         if ( herr < 0 ) return herr;
+ 
+         return H5PART_SUCCESS;
+ }
+ 
+ h5part_int64_t
+ H5PartAppendDataInt64 (
+         H5PartFile *f,          /*!< [in] Handle to open file */
+         const char *name,       /*!< [in] Name to associate array with */
+         const h5part_int64_t *array   /*!< [in] Array to commit to disk */
+         ) {
+ 
+         SET_FNAME ( "H5PartWriteDataInt64" );
+         h5part_int64_t herr;
+ 
+         CHECK_FILEHANDLE ( f );
+         CHECK_WRITABLE_MODE( f );
+         CHECK_TIMEGROUP( f );
+ 
+         herr = _append_data ( f, name, (void*)array, H5T_NATIVE_INT64 );
+         if ( herr < 0 ) return herr;
+ 
+         return H5PART_SUCCESS;
+ }
+ 
+ 
  /********************** reading and writing attribute ************************/
  
  /********************** private functions to handle attributes ***************/

EOF

}

function apply_h5part_patch
{
    if [[ ${H5PART_VERSION} == 1.6.6 ]] ; then
        apply_h5part_1_6_6_patch
        if [[ $? != 0 ]] ; then
            return 1
        fi
    fi

    return 0
}

# ***************************************************************************
#                         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

    #
    # Apply patches
    #
    apply_h5part_patch
    if [[ $? != 0 ]] ; then
        if [[ $untarred_h5part == 1 ]] ; then
            warn "Giving up on H5part 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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi

    #
    # Apply configure
    #
    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

    EXTRAARGS=""
    # detect coral systems, which older versions of autoconf don't detect
    if [[ "$(uname -m)" == "ppc64le" ]] ; then
         EXTRAARGS="ac_cv_build=powerpc64le-unknown-linux-gnu"
    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 $EXTRAARGS \
       --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"
}

function bv_hdf4_enable
{
    DO_HDF4="yes"
    DO_SZIP="yes"
}

function bv_hdf4_disable
{
    DO_HDF4="no"
}

function bv_hdf4_depends_on
{
    echo "szip zlib"
}

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="73b0021210bae8c779f9f1435a393ded0f344cfb01f7ee8b8794ec9d41dcd427"
}

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 "%-20s %s [%s]\n" "--hdf4" "Build HDF4" "${DO_HDF4}"
}

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=$?
    # 0, already exists, 1 untarred src, 2 error

    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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi

    #
    # Set  Fortran compiler
    #
    # Disable Fortran on Darwin since it causes HDF4 builds to fail.
    if [[ "$OPSYS" == "Darwin" ]]; then
        FORTRANARGS="--disable-fortran"
    elif [[ "$FC_COMPILER" == "no" ]] ; then
        FORTRANARGS="--disable-fortran"
    else
        FORTRANARGS="FC=\"$FC_COMPILER\" F77=\"$FC_COMPILER\" FCFLAGS=\"$FCFLAGS\" FFLAGS=\"$FCFLAGS\" --enable-fortran"
    fi

    #
    # Configure HDF4
    #
    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\" \
        --with-zlib=\"$VISITDIR/zlib/$ZLIB_VERSION/$VISITARCH\" \
        --disable-dependency-tracking --disable-netcdf"
        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\" \
        --with-zlib=\"$VISITDIR/zlib/$ZLIB_VERSION/$VISITARCH\" --disable-netcdf"
        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"

        # relocate the .a's we don't want them.
        mkdir "$VISITDIR/hdf4/$HDF4_VERSION/$VISITARCH/lib/static"
        mv "$VISITDIR/hdf4/$HDF4_VERSION/$VISITARCH/lib/libdf.a" "$VISITDIR/hdf4/$HDF4_VERSION/$VISITARCH/lib/static"
        mv "$VISITDIR/hdf4/$HDF4_VERSION/$VISITARCH/lib/libmfhdf.a" "$VISITDIR/hdf4/$HDF4_VERSION/$VISITARCH/lib/static"
    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 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"
}

function bv_hdf5_disable
{
    DO_HDF5="no"
}

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="zlib"

        if [[ "$DO_SZIP" == "yes" ]] ; then
            depends_on="$depends_on szip"    
        fi

        if [[ -n "$PAR_COMPILER" && "$DO_MOAB" == "yes"  && "$DO_MPICH" == "yes" ]]; then
            depends_on="$depends_on mpich"
        fi

        echo $depends_on
    fi
}

function bv_hdf5_initialize_vars
{
    if [[ "$USE_SYSTEM_HDF5" == "no" ]]; then
        HDF5_INSTALL_DIR="${VISITDIR}/hdf5/$HDF5_VERSION/${VISITARCH}"
        if [[ -n "$PAR_COMPILER" && "$DO_MOAB" == "yes" ]]; then
            HDF5_MPI_INSTALL_DIR="${VISITDIR}/hdf5_mpi/$HDF5_VERSION/${VISITARCH}"
        fi
    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 "%-20s %s [%s]\n" "--hdf5" "Build HDF5" "${DO_HDF5}"
    printf "%-20s %s [%s]\n" "--alt-hdf5-dir" "Use HDF5 from an alternative directory"
}

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 [[ -n "$HDF5_MPI_INSTALL_DIR" ]]; then
                echo \
                    "VISIT_OPTION_DEFAULT(VISIT_HDF5_MPI_DIR \${VISITHOME}/hdf5_mpi/$HDF5_VERSION/\${VISITARCH})" \
                    >> $HOSTCONF 
            fi

            ZLIB_LIBDEP="\${VISITHOME}/zlib/\${ZLIB_VERSION}/\${VISITARCH}/lib z"
            SZIP_LIBDEP=""
            if [[ "$DO_SZIP" == "yes" ]] ; then
                SZIP_LIBDEP="\${VISITHOME}/szip/$SZIP_VERSION/\${VISITARCH}/lib sz"
            fi
            
            echo \
                "VISIT_OPTION_DEFAULT(VISIT_HDF5_LIBDEP $SZIP_LIBDEP $ZLIB_LIBDEP TYPE STRING)" \
                    >> $HOSTCONF
            if [[ -n "$HDF5_MPI_INSTALL_DIR" ]]; then
                echo \
                    "VISIT_OPTION_DEFAULT(VISIT_HDF5_MPI_LIBDEP $SZIP_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=$?
    # 0, already exists, 1 untarred src, 2 error

    if [[ $untarred_hdf5 == -1 ]] ; then
        warn "Unable to prepare HDF5 Build Directory. Giving Up"
        return 1
    fi

    #
    # Apply patches
    #
    cd $HDF5_BUILD_DIR || error "Can't cd to HDF5 build dir."
    apply_hdf5_patch
    if [[ $? != 0 ]] ; then
        if [[ $untarred_hdf5 == 1 ]] ; then
            warn "Giving up on HDF5 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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi

    #
    # Configure HDF5
    #
    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
    info "Configuring HDF5 with ZLib support."
    cf_zlib="--with-zlib=${zlib_dir}"
    zlib_dir="${VISITDIR}/zlib/${ZLIB_VERSION}/${VISITARCH}"

    # Disable Fortran on Darwin since it causes HDF5 builds to fail.
    if [[ "$OPSYS" == "Darwin" ]]; then
        cf_fortranargs=""
    elif [[ "$FC_COMPILER" == "no" ]] ; then
        cf_fortranargs=""
    else
        cf_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

    par_build_types="serial"
    if [[ -n "$PAR_COMPILER" && "$DO_MOAB" == "yes" ]]; then
        par_build_types="$par_build_types parallel"
    fi

    extra_ac_flags=""
    # detect coral systems, which older versions of autoconf don't detect
    if [[ "$(uname -m)" == "ppc64le" ]] ; then
         extra_ac_flags="ac_cv_build=powerpc64le-unknown-linux-gnu"
    fi 
    
    for bt in $par_build_types; do

        rm -rf build_$bt
        mkdir build_$bt
        pushd build_$bt

        cf_build_parallel=""
        cf_par_suffix=""
        if [[ "$bt" == "serial" ]]; then
            cf_build_parallel="--disable-parallel"
            cf_c_compiler="$C_COMPILER"
        elif [[ "$bt" == "parallel" ]]; then
            # these commands ruin the untar'd source code for 'normal' builds
            sed -e 's/libhdf5/libhdf5_mpi/g' -i.orig ../configure
            find .. -name Makefile.in -exec sed -e 's/libhdf5/libhdf5_mpi/g' -i.orig {} \;
            sed -e 's/libhdf5\.settings/libhdf5_mpi.settings/g' -i.orig ../src/H5make_libsettings.c
            pushd ../src; ln -s libhdf5.settings.in libhdf5_mpi.settings.in; popd
            cf_build_parallel="--enable-parallel"
            cf_par_suffix="_mpi"
            cf_c_compiler="$PAR_COMPILER"
        fi

        # In order to ensure $cf_fortranargs is expanded to build the arguments to
        # configure, we wrap the invokation in 'sh -c "..."' syntax
        info "Invoking command to configure $bt HDF5"
        info "../configure CC=\"$cf_c_compiler\" \
            CFLAGS=\"$CFLAGS $C_OPT_FLAGS\" $cf_fortranargs \
            --prefix=\"$VISITDIR/hdf5${cf_par_suffix}/$HDF5_VERSION/$VISITARCH\" \
            ${cf_szip} ${cf_zlib} ${cf_build_type} ${cf_build_thread} \
            ${cf_build_parallel} ${extra_ac_flags}"
        sh -c "../configure CC=\"$cf_c_compiler\" \
            CFLAGS=\"$CFLAGS $C_OPT_FLAGS\" $cf_fortranargs \
            --prefix=\"$VISITDIR/hdf5${cf_par_suffix}/$HDF5_VERSION/$VISITARCH\" \
            ${cf_szip} ${cf_zlib} ${cf_build_type} ${cf_build_thread} \
            ${cf_build_parallel} ${extra_ac_flags}"
        if [[ $? != 0 ]] ; then
            warn "$bt HDF5 configure failed.  Giving up"
            return 1
        fi

        #
        # Build HDF5
        #
        info "Making $bt HDF5 . . ."
        info "$MAKE $MAKE_OPT_FLAGS" lib
        $MAKE $MAKE_OPT_FLAGS lib
        if [[ $? != 0 ]] ; then
            warn "$bt HDF5 build failed.  Giving up"
            return 1
        fi
        #
        # Install into the VisIt third party location.
        #
        # Install all targets until we can figure out
        # how to avoid installing just the tests.
        #
        info "Installing $bt HDF5 . . ."
        $MAKE install

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

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

        popd
    done

    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"
}

function bv_icet_enable
{
    DO_ICET="yes"
}

function bv_icet_disable
{
    DO_ICET="no"
}

function bv_icet_depends_on
{
    depends_on="cmake"
    if [[ "$DO_MPICH" == "yes" ]] ; then
        depends_on="$depends_on mpich"
    fi

    echo $depends_on
}

function bv_icet_info
{
    export ICET_FILE=${ICET_FILE:-"icet-master-77c708f9090236b576669b74c53e9f105eedbd7e.tar.gz"}
    export ICET_VERSION=${ICET_VERSION:-"77c708f9090236b576669b74c53e9f105eedbd7e"}
    export ICET_COMPATIBILITY_VERSION=${ICET_COMPATIBILITY_VERSION:-"77c708f9090236b576669b74c53e9f105eedbd7e"}
    export ICET_BUILD_DIR=${ICET_BUILD_DIR:-"icet-master-77c708f9090236b576669b74c53e9f105eedbd7e"}
    export ICET_MD5_CHECKSUM="c2e185e7d624b1f1bf0efd41bc83c83c"
    export ICET_SHA256_CHECKSUM="38ed9599b4815b376444223435905b66763912cb66749d90d377ef41d430ba77"
}

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 "%-20s %s [%s]\n" "--icet" "Build Ice-T (parallel rendering lib)" "$DO_ICET"
    printf "%-20s %s [%s]\n" "--no-icet" "Prevent Ice-T from being built" "$PREVENT_ICET"
    printf "%-20s %s\n" "" "NOTE: Ice-T is automatically built with --enable-parallel."
}

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://icet.sandia.gov/_assets/files"
        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_patch
{
    info "Patching IceT . . ."
    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 build 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

    if [[ "$OPSYS" == "Darwin" ]] ; then
        ${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}"\
        -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\
        .
    else
        ${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\
        .
    fi

    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_ispc_initialize
{
    export DO_ISPC="no"
    export USE_SYSTEM_ISPC="no"
    add_extra_commandline_args "ispc" "alt-ispc-dir" 1 "Use alternative directory for ispc"
}

function bv_ispc_enable
{
    DO_ISPC="yes"
}

function bv_ispc_disable
{
    DO_ISPC="no"
}

function bv_ispc_alt_ispc_dir
{
    echo "Using alternate ispc directory"
    bv_ispc_enable
    USE_SYSTEM_ISPC="yes"
    ISPC_INSTALL_DIR="$1"
}

function bv_ispc_depends_on
{
    echo ""
}

function bv_ispc_initialize_vars
{
    info "initializing ispc vars"
    if [[ "$DO_ISPC" == "yes" ]] ; then
        if [[ "$USE_SYSTEM_ISPC" == "no" ]]; then
            ISPC_INSTALL_DIR=$VISITDIR/ispc/$ISPC_VERSION/$VISITARCH
        fi
    fi
}

function bv_ispc_info
{
    export ISPC_VERSION=${ISPC_VERSION:-"1.9.2"}
    if [[ "$OPSYS" == "Darwin" ]] ; then
        export ISPC_FILE=${ISPC_FILE:-"ispc-v${ISPC_VERSION}-osx.tar.gz"}
        export ISPC_URL=${ISPC_URL:-"http://sdvis.org/ospray/download/dependencies/osx/"}
        # these are binary builds, not source tarballs so the mdf5s and shas differ 
        # between platforms 
        export ISPC_MD5_CHECKSUM="387cce62a6c63def5e6eb1c0a468a3db"
        export ISPC_SHA256_CHECKSUM="aa307b97bea67d71aff046e3f69c0412cc950eda668a225e6b909dba752ef281"
        export ISPC_INSTALL_DIR_NAME=ispc-v$ISPC_VERSION-osx
    else
        export ISPC_FILE=${ISPC_FILE:-"ispc-v${ISPC_VERSION}-linux.tar.gz"}
        export ISPC_URL=${ISPC_URL:-"http://sdvis.org/ospray/download/dependencies/linux/"}
        # these are binary builds, not source tarballs so the mdf5s and shas differ 
        # between platforms 
        export ISPC_MD5_CHECKSUM="0178a33a065ae65d0be00be23871cf9f"
        export ISPC_SHA256_CHECKSUM="5513fbf8a2f6e889232ec1e7aa42f6f0b47954dcb9797e1e3d5e8d6f59301e40"
        export ISPC_INSTALL_DIR_NAME=ispc-v$ISPC_VERSION-linux
    fi
    export ISPC_COMPATIBILITY_VERSION=${ISPC_COMPATIBILITY_VERSION:-"${ISPC_VERSION}"}
    export ISPC_BUILD_DIR=${ISPC_BUILD_DIR:-"${ISPC_VERSION}"}
}

function bv_ispc_print
{
    printf "%s%s\n" "ISPC_FILE=" "${ISPC_FILE}"
    printf "%s%s\n" "ISPC_VERSION=" "${ISPC_VERSION}"
    printf "%s%s\n" "ISPC_COMPATIBILITY_VERSION=" "${ISPC_COMPATIBILITY_VERSION}"
    printf "%s%s\n" "ISPC_BUILD_DIR=" "${ISPC_BUILD_DIR}"
}

function bv_ispc_host_profile
{
    if [[ "$DO_ISPC" == "yes" ]]; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## ISPC" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        if [[ "$USE_SYSTEM_ISPC" == "no" ]]; then
            echo "SETUP_APP_VERSION(ISPC ${ISPC_VERSION})" >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(VISIT_ISPC_DIR \${VISITHOME}/ispc/\${ISPC_VERSION}/\${VISITARCH})" >> $HOSTCONF
        else
            echo "VISIT_OPTION_DEFAULT(VISIT_ISPC_DIR ${ISPC_INSTALL_DIR})" >> $HOSTCONF
        fi
    fi
}

function bv_ispc_print_usage
{
    #ispc does not have an option, it is only dependent on ispc.
    printf "%-20s %s [%s]\n" "--ispc" "Build ISPC" "$DO_ISPC"
}

function bv_ispc_ensure
{
    if [[ "$DO_ISPC" == "yes" && "$USE_SYSTEM_ISPC" == "no" ]] ; then
        ensure_built_or_ready "ispc" $ISPC_VERSION $ISPC_BUILD_DIR $ISPC_FILE $ISPC_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_ISPC="no"
            error "Unable to build ISPC.  ${ISPC_FILE} not found."
        fi
    fi
}

function bv_ispc_dry_run
{
    if [[ "$DO_ISPC" == "yes" ]] ; then
        echo "Dry run option not set for ISPC."
    fi
}

# ***************************************************************************
# build_ispc
#
# Modifications:
#
# ***************************************************************************

function build_ispc
{
    # Unzip the ISPC tarball and copy it to the VisIt installation.
    info "Installing prebuilt ISPC"    
    tar zxvf $ISPC_FILE
    mkdir -p $VISITDIR/ispc/$ISPC_VERSION/$VISITARCH || error "Cannot create ispc install directory"
    cp -R $ISPC_INSTALL_DIR_NAME/* $VISITDIR/ispc/$ISPC_VERSION/$VISITARCH || error "Cannot copy to ispc install directory"
    if [[ "$DO_GROUP" == "yes" ]] ; then
        chmod -R ug+w,a+rX "$VISITDIR/ispc/$ISPC_VERSION/$VISITARCH"
        chgrp -R ${GROUP} "$VISITDIR/ispc/$ISPC_VERSION/$VISITARCH"
    fi
    cd "$START_DIR"
    info "Done with ISPC"
    return 0
}

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

function bv_ispc_is_installed
{
    if [[ "$USE_SYSTEM_ISPC" == "yes" ]]; then   
        return 1
    fi

    check_if_installed "ispc" $ISPC_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_ispc_build
{
    if [[ "$DO_ISPC" == "yes" && "$USE_SYSTEM_ISPC" == "no" ]] ; then
        check_if_installed "ispc" $ISPC_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping build of ISPC"
        else
            build_ispc
            if [[ $? != 0 ]] ; then
                error "Unable to build or install ISPC.  Bailing out."
            fi
            info "Done building ISPC"
        fi
    fi
}

function bv_llvm_initialize
{
    export DO_LLVM="no"
}

function bv_llvm_enable
{
    DO_LLVM="yes"
}

function bv_llvm_disable
{
    DO_LLVM="no"
}

function bv_llvm_depends_on
{
    depends_on="cmake"
    if [[ $DO_PYTHON == "yes" ]] ; then
        depends_on="$depends_on python"
    fi

    echo ${depends_on}
}

function bv_llvm_info
{
    export BV_LLVM_VERSION=${BV_LLVM_VERSION:-"5.0.0"}
    export BV_LLVM_FILE=${BV_LLVM_FILE:-"llvm-${BV_LLVM_VERSION}.src.tar.xz"}
    export BV_LLVM_URL=${BV_LLVM_URL:-"http://releases.llvm.org/${BV_LLVM_VERSION}/"}
    export BV_LLVM_BUILD_DIR=${BV_LLVM_BUILD_DIR:-"llvm-${BV_LLVM_VERSION}.src"}
    export LLVM_MD5_CHECKSUM="5ce9c5ad55243347ea0fdb4c16754be0"
    export LLVM_SHA256_CHECKSUM="e35dcbae6084adcf4abb32514127c5eabd7d63b733852ccdb31e06f1373136da"
}

function bv_llvm_print
{
    printf "%s%s\n" "BV_LLVM_FILE=" "${BV_LLVM_FILE}"
    printf "%s%s\n" "BV_LLVM_VERSION=" "${BV_LLVM_VERSION}"
    printf "%s%s\n" "LLVM_TARGET=" "${LLVM_TARGET}"
    printf "%s%s\n" "BV_LLVM_BUILD_DIR=" "${BV_LLVM_BUILD_DIR}"
}

function bv_llvm_print_usage
{
    printf "%-20s %s [%s]\n" "--llvm" "Build LLVM" "$DO_LLVM"
}

function bv_llvm_host_profile
{
    if [[ "$DO_LLVM" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## LLVM" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_LLVM_DIR \${VISITHOME}/llvm/$BV_LLVM_VERSION/\${VISITARCH})" >> $HOSTCONF
    fi
}

function bv_llvm_initialize_vars
{
    export VISIT_LLVM_DIR=${VISIT_LLVM_DIR:-"$VISITDIR/llvm/${BV_LLVM_VERSION}/${VISITARCH}"}
    LLVM_INCLUDE_DIR="${VISIT_LLVM_DIR}/include"
    LLVM_LIB_DIR="${VISIT_LLVM_DIR}/lib"
    if [[ "$DO_STATIC_BUILD" == "yes" ]]; then
        LLVM_LIB="${LLVM_LIB_DIR}/libLLVM.a"
    else
        LLVM_LIB="${LLVM_LIB_DIR}/libLLVM.${SO_EXT}"
    fi
}

function bv_llvm_selected
{
    args=$@
    if [[ $args == "--llvm" ]]; then
        DO_LLVM="yes"
        return 1
    fi

    return 0
}

function bv_llvm_ensure
{
    if [[ "$DO_DBIO_ONLY" != "yes" ]]; then
        if [[ "$DO_LLVM" == "yes" ]] ; then
            ensure_built_or_ready "llvm"   $BV_LLVM_VERSION   $BV_LLVM_BUILD_DIR   $BV_LLVM_FILE $BV_LLVM_URL
            if [[ $? != 0 ]] ; then
                return 1
            fi
        fi
    fi
}

function bv_llvm_dry_run
{
    if [[ "$DO_LLVM" == "yes" ]] ; then
        echo "Dry run option not set for llvm."
    fi
}

function apply_llvm_patch
{
    # fixes a bug in LLVM 5.0.0
    # where if the LLVM_BUILD_LLVM_DYLIB CMake var is set to ON,
    # CMake will fail when checking an internal variable that is empty
    # patch based on https://reviews.llvm.org/D31445

    patch -p0 << \EOF
*** tools/llvm-shlib/CMakeLists.txt.original     2018-06-14 16:16:13.185286160 -0500
--- tools/llvm-shlib/CMakeLists.txt      2018-06-14 16:16:59.773283611 -0500
***************
*** 36,42 ****

  add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${SOURCES})

! list(REMOVE_DUPLICATES LIB_NAMES)
  if(("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") OR (MINGW) OR (HAIKU) OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD") OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "DragonFly")) # FIXME: It should be "GNU ld for elf"
    configure_file(
    ${CMAKE_CURRENT_SOURCE_DIR}/simple_version_script.map.in
--- 36,44 ----

  add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${SOURCES})

! if(LIB_NAMES)
!     list(REMOVE_DUPLICATES LIB_NAMES)
! endif()
  if(("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") OR (MINGW) OR (HAIKU) OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD") OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "DragonFly")) # FIXME: It should be "GNU ld for elf"
    configure_file(
    ${CMAKE_CURRENT_SOURCE_DIR}/simple_version_script.map.in
EOF
    if [[ $? != 0 ]] ; then
        warn "llvm patch for tools/llvm-shlib/CMakeLists.txt failed"
        return 1
    fi

    # fixes a bug in LLVM 5.0.0
    # a vector<char> is cast to a vector<unsigned char>. This patch comes
    # from http://lists.busybox.net/pipermail/buildroot/2018-May/221648.html
    # This is presumably fixed in LLVM 6.0.0.

    patch -p0 << \EOF
--- include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h.orig	2019-07-26 13:23:06.588925000 -0700
+++ include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h	2019-07-26 13:23:53.990216000 -0700
@@ -713,8 +713,8 @@
 
   uint32_t getTrampolineSize() const { return RemoteTrampolineSize; }
 
-  Expected<std::vector<char>> readMem(char *Dst, JITTargetAddress Src,
-                                      uint64_t Size) {
+  Expected<std::vector<uint8_t>> readMem(char *Dst, JITTargetAddress Src,
+                                         uint64_t Size) {
     // Check for an 'out-of-band' error, e.g. from an MM destructor.
     if (ExistingError)
       return std::move(ExistingError);
EOF
    if [[ $? != 0 ]] ; then
        warn "llvm patch for include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h failed"
        return 1
    fi
}

function build_llvm
{
    #
    # prepare build dir
    #
    prepare_build_dir $BV_LLVM_BUILD_DIR $BV_LLVM_FILE
    untarred_llvm=$?
    if [[ $untarred_llvm == -1 ]] ; then
        warn "Unable to prepare LLVM build directory. Giving Up!"
        return 1
    fi

    #
    # Build LLVM.
    #

    #
    # LLVM must be built with an out of source build.
    #
    BV_LLVM_SRC_DIR=${BV_LLVM_BUILD_DIR}
    BV_LLVM_BUILD_DIR="${BV_LLVM_SRC_DIR}-build"
    if [[ ! -d ${BV_LLVM_BUILD_DIR} ]] ; then
        info "Making build directory ${BV_LLVM_BUILD_DIR}"
        mkdir ${BV_LLVM_BUILD_DIR}
    fi

    #
    # Patch LLVM
    #
    
    cd "$BV_LLVM_SRC_DIR" || error "Couldn't cd to llvm src dir."
    apply_llvm_patch
    if [[ $? != 0 ]] ; then
	if [[ $untarred_llvm == 1 ]] ; then
	    warn "Giving up on LLVM 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 that had\n" \
		 "already been patched ... that is, the patch is\n" \
		 "failing harmlessly on a second application."
        fi
    fi

    cd "$START_DIR"
    cd ${BV_LLVM_BUILD_DIR} || error "Couldn't cd to llvm build dir."

    #
    # Remove any CMakeCache.txt files just to be safe.
    #
    rm -f CMakeCache.txt */CMakeCache.txt

    info "Configuring LLVM . . ."
    if [[ $DO_PYTHON == "yes" ]] ; then
        LLVM_CMAKE_PYTHON="-DPYTHON_EXECUTABLE:FILEPATH=$PYTHON_COMMAND"
    fi

    #
    # Determine the LLVM_TARGET_TO_BUILD.
    #
    if [[ "$(uname -m)" == "ppc64" || "$(uname -m)" == "ppc64le" ]]; then
        LLVM_TARGET="PowerPC"
    else
        LLVM_TARGET="X86"
    fi

    # LLVM documentation states thet BUILD_SHARED_LIBS is not to be used
    # in conjuction with LLVM_BUILD_LLVM_DYLIB, and should only be used
    # by LLVM developers.
    ${CMAKE_COMMAND} \
        -DCMAKE_INSTALL_PREFIX:PATH="${VISIT_LLVM_DIR}" \
        -DCMAKE_BUILD_TYPE:STRING="${VISIT_BUILD_MODE}" \
        -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON \
        -DBUILD_SHARED_LIBS:BOOL=OFF \
        -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} \
        -DLLVM_TARGETS_TO_BUILD=${LLVM_TARGET} \
        -DLLVM_ENABLE_RTTI:BOOL=ON \
        -DLLVM_BUILD_LLVM_DYLIB:BOOL=ON \
        $LLVM_CMAKE_PYTHON \
        ../${BV_LLVM_SRC_DIR}
    if [[ $? != 0 ]] ; then
        warn "LLVM cmake failed.  Giving up"
        return 1
    fi

    info "Building LLVM . . ."
    ${MAKE} ${MAKE_OPT_FLAGS}
    if [[ $? != 0 ]] ; then
        warn "LLVM build failed.  Giving up"
        return 1
    fi

    info "Installing LLVM . . ."
    ${MAKE} ${MAKE_OPT_FLAGS} install
    if [[ $? != 0 ]] ; then
        warn "LLVM install failed.  Giving up"
        return 1
    fi

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

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

function bv_llvm_is_installed
{
    check_if_installed "llvm" $BV_LLVM_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_llvm_build
{
    #
    # Build LLVM
    #
    cd "$START_DIR"
    if [[ "$DO_LLVM" == "yes" ]] ; then
        check_if_installed "llvm" $BV_LLVM_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping LLVM build.  LLVM is already installed."
        else
            info "Building LLVM (~60 minutes)"
            build_llvm
            if [[ $? != 0 ]] ; then
                error "Unable to build or install LLVM.  Bailing out."
            fi
            info "Done building LLVM"
        fi
    fi
}
function bv_mdsplus_initialize
{
    export DO_MDSPLUS="no"
}

function bv_mdsplus_enable
{
    DO_MDSPLUS="yes"
}

function bv_mdsplus_disable
{
    DO_MDSPLUS="no"
}

function bv_mdsplus_depends_on
{
    echo ""
}

function bv_mdsplus_info
{
    export MDSPLUS_VERSION=${MDSPLUS_VERSION:-"5.0"}
    export MDSPLUS_FILE=${MDSPLUS_FILE:-"mdsplus-${MDSPLUS_VERSION}.tar.gz"}
    export MDSPLUS_COMPATIBILITY_VERSION=${MDSPLUS_COMPATIBILITY_VERSION:-"5.0"}
    export MDSPLUS_BUILD_DIR=${MDSPLUS_BUILD_DIR:-"mdsplus-${MDSPLUS_VERSION}"}
    #export MDSPLUS_BUILD_DIR=${MDSPLUS_BUILD_DIR:-"mdsplus"}
    export MDSPLUS_MD5_CHECKSUM=""
    export MDSPLUS_SHA256_CHECKSUM=""
}

function bv_mdsplus_print
{
    printf "%s%s\n" "MDSPLUS_FILE=" "${MDSPLUS_FILE}"
    printf "%s%s\n" "MDSPLUS_VERSION=" "${MDSPLUS_VERSION}"
    printf "%s%s\n" "MDSPLUS_COMPATIBILITY_VERSION=" "${MDSPLUS_COMPATIBILITY_VERSION}"
    printf "%s%s\n" "MDSPLUS_BUILD_DIR=" "${MDSPLUS_BUILD_DIR}"
}

function bv_mdsplus_print_usage
{
    printf "%-20s %s [%s]\n" "--mdsplus" "Build MDSplus" "${DO_MDSPLUS}"
}

function bv_mdsplus_host_profile
{
    if [[ "$DO_MDSPLUS" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## Mdsplus" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
            "VISIT_OPTION_DEFAULT(VISIT_MDSPLUS_DIR \${VISITHOME}/mdsplus/$MDSPLUS_VERSION/\${VISITARCH})" \
            >> $HOSTCONF
        echo \
            "VISIT_OPTION_DEFAULT(VISIT_MDSPLUS_LIBDEP HDF5_LIBRARY_DIR hdf5 \${VISIT_HDF5_LIBDEP} TYPE STRING)" \
            >> $HOSTCONF
    fi
}

function bv_mdsplus_ensure
{
    if [[ "$DO_MDSPLUS" == "yes" ]] ; then
        ensure_built_or_ready "mdsplus" $MDSPLUS_VERSION $MDSPLUS_BUILD_DIR $MDSPLUS_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_MDSPLUS="no"
            error "Unable to build MDSplus.  ${MDSPLUS_FILE} not found."
        fi
    fi
}

function bv_mdsplus_dry_run
{
    if [[ "$DO_MDSPLUS" == "yes" ]] ; then
        echo "Dry run option not set for mdsplus."
    fi
}

# ***************************************************************************
#                         Function 8.20, build_mdsplus
#
# Modifications:
#
#  Mark C. Miller, Tue Oct 28 11:10:36 PDT 2008
#  Added -DH5_USE_16_API to CFLAGS for configuring MDSplus. This should be
#  harmless when building MDSplus 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 MDSplus was implemented with.
# ***************************************************************************

function build_mdsplus
{
    #
    # Prepare build dir
    #
    prepare_build_dir $MDSPLUS_BUILD_DIR $MDSPLUS_FILE
    untarred_mdsplus=$?
    if [[ $untarred_mdsplus == -1 ]] ; then
        warn "Unable to prepare MDSplus Build Directory. Giving Up"
        return 1
    fi

    #
    info "Configuring MDSplus . . ."
    cd $MDSPLUS_BUILD_DIR || error "Can't cd to mdsplus build dir."
    info "Invoking command to configure MDSplus"
    ./configure ${OPTIONAL} --disable-java CXX="$CXX_COMPILER" \
                CC="$C_COMPILER" CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
                --prefix="$VISITDIR/mdsplus/$MDSPLUS_VERSION/$VISITARCH"
    if [[ $? != 0 ]] ; then
        warn "MDSplus configure failed.  Giving up"
        return 1
    fi

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

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

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

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

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

function bv_mdsplus_is_installed
{
    check_if_installed "mdsplus" $MDSPLUS_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_mdsplus_build
{
    cd "$START_DIR"
    if [[ "$DO_MDSPLUS" == "yes" ]] ; then
        check_if_installed "mdsplus" $MDSPLUS_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping MDSplus build.  MDSplus is already installed."
        else
            info "Building MDSplus (~1 minutes)"
            build_mdsplus
            if [[ $? != 0 ]] ; then
                error "Unable to build or install MDSplus.  Bailing out."
            fi
            info "Done building MDSplus"
        fi
    fi
}
function bv_mesagl_initialize
{
    export DO_MESAGL="no"
}

function bv_mesagl_enable
{
    DO_MESAGL="yes"
    bv_glu_enable
}

function bv_mesagl_disable
{
    DO_MESAGL="no"
}

function bv_mesagl_depends_on
{
    echo "llvm"
}

function bv_mesagl_info
{
    export MESAGL_VERSION=${MESAGL_VERSION:-"17.2.8"}
    export MESAGL_FILE=${MESAGL_FILE:-"mesa-$MESAGL_VERSION.tar.gz"}
    export MESAGL_URL=${MESAGL_URL:-"https://mesa.freedesktop.org/archive/"}
    export MESAGL_BUILD_DIR=${MESAGL_BUILD_DIR:-"mesa-$MESAGL_VERSION"}
    export MESAGL_MD5_CHECKSUM="19832be1bc5784fc7bbad4d138537619"
    export MESAGL_SHA256_CHECKSUM="c715c3a3d6fe26a69c096f573ec416e038a548f0405e3befedd5136517527a84"
}

function bv_mesagl_print
{
    printf "%s%s\n" "MESAGL_FILE=" "${MESAGL_FILE}"
    printf "%s%s\n" "MESAGL_VERSION=" "${MESAGL_VERSION}"
    printf "%s%s\n" "MESAGL_TARGET=" "${MESAGL_TARGET}"
    printf "%s%s\n" "MESAGL_BUILD_DIR=" "${MESAGL_BUILD_DIR}"
}

function bv_mesagl_print_usage
{
    printf "%-20s %s [%s]\n" "--mesagl" "Build MesaGL" "$DO_MESAGL"
}

function bv_mesagl_host_profile
{
    if [[ "$DO_MESAGL" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## MesaGL" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_MESAGL_DIR \${VISITHOME}/mesagl/$MESAGL_VERSION/\${VISITARCH})" >> $HOSTCONF
    fi
}

function bv_mesagl_selected
{
    args=$@
    if [[ $args == "--mesagl" ]]; then
        DO_MESAGL="yes"
        return 1
    fi

    return 0
}

function bv_mesagl_initialize_vars
{
    info "initalizing mesagl vars"
    if [[ "$DO_MESAGL" == "yes" ]]; then
        MESAGL_INSTALL_DIR="${VISITDIR}/mesagl/${MESAGL_VERSION}/${VISITARCH}"
        MESAGL_INCLUDE_DIR="${MESAGL_INSTALL_DIR}/include"
        MESAGL_LIB_DIR="${MESAGL_INSTALL_DIR}/lib"
        if [[ "$DO_STATIC_BUILD" == "yes" ]]; then
            MESAGL_OPENGL_LIB="${MESAGL_LIB_DIR}/libGL.a"
            MESAGL_OSMESA_LIB="${MESAGL_LIB_DIR}/libOSMesa.a"
            # initialized here, because glu's initialize_vars is called first
            # and install location won't be set properly for use with VTK
            MESAGL_GLU_LIB="${MESAGL_LIB_DIR}/libGLU.a"
        else
            MESAGL_OPENGL_LIB="${MESAGL_LIB_DIR}/libGL.${SO_EXT}"
            MESAGL_OSMESA_LIB="${MESAGL_LIB_DIR}/libOSMesa.${SO_EXT}"
            # initialized here, because glu's initialize_vars is called first
            # and install location won't be set properly for use with VTK
            MESAGL_GLU_LIB="${MESAGL_LIB_DIR}/libGLU.${SO_EXT}"
        fi
    fi
}

function bv_mesagl_ensure
{
    if [[ "$DO_DBIO_ONLY" != "yes" ]]; then
        if [[ "$DO_MESAGL" == "yes" ]] ; then
            ensure_built_or_ready "mesagl"   $MESAGL_VERSION   $MESAGL_BUILD_DIR   $MESAGL_FILE $MESAGL_URL
            if [[ $? != 0 ]] ; then
                return 1
            fi
        fi
    fi
}

function bv_mesagl_dry_run
{
    if [[ "$DO_MESAGL" == "yes" ]] ; then
        echo "Dry run option not set for mesagl."
    fi
}

function apply_mesagl_patch
{
    patch -p0 << \EOF
diff -c configure.ac.orig configure.ac
*** configure.ac.orig	Thu Oct 10 15:44:18 2019
--- configure.ac	Thu Oct 10 15:44:26 2019
***************
*** 2690,2696 ****
      dnl (See https://llvm.org/bugs/show_bug.cgi?id=6823)
      if test "x$enable_llvm_shared_libs" = xyes; then
          dnl We can't use $LLVM_VERSION because it has 'svn' stripped out,
!         LLVM_SO_NAME=LLVM-`$LLVM_CONFIG --version`
          AS_IF([test -f "$LLVM_LIBDIR/lib$LLVM_SO_NAME.$IMP_LIB_EXT"], [llvm_have_one_so=yes])
  
          if test "x$llvm_have_one_so" = xyes; then
--- 2690,2696 ----
      dnl (See https://llvm.org/bugs/show_bug.cgi?id=6823)
      if test "x$enable_llvm_shared_libs" = xyes; then
          dnl We can't use $LLVM_VERSION because it has 'svn' stripped out,
!         LLVM_SO_NAME=LLVM-$LLVM_VERSION
          AS_IF([test -f "$LLVM_LIBDIR/lib$LLVM_SO_NAME.$IMP_LIB_EXT"], [llvm_have_one_so=yes])
  
          if test "x$llvm_have_one_so" = xyes; then
EOF
    if [[ $? != 0 ]] ; then
        warn "MesaGL patch failed."
        return 1
    fi

    return 0;
}

function build_mesagl
{
    #
    # prepare build dir
    #
    prepare_build_dir $MESAGL_BUILD_DIR $MESAGL_FILE
    untarred_mesagl=$?
    if [[ $untarred_mesagl == -1 ]] ; then
        warn "Unable to prepare MesaGL build directory. Giving Up!"
        return 1
    fi

    #
    # Apply patches
    #
    cd $MESAGL_BUILD_DIR || error "Couldn't cd to mesagl build dir."

    info "Patching MesaGL"
    apply_mesagl_patch
    if [[ $? != 0 ]] ; then
        if [[ $untarred_mesagl == 1 ]] ; then
            warn "Giving up on MesaGL 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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi

    #
    # Build MESAGL.
    #
    if [[ "$DO_STATIC_BUILD" == "yes" ]]; then
        MESAGL_STATIC_DYNAMIC="--disable-shared --disable-shared-glapi --enable-static --enable-static-glapi"
    fi
    if [[ "$VISIT_BUILD_MODE" == "Debug" ]]; then
        MESAGL_DEBUG_BUILD="--enable-debug"
    fi
    if [[ "$(uname -m)" == "x86_64" ]] ; then
        MESAGL_GALLIUM_DRIVERS="swrast,swr"
    else
        MESAGL_GALLIUM_DRIVERS="swrast"
    fi

    info "Configuring MesaGL . . ."
    echo CXXFLAGS="${CXXFLAGS} ${CXX_OPT_FLAGS}" \
        CXX=${CXX_COMPILER} \
        CFLAGS="${CFLAGS} ${C_OPT_FLAGS}" \
        CC=${C_COMPILER} \
        ./autogen.sh \
        --prefix=${VISITDIR}/mesagl/${MESAGL_VERSION}/${VISITARCH} \
        --with-platforms=x11 \
        --disable-dri \
        --disable-dri3 \
        --disable-egl \
        --disable-gbm \
        --disable-gles1 \
        --disable-gles2 \
        --disable-xvmc \
        --disable-vdpau \
        --disable-va \
        --enable-glx \
        --enable-llvm \
        --with-gallium-drivers=${MESAGL_GALLIUM_DRIVERS} \
        --enable-gallium-osmesa $MESAGL_STATIC_DYNAMIC $MESAGL_DEBUG_BUILD \
        --with-llvm-prefix=${VISIT_LLVM_DIR}
    env CXXFLAGS="${CXXFLAGS} ${CXX_OPT_FLAGS}" \
        CXX=${CXX_COMPILER} \
        CFLAGS="${CFLAGS} ${C_OPT_FLAGS}" \
        CC=${C_COMPILER} \
        ./autogen.sh \
        --prefix=${VISITDIR}/mesagl/${MESAGL_VERSION}/${VISITARCH} \
        --with-platforms=x11 \
        --disable-dri \
        --disable-dri3 \
        --disable-egl \
        --disable-gbm \
        --disable-gles1 \
        --disable-gles2 \
        --disable-xvmc \
        --disable-vdpau \
        --disable-va \
        --enable-glx \
        --enable-llvm \
        --with-gallium-drivers=${MESAGL_GALLIUM_DRIVERS} \
        --enable-gallium-osmesa $MESAGL_STATIC_DYNAMIC $MESAGL_DEBUG_BUILD \
        --with-llvm-prefix=${VISIT_LLVM_DIR}

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

    info "Building MesaGL . . ."
    ${MAKE} ${MAKE_OPT_FLAGS}
    if [[ $? != 0 ]] ; then
        warn "MesaGL build failed.  Giving up"
        return 1
    fi

    info "Installing MesaGL ..."
    ${MAKE} ${MAKE_OPT_FLAGS} install
    if [[ $? != 0 ]] ; then
        warn "MesaGL install failed.  Giving up"
        return 1
    fi

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

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

function bv_mesagl_is_installed
{
    check_if_installed "mesagl" $MESAGL_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_mesagl_build
{
    #
    # Build MesaGL
    #
    cd "$START_DIR"
    if [[ "$DO_MESAGL" == "yes" ]] ; then
        check_if_installed "mesagl" $MESAGL_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping MesaGL build.  MesaGL is already installed."
        else
            info "Building MesaGL (~20 minutes)"
            build_mesagl
            if [[ $? != 0 ]] ; then
                error "Unable to build or install MesaGL.  Bailing out."
            fi
            info "Done building MesaGL"
        fi
    fi
}
function bv_mfem_initialize
{
    export DO_MFEM="no"
}

function bv_mfem_enable
{
    DO_MFEM="yes"
}

function bv_mfem_disable
{
    DO_MFEM="no"
}

function bv_mfem_depends_on
{
    local depends_on="zlib"

    if [[ "$DO_CONDUIT" == "yes" ]] ; then
        depends_on="$depends_on conduit"
    fi

    echo $depends_on
}

function bv_mfem_info
{
    export MFEM_VERSION=${MFEM_VERSION:-"3.4"}
    export MFEM_FILE=${MFEM_FILE:-"mfem-${MFEM_VERSION}.tgz"}
    export MFEM_BUILD_DIR=${MFEM_BUILD_DIR:-"mfem-${MFEM_VERSION}"}
    export MFEM_URL=${MFEM_URL:-"https://bit.ly/mfem-3-4"}
    export MFEM_MD5_CHECKSUM="59aff55ba3d7d7816cb3efbf84af7724"
    export MFEM_SHA256_CHECKSUM="4e73e4fe0482636de3c5dc983cd395839a83cb16f6f509bd88b053e8b3858e05"
}

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 "%-20s %s [%s]\n" "--mfem" "Build mfem support" "$DO_MFEM"
}

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

        ZLIB_LIBDEP="\${VISITHOME}/zlib/\${ZLIB_VERSION}/\${VISITARCH}/lib z"

        CONDUIT_LIBDEP=""
        if [[ "$DO_CONDUIT" == "yes" ]] ; then
            CONDUIT_LIBDEP="\${VISIT_CONDUIT_LIBDEP}"
            echo \
                "VISIT_OPTION_DEFAULT(VISIT_MFEM_INCDEP CONDUIT_INCLUDE_DIR TYPE STRING)" \
                    >> $HOSTCONF
        fi


        echo \
            "VISIT_OPTION_DEFAULT(VISIT_MFEM_LIBDEP $CONDUIT_LIBDEP $ZLIB_LIBDEP TYPE STRING)" \
                >> $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."

    ZLIBARG=-L${VISITDIR}/zlib/${ZLIB_VERSION}/${VISITARCH}/lib

    MFEM_USE_CONDUIT=NO

    if [[ "$DO_CONDUIT" == "yes" ]] ; then
        MFEM_USE_CONDUIT=YES
        CONDUIT_OPT_VALS="-I${VISITDIR}/conduit/${CONDUIT_VERSION}/${VISITARCH}/include/conduit"
        CONDUIT_LIB_VALS="-L${VISITDIR}/conduit/${CONDUIT_VERSION}/${VISITARCH}/lib/ -lconduit_relay -lconduit_blueprint -lconduit"
        # we may also need HDF5, conduit's config.mk includes this info, but mfem isn't using it yet
        if [[ "$DO_HDF5" == "yes" ]] ; then
            CONDUIT_OPT_VALS="${CONDUIT_OPT_VALS} -I${VISITDIR}/hdf5/${HDF5_VERSION}/${VISITARCH}/include/"
            CONDUIT_LIB_VALS="${CONDUIT_OPT_VALS} -L${VISITDIR}/hdf5/${HDF5_VERSION}/${VISITARCH}/ -lhdf5"
        fi
    fi

    #
    # Call configure
    #
    info "Configuring mfem . . ."
    info $MAKE config CXX="$CXX_COMPILER" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" MFEM_USE_GZSTREAM=YES LDFLAGS="$ZLIBARG -lz" \
              MFEM_USE_CONDUIT=${MFEM_USE_CONDUIT} CONDUIT_OPT="${CONDUIT_OPT_VALS}" CONDUIT_LIB="${CONDUIT_LIB_VALS}"

    $MAKE config CXX="$CXX_COMPILER" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" MFEM_USE_GZSTREAM=YES LDFLAGS="$ZLIBARG -lz" \
              MFEM_USE_CONDUIT=${MFEM_USE_CONDUIT} CONDUIT_OPT="${CONDUIT_OPT_VALS}" CONDUIT_LIB="${CONDUIT_LIB_VALS}"

    #
    # 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"
}

function bv_mili_enable
{
    DO_MILI="yes"
}

function bv_mili_disable
{
    DO_MILI="no"
}

function bv_mili_depends_on
{
    echo ""
}

function bv_mili_info
{
    export MILI_FILE=${MILI_FILE:-"mili-LGPL-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="8a1a42133c05d541a85c38cd8e9b51de"
    export MILI_SHA256_CHECKSUM="2a83a507965df6f92169bcb3e68467e8a514c641ad56d7046a4561212c562a66"
}

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 "%-20s %s [%s]\n" "--mili" "Build Mili" "$DO_MILI"
}

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_151_darwin_patch4
{
    patch -p0 << \EOF
--- mili/configure	2015-09-11 06:32:00.000000000 -0700
+++ mili/configure_minus_fortran	2016-06-22 09:34:12.000000000 -0700
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.ac Revision: 1.26.4.1 .
+# From configure.ac Revision: 1.26.4.2 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.63 for Mili V15_01.
 #
@@ -721,16 +721,13 @@
 EGREP
 GREP
 CPP
+OBJEXT
+EXEEXT
 ac_ct_CC
 CPPFLAGS
+LDFLAGS
 CFLAGS
 CC
-OBJEXT
-EXEEXT
-ac_ct_F77
-LDFLAGS
-FFLAGS
-F77
 HOSTNAME
 HOSTDIR
 HDF_DEBUG_ENABLE
@@ -830,12 +827,10 @@
       ac_precious_vars='build_alias
 host_alias
 target_alias
-F77
-FFLAGS
-LDFLAGS
-LIBS
 CC
 CFLAGS
+LDFLAGS
+LIBS
 CPPFLAGS
 CPP'
 
@@ -1484,13 +1479,11 @@
   --with-usrbuild=PATH    Use given PATH for BUILD DIRECTORY
 
 Some influential environment variables:
-  F77         Fortran 77 compiler command
-  FFLAGS      Fortran 77 compiler flags
+  CC          C compiler command
+  CFLAGS      C compiler flags
   LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
               nonstandard directory <lib dir>
   LIBS        libraries to pass to the linker, e.g. -l<library>
-  CC          C compiler command
-  CFLAGS      C compiler flags
   CPPFLAGS    C/C++/Objective C preprocessor flags, e.g. -I<include dir> if
               you have headers in a nonstandard directory <include dir>
   CPP         C preprocessor
@@ -2096,20 +2089,20 @@
 # Variable Initialization
 
 cat >>confdefs.h <<\_ACEOF
-#define PACKAGE_DATE "2015/09/11"
+#define PACKAGE_DATE "2015/09/18"
 _ACEOF
 
 
 cat >>confdefs.h <<\_ACEOF
-#define PACKAGE_TIME "06:00:00"
+#define PACKAGE_TIME "09:00:00"
 _ACEOF
 
 
 cat >>confdefs.h <<\_ACEOF
-#define PACKAGE_DATETIME "2015/09/11 06:00:00"
+#define PACKAGE_DATETIME "2015/09/18 09:00:00"
 _ACEOF
 
-PACKAGE_DATETIME="2015/09/11 06:00:00"
+PACKAGE_DATETIME="2015/09/18 09:00:00"
 
 
 #############################################################################
@@ -2441,22 +2434,24 @@
 # select compiler
 
 #AC_PROG_FC
-ac_ext=f
-ac_compile='$F77 -c $FFLAGS conftest.$ac_ext >&5'
-ac_link='$F77 -o conftest$ac_exeext $FFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_f77_compiler_gnu
+#AC_PROG_F77([ifort xlf gfortran])
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
 if test -n "$ac_tool_prefix"; then
-  for ac_prog in ifort xlf gfortran
+  for ac_prog in icc xlc gcc
   do
     # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
 set dummy $ac_tool_prefix$ac_prog; ac_word=$2
 { $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_F77+set}" = set; then
+if test "${ac_cv_prog_CC+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$F77"; then
-  ac_cv_prog_F77="$F77" # Let the user override the test.
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
 else
 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 for as_dir in $PATH
@@ -2465,7 +2460,7 @@
   test -z "$as_dir" && as_dir=.
   for ac_exec_ext in '' $ac_executable_extensions; do
   if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_F77="$ac_tool_prefix$ac_prog"
+    ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
     $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -2475,32 +2470,32 @@
 
 fi
 fi
-F77=$ac_cv_prog_F77
-if test -n "$F77"; then
-  { $as_echo "$as_me:$LINENO: result: $F77" >&5
-$as_echo "$F77" >&6; }
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:$LINENO: result: $CC" >&5
+$as_echo "$CC" >&6; }
 else
   { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-    test -n "$F77" && break
+    test -n "$CC" && break
   done
 fi
-if test -z "$F77"; then
-  ac_ct_F77=$F77
-  for ac_prog in ifort xlf gfortran
+if test -z "$CC"; then
+  ac_ct_CC=$CC
+  for ac_prog in icc xlc gcc
 do
   # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
 { $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_ac_ct_F77+set}" = set; then
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$ac_ct_F77"; then
-  ac_cv_prog_ac_ct_F77="$ac_ct_F77" # Let the user override the test.
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
 else
 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 for as_dir in $PATH
@@ -2509,7 +2504,7 @@
   test -z "$as_dir" && as_dir=.
   for ac_exec_ext in '' $ac_executable_extensions; do
   if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_ac_ct_F77="$ac_prog"
+    ac_cv_prog_ac_ct_CC="$ac_prog"
     $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -2519,21 +2514,21 @@
 
 fi
 fi
-ac_ct_F77=$ac_cv_prog_ac_ct_F77
-if test -n "$ac_ct_F77"; then
-  { $as_echo "$as_me:$LINENO: result: $ac_ct_F77" >&5
-$as_echo "$ac_ct_F77" >&6; }
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  { $as_echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
 else
   { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-  test -n "$ac_ct_F77" && break
+  test -n "$ac_ct_CC" && break
 done
 
-  if test "x$ac_ct_F77" = x; then
-    F77=""
+  if test "x$ac_ct_CC" = x; then
+    CC=""
   else
     case $cross_compiling:$ac_tool_warned in
 yes:)
@@ -2541,13 +2536,21 @@
 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
 ac_tool_warned=yes ;;
 esac
-    F77=$ac_ct_F77
+    CC=$ac_ct_CC
   fi
 fi
 
 
+test -z "$CC" && { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+{ { $as_echo "$as_me:$LINENO: error: no acceptable C compiler found in \$PATH
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: no acceptable C compiler found in \$PATH
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
+
 # Provide some information about the compiler.
-$as_echo "$as_me:$LINENO: checking for Fortran 77 compiler version" >&5
+$as_echo "$as_me:$LINENO: checking for C compiler version" >&5
 set X $ac_compile
 ac_compiler=$2
 { (ac_try="$ac_compiler --version >&5"
@@ -2583,20 +2586,29 @@
   ac_status=$?
   $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }
-rm -f a.out
 
 cat >conftest.$ac_ext <<_ACEOF
-      program main
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
 
-      end
+int
+main ()
+{
+
+  ;
+  return 0;
+}
 _ACEOF
 ac_clean_files_save=$ac_clean_files
 ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out"
 # Try to create an executable without -o first, disregard a.out.
 # It will help us diagnose broken compilers, and finding out an intuition
 # of exeext.
-{ $as_echo "$as_me:$LINENO: checking for Fortran 77 compiler default output file name" >&5
-$as_echo_n "checking for Fortran 77 compiler default output file name... " >&6; }
+{ $as_echo "$as_me:$LINENO: checking for C compiler default output file name" >&5
+$as_echo_n "checking for C compiler default output file name... " >&6; }
 ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
 
 # The possible output files:
@@ -2667,9 +2679,9 @@
 
 { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-{ { $as_echo "$as_me:$LINENO: error: Fortran 77 compiler cannot create executables
+{ { $as_echo "$as_me:$LINENO: error: C compiler cannot create executables
 See \`config.log' for more details." >&5
-$as_echo "$as_me: error: Fortran 77 compiler cannot create executables
+$as_echo "$as_me: error: C compiler cannot create executables
 See \`config.log' for more details." >&2;}
    { (exit 77); exit 77; }; }; }
 fi
@@ -2678,8 +2690,8 @@
 
 # Check that the compiler produces executables we can run.  If not, either
 # the compiler is broken, or we cross compile.
-{ $as_echo "$as_me:$LINENO: checking whether the Fortran 77 compiler works" >&5
-$as_echo_n "checking whether the Fortran 77 compiler works... " >&6; }
+{ $as_echo "$as_me:$LINENO: checking whether the C compiler works" >&5
+$as_echo_n "checking whether the C compiler works... " >&6; }
 # FIXME: These cross compiler hacks should be removed for Autoconf 3.0
 # If not cross compiling, check that we can run a simple program.
 if test "$cross_compiling" != yes; then
@@ -2701,10 +2713,10 @@
     else
 	{ { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-{ { $as_echo "$as_me:$LINENO: error: cannot run Fortran 77 compiled programs.
+{ { $as_echo "$as_me:$LINENO: error: cannot run C compiled programs.
 If you meant to cross compile, use \`--host'.
 See \`config.log' for more details." >&5
-$as_echo "$as_me: error: cannot run Fortran 77 compiled programs.
+$as_echo "$as_me: error: cannot run C compiled programs.
 If you meant to cross compile, use \`--host'.
 See \`config.log' for more details." >&2;}
    { (exit 1); exit 1; }; }; }
@@ -2772,9 +2784,19 @@
   $as_echo_n "(cached) " >&6
 else
   cat >conftest.$ac_ext <<_ACEOF
-      program main
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
 
-      end
+  ;
+  return 0;
+}
 _ACEOF
 rm -f conftest.o conftest.obj
 if { (ac_try="$ac_compile"
@@ -2815,280 +2837,6 @@
 $as_echo "$ac_cv_objext" >&6; }
 OBJEXT=$ac_cv_objext
 ac_objext=$OBJEXT
-# If we don't use `.F' as extension, the preprocessor is not run on the
-# input file.  (Note that this only needs to work for GNU compilers.)
-ac_save_ext=$ac_ext
-ac_ext=F
-{ $as_echo "$as_me:$LINENO: checking whether we are using the GNU Fortran 77 compiler" >&5
-$as_echo_n "checking whether we are using the GNU Fortran 77 compiler... " >&6; }
-if test "${ac_cv_f77_compiler_gnu+set}" = set; then
-  $as_echo_n "(cached) " >&6
-else
-  cat >conftest.$ac_ext <<_ACEOF
-      program main
-#ifndef __GNUC__
-       choke me
-#endif
-
-      end
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
-$as_echo "$ac_try_echo") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_f77_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_compiler_gnu=yes
-else
-  $as_echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_compiler_gnu=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-ac_cv_f77_compiler_gnu=$ac_compiler_gnu
-
-fi
-{ $as_echo "$as_me:$LINENO: result: $ac_cv_f77_compiler_gnu" >&5
-$as_echo "$ac_cv_f77_compiler_gnu" >&6; }
-ac_ext=$ac_save_ext
-ac_test_FFLAGS=${FFLAGS+set}
-ac_save_FFLAGS=$FFLAGS
-FFLAGS=
-{ $as_echo "$as_me:$LINENO: checking whether $F77 accepts -g" >&5
-$as_echo_n "checking whether $F77 accepts -g... " >&6; }
-if test "${ac_cv_prog_f77_g+set}" = set; then
-  $as_echo_n "(cached) " >&6
-else
-  FFLAGS=-g
-cat >conftest.$ac_ext <<_ACEOF
-      program main
-
-      end
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
-$as_echo "$ac_try_echo") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_f77_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_cv_prog_f77_g=yes
-else
-  $as_echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_prog_f77_g=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-
-fi
-{ $as_echo "$as_me:$LINENO: result: $ac_cv_prog_f77_g" >&5
-$as_echo "$ac_cv_prog_f77_g" >&6; }
-if test "$ac_test_FFLAGS" = set; then
-  FFLAGS=$ac_save_FFLAGS
-elif test $ac_cv_prog_f77_g = yes; then
-  if test "x$ac_cv_f77_compiler_gnu" = xyes; then
-    FFLAGS="-g -O2"
-  else
-    FFLAGS="-g"
-  fi
-else
-  if test "x$ac_cv_f77_compiler_gnu" = xyes; then
-    FFLAGS="-O2"
-  else
-    FFLAGS=
-  fi
-fi
-
-if test $ac_compiler_gnu = yes; then
-  G77=yes
-else
-  G77=
-fi
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-if test -n "$ac_tool_prefix"; then
-  for ac_prog in icc xlc gcc
-  do
-    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
-set dummy $ac_tool_prefix$ac_prog; ac_word=$2
-{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_CC+set}" = set; then
-  $as_echo_n "(cached) " >&6
-else
-  if test -n "$CC"; then
-  ac_cv_prog_CC="$CC" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-  for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
-    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-done
-IFS=$as_save_IFS
-
-fi
-fi
-CC=$ac_cv_prog_CC
-if test -n "$CC"; then
-  { $as_echo "$as_me:$LINENO: result: $CC" >&5
-$as_echo "$CC" >&6; }
-else
-  { $as_echo "$as_me:$LINENO: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
-    test -n "$CC" && break
-  done
-fi
-if test -z "$CC"; then
-  ac_ct_CC=$CC
-  for ac_prog in icc xlc gcc
-do
-  # Extract the first word of "$ac_prog", so it can be a program name with args.
-set dummy $ac_prog; ac_word=$2
-{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
-  $as_echo_n "(cached) " >&6
-else
-  if test -n "$ac_ct_CC"; then
-  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-  for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_ac_ct_CC="$ac_prog"
-    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-done
-IFS=$as_save_IFS
-
-fi
-fi
-ac_ct_CC=$ac_cv_prog_ac_ct_CC
-if test -n "$ac_ct_CC"; then
-  { $as_echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
-$as_echo "$ac_ct_CC" >&6; }
-else
-  { $as_echo "$as_me:$LINENO: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
-  test -n "$ac_ct_CC" && break
-done
-
-  if test "x$ac_ct_CC" = x; then
-    CC=""
-  else
-    case $cross_compiling:$ac_tool_warned in
-yes:)
-{ $as_echo "$as_me:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5
-$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
-ac_tool_warned=yes ;;
-esac
-    CC=$ac_ct_CC
-  fi
-fi
-
-
-test -z "$CC" && { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-{ { $as_echo "$as_me:$LINENO: error: no acceptable C compiler found in \$PATH
-See \`config.log' for more details." >&5
-$as_echo "$as_me: error: no acceptable C compiler found in \$PATH
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }; }
-
-# Provide some information about the compiler.
-$as_echo "$as_me:$LINENO: checking for C compiler version" >&5
-set X $ac_compile
-ac_compiler=$2
-{ (ac_try="$ac_compiler --version >&5"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
-$as_echo "$ac_try_echo") >&5
-  (eval "$ac_compiler --version >&5") 2>&5
-  ac_status=$?
-  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }
-{ (ac_try="$ac_compiler -v >&5"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
-$as_echo "$ac_try_echo") >&5
-  (eval "$ac_compiler -v >&5") 2>&5
-  ac_status=$?
-  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }
-{ (ac_try="$ac_compiler -V >&5"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
-$as_echo "$ac_try_echo") >&5
-  (eval "$ac_compiler -V >&5") 2>&5
-  ac_status=$?
-  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }
-
 { $as_echo "$as_me:$LINENO: checking whether we are using the GNU C compiler" >&5
 $as_echo_n "checking whether we are using the GNU C compiler... " >&6; }
 if test "${ac_cv_c_compiler_gnu+set}" = set; then
EOF
    if [[ $? != 0 ]] ; then
        warn "Unable to apply Darwin patch 4 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
        if [[ "${MILI_FILE}" == "mili_15_1.tar.gz" ]]; then
            apply_mili_151_darwin_patch4
            if [[ $? != 0 ]] ; then
                return 1
            fi
        fi
    fi

    return 0
}

function build_mili
{
    #
    # Prepare build dir
    #
    prepare_build_dir $MILI_BUILD_DIR $MILI_FILE
    untarred_mili=$?
    # 0, already exists, 1 untarred src, 2 error

    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\n" \
                 "tried to apply a patch to an existing directory that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi

    #
    # Configure Mili
    #
    info "Configuring Mili . . ."
    cd $MILI_BUILD_DIR || error "Can't cd to mili build dir."

    extra_ac_flags=""
    # detect coral systems, which older versions of autoconf don't detect
    if [[ "$(uname -m)" == "ppc64le" ]] ; then
         extra_ac_flags="ac_cv_build=powerpc64le-unknown-linux-gnu"
    fi

    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 $extra_ac_flags \
                --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_moab_initialize
{
    export DO_MOAB="no"
}

function bv_moab_enable
{
    DO_MOAB="yes"
}

function bv_moab_disable
{
    DO_MOAB="no"
}

function bv_moab_depends_on
{
    local depends_on="hdf5 zlib"

    if [[ "$DO_SZIP" == "yes" ]] ; then
        depends_on="$depends_on szip"
    fi

    echo $depends_on
}

function bv_moab_info
{
    export MOAB_VERSION=${MOAB_VERSION:-"4.9.2-RC0"}
    export MOAB_FILE=${MOAB_FILE:-"moab-${MOAB_VERSION}.tar.gz"}
    export MOAB_URL=${MOAB_URL:-"ftp://ftp.mcs.anl.gov/pub/fathom"}
    export MOAB_BUILD_DIR=${MOAB_BUILD_DIR:-"moab-4.9.2"}
    export MOAB_MD5_CHECKSUM="8581acec855308b34144c66e1163ad8e"
    export MOAB_SHA256_CHECKSUM="216e34f07717714fcc0675f211a2ddbd5063530a753467b8c13d5ba69535c7f4"
}

function bv_moab_print
{
    printf "%s%s\n" "MOAB_FILE=" "${MOAB_FILE}"
    printf "%s%s\n" "MOAB_VERSION=" "${MOAB_VERSION}"
    printf "%s%s\n" "MOAB_BUILD_DIR=" "${MOAB_BUILD_DIR}"
}

function bv_moab_print_usage
{
    printf "%-20s %s [%s]\n" "--moab" "Build moab support" "$DO_MOAB"
}

function bv_moab_host_profile
{
    if [[ "$DO_MOAB" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## MOAB " >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
            "VISIT_OPTION_DEFAULT(VISIT_MOAB_DIR \${VISITHOME}/moab/$MOAB_VERSION/\${VISITARCH})" \
            >> $HOSTCONF
        echo \
            "VISIT_OPTION_DEFAULT(VISIT_MOAB_LIBDEP HDF5_LIBRARY_DIR hdf5 \${VISIT_HDF5_LIBDEP} TYPE STRING)" \
            >> $HOSTCONF
        if [[ -n "$PAR_COMPILER" ]]; then
            echo \
                "VISIT_OPTION_DEFAULT(VISIT_MOAB_MPI_DIR \${VISITHOME}/moab_mpi/$MOAB_VERSION/\${VISITARCH})" \
                >> $HOSTCONF
            echo \
                "VISIT_OPTION_DEFAULT(VISIT_MOAB_MPI_LIBDEP HDF5_MPI_LIBRARY_DIR hdf5_mpi \${VISIT_HDF5_MPI_LIBDEP} TYPE STRING)" \
                >> $HOSTCONF
        fi
    fi
}

function bv_moab_ensure
{
    if [[ "$DO_MOAB" == "yes" ]] ; then
        ensure_built_or_ready "moab" $MOAB_VERSION $MOAB_BUILD_DIR $MOAB_FILE $MOAB_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_MOAB="no"
            error "Unable to build moab.  ${MOAB_FILE} not found."
        fi
    fi
}

function bv_moab_dry_run
{
    if [[ "$DO_MOAB" == "yes" ]] ; then
        echo "Dry run option not set for moab."
    fi
}

# *************************************************************************** #
#                            Function 8, build_moab
# *************************************************************************** #
function build_moab
{
    #
    # Prepare build dir
    #
    prepare_build_dir $MOAB_BUILD_DIR $MOAB_FILE
    untarred_moab=$?
    if [[ $untarred_moab == -1 ]] ; then
        warn "Unable to prepare moab build directory. Giving Up!"
        return 1
    fi

    cd $MOAB_BUILD_DIR || error "Can't cd to moab build dir."
    rm -f src/moab/MOABConfig.h # work around a potential issue in MOAB tarball

    par_build_types="serial"
    if [[ -n "$PAR_COMPILER_CXX" ]]; then
        par_build_types="$par_build_types parallel"
    fi

    for bt in $par_build_types; do 

        mkdir build_$bt
        pushd build_$bt

        cf_mpi_arg=""
        cf_par_suffix=""
        if [[ "$bt" == "serial" ]]; then
            cf_c_compiler="$C_COMPILER"
            cf_cxx_compiler="$CXX_COMPILER"
        elif [[ "$bt" == "parallel" ]]; then
            # these commands ruin the untar'd source code for normal builds
            sed -i.orig -e 's/libhdf5/libhdf5_mpi/g' ../configure
            sed -i.orig -e 's/libMOAB/libMOAB_mpi/g' ../configure
            sed -i.orig -e 's/=hdf5/=hdf5_mpi/' ../configure
            sed -i.orig -e 's/^LIBS = @LIBS@/LIBS = @HDF5_LIBS@ @LIBS@/' ../tools/Makefile.in
            find .. -name Makefile.in -exec sed -e 's/libMOAB/libMOAB_mpi/g' -i.orig {} \;
            cf_mpi_arg="--with-mpi"
            cf_par_suffix="_mpi"
            cf_c_compiler="$PAR_COMPILER"
            cf_cxx_compiler="$PAR_COMPILER_CXX"
        fi

        cf_prefix_arg="--prefix=$VISITDIR/moab${cf_par_suffix}/$MOAB_VERSION/$VISITARCH"
        cf_common_args="--with-pic --disable-fortran --disable-imesh --disable-cgns"

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

        cf_hdf5_ldflags_arg=""
        cf_szip_arg=""
        cf_zlib_arg=""
        cf_hdf5_arg="--with-hdf5=$VISITDIR/hdf5${cf_par_suffix}/$HDF5_VERSION/$VISITARCH"
        if [[ "$DO_SZIP" == "yes" ]] ; then
            cf_szip_arg="--with-szip=$VISITDIR/szip/$SZIP_VERSION/$VISITARCH"
            cf_hdf5_ldflags_arg="-lsz"
        fi
        cf_zlib_arg="--with-zlib=$VISITDIR/zlib/$ZLIB_VERSION/$VISITARCH"
        cf_hdf5_ldflags_arg="$cf_hdf5_ldflags_arg -lz"
        if [[ -n "$cf_hdf5_ldflags_arg" ]]; then
            cf_hdf5_ldflags_arg="--with-hdf5-ldflags=\"$cf_hdf5_ldflags_arg\""
        fi

        info "Configuring $bt moab . . ."
        info ../configure CXX=\"$cf_cxx_compiler\" CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS\" \
            CC=\"$cf_c_compiler\" CFLAGS=\"$CFLAGS $C_OPT_FLAGS\" \
            ${cf_prefix_arg} ${cf_mpi_arg} ${cf_common_args} ${cf_static_args} \
            ${cf_hdf5_arg} ${cf_hdf5_ldflags_arg} \
            ${cf_szip_arg} ${cf_zlib_arg}

        sh -c "../configure \
            CXX=\"$cf_cxx_compiler\" CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS\" \
            CC=\"$cf_c_compiler\" CFLAGS=\"$CFLAGS $C_OPT_FLAGS\" \
            ${cf_prefix_arg} ${cf_mpi_arg} ${cf_common_args} ${cf_static_args} \
            ${cf_hdf5_arg} ${cf_hdf5_ldflags_arg} \
            ${cf_szip_arg} ${cf_zlib_arg}"

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

        #
        # Build moab
        #

        info "Building $bt moab . . . (~2 minutes)"
        $MAKE $MAKE_OPT_FLAGS
        if [[ $? != 0 ]] ; then
            warn "$bt moab build failed.  Giving up"
            return 1
        fi

        #
        # Install into the VisIt third party location.
        #
        info "Installing $bt moab"
        $MAKE install

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

        #
        # Change name of installed lib to libXXX_mpi.whatever
        #
        if [[ "$bt" == "parallel" ]]; then
            pushd $VISITDIR/moab${cf_par_suffix}/$MOAB_VERSION/$VISITARCH/lib
            if [[ "$OPSYS" == "Darwin" ]]; then
                install_name_tool -id $VISITDIR/moab${cf_par_suffix}/$MOAB_VERSION/$VISITARCH/lib/libMOAB_mpi.dylib libMOAB_mpi.dylib
            fi
            popd
        fi

        popd
    done

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


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

function bv_moab_is_installed
{
    check_if_installed "moab" $MOAB_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_moab_build
{
    cd "$START_DIR"
    if [[ "$DO_MOAB" == "yes" ]] ; then
        check_if_installed "moab" $MOAB_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping moab build.  moab is already installed."
        else
            info "Building moab (~2 minutes)"
            build_moab
            if [[ $? != 0 ]] ; then
                error "Unable to build or install moab.  Bailing out."
            fi
            info "Done building moab"
        fi
    fi
}
function bv_mpich_initialize
{
    export DO_MPICH="no"
}

function bv_mpich_enable
{
    DO_MPICH="yes"
}

function bv_mpich_disable
{
    DO_MPICH="no"
}

function bv_mpich_depends_on
{
    local depends_on=""

    echo $depends_on
}

function bv_mpich_info
{
    export MPICH_VERSION=${MPICH_VERSION:-"3.3.1"}
    export MPICH_FILE=${MPICH_FILE:-"mpich-${MPICH_VERSION}.tar.gz"}
    export MPICH_COMPATIBILITY_VERSION=${MPICH_COMPATIBILITY_VERSION:-"3.3"}
    export MPICH_BUILD_DIR=${MPICH_BUILD_DIR:-"mpich-${MPICH_VERSION}"}
    export MPICH_URL=${MPICH_URL:-http://www.mpich.org/static/tarballs/${MPICH_VERSION}}
    export MPICH_MD5_CHECKSUM="9ed4cabd3fb86525427454381b25f6af"
    export MPICH_SHA256_CHECKSUM="fe551ef29c8eea8978f679484441ed8bb1d943f6ad25b63c235d4b9243d551e5"
}

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 "%-20s %s [%s]\n" "--mpich" "Build MPICH support" "$DO_MPICH"
}

function bv_mpich_host_profile
{
    if [[ "$DO_MPICH" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## MPICH" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "SETUP_APP_VERSION(MPICH $MPICH_VERSION)" >> $HOSTCONF
        echo \
            "VISIT_OPTION_DEFAULT(VISIT_MPICH_DIR \${VISITHOME}/mpich/\${MPICH_VERSION}/\${VISITARCH})" \
            >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_MPICH_INSTALL ON TYPE BOOL)" >> $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 TYPE FILEPATH)"  >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_PARALLEL ON TYPE BOOL)" >> $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"

    #
    # Turn on shared version of the libs
    #
    mpich_opts="--enable-shared"
    if [[ "$OPSYS" == "Darwin" ]]; then
        mpich_opts="${mpich_opts} --enable-two-level-namespace --enable-threads=single"
    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'`

    #
    # Enable/disable fortran as needed.
    #
    if [[ "$FC_COMPILER" == "no" ]] ; then
        mpich_opts="${mpich_opts} --enable-fortran=no"
    else
        mpich_opts="${mpich_opts} --enable-fortran=all"	
    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_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"
}

function bv_mxml_enable
{
    DO_MXML="yes"
}

function bv_mxml_disable
{
    DO_MXML="no"
}

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="b0d347da1a0d5a8c9e82f66087d55cfe499728dacae563740d7e733648c69795"
}

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 "%-20s %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
{
    info "Patching MXML for darwin build"
    patch -p0 << \EOF
diff -c mxml-2.6/Makefile.in mxml-2.6/Makefile.in.new
*** mxml-2.6/Makefile.in	2016-06-21 14:05:57.000000000 -0600
--- mxml-2.6/Makefile.in.new	2016-06-21 14:07:38.000000000 -0600
***************
*** 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=$?
    # 0, already exists, 1 untarred src, 2 error

    if [[ $untarred_mxml == -1 ]] ; then
        warn "Unable to prepare MXML Build Directory. Giving Up"
        return 1
    fi

    #
    # Apply patches
    #
    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\n" \
                 "tried to apply a patch to an existing directory that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi
    
    #
    # Configure MXML
    #
    cd $MXML_BUILD_DIR || error "Can't cd to MXML build dir."

    info "Configuring 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 MXML . . ."

    $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_nektarpp_initialize
{
    export DO_NEKTAR_PLUS_PLUS="no"
    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"
}

function bv_nektarpp_disable
{
    DO_NEKTAR_PLUS_PLUS="no"
}

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
{
    if [[ "$USE_SYSTEM_NEKTAR_PLUS_PLUS" == "yes" ]]; then
        echo ""
    else
        echo "cmake boost zlib"
    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.4.1"}
    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:-"4.4"}
    export NEKTAR_PLUS_PLUS_URL=${NEKTAR_PLUS_PLUS_URL:-"https://www.nektar.info/wp-content/uploads/2017/03/"}
    export NEKTAR_PLUS_PLUS_BUILD_DIR=${NEKTAR_PLUS_PLUS_BUILD_DIR:-"nektar++-${NEKTAR_PLUS_PLUS_VERSION}"}
    export NEKTAR_PLUS_PLUS_MD5_CHECKSUM="9ebf2d418052c697851bc17746d4a153"
    export NEKTAR_PLUS_PLUS_SHA256_CHECKSUM="47a42ef738313f01c342114df5c9e75cf04001a59034d604e6b834342601207d"
}

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 "%-20s %s [%s]\n" "--nektarpp" "Build Nektar++" "${DO_NEKTAR_PLUS_PLUS}"
    printf "%-20s %s [%s]\n" "--alt-nektarpp-dir" "Use Nektar++ from an alternative directory"
}

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 

            ZLIB_LIBDEP="\${VISITHOME}/zlib/\${ZLIB_VERSION}/\${VISITARCH}/lib z"

            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_4_4_0_patch
{
    info "Patching Nektar++ 4.4.0"
    patch -p0 << \EOF
diff -rcN nektar++-4.4.0/library/LibUtilities/Communication/CommDataType_orig.h nektar++-4.4.0/library/LibUtilities/Communication/CommDataType.h
*** nektar++-4.4.0/library/LibUtilities/Communication/CommDataType_orig.h	2017-03-06 11:04:22.000000000 -0700
--- nektar++-4.4.0/library/LibUtilities/Communication/CommDataType.h	2017-09-05 14:22:16.000000000 -0600
***************
*** 56,73 ****
  {
  namespace LibUtilities
  {
! enum CommDataType
! {
!     MPI_INT,
!     MPI_UNSIGNED,
!     MPI_LONG,
!     MPI_UNSIGNED_LONG,
!     MPI_LONG_LONG,
!     MPI_UNSIGNED_LONG_LONG,
!     MPI_FLOAT,
!     MPI_DOUBLE,
!     MPI_LONG_DOUBLE
! };
  }
  }
  #endif
--- 56,99 ----
  {
  namespace LibUtilities
  {
! typedef int CommDataType;
! 
! #ifndef MPI_INT
!     #define MPI_INT            ((CommDataType)0x4c000405)
! #endif
! 
! #ifndef MPI_UNSIGNED
!     #define MPI_UNSIGNED       ((CommDataType)0x4c000406)
! #endif
! 
! #ifndef MPI_LONG
!     #define MPI_LONG           ((CommDataType)0x4c000807)
! #endif
! 
! #ifndef MPI_UNSIGNED_LONG
!     #define MPI_UNSIGNED_LONG  ((CommDataType)0x4c000808)
! #endif
! 
! #ifndef MPI_LONG_LONG
!     #define MPI_LONG_LONG      ((CommDataType)0x4c000809)
! #endif
! 
! #ifndef MPI_UNSIGNED_LONG_LONG
!     #define MPI_UNSIGNED_LONG_LONG ((CommDataType)0x4c000819)
! #endif
! 
! #ifndef MPI_FLOAT
!     #define MPI_FLOAT          ((CommDataType)0x4c00040a)
! #endif
! 
! #ifndef MPI_DOUBLE
!     #define MPI_DOUBLE         ((CommDataType)0x4c00080b)
! #endif
! 
! #ifndef MPI_LONG_DOUBLE
!     #define MPI_LONG_DOUBLE    ((CommDataType)0x4c00100c)
! #endif
! 
  }
  }
  #endif
EOF
}

function apply_nektarpp_4_4_1_patch
{
    info "Patching Nektar++ 4.4.1"
    patch -p0 << \EOF
diff -rcN nektar++-4.4.1/library/LibUtilities/Communication/CommDataType_orig.h nektar++-4.4.1/library/LibUtilities/Communication/CommDataType.h
*** nektar++-4.4.1/library/LibUtilities/Communication/CommDataType_orig.h	2017-03-06 11:04:22.000000000 -0700
--- nektar++-4.4.1/library/LibUtilities/Communication/CommDataType.h	2017-09-05 14:22:16.000000000 -0600
***************
*** 56,73 ****
  {
  namespace LibUtilities
  {
! enum CommDataType
! {
!     MPI_INT,
!     MPI_UNSIGNED,
!     MPI_LONG,
!     MPI_UNSIGNED_LONG,
!     MPI_LONG_LONG,
!     MPI_UNSIGNED_LONG_LONG,
!     MPI_FLOAT,
!     MPI_DOUBLE,
!     MPI_LONG_DOUBLE
! };
  }
  }
  #endif
--- 56,99 ----
  {
  namespace LibUtilities
  {
! typedef int CommDataType;
! 
! #ifndef MPI_INT
!     #define MPI_INT            ((CommDataType)0x4c000405)
! #endif
! 
! #ifndef MPI_UNSIGNED
!     #define MPI_UNSIGNED       ((CommDataType)0x4c000406)
! #endif
! 
! #ifndef MPI_LONG
!     #define MPI_LONG           ((CommDataType)0x4c000807)
! #endif
! 
! #ifndef MPI_UNSIGNED_LONG
!     #define MPI_UNSIGNED_LONG  ((CommDataType)0x4c000808)
! #endif
! 
! #ifndef MPI_LONG_LONG
!     #define MPI_LONG_LONG      ((CommDataType)0x4c000809)
! #endif
! 
! #ifndef MPI_UNSIGNED_LONG_LONG
!     #define MPI_UNSIGNED_LONG_LONG ((CommDataType)0x4c000819)
! #endif
! 
! #ifndef MPI_FLOAT
!     #define MPI_FLOAT          ((CommDataType)0x4c00040a)
! #endif
! 
! #ifndef MPI_DOUBLE
!     #define MPI_DOUBLE         ((CommDataType)0x4c00080b)
! #endif
! 
! #ifndef MPI_LONG_DOUBLE
!     #define MPI_LONG_DOUBLE    ((CommDataType)0x4c00100c)
! #endif
! 
  }
  }
  #endif
EOF
}

function apply_nektarpp_4_4_0_OSX_patch
{
    info "Patching Nektar++ 4.4.0 for OS X"
    patch -p0 << \EOF
diff -rcN nektar++-4.4.0/CMakeLists_orig.txt  nektar++-4.4.0/CMakeLists.txt 
*** nektar++-4.4.0/CMakeLists_orig.txt	2017-03-06 11:04:22.000000000 -0700
--- nektar++-4.4.0/CMakeLists.txt	2017-09-05 14:47:37.000000000 -0600
***************
*** 326,333 ****
  
  # Build active components
  IF (NEKTAR_BUILD_LIBRARY)
!     SET(NEKTAR++_LIBRARIES SolverUtils LibUtilities StdRegions SpatialDomains LocalRegions
!         MultiRegions Collections GlobalMapping FieldUtils NekMeshUtils)
      INCLUDE_DIRECTORIES(library)
      ADD_SUBDIRECTORY(library)
      INSTALL(EXPORT Nektar++Libraries DESTINATION ${LIB_DIR}/cmake COMPONENT dev)
--- 326,333 ----
  
  # Build active components
  IF (NEKTAR_BUILD_LIBRARY)
!     SET(NEKTAR++_LIBRARIES LibUtilities StdRegions SpatialDomains LocalRegions
!         MultiRegions Collections GlobalMapping FieldUtils)
      INCLUDE_DIRECTORIES(library)
      ADD_SUBDIRECTORY(library)
      INSTALL(EXPORT Nektar++Libraries DESTINATION ${LIB_DIR}/cmake COMPONENT dev)
EOF
}

function apply_nektarpp_4_4_1_OSX_patch
{
    info "Patching Nektar++ 4.4.1 for OS X"
    patch -p0 << \EOF
diff -rcN nektar++-4.4.1/CMakeLists.orig.txt  nektar++-4.4.1/CMakeLists.txt 
*** nektar++-4.4.1/CMakeLists.orig.txt	2018-11-06 08:03:29.000000000 -0700
--- nektar++-4.4.1/CMakeLists.txt	2018-11-06 08:04:33.000000000 -0700
***************
*** 326,333 ****
  
  # Build active components
  IF (NEKTAR_BUILD_LIBRARY)
!     SET(NEKTAR++_LIBRARIES SolverUtils LibUtilities StdRegions SpatialDomains LocalRegions
!         MultiRegions Collections GlobalMapping FieldUtils NekMeshUtils)
      INCLUDE_DIRECTORIES(library)
      ADD_SUBDIRECTORY(library)
      INSTALL(EXPORT Nektar++Libraries DESTINATION ${LIB_DIR}/cmake COMPONENT dev)
--- 326,333 ----
  
  # Build active components
  IF (NEKTAR_BUILD_LIBRARY)
!     SET(NEKTAR++_LIBRARIES LibUtilities StdRegions SpatialDomains LocalRegions
!         MultiRegions Collections GlobalMapping FieldUtils)
      INCLUDE_DIRECTORIES(library)
      ADD_SUBDIRECTORY(library)
      INSTALL(EXPORT Nektar++Libraries DESTINATION ${LIB_DIR}/cmake COMPONENT dev)
EOF
}

function apply_nektarpp_patch
{
    if [[ "${NEKTAR_PLUS_PLUS_VERSION}" == 4.4.0 ]] ; then
        apply_nektarpp_4_4_0_patch
        if [[ $? != 0 ]]; then
           return 1
        fi

#        if [[ "$OPSYS" == "Darwin" ]]; then
            apply_nektarpp_4_4_OSX_patch
            if [[ $? != 0 ]]; then
		return 1
            fi
#	fi	

    elif [[ "${NEKTAR_PLUS_PLUS_VERSION}" == 4.4.1 ]] ; then
        apply_nektarpp_4_4_1_patch
        if [[ $? != 0 ]]; then
           return 1
        fi

#        if [[ "$OPSYS" == "Darwin" ]]; then
            apply_nektarpp_4_4_1_OSX_patch
            if [[ $? != 0 ]]; then
		return 1
            fi
#	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=$?
    # 0, already exists, 1 untarred src, 2 error

    if [[ $untarred_nektar_plus_plus == -1 ]] ; then
        warn "Unable to prepare Nektar++ Build Directory. Giving Up"
        return 1
    fi

    #
    # Apply patches
    #
    info "Patching Nektar++ . . ."
    apply_nektarpp_patch
    if [[ $? != 0 ]] ; then
        if [[ $untarred_nektar_plus_plus == 1 ]] ; then
            warn "Giving up on Nektar++ 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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi
 
    #
    cd $NEKTAR_PLUS_PLUS_BUILD_DIR || error "Can't cd to Nektar++ build dir." $NEKTAR_PLUS_PLUS_BUILD_DIR 

    #
    # Configure Nektar++
    #
    info "Configuring Nektar++ . . ."

    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 [[ "$DO_BOOST" == "yes" ]] ; 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

    info "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

#    if test "${DO_MPICH}" = "yes"; 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 "${DO_VTK}" = "yes"; 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

    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 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"
}

function bv_netcdf_disable
{
    DO_NETCDF="no"
}

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="zlib"
        if [[ "$DO_HDF5" == "yes" ]] ; then
            depends_on="hdf5"        
            if [[ "$DO_SZIP" == "yes" ]] ; then
                depends_on="${depends_on} szip"        
            fi
        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="7933d69d378c57f038375bae4dd78c52442a06e2647fce4b75c13a225e342fb0"
}

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 "%-20s %s [%s]\n" "--netcdf" "Build NetCDF" "${DO_NETCDF}"
    printf "%-20s %s [%s]\n" "--alt-netcdf-dir" "Use NetCDF from an alternative directory"
}

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_OSX10_13_patch
{
    patch -p0 << \EOF
diff -c netcdf-4.1.1/ncgen3/orig/genlib.h netcdf-4.1.1/ncgen3/genlib.h 
*** netcdf-4.1.1/ncgen3/orig/genlib.h	Thu Aug 23 21:46:38 2018
--- netcdf-4.1.1/ncgen3/genlib.h	Thu Aug 23 21:07:33 2018
***************
*** 5,10 ****
--- 5,11 ----
   *   See netcdf/COPYRIGHT file for copying and redistribution conditions.
   *   $Header: /upc/share/CVS/netcdf-3/ncgen3/genlib.h,v 1.15 2009/12/29 18:42:35 dmh Exp $
   *********************************************************************/
+ #include <config.h>
  #include <stdlib.h>
  #include <limits.h>
  
EOF
    if [[ $? != 0 ]] ; then
        warn "netcdf 4.1.1 OSX 10.13 patch failed."
        return 1
    fi

    return 0;
}

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]* ||
                  `sw_vers -productVersion` == 10.10.[0-9]* ||
                  `sw_vers -productVersion` == 10.11.[0-9]* ||
                  `sw_vers -productVersion` == 10.12.[0-9]* ]] ; then
                info "Applying OS X 10.9 and up patch . . ."
                apply_netcdf_411_darwin_patch
            fi
            
            if [[ `sw_vers -productVersion` == 10.13.[0-9]* ]] ; then
                info "Applying OS X 10.13 patch . . ."
                apply_netcdf_411_OSX10_13_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=$?
    # 0, already exists, 1 untarred src, 2 error

    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" \
                 "tried to apply a patch to an existing directory that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi

    #
    # Configure NetCDF
    #
    info "Configuring NetCDF . . ."
    cd $NETCDF_BUILD_DIR || error "Can't cd to netcdf build dir."
    info "Invoking command to configure NetCDF"
    EXTRA_FLAGS=""
    if [[ "$OPSYS" == "Darwin" ]]; then
        if [[ "$DO_STATIC_BUILD" == "no" ]]; then
            EXTRA_FLAGS="--enable-largefile --enable-shared --disable-static"
        else
            EXTRA_FLAGS="--enable-largefile"
        fi
    fi
    EXTRA_AC_FLAGS=""
    # detect coral systems, which older versions of autoconf don't detect
    if [[ "$(uname -m)" == "ppc64le" ]] ; then
         EXTRA_AC_FLAGS="ac_cv_build=powerpc64le-unknown-linux-gnu"
    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="--with-zlib=$VISITDIR/zlib/$ZLIB_VERSION/$VISITARCH"

    info "./configure CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" \
        CFLAGS=\"$C_OPT_FLAGS\" CXXFLAGS=\"$CXX_OPT_FLAGS\" \
        FC=\"\" $EXTRA_AC_FLAGS $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_AC_FLAGS $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_openexr_initialize
{
    export DO_OPENEXR="no"
}

function bv_openexr_enable
{
    DO_OPENEXR="yes"
}

function bv_openexr_disable
{
    DO_OPENEXR="no"
}

function bv_openexr_depends_on
{
    echo ""
}

function bv_openexr_info
{
    export OPENEXR_FILE=${OPENEXR_FILE:-"openexr-2.2.0.tar.gz"}
    export OPENEXR_VERSION=${OPENEXR_VERSION:-"2.2.0"}
    export OPENEXR_COMPATIBILITY_VERSION=${OPENEXR_COMPATIBILITY_VERSION:-"2.2.0"}
    export OPENEXR_BUILD_DIR=${OPENEXR_BUILD_DIR:-"openexr-2.2.0"}
    export OPENEXR_MD5_CHECKSUM="b64e931c82aa3790329c21418373db4e"
    export OPENEXR_SHA256_CHECKSUM="36a012f6c43213f840ce29a8b182700f6cf6b214bea0d5735594136b44914231"

    export ILMBASE_FILE=${ILMBASE_FILE:-"ilmbase-2.2.0.tar.gz"}
    export ILMBASE_VERSION=${ILMBASE_VERSION:-"2.2.0"}
    export ILMBASE_COMPATIBILITY_VERSION=${OPENEXR_COMPATIBILITY_VERSION:-"2.2.0"}
    export ILMBASE_BUILD_DIR=${ILMBASE_BUILD_DIR:-"ilmbase-2.2.0"}
    export ILMBASE_MD5_CHECKSUM="b540db502c5fa42078249f43d18a4652"
    export ILMBASE_SHA256_CHECKSUM="ecf815b60695555c1fbc73679e84c7c9902f4e8faa6e8000d2f905b8b86cedc7"
}

function bv_openexr_print
{
    printf "%s%s\n" "OPENEXR_FILE=" "${OPENEXR_FILE}"
    printf "%s%s\n" "OPENEXR_VERSION=" "${OPENEXR_VERSION}"
    printf "%s%s\n" "OPENEXR_COMPATIBILITY_VERSION=" "${OPENEXR_COMPATIBILITY_VERSION}"
    printf "%s%s\n" "OPENEXR_BUILD_DIR=" "${OPENEXR_BUILD_DIR}"

    printf "%s%s\n" "ILMBASE_FILE=" "${ILMBASE_FILE}"
    printf "%s%s\n" "ILMBASE_VERSION=" "${ILMBASE_VERSION}"
    printf "%s%s\n" "ILMBASE_COMPATIBILITY_VERSION=" "${ILMBASE_COMPATIBILITY_VERSION}"
    printf "%s%s\n" "ILMBASE_BUILD_DIR=" "${ILMBASE_BUILD_DIR}"
}

function bv_openexr_host_profile
{
    if [[ "$DO_OPENEXR" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## OpenEXR" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
            "VISIT_OPTION_DEFAULT(VISIT_OPENEXR_DIR \${VISITHOME}/openexr/$OPENEXR_VERSION/\${VISITARCH})" \
            >> $HOSTCONF
    fi
}

function bv_openexr_print_usage
{
    #openexr does not have an option, it is only dependent on openexr.
    printf "%-20s %s [%s]\n" "--openexr" "Build OpenEXR" "$DO_OPENEXR"
}

function bv_openexr_ensure
{
    if [[ "$DO_OPENEXR" == "yes" ]] ; then
        ensure_built_or_ready "openexr" $OPENEXR_VERSION $OPENEXR_BUILD_DIR $OPENEXR_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_OPENEXR="no"
            error "Unable to build OpenEXR.  ${OPENEXR_FILE} not found."
        fi
        ensure_built_or_ready "openexr (ILMBase) " $ILMBASE_VERSION $ILMBASE_BUILD_DIR $ILMBASE_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_OPENEXR="no"
            error "Unable to build OpenEXR (ILMBase).  ${ILMBASE_FILE} not found."
        fi
    fi
}

function bv_openexr_dry_run
{
    if [[ "$DO_OPENEXR" == "yes" ]] ; then
        echo "Dry run option not set for OpenEXR."
    fi
}

# ***************************************************************************
# build_ilmbase
#
# Modifications:
#
# ***************************************************************************

function build_ilmbase
{
    #
    # Prepare build dir
    #
    prepare_build_dir $ILMBASE_BUILD_DIR $ILMBASE_FILE
    untarred_ilmbase=$?
    # 0, already exists, 1 untarred src, 2 error

    if [[ $untarred_ilmbase == -1 ]] ; then
        warn "Unable to prepare ILMBase Build Directory. Giving Up"
        return 1
    fi
    
    #
    # Configure ILMBase
    #
    cd $ILMBASE_BUILD_DIR || error "Can't cd to ILMBase build dir."
    if [[ "$DO_STATIC_BUILD" == "yes" || "$OPSYS" == "Linux"  ]]; then
        DISABLE_BUILDTYPE="--disable-shared"
    else
        DISABLE_BUILDTYPE="--disable-static"
    fi
    info "Configuring ILMBase . . ."
    ./configure ${OPTIONAL} CXX="$CXX_COMPILER" \
                CC="$C_COMPILER" CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
                --prefix="$VISITDIR/openexr/$ILMBASE_VERSION/$VISITARCH" $DISABLE_BUILDTYPE
    if [[ $? != 0 ]] ; then
        warn "ILMBase configure failed.  Giving up"
        return 1
    fi

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

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

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

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

# ***************************************************************************
# build_openexr
#
# Modifications:
#
# ***************************************************************************

function build_openexr
{
    #
    # Prepare build dir
    #
    prepare_build_dir $OPENEXR_BUILD_DIR $OPENEXR_FILE
    untarred_openexr=$?
    # 0, already exists, 1 untarred src, 2 error

    if [[ $untarred_openexr == -1 ]] ; then
        warn "Unable to prepare OpenEXR Build Directory. Giving Up"
        return 1
    fi
    
    #
    # Configure OpenEXR
    #
    cd $OPENEXR_BUILD_DIR || error "Can't cd to OpenEXR build dir."
    if [[ "$DO_STATIC_BUILD" == "yes" || "$OPSYS" == "Linux" ]]; then
        DISABLE_BUILDTYPE="--disable-shared"
    else
        DISABLE_BUILDTYPE="--disable-static"
    fi
    info "Configuring OpenEXR . . ."
    ./configure ${OPTIONAL} CXX="$CXX_COMPILER" \
                CC="$C_COMPILER" CFLAGS="$CFLAGS $C_OPT_FLAGS" CXXFLAGS="$CXXFLAGS $CXX_OPT_FLAGS" \
                --prefix="$VISITDIR/openexr/$OPENEXR_VERSION/$VISITARCH" \
                --with-ilmbase-prefix="$VISITDIR/openexr/$OPENEXR_VERSION/$VISITARCH" \
                --with-pic --enable-imfexamples $DISABLE_BUILDTYPE
    if [[ $? != 0 ]] ; then
        warn "openexr configure failed.  Giving up"
        return 1
    fi

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

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

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

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

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

function bv_openexr_is_installed
{
    check_if_installed "openexr" $OPENEXR_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_openexr_build
{
    if [[ "$DO_OPENEXR" == "yes" ]] ; then
        check_if_installed "openexr" $OPENEXR_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping build of OpenEXR"
        else
            build_ilmbase
            if [[ $? != 0 ]] ; then
                error "Unable to build or install ILMBase for OpenEXR.  Bailing out."
            fi
            info "Done building ILMBase"
            build_openexr
            if [[ $? != 0 ]] ; then
                error "Unable to build or install OpenEXR.  Bailing out."
            fi
            info "Done building OpenEXR"
        fi
    fi
}

function bv_openssl_initialize
{
    export DO_OPENSSL="yes"
}

function bv_openssl_enable
{
    DO_OPENSSL="yes"
}

function bv_openssl_disable
{
    DO_OPENSSL="no"
}

function bv_openssl_depends_on
{
    echo "zlib"

}

function bv_openssl_info
{
    export OPENSSL_VERSION=${OPENSSL_VERSION:-"1.0.2j"}
    export OPENSSL_FILE=${OPENSSL_FILE:-"openssl-${OPENSSL_VERSION}.tar.gz"}
    export OPENSSL_URL=${OPENSSL_URL:-"https://www.openssl.org/source/"}
    export OPENSSL_BUILD_DIR=${OPENSSL_BUILD_DIR:-"openssl-${OPENSSL_VERSION}"}
    export OPENSSL_MD5_CHECKSUM="96322138f0b69e61b7212bc53d5e912b"
    export OPENSSL_SHA256_CHECKSUM="e7aff292be21c259c6af26469c7a9b3ba26e9abaaffd325e3dccc9785256c431"
}

function bv_openssl_print
{
    printf "%s%s\n" "OPENSSL_FILE=" "${OPENSSL_FILE}"
    printf "%s%s\n" "OPENSSL_VERSION=" "${OPENSSL_VERSION}"
    printf "%s%s\n" "OPENSSL_BUILD_DIR=" "${OPENSSL_BUILD_DIR}"
}

function bv_openssl_print_usage
{
    printf "%-20s %s [%s]\n" "--openssl" "Build openssl support" "$DO_OPENSSL"
}

function bv_openssl_host_profile
{
    if [[ "$DO_OPENSSL" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## OPENSSL " >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
            "VISIT_OPTION_DEFAULT(VISIT_OPENSSL_DIR \${VISITHOME}/openssl/$OPENSSL_VERSION/\${VISITARCH})" \
            >> $HOSTCONF
    fi
}

function bv_openssl_ensure
{
    if [[ "$DO_OPENSSL" == "yes" ]] ; then
        ensure_built_or_ready "openssl" $OPENSSL_VERSION $OPENSSL_BUILD_DIR $OPENSSL_FILE $OPENSSL_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_OPENSSL="no"
            error "Unable to build openssl.  ${OPENSSL_FILE} not found."
        fi
    fi
}

function bv_openssl_dry_run
{
    if [[ "$DO_OPENSSL" == "yes" ]] ; then
        echo "Dry run option not set for openssl."
    fi
}

# *************************************************************************** #
#                            Function 8, build_openssl
# *************************************************************************** #
function build_openssl
{
    #
    # Prepare build dir
    #
    prepare_build_dir $OPENSSL_BUILD_DIR $OPENSSL_FILE
    untarred_openssl=$?
    if [[ $untarred_openssl == -1 ]] ; then
        warn "Unable to prepare openssl build directory. Giving Up!"
        return 1
    fi

    cd $OPENSSL_BUILD_DIR || error "Can't cd to openssl build dir."

    #
    # Call configure
    #
    info "Configuring openssl . . ."

    WITH_ZLIB_LIB="--with-zlib-lib=$VISITDIR/zlib/$ZLIB_VERSION/$VISITARCH/lib"
    WITH_ZLIB_INCLUDE="--with-zlib-include=$VISITDIR/zlib/$ZLIB_VERSION/$VISITARCH/include"

    info env CC="$C_COMPILER $CFLAGS $C_OPT_FLAGS" KERNEL_BITS=64 ./config \
            $WITH_ZLIB_LIB $WITH_ZLIB_INCLUDE \
            --prefix="$VISITDIR/openssl/$OPENSSL_VERSION/$VISITARCH/" \
            --openssldir="$VISITDIR/openssl/$OPENSSL_VERSION/$VISITARCH/etc/openssl" 
    env CC="$C_COMPILER $CFLAGS $C_OPT_FLAGS" KERNEL_BITS=64 ./config \
            $WITH_ZLIB_LIB $WITH_ZLIB_INCLUDE \
            --prefix="$VISITDIR/openssl/$OPENSSL_VERSION/$VISITARCH/" \
            --openssldir="$VISITDIR/openssl/$OPENSSL_VERSION/$VISITARCH/etc/openssl" 

    #
    # Build openssl
    #
    info "Building openssl . . . (~2 minutes)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
        warn "openssl build failed.  Giving up"
        return 1
    fi

    #
    # Install into the VisIt third party location.
    #
    info "Installing openssl"
    $MAKE install 

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


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

function bv_openssl_is_installed
{
    check_if_installed "openssl" $OPENSSL_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_openssl_build
{
    cd "$START_DIR"
    if [[ "$DO_OPENSSL" == "yes" ]] ; then
        check_if_installed "openssl" $OPENSSL_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping openssl build.  openssl is already installed."
        else
            info "Building openssl (~2 minutes)"
            build_openssl
            if [[ $? != 0 ]] ; then
                error "Unable to build or install openssl.  Bailing out."
            fi
            info "Done building openssl"
        fi
    fi
}
function bv_osmesa_initialize
{
    export DO_OSMESA="no"
}

function bv_osmesa_enable
{
    DO_OSMESA="yes"
}

function bv_osmesa_disable
{
    DO_OSMESA="no"
}

function bv_osmesa_depends_on
{
    depends_on="llvm"

    echo ${depends_on}
}

function bv_osmesa_info
{
    export OSMESA_VERSION=${OSMESA_VERSION:-"17.2.8"}
    export OSMESA_FILE=${OSMESA_FILE:-"mesa-$OSMESA_VERSION.tar.gz"}
    export OSMESA_URL=${OSMESA_URL:-"ftp://ftp.freedesktop.org/pub/mesa"}
    export OSMESA_BUILD_DIR=${OSMESA_BUILD_DIR:-"mesa-$OSMESA_VERSION"}
    export OSMESA_MD5_CHECKSUM="19832be1bc5784fc7bbad4d138537619"
    export OSMESA_SHA256_CHECKSUM="c715c3a3d6fe26a69c096f573ec416e038a548f0405e3befedd5136517527a84"
}

function bv_osmesa_print
{
    printf "%s%s\n" "OSMESA_FILE=" "${OSMESA_FILE}"
    printf "%s%s\n" "OSMESA_VERSION=" "${OSMESA_VERSION}"
    printf "%s%s\n" "OSMESA_TARGET=" "${OSMESA_TARGET}"
    printf "%s%s\n" "OSMESA_BUILD_DIR=" "${OSMESA_BUILD_DIR}"
}

function bv_osmesa_print_usage
{
    printf "%-20s %s [%s]\n" "--osmesa" "Build OSMesa" "$DO_OSMESA"
}

function bv_osmesa_host_profile
{
    # If we are using osmesa as the GL for VTK in a static build, we'll tell
    # VisIt about osmesa using a different mechanism.
    addhp="yes"
    if [[ "$DO_STATIC_BUILD" == "yes" ]] ; then
        if [[ "$DO_SERVER_COMPONENTS_ONLY" == "yes" || "$DO_ENGINE_ONLY" == "yes" ]] ; then
            addhp="no"
        fi
    fi

    if [[ "$DO_OSMESA" == "yes" && "$addhp" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## OSMesa" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_OSMESA_DIR \${VISITHOME}/osmesa/$OSMESA_VERSION/\${VISITARCH})" >> $HOSTCONF
    fi
}

function bv_osmesa_selected
{
    args=$@
    if [[ $args == "--osmesa" ]]; then
        DO_OSMESA="yes"
        return 1
    fi

    return 0
}

function bv_osmesa_initialize_vars
{
    info "initalizing osmesa vars"
    if [[ "$DO_OSMESA" == "yes" ]]; then
        OSMESA_INSTALL_DIR="${VISITDIR}/osmesa/${OSMESA_VERSION}/${VISITARCH}"
        OSMESA_INCLUDE_DIR="${OSMESA_INSTALL_DIR}/include"
        OSMESA_LIB_DIR="${OSMESA_INSTALL_DIR}/lib"
        if [[ "$DO_STATIC_BUILD" == "yes" ]]; then
            OSMESA_LIB="${OSMESA_LIB_DIR}/libOSMesa.a"
        else
            OSMESA_LIB="${OSMESA_LIB_DIR}/libOSMesa.${SO_EXT}"
        fi
    fi
}

function bv_osmesa_ensure
{
    if [[ "$DO_DBIO_ONLY" != "yes" ]]; then
        if [[ "$DO_OSMESA" == "yes" ]] ; then
            ensure_built_or_ready "osmesa"   $OSMESA_VERSION   $OSMESA_BUILD_DIR   $OSMESA_FILE $OSMESA_URL
            if [[ $? != 0 ]] ; then
                return 1
            fi
        fi
    fi
}

function bv_osmesa_dry_run
{
    if [[ "$DO_OSMESA" == "yes" ]] ; then
        echo "Dry run option not set for osmesa."
    fi
}

function apply_osmesa_patch
{
    patch -p0 << \EOF
diff -c configure.ac.orig configure.ac
*** configure.ac.orig	Thu Oct 10 15:44:18 2019
--- configure.ac	Thu Oct 10 15:44:26 2019
***************
*** 2690,2696 ****
      dnl (See https://llvm.org/bugs/show_bug.cgi?id=6823)
      if test "x$enable_llvm_shared_libs" = xyes; then
          dnl We can't use $LLVM_VERSION because it has 'svn' stripped out,
!         LLVM_SO_NAME=LLVM-`$LLVM_CONFIG --version`
          AS_IF([test -f "$LLVM_LIBDIR/lib$LLVM_SO_NAME.$IMP_LIB_EXT"], [llvm_have_one_so=yes])
  
          if test "x$llvm_have_one_so" = xyes; then
--- 2690,2696 ----
      dnl (See https://llvm.org/bugs/show_bug.cgi?id=6823)
      if test "x$enable_llvm_shared_libs" = xyes; then
          dnl We can't use $LLVM_VERSION because it has 'svn' stripped out,
!         LLVM_SO_NAME=LLVM-$LLVM_VERSION
          AS_IF([test -f "$LLVM_LIBDIR/lib$LLVM_SO_NAME.$IMP_LIB_EXT"], [llvm_have_one_so=yes])
  
          if test "x$llvm_have_one_so" = xyes; then
EOF
    if [[ $? != 0 ]] ; then
        warn "OSMesa patch failed."
        return 1
    fi

    return 0;
}

function build_osmesa
{
    #
    # prepare build dir
    #
    prepare_build_dir $OSMESA_BUILD_DIR $OSMESA_FILE
    untarred_osmesa=$?
    if [[ $untarred_osmesa == -1 ]] ; then
        warn "Unable to prepare Mesa build directory. Giving Up!"
        return 1
    fi

    #
    # Apply patches
    #
    cd $OSMESA_BUILD_DIR || error "Couldn't cd to osmesa build dir."

    info "Patching OSMesa"
    apply_osmesa_patch
    if [[ $? != 0 ]] ; then
        if [[ $untarred_osmesa == 1 ]] ; then
            warn "Giving up on OSMesa 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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi

    #
    # Build OSMESA.
    #
    if [[ "$DO_STATIC_BUILD" == "yes" ]]; then
        OSMESA_STATIC_DYNAMIC="--disable-shared --disable-shared-glapi --enable-static --enable-static-glapi"
    fi
    if [[ "$VISIT_BUILD_MODE" == "Debug" ]]; then
        OSMESA_DEBUG_BUILD="--enable-debug"
    fi

    info "Configuring OSMesa . . ."
    echo CXXFLAGS="${CXXFLAGS} ${CXX_OPT_FLAGS}" \
        CXX=${CXX_COMPILER} \
        CFLAGS="${CFLAGS} ${C_OPT_FLAGS}" \
        CC=${C_COMPILER} \
        ./autogen.sh \
        --prefix=${VISITDIR}/osmesa/${OSMESA_VERSION}/${VISITARCH} \
        --disable-gles1 \
        --disable-gles2 \
        --disable-dri \
        --disable-dri3 \
        --disable-glx \
        --disable-glx-tls \
        --disable-egl \
        --disable-gbm \
        --disable-xvmc \
        --disable-vdpau \
        --disable-va \
        --with-platforms= \
        --with-gallium-drivers=swrast,swr \
        --enable-gallium-osmesa $OSMESA_STATIC_DYNAMIC  $OSMESA_DEBUG_BUILD \
        --with-llvm-prefix=${VISIT_LLVM_DIR}
    env CXXFLAGS="${CXXFLAGS} ${CXX_OPT_FLAGS}" \
        CXX=${CXX_COMPILER} \
        CFLAGS="${CFLAGS} ${C_OPT_FLAGS}" \
        CC=${C_COMPILER} \
        ./autogen.sh \
        --prefix=${VISITDIR}/osmesa/${OSMESA_VERSION}/${VISITARCH} \
        --disable-gles1 \
        --disable-gles2 \
        --disable-dri \
        --disable-dri3 \
        --disable-glx \
        --disable-glx-tls \
        --disable-egl \
        --disable-gbm \
        --disable-xvmc \
        --disable-vdpau \
        --disable-va \
        --with-platforms= \
        --with-gallium-drivers=swrast,swr \
        --enable-gallium-osmesa $OSMESA_STATIC_DYNAMIC $OSMESA_DEBUG_BUILD \
        --with-llvm-prefix=${VISIT_LLVM_DIR}

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

    info "Building OSMesa . . ."
    ${MAKE} ${MAKE_OPT_FLAGS}
    if [[ $? != 0 ]] ; then
        warn "OSMesa build failed.  Giving up"
        return 1
    fi

    info "Installing OSMesa ..."
    ${MAKE} ${MAKE_OPT_FLAGS} install
    if [[ $? != 0 ]] ; then
        warn "OSMesa install failed.  Giving up"
        return 1
    fi

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

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

function bv_osmesa_is_installed
{
    check_if_installed "osmesa" $OSMESA_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_osmesa_build
{
    #
    # Build OSMesa
    #
    cd "$START_DIR"
    if [[ "$DO_OSMESA" == "yes" ]] ; then
        check_if_installed "osmesa" $OSMESA_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping OSMesa build.  OSMesa is already installed."
            return 0
        fi
        check_if_installed "mesagl" $MESAGL_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping OSMesa build.  MesaGL is already installed."
        else
            info "Building OSMesa (~20 minutes)"
            build_osmesa
            if [[ $? != 0 ]] ; then
                error "Unable to build or install OSMesa.  Bailing out."
            fi
            info "Done building OSMesa"
        fi
    fi
}
# Module automatically read in from construct_build_visit
# Insert header and comments
function bv_ospray_initialize
{
    export DO_OSPRAY="no"
    export USE_SYSTEM_OSPRAY="no"
    export OSPRAY_CONFIG_DIR=""
    add_extra_commandline_args "ospray" "alt-ospray-dir" 1 "Use alternative directory for ospray"
}

function bv_ospray_enable
{
    DO_OSPRAY="yes"
}

function bv_ospray_disable
{
    DO_OSPRAY="no"
}

function bv_ospray_alt_ospray_dir
{
    echo "Using alternate ospray directory"
    bv_ospray_enable
    USE_SYSTEM_OSPRAY="ospray"
    OSPRAY_CONFIG_DIR="$1"
}

function bv_ospray_check_openmp
{
    _OPENMP=$(echo | cpp -fopenmp -dM | grep -i open)
    if [[ "$_OPENMP" == "#define _OPENMP"* ]]; then
        return 0
    fi
    return -1
}

function bv_ospray_depends_on
{
    depends_on="cmake ispc embree"

    if [[ "$DO_TBB" == "yes" ]]; then
        depends_on="${depends_on} tbb"
    else
        bv_ospray_check_openmp
        if [[ $? == -1 ]]; then
            depends_on="${depends_on} tbb"
        fi
    fi

    echo ${depends_on}
}

function bv_ospray_info
{
    # versions
    export OSPRAY_VERSION=${OSPRAY_VERSION:-"1.6.1"}
    export OSPRAY_VISIT_MODULE_VERSION=${OSPRAY_VISIT_MODULE_VERSION:-"1.6.x"}
    
    # ospray source
    export OSPRAY_TARBALL=${OSPRAY_TARBALL:-"ospray-${OSPRAY_VERSION}.tar.gz"}
    export OSPRAY_BUILD_DIR=${OSPRAY_BUILD_DIR:-"ospray-${OSPRAY_VERSION}"}
    export OSPRAY_DOWNLOAD_URL=${OSPRAY_DOWNLOAD_URL:-"https://github.com/wilsonCernWq/module_visit/releases/download/v1.6.x"}

    # ospray module
    export OSPRAY_VISIT_MODULE_TARBALL=${OSPRAY_VISIT_MODULE_TARBALL:-"module_visit-${OSPRAY_VISIT_MODULE_VERSION}.zip"}
    export OSPRAY_VISIT_MODULE_UNTAR_DIR=${OSPRAY_VISIT_MODULE_UNTAR_DIR:-"module_visit-${OSPRAY_VISIT_MODULE_VERSION}"}
    export OSPRAY_VISIT_MODULE_BUILD_DIR=${OSPRAY_VISIT_MODULE_BUILD_DIR:-"${OSPRAY_BUILD_DIR}/modules/module_visit"}
    export OSPRAY_VISIT_MODULE_DOWNLOAD_URL=${OSPRAY_VISIT_MODULE_DOWNLOAD_URL:-"https://github.com/wilsonCernWq/module_visit/releases/download/v1.6.x"}
    export OSPRAY_MD5_CHECKSUM="58cfed6a24e8023389f63f65455466aa"
    export OSPRAY_SHA256_CHECKSUM="e080ca1161cbb987d889bb2ce308be7a38e0928afe7c9e952afd8273e29de432"
}

function bv_ospray_print
{
    print "%s%s\n" "OSPRAY_TARBALL=" "${OSPRAY_TARBALL}"
    print "%s%s\n" "OSPRAY_VERSION=" "${OSPRAY_VERSION}"
    print "%s%s\n" "OSPRAY_TARGET=" "${OSPRAY_TARGET}"
    print "%s%s\n" "OSPRAY_BUILD_DIR=" "${OSPRAY_BUILD_DIR}"
}

function bv_ospray_print_usage
{
    printf "%-20s %s [%s]\n" "--ospray" "Build OSPRay rendering support" "$DO_OSPRAY"
}

function bv_ospray_host_profile
{
    if [[ "$DO_OSPRAY" == "yes" ]]; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## OSPRay" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_OSPRAY ON TYPE BOOL)" >> $HOSTCONF
        if [[ "$USE_SYSTEM_OSPRAY" == "no" ]]; then
            echo "SETUP_APP_VERSION(OSPRAY ${OSPRAY_VERSION})" >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(VISIT_OSPRAY_DIR \${VISITHOME}/ospray/\${OSPRAY_VERSION}/\${VISITARCH})" >> $HOSTCONF
        else
            local _tmp_=$(basename ${OSPRAY_CONFIG_DIR})
            echo "SETUP_APP_VERSION(OSPRAY ${_tmp_:7})" >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(VISIT_OSPRAY_DIR ${OSPRAY_INSTALL_DIR})" >> $HOSTCONF
        fi
    fi
}

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

function bv_ospray_ensure
{
    if [[ "$DO_OSPRAY" == "yes" && "$USE_SYSTEM_OSPRAY" == "no" ]]; then
        ensure_built_or_ready "ospray" \
            $OSPRAY_VERSION \
            $OSPRAY_BUILD_DIR \
            $OSPRAY_TARBALL \
            $OSPRAY_DOWNLOAD_URL 
        if [[ $? != 0 ]] ; then
            return 1
        fi
        ensure_built_or_ready "ospray-visit-module" \
            $OSPRAY_VISIT_MODULE_VERSION \
            $OSPRAY_VISIT_MODULE_BUILD_DIR \
            $OSPRAY_VISIT_MODULE_TARBALL \
            $OSPRAY_VISIT_MODULE_DOWNLOAD_URL
        if [[ $? != 0 ]] ; then
            return 1
        fi       
    fi
}

function bv_ospray_initialize_vars
{
    info "initializing ospray vars"
    if [[ "$DO_OSPRAY" == "yes" ]]; then
        if [[ "$USE_SYSTEM_OSPRAY" == "no" ]]; then
            OSPRAY_INSTALL_DIR="${VISITDIR}/ospray/${OSPRAY_VERSION}/${VISITARCH}"
        else
            OSPRAY_INSTALL_DIR="${OSPRAY_CONFIG_DIR}/../../../"
        fi

        # Qi's Note: Are those variables necessary ?
        OSPRAY_INCLUDE_DIR="${OSPRAY_INSTALL_DIR}/include"
        if [[ -d $OSPRAY_INSTALL_DIR/lib64 ]]; then
            OSPRAY_LIB_DIR="${OSPRAY_INSTALL_DIR}/lib64"
        else
            OSPRAY_LIB_DIR="${OSPRAY_INSTALL_DIR}/lib"
        fi        
        OSPRAY_LIB="${OSPRAY_LIB_DIR}/libospray.so"            

        VTK_USE_OSPRAY="yes"
    fi
}

function bv_ospray_dry_run
{
    if [[ "$DO_OSPRAY" == "yes" ]] ; then
        echo "Dry run option not set for ospray."
    fi
}

function bv_ospray_is_installed
{
    if [[ "$USE_SYSTEM_OSPRAY" == "yes" ]]; then   
        return 1
    fi

    check_if_installed "ospray" $OSPRAY_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function build_ospray_in_source
{
    # set compiler if the user hasn't explicitly set CC and CXX
    if [ -z $CC ]; then
        echo "***NOTE: using compiler $C_COMPILER/$CXX_COMPILER!"
        export CC=$C_COMPILER
        export CXX=$CXX_COMPILER
    fi

    #### Build OSPRay ####
    mkdir -p build
    cd build

    # Clean out build directory to be sure we are doing a fresh build
    rm -rf *

    # set release and RPM settings
    info "Configure OSPRay . . . "
    CMAKE_INSTALL=${CMAKE_INSTALL:-"$VISITDIR/cmake/${CMAKE_VERSION}/$VISITARCH/bin"}

    CMAKE_VARS=""
    CMAKE_VARS=${CMAKE_VARS}" -D CMAKE_INSTALL_PREFIX=${OSPRAY_INSTALL_DIR} "
    CMAKE_VARS=${CMAKE_VARS}" -D OSPRAY_BUILD_ISA=ALL "
    CMAKE_VARS=${CMAKE_VARS}" -D OSPRAY_MODULE_VISIT=ON "
    CMAKE_VARS=${CMAKE_VARS}" -D OSPRAY_MODULE_MPI=OFF "
    CMAKE_VARS=${CMAKE_VARS}" -D OSPRAY_MODULE_MPI_APPS=OFF "
    CMAKE_VARS=${CMAKE_VARS}" -D OSPRAY_APPS_EXAMPLEVIEWER=OFF "
    CMAKE_VARS=${CMAKE_VARS}" -D OSPRAY_APPS_BENCHMARK=OFF "
    CMAKE_VARS=${CMAKE_VARS}" -D OSPRAY_SG_CHOMBO=OFF "
    CMAKE_VARS=${CMAKE_VARS}" -D OSPRAY_SG_OPENIMAGEIO=OFF "
    CMAKE_VARS=${CMAKE_VARS}" -D OSPRAY_SG_VTK=OFF "
    CMAKE_VARS=${CMAKE_VARS}" -D OSPRAY_ZIP_MODE=OFF "
    CMAKE_VARS=${CMAKE_VARS}" -D embree_DIR=${EMBREE_INSTALL_DIR} "
    CMAKE_VARS=${CMAKE_VARS}" -D ISPC_EXECUTABLE=${ISPC_INSTALL_DIR}/ispc "
    if [[ "${TBB_INSTALL_DIR}" == "" ]]; then
        bv_ospray_check_openmp
        if [[ $? == 0 ]]; then
            CMAKE_VARS=${CMAKE_VARS}" -D OSPRAY_TASKING_SYSTEM=OpenMP "
        else
            error "OSPRay cannot find neither TBB nor OpenMP."
        fi
    else
        CMAKE_VARS=${CMAKE_VARS}" -D TBB_ROOT=${TBB_INSTALL_DIR} "
    fi
    ${CMAKE_INSTALL}/cmake ${CMAKE_VARS} \
        .. || error "OSPRay did not configure correctly.  Giving up."

    #
    # Now build OSPRay
    #
    info "Building OSPRay (~10 minute)"
    env DYLD_LIBRARY_PATH=`pwd`/bin $MAKE $MAKE_OPT_FLAGS || \
        error "OSPRay did not build correctly.  Giving up."

    info "Installing OSPRay . . . "
    $MAKE install || error "OSPRay did not install correctly."
}

function build_ospray
{
    # prepare directories
    prepare_build_dir $OSPRAY_BUILD_DIR $OSPRAY_TARBALL
    untarred_ospray=$?
    if [[ $untarred_ospray == -1 ]]; then
        warn "Unable to prepare OSPRay build directory. Giving up!"
        return 1
    fi
    prepare_build_dir $OSPRAY_VISIT_MODULE_BUILD_DIR $OSPRAY_VISIT_MODULE_TARBALL
    untarred_ospray_visit_module=$?
    if [[ $untarred_ospray_visit_module == -1 ]]; then
        warn "Unable to prepare OSPRay build directory. Giving up!"
        return 1
    elif [[ $untarred_ospray_visit_module == 1 ]]; then
        rm -fr $OSPRAY_VISIT_MODULE_BUILD_DIR
        mv $OSPRAY_VISIT_MODULE_UNTAR_DIR $OSPRAY_VISIT_MODULE_BUILD_DIR \
            || error "Couldn't find module_visit for OSPRay"
    fi

    # build and install
    cd $OSPRAY_BUILD_DIR || error "Couldn't cd to OSPRay build dir."
    build_ospray_in_source

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

function bv_ospray_build
{
    cd "$START_DIR"
    if [[ "$DO_OSPRAY" == "yes" && "$USE_SYSTEM_OSPRAY" == "no" ]]; then
        check_if_installed "ospray" $OSPRAY_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping OSPRay build. OSPRay is already installed."
        else
            build_ospray
            if [[ $? != 0 ]]; then
                error "Unable to build or install OSPRay. Bailing out."
            fi
        fi
    fi
}

function bv_p7zip_initialize
{
    export DO_P7ZIP="no"
}

function bv_p7zip_enable
{
    DO_P7ZIP="yes"
}

function bv_p7zip_disable
{
    DO_P7ZIP="no"
}

function bv_p7zip_depends_on
{
    local depends_on=""

    echo $depends_on
}

function bv_p7zip_info
{
    export P7ZIP_VERSION=${P7ZIP_VERSION:-"16.02"}
    export P7ZIP_FILE=${P7ZIP_FILE:-"p7zip_${P7ZIP_VERSION}_src_all.tar.bz2"}
    export P7ZIP_COMPATIBILITY_VERSION=${P7ZIP_COMPATIBILITY_VERSION:-"16.0"}
    export P7ZIP_BUILD_DIR=${P7ZIP_BUILD_DIR:-"p7zip_${P7ZIP_VERSION}"}
    export P7ZIP_URL=${P7ZIP_URL:-https://sourceforge.net/projects/p7zip/files/p7zip/${P7ZIP_VERSION}}
    export P7ZIP_MD5_CHECKSUM="a0128d661cfe7cc8c121e73519c54fbf"
    export P7ZIP_SHA256_CHECKSUM="5eb20ac0e2944f6cb9c2d51dd6c4518941c185347d4089ea89087ffdd6e2341f"
}

function bv_p7zip_print
{
    printf "%s%s\n" "P7ZIP_FILE=" "${P7ZIP_FILE}"
    printf "%s%s\n" "P7ZIP_VERSION=" "${P7ZIP_VERSION}"
    printf "%s%s\n" "P7ZIP_COMPATIBILITY_VERSION=" "${P7ZIP_COMPATIBILITY_VERSION}"
    printf "%s%s\n" "P7ZIP_BUILD_DIR=" "${P7ZIP_BUILD_DIR}"
}

function bv_p7zip_print_usage
{
    printf "%-20s %s [%s]\n" "--p7zip" "Build P7ZIP support" "$DO_P7ZIP"
}

function bv_p7zip_host_profile
{
    if [[ "$DO_P7ZIP" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## P7ZIP" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
            "VISIT_OPTION_DEFAULT(VISIT_SEVEN_ZIP_DIR \${VISITHOME}/p7zip/$P7ZIP_VERSION/\${VISITARCH})" \
            >> $HOSTCONF
    fi
}

function bv_p7zip_ensure
{
    if [[ "$DO_P7ZIP" == "yes" ]] ; then
        ensure_built_or_ready "p7zip" $P7ZIP_VERSION $P7ZIP_BUILD_DIR $P7ZIP_FILE $P7ZIP_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_P7ZIP="no"
            error "Unable to build P7ZIP.  ${P7ZIP_FILE} not found."
        fi
    fi
}

function bv_p7zip_dry_run
{
    if [[ "$DO_P7ZIP" == "yes" ]] ; then
        echo "Dry run option not set for p7zip."
    fi
}

# *************************************************************************** #
#                            Function 8, build_p7zip
#
# Modfications:
#
# *************************************************************************** #

function build_p7zip
{
    #
    # Prepare build dir
    #
    prepare_build_dir $P7ZIP_BUILD_DIR $P7ZIP_FILE
    untarred_p7zip=$?
    if [[ $untarred_p7zip == -1 ]] ; then
        warn "Unable to prepare P7ZIP build directory. Giving Up!"
        return 1
    fi
    
    cd $P7ZIP_BUILD_DIR || error "Can't cd to P7ZIP build dir."
    if [[ "$OPSYS" == "Darwin" ]] ; then
        DTDIGITS=$(echo ${MACOSX_DEPLOYMENT_TARGET} | tr -d'.')
        if [[ $DTDIGITS -le 109 ]]; then #
            cp makefile.macosx_gcc_32bits makefile.machine
        else
            cp makefile.macosx_llvm_64bits makefile.machine
        fi
    fi

    #
    # Build P7ZIP
    #
    info "Building P7ZIP . . . (~1 minute)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
        warn "P7ZIP build failed.  Giving up"
        return 1
    fi

    #
    # Install into the VisIt third party location.
    #
    info "Installing P7ZIP"
    grep -v '^DEST_HOME=' install.sh > install2.sh
    env DEST_HOME="$VISITDIR/p7zip/$P7ZIP_VERSION/$VISITARCH" sh install2.sh
    if [[ $? != 0 ]] ; then
        warn "P7ZIP install failed.  Giving up"
        return 1
    fi

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

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

function bv_p7zip_is_installed
{
    check_if_installed "p7zip" $P7ZIP_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_p7zip_build
{
    cd "$START_DIR"
    if [[ "$DO_P7ZIP" == "yes" ]] ; then
        check_if_installed "p7zip" $P7ZIP_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping P7ZIP build.  P7ZIP is already installed."
        else
            info "Building P7ZIP (~1 minute)"
            build_p7zip
            if [[ $? != 0 ]] ; then
                error "Unable to build or install P7ZIP.  Bailing out."
            fi
            info "Done building P7ZIP"
        fi
    fi
}
function bv_pidx_initialize
{
    export DO_PIDX="no"
    export USE_SYSTEM_PIDX="no"
    add_extra_commandline_args "pidx" "alt-pidx-dir" 1 "Use alternative directory for pidx"
}

function bv_pidx_enable
{
    DO_PIDX="yes"
}

function bv_pidx_disable
{
    DO_PIDX="no"
}

function bv_pidx_alt_pidx_dir
{
    bv_pidx_enable
    USE_SYSTEM_PIDX="yes"
    PIDX_INSTALL_DIR="$1"
}

function bv_pidx_depends_on
{
    depends_on="cmake"

    if [[ "$USE_SYSTEM_PIDX" == "yes" ]]; then
        echo ""
    else
        if [[ "$DO_MPICH" == "yes" ]] ; then
            depends_on="$depends_on mpich"
        fi

        echo $depends_on
    fi
}

function bv_pidx_initialize_vars
{
    if [[ "$USE_SYSTEM_PIDX" == "no" ]]; then
        PIDX_INSTALL_DIR="${VISITDIR}/pidx/$PIDX_VERSION/${VISITARCH}"
    fi
}

function bv_pidx_info
{
    export PIDX_VERSION=${PIDX_VERSION:-"0.9.3"}
    export PIDX_FILE=${PIDX_FILE:-"PIDX-${PIDX_VERSION}.tar.gz"}
    export PIDX_COMPATIBILITY_VERSION=${PIDX_COMPATIBILITY_VERSION:-"1.8"}
    export PIDX_BUILD_DIR=${PIDX_BUILD_DIR:-"PIDX-${PIDX_VERSION}"}
    export PIDX_URL=${PIDX_URL:-"https://github.com/sci-visus/PIDX/releases/download/v${PIDX_VERSION}"}
    export PIDX_MD5_CHECKSUM="bddd00f980e8e8e2ee701b4d816aa6dd"
    export PIDX_SHA256_CHECKSUM="e6c91546821134f87b80ab1d3ed6aa0930c4507d84ad1f19ec51a7ae10152888"
}

function bv_pidx_print
{
    printf "%s%s\n" "PIDX_FILE=" "${PIDX_FILE}"
    printf "%s%s\n" "PIDX_VERSION=" "${PIDX_VERSION}"
    printf "%s%s\n" "PIDX_COMPATIBILITY_VERSION=" "${PIDX_COMPATIBILITY_VERSION}"
    printf "%s%s\n" "PIDX_BUILD_DIR=" "${PIDX_BUILD_DIR}"
}

function bv_pidx_print_usage
{
    printf "%-20s %s [%s]\n" "--pidx" "Build pidx" "${DO_PIDX}"
    printf "%-20s %s [%s]\n" "--alt-pidx-dir" "Use pidx from an alternative directory"
}

function bv_pidx_host_profile
{
    if [[ "$DO_PIDX" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## PIDX" >> $HOSTCONF
        echo "##" >> $HOSTCONF

        echo "SETUP_APP_VERSION(PIDX $PIDX_VERSION)" >> $HOSTCONF 

        if [[ "$USE_SYSTEM_PIDX" == "yes" ]]; then
            echo \
                "VISIT_OPTION_DEFAULT(VISIT_PIDX_DIR $PIDX_INSTALL_DIR)" \
                >> $HOSTCONF 
        else
            echo \
                "VISIT_OPTION_DEFAULT(VISIT_PIDX_DIR \${VISITHOME}/pidx/\${PIDX_VERSION}/\${VISITARCH})" \
                >> $HOSTCONF 
        fi
    fi
}

function bv_pidx_ensure
{
    if [[ "$DO_PIDX" == "yes" && "$USE_SYSTEM_PIDX" == "no" ]] ; then
        ensure_built_or_ready "pidx" $PIDX_VERSION $PIDX_BUILD_DIR $PIDX_FILE $PIDX_URL 
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_PIDX="no"
            error "Unable to build pidx.  ${PIDX_FILE} not found."
        fi
    fi
}

function bv_pidx_dry_run
{
    if [[ "$DO_PIDX" == "yes" ]] ; then
        echo "Dry run option not set for pidx."
    fi
}

function apply_pidx_patch
{
    #    if [[ "${PIDX_VERSION}" == 4.0.0 ]] ; then
    #        apply_pidx_XXX_patch
    #        if [[ $? != 0 ]]; then
    #           return 1
    #        fi
    #    fi

    return 0
}

# *************************************************************************** #
#              Function 8.1, build_pidx                                   #
# *************************************************************************** #
function build_pidx
{
    #
    # CMake is the build system for PIDX.  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 "pidx: 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 $PIDX_BUILD_DIR $PIDX_FILE
    untarred_pidx=$?
    # 0, already exists, 1 untarred src, 2 error

    if [[ $untarred_pidx == -1 ]] ; then
        warn "Unable to prepare pidx build directory. Giving Up"
        return 1
    fi

    #
    cd $PIDX_BUILD_DIR || error "Can't cd to pidx build dir." $PIDX_BUILD_DIR 

    #
    # Apply patches
    #
    info "Patching pidx . . ."
    apply_pidx_patch
    if [[ $? != 0 ]] ; then
        if [[ $untarred_pidx == 1 ]] ; then
            warn "Giving up on pidx 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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi
 
    #
    # Configure pidx
    #
    info "Configuring pidx . . ."

    ntopts=""
    pidx_build_mode="${VISIT_BUILD_MODE}"
    pidx_inst_path="${PIDX_INSTALL_DIR}"

    ntopts="${ntopts} -DCMAKE_BUILD_TYPE:STRING=${pidx_build_mode}"
    ntopts="${ntopts} -DCMAKE_INSTALL_PREFIX:PATH=${pidx_inst_path}"

    # Currently does not work but should be used.
#    ntopts="${ntopts} -DBUILD_SHARED_LIBS:BOOL=ON"

    # Because above the build type is specificed the compiler flags are set
    # So do not set any of these four flags. Otherse a semi-colon gets
    # inserted into the the makefile comands.
    ntopts="${ntopts} -DCMAKE_C_COMPILER:STRING=${C_COMPILER}"
    ntopts="${ntopts} -DCMAKE_CXX_COMPILER:STRING=${CXX_COMPILER}"
    ntopts="${ntopts} -DCMAKE_C_FLAGS:STRING=\"\""
    ntopts="${ntopts} -DCMAKE_CXX_FLAGS:STRING=\"\""
    
#    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}"

    # pidx specific options.

    
#    if test "${OPSYS}" = "Darwin" ; then
#        ntopts="${ntopts} -DCMAKE_INSTALL_NAME_DIR:PATH=${pidx_inst_path}/lib"
#    fi

    if [[ "${DO_MPICH}" == "yes" ]]; then
        info "mpich requested.  Configuring PIDX with mpich support."
        ntopts="${ntopts} -DMPI_C_COMPILER:PATH=${VISITDIR}/mpich/${MPICH_VERSION}/${VISITARCH}/bin/mpicc"
        ntopts="${ntopts} -DMPI_CXX_COMPILER:PATH=${VISITDIR}/mpich/${MPICH_VERSION}/${VISITARCH}/bin/mpicxx"

#        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
    elif [[ "$parallel" == "yes" ]]; then
        if [[ "$PAR_COMPILER" != "" ]]; then
            ntopts="${ntopts} -DMPI_C_COMPILER:STRING=${PAR_COMPILER}"
        fi
        if [[ "$PAR_COMPILER_CXX" != "" ]]; then
            ntopts="${ntopts} -DMPI_CXX_COMPILER:STRING=${PAR_COMPILER_CXX}"
        fi
        if [[ "$PAR_INCLUDE" != "" ]] ; then
            ntopts="${ntopts} -DMPI_C_INCLUDE_PATH:STRING=${PAR_INCLUDE_PATH}"
            ntopts="${ntopts} -DMPI_CXX_INCLUDE_PATH:STRING=${PAR_INCLUDE_PATH}"
        fi
        if [[ "$PAR_LIBS" != "" ]] ; then
            ntopts="${ntopts} -DMPI_C_LINK_FLAGS:STRING=${PAR_LINKER_FLAGS}"
            ntopts="${ntopts} -DMPI_C_LIBRARIES:STRING=${PAR_LIBRARY_LINKER_FLAGS}"
            ntopts="${ntopts} -DMPI_CXX_LINK_FLAGS:STRING=${PAR_LINKER_FLAGS}"
            ntopts="${ntopts} -DMPI_CXX_LIBRARIES:STRING=${PAR_LIBRARY_LINKER_FLAGS}"
        fi
    fi

    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.
    PIDX_SRC_DIR=$PIDX_BUILD_DIR
    PIDX_BUILD_DIR="${PIDX_SRC_DIR}-build"
    if [[ ! -d $PIDX_BUILD_DIR ]] ; then
        echo "Making build directory $PIDX_BUILD_DIR"
        mkdir $PIDX_BUILD_DIR
    fi

    CMAKE_BIN="${CMAKE_INSTALL}/cmake"

    cd ${PIDX_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 ${PIDX_BUILD_DIR}/CMakeCache.txt ${PIDX_BUILD_DIR}/*/CMakeCache.txt

    echo "\"${CMAKE_BIN}\"" ${ntopts} ../${PIDX_SRC_DIR} > bv_run_cmake.sh
    cat bv_run_cmake.sh
    issue_command bash bv_run_cmake.sh || error "pidx configuration failed."

    #
    # Build PIDX
    #
    info "Making pidx . . ."
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
        warn "pidx build failed.  Giving up"
        return 1
    fi

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

#    mv ${pidx_inst_path}/lib64/* ${pidx_inst_path}/lib

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

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

function bv_pidx_is_installed
{

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

    check_if_installed "pidx" $PIDX_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_pidx_build
{
    cd "$START_DIR"

    if [[ "$DO_PIDX" == "yes" && "$USE_SYSTEM_PIDX" == "no" ]] ; then
        check_if_installed "pidx" $PIDX_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping pidx build.  pidx is already installed."
        else
            info "Building pidx (~2 minutes)"
            build_pidx
            if [[ $? != 0 ]] ; then
                error "Unable to build or install pidx.  Bailing out."
            fi
            info "Done building pidx"
        fi
    fi
}
function bv_pyqt_initialize
{
    export DO_PYQT="no"
    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"
}

function bv_pyqt_disable
{
    DO_PYQT="no"
}

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 "%-20s %s [%s]\n" "--pyqt" "Build PyQt support" "$DO_PYQT"
    printf "%-20s %s [%s]\n" "--alt-pyqt-dir" "Use alternative PyQt dir"
}

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_python_initialize
{
    export DO_PYTHON="yes"
    export FORCE_PYTHON="no"
    export USE_SYSTEM_PYTHON="no"
    export BUILD_MPI4PY="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"
    add_extra_commandline_args "python" "mpi4py" 0 "Build mpi4py"
}

function bv_python_enable
{
    DO_PYTHON="yes"
    FORCE_PYTHON="yes"
}

function bv_python_disable
{
    DO_PYTHON="no"
    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
    #
    # use python's distutils info to get the proper library directory.
    #
    PYTHON_LIBRARY_DIR=`"$PYTHON_COMMAND" -c "import sys;from distutils.sysconfig import get_config_var; sys.stdout.write(get_config_var('LIBDIR'))"`
    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
            # some systems eg debian use x86_64-linux-gnu...
            PYTHON_LIBRARY_DIR="${VISIT_PYTHON_DIR}/lib/x86_64-linux-gnu"
            if [ ! -e "${PYTHON_LIBRARY_DIR}/${PYTHON_LIBRARY}" ]
            then
                error "python library was not found, cannot configure python"
            fi
        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_mpi4py
{
    echo "configuring for building mpi4py"
    export BUILD_MPI4PY="yes"
}

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
{
    # we always need openssl b/c of requests.
    echo "openssl zlib"
}

function bv_python_info
{
    export PYTHON_FILE_SUFFIX="tgz"
    export PYTHON_VERSION=${PYTHON_VERSION:-"2.7.14"}
    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="cee2e4b33ad3750da77b2e85f2f8b724"
    export PYTHON_SHA256_CHECKSUM="304c9b202ea6fbd0a4a8e0ad3733715fbd4749f2204a9173a58ec53c32ea73e8"

    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 PIL_MD5_CHECKSUM="fc14a54e1ce02a0225be8854bfba478e"
    export PIL_SHA256_CHECKSUM="895bc7c2498c8e1f9b99938f1a40dc86b3f149741f105cf7c7bd2e0725405211"

    export PYPARSING_FILE=${PYPARSING_FILE:-"pyparsing-1.5.2.tar.gz"}
    export PYPARSING_BUILD_DIR=${PYPARSING_BUILD_DIR:-"pyparsing-1.5.2"}
    export PYPARSING_MD5_CHECKSUM="13aed3cb21a427f8aeb0fe7ca472ba42"
    export PYPARSING_SHA256_CHECKSUM="1021fd2cfdf9c3b6ac0191b018c15d591501b77d977baded59d8ef76d375f21c"

    export PYREQUESTS_FILE=${PYREQUESTS_FILE:-"requests-2.5.1.tar.gz"}
    export PYREQUESTS_BUILD_DIR=${PYREQUESTS_BUILD_DIR:-"requests-2.5.1"}
    export PYREQUESTS_MD5_CHECKSUM="a89558d5dd35a5cb667e9a6e5d4f06f1"
    export PYREQUESTS_SHA256_CHECKSUM="1e5ea203d49273be90dcae2b98120481b2ecfc9f2ae512ce545baab96f57b58c"

    export SEEDME_URL=${SEEDME_URL:-"https://seedme.org/sites/seedme.org/files/downloads/clients/"}
    export SEEDME_FILE=${SEEDME_FILE:-"seedme-python-client-v1.2.4.zip"}
    export SEEDME_BUILD_DIR=${SEEDME_BUILD_DIR:-"seedme-python-client-v1.2.4"}
    export SEEDME_MD5_CHECKSUM="84960d455073fd2f51c31b7fcbc64d58"
    export SEEDME_SHA256_CHECKSUM="71fb233d3b20e95ecd14db1d9cb5deefe775c6ac8bb0ab7604240df7f0e5c5f3"

    export SETUPTOOLS_URL=${SETUPTOOLS_URL:-"https://pypi.python.org/packages/f7/94/eee867605a99ac113c4108534ad7c292ed48bf1d06dfe7b63daa51e49987/"}
    export SETUPTOOLS_FILE=${SETUPTOOLS_FILE:-"setuptools-28.0.0.tar.gz"}
    export SETUPTOOLS_BUILD_DIR=${SETUPTOOLS_BUILD_DIR:-"setuptools-28.0.0"}
    export SETUPTOOLS_MD5_CHECKSUM="9b23df90e1510c7353a5cf07873dcd22"
    export SETUPTOOLS_SHA256_CHECKSUM="e1a2850bb7ad820e4dd3643a6c597bea97a35de2909e9bf0afa3f337836b5ea3"

    export CYTHON_URL=${CYTHON_URL:-"https://pypi.python.org/packages/c6/fe/97319581905de40f1be7015a0ea1bd336a756f6249914b148a17eefa75dc/"}
    export CYTHON_FILE=${CYTHON_FILE:-"Cython-0.25.2.tar.gz"}
    export CYTHON_BUILD_DIR=${CYTHON_BUILD_DIR:-"Cython-0.25.2"}
    export CYTHON_MD5_CHECKSUM="642c81285e1bb833b14ab3f439964086"
    export CYTHON_SHA256_CHECKSUM="f141d1f9c27a07b5a93f7dc5339472067e2d7140d1c5a9e20112a5665ca60306"

    export NUMPY_URL=${NUMPY_URL:-"https://pypi.python.org/packages/a3/99/74aa456fc740a7e8f733af4e8302d8e61e123367ec660cd89c53a3cd4d70/"}
    export NUMPY_FILE=${NUMPY_FILE:-"numpy-1.14.1.zip"}
    export NUMPY_BUILD_DIR=${NUMPY_BUILD_DIR:-"numpy-1.14.1"}
    export NUMPY_MD5_CHECKSUM="b8324ef90ac9064cd0eac46b8b388674"
    export NUMPY_SHA256_CHECKSUM="fa0944650d5d3fb95869eaacd8eedbd2d83610c85e271bd9d3495ffa9bc4dc9c"

    export MPI4PY_URL=${MPI4PY_URL:-"https://pypi.python.org/pypi/mpi4py"}
    export MPI4PY_FILE=${MPI4PY_FILE:-"mpi4py-2.0.0.tar.gz"}
    export MPI4PY_BUILD_DIR=${MPI4PY_BUILD_DIR:-"mpi4py-2.0.0"}
    export MPI4PY_MD5_CHECKSUM="4f7d8126d7367c239fd67615680990e3"
    export MPI4PY_SHA256_CHECKSUM="6543a05851a7aa1e6d165e673d422ba24e45c41e4221f0993fe1e5924a00cb81"
}

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 "%-20s %s\n" "--python" "Build Python" 
    printf "%-20s %s [%s]\n" "--system-python" "Use the system installed Python"
    printf "%-20s %s [%s]\n" "--alt-python-dir" "Use Python from an alternative directory"
    printf "%-20s %s [%s]\n" "--mpi4py" "Build mpi4py with Python"
}

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_patch
{
    if [[ "$OPSYS" == "Darwin" ]]; then
        VER=$(uname -r)
        if [[ ${VER%%.*} == 8 ]] ; then
            apply_python_osx104_patch
            if [[ $? != 0 ]] ; then
                return 1
            fi
        fi
    fi

    return 0
}


# *************************************************************************** #
#                         Function 7, build_python                            #
# *************************************************************************** #

function build_python
{
    prepare_build_dir $PYTHON_BUILD_DIR $PYTHON_FILE
    untarred_python=$?
    # 0, already exists, 1 untarred src, 2 error

    if [[ $untarred_python == -1 ]] ; then
        warn "Unable to prepare Python build directory. Giving Up!"
        return 1
    fi

    #
    # Apply patches
    #
    cd $PYTHON_BUILD_DIR || error "Can't cd to Python build dir."
    apply_python_patch
    if [[ $? != 0 ]] ; then
        if [[ $untarred_python == 1 ]] ; then
            warn "Giving up on Python 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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi

    #
    # Configure Python
    #
    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_CPPFLAGS=""
    PYTHON_PREFIX_DIR="$VISITDIR/python/$PYTHON_VERSION/$VISITARCH"
    if [[ "$DO_STATIC_BUILD" == "no" ]]; then
        PYTHON_SHARED="--enable-shared"
        #
        # 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

    if [[ "$DO_OPENSSL" == "yes" ]]; then
        OPENSSL_INCLUDE="$VISITDIR/openssl/$OPENSSL_VERSION/$VISITARCH/include"
        OPENSSL_LIB="$VISITDIR/openssl/$OPENSSL_VERSION/$VISITARCH/lib"
        PYTHON_LDFLAGS="${PYTHON_LDFLAGS} -L${OPENSSL_LIB}"
        PYTHON_CPPFLAGS="${PTYHON_CPPFLAGS} -I${OPENSSL_INCLUDE}"
    fi

    PY_ZLIB_INCLUDE="$VISITDIR/zlib/$ZLIB_VERSION/$VISITARCH/include"
    PY_ZLIB_LIB="$VISITDIR/zlib/$ZLIB_VERSION/$VISITARCH/lib"
    PYTHON_LDFLAGS="${PYTHON_LDFLAGS} -L${PY_ZLIB_LIB}"
    PYTHON_CPPFLAGS="${PYTHON_CPPFLAGS} -I${PY_ZLIB_INCLUDE}"

    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\" CPPFLAGS=\"$PYTHON_CPPFLAGS\""\
             "${PYTHON_SHARED} --prefix=\"$PYTHON_PREFIX_DIR\" --disable-ipv6"
        ./configure OPT="$PYTHON_OPT" CXX="$cxxCompiler" CC="$cCompiler" \
                    LDFLAGS="$PYTHON_LDFLAGS" \
                    CPPFLAGS="$PYTHON_CPPFLAGS" \
                    ${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
        if [[ $untarred_python == 1 ]] ; then
            warn "Giving up on Pyhton Pil 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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    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 
    if test $? -ne 0 ; then
        popd > /dev/null
        warn "Could not build PIL"
        return 1
    fi
    info "Installing PIL ..."
    ${PYHOME}/bin/python ./setup.py install --prefix="${PYHOME}"
    if test $? -ne 0 ; then
        popd > /dev/null
        warn "Could not install PIL"
        return 1
    fi
    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}"
    if test $? -ne 0 ; then
        popd > /dev/null
        warn "Could not install pyparsing"
        return 1
    fi
    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}"
    if test $? -ne 0 ; then
        popd > /dev/null
        warn "Could not install requests module"
        return 1
    fi
    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}"
    if test $? -ne 0 ; then
        popd > /dev/null
        warn "Could not install seedme module"
        return 1
    fi
    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
}

# *************************************************************************** #
#                                  build_mpi4py                               #
# *************************************************************************** #
function build_mpi4py
{
    # download
    if ! test -f ${MPI4PY_FILE} ; then
        download_file ${MPI4PY_FILE}
        if [[ $? != 0 ]] ; then
            warn "Could not download ${MPI4PY_FILE}"
            return 1
        fi
    fi

    # extract
    if ! test -d ${MPI4PY_BUILD_DIR} ; then
        info "Extracting mpi4py ..."
        uncompress_untar ${MPI4PY_FILE}
        if test $? -ne 0 ; then
            warn "Could not extract ${MPI4PY_FILE}"
            return 1
        fi
    fi

    # install
    pushd $MPI4PY_BUILD_DIR > /dev/null
    info "Installing mpi4py (~ 2 min) ..."
    ${PYHOME}/bin/python ./setup.py install --prefix="${PYHOME}"
    if test $? -ne 0 ; then
        popd > /dev/null
        warn "Could not install mpi4py"
        return 1
    fi
    popd > /dev/null

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

    return 0
}

# *************************************************************************** #
#                                  build_numpy                                #
# *************************************************************************** #
function build_numpy
{
    # download
    if ! test -f ${SETUPTOOLS_FILE} ; then
        download_file ${SETUPTOOLS_FILE}
        if [[ $? != 0 ]] ; then
            warn "Could not download ${SETUPTOOLS_FILE}"
            return 1
        fi
    fi

    if ! test -f ${CYTHON_FILE} ; then
        download_file ${CYTHON_FILE}
        if [[ $? != 0 ]] ; then
            warn "Could not download ${CYTHON_FILE}"
            return 1
        fi
    fi

    if ! test -f ${NUMPY_FILE} ; then
        download_file ${NUMPY_FILE}
        if [[ $? != 0 ]] ; then
            warn "Could not download ${NUMPY_FILE}"
            return 1
        fi
    fi

    # extract
    if ! test -d ${SETUPTOOLS_BUILD_DIR} ; then
        info "Extracting setuptools ..."
        uncompress_untar ${SETUPTOOLS_FILE}
        if test $? -ne 0 ; then
            warn "Could not extract ${SETUPTOOLS_FILE}"
            return 1
        fi
    fi

    if ! test -d ${CYTHON_BUILD_DIR} ; then
        info "Extracting cython ..."
        uncompress_untar ${CYTHON_FILE}
        if test $? -ne 0 ; then
            warn "Could not extract ${CYTHON_FILE}"
            return 1
        fi
    fi

    if ! test -d ${NUMPY_BUILD_DIR} ; then
        info "Extracting numpy ..."
        uncompress_untar ${NUMPY_FILE}
        if test $? -ne 0 ; then
            warn "Could not extract ${NUMPY_FILE}"
            return 1
        fi
    fi

    # install
    PYHOME="${VISITDIR}/python/${PYTHON_VERSION}/${VISITARCH}"
    pushd $SETUPTOOLS_BUILD_DIR > /dev/null
    info "Installing setuptools (~1 min) ..."
    ${PYHOME}/bin/python ./setup.py install --prefix="${PYHOME}"
    if test $? -ne 0 ; then
        popd > /dev/null
        warn "Could not install setuptools"
        return 1
    fi
    popd > /dev/null

    pushd $CYTHON_BUILD_DIR > /dev/null
    info "Installing cython (~ 2 min) ..."
    ${PYHOME}/bin/python ./setup.py install --prefix="${PYHOME}"
    if test $? -ne 0 ; then
        popd > /dev/null
        warn "Could not install cython"
        return 1
    fi
    popd > /dev/null

    pushd $NUMPY_BUILD_DIR > /dev/null
    info "Installing numpy (~ 2 min) ..."
    sed -i 's#\\\\\"%s\\\\\"#%s#' numpy/distutils/system_info.py
    ${PYHOME}/bin/python ./setup.py install --prefix="${PYHOME}"
    if test $? -ne 0 ; then
        popd > /dev/null
        warn "Could not install numpy"
        return 1
    fi
    popd > /dev/null

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

    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"

            # Do not build those packages for a static build!
            if [[ "$DO_STATIC_BUILD" == "yes" ]]; then
                return 0
            fi

            info "Building the Python Imaging Library"
            build_pil
            if [[ $? != 0 ]] ; then
                error "PIL build failed. Bailing out."
            fi
            info "Done building the Python Imaging Library"

            info "Building the numpy module"
            build_numpy
            if [[ $? != 0 ]] ; then
                error "numpy build failed. Bailing out."
            fi
            info "Done building the numpy module."

            if [[ "$BUILD_MPI4PY" == "yes" ]]; then
                info "Building the mpi4py module"
                build_mpi4py
                if [[ $? != 0 ]] ; then
                    error "mpi4py build failed. Bailing out."
                fi
                info "Done building the mpi4py module"
            fi

            info "Building the pyparsing module"
            build_pyparsing
            if [[ $? != 0 ]] ; then
                error "pyparsing build failed. Bailing out."
            fi
            info "Done building the pyparsing module."

            build_requests
            if [[ $? != 0 ]] ; then
                error "requests python module build failed. Bailing out."
            fi
            info "Done building the requests python module."

            build_seedme
            if [[ $? != 0 ]] ; then
                error "seedme python module build failed. Bailing out."
            fi
            info "Done building the seedme python module."

        fi
    fi
}
function bv_qt_initialize
{
    export DO_QT="yes"
    export FORCE_QT="no"
    export USE_SYSTEM_QT="no"
    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"
    FORCE_QT="yes"
}

function bv_qt_disable
{
    DO_QT="no"
    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"
}

function bv_qt_system_qt
{
    echo "using system qt"

    QTEXEC="qmake"
    TEST=`which $QTEXEC`
    if [[ $? != 0 ]]; then
        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
        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_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
{
    if [[ "$DO_MESAGL" == "yes" ]] ; then
       echo "mesagl glu"
    else
        echo ""
    fi
}


function bv_qt_info
{
    bv_qt_enable

    export QT_VERSION=${QT_VERSION:-"5.10.1"}
    export QT_FILE=${QT_FILE:-"qt-everywhere-src-${QT_VERSION}.tar.xz"}
    export QT_BUILD_DIR=${QT_BUILD_DIR:-"${QT_FILE%.tar*}"}
    export QT_BIN_DIR=${QT_BIN_DIR:-"${QT_BUILD_DIR}/bin"}
    export QT_MD5_CHECKSUM="7e167b9617e7bd64012daaacb85477af"
    export QT_SHA256_CHECKSUM="05ffba7b811b854ed558abf2be2ddbd3bb6ddd0b60ea4b5da75d277ac15e740a"
}

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 "%-20s %s\n" "--qt" "Build Qt5" 
    printf "%-20s %s [%s]\n" "--system-qt" "Use the system installed Qt"
    printf "%-20s %s [%s]\n" "--alt-qt-dir" "Use Qt from alternative directory"
}

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
                echo "SETUP_APP_VERSION(QT $QT_VERSION)" >> $HOSTCONF

                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_DIR \${VISITHOME}/qt/\${QT_VERSION}/\${VISITARCH})" >> $HOSTCONF
                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"
    info $QT_LIC_MSG
    read RESPONSE
    if [[ "$RESPONSE" != "yes" ]] ; then
        info $QT_CONFIRM_MSG
        read RESPONSE
        if [[ $RESPONSE != "yes" ]] ; then
            return 1
        fi
    fi

    return 0
}


function apply_qt_patch
{
    if [[ "$DO_MESAGL" == "yes" ]] ; then
        if [[ ${QT_VERSION} == 5.10.1 ]] ; then
            if [[ "$OPSYS" == "Linux" ]]; then
                apply_qt_5101_linux_mesagl_patch
                if [[ $? != 0 ]] ; then
                    return 1
                fi
            fi
        fi
    fi

    if [[ ${QT_VERSION} == 5.10.1 ]] ; then
        if [[ -f /etc/centos-release ]] ; then
            VER=`cat /etc/centos-release | cut -d' ' -f 4`
            if [[ "${VER:0:3}" == "8.0" ]] ; then
                apply_qt_5101_centos8_patch
                if [[ $? != 0 ]] ; then
                    return 1
                fi
            fi
        elif [[ -f /etc/lsb-release ]] ; then
            VER=`cat /etc/lsb-release | grep "DISTRIB_RELEASE" | cut -d'=' -f 2`
            if [[ "${VER:0:3}" == "19." ]] ; then
                apply_qt_5101_centos8_patch
                if [[ $? != 0 ]] ; then
                    return 1
                fi
            fi
        fi

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

    return 0
}

function apply_qt_5101_linux_mesagl_patch
{   
    info "Patching qt 5.10.1 for Linux and Mesa-as-GL"
    patch -p0 <<EOF
    diff -c qtbase/mkspecs/linux-g++-64/qmake.conf.orig  qtbase/mkspecs/linux-g++-64/qmake.conf
    *** qtbase/mkspecs/linux-g++-64/qmake.conf.orig     Thu Feb  8 18:24:48 2018
    --- qtbase/mkspecs/linux-g++-64/qmake.conf  Fri Feb 22 22:04:50 2019
    ***************
    *** 19,24 ****
  
  
      QMAKE_LIBDIR_X11        = /usr/X11R6/lib64
    ! QMAKE_LIBDIR_OPENGL     = /usr/X11R6/lib64
  
      load(qt_config)
    --- 19,25 ----
  
  
      QMAKE_LIBDIR_X11        = /usr/X11R6/lib64
    ! QMAKE_LIBDIR_OPENGL=$MESAGL_LIB_DIR $LLVM_LIB_DIR
    ! QMAKE_INCDIR_OPENGL=$MESAGL_INCLUDE_DIR
  
      load(qt_config)
EOF
    if [[ $? != 0 ]] ; then
        warn "qt 5.10.1 linux mesagl patch failed."
        return 1
    fi
    
    return 0;
}

function apply_qt_5101_centos8_patch
{   
    info "Patching qt 5.10.1 for Centos8"
    patch -p0 <<EOF
diff -c qtbase/src/corelib/io/qfilesystemengine_unix.cpp.orig qtbase/src/corelib/io/qfilesystemengine_unix.cpp
*** qtbase/src/corelib/io/qfilesystemengine_unix.cpp.orig	Thu Oct 17 13:54:59 2019
--- qtbase/src/corelib/io/qfilesystemengine_unix.cpp	Thu Oct 17 13:57:20 2019
***************
*** 97,102 ****
--- 97,103 ----
  #  define FICLONE       _IOW(0x94, 9, int)
  #endif
  
+ #if 0
  #  if !QT_CONFIG(renameat2) && defined(SYS_renameat2)
  static int renameat2(int oldfd, const char *oldpath, int newfd, const char *newpath, unsigned flags)
  { return syscall(SYS_renameat2, oldfd, oldpath, newfd, newpath, flags); }
***************
*** 108,117 ****
--- 109,121 ----
  { return syscall(SYS_statx, dirfd, pathname, flag, mask, statxbuf); }
  #  endif
  #endif
+ #endif
  
+ #if 0
  #ifndef STATX_BASIC_STATS
  struct statx { mode_t stx_mode; };
  #endif
+ #endif
  
  QT_BEGIN_NAMESPACE
  
EOF
    if [[ $? != 0 ]] ; then
        warn "qt 5.10.1 centos8 patch failed."
        return 1
    fi
    
    return 0;
}

function apply_qt_5101_blueos_patch
{   
    info "Patching qt 5.10.1 for Blueos"
    sed -i "s/PNG_ARM_NEON_OPT=0/PNG_ARM_NEON_OPT=0 PNG_POWERPC_VSX_OPT=0/" qtbase/src/3rdparty/libpng/libpng.pro
    if [[ $? != 0 ]] ; then
        warn "qt 5.10.1 blueos patch failed."
        return 1
    fi
    
    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 . . ."
    cd $QT_BUILD_DIR || error "Can't cd to Qt build dir."
    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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi

    #
    # Platform specific configuration
    #

    #
    # Select the proper value for QT_PLATFORM 
    #
    # Question: Could qt auto detect this via the CC and CXX env vars?
    #
    # 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 [[ "$OPSYS" == "Darwin" ]]; then       
        QT_PLATFORM="macx-clang"

    elif [[ "$OPSYS" == "AIX" ]]; then
        if [[ "$OBJECT_MODE" == 32 ]]; then
            QT_PLATFORM="aix-g++"
        else
            QT_PLATFORM="aix-g++-64"
        fi
    elif [[ "$OPSYS" == "SunOS" ]]; then
        if [[ "$OBJECT_MODE" == 32 ]]; then
            QT_PLATFORM="aix-solaris"
        else
            QT_PLATFORM="aix-solaris-64"
        fi
    elif [[ "$OPSYS" == "Linux" ]] ; then
        if [[ "$C_COMPILER" == "clang" ]]; then
            QT_PLATFORM="linux-clang"
        elif [[ "$C_COMPILER" == "llvm" ]]; then
            QT_PLATFORM="linux-llvm"
        elif [[ "$(uname -m)" == "ia64" ]]; then
            QT_PLATFORM="linux-g++-64"
        elif [[ "$(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
        elif [[ "$(uname -m)" == "ppc64" || "$(uname -m)" == "ppc64le" ]]; then
            QT_PLATFORM="linux-g++-64"
        else
            if [[ "$C_COMPILER" == "icc" || "$CXX_COMPILER" == "icpc" ]]; then
                QT_PLATFORM="linux-icc-32"
            else
                QT_PLATFORM="linux-g++-32"
            fi
        fi

        # 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"
        # For Fedora, disable openssl
        elif [[ -n "$(cat /proc/version 2>/dev/null | grep -i fedora)" ]]; then
            EXTRA_QT_FLAGS="$EXTRA_QT_FLAGS -no-openssl"
        fi
    fi

    QT_PLATFORM=${QT_PLATFORM:-"linux-g++"}

    # 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="Qt5"
    qt_flags="${qt_flags} -skip 3d"
    qt_flags="${qt_flags} -skip canvas3d"
    qt_flags="${qt_flags} -skip charts"
    qt_flags="${qt_flags} -skip connectivity"
    qt_flags="${qt_flags} -skip datavis3d"
    qt_flags="${qt_flags} -skip doc"
    qt_flags="${qt_flags} -skip gamepad"
    qt_flags="${qt_flags} -skip graphicaleffects"
    qt_flags="${qt_flags} -skip location"
    qt_flags="${qt_flags} -skip multimedia"
    qt_flags="${qt_flags} -skip networkauth"
    qt_flags="${qt_flags} -skip purchasing"
    qt_flags="${qt_flags} -skip quickcontrols"
    qt_flags="${qt_flags} -skip quickcontrols2"
    qt_flags="${qt_flags} -skip remoteobjects"
    qt_flags="${qt_flags} -skip scxml"
    qt_flags="${qt_flags} -skip sensors"
    qt_flags="${qt_flags} -skip serialport"
    qt_flags="${qt_flags} -skip speech"
    qt_flags="${qt_flags} -skip wayland"
    qt_flags="${qt_flags} -nomake examples"
    qt_flags="${qt_flags} -nomake tests"
    qt_flags="${qt_flags} -no-qml-debug"
    qt_flags="${qt_flags} -qt-zlib"
    qt_flags="${qt_flags} -qt-libpng"

    if [[ "$OPSYS" == "Linux" ]] ; then
        qt_flags="${qt_flags} -qt-xcb -qt-xkbcommon"
    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

    if [[ "$DO_MESAGL" == "yes" ]] ; then
        if [[ ${QT_VERSION} == 5.10.1 ]] ; then
            if [[ "$OPSYS" == "Linux" ]]; then
                sed -i 's/-o Makefile/-o Makefile -after "QMAKE_LIBS_OPENGL+=-lLLVM"/' Makefile
            fi
        fi
    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 [[ "$HAS_OPENGL_SUPPORT" != "yes" ]]; then
    #        warn "Qt configure did not find OpenGL." \
    #             "VisIt needs Qt 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 Qt. Config options above make sure we only build the libs & tools.
    #
    info "Building ${QT_VER_MSG} . . . (~60 minutes)"
    if [[ "${DO_QT_SILENT}" == "yes" ]] ; then
        $MAKE -s $MAKE_OPT_FLAGS
    else
        $MAKE $MAKE_OPT_FLAGS
    fi

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

    info "Installing ${QT_VER_MSG} . . . "
    if [[ "${DO_QT_SILENT}" == "yes" ]] ; then
        $MAKE -s install
    else
        $MAKE install
    fi

    # 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.  Qt 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_qwt_initialize
{
    export DO_QWT="yes"
    export FORCE_QWT="no"
    export USE_SYSTEM_QWT="no"
    add_extra_commandline_args "qwt" "alt-qwt-dir" 1 "Use alternative directory for Qwt"
}

function bv_qwt_enable
{
    DO_QWT="yes"
    FORCE_QWT="yes"
}

function bv_qwt_disable
{
    DO_QWT="no"
    FORCE_QWT="no"
}

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

function bv_qwt_alt_qwt_dir
{
    bv_qwt_enable
    USE_SYSTEM_QWT="yes"
    QWT_INSTALL_DIR="$1"
}

function bv_qwt_depends_on
{
    depends_on="qt"

    if [[ "$USE_SYSTEM_QWT" == "yes" ]]; then
        echo ""
    else
        echo $depends_on
    fi
}

function bv_qwt_initialize_vars
{
    if [[ "$USE_SYSTEM_QWT" == "no" ]]; then
        QWT_INSTALL_DIR="${VISITDIR}/qwt/${QWT_VERSION}/${VISITARCH}"
    fi
}

function bv_qwt_info
{
    export QWT_FILE=${QWT_FILE:-"qwt-6.1.2.tar.bz2"}
    export QWT_VERSION=${QWT_VERSION:-"6.1.2"}
    export QWT_COMPATIBILITY_VERSION=${QWT_COMPATIBILITY_VERSION:-"6.0"}
    export QWT_BUILD_DIR=${QWT_BUILD_DIR:-"qwt-6.1.2"}
    export QWT_MD5_CHECKSUM="9c88db1774fa7e3045af063bbde44d7d"
    export QWT_SHA256_CHECKSUM="2b08f18d1d3970e7c3c6096d850f17aea6b54459389731d3ce715d193e243d0c"
}

function bv_qwt_print
{
    printf "%s%s\n" "QWT_FILE=" "${QWT_FILE}"
    printf "%s%s\n" "QWT_VERSION=" "${QWT_VERSION}"
    printf "%s%s\n" "QWT_COMPATIBILITY_VERSION=" "${QWT_COMPATIBILITY_VERSION}"
    printf "%s%s\n" "QWT_BUILD_DIR=" "${QWT_BUILD_DIR}"
}

function bv_qwt_print_usage
{
    printf "%-20s %s [%s]\n" "--qwt" "Build with Qwt" "$DO_QWT"  
    printf "%-20s %s [%s]\n" "--alt-qwt-dir" "Use Qwt from an alternative directory"
}

function bv_qwt_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 "## QWT" >> $HOSTCONF
                echo "##" >> $HOSTCONF
                echo "SETUP_APP_VERSION(QWT $QWT_VERSION)" >> $HOSTCONF
                if [[ "$USE_SYSTEM_QWT" == "yes" ]]; then
                    echo "VISIT_OPTION_DEFAULT(VISIT_QWT_DIR $SYSTEM_QWT_DIR)" >> $HOSTCONF
                else
                    echo "VISIT_OPTION_DEFAULT(VISIT_QWT_DIR \${VISITHOME}/qwt/\${QWT_VERSION}/\${VISITARCH})" >> $HOSTCONF
                fi
            fi
        fi
    fi
}

function bv_qwt_ensure
{    
    if [[ "$DO_QWT" == "yes" && "$DO_SERVER_COMPONENTS_ONLY" == "no" ]] ; then
        ensure_built_or_ready "qwt" $QWT_VERSION $QWT_BUILD_DIR $QWT_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_QWT="no"
            error "Unable to build Qwt.  ${QWT_FILE} not found."
        fi
    fi
}

function bv_qwt_dry_run
{
    if [[ "$DO_QWT" == "yes" ]] ; then
        echo "Dry run option not set for qwt."
    fi
}

function apply_qwt_linux_patch
{
    PATCHFILE="./patchfile.patch"
    rm -rf $PATCHFILE
    touch $PATCHFILE

    echo "--- qwtconfig.pri        2014-12-11 07:13:13.000000000 -0700" >> $PATCHFILE
    echo "+++ qwtconfig.pri.new    2016-05-03 16:14:00.000000000 -0600" >> $PATCHFILE
    echo "@@ -19,7 +19,7 @@" >> $PATCHFILE
    echo " QWT_INSTALL_PREFIX = \$\$[QT_INSTALL_PREFIX]" >> $PATCHFILE
    echo " " >> $PATCHFILE
    echo " unix {" >> $PATCHFILE
    echo "-    QWT_INSTALL_PREFIX    = /usr/local/qwt-\$\$QWT_VERSION" >> $PATCHFILE
    echo "+    QWT_INSTALL_PREFIX    = ${QWT_INSTALL_DIR}" >> $PATCHFILE
    echo "     # QWT_INSTALL_PREFIX = /usr/local/qwt-\$\$QWT_VERSION-qt-\$\$QT_VERSION" >> $PATCHFILE
    echo " }" >> $PATCHFILE

    patch -p0 < $PATCHFILE

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

#    rm -rf $PATCHFILE
    
    return 0;
}

function apply_qwt_static_patch
{
    # must patch a file in order to create static library
    info "Patching qwt for static build"
    patch -p0 << \EOF
*** qwtconfig.pri.orig	2019-02-07 09:54:46.000000000 -0800
--- qwtconfig.pri	2019-02-07 09:54:58.000000000 -0800
***************
*** 72,78 ****
  # it will be a static library.
  ######################################################################
  
! QWT_CONFIG           += QwtDll
  
  ######################################################################
  # QwtPlot enables all classes, that are needed to use the QwtPlot 
--- 72,78 ----
  # it will be a static library.
  ######################################################################
  
! #QWT_CONFIG           += QwtDll
  
  ######################################################################
  # QwtPlot enables all classes, that are needed to use the QwtPlot 
***************
*** 93,99 ****
  # export a plot to a SVG document
  ######################################################################
  
! QWT_CONFIG     += QwtSvg
  
  ######################################################################
  # If you want to use a OpenGL plot canvas
--- 93,99 ----
  # export a plot to a SVG document
  ######################################################################
  
! #QWT_CONFIG     += QwtSvg
  
  ######################################################################
  # If you want to use a OpenGL plot canvas
***************
*** 118,124 ****
  # Otherwise you have to build it from the designer directory.
  ######################################################################
  
! QWT_CONFIG     += QwtDesigner
  
  ######################################################################
  # Compile all Qwt classes into the designer plugin instead
--- 118,124 ----
  # Otherwise you have to build it from the designer directory.
  ######################################################################
  
! #QWT_CONFIG     += QwtDesigner
  
  ######################################################################
  # Compile all Qwt classes into the designer plugin instead


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

    return 0;

}

function apply_qwt_patch
{
    if [[ "$OPSYS" == "Linux" || "$OPSYS" == "Darwin" ]]; then
        apply_qwt_linux_patch
    fi

    if [[ "$DO_STATIC_BUILD" == "yes" ]] ; then
        apply_qwt_static_patch
    fi
}

# *************************************************************************** #
#                          Function 8.0, build_qwt                           #
# *************************************************************************** #

function build_qwt
{
    #
    # we need or patch to work for any successive configure to build qwt
    # the easiest and most robust way to tackle this is to always delete
    # the source dir if it exists
    
    if [[ -d ${QWT_BUILD_DIR} ]] ; then
        info "Removing old Qwt build dir ${QWT_BUILD_DIR} . . ."
        rm -rf ${QWT_BUILD_DIR}
    fi

    
    #
    # Prepare build dir
    #
    prepare_build_dir $QWT_BUILD_DIR $QWT_FILE
    untarred_qwt=$?
    if [[ $untarred_qwt == -1 ]] ; then
        warn "Unable to prepare Qwt build directory. Giving Up!"
        return 1
    fi

    #
    # Apply patches
    #
    info "Patching Qwt . . ."
    cd $QWT_BUILD_DIR || error "Can't cd to Qwt build dir."
    apply_qwt_patch
    if [[ $? != 0 ]] ; then
        if [[ $untarred_qwt == 1 ]] ; then
            warn "Giving up on Qwt 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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi

    #
    # Build Qwt
    #
    info "Configuring Qwt . . . (~1 minute)"
    ${QT_BIN_DIR}/qmake qwt.pro
    if [[ $? != 0 ]] ; then
        warn "Qwt project build failed.  Giving up"
        return 1
    fi
    
    info "Building Qwt . . . (~2 minutes)"
    $MAKE
    if [[ $? != 0 ]] ; then
        warn "Qwt build failed.  Giving up"
        return 1
    fi
    #
    # Install into the VisIt third party location.
    #
    info "Installing Qwt . . ."

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

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

            fulllibname="${QWT_INSTALL_DIR}/lib/qwt.framework/Versions/6/qwt"
	
            install_name_tool -id $fulllibname $fulllibname

            if [[ $? != 0 ]] ; then
                warn "Qwt dynamic library build failed.  Giving up"
                return 1
            fi
        else
            # Static build. For whatever reason, it was not installing headers.
            mkdir "${QWT_INSTALL_DIR}/include"
            cp -f src/*.h "${QWT_INSTALL_DIR}/include"
        fi
    fi

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

function bv_qwt_is_enabled
{
    if [[ "$DO_SERVER_COMPONENTS_ONLY" == "yes" ]]; then
        return 0
    fi
    if [[ $DO_QWT == "yes" ]]; then
        return 1    
    fi
    return 0
}

function bv_qwt_is_installed
{
    check_if_installed "qwt" $QWT_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_qwt_build
{
    cd "$START_DIR"
    if [[ "$DO_QWT" == "yes" && "$DO_SERVER_COMPONENTS_ONLY" == "no" ]] ; then
        check_if_installed "qwt" $QWT_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping Qwt build. Qwt is already installed."
        else
            info "Building Qwt (~3 minutes)"
            build_qwt
            if [[ $? != 0 ]] ; then
                error "Unable to build or install Qwt. Bailing out."
            fi
            info "Done building Qwt"
        fi
    fi
}
function bv_silo_initialize
{
    export DO_SILO="no"
    export DO_SILEX="no"
    add_extra_commandline_args "silo" "silex" 0 "Enable silex when building Silo"
}

function bv_silo_enable
{
    DO_SILO="yes"
}

function bv_silo_disable
{
    DO_SILO="no"
}

function bv_silo_silex
{
    info "Enabling silex in Silo build"
    DO_SILEX="yes"
    bv_silo_enable
}

function bv_silo_depends_on
{
    local depends_on="zlib"

    if [[ "$DO_HDF5" == "yes" ]] ; then
        depends_on="hdf5"
    fi
    
    if [[ "$DO_SZIP" == "yes" ]] ; then
        depends_on="$depends_on szip"
    fi


    echo $depends_on
}

function bv_silo_info
{
    export SILO_VERSION=${SILO_VERSION:-"4.10.2"}
    export SILO_FILE=${SILO_FILE:-"silo-${SILO_VERSION}.tar.gz"}
    export SILO_COMPATIBILITY_VERSION=${SILO_COMPATIBILITY_VERSION:-"4.10.2"}
    export SILO_URL=${SILO_URL:-https://wci.llnl.gov/codes/silo/silo-${SILO_VERSION}}
    export SILO_BUILD_DIR=${SILO_BUILD_DIR:-"silo-${SILO_VERSION}"}
    export SILO_MD5_CHECKSUM="9ceac777a2f2469ac8cef40f4fab49c8"
    export SILO_SHA256_CHECKSUM="3af87e5f0608a69849c00eb7c73b11f8422fa36903dd14610584506e7f68e638"
}

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 "%-20s %s [%s]\n" "--silo" "Build Silo support" "$DO_SILO"
    printf "%-20s %s [%s]\n" "--silex" "Enable silex when building Silo" "$DO_SILEX"
}

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

        libdep=""
        if [[ "$DO_HDF5" == "yes" ]] ; then
            libdep="HDF5_LIBRARY_DIR hdf5 \${VISIT_HDF5_LIBDEP}"
        fi
        libdep="$libdep ZLIB_LIBRARY_DIR z"
        if [[ -n "$libdep" ]]; then
            echo \
                "VISIT_OPTION_DEFAULT(VISIT_SILO_LIBDEP $libdep TYPE STRING)" \
                >> $HOSTCONF
        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" ]] ; 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

    ZLIBARGS="--with-zlib=${VISITDIR}/zlib/${ZLIB_VERSION}/${VISITARCH}/include,${VISITDIR}/zlib/${ZLIB_VERSION}/${VISITARCH}/lib"

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

    extra_ac_flags=""
    # detect coral systems, which older versions of autoconf don't detect
    if [[ "$(uname -m)" == "ppc64le" ]] ; then
         extra_ac_flags="ac_cv_build=powerpc64le-unknown-linux-gnu"
    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 ${extra_ac_flags}"

    # 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 ${extra_ac_flags}"

    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"
}

function bv_szip_enable
{
    DO_SZIP="yes"
}

function bv_szip_disable
{
    DO_SZIP="no"
}

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="90f103d6bb3d48e1ab32284d35a34411217b138d45efd830b2cb42a29c5c8d5c"
}

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 "%-20s %s [%s]\n" "--szip" "Build with SZIP" "$DO_SZIP"  
}

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

    extra_ac_flags=""
    # detect coral systems, which older versions of autoconf don't detect
    if [[ "$(uname -m)" == "ppc64le" ]] ; then
         extra_ac_flags="ac_cv_build=powerpc64le-unknown-linux-gnu"
    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} \
        ${extra_ac_flags}"

    ./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} \
                ${extra_ac_flags}

    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_tbb_initialize
{
    export DO_TBB="no"
    export USE_SYSTEM_TBB="no"
    add_extra_commandline_args "tbb" "alt-tbb-dir" 1 "Use alternative directory for tbb"
}

function bv_tbb_enable
{
    DO_TBB="yes"
}

function bv_tbb_disable
{
    DO_TBB="no"
}

function bv_tbb_alt_tbb_dir
{
    echo "Using alternate TBB directory"
    bv_tbb_enable
    USE_SYSTEM_TBB="yes"
    TBB_INSTALL_DIR="$1"
}

function bv_tbb_depends_on
{
    if [[ "$USE_SYSTEM_TBB" == "yes" ]] ; then
        echo ""
    else
        echo ""
    fi
}

function bv_tbb_initialize_vars
{
    info "initializing TBB vars"
    if [[ "$DO_TBB" == "yes" ]] ; then
        if [[ "$USE_SYSTEM_TBB" == "no" ]]; then
            TBB_INSTALL_DIR=$VISITDIR/tbb/$TBB_VERSION/$VISITARCH
        fi
    fi
    export TBB_ROOT="${TBB_INSTALL_DIR}"
}

function bv_tbb_info
{
    export TBB_VERSION=${TBB_VERSION:-"tbb2018_20171205oss"}
    if [[ "$OPSYS" == "Darwin" ]] ; then
        export TBB_FILE=${TBB_FILE:-"${TBB_VERSION}_mac.tgz"}
        export TBB_MD5_CHECKSUM="ff7a02f58fee4e2e637db6da19a21806"
        export TBB_SHA256_CHECKSUM="00955b15609298c13104c0b2a500757ea57a5e0ae9fe80a71ce20f29d76629ed"
    else
        export TBB_FILE=${TBB_FILE:-"${TBB_VERSION}_lin.tgz"}
        export TBB_MD5_CHECKSUM="d637d29f59ee31fe5830a0366e2e973a"
        export TBB_SHA256_CHECKSUM="7c2ec94f6f1c2b95293fc0fc7652e0fdeefabfc10cdb66f7176fbf6d99431fb6"
    fi
    export TBB_COMPATIBILITY_VERSION=${TBB_COMPATIBILITY_VERSION:-"${TBB_VERSION}"}
    export TBB_BUILD_DIR=${TBB_BUILD_DIR:-"${TBB_VERSION}"}
}

function bv_tbb_print
{
    printf "%s%s\n" "TBB_FILE=" "${TBB_FILE}"
    printf "%s%s\n" "TBB_VERSION=" "${TBB_VERSION}"
    printf "%s%s\n" "TBB_COMPATIBILITY_VERSION=" "${TBB_COMPATIBILITY_VERSION}"
    printf "%s%s\n" "TBB_BUILD_DIR=" "${TBB_BUILD_DIR}"
}

function bv_tbb_host_profile
{
    if [[ "$DO_TBB" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## TBB" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        # Note by Qi
        #   bv_tbb.sh is not completely written by me. TBB_ROOT cmake variable is commonly used in many
        #   TBB related projects. I want to keep it set here since I am afraid of breaking other packages
        #   other than ospray
        if [[ "$USE_SYSTEM_TBB" == "no" ]]; then
            echo "SETUP_APP_VERSION(TBB ${TBB_VERSION})" >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(TBB_ROOT \${VISITHOME}/tbb/\${TBB_VERSION}/\${VISITARCH})" >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(VISIT_TBB_DIR \${VISITHOME}/tbb/\${TBB_VERSION}/\${VISITARCH})" >> $HOSTCONF
        else
            echo "VISIT_OPTION_DEFAULT(TBB_ROOT ${TBB_INSTALL_DIR})" >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(VISIT_TBB_DIR ${TBB_INSTALL_DIR})" >> $HOSTCONF
        fi
    fi
}

function bv_tbb_print_usage
{
    #tbb does not have an option, it is only dependent on tbb.
    printf "%-20s %s [%s]\n" "--tbb" "Build TBB" "$DO_TBB"
}

function bv_tbb_ensure
{
    if [[ "$DO_TBB" == "yes" && "$USE_SYSTEM_TBB" == "no" ]] ; then
        ensure_built_or_ready "tbb" $TBB_VERSION $TBB_BUILD_DIR $TBB_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_TBB="no"
            error "Unable to build TBB.  ${TBB_FILE} not found."
        fi
    fi
}

function bv_tbb_dry_run
{
    if [[ "$DO_TBB" == "yes" ]] ; then
        echo "Dry run option not set for TBB."
    fi
}

# ***************************************************************************
# build_tbb
#
# Modifications:
#
# ***************************************************************************

function build_tbb
{
    # Unzip the TBB tarball and copy it to the VisIt installation.
    info "Installing prebuilt TBB"
    tar zxvf $TBB_FILE
    mkdir -p $VISITDIR/tbb/$TBB_VERSION/$VISITARCH || error "Cannot make tbb install directory"
    cp -R $TBB_VERSION/* $VISITDIR/tbb/$TBB_VERSION/$VISITARCH || error "Cannot copy to tbb install directory"

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

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

function bv_tbb_is_installed
{
    if [[ "$USE_SYSTEM_TBB" == "yes" ]]; then   
        return 1
    fi

    check_if_installed "tbb" $TBB_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_tbb_build
{
    if [[ "$DO_TBB" == "yes" && "$USE_SYSTEM_TBB" == "no" ]] ; then
        check_if_installed "tbb" $TBB_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping build of TBB"
        else
            build_tbb
            if [[ $? != 0 ]] ; then
                error "Unable to build or install TBB.  Bailing out."
            fi
            info "Done building TBB"
        fi
    fi
}

function bv_tcmalloc_initialize
{
    export DO_TCMALLOC="no"
}

function bv_tcmalloc_enable
{
    DO_TCMALLOC="yes"
}

function bv_tcmalloc_disable
{
    DO_TCMALLOC="no"
}

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="c879267296d91ccadf3aacb9340ca5801b41fbd37aad097b2b6081bf27bb505c"
}

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 "%-20s %s [%s]\n" "--tcmalloc" "Build tcmalloc from Google's perftools" "$DO_TCMALLOC"  
}

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 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"
}

function bv_uintah_disable
{
    DO_UINTAH="no"
}

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/VisIt/interfaces/datatypes.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 "zlib"
    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:-"2.6.1"}
    export UINTAH_FILE=${UINTAH_FILE:-"Uintah-${UINTAH_VERSION}.tar.gz"}
    export UINTAH_COMPATIBILITY_VERSION=${UINTAH_COMPATIBILITY_VERSION:-"2.6"}
    export UINTAH_URL=${UINTAH_URL:-"https://gforge.sci.utah.edu/svn/uintah/releases/uintah_v${UINTAH_VERSION}"}
    export UINTAH_BUILD_DIR=${UINTAH_BUILD_DIR:-"Uintah-${UINTAH_VERSION}/optimized"}
    export UINTAH_MD5_CHECKSUM="09cad7b2fcc7b1f41dabcf7ecae21f54"
    export UINTAH_SHA256_CHECKSUM="0801da6e5700fa826f2cbc6ed01f81f743f92df3e946cc6ba3748458f36f674e"
}

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 "%-20s %s [%s]\n" "--uintah" "Build Uintah" "${DO_UINTAH}"
    printf "%-20s %s [%s]\n" "--alt-uintah-dir" "Use Uintah from an alternative directory"
}

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
            warn "Assuming version 2.7.0 for Uintah"
            echo "SETUP_APP_VERSION(UINTAH 2.7.0)" >> $HOSTCONF
            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.                                     #
#                                                                              #
# Kevin Griffin, Wed Aug 28 10:25:30 PDT 2019                                  #
# Added the --with-libxml2 option to ensure that the /usr/lib/ version is used #
# **************************************************************************** #

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

    #
    # 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

    #
    if [[ ! -d $UINTAH_BUILD_DIR ]] ; then
        echo "Making build directory $UINTAH_BUILD_DIR"
        mkdir $UINTAH_BUILD_DIR
    fi
    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="--enable-static"
    else
        cf_build_type="--disable-static"
    fi

    if [[ "$OPSYS" == "Darwin" ]]; then

        info "Invoking command to configure UINTAH"
        info "../src/configure CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" \
        CFLAGS=\"$CFLAGS $C_OPT_FLAGS -headerpad_max_install_names\" CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS\" \
        MPI_EXTRA_LIB_FLAG=\"$PAR_LIBRARY_NAMES\" \
        --with-zlib=\"$VISITDIR/zlib/$ZLIB_VERSION/$VISITARCH\" \
        --prefix=\"$VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH\" \
        ${cf_darwin} \
        ${cf_build_type} \
	--enable-minimal --enable-optimize \
	--with-fortran=no --with-petsc=no --with-hypre=no \
	--with-lapack=no --with-blas=no \
        --with-mpi=\"$PAR_INCLUDE_DIR/..\" \ 
        --with-libxml2=\"/usr\" "

        #        --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 -headerpad_max_install_names\" CXXFLAGS=\"$CXXFLAGS $CXX_OPT_FLAGS\" \
        MPI_EXTRA_LIB_FLAG=\"$PAR_LIBRARY_NAMES\" \
        --with-zlib=\"$VISITDIR/zlib/$ZLIB_VERSION/$VISITARCH\" \
        --prefix=\"$VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH\" \
        ${cf_darwin} \
        ${cf_build_type} \
        --enable-minimal --enable-optimize \
	--with-fortran=no --with-petsc=no --with-hypre=no \
	--with-lapack=no --with-blas=no \
        --with-mpi=\"$PAR_INCLUDE_DIR/..\" \
        --with-libxml2=\"/usr\" "

        #        --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\" \
        --with-zlib=\"$VISITDIR/zlib/$ZLIB_VERSION/$VISITARCH\" \
        --prefix=\"$VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH\" \
        ${cf_build_type} \
        --enable-minimal --enable-optimize \
	--with-fortran=no --with-petsc=no --with-hypre=no \
	--with-lapack=no --with-blas=no \
        --with-mpi=built-in"

        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\" \
        --with-zlib=\"$VISITDIR/zlib/$ZLIB_VERSION/$VISITARCH\" \
        --prefix=\"$VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH\" \
        ${cf_build_type} \
        --enable-minimal --enable-optimize \
        --with-fortran=no --with-petsc=no --with-hypre=no \
	--with-lapack=no --with-blas=no \
        --with-mpi=built-in"
    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
        mkdir $VISITDIR/uintah/$UINTAH_VERSION || error "Can't make UINTAH install dir."
    fi

    if [[ ! -e $VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH ]] ; then
        mkdir $VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH || error "Can't make UINTAH install dir."
    else        
        rm -rf $VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH/* || error "Can't remove old UINTAH install dir."
    fi

    mkdir $VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH/lib || error "Can't make UINTAH install lib dir."
    mkdir $VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH/include || error "Can't make UINTAH install include dir."
    mkdir $VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH/include/VisIt || error "Can't make UINTAH install include/VisIt dir."
    mkdir $VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH/include/VisIt/interfaces || error "Can't make UINTAH install include/VisIt/interfaces dir."

    cp lib/* $VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH/lib
    cp ../src/VisIt/interfaces/datatypes.h $VISITDIR/uintah/$UINTAH_VERSION/$VISITARCH/include/VisIt/interfaces/datatypes.h

    #    $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 . . ."
        INSTALLNAMEPATH="${UINTAH_INSTALL_DIR}/lib"

        libs=`ls ${INSTALLNAMEPATH}/*.${SO_EXT}`

        for lib in $libs;
        do
            # Get the library path right
            install_name_tool -id $lib $lib

            # Find all the dependent libraries (more or less)
            deplibs=`otool -L $lib | sed "s/(.*)//g"`

            for deplib in $deplibs;
            do
                # Only get the libraries related to Uintah
                if [[ `echo $deplib | grep -c ${UINTAH_BUILD_DIR}` == 1 ]] ; then

                    # Get the library name sans the directory path
                    deplibname=`echo $deplib | sed "s/.*\///"`

                    # Finally set the library path
                    install_name_tool -change \
                                      $deplib ${INSTALLNAMEPATH}/$deplibname $lib
                fi
            done
        done
    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_vtk_initialize
{
    export DO_VTK="yes"
    export FORCE_VTK="no"
    export USE_SYSTEM_VTK="no"
    add_extra_commandline_args "vtk" "system-vtk" 0 "Using system VTK (exp)"
    add_extra_commandline_args "vtk" "alt-vtk-dir" 1 "Use alternate VTK (exp)"
}

function bv_vtk_enable
{
    DO_VTK="yes"
    FORCE_VTK="yes"
}

function bv_vtk_disable
{
    DO_VTK="no"
    FORCE_VTK="no"
}

function bv_vtk_system_vtk
{
    TEST=`which vtk-config`
    [ $? != 0 ] && error "System vtk-config not found, cannot configure vtk"

    bv_vtk_enable
    USE_SYSTEM_VTK="yes"
    SYSTEM_VTK_DIR="$1"
    info "Using System VTK: $SYSTEM_VTK_DIR"
}

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 zlib"

    if [[ "$DO_PYTHON" == "yes" ]]; then
        depends_on="${depends_on} python"
    fi

    if [[ "$DO_MESAGL" == "yes" ]]; then
        depends_on="${depends_on} mesagl glu"
    fi

    if [[ "$DO_OSPRAY" == "yes" ]]; then
        depends_on="${depends_on} ospray"
    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-8.1.0.tar.gz"}
    export VTK_VERSION=${VTK_VERSION:-"8.1.0"}
    export VTK_SHORT_VERSION=${VTK_SHORT_VERSION:-"8.1"}
    export VTK_COMPATIBILITY_VERSION=${VTK_SHORT_VERSION}
    export VTK_URL=${VTK_URL:-"http://www.vtk.org/files/release/${VTK_SHORT_VERSION}"}
    export VTK_BUILD_DIR=${VTK_BUILD_DIR:-"VTK-8.1.0"}
    export VTK_INSTALL_DIR=${VTK_INSTALL_DIR:-"vtk"}
    export VTK_MD5_CHECKSUM="4fa5eadbc8723ba0b8d203f05376d932"
    export VTK_SHA256_CHECKSUM="6e269f07b64fb13774f5925161fb4e1f379f4e6a0131c8408c555f6b58ef3cb7"
}

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 "%-20s %s\n" "--vtk" "Build VTK"
    printf "%-20s %s [%s]\n" "--system-vtk" "Use the system installed VTK"
    printf "%-20s %s [%s]\n" "--alt-vtk-dir" "Use VTK from an alternative directory"
}

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
        # vtk's target system should take care of this, so does VisIt need to know?
        echo "VISIT_OPTION_DEFAULT(VISIT_VTK_INCDEP ZLIB_INCLUDE_DIR)" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_VTK_LIBDEP ZLIB_LIBRARY)" >> $HOSTCONF
    fi
}

function bv_vtk_initialize_vars
{
    info "initalizing vtk vars"
}

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_vtkxopenglrenderwindow_patch
{
  # patch vtk's vtkXOpenRenderWindow to fix segv when deleting windows in
  # offscreen mode.

   patch -p0 << \EOF
*** Rendering/OpenGL2/vtkXOpenGLRenderWindow.cxx.orig 2018-03-30 14:38:07.000000000
--- Rendering/OpenGL2/vtkXOpenGLRenderWindow.cxx 2018-03-30 14:38:40.000000000
***************
*** 1148,1160 ****

  void vtkXOpenGLRenderWindow::PopContext()
  {
    GLXContext current = glXGetCurrentContext();
    GLXContext target = static_cast<GLXContext>(this->ContextStack.top());
    this->ContextStack.pop();
!   if (target != current)
    {
      glXMakeCurrent(this->DisplayStack.top(),
        this->DrawableStack.top(),
        target);
    }
    this->DisplayStack.pop();
--- 1148,1160 ----

  void vtkXOpenGLRenderWindow::PopContext()
  {
    GLXContext current = glXGetCurrentContext();
    GLXContext target = static_cast<GLXContext>(this->ContextStack.top());
    this->ContextStack.pop();
!   if (target && target != current)
    {
      glXMakeCurrent(this->DisplayStack.top(),
        this->DrawableStack.top(),
        target);
    }
    this->DisplayStack.pop();

EOF

    if [[ $? != 0 ]] ; then
      warn "vtk patch for vtkXOpenGLRenderWindow failed."
      return 1
    fi
    return 0;

}

function apply_vtkopenglspheremapper_h_patch
{
  # patch vtk's vtkOpenGLSphereMapper.h to fix bug evidenced when
  # points are double precision

   patch -p0 << \EOF
*** Rendering/OpenGL2/vtkOpenGLSphereMapper.h.orig  2019-06-05 11:49:48.675659000 -0700
--- Rendering/OpenGL2/vtkOpenGLSphereMapper.h  2019-06-05 10:25:08.000000000 -0700
***************
*** 94,105 ****
  
    void RenderPieceDraw(vtkRenderer *ren, vtkActor *act) override;
  
-   virtual void CreateVBO(
-     float * points, vtkIdType numPts,
-     unsigned char *colors, int colorComponents,
-     vtkIdType nc,
-     float *sizes, vtkIdType ns, vtkRenderer *ren);
- 
    // used for transparency
    bool Invert;
    float Radius;
--- 94,99 ----
EOF

    if [[ $? != 0 ]] ; then
      warn "vtk patch for vtkOpenGLSphereMapper.h failed."
      return 1
    fi
    return 0;
}

function apply_vtkopenglspheremapper_patch
{
  # patch vtk's vtkOpenGLSphereMapper to fix bug that ignores opacity when
  # specifying single color for the sphere imposters, and another bug
  # evidenced when points are double precision

   patch -p0 << \EOF
*** Rendering/OpenGL2/vtkOpenGLSphereMapper.cxx.orig 2017-12-22 08:33:25.000000000 -0800
--- Rendering/OpenGL2/vtkOpenGLSphereMapper.cxx 2019-06-06 12:21:13.735291000 -0700
***************
*** 15,20 ****
--- 15,21 ----
  
  #include "vtkOpenGLHelper.h"
  
+ #include "vtkDataArrayAccessor.h"
  #include "vtkFloatArray.h"
  #include "vtkMath.h"
  #include "vtkMatrix4x4.h"
***************
*** 211,253 ****
    os << indent << "Radius: " << this->Radius << "\n";
  }
  
! // internal function called by CreateVBO
! void vtkOpenGLSphereMapper::CreateVBO(
!   float * points, vtkIdType numPts,
!   unsigned char *colors, int colorComponents,
!   vtkIdType nc,
!   float *sizes, vtkIdType ns, vtkRenderer *ren)
  {
!   vtkFloatArray *verts = vtkFloatArray::New();
!   verts->SetNumberOfComponents(3);
!   verts->SetNumberOfTuples(numPts*3);
!   float *vPtr = static_cast<float *>(verts->GetVoidPointer(0));
  
!   vtkFloatArray *offsets = vtkFloatArray::New();
!   offsets->SetNumberOfComponents(2);
!   offsets->SetNumberOfTuples(numPts*3);
    float *oPtr = static_cast<float *>(offsets->GetVoidPointer(0));
- 
-   vtkUnsignedCharArray *ucolors = vtkUnsignedCharArray::New();
-   ucolors->SetNumberOfComponents(4);
-   ucolors->SetNumberOfTuples(numPts*3);
    unsigned char *cPtr = static_cast<unsigned char *>(ucolors->GetVoidPointer(0));
  
!   float *pointPtr;
!   unsigned char *colorPtr;
  
    float cos30 = cos(vtkMath::RadiansFromDegrees(30.0));
  
    for (vtkIdType i = 0; i < numPts; ++i)
    {
!     pointPtr = points + i*3;
!     colorPtr = (nc == numPts ? colors + i*colorComponents : colors);
!     float radius = (ns == numPts ? sizes[i] : sizes[0]);
  
      // Vertices
!     *(vPtr++) = pointPtr[0];
!     *(vPtr++) = pointPtr[1];
!     *(vPtr++) = pointPtr[2];
      *(cPtr++) = colorPtr[0];
      *(cPtr++) = colorPtr[1];
      *(cPtr++) = colorPtr[2];
--- 212,250 ----
    os << indent << "Radius: " << this->Radius << "\n";
  }
  
! // internal function called by BuildBufferObjects
! template <typename PtsArray, typename SizesArray>
! void vtkOpenGLSphereMapper_PrepareVBO(
!   PtsArray *points, unsigned char *colors, int colorComponents,
!   vtkIdType nc, SizesArray *sizesA, vtkIdType ns,
!   vtkFloatArray *verts, vtkFloatArray *offsets, vtkUnsignedCharArray *ucolors)
  {
!   vtkIdType numPts = points->GetNumberOfTuples();
  
!   float *vPtr = static_cast<float *>(verts->GetVoidPointer(0));
    float *oPtr = static_cast<float *>(offsets->GetVoidPointer(0));
    unsigned char *cPtr = static_cast<unsigned char *>(ucolors->GetVoidPointer(0));
  
!   vtkDataArrayAccessor<PtsArray> pointPtr(points);
!   vtkDataArrayAccessor<SizesArray> sizes(sizesA);
! 
!   float radius = sizes.Get(0, 0);
!   
!   unsigned char *colorPtr = colors;
  
    float cos30 = cos(vtkMath::RadiansFromDegrees(30.0));
  
    for (vtkIdType i = 0; i < numPts; ++i)
    {
!     if (nc == numPts)
!         colorPtr = colors + i*colorComponents;
!     if (ns == numPts)
!         radius = sizes.Get(i, 0);
  
      // Vertices
!     *(vPtr++) = pointPtr.Get(i, 0);
!     *(vPtr++) = pointPtr.Get(i, 1);
!     *(vPtr++) = pointPtr.Get(i, 2);
      *(cPtr++) = colorPtr[0];
      *(cPtr++) = colorPtr[1];
      *(cPtr++) = colorPtr[2];
***************
*** 255,263 ****
      *(oPtr++) = -2.0f*radius*cos30;
      *(oPtr++) = -radius;
  
!     *(vPtr++) = pointPtr[0];
!     *(vPtr++) = pointPtr[1];
!     *(vPtr++) = pointPtr[2];
      *(cPtr++) = colorPtr[0];
      *(cPtr++) = colorPtr[1];
      *(cPtr++) = colorPtr[2];
--- 252,260 ----
      *(oPtr++) = -2.0f*radius*cos30;
      *(oPtr++) = -radius;
  
!     *(vPtr++) = pointPtr.Get(i, 0);
!     *(vPtr++) = pointPtr.Get(i, 1);
!     *(vPtr++) = pointPtr.Get(i, 2);
      *(cPtr++) = colorPtr[0];
      *(cPtr++) = colorPtr[1];
      *(cPtr++) = colorPtr[2];
***************
*** 265,273 ****
      *(oPtr++) = 2.0f*radius*cos30;
      *(oPtr++) = -radius;
  
!     *(vPtr++) = pointPtr[0];
!     *(vPtr++) = pointPtr[1];
!     *(vPtr++) = pointPtr[2];
      *(cPtr++) = colorPtr[0];
      *(cPtr++) = colorPtr[1];
      *(cPtr++) = colorPtr[2];
--- 262,270 ----
      *(oPtr++) = 2.0f*radius*cos30;
      *(oPtr++) = -radius;
  
!     *(vPtr++) = pointPtr.Get(i, 0);
!     *(vPtr++) = pointPtr.Get(i, 1);
!     *(vPtr++) = pointPtr.Get(i, 2);
      *(cPtr++) = colorPtr[0];
      *(cPtr++) = colorPtr[1];
      *(cPtr++) = colorPtr[2];
***************
*** 275,288 ****
      *(oPtr++) = 0.0f;
      *(oPtr++) = 2.0f*radius;
    }
- 
-   this->VBOs->CacheDataArray("vertexMC", verts, ren, VTK_FLOAT);
-   verts->Delete();
-   this->VBOs->CacheDataArray("offsetMC", offsets, ren, VTK_FLOAT);
-   offsets->Delete();
-   this->VBOs->CacheDataArray("scalarColor", ucolors, ren, VTK_UNSIGNED_CHAR);
-   ucolors->Delete();
-   VBOs->BuildAllVBOs(ren);
  }
  
  //-------------------------------------------------------------------------
--- 272,277 ----
***************
*** 320,326 ****
    // then the scalars do not have to be regenerted.
    this->MapScalars(1.0);
  
!   vtkIdType numPts = poly->GetPoints()->GetNumberOfPoints();
    unsigned char *c;
    int cc;
    vtkIdType nc;
--- 309,317 ----
    // then the scalars do not have to be regenerted.
    this->MapScalars(1.0);
  
!   vtkPoints *pts = poly->GetPoints();
! 
!   vtkIdType numPts = pts->GetNumberOfPoints();
    unsigned char *c;
    int cc;
    vtkIdType nc;
***************
*** 333,373 ****
    else
    {
      double *ac = act->GetProperty()->GetColor();
!     c = new unsigned char[3];
      c[0] = (unsigned char) (ac[0] *255.0);
      c[1] = (unsigned char) (ac[1] *255.0);
      c[2] = (unsigned char) (ac[2] *255.0);
      nc = 1;
!     cc = 3;
    }
  
!   float *scales;
    vtkIdType ns = poly->GetPoints()->GetNumberOfPoints();
    if (this->ScaleArray != nullptr &&
        poly->GetPointData()->HasArray(this->ScaleArray))
    {
!     scales = static_cast<float*>(poly->GetPointData()->GetArray(this->ScaleArray)->GetVoidPointer(0));
      ns = numPts;
    }
    else
    {
!     scales = &this->Radius;
      ns = 1;
    }
  
!   // Iterate through all of the different types in the polydata, building OpenGLs
!   // and IBOs as appropriate for each type.
!   this->CreateVBO(
!     static_cast<float *>(poly->GetPoints()->GetVoidPointer(0)),
!     numPts,
!     c, cc, nc,
!     scales, ns,
!     ren);
  
    if (!this->Colors)
    {
      delete [] c;
    }
  
    // create the IBO
    this->Primitives[PrimitivePoints].IBO->IndexCount = 0;
--- 324,386 ----
    else
    {
      double *ac = act->GetProperty()->GetColor();
!     double opac = act->GetProperty()->GetOpacity();
!     c = new unsigned char[4];
      c[0] = (unsigned char) (ac[0] *255.0);
      c[1] = (unsigned char) (ac[1] *255.0);
      c[2] = (unsigned char) (ac[2] *255.0);
+     c[3] = (unsigned char) (opac  *255.0);
      nc = 1;
!     cc = 4;
    }
  
!   vtkDataArray *scales = NULL;
    vtkIdType ns = poly->GetPoints()->GetNumberOfPoints();
    if (this->ScaleArray != nullptr &&
        poly->GetPointData()->HasArray(this->ScaleArray))
    {
!     scales = poly->GetPointData()->GetArray(this->ScaleArray);
      ns = numPts;
    }
    else
    {
!     scales = vtkFloatArray::New();
!     scales->SetNumberOfTuples(1);
!     scales->SetTuple1(0, this->Radius);
      ns = 1;
    }
  
!   vtkFloatArray *verts = vtkFloatArray::New();
!   verts->SetNumberOfComponents(3);
!   verts->SetNumberOfTuples(numPts*3);
! 
!   vtkFloatArray *offsets = vtkFloatArray::New();
!   offsets->SetNumberOfComponents(2);
!   offsets->SetNumberOfTuples(numPts*3);
! 
!   vtkUnsignedCharArray *ucolors = vtkUnsignedCharArray::New();
!   ucolors->SetNumberOfComponents(4);
!   ucolors->SetNumberOfTuples(numPts*3);
! 
!   vtkOpenGLSphereMapper_PrepareVBO(pts->GetData(), c, cc, nc, scales, ns,
!                                    verts, offsets, ucolors);
! 
!   this->VBOs->CacheDataArray("vertexMC", verts, ren, VTK_FLOAT);
!   verts->Delete();
!   this->VBOs->CacheDataArray("offsetMC", offsets, ren, VTK_FLOAT);
!   offsets->Delete();
!   this->VBOs->CacheDataArray("scalarColor", ucolors, ren, VTK_UNSIGNED_CHAR);
!   ucolors->Delete();
!   this->VBOs->BuildAllVBOs(ren);
  
    if (!this->Colors)
    {
      delete [] c;
    }
+   if (ns != numPts)
+   {
+     scales->Delete();
+   }
  
    // create the IBO
    this->Primitives[PrimitivePoints].IBO->IndexCount = 0;
EOF

    if [[ $? != 0 ]] ; then
      warn "vtk patch for vtkOpenGLSphereMapper.cxx failed."
      return 1
    fi
    return 0;
}

function apply_vtkdatawriter_patch
{
  # patch vtk's vtkDataWriter to fix bug when writing binary vtkBitArray.

   patch -p0 << \EOF
*** IO/Legacy/vtkDataWriter.cxx.original 2018-01-19 13:52:19.000000000
--- IO/Legacy/vtkDataWriter.cxx 2018-01-19 13:52:49.000000000
***************
*** 1070,1082 ****
            }
          }
        }
        else
        {
          unsigned char *cptr=
!           static_cast<vtkUnsignedCharArray *>(data)->GetPointer(0);
          fp->write(reinterpret_cast<char *>(cptr),
                    (sizeof(unsigned char))*((num-1)/8+1));

        }
        *fp << "\n";
      }
--- 1070,1082 ----
            }
          }
        }
        else
        {
          unsigned char *cptr=
!           static_cast<vtkBitArray *>(data)->GetPointer(0);
          fp->write(reinterpret_cast<char *>(cptr),
                    (sizeof(unsigned char))*((num-1)/8+1));

        }
        *fp << "\n";
      }
EOF

    if [[ $? != 0 ]] ; then
      warn "vtk patch for vtkDataWriter failed."
      return 1
    fi
    return 0;
}

function apply_vtkospray_patches
{
	count_patches=3
    # patch vtkOSPRay files:

    # 1) expose vtkViewNodeFactory via vtkOSPRayPass
	current_patch=1
    patch -p0 << \EOF
*** Rendering/OSPRay/vtkOSPRayPass.h.original     2018-04-23 19:23:29.000000000 -0700
--- Rendering/OSPRay/vtkOSPRayPass.h  2018-04-30 21:31:49.911508591 -0700
***************
*** 48,53 ****
--- 48,54 ----
  class vtkRenderPassCollection;
  class vtkSequencePass;
  class vtkVolumetricPass;
+ class vtkViewNodeFactory;

  class VTKRENDERINGOSPRAY_EXPORT vtkOSPRayPass : public vtkRenderPass
  {
***************
*** 74,79 ****
--- 75,82 ----
     */
    virtual void RenderInternal(const vtkRenderState *s);

+   virtual vtkViewNodeFactory* GetViewNodeFactory();
+
   protected:
    /**
     * Default constructor.
*** Rendering/OSPRay/vtkOSPRayPass.cxx.original	2018-04-23 19:23:29.000000000 -0700
--- Rendering/OSPRay/vtkOSPRayPass.cxx	2018-04-30 21:31:49.907508611 -0700
***************
*** 273,275 ****
--- 273,280 ----
      }
    }
  }
+
+ vtkViewNodeFactory* vtkOSPRayPass::GetViewNodeFactory()
+ {
+   return this->Internal->Factory;
+ }
EOF
    if [[ $? != 0 ]] ; then
        warn "vtk patch ${current_patch}/${count_patches} for vtkOSPRayPass failed."
        return 1
    fi

	# 2) enable vtkOSPRayFollowerNode
	((current_patch++))
	patch -p0 << \EOF
*** Rendering/OSPRay/vtkOSPRayViewNodeFactory.cxx.original	2018-04-23 19:23:29.000000000 -0700
--- Rendering/OSPRay/vtkOSPRayViewNodeFactory.cxx	2018-05-07 19:43:23.902077745 -0700
***************
*** 19,24 ****
--- 19,25 ----
  #include "vtkOSPRayAMRVolumeMapperNode.h"
  #include "vtkOSPRayCameraNode.h"
  #include "vtkOSPRayCompositePolyDataMapper2Node.h"
+ #include "vtkOSPRayFollowerNode.h"
  #include "vtkOSPRayLightNode.h"
  #include "vtkOSPRayRendererNode.h"
  #include "vtkOSPRayPolyDataMapperNode.h"
***************
*** 44,49 ****
--- 45,56 ----
    return vn;
  }

+ vtkViewNode *fol_maker()
+ {
+   vtkOSPRayFollowerNode *vn = vtkOSPRayFollowerNode::New();
+   return vn;
+ }
+
  vtkViewNode *vol_maker()
  {
    return vtkOSPRayVolumeNode::New();
***************
*** 96,101 ****
--- 103,109 ----
    this->RegisterOverride("vtkOpenGLRenderer", ren_maker);
    this->RegisterOverride("vtkOpenGLActor", act_maker);
    this->RegisterOverride("vtkPVLODActor", act_maker);
+   this->RegisterOverride("vtkFollower", fol_maker);
    this->RegisterOverride("vtkPVLODVolume", vol_maker);
    this->RegisterOverride("vtkVolume", vol_maker);
    this->RegisterOverride("vtkOpenGLCamera", cam_maker);
*** Rendering/OSPRay/CMakeLists.txt.original	2018-04-23 19:23:28.000000000 -0700
--- Rendering/OSPRay/CMakeLists.txt	2018-04-23 21:07:41.269154859 -0700
***************
*** 7,12 ****
--- 7,13 ----
    vtkOSPRayVolumeNode.cxx
    vtkOSPRayCameraNode.cxx
    vtkOSPRayCompositePolyDataMapper2Node.cxx
+   vtkOSPRayFollowerNode.cxx
    vtkOSPRayLightNode.cxx
    vtkOSPRayMaterialHelpers.cxx
    vtkOSPRayMaterialLibrary.cxx
*** Rendering/OSPRay/vtkOSPRayFollowerNode.h.original	1969-12-31 16:00:00.000000000 -0800
--- Rendering/OSPRay/vtkOSPRayFollowerNode.h	2018-04-23 21:07:41.269154859 -0700
***************
*** 0 ****
--- 1,49 ----
+ /*=========================================================================
+
+   Program:   Visualization Toolkit
+   Module:    vtkOSPRayFollowerNode.h
+
+   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
+   All rights reserved.
+   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
+
+      This software is distributed WITHOUT ANY WARRANTY; without even
+      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+      PURPOSE.  See the above copyright notice for more information.
+
+ =========================================================================*/
+ /**
+  * @class   vtkOSPRayFollowerNode
+  * @brief   links vtkFollower to OSPRay
+  *
+  * Translates vtkFollower state into OSPRay rendering calls
+ */
+
+ #ifndef vtkOSPRayFollowerNode_h
+ #define vtkOSPRayFollowerNode_h
+
+ #include "vtkOSPRayActorNode.h"
+
+ class VTKRENDERINGOSPRAY_EXPORT vtkOSPRayFollowerNode :
+   public vtkOSPRayActorNode
+ {
+ public:
+   static vtkOSPRayFollowerNode* New();
+   vtkTypeMacro(vtkOSPRayFollowerNode, vtkOSPRayActorNode);
+   void PrintSelf(ostream& os, vtkIndent indent) override;
+
+   /**
+    * Overridden to take into account my renderables time, including
+    * its associated camera
+    */
+   virtual vtkMTimeType GetMTime() override;
+
+ protected:
+   vtkOSPRayFollowerNode();
+   ~vtkOSPRayFollowerNode();
+
+ private:
+   vtkOSPRayFollowerNode(const vtkOSPRayFollowerNode&) = delete;
+   void operator=(const vtkOSPRayFollowerNode&) = delete;
+ };
+ #endif
*** Rendering/OSPRay/vtkOSPRayFollowerNode.cxx.original	1969-12-31 16:00:00.000000000 -0800
--- Rendering/OSPRay/vtkOSPRayFollowerNode.cxx	2018-04-27 18:41:41.770557480 -0700
***************
*** 0 ****
--- 1,51 ----
+ /*=========================================================================
+
+   Program:   Visualization Toolkit
+   Module:    vtkOSPRayFollowerNode.cxx
+
+   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
+   All rights reserved.
+   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
+
+      This software is distributed WITHOUT ANY WARRANTY; without even
+      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+      PURPOSE.  See the above copyright notice for more information.
+
+ =========================================================================*/
+ #include "vtkOSPRayFollowerNode.h"
+ #include "vtkCamera.h"
+ #include "vtkFollower.h"
+ #include "vtkObjectFactory.h"
+
+ //============================================================================
+ vtkStandardNewMacro(vtkOSPRayFollowerNode);
+
+ //----------------------------------------------------------------------------
+ vtkOSPRayFollowerNode::vtkOSPRayFollowerNode()
+ {
+ }
+
+ //----------------------------------------------------------------------------
+ vtkOSPRayFollowerNode::~vtkOSPRayFollowerNode()
+ {
+ }
+
+ //----------------------------------------------------------------------------
+ void vtkOSPRayFollowerNode::PrintSelf(ostream& os, vtkIndent indent)
+ {
+   this->Superclass::PrintSelf(os, indent);
+ }
+
+ //----------------------------------------------------------------------------
+ vtkMTimeType vtkOSPRayFollowerNode::GetMTime()
+ {
+   vtkMTimeType mtime = this->Superclass::GetMTime();
+   vtkCamera *cam = ((vtkFollower*)this->GetRenderable())->GetCamera();
+
+   if (cam->GetMTime() > mtime)
+   {
+     mtime = cam->GetMTime();
+   }
+
+   return mtime;
+ }
*** Rendering/Core/vtkFollower.cxx.original	2017-12-22 10:33:25.000000000 -0600
--- Rendering/Core/vtkFollower.cxx	2018-06-14 13:35:08.481815058 -0500
***************
*** 156,161 ****
--- 156,165 ----
      this->Transform->GetMatrix(this->Matrix);
      this->MatrixMTime.Modified();
      this->Transform->Pop();
+
+     // if we get to here it's pretty safe to assume
+     // that our transform isn't an identity matrix
+     this->IsIdentity = 0;
    }
  }
EOF
    if [[ $? != 0 ]] ; then
        warn "vtk patch $current_patch/$count_patches for vtkOSPRayFollowerNode failed."
        return 1
    fi

	((current_patch++))
    patch -p0 << \EOF
*** Rendering/OSPRay/vtkOSPRayVolumeMapper.cxx.original	2018-04-23 15:32:58.538749914 -0400
--- Rendering/OSPRay/vtkOSPRayVolumeMapper.cxx	2018-04-23 15:34:58.399824907 -0400
***************
*** 72,77 ****
--- 72,79 ----
    {
      this->Init();
    }
+   vtkOSPRayRendererNode::SetSamplesPerPixel(vtkOSPRayRendererNode::GetSamplesPerPixel(ren), this->InternalRenderer);
+   vtkOSPRayRendererNode::SetAmbientSamples(vtkOSPRayRendererNode::GetAmbientSamples(ren), this->InternalRenderer);
    this->InternalRenderer->SetRenderWindow(ren->GetRenderWindow());
    this->InternalRenderer->SetActiveCamera(ren->GetActiveCamera());
    this->InternalRenderer->SetBackground(ren->GetBackground());
EOF
    if [[ $? != 0 ]] ; then
        warn "vtk patch $current_patch/$count_patches for vtkOSPRayVolumeMapper failed."
        return 1
    fi
}

function apply_vtkospraypolydatamappernode_patch
{
    # patch vtk's vtkOSPRayPolyDataMapperNode to handle vtkDataSets in
    # addition to vtkPolyData.

    patch -p0 << \EOF
diff -c Rendering/OSPRay/vtkOSPRayPolyDataMapperNode.h.original Rendering/OSPRay/vtkOSPRayPolyDataMapperNode.h
*** Rendering/OSPRay/vtkOSPRayPolyDataMapperNode.h.original     Fri Dec 22 08:33:25 2017
--- Rendering/OSPRay/vtkOSPRayPolyDataMapperNode.h      Fri Dec 28 15:56:33 2018
***************
*** 25,30 ****
--- 25,31 ----
  #include "vtkRenderingOSPRayModule.h" // For export macro
  #include "vtkPolyDataMapperNode.h"
  
+ class vtkDataSetSurfaceFilter;
  class vtkOSPRayActorNode;
  class vtkPolyData;
  
***************
*** 61,66 ****
--- 62,69 ----
    void CreateNewMeshes();
    void AddMeshesToModel(void *arg);
  
+   vtkDataSetSurfaceFilter *GeometryExtractor;
+ 
  private:
    vtkOSPRayPolyDataMapperNode(const vtkOSPRayPolyDataMapperNode&) = delete;
    void operator=(const vtkOSPRayPolyDataMapperNode&) = delete;
EOF

    if [[ $? != 0 ]] ; then
      warn "vtk patch for vtkOSPRayPolyDataMapperNode failed."
      return 1
    fi

    patch -p0 << \EOF
diff -c Rendering/OSPRay/vtkOSPRayPolyDataMapperNode.cxx.original Rendering/OSPRay/vtkOSPRayPolyDataMapperNode.cxx
*** Rendering/OSPRay/vtkOSPRayPolyDataMapperNode.cxx.original   Fri Dec 22 08:33:25 2017
--- Rendering/OSPRay/vtkOSPRayPolyDataMapperNode.cxx    Fri Dec 28 16:32:06 2018
***************
*** 19,24 ****
--- 19,25 ----
  #include "vtkOSPRayMaterialHelpers.h"
  #include "vtkOSPRayRendererNode.h"
  #include "vtkDataArray.h"
+ #include "vtkDataSetSurfaceFilter.h"
  #include "vtkFloatArray.h"
  #include "vtkImageData.h"
  #include "vtkInformation.h"
***************
*** 738,749 ****
--- 739,755 ----
  vtkOSPRayPolyDataMapperNode::vtkOSPRayPolyDataMapperNode()
  {
    this->OSPMeshes = nullptr;
+   this->GeometryExtractor = nullptr;
  }
  
  //----------------------------------------------------------------------------
  vtkOSPRayPolyDataMapperNode::~vtkOSPRayPolyDataMapperNode()
  {
    delete (vtkosp::MyGeom*)this->OSPMeshes;
+   if ( this->GeometryExtractor )
+   {
+     this->GeometryExtractor->Delete();
+   }
  }
  
  //----------------------------------------------------------------------------
***************
*** 1318,1324 ****
      vtkMapper *mapper = act->GetMapper();
      if (mapper)
      {
!       poly = (vtkPolyData*)(mapper->GetInput());
      }
      if (poly)
      {
--- 1324,1343 ----
      vtkMapper *mapper = act->GetMapper();
      if (mapper)
      {
!       if (mapper->GetInput()->GetDataObjectType() == VTK_POLY_DATA)
!       {
!         poly = (vtkPolyData*)(mapper->GetInput());
!       }
!       else
!       {
!         if (! this->GeometryExtractor)
!         {
!           this->GeometryExtractor = vtkDataSetSurfaceFilter::New();
!         }
!         this->GeometryExtractor->SetInputData(mapper->GetInput());
!         this->GeometryExtractor->Update();
!         poly = (vtkPolyData*)this->GeometryExtractor->GetOutput();
!       }
      }
      if (poly)
      {
EOF

    if [[ $? != 0 ]] ; then
      warn "vtk patch for vtkOSPRayPolyDataMapperNode failed."
      return 1
    fi

    return 0;
}


function apply_vtkospray_linking_patch
{
    # fix from kevin griffin
    # patch to vtk linking issue noticed on macOS
    patch -p0 << \EOF
    diff -c Rendering/OSPRay/CMakeLists.txt.orig  Rendering/OSPRay/CMakeLists.txt
    *** Rendering/OSPRay/CMakeLists.txt.orig	2019-05-21 15:15:50.000000000 -0700
    --- Rendering/OSPRay/CMakeLists.txt	2019-05-21 15:16:07.000000000 -0700
    ***************
    *** 37,42 ****
    --- 37,45 ----
      vtk_module_library(vtkRenderingOSPRay ${Module_SRCS})
  
      target_link_libraries(${vtk-module} LINK_PUBLIC ${OSPRAY_LIBRARIES})
    + # patch to solve linking issue noticed on macOS
    + target_link_libraries(${vtk-module} LINK_PUBLIC vtkFiltersGeometry)
    + 
  
      # OSPRay_Core uses MMTime which is in it's own special library.
      if(WIN32)
EOF

    if [[ $? != 0 ]] ; then
      warn "vtk patch for ospray linking failed."
      return 1
    fi

    return 0;
}



function apply_vtk_patch
{
    apply_vtkdatawriter_patch
    if [[ $? != 0 ]] ; then
       return 1
    fi

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

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

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

    # Note: don't guard ospray patches by if ospray is selected 
    # b/c subsequent calls to build_visit won't get a chance to patch
    # given the if test logic used above
    apply_vtkospraypolydatamappernode_patch
    if [[ $? != 0 ]] ; then
        return 1
    fi

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

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

    return 0
}

function build_vtk
{
    # 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 the build dir using src file.
    #
    prepare_build_dir $VTK_BUILD_DIR $VTK_FILE
    untarred_vtk=$?
    # 0, already exists, 1 untarred src, 2 error

    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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi

    # move back up to the start dir
    cd "$START_DIR"

    #
    # Configure VTK
    #
    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} -DVTK_LEGACY_REMOVE:BOOL=true"
    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=true"
    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
        elif test "${MACOSX_DEPLOYMENT_TARGET}" = "10.12"; then
            # If building on 10.12 (Sierra) check if we are building with Xcode 9 ...
            XCODE_VER=$(xcodebuild -version | head -n 1 | awk '{print $2}')
            if test ${XCODE_VER%.*} == 9; then
                # Workaround for Xcode 9 not having a 10.12 SDK: Prevent CMake from linking to 10.13 SDK
                # by using Frameworks installed in root directory.
                echo "Xcode 9 on MacOS 10.12 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"
    vopts="${vopts} -DVTK_Group_Web: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_vtkRenderingOpenGL2: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"
                vopts="${vopts} -DVTK_QT_VERSION=5"
                vopts="${vopts} -DCMAKE_PREFIX_PATH=${QT_INSTALL_DIR}/lib/cmake"
            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

    # Use Mesa as GL?
    if [[ "$DO_MESAGL" == "yes" ]] ; then
        vopts="${vopts} -DVTK_OPENGL_HAS_OSMESA:BOOL=ON"
        vopts="${vopts} -DOPENGL_INCLUDE_DIR:PATH=${MESAGL_INCLUDE_DIR}"
        vopts="${vopts} -DOPENGL_gl_LIBRARY:PATH=\"${MESAGL_OPENGL_LIB};${LLVM_LIB}\""
        vopts="${vopts} -DOPENGL_glu_LIBRARY:PATH=${MESAGL_GLU_LIB}"
        vopts="${vopts} -DOSMESA_LIBRARY:FILEPATH=\"${MESAGL_OSMESA_LIB};${LLVM_LIB}\""
        vopts="${vopts} -DOSMESA_INCLUDE_DIR:PATH=${MESAGL_INCLUDE_DIR}"

        if [[ "$DO_STATIC_BUILD" == "yes" ]] ; then
            if [[ "$DO_SERVER_COMPONENTS_ONLY" == "yes" || "$DO_ENGINE_ONLY" == "yes" ]] ; then
                vopts="${vopts} -DVTK_USE_X:BOOL=OFF"
            fi
        fi
    fi

    # Use OSPRay?
    if [[ "$DO_OSPRAY" == "yes" ]] ; then
        vopts="${vopts} -DModule_vtkRenderingOSPRay:BOOL=ON"
        vopts="${vopts} -DOSPRAY_INSTALL_DIR=${OSPRAY_INSTALL_DIR}"
        vopts="${vopts} -Dembree_DIR=${EMBREE_INSTALL_DIR}"
    fi

    # zlib support, use the one we build
    vopts="${vopts} -DVTK_USE_SYSTEM_ZLIB:BOOL=ON"
    vopts="${vopts} -DZLIB_INCLUDE_DIR:PATH=${ZLIB_INCLUDE_DIR}"
    if [[ "$VISIT_BUILD_MODE" == "Release" ]] ; then
        vopts="${vopts} -DZLIB_LIBRARY_RELEASE:FILEPATH=${ZLIB_LIBRARY}"
    else
        vopts="${vopts} -DZLIB_LIBRARY_DEBUG:FILEPATH=${ZLIB_LIBRARY}"
    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_vtkh_initialize
{
    export DO_VTKH="no"
}

function bv_vtkh_enable
{
    DO_VTKH="yes"
}

function bv_vtkh_disable
{
    DO_VTKH="no"
}

function bv_vtkh_depends_on
{
    depends_on="vtkm"

    echo ${depends_on}
}

function bv_vtkh_initialize_vars
{
    VTKH_INSTALL_DIR="\${VISITHOME}/vtkh/$VTKH_VERSION/\${VISITARCH}"
}

function bv_vtkh_info
{
    export VTKH_VERSION=${VTKH_VERSION:-"2ce3fa"}
    export VTKH_FILE=${VTKH_FILE:-"vtkh-${VTKH_VERSION}.tar.gz"}
    export VTKH_BUILD_DIR=${VTKH_BUILD_DIR:-"vtkh-${VTKH_VERSION}"}
    export VTKH_MD5_CHECKSUM="993cbd4b7a1bc5d5c0e9ff900ec2eacc"
    export VTKH_SHA256_CHECKSUM="ad3ed46ba9f435d367572bc3015ce0c546800b5cdf470dd494f1584142f48dbc"
}

function bv_vtkh_print
{
    printf "%s%s\n" "VTKH_FILE=" "${VTKH_FILE}"
    printf "%s%s\n" "VTKH_VERSION=" "${VTKH_VERSION}"
    printf "%s%s\n" "VTKH_BUILD_DIR=" "${VTKH_BUILD_DIR}"
}

function bv_vtkh_print_usage
{
    printf "%-20s %s [%s]\n" "--vtkh" "Build VTKh support" "$DO_VTKH"
}

function bv_vtkh_host_profile
{
    if [[ "$DO_VTKH" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## VTKH" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
            "VISIT_OPTION_DEFAULT(VISIT_VTKH_DIR ${VTKH_INSTALL_DIR})" \
            >> $HOSTCONF
    fi
}

function bv_vtkh_ensure
{
    if [[ "$DO_VTKH" == "yes" ]] ; then
        ensure_built_or_ready "vtk-h" $VTKH_VERSION $VTKH_BUILD_DIR $VTKH_FILE $VTKH_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_VTKH="no"
            error "Unable to build VTKh. ${VTKH_FILE} not found."
        fi
    fi
}

function bv_vtkh_dry_run
{
    if [[ "$DO_VTKH" == "yes" ]] ; then
        echo "Dry run option not set for VTKh"
    fi
}

# *************************************************************************** #
#                            Function 8, build_vtkh
#
#
# *************************************************************************** #

function apply_vtkh_patch
{
    info "Patching VTKh . . ."

    return 0
}

function build_vtkh
{
    #
    # Extract the sources
    #
    if [[ -d $VTKH_BUILD_DIR ]] ; then
        if [[ ! -f $VTKH_FILE ]] ; then
            warn "The directory VTKH exists, deleting before uncompressing"
            rm -Rf $VTKH_BUILD_DIR
            ensure_built_or_ready $VTKH_INSTALL_DIR $VTKH_VERSION $VTKH_BUILD_DIR $VTKH_FILE
        fi
    fi

    #
    # Prepare build dir
    #
    prepare_build_dir $VTKH_BUILD_DIR $VTKH_FILE
    untarred_vtkh=$?
    # 0, already exists, 1 untarred src, 2 error

    if [[ $untarred_vtkh == -1 ]] ; then
        warn "Unable to prepare VTKh build directory. Giving Up!"
        return 1
    fi
    
    #
    # Apply patches
    #
    cd $VTKH_BUILD_DIR || error "Can't cd to VTKh build dir."
    apply_vtkh_patch
    if [[ $? != 0 ]] ; then
        if [[ $untarred_vtkh == 1 ]] ; then
            warn "Giving up on VTKh 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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi
    # move back up to the start dir
    cd "$START_DIR"

    #
    # Configure VTKH
    #
    info "Configuring VTKh . . ."
    
    CMAKE_BIN="${CMAKE_INSTALL}/cmake"

    # Make a build directory for an out-of-source build.. Change the
    # VTKH_BUILD_DIR variable to represent the out-of-source build directory.
    VTKH_SRC_DIR=$VTKH_BUILD_DIR
    VTKH_BUILD_DIR="${VTKH_SRC_DIR}-build"
    if [[ ! -d $VTKH_BUILD_DIR ]] ; then
        echo "Making build directory $VTKH_BUILD_DIR"
        mkdir $VTKH_BUILD_DIR
    fi

    cd $VTKH_BUILD_DIR || error "Can't cd to VTKh build dir."

    vopts=""
    vopts="${vopts} -DCMAKE_INSTALL_PREFIX:PATH=${VISITDIR}/vtkh/${VTKH_VERSION}/${VISITARCH}"
    vopts="${vopts} -DVTKM_DIR=${VISITDIR}/vtkm/${VTKM_VERSION}/${VISITARCH}"
    vopts="${vopts} -DBUILD_SHARED_LIBS=ON"
    vopts="${vopts} -DENABLE_MPI=OFF"
    vopts="${vopts} -DENABLE_OPENMP=OFF"
    vopts="${vopts} -DCMAKE_BUILD_TYPE=Release"
    if [[ -d $CUDA_HOME ]]; then
        echo "Building with CUDA support."
        vopts="${vopts} -DENABLE_CUDA=ON"
    fi

    #
    # 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} ../${VTKH_SRC_DIR}/src > bv_run_cmake.sh
    cat bv_run_cmake.sh
    issue_command bash bv_run_cmake.sh || error "VTKh configuration failed."

    #
    # Build vtkh
    #
    info "Building VTKh . . . (~2 minutes)"
    $MAKE $MAKE_OPT_FLAGS || error "VTKh did not build correctly. Giving up."

    info "Installing VTKh . . . (~2 minutes)"
    $MAKE install || error "VTKh did not install correctly."

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

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

function bv_vtkh_is_installed
{
    check_if_installed "vtkh" $VTKH_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_vtkh_build
{
    cd "$START_DIR"
    if [[ "$DO_VTKH" == "yes" ]] ; then
        check_if_installed "vtkh" $VTKH_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping VTKh build. VTKh is already installed."
        else
            info "Building VTKh (~2 minutes)"
            build_vtkh
            if [[ $? != 0 ]] ; then
                error "Unable to build or install VTKh.  Bailing out."
            fi
            info "Done building VTKh"
        fi
    fi
}
function bv_vtkm_initialize
{
    export DO_VTKM="no"
    export USE_SYSTEM_VTKM="no"
    add_extra_commandline_args "vtkm" "alt-vtkm-dir" 1 "Use alternative directory for VTKm"
}

function bv_vtkm_enable
{
    DO_VTKM="yes"
}

function bv_vtkm_disable
{
    DO_VTKM="no"
}

function bv_vtkm_alt_vtkm_dir
{
    bv_vtkm_enable
    USE_SYSTEM_VTKM="yes"
    VTKM_INSTALL_DIR="$1"
    info "Using Alternate VTKM: $SYSTEM_VTKM_DIR"
}

function bv_vtkm_depends_on
{
    depends_on="cmake"

    echo ${depends_on}
}

function bv_vtkm_initialize_vars
{
    if [[ "$USE_SYSTEM_VTKM" == "no" ]]; then
        VTKM_INSTALL_DIR="\${VISITHOME}/vtkm/$VTKM_VERSION/\${VISITARCH}"
    fi
}

function bv_vtkm_info
{
    export VTKM_VERSION=${VTKM_VERSION:-"0d141c"}
    export VTKM_FILE=${VTKM_FILE:-"vtkm-${VTKM_VERSION}.tar.gz"}
    export VTKM_BUILD_DIR=${VTKM_BUILD_DIR:-"vtkm-${VTKM_VERSION}"}
    export VTKM_MD5_CHECKSUM="72f862af47da3578370734f3ba0a4c59"
    export VTKM_SHA256_CHECKSUM="965b6bb7a1a579b8494523b993f060b6bc461a5dc0296b8ad6033ff10916628f"
}

function bv_vtkm_print
{
    printf "%s%s\n" "VTKM_FILE=" "${VTKM_FILE}"
    printf "%s%s\n" "VTKM_VERSION=" "${VTKM_VERSION}"
    printf "%s%s\n" "VTKM_BUILD_DIR=" "${VTKM_BUILD_DIR}"
}

function bv_vtkm_print_usage
{
    printf "%-20s %s [%s]\n" "--vtkm" "Build VTKm support" "$DO_VTKM"
    printf "%-20s %s [%s]\n" "--alt-vtkm-dir" "Use VTKm from an alternative directory"
}

function bv_vtkm_host_profile
{
    if [[ "$DO_VTKM" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## VTKM" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
            "VISIT_OPTION_DEFAULT(VISIT_VTKM_DIR ${VTKM_INSTALL_DIR})" \
            >> $HOSTCONF
    fi
}

function bv_vtkm_ensure
{
    if [[ "$DO_VTKM" == "yes" && "$USE_SYSTEM_VTKM" == "no" ]] ; then
        ensure_built_or_ready "vtk-m" $VTKM_VERSION $VTKM_BUILD_DIR $VTKM_FILE $VTKM_URL
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_VTKM="no"
            error "Unable to build VTKm. ${VTKM_FILE} not found."
        fi
    fi
}

function bv_vtkm_dry_run
{
    if [[ "$DO_VTKM" == "yes" ]] ; then
        echo "Dry run option not set for VTKm"
    fi
}

# *************************************************************************** #
#                            Function 8, build_vtkm
#
#
# *************************************************************************** #

function apply_patch_1
{
   patch -p0 << \EOF
diff -c ./vtkm/TypeListTag.h.orig ./vtkm/TypeListTag.h
*** ./vtkm/TypeListTag.h.orig	Tue Nov  6 16:17:57 2018
--- ./vtkm/TypeListTag.h	Tue Nov  6 16:15:29 2018
***************
*** 204,210 ****
  /// A list of the most commonly used types across multiple domains. Includes
  /// integers, floating points, and 3 dimensional vectors of floating points.
  ///
! struct TypeListTagCommon : vtkm::ListTagBase<vtkm::Int32,
                                               vtkm::Int64,
                                               vtkm::Float32,
                                               vtkm::Float64,
--- 204,211 ----
  /// A list of the most commonly used types across multiple domains. Includes
  /// integers, floating points, and 3 dimensional vectors of floating points.
  ///
! struct TypeListTagCommon : vtkm::ListTagBase<vtkm::UInt8,
!                                              vtkm::Int32,
                                               vtkm::Int64,
                                               vtkm::Float32,
                                               vtkm::Float64,
EOF

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

function apply_patch_2
{
   patch -p0 << \EOF
diff -c ./vtkm/cont/arg/TransportTagTopologyFieldIn.h.orig ./vtkm/cont/arg/TransportTagTopologyFieldIn.h
*** ./vtkm/cont/arg/TransportTagTopologyFieldIn.h.orig	Tue Nov  6 16:18:09 2018
--- ./vtkm/cont/arg/TransportTagTopologyFieldIn.h	Tue Nov  6 16:16:18 2018
***************
*** 98,104 ****
--- 98,106 ----
    {
      if (object.GetNumberOfValues() != detail::TopologyDomainSize(inputDomain, TopologyElementTag()))
      {
+ #if 0
        throw vtkm::cont::ErrorBadValue("Input array to worklet invocation the wrong size.");
+ #endif
      }
  
      return object.PrepareForInput(Device());
EOF

    if [[ $? != 0 ]] ; then
      warn "vtkm patch 2 failed."
      return 1
    fi
    return 0;
}

function apply_vtkm_patch
{
    info "Patching VTKm . . ."

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

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

    return 0
}

function build_vtkm
{
    #
    # Extract the sources
    #
    if [[ -d $VTKM_BUILD_DIR ]] ; then
        if [[ ! -f $VTKM_FILE ]] ; then
            warn "The directory VTKM exists, deleting before uncompressing"
            rm -Rf $VTKM_BUILD_DIR
            ensure_built_or_ready $VTKM_INSTALL_DIR $VTKM_VERSION $VTKM_BUILD_DIR $VTKM_FILE
        fi
    fi

    #
    # Prepare build dir
    #
    prepare_build_dir $VTKM_BUILD_DIR $VTKM_FILE
    untarred_vtkm=$?
    # 0, already exists, 1 untarred src, 2 error

    if [[ $untarred_vtkm == -1 ]] ; then
        warn "Unable to prepare VTKm build directory. Giving Up!"
        return 1
    fi
    
    #
    # Apply patches
    #
    cd $VTKM_BUILD_DIR || error "Can't cd to VTKm build dir."
    apply_vtkm_patch
    if [[ $? != 0 ]] ; then
        if [[ $untarred_vtkm == 1 ]] ; then
            warn "Giving up on VTKm 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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi
    # move back up to the start dir
    cd "$START_DIR"

    #
    # Configure VTKM
    #
    info "Configuring VTKm . . ."
    
    CMAKE_BIN="${CMAKE_INSTALL}/cmake"

    # Make a build directory for an out-of-source build.. Change the
    # VTKM_BUILD_DIR variable to represent the out-of-source build directory.
    VTKM_SRC_DIR=$VTKM_BUILD_DIR
    VTKM_BUILD_DIR="${VTKM_SRC_DIR}-build"
    if [[ ! -d $VTKM_BUILD_DIR ]] ; then
        echo "Making build directory $VTKM_BUILD_DIR"
        mkdir $VTKM_BUILD_DIR
    fi

    cd $VTKM_BUILD_DIR || error "Can't cd to VTKm build dir."

    vopts=""
    vopts="${vopts} -DCMAKE_INSTALL_PREFIX:PATH=${VISITDIR}/vtkm/${VTKM_VERSION}/${VISITARCH}"
    vopts="${vopts} -DVTKm_ENABLE_TESTING:BOOL=OFF"
    vopts="${vopts} -DVTKm_ENABLE_RENDERING:BOOL=ON"
    vopts="${vopts} -DVTKm_USE_64BIT_IDS:BOOL=OFF"
    vopts="${vopts} -DVTKm_USE_DOUBLE_PRECISION:BOOL=ON"
    vopts="${vopts} -DCMAKE_BUILD_TYPE:STRING=Release"
    if [[ -d $CUDA_HOME ]]; then
        echo "Building with CUDA support."
        vopts="${vopts} -DVTKm_ENABLE_CUDA:BOOL=ON"
        vopts="${vopts} -DVTKm_CUDA_Architecture=kepler"
    fi

    #
    # 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} ../${VTKM_SRC_DIR} > bv_run_cmake.sh
    cat bv_run_cmake.sh
    issue_command bash bv_run_cmake.sh || error "VTKm configuration failed."

    #
    # Build vtkm
    #
    info "Building VTKm . . . (~2 minutes)"
    $MAKE $MAKE_OPT_FLAGS || error "VTKm did not build correctly. Giving up."

    info "Installing VTKm . . . (~2 minutes)"
    $MAKE install || error "VTKm did not install correctly."

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

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

function bv_vtkm_is_installed
{
    if [[ "$USE_SYSTEM_VTKM" == "yes" ]]; then
        return 1
    fi

    check_if_installed "vtkm" $VTKM_VERSION
    if [[ $? == 0 ]] ; then
        return 1
    fi
    return 0
}

function bv_vtkm_build
{
    cd "$START_DIR"
    if [[ "$DO_VTKM" == "yes" && "$USE_SYSTEM_VTKM" == "no" ]] ; then
        check_if_installed "vtkm" $VTKM_VERSION
        if [[ $? == 0 ]] ; then
            info "Skipping VTKm build. VTKm is already installed."
        else
            info "Building VTKm (~2 minutes)"
            build_vtkm
            if [[ $? != 0 ]] ; then
                error "Unable to build or install VTKm.  Bailing out."
            fi
            info "Done building VTKm"
        fi
    fi
}
function bv_xdmf_initialize
{
    export DO_XDMF="no"
}

function bv_xdmf_enable
{
    DO_XDMF="yes"

    #xdmf is dependent on HDF5
    DO_HDF5="yes"
}

function bv_xdmf_disable
{
    DO_XDMF="no"
}

function bv_xdmf_depends_on
{
    echo "cmake vtk hdf5 zlib"
}

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="4f0c2011d1d6f86052b102b25b36276168a31e191b4206a8d0c9d716ebced7e1"
}

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 "%-20s %s [%s]\n" "--xdmf" "Build Xdmf" "$DO_XDMF"
}

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 apply_xdmf_patch
{
   patch -p0 << \EOF
diff -c a/libsrc/FXdmfValuesBinary.cxx Xdmf/libsrc/XdmfValuesBinary.cxx
*** a/libsrc/XdmfValuesBinary.cxx
--- Xdmf/libsrc/XdmfValuesBinary.cxx
***************
*** 282,288 ****
      }
      FullFileName << DataSetName << ends;
      char * path = FullFileName.rdbuf()->str();
!     XdmfDebug("Opening Binary Data for Reading : " << FullFileName);
  
  
      //char * path = new char [ strlen(this->DOM->GetWorkingDirectory())+strlen(DataSetName) + 1 ];
--- 282,288 ----
      }
      FullFileName << DataSetName << ends;
      char * path = FullFileName.rdbuf()->str();
!     XdmfDebug("Opening Binary Data for Reading : " << path);
  
  
      //char * path = new char [ strlen(this->DOM->GetWorkingDirectory())+strlen(DataSetName) + 1 ];
EOF
    if [[ $? != 0 ]] ; then
        warn "boxlib patch failed."
        return 1
    fi

    return 0;

}

function apply_xdmf_osx_patch
{
    info "Patching Xdmf 2.1.1 for Xcode 9 . . ."
    patch -p0 << \EOF
diff -c Xdmf/libsrc/orig/XdmfDsmComm.cxx Xdmf/libsrc/XdmfDsmComm.cxx 
*** Xdmf/libsrc/orig/XdmfDsmComm.cxx	Thu Aug 23 22:05:42 2018
--- Xdmf/libsrc/XdmfDsmComm.cxx	Thu Aug 23 21:27:43 2018
***************
*** 50,56 ****
          XdmfErrorMessage("Cannot Receive Message of Length = " << Msg->Length);
          return(XDMF_FAIL);
      }
!     if(Msg->Data <= 0 ){
          XdmfErrorMessage("Cannot Receive Message into Data Buffer = " << Msg->Length);
          return(XDMF_FAIL);
      }
--- 50,56 ----
          XdmfErrorMessage("Cannot Receive Message of Length = " << Msg->Length);
          return(XDMF_FAIL);
      }
!     if(Msg->Data == (void *) NULL ){
          XdmfErrorMessage("Cannot Receive Message into Data Buffer = " << Msg->Length);
          return(XDMF_FAIL);
      }
***************
*** 64,70 ****
          XdmfErrorMessage("Cannot Send Message of Length = " << Msg->Length);
          return(XDMF_FAIL);
      }
!     if(Msg->Data <= 0 ){
          XdmfErrorMessage("Cannot Send Message from Data Buffer = " << Msg->Length);
          return(XDMF_FAIL);
      }
--- 64,70 ----
          XdmfErrorMessage("Cannot Send Message of Length = " << Msg->Length);
          return(XDMF_FAIL);
      }
!     if(Msg->Data == (void *) NULL ){
          XdmfErrorMessage("Cannot Send Message from Data Buffer = " << Msg->Length);
          return(XDMF_FAIL);
      }
EOF
    if [[ $? != 0 ]] ; then
        warn "Xdmf 2.1.1 Xcode 9 patch failed."
        return 1
    fi

    return 0;
}

function apply_xdmf1_patch
{
    if [[ ${XDMF_VERSION} == 2.1.1 ]] ; then
        if [[ "$OPSYS" == "Darwin" ]] ; then
                XCODE_VERSION="$(/usr/bin/xcodebuild -version)"
                if [[ "$XCODE_VERSION" == "Xcode 9"* ]] ; then
                    apply_xdmf_osx_patch
                fi
        fi
    fi
}

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

    #
    # Apply patches
    #
    info "Patching Xdmf . . ."
    apply_xdmf_patch
    apply_xdmf1_patch
    if [[ $? != 0 ]] ; then
        if [[ $untarred_xdmf == 1 ]] ; then
            warn "Giving up on Xdmf 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 that had\n" \
                 "already been patched ... that is, the patch is\n" \
                 "failing harmlessly on a second application."
        fi
    fi

    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:FILEPATH="$VISITDIR/hdf5/$HDF5_VERSION/$VISITARCH/lib/libhdf5.${SO_EXT}" \
                 -DXDMF_SYSTEM_ZLIB:BOOL=ON \
                 -DZLIB_INCLUDE_DIR:PATH=${ZLIB_INCLUDE_DIR} \
                 -DZLIB_LIBRARY:FILEPATH=${ZLIB_LIBRARY} \
                 -DXDMF_SYSTEM_LIBXML2:BOOL=ON \
                 -DLIBXML2_INCLUDE_PATH:PATH="$VISITDIR/${VTK_INSTALL_DIR}/$VTK_VERSION/$VISITARCH/include/vtk-${VTK_SHORT_VERSION}/vtklibxml2" \
                 -DLIBXML2_LIBRARY:FILEPATH="$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"
}

function bv_xercesc_enable
{
    DO_XERCESC="yes"
}

function bv_xercesc_disable
{
    DO_XERCESC="no"
}

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://archive.apache.org/dist/xerces/c/3/sources"}
    export XERCESC_MD5_CHECKSUM="9eb1048939e88d6a7232c67569b23985"
    export XERCESC_SHA256_CHECKSUM="743bd0a029bf8de56a587c270d97031e0099fe2b7142cef03e0da16e282655a0"
}

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}"
}

function bv_xercesc_print_usage
{
    printf "%-20s %s [%s]\n" "--xercesc"   "Build XERCESC" "$DO_XERCESC"
}

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"
}

function bv_xsd_enable
{ 
    DO_XSD="yes"
}

function bv_xsd_disable
{
    DO_XSD="no"
}

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_MD5_CHECKSUM="ae64d7fcd258addc9b045fe3f96208bb"
    export XSD_SHA256_CHECKSUM="eca52a9c8f52cdbe2ae4e364e4a909503493a0d51ea388fc6c9734565a859817"
}

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 "%-20s %s [%s]\n" "--xsd"   "Build XSD" "$DO_XSD"
}

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="yes"
}

function bv_zlib_enable
{
    DO_ZLIB="yes"
}

function bv_zlib_disable
{
    DO_ZLIB="no"
}

function bv_zlib_depends_on
{
    local depends_on=""

    echo $depends_on
}

function bv_zlib_info
{
    export ZLIB_VERSION=${ZLIB_VERSION:-"1.2.11"}
    export ZLIB_FILE=${ZLIB_FILE:-"zlib-${ZLIB_VERSION}.tar.xz"}
    export ZLIB_COMPATIBILITY_VERSION=${ZLIB_COMPATIBILITY_VERSION:-"1.2"}
    export ZLIB_URL=${ZLIB_URL:-https://www.zlib.net}
    export ZLIB_BUILD_DIR=${ZLIB_BUILD_DIR:-"zlib-${ZLIB_VERSION}"}
    export ZLIB_MD5_CHECKSUM="85adef240c5f370b308da8c938951a68"
    export ZLIB_SHA256_CHECKSUM="4ff941449631ace0d4d203e3483be9dbc9da454084111f97ea0a2114e19bf066"
}

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 "%-20s %s [%s]\n" "--zlib" "Build ZLIB support" "$DO_ZLIB"
}

function bv_zlib_host_profile
{
    echo >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "## ZLIB" >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "SETUP_APP_VERSION(ZLIB $ZLIB_VERSION)" >> $HOSTCONF
    echo \
        "VISIT_OPTION_DEFAULT(VISIT_ZLIB_DIR \${VISITHOME}/zlib/\${ZLIB_VERSION}/\${VISITARCH})" \
        >> $HOSTCONF
}

function bv_zlib_initialize_vars
{
    export VISIT_ZLIB_DIR=${VISIT_ZLIB_DIR:-"$VISITDIR/zlib/${ZLIB_VERSION}/${VISITARCH}"}
    export ZLIB_LIBRARY_DIR="${VISIT_ZLIB_DIR}/lib"
    export ZLIB_INCLUDE_DIR="${VISIT_ZLIB_DIR}/include"
    export ZLIB_LIBRARY="${ZLIB_LIBRARY_DIR}/libz.${SO_EXT}"
}

function bv_zlib_ensure
{
    ensure_built_or_ready "zlib" $ZLIB_VERSION $ZLIB_BUILD_DIR $ZLIB_FILE $ZLIB_URL
    if [[ $? != 0 ]] ; then
        ANY_ERRORS="yes"
        error "Unable to build ZLIB.  ${ZLIB_FILE} not found."
    fi
}

function bv_zlib_dry_run
{
    echo "Dry run option not set for zlib."
}

# *************************************************************************** #
#                            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"
    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
}
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=\"openssl\"/>"
xmlp_filecontents[5]="<lib name=\"python\"/>"
xmlp_filecontents[6]="<lib name=\"vtk\"/>"
xmlp_filecontents[7]="<lib name=\"qt\"/>"
xmlp_filecontents[8]="<lib name=\"qwt\"/>"
xmlp_filecontents[9]="<lib name=\"zlib\"/>"
xmlp_filecontents[10]="</required>"
xmlp_filecontents[11]="<optional>"
xmlp_filecontents[12]="<lib name=\"adios\"/>"
xmlp_filecontents[13]="<lib name=\"adios2\"/>"
xmlp_filecontents[14]="<lib name=\"advio\"/>"
xmlp_filecontents[15]="<lib name=\"boost\"/>"
xmlp_filecontents[16]="<lib name=\"boxlib\"/>"
xmlp_filecontents[17]="<lib name=\"cfitsio\"/>"
xmlp_filecontents[18]="<lib name=\"cgns\"/>"
xmlp_filecontents[19]="<lib name=\"conduit\"/>"
xmlp_filecontents[20]="<lib name=\"embree\"/>"
xmlp_filecontents[21]="<lib name=\"fastbit\"/>"
xmlp_filecontents[22]="<lib name=\"fastquery\"/>"
xmlp_filecontents[23]="<lib name=\"gdal\"/>"
xmlp_filecontents[24]="<lib name=\"glu\"/>"
xmlp_filecontents[25]="<lib name=\"h5part\"/>"
xmlp_filecontents[26]="<lib name=\"hdf4\"/>"
xmlp_filecontents[27]="<lib name=\"hdf5\"/>"
xmlp_filecontents[28]="<lib name=\"icet\"/>"
xmlp_filecontents[29]="<lib name=\"ispc\"/>"
xmlp_filecontents[30]="<lib name=\"llvm\"/>"
xmlp_filecontents[31]="<lib name=\"mdsplus\"/>"
xmlp_filecontents[32]="<lib name=\"mesagl\"/>"
xmlp_filecontents[33]="<lib name=\"mfem\"/>"
xmlp_filecontents[34]="<lib name=\"mili\"/>"
xmlp_filecontents[35]="<lib name=\"moab\"/>"
xmlp_filecontents[36]="<lib name=\"mpich\"/>"
xmlp_filecontents[37]="<lib name=\"mxml\"/>"
xmlp_filecontents[38]="<lib name=\"nektarpp\"/>"
xmlp_filecontents[39]="<lib name=\"netcdf\"/>"
xmlp_filecontents[40]="<lib name=\"openexr\"/>"
xmlp_filecontents[41]="<lib name=\"osmesa\"/>"
xmlp_filecontents[42]="<lib name=\"ospray\"/>"
xmlp_filecontents[43]="<lib name=\"p7zip\"/>"
xmlp_filecontents[44]="<lib name=\"pidx\"/>"
xmlp_filecontents[45]="<lib name=\"silo\"/>"
xmlp_filecontents[46]="<lib name=\"szip\"/>"
xmlp_filecontents[47]="<lib name=\"tbb\"/>"
xmlp_filecontents[48]="<lib name=\"tcmalloc\"/>"
xmlp_filecontents[49]="<lib name=\"uintah\"/>"
xmlp_filecontents[50]="<lib name=\"vtkm\"/>"
xmlp_filecontents[51]="<lib name=\"vtkh\"/>"
xmlp_filecontents[52]="<lib name=\"xdmf\"/>"
xmlp_filecontents[53]="</optional>"
xmlp_filecontents[54]="<group name=\"required\" comment=\"All required libraries\" enabled=\"yes\">"
xmlp_filecontents[55]="<lib name=\"cmake\"/>"
xmlp_filecontents[56]="<lib name=\"openssl\"/>"
xmlp_filecontents[57]="<lib name=\"python\"/>"
xmlp_filecontents[58]="<lib name=\"vtk\"/>"
xmlp_filecontents[59]="<lib name=\"qt\"/>"
xmlp_filecontents[60]="<lib name=\"qwt\"/>"
xmlp_filecontents[61]="<lib name=\"zlib\"/>"
xmlp_filecontents[62]="</group>"
xmlp_filecontents[63]="<group name=\"optional\" comment=\"All optional libraries\" enabled=\"no\">"
xmlp_filecontents[64]="<lib name=\"adios\"/>"
xmlp_filecontents[65]="<lib name=\"adios2\"/>"
xmlp_filecontents[66]="<lib name=\"advio\"/>"
xmlp_filecontents[67]="<lib name=\"boost\"/>"
xmlp_filecontents[68]="<lib name=\"boxlib\"/>"
xmlp_filecontents[69]="<lib name=\"cfitsio\"/>"
xmlp_filecontents[70]="<lib name=\"cgns\"/>"
xmlp_filecontents[71]="<lib name=\"conduit\"/>"
xmlp_filecontents[72]="<lib name=\"embree\"/>"
xmlp_filecontents[73]="<lib name=\"gdal\"/>"
xmlp_filecontents[74]="<lib name=\"glu\"/>"
xmlp_filecontents[75]="<lib name=\"h5part\"/>"
xmlp_filecontents[76]="<lib name=\"hdf4\"/>"
xmlp_filecontents[77]="<lib name=\"hdf5\"/>"
xmlp_filecontents[78]="<lib name=\"icet\"/>"
xmlp_filecontents[79]="<lib name=\"ispc\"/>"
xmlp_filecontents[80]="<lib name=\"llvm\"/>"
xmlp_filecontents[81]="<lib name=\"mfem\"/>"
xmlp_filecontents[82]="<lib name=\"mili\"/>"
xmlp_filecontents[83]="<lib name=\"moab\"/>"
xmlp_filecontents[84]="<lib name=\"mxml\"/>"
xmlp_filecontents[85]="<lib name=\"netcdf\"/>"
xmlp_filecontents[86]="<lib name=\"openexr\"/>"
xmlp_filecontents[87]="<lib name=\"ospray\"/>"
xmlp_filecontents[88]="<lib name=\"p7zip\"/>"
xmlp_filecontents[89]="<lib name=\"pidx\"/>"
xmlp_filecontents[90]="<lib name=\"silo\"/>"
xmlp_filecontents[91]="<lib name=\"szip\"/>"
xmlp_filecontents[92]="<lib name=\"tbb\"/>"
xmlp_filecontents[93]="<lib name=\"vtkm\"/>"
xmlp_filecontents[94]="<lib name=\"vtkh\"/>"
xmlp_filecontents[95]="<lib name=\"xdmf\"/>"
xmlp_filecontents[96]="</group>"
xmlp_filecontents[97]="<group name=\"no-thirdparty\" comment=\"Do not build required 3rd party libraries\" enabled=\"no\">"
xmlp_filecontents[98]="<lib name=\"no-cmake\"/>"
xmlp_filecontents[99]="<lib name=\"no-openssl\"/>"
xmlp_filecontents[100]="<lib name=\"no-python\"/>"
xmlp_filecontents[101]="<lib name=\"no-qt\" />"
xmlp_filecontents[102]="<lib name=\"no-qwt\" />"
xmlp_filecontents[103]="<lib name=\"no-vtk\"/>"
xmlp_filecontents[104]="<lib name=\"no-zlib\"/>"
xmlp_filecontents[105]="</group>"
xmlp_filecontents[106]="<group name=\"all-io\" comment=\"Build all available I/O libraries\" enabled=\"no\">"
xmlp_filecontents[107]="<lib name=\"adios\"/>"
xmlp_filecontents[108]="<lib name=\"adios2\"/>"
xmlp_filecontents[109]="<lib name=\"boost\"/>"
xmlp_filecontents[110]="<lib name=\"boxlib\"/>"
xmlp_filecontents[111]="<lib name=\"cfitsio\"/>"
xmlp_filecontents[112]="<lib name=\"conduit\"/>"
xmlp_filecontents[113]="<lib name=\"mfem\"/>"
xmlp_filecontents[114]="<lib name=\"cgns\"/>"
xmlp_filecontents[115]="<lib name=\"fastbit\"/>"
xmlp_filecontents[116]="<lib name=\"fastquery\"/>"
xmlp_filecontents[117]="<lib name=\"gdal\"/>"
xmlp_filecontents[118]="<lib name=\"h5part\"/>"
xmlp_filecontents[119]="<lib name=\"hdf5\"/>"
xmlp_filecontents[120]="<lib name=\"mxml\"/>"
xmlp_filecontents[121]="<lib name=\"netcdf\"/>"
xmlp_filecontents[122]="<lib name=\"nektarpp\"/>"
xmlp_filecontents[123]="<lib name=\"openexr\"/>"
xmlp_filecontents[124]="<lib name=\"pidx\"/>"
xmlp_filecontents[125]="<lib name=\"silo\"/>"
xmlp_filecontents[126]="<lib name=\"szip\"/>"
xmlp_filecontents[127]="<lib name=\"uintah\"/>"
xmlp_filecontents[128]="<lib name=\"xdmf\"/>"
xmlp_filecontents[129]="<lib name=\"zlib\"/>"
xmlp_filecontents[130]="</group>"
xmlp_filecontents[131]="<group name=\"dbio-only\" comment=\"Disables EVERYTHING but I/O.\" enabled=\"no\">"
xmlp_filecontents[132]="<lib name=\"adios\"/>"
xmlp_filecontents[133]="<lib name=\"adios2\"/>"
xmlp_filecontents[134]="<lib name=\"advio\"/>"
xmlp_filecontents[135]="<lib name=\"boost\"/>"
xmlp_filecontents[136]="<lib name=\"boxlib\"/>"
xmlp_filecontents[137]="<lib name=\"cfitsio\"/>"
xmlp_filecontents[138]="<lib name=\"conduit\"/>"
xmlp_filecontents[139]="<lib name=\"mfem\"/>"
xmlp_filecontents[140]="<lib name=\"cgns\"/>"
xmlp_filecontents[141]="<lib name=\"fastbit\"/>"
xmlp_filecontents[142]="<lib name=\"fastquery\"/>"
xmlp_filecontents[143]="<lib name=\"gdal\"/>"
xmlp_filecontents[144]="<lib name=\"h5part\"/>"
xmlp_filecontents[145]="<lib name=\"hdf5\"/>"
xmlp_filecontents[146]="<lib name=\"mxml\"/>"
xmlp_filecontents[147]="<lib name=\"netcdf\"/>"
xmlp_filecontents[148]="<lib name=\"nektarpp\"/>"
xmlp_filecontents[149]="<lib name=\"pidx\"/>"
xmlp_filecontents[150]="<lib name=\"silo\"/>"
xmlp_filecontents[151]="<lib name=\"szip\"/>"
xmlp_filecontents[152]="<lib name=\"uintah\"/>"
xmlp_filecontents[153]="<lib name=\"xdmf\"/>"
xmlp_filecontents[154]="<lib name=\"zlib\"/>"
xmlp_filecontents[155]="<lib name=\"no-qt\"/>"
xmlp_filecontents[156]="<lib name=\"no-qwt\"/>"
xmlp_filecontents[157]="<lib name=\"no-python\"/>"
xmlp_filecontents[158]="</group>"
xmlp_filecontents[159]="<group name=\"nonio\" comment=\"Build non I/O libraries\" enabled=\"no\">"
xmlp_filecontents[160]="<lib name=\"icet\"/>"
xmlp_filecontents[161]="<lib name=\"embree\"/>"
xmlp_filecontents[162]="<lib name=\"ispc\"/>"
xmlp_filecontents[163]="<lib name=\"tbb\"/>"
xmlp_filecontents[164]="<lib name=\"ospray\"/>"
xmlp_filecontents[165]="</group>"
xmlp_filecontents[166]="<group name=\"advanced\" comment=\"Must be manually downloaded\" enabled=\"no\">"
xmlp_filecontents[167]="<lib name=\"hdf4\"/>"
xmlp_filecontents[168]="<lib name=\"mili\"/>"
xmlp_filecontents[169]="<lib name=\"tcmalloc\"/>"
xmlp_filecontents[170]="</group>"
xmlp_filecontents[171]="</license>"
xmlp_filecontents[172]="<license name=\"gpl\">"
xmlp_filecontents[173]="<required>"
xmlp_filecontents[174]="<lib name=\"cmake\"/>"
xmlp_filecontents[175]="<lib name=\"python\"/>"
xmlp_filecontents[176]="<lib name=\"vtk\"/>"
xmlp_filecontents[177]="<lib name=\"qt\"/>"
xmlp_filecontents[178]="<lib name=\"qwt\"/>"
xmlp_filecontents[179]="<lib name=\"zlib\"/>"
xmlp_filecontents[180]="</required>"
xmlp_filecontents[181]="<optional>"
xmlp_filecontents[182]="<lib name=\"boost\"/>"
xmlp_filecontents[183]="<lib name=\"szip\"/>"
xmlp_filecontents[184]="<lib name=\"netcdf\"/>"
xmlp_filecontents[185]="<lib name=\"glu\"/>"
xmlp_filecontents[186]="<lib name=\"hdf5\"/>"
xmlp_filecontents[187]="<lib name=\"icet\"/>"
xmlp_filecontents[188]="<lib name=\"llvm\"/>"
xmlp_filecontents[189]="<lib name=\"mesagl\"/>"
xmlp_filecontents[190]="<lib name=\"mpich\"/>"
xmlp_filecontents[191]="<lib name=\"osmesa\"/>"
xmlp_filecontents[192]="<lib name=\"pyqt\"/>"
xmlp_filecontents[193]="<lib name=\"uintah\"/>"
xmlp_filecontents[194]="<lib name=\"damaris\"/>"
xmlp_filecontents[195]="<lib name=\"xercesc\"/>"
xmlp_filecontents[196]="<lib name=\"xsd\"/>"
xmlp_filecontents[197]="</optional>"
xmlp_filecontents[198]="<group name=\"required\" comment=\"All required libraries\" enabled=\"yes\">"
xmlp_filecontents[199]="<lib name=\"cmake\"/>"
xmlp_filecontents[200]="<lib name=\"python\"/>"
xmlp_filecontents[201]="<lib name=\"vtk\"/>"
xmlp_filecontents[202]="<lib name=\"qt\"/>"
xmlp_filecontents[203]="<lib name=\"qwt\"/>"
xmlp_filecontents[204]="<lib name=\"zlib\"/>"
xmlp_filecontents[205]="</group>"
xmlp_filecontents[206]="<group name=\"optional\" comment=\"All optional libraries\" enabled=\"no\">"
xmlp_filecontents[207]="<lib name=\"boost\"/>"
xmlp_filecontents[208]="<lib name=\"hdf5\"/>"
xmlp_filecontents[209]="<lib name=\"openssl\"/>"
xmlp_filecontents[210]="<lib name=\"netcdf\"/>"
xmlp_filecontents[211]="<lib name=\"mpich\"/>"
xmlp_filecontents[212]="<lib name=\"szip\"/>"
xmlp_filecontents[213]="<lib name=\"uintah\"/>"
xmlp_filecontents[214]="<lib name=\"damaris\"/>"
xmlp_filecontents[215]="<lib name=\"xercesc\"/>"
xmlp_filecontents[216]="<lib name=\"xsd\"/>"
xmlp_filecontents[217]="</group>"
xmlp_filecontents[218]="<group name=\"no-thirdparty\" comment=\"Do not build required 3rd party libraries\" enabled=\"no\">"
xmlp_filecontents[219]="<lib name=\"no-cmake\"/>"
xmlp_filecontents[220]="<lib name=\"no-python\"/>"
xmlp_filecontents[221]="<lib name=\"no-qt\" />"
xmlp_filecontents[222]="<lib name=\"no-qwt\" />"
xmlp_filecontents[223]="<lib name=\"no-vtk\"/>"
xmlp_filecontents[224]="<lib name=\"no-zlib\"/>"
xmlp_filecontents[225]="</group>"
xmlp_filecontents[226]="<group name=\"dbio-only\" comment=\"Disables EVERYTHING but I/O.\" enabled=\"no\">"
xmlp_filecontents[227]="<lib name=\"hdf5\"/>"
xmlp_filecontents[228]="<lib name=\"netcdf\"/>"
xmlp_filecontents[229]="<lib name=\"szip\"/>"
xmlp_filecontents[230]="<lib name=\"zlib\"/>"
xmlp_filecontents[231]="<lib name=\"uintah\"/>"
xmlp_filecontents[232]="<lib name=\"no-python\"/>"
xmlp_filecontents[233]="<lib name=\"no-qt\"/>"
xmlp_filecontents[234]="<lib name=\"no-qwt\"/>"
xmlp_filecontents[235]="</group>"
xmlp_filecontents[236]="<group name=\"all-io\" comment=\"Build all available I/O libraries\" enabled=\"no\">"
xmlp_filecontents[237]="<lib name=\"hdf5\"/>"
xmlp_filecontents[238]="<lib name=\"netcdf\"/>"
xmlp_filecontents[239]="<lib name=\"szip\"/>"
xmlp_filecontents[240]="<lib name=\"zlib\"/>"
xmlp_filecontents[241]="<lib name=\"uintah\"/>"
xmlp_filecontents[242]="</group>"
xmlp_filecontents[243]="<group name=\"nonio\" comment=\"Build non I/O libraries\" enabled=\"no\">"
xmlp_filecontents[244]="<lib name=\"icet\"/>"
xmlp_filecontents[245]="</group>"
xmlp_filecontents[246]="</license>"
xmlp_filecontents[247]="</modules>"
xmlp_licenses[0]="bsd|mit|lgpl"
xmlp_licenses_range[0]="1 171"
xmlp_licenses[1]="gpl"
xmlp_licenses_range[1]="172 246"
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]}"
    grouplibs_enabled[${#grouplibs_enabled[*]}]="${xmlp_grouplibs_enabled[$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 "$@"
