#!/bin/bash
# *****************************************************************************
#   Script: build_visit
#
#   Purpose:
#       A script that performs a complete build of VisIt and its support
#       libraries.  The script will detect if support libraries have already
#       been built and, if so, use those pre-built libraries.
#
#   Warning:
#       This script is only expected to work for Linux, and Darwin systems.
#       If you need to build VisIt for another platform, you should consult
#       the BUILD_NOTES that come with the VisIt source.  That document
#       contains instructions on how to build VisIt and its third party
#       libraries.
#
#   This script has been tested and is known to work with the following OS/
#   compiler combinations:
#
#	OS	Hardware	Compiler	Machine
#	-----	--------	--------	-------
#       RHEL3,	x86,		GCC 3.4.6	staples.llnl.gov
#       RHEL3, 	x86,		GCC 3.2.3	hoth.llnl.gov
#       CHAOS, 	x86_64,		GCC 3.4.5	vertex.llnl.gov
#       CHAOS,	ia64, 		GCC 3.4.5	thunder.llnl.gov
#       SuSE,   x86_64,		GCC 4.0.2	antares.lbl.gov
#       SuSE,   x86_64,		GCC 4.1.0	octagon.lbl.gov
#       MacOSX  i386,		GCC 4.0.1	dantooine.llnl.gov
#       MacOSX  ppc,		GCC 4.0.1	snailbait.llnl.gov
#
#   It is believed that this script will also work with other Linux variations.
#   Please send feedback to visit-users@ornl.gov if you run into problems
#   so that this script can be improved in the future.  If you have built
#   VisIt using this script on an OS/hardware/compiler combination not listed
#   above, please send a note to visit-users@ornl.gov, so we can add that
#   information to the script.
#
#   Setup:
#       This script assumes you have downloaded the VisIt source code and
#       the necessary third party libraries and that they are placed in the
#       current directory.  If it does not locate these libraries, it will
#       try to download them.
#       You must have:
#          Qt       qt-everywhere-opensource-src-4.6.1.tar.gz
#          Mesa     MesaLib-7.5.tar.gz
#          Python   Python-2.6.4tgz
#          VTK      vtk-5.0.0d.tar.gz
#          CMake    cmake-2.8.0.tar.gz
#
#        The following optional libraries need to be in the current directory
#        to be built. You must explicitly select which option library to
#        build, either through run string options or the dialog gui. If
#        the tarballs don't exist they will not be built or downloaded
#           Library  Version  Source Tarball Name    Command Option
#           Boxlib   2.5      boxlib.tar.gz          -b
#           CCMIO    2.6.1    libccmio-2.6.1.tar.gz  -C
#           CFITSIO  3006     cfitsio3006.tar.gz     -f
#           CGNS     2.4.3    cgnslib_2.4-3.tar.gz   -c
#           ExodusII 4.46     exodusii-4.46.tar.gz   -e
#           FastBit  0.9.9    fastbit-b0.9.9.tar.gz  -r
#           GDAL     1.3.2    gdal-1.3.2.tar.gz      -g (no AIX)
#           H5part   1.4.2    H5Part-1.6.0.tar.gz    -r
#           HDF4     2.4.1    HDF4.2r1.tar.gz        -4
#           HDF5     1.8.4    hdf5-1.8.4.tar.gz      -5
#           Mili     1.10     mili-1.10a.tar.gz      -m (internal)
#           NetCDF   3.6.0    netcdf.tar.gz          -n
#           AdvIO    1.2.0    AdvIO-1.2.tar.gz
#           Silo     4.7.2    silo-4.7.2.tar.gz
#           szip     2.1      szip-2.1.tar.gz
#
#         Experimental (internal)
#           ITAPS             ITAPS-FMDB-1.0-15Apr09.tar.gz
#           ITAPS             ITAPS-GRUMMP-0.5.0-20Apr09.tar.gz
#           ITAPS             ITAPS-MOAB-3.99-20Apr09.tar.gz
#           ViSUS             visus_26Feb07.tar.gz      -V
#
#   Layout:
#     Section 1:                    setting up inputs/environment variables
#     Function 1, check_files:      ensures input files are available
#     Function 2.0, check_more_options:edit option parameters
#     Function 2.1, check_parallel: parallel build information
#     Function 2.2, check_variables:edit variable build information
#     Function 3, build_mesa:       build mangled Mesa
#     Function 4, build_qt:         build Qt
#     Function 5, build_cmake:      build CMake (like configure, for VTK)
#     Function 6, build_vtk:        build VTK
#     Function 7, build_python:     build Python
#     Function 7.1, build_pil       build the Python Imaging Library
#     Function 8.0, build_szip:     build SZIP
#     Function 8.1, build_hdf5:     build HDF5
#     Function 8.2, build_mili:     build Mili
#     Function 8.3, build_hdf4:     build HDF4
#     Function 8.4, build_netcdf:   build NetCDF
#     Function 8.5, build_cgns:     build CGNS
#     Function 8.6, build_gdal:     build GDAL
#     Function 8.7, build_exodus:   build Exodus
#     Function 8.8, build_boxlib:   build Boxlib
#     Function 8.9, build_cfitsio:  build CFITSIO
#     Function 8.10, build_h5part:  build H5Part
#     Function 8.11, build_ccmio:   build CCMIO
#     Function 8.12, build_tcmalloc: build google-perftools/tcmalloc
#     Function 8.13, build_icet:    build Ice-T
#     Function 8.14, build_fastbit: build FastBit
#     Function 8.15, build_itaps_moab: build MOAB impl. of ITAPS
#     Function 8.16, build_itaps_fmdb: build FMDB impl. of ITAPS
#     Function 8.17, build_itaps_grummp: build GRUMMP impl. of ITAPS
#     Function 8.18, build_advio:   build AdvIO
#     Function 8, build_silo:       build Silo
#     Function 9, build_hostconf:   build the config-site/host.conf file
#     Function 9.1, build_visit:    build the VisIt source code
#     Section 2:                    oversees build process (calls Functions 1-8)
#
#   Programmer: Hank Childs (with large portions borrowed from BUILD_NOTES,
#                            which is maintained by Eric Brugger)
#   Creation:   October 21, 2006
#
#   Modifications:
#
#     Hank Childs, Mon Oct 30 17:18:24 PST 2006
#     Fixed two bugs: (1) forgot to check return value of function that checks
#     to make sure third party libraries are there.  (2) construction of
#     "visit-arch" string involved undefined variable, which caused problems
#     on some platforms.
#
#     Brad Whitlock, Fri Dec 15 11:51:40 PDT 2006
#     Added support for Python 2.5.
#
#     Hank Childs, Sun Mar  4 11:14:54 PST 2007
#     Add support for parallelization.  Also misc bug fixes.
#
#     Brad Whitlock, Fri Apr 6 14:09:00 PST 2007
#     Added support for downloading missing source files and for graphical
#     progress dialogs and menus for making choices about parallel, etc.
#
#     Thomas R. Treadway, Mon Apr 16 09:01:29 PDT 2007
#     Added Gunther H. Weber changes for MacOS X support.
#     Tuned for building under both i386 and ppc.
#
#     Thomas R. Treadway, Wed Apr 25 13:22:57 PDT 2007
#     Added optional 3rd-party build information
#     New argument options, dialog checklist
#     Reordered logic to better support more architectures
#     Went back to the HDF4.2r1.tar.gz release ffor the Mac.
#
#     Thomas R. Treadway, Mon May  7 16:51:58 PDT 2007
#     More bug fixes, and argument options.
#
#     Thomas R. Treadway, Thu May 17 14:31:47 PDT 2007
#     Support for multiple architectures
#     Support bz2 uncompression
#     Added a variable editing dialog
#
#     Thomas R. Treadway, Wed May 23 17:04:07 PDT 2007
#     Using common libraries everywhere
#     Now using stable Mesa-6.4.2, cmake-2.4.5
#     Changes to support AIX (except for gdal)
#     Added a MAKE variable
#
#     Thomas R. Treadway, Thu May 24 16:26:37 PDT 2007
#     Added an option to disable building VisIt
#     Missing required libraries cause immediate abort
#
#     Thomas R. Treadway, Fri May 25 15:41:42 PDT 2007
#     Added an option to build from svn
#     Added a build_hostconf function to create the host conf file
#
#     Thomas R. Treadway, Thu May 31 16:05:36 PDT 2007
#     Modified Mesa install for 64-bit linux
#     Change Boxlib install path back to the legacy path
#
#     Cyrus Harrison, Mon Jun 11 08:41:00 PDT 2007
#     Added support for SVN_NERSC_NAME for svn mode
#
#     Thomas R. Treadway, Thu May 31 16:05:36 PDT 2007
#     Modified access control on 3rd party libraries.
#
#     Hank Childs, Fri Jul  6 11:53:05 PDT 2007
#     Fix inconsistency with Python.  It installs Python in a location that
#     it can't find in later builds.  Also add a no-graphics mode (-z).  Also
#     don't prompt for Qt license if it is already built.
#
#     Thomas R. Treadway, Fri Jul  6 12:58:58 PDT 2007
#     Added option to redirect build log to /dev/tty
#     Allow a mix of SVN for 3rd party libraries, and tar file for VisIt
#     Added a skip of required 3rd party libraries.
#
#     Thomas R. Treadway, Mon Jul  9 17:26:26 PDT 2007
#     Updated to VisIt 1.6.1
#     Corrects some VisIt tarball vs SVN problems
#
#     Cyrus Harrison, Mon Jul  9 14:46:11 PDT 2007
#     Switched from "svn export" to "svn cat" b/c of problems with old svn
#     clients.
#
#     Thomas R. Treadway, Wed Jul 11 12:35:37 PDT 2007
#     Cleanup and fix of many small errors
#     Addition of H5Part third party library
#
#     Thomas R. Treadway, Fri Jul 13 11:19:32 PDT 2007
#     Added options for VisIt builds with --enable-visitmodule and
#     --enable-java
#
#     Thomas R. Treadway, Thu Jul 26 14:53:18 PDT 2007
#     Modified sources path in VisIt tar file.
#     Changed link options on Mac
#
#     Kathleen Bonnell, Mon Aug 27 08:42:06 PDT 2007
#     Changed -DMANGLED_OSMESA_INCLUDE to -DMANGLED_OSMESA_INCLUDE_DIR
#     in build_vtk. 
#
#     Gunther H. Weber, Wed Aug 29 12:34:58 PDT 2007
#     - Added rv=0 to beginning of check_parallel to fix error when trying
#       to build a parallel version of VisIt.
#     - Added missing VISITARCH component to path that is used for checking
#       if Mili was already built.
#     - Add processor architecture for Linux builds to VISITARCH
#     - Do not specify a username for svn checkout if SVN_NERSC_USERNAME is
#       not set, so that one can use .ssh/config for that purpose
#     - Fix gcc version detection if ./configure line containts "version"
#
#     Hank Childs, Mon Sep 10 12:33:06 PDT 2007
#     If you are building only an optional third party library, then don't
#     download Qt, VTK, Mesa, VisIt source, etc.
#
#     Hank Childs, Thu Sep 13 06:15:07 PDT 2007
#     If you are building Exodus, then build NetCDF too.  Otherwise the build
#     will fail.  Also, install Exodus using relative paths for its symlinks.
#
#     Thomas R. Treadway, Thu Jul 26 14:53:18 PDT 2007
#     szip library now required with HDF4 and HDF5
#     Modified parallel options handeling, allowing non-GUI setting
#
#     Thomas R. Treadway, Sun Oct  7 19:21:48 PDT 2007
#     Modify H5Part dynamic library build for PPC Mac
#     Fixed a few typos
#
#     Hank Childs, Sat Oct 13 08:09:41 PDT 2007
#     Commit numerous fixes pointed out by Matthew Wheeler.  Highlights include
#     improved SunOS and AIX support.
#
#     Thomas R. Treadway, Fri Oct 19 13:37:00 PDT 2007
#     Fixes for Linux build:
#     - forcing static libraries in szip and hdf5
#     - corrected problems with szip in Silo build
#     Added information about visit-bin-dist and visit-install
#
#     Hank Childs, Mon Oct 22 10:09:42 PDT 2007
#     Fix typo.  Compiler flage -> Compiler flags.
#
#     Thomas R. Treadway, Fri Oct 19 13:37:00 PDT 2007
#     Added patches to support MacOS X 10.5. Note Qt-3.3.8 is not
#     supported on MacOS X 10.5 and will not build, so use a 10.4 
#     (or earlier) built version of Qt and install it in
#     $VISITDIR/qt/${QT_VERSION}/$VISITARCH
#
#     Hank Childs, Thu Nov 15 09:14:58 PST 2007
#     Update references from version 1.6.1 to version 1.7.
#
#     Hank Childs, Thu Nov 15 15:01:07 PST 2007
#     Tweak name of visit file so it automatically gets updated when version
#     changes.
#
#     Thomas R. Treadway, Fri Nov 15 16:37:00 PDT 2007
#     Modified visit file to allow interactive updating.
#
#     Gunther H. Weber, Mon Nov 19 19:03:24 PST 2007
#     Patch Qt to build on MacOS X 10.5 (based on patches used by the Fink
#     project). 
#
#     Thomas R. Treadway, Mon Nov 26 10:03:38 PST 2007
#     Changed web pages from www.llnl.gov/VisIt to wci.llnl.gov/codes/visit 
#
#     Sean Ahern, Wed Jan 16 15:47:12 EST 2008
#     Fixed spelling, grammar, general prettying-up.
#
#     Thomas R. Treadway, Thu Jan  3 17:24:29 PST 2008
#     Put a check for wget version 1.8
#     Added explicit check for mesa 6.4.2
#
#     Thomas R. Treadway, Fri Jan  4 10:23:18 PST 2008
#     Linux defaults to Mesa-5.0, because of driver problems
#
#     Eric Brugger, Fri Feb  1 08:57:04 PST 2008
#     Changed the version to 1.8.0.
#
#     Hank Childs, Fri Feb  1 15:06:35 PST 2008
#     Change MESA_TARGET from linux-x86 to linux, since linux-x86 does not
#
#     Thomas R. Treadway, Fri Feb  1 15:52:08 PST 2008
#     Updated Silo release to 4.6.1
#     Updated H5Part release to 1.4.0
#     Added --enable-slivr support
#     Added support for CCMIO library
#     Hooks for ITAPS, and ViSUS libraries, but no implementation
#     Modified the third party untar behavior
#
#     Hank Childs, Mon Feb  4 16:59:30 PST 2008
#     Make it obvious that Mili cannot be downloaded from the web.
#
#     Hank Childs, Wed Feb  6 11:27:24 PST 2008
#     1) Rename some variables that are conflicting with names used elsewhere.
#     (QT_DIR by Linux, MILI_DIR by VisIt's configure script.)
#     2) Do not do a parallel build for H5_part.
#
#     Thomas R. Treadway, Wed Feb  6 15:08:07 PST 2008
#     Corrected the silo build
#     Added an explicit CMake build step.
#     Added a parallel make option
#
#     Thomas R. Treadway, Thu Feb  7 16:58:19 PST 2008
#     Corrected the ccmio build for x86_64
#
#     Thomas R. Treadway, Fri Feb  8 15:30:08 PST 2008
#     Added David Bremer's patch for fixing QT's OpenGL path problems.
#
#     Hank Childs, Sat Feb  9 14:18:54 PST 2008
#     Change clearcase_bin to svn_bin in help section.
#
#     Hank Childs, Sat Feb  9 15:23:42 PST 2008
#     Rename components directory to avt.
#
#     Brad Whitlock, Wed Mar 12 11:15:09 PDT 2008
#     Fixed Mesa build on AIX.
#
#     Kathleen Bonnell, Wed Mar 26 17:10:12 PDT 2008 
#     Moved calls to check_more_options, check_parallel and check_variables
#     to BEFORE THIRD_PARTY_PATH is used to set VISITDIR.
#
#     Gabe Rockefeller & Steven Diehl, Mon March 24 15:00 PST 2008
#     Fixed bug for setting the default values for parallel build flag. 
#     Now uses mpic++ instead of mpicc, since these flags get passed into
#     g++ during the build process.
#
#     Thomas R. Treadway, Thu Mar 27 12:16:19 PDT 2008
#     Implemented the above.
#     Merged in 1.8.1 changes, which included:
#     - Added support to CCMIO for i386 MacOS X10.5, and 
#       PPC MacOS X10.5, 10.4, and 10.3 
#     - Patch for MacOS X10.5's problem with GLU during CCM database build
#     Removed redundent THIRD_PARTY_PATH from GUI, rename More Variable
#     Settings GUI screen.
#     Changed version to 1.9.0.
#     Fixed a few typos.
#
#     Brad Whitlock, Fri Apr  4 10:38:58 PDT 2008
#     Fixed a bug with building Silo on the Mac when HDF5 is not used.
#
#     Thomas R. Treadway, Wed Apr 16 13:14:07 PDT 2008
#     Modified parallel build routine, check for mpic++, mpicxx, mpiCC.
#     Added option to display user settable environment variables
#
#     Gunther H. Weber, Wed Apr 16 16:26:21 PDT 2008
#     Check whether Qt configure enables OpenGL support and fail if it
#     does not.
#
#     Thomas R. Treadway, Fri Apr 18 14:03:06 PDT 2008
#     Correct a printout problem with the -E, display user settable 
#     environment variables option. Added PAR_INCLUDE and PAR_LIBS 
#     to the variable list.
#
#     Thomas R. Treadway, Wed Apr 23 15:14:43 PDT 2008
#     Fixed dialog text input box processing in parallel build dialog
#     Modified Variable setting menu
#     Changed implemented in More options and moved into a function
#     Added a GUI, and -R option to specify an VisIt SVN revision argument
#
#     Thomas R. Treadway, Mon May  5 14:14:11 PDT 2008
#     Check for wget version 9.x, because SSL options different from V10.
#     Corrected problem with having QTDIR defined
#
#     Sean Ahern, Tue May  6 12:00:35 EDT 2008
#     Made the Qt OpenGL patch apply more generally to 64-bit platforms.
#
#     Thomas R. Treadway, Wed May  7 15:15:58 PDT 2008
#     Added better logic for VISITARCH variable feedback.
#
#     Thomas R. Treadway, Tue May 13 16:24:20 PDT 2008
#     Fixed CCMIO library creation for Darwin.
#     Commented out the SETPGRP_HAVE_ARG fix.
#
#     Thomas R. Treadway, Mon May 19 12:16:21 PDT 2008
#     Support for poor MacOS X 10.3 and C99 additions.
#
#     Thomas R. Treadway, Wed May 21 15:51:51 PDT 2008
#     Version changed to 1.9.1
#
#     Hank Childs, Fri Jun 13 14:22:30 PDT 2008
#     Add support for libtcmalloc.
#
#     Jeremy Meredith, Tue Jun 24 14:34:38 EDT 2008
#     Patch Mesa 6.4.2 to use a larger offscreen window size limit.
#
#     Eric Brugger, Wed Jul  2 13:57:28 PDT 2008
#     Modified the logic that splits the output of "mpiCC -show" into
#     parallel linker and compiler flags to select any strings that start
#     with "-L", "-l" and "-Wl" as linker flags, any strings that start
#     with "-I" and "-D" as compiler flags, and any remaining strings that
#     start with "-" as both compiler and linker flags. 
#
#     Tom Fogal, Fri Jul 11 10:47:31 EDT 2008
#     Added PIL to build_python.
#
#     Jeremy Meredith, Fri Aug  8 13:13:36 EDT 2008
#     Added new "download_web_file" which lets us grab a file directly
#     off the web instead of visit's 3rd party directory.
#
#     Hank Childs, Mon Aug 18 10:46:10 PDT 2008
#     Patches for VTK and Silo for compilation issue with gcc 4.3.
#
#     Hank Childs, Thu Aug 28 10:11:34 PDT 2008
#     Make szip build on FC9.  (szip is required for HDF5.)
#
#     Hank Childs, Mon Sep  1 09:21:27 PDT 2008
#     Move all patches to their own function.  (Purpose is to improve
#     readability and maintainability.)
#
#     Tom Fogal, Thu Oct  2 22:03:56 MDT 2008
#     Move PIL out of build_python into its own function.
#
#     Tom Fogal, Fri Oct  3 11:01:28 MDT 2008
#     Fix the PIL download URL, and add a dir variable.
#     Added a set of functions for ease of use.
#     Cleaned up the PIL build function, and don't redirect the function so it
#     can easily use the new functions to log information.
#
#     Tom Fogal, Mon Oct  6 23:11:17 MDT 2008
#     Force -fPIC in BoxLib for non-AIX.  Switch fortran to compiler to
#     `gfortran' if `g77' is not found.
#
#     Tom Fogal, Thu Oct  9 16:11:56 MDT 2008
#     Long options and parsing.
#     Updated 'usage' message to account for long options, and greatly
#     improved the formatting.
#
#     Tom Fogal, Fri Oct 10 11:20:24 MDT 2008
#     Removed an embarassing oversight leftover from debugging my
#     earlier work on the PIL.
#
#     Eric Brugger, Tue Oct 14 11:23:14 PDT 2008
#     Changed the version to 1.11.0.
#
#     Mark C. Miller, Tue Oct 21 10:32:36 PDT 2008
#     Modified to support VisIt's configure new way of handling hdf5.
#     Modified to support shared hdf5.
#
#     Tom Fogal, Wed Oct 22 09:05:43 MDT 2008
#     Add an --szip command line to enable SZip.  Don't force SZip if the user
#     wants HDF5, but enable SZip if they ask for it.
#
#     Mark C. Miller, Tue Oct 28 11:14:17 PDT 2008
#     Modified build of H5Part to use -DH5_USE_16_API. See notes in that func.
#
#     Mark C. Miller, Mon Nov 17 22:30:28 PST 2008
#     Made Silo optional instead of required; removed Silo patching; upgraded
#     Silo version to 4.6.2. Copied the pattern used for CCMIO.
#
#     Mark C. Miller, Thu Nov 20 10:03:12 PST 2008
#     Fixed typo in DEFAULT_SILO symbols put in generated config-site file.
#     Updated DEFAULT_SILO symbols to use LIBLOC/LIBDEP form.
#
#     Cyrus Harrison, Tue Nov 18 16:34:49 PST 2008
#     Changes for Qt4 including:
#      *Added build_qt4 (doesn't currently download the src tarball however)
#      *Replaced the repeated "check for dir + try to unzip + try to untar" 
#        chunk of code with new function: prepare_build_dir
#      *Changed all build dirs vars to name [NAME]_BUILD_DIR, instead of 
#        [NAME]_DIR.In some cases [NAME]_DIR caused problems and was previously 
#        fixed with a special name BV_[NAME]_DIR, I just made everything 
#        uniform.
#
#     Cyrus Harrison, Tue Dec  2 13:44:29 PST 2008
#     Stopped creating symlink of szip static lib in hdf5 install.
#
#     Tom Fogal, Sat Dec  6 21:27:55 PST 2008
#     A silo path variable was missing "silo".
#
#     Tom Fogal, Mon Dec  8 22:46:17 MST 2008
#     Quoted compiler flags given to VTK.
#
#     Mark C. Miller, Thu Dec 11 08:38:41 PST 2008
#     Made the auto-generated config-site file a little more portable by
#     creating a VISITARCH variable in the file and using \$VISITARCH
#     everywhere to refer to that variable in the config-site file and not
#     the shell variable defined in build_visit.
#
#     Sean Ahern, Thu Dec 11 16:02:54 EST 2008
#     Modified the variables in the auto-generated config-site file for
#     Silo-HDF5 dependency.
#
#     Hank Childs, Fri Dec 12 09:11:07 PST 2008
#     Added support for Ice-T.
#
#     Cyrus Harrison, Fri Dec 12 14:14:55 PST 2008
#     Fixed problem with checking if cgns is already built/installed.
#
#     Cyrus Harrison, Fri Dec 12 14:14:55 PST 2008
#     Changed version of google-perftools to 0.97 (from 0.98). 
#     0.97 is the version already in our repo and I verified it was the 
#     version Hank integrated into VisIt. 
#
#     Tom Fogal, Mon Dec 15 16:21:47 MST 2008
#     Cleanups for the IceT macro: handle multiple options in PAR_INCLUDE,
#     enable verbose makefiles so debugging IceT issues is possible, and
#     install IceT instead of copying libraries manually.
#
#     Hank Childs, Mon Jan 26 15:57:02 PST 2009
#     Add support for FastBit.
#
#     Jeremy Meredith, Thu Jan 29 13:24:34 EST 2009
#     Fixing Mesa 6.4.2 patching.  (This is already fixed on the 2.0 branch?)
#
#     Tom Fogal, Sat Feb  7 15:40:49 EST 2009
#     Die if we can't cd to a build directory.
#     Use make option flags on Mesa's build.
#     Document that Exodus requires NetCDF.
#
#     Mark C. Miller, Wed Feb 18 22:57:25 PST 2009
#     Updated Silo to version 4.7 and added to build_silo logic to use Qt
#     for silex. Installed some binaries for Mac OS
#
#     Mark C. Miller, Thu Feb 19 09:41:43 PST 2009
#     Added ability to specify alternate download paths for downloading files.
#     Set Silo functions to download silo from Silo's web site.
#
#     Mark C. Miller, Thu Feb 19 12:31:20 PST 2009
#     Refactored the multiple places that downloads functions were implmeneted
#     to download_file/try_download_file. The former either trys known places
#     or loops over specified sites. The latter attempts a specific download.
#
#     Mark C. Miller, Thu Feb 19 14:51:07 PST 2009
#     Fixed help message for --svn option. It DOES NOT assume HEAD and always
#     reads the revision argument.
#
#     Mark C. Miller, Thu Mar  5 13:46:15 PST 2009
#     Added this comment regarding recent changes that I neglected to comment
#     about. Added support for a dbio-only (DO_DBIO_ONLY) build. Added logic
#     in several places to disable stuff that is not needed for a dbio-only
#     build as well as enable all 3rd party database plugin libs.
#
#     Mark C. Miller, Thu Mar  5 16:33:45 PST 2009
#     I fixed problems that arose due to a bad commit.
#
#     Mark C. Miller, Wed Mar 11 14:24:36 PDT 2009
#     Fixed convenience logic for enabling ALL third party I/O libs for
#     dbio-only builds.
#
#     Patrick Shinpaugh, Wed Mar 11 11:38:55 MST 2009
#     Set flags + Mesa && Qt targets for ppc64 systems.
#
#     Tom Fogal, Wed Mar 11 11:45:59 MST 2009
#     Incorporated a patch from Patrick Shinpaugh which fixes the BoxLib build
#     on Linux-ppc64.
#
#     Tom Fogal, Wed Mar 11 11:52:09 MST 2009
#     Incorporated a patch from Patrick which fixes the Linux-ppc64 HDF4 build.
#
#     Mark C. Miller, Thu Mar 12 00:24:18 PDT 2009
#     Eliminated Qt dependence for dbio-only builds.
#
#     Tom Fogal, Tue Mar 17 21:15:53 MST 2009
#     Added a patch which sets the endianness properly on Linux-ppc systems
#     (based on a patch from Patrick Shinpaugh).
#
#     Mark C. Miller, Thu Mar 19 09:08:28 PDT 2009
#     Merged from RC. Added web path for fastbit.
#     Fixed cut-n-paste typos in error messages from ITAPS configures.
#     Set VisIt version number to 2.0.0
#
#     Mark C. Miller, Thu Mar 19 09:39:41 PDT 2009
#     Merged from RC.
#     Added ITAPS to graphical options for 3rd party libs. Updated HDF5 to
#     1.8.1 and added web-links for HDF5 and HDF4 and GDAL. Made download_file
#     fallback to getting from other sites if gets from svn/visit site fails.
#
#     Tom Fogal, Tue Mar 17 21:15:53 MST 2009
#     Added a patch which sets the endianness properly on Linux-ppc systems
#     (based on a patch from Patrick Shinpaugh).
#
#     Tom Fogal, Sun Mar 22 15:34:39 MST 2009
#     Fix CCMIO builds on Linux-PPC. -- thanks to Patrick Shinpaugh.
#
#     Tom Fogal, Sun Mar 22 20:00:46 MST 2009
#     Correct an earlier patch I had made to PPC HDF4 -- thanks P.S.
#
#     Eric Brugger, Mon Mar 23 17:09:00 PDT 2009
#     Added -DH5_USE_16_API to the CFLAGS and CXXFLAGS for the gdal build
#     so that it would build with hdf5 1.8.
#
#     Mark C. Miller, Tue Apr  7 14:56:44 PDT 2009
#     Added missing surrounding quotes in creation of DEFAULT_ITAPS_IMPLS
#     symbol for config.conf file that gets created.
#
#     Mark C. Miller, Tue Apr  7 15:02:19 PDT 2009
#     Added missing path component for include path for ITAPS_FMDB symbol.
#
#     Mark C. Miller, Wed Apr  8 10:25:38 PDT 2009
#     Fixed some problems with _IMPL symbol for ITAPS_GRUMMP. Fixed install
#     of ITAPS_GRUMMP missing iMesh_protos.h
#
#     Mark C. Miller, Wed Apr  8 11:48:04 PDT 2009
#     Removed shared libs from ITAPS installs to make it easier to package
#     the build up using visit-bin-dist.
#
#     Mark C. Miller, Tue Apr 21 14:38:20 PDT 2009
#     Updated to newest ITAPS implementations. Changed places where the string
#     'build_visit' is explicilty used in 3-4 places with $0. That allows
#     this script to be re-named (such as for ITAPS' iMeshIO tool) and things
#     still make some sense. Changed configuration for build_grummp to use
#     --enable-itaps instead of --enable-imesh --enable-ibase. Added a wee bit
#     of logic to rename visitconvert tools in case we're using this script
#     to build iMeshIO. 
#
#     Gunther H. Weber, Thu May  7 11:20:50 PDT 2009
#     Update H5Part to 1.4.2 and FastBit to 1.0.8 as required by changes
#     to the HDF_UC database plugin. Download FastBit automatically from
#     LBNL Codeforge if TAR ball not present.
#
#     Jeremy Meredith, Thu May 14 15:56:44 EDT 2009
#     HDF5 seemed to be updated to 1.8.2 in some places, but others were
#     left as 1.8.1 or 1.6.5.  I updated *all* references to be to 1.8.2.
#     At the very least, this fixed ftp downloading of HDF5.
#
#     Tom Fogal, Sat May 16 14:47:05 MDT 2009
#     Enhanced downloadv to check subversion.
#     Update NetCDF version to workaround compilation issues.
#
#     Mark C. Miller, Wed May 20 11:14:15 PDT 2009
#     Removed all refs to functions 'webget' and 'downloadv'. Those were
#     made obsolete following changes of Feb 19, 2009. Adjusted some text
#     were explicit refs to 'VisIt Build Process' or 'VisIt' were used to
#     use DLG_BACKTITLE and/or DLG_PKGNAME to make this script less
#     confusing when being used to install visit-related capabilities but
#     named differently (e.g. iMeshIO for ITAPS project).
#
#     Mark C. Miller, Wed May 20 11:40:55 PDT 2009
#     Fixed typo in NETCDF_BUILD_DIR name. It was missing '_BUILD'.
#
#     Tom Fogal, Mon May 25 15:42:30 MDT 2009
#     Fixed NetCDF downloading (mirror was missing).
#
#     Tom Fogal, Wed Jun 10 16:19:38 MDT 2009
#     Update Mesa to 7.5.
#
#     Mark C. Miller, Mon Jun 22 13:56:05 PDT 2009
#     Removed dup ON_SILO/DO_SILO lines.
#
#     Mark C. Miller, Mon Jun 22 21:54:25 PDT 2009
#     Adjusted _VERSION/_FILE/_BUILD_DIR symbols for FastBit, H5Part, HDF5
#     and Silo so that you don't have upteen different places to edit the
#     version number, they are consistent with other lib symbols and they
#     are correct and up to date.
#
#     Mark C. Miller, Wed Jun 24 15:40:59 PDT 2009
#     Fixed missing opening double quote for call to info in build_silo.
#
#     Hank Childs, Tue Jul 14 15:32:09 PDT 2009
#     Fix problem where .conf file is setting up CXXFLAGS and CFLAGS improperly.
#
#     Tom Fogal, Thu Jul 23 15:52:24 MDT 2009
#     Make sure the user knows why we couldn't use the dialog interface.
#
#     Tom Fogal, Thu Jul 30 19:20:29 MDT 2009
#     Unset CDPATH to make sure we don't inherit a bad setting.
#
#     Tom Fogal, Tue Aug  4 11:24:29 MDT 2009
#     Make VTK link against mangled Mesa.
#
#     Mark C. Miller, Tue Aug  4 13:24:24 PDT 2009
#     Changed MESA_MIRRORS to MESA_URL to make consistent with other symbols.
#     Added $MESA_URL to ensure_built_or_ready invokation. I also made it
#     possible to specify value for VISITDIR external to script so you can
#     essentially tell build_visit where to install its libs to.
# 
#     Cyrus Harrison,  Tue Aug  4 16:06:20 PDT 2009
#     Fixed a typo w/ MESA_URL - it was providing the full path for the sourceforge
#     download, and because of this build_visit was putting the tarball in the path twice.
#
#     Brad Whitlock, Mon Aug 17 12:49:11 PDT 2009
#     Use the regular build path for NetCDF on Darwin but fixup the library
#     names after installation. Don't always assume szip for hdf5 on Darwin.
#
#     Mark C. Miller, Mon Aug 17 14:08:38 PDT 2009
#     Added BUILD_VISIT_ENV to facilitate correct behavior of top-level
#     Makefile's env-make var collision check when it is being run from within
#     build_visit.
#
#     Gunther H. Weber, Thu Sep  3 10:14:33 PDT 2009
#     Change install name for Qt 4 on Darwin so that TAR-balls created with
#     visit-bin-dist work on other machines. Added comments for necessary changes
#     to switch to Qt 4.5.
#
#     Gunther H. Weber, Tue Sep 15 11:35:19 PDT 2009
#     Only use first two components of gcc version in architecture string
#     since the "least significant" portion of the version number can
#     be changed by gcc maintenance updates (at least on Ubuntu) and these
#     updated maintain binary compatibility.
#
#     Brad Whitlock, Mon Sep 21 09:53:56 PDT 2009
#     Adding support for AdvIO
#
#     Cyrus Harrison, Thu Oct 15 08:42:01 PDT 2009
#     Modifications to build_mesa & its patches to support building on AIX.
#
#     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
#     Support for build on Snow Leopard
#
#     Jed Brown, Sat Oct 24 21:57:05 CEST 2009
#     Do not build QtSql components (they are not used and broke gcc-4.4.1/qt-4.4.3)
#
#     Gunther H. Weber, Fri Oct 30 14:19:57 PDT 2009
#     Yet another Python fix: Use compatibility version in host.conf file instead
#     of version.
#
#     Cyrus Harrison, Tue Nov  3 16:43:53 PST 2009
#     Use of vtk-5.0.0d & transition to a "make install"ed vtk
#
#     Cyrus Harrison, Tue Nov  3 16:43:53 PST 2009
#     Added support for using VisIt's anonymous svn server via "--svn-anonymous"
#     Switched all versions of OSX to use Python 2.6.4 by default.
#
#     Hank Childs, Tue Nov 10 08:21:19 PST 2009
#     Add support for "build_visit --no-thirdparty --vtk".  This was a
#     supported option before, but it failed to properly download and/or build 
#     Mesa, CMake, and Python.
#
#     Gunther H. Weber, Tue Nov 10 19:46:08 PST 2009
#     Change install_name for VTK on MacOS.
#
#     Cyrus Harrison, Tue Nov 17 12:33:47 PST 2009
#     Reverted back to custom creation of python shared library on AIX.
#     Changed SO_EXT for AIX to ".a"
#
#     Hank Childs, Mon Nov 23 07:59:36 PST 2009
#     Add parallel include to CFLAGS.
#
#     Hank Childs, Wed Nov 25 11:43:31 PST 2009
#     Add some defense against using existing "VTK" directory from 5.0.0c.
#     Quote the PYTHON_EXTRA_LIBS.  Remove CMakeCache.txt file.  Change
#     the log file to be in the current directory.
#
#     Cyrus Harrison, Thu Dec 10 09:13:40 PST 2009
#     Added rpath linker flags when python is built using gcc.
#     This is necessary b/c python's build system does not build an exe that
#     runs without setting LD_LIBRARY_PATH if a non standard prefix is used.
#
#     Jeremy Meredith, Mon Dec 21 12:42:52 EST 2009
#     Removed one final use of .conf, changed to .cmake.
#     Fixed a few bugs in the way the host .cmake file is generated.
#
#     Tom Fogal, Mon Dec 21 15:05:42 MST 2009
#     Fix Mesa libraries used when building VTK.
#
#     Tom Fogal, Tue Dec 22 14:20:51 MST 2009
#     Revert above change, at least on Linux.
#     Add missing CMake type specifier.
#
#     Cyrus Harrison, Tue Dec 29 14:07:52 PST 2009
#     Removed stray instance of $VISITDIR & changed hostconf generator to use
#     ITAPS_FILE_PATTERNS  instead of ITAPS_FILE_EXTENSIONS to match
#     Jeremy's change to db plugins.
#
#     Tom Fogal, Tue Jan  5 19:44:21 MST 2010
#     Linux: Switch mangled Mesa and OSMesa library settings.
#
#     Tom Fogal, Wed Jan  6 18:53:08 MST 2010
#     Add -pthread to python link flags.
#
#     Tom Fogal, Tue Jan 12 20:32:14 MST 2010
#     Don't build some Qt subsystems that we don't need.
#
#     Tom Fogal, Wed Jan 13 14:05:59 MST 2010
#     Fix the above change; only changed what *printed* before!
#
#     Tom Fogal, Wed Jan 13 19:53:25 MST 2010
#     Get rid of OpenSSL too; we're not using QtNetwork.
#
#     Brad Whitlock, Thu Jan 28 10:16:29 PST 2010
#     Added some small changes for MacOS X 10.4
#
#     Tom Fogal, Wed Jan 20 22:58:41 MST 2010
#     Re-add QtXml to the list of Mac frameworks.
#
#     Tom Fogal, Thu Jan 21 20:27:37 MST 2010
#     Re-add OpenSSL, it's used directly (not through QtNetwork!).
#
#     Jeremy Meredith, Thu Jan 28 10:23:10 EST 2010
#     Changed VISIT_EXODUS_DIR in .cmake generation to EXODUSII, to
#     match what the build system expects.
#
#     Jeremy Meredith, Thu Jan 28 17:47:24 EST 2010
#     Couple changes for OS X 10.4: don't pass rpath to python since the
#     linker doesn't understand it (python filters are disabled for 10.4),
#     and don't pass the compatibility/current version flags to libtool
#     since VTK/CMake seems to be setting them appropriately on its own.
#
#     Mark C. Miller, Tue Feb  2 11:20:33 PST 2010
#     Updated Silo to 4.7.2 and HDF5 to 1.8.4. Also fixed a problem where the
#     hostconf file was specifying a relative path for the first line for
#     cmake. Configure didn't like that.
#
#     Mark C. Miller, Wed Feb  3 10:36:05 PST 2010
#     Added -no-libtiff to qt build.
#
#     Brad Whitlock Wed Feb 3 10:00:36 PDT 2010
#     I added Jean Favre's VISIT_STATIC patch.
#
#     Mark C. Miller, Wed Feb  3 11:00:11 PST 2010
#     Averted breaking --thirdparty-path by changing logic that includes
#     cmake path in hostconf file to compute absolute path from
#     $THIRD_PARTY_PATH
#
#     Hank Childs, Thu Feb  4 08:21:27 PST 2010
#     Add argument --svn-revision.
#
#     Brad Whitlock, Wed Feb 10 23:35:34 PST 2010
#     Added a patch for Boxlib and upgraded GDAL to get them working on
#     Ubuntu 9.10.
#
#     Gunther H. Weber, Tue Feb 16 11:07:08 PST 2010
#     Adapted to new H5Part
#
#     Hank Childs and Paul Navratil, Sat Feb 20 17:31:54 CST 2010
#     Fix for building Ice-T when PAR_INCLUDE has a -DDEFINE first.
#
#     Eric Brugger, Mon Feb 22 13:39:04 PST 2010
#     I modified build_qt to build a 32 bit versoin of Qt if the OBJECT_MODE
#     environment variable was 32.  I added a check to make sure that if we
#     are building on AIX that we are using GNU tar.  I made the tar command
#     be a variable so that it could be easily changed.  I modified the patch
#     commands so that they would work on AIX systems.  I modified one of the
#     mesa patches to add some AIX specific code from a later version of mesa
#     (that Tom Fogal had contributed to mesa).
#
#     Hank Childs, Sun Feb 28 13:28:05 PST 2010
#     Make IceT builds be automatic if you enable parallel builds.
#
#     Cyrus Harrison, Tue Mar  9 07:52:50 PST 2010
#     Install name patching for vtk python module on OSX.
#
#     Eric Brugger, Fri Mar 12 14:18:26 PST 2010
#     I modified build_exodus so that the netcdf header file and library
#     are files instead of links in the installation directory so that make
#     package works with VISIT_INSTALL_THIRD_PARTY defined.
#
#     Cyrus Harrison, Fri Mar 12 15:47:11 PST 2010
#     Use qt 4.6.1 & python 2.6.4 on all platforms.
#
#     Eric Brugger, Mon Mar 15 14:27:23 PDT 2010
#     I added a patch for ccmio 2.6.1 so that it would build in 32 bit mode
#     on AIX.
#
#     Cyrus Harrison, Wed Mar 17 10:21:15 PDT 2010
#     Use cmake 2.8.0.
#
#     Cyrus Harrison, Wed Mar 17 10:21:15 PDT 2010
#     Fix python shared lib gen on AIX + removed old python patches.
#
#     Eric Brugger, Thu Mar 18 15:12:19 PDT 2010
#     I added several patches for VTK so that VTK would compile under AIX
#     with cmake 2.8.0.
#
#     Eric Brugger, Fri Mar 19 16:04:36 PDT 2010
#     I added several patches and disabled javascript-jit, script, and
#     scripttools for Qt 4.6.1 so that it would compile with gcc 3.2.3 on
#     an x86 platform.
#
#     Cyrus Harrison, Tue Mar 23 09:21:32 PDT 2010
#     Added support to set group permissions on:
#      pil, tcmalloc, icet & advio
#
#     Tom Fogal, Fri Mar 26 17:24:39 MDT 2010
#     Add --cflag, --cxxflag.  These *append* a specific flag.
#     Getting '--cflags' to quote reliably is a nightmare.
#
#     Cyrus Harrison, Tue Apr 20 17:03:10 PDT 2010
#     Add support for setting up MPI_INCLUDE_PATH for ice-t via
#     PAR_COMPILER. Includes special case for osx w/ default mpic++.
#
# *****************************************************************************
#                                                                             #
# *************************************************************************** #
#                       Section 1, setting up inputs                          #
# --------------------------------------------------------------------------- #
# This section sets up the inputs to the VisIt script.  This is where you can #
# specify which compiler to use, which versions of the third party libraries, #
# etc.  Note that this script is really only known to work with gcc.          #
# *************************************************************************** #

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

# 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

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
   if (( ${VER%%.*} < 8 )) ; then
      export MACOSX_DEPLOYMENT_TARGET=10.3
   elif [[ ${VER%%.*} == 8 ]] ; then
      export MACOSX_DEPLOYMENT_TARGET=10.4
   elif [[ ${VER%%.*} == 9 ]] ; then
      export MACOSX_DEPLOYMENT_TARGET=10.5
   elif [[ ${VER%%.*} == 10 ]] ; then
      export MACOSX_DEPLOYMENT_TARGET=10.6
   else
      export MACOSX_DEPLOYMENT_TARGET=10.6
   fi
   export C_COMPILER=${C_COMPILER:-"gcc"}
   export CXX_COMPILER=${CXX_COMPILER:-"g++"}
   export C_OPT_FLAGS=${C_OPT_FLAGS:-"-O2 -fno-common -fexceptions"}
   export CXX_OPT_FLAGS=${CXX_OPT_FLAGS:-"-O2 -fno-common -fexceptions"}
   export MESA_TARGET=${MESA_TARGET:-"darwin"}
   export QT_PLATFORM=${QT_PLATFORM:-"macx-g++"}
elif [[ "$OPSYS" == "Linux" ]]; then
   export ARCH=${ARCH:-"linux-$(uname -m)"} # You can change this to say RHEL, SuSE, Fedora.
   export SO_EXT="so"
   if [[ "$(uname -m)" == "i386" ]] ; then
###   export MESA_TARGET=${MESA_TARGET:-"linux-x86"} # Mesa-6.x
      export MESA_TARGET=${MESA_TARGET:-"linux"}
   elif [[ "$(uname -m)" == "i686" ]] ; then
###   export MESA_TARGET=${MESA_TARGET:-"linux-x86"} # Mesa-6.x
      export MESA_TARGET=${MESA_TARGET:-"linux"}
   elif [[ "$(uname -m)" == "x86_64" ]] ; then
      C_OPT_FLAGS="$C_OPT_FLAGS -m64 -fPIC"
      CXX_OPT_FLAGS="$CXX_OPT_FLAGS -m64 -fPIC"
###   export MESA_TARGET=${MESA_TARGET:-"linux-x86-64"} # Mesa-6.x
      export MESA_TARGET=${MESA_TARGET:-"linux"}
      QT_PLATFORM="linux-g++-64"
   elif [[ "$(uname -m)" == "ppc64" ]] ; then
      if [[ "$C_COMPILER" == "xlc" ]] ; then
          C_OPT_FLAGS="$C_OPT_FLAGS -qpic"
          CXX_OPT_FLAGS="$CXX_OPT_FLAGS -qpic"
          export CXX_COMPILER=${CXX_COMPILER-"xlC"}
          export MESA_TARGET=${MESA_TARGET-"linux"}
          QT_PLATFORM="linux-xlc" #aix-xlc"
      else
          C_OPT_FLAGS="$C_OPT_FLAGS -fPIC"
          CXX_OPT_FLAGS="$CXX_OPT_FLAGS -fPIC"
          export MESA_TARGET=${MESA_TARGET-"linux"}
          QT_PLATFORM="linux-g++"
      fi
   elif [[ "$(uname -m)" == "ia64" ]] ; then
      C_OPT_FLAGS="$C_OPT_FLAGS -fPIC"
      CXX_OPT_FLAGS="$CXX_OPT_FLAGS -fPIC"
      QT_PLATFORM="linux-g++"
   fi
   export C_COMPILER=${C_COMPILER:-"gcc"}
   export CXX_COMPILER=${CXX_COMPILER:-"g++"}
   export C_OPT_FLAGS=${C_OPT_FLAGS:-"-O2"}
   export CXX_OPT_FLAGS=${CXX_OPT_FLAGS:-"-O2"}
   export MESA_TARGET=${MESA_TARGET:-"linux"}
   export QT_PLATFORM=${QT_PLATFORM:-"linux-g++"}
elif [[ "$OPSYS" == "AIX" ]]; then
   export ARCH="aix" # You can change this to say RHEL, SuSE, Fedora, etc.
   export SO_EXT="a"
   export C_COMPILER=${C_COMPILER:-"xlc"}
   export CXX_COMPILER=${CXX_COMPILER:-"xlC"}
   export C_OPT_FLAGS=${C_OPT_FLAGS:-"-O2"}
   export CXX_OPT_FLAGS=${CXX_OPT_FLAGS:-"-O2"}
   export MAKE=${MAKE:-"gmake"}
   export MESA_TARGET=${MESA_TARGET:-"aix"}
   if [[ "$OBJECT_MODE" == 32 ]]; then
      export QT_PLATFORM=${QT_PLATFORM:-"aix-xlc"}
   else
      export QT_PLATFORM=${QT_PLATFORM:-"aix-xlc-64"}
   fi
elif [[ "$OPSYS" == "IRIX64" ]]; then
   export ARCH="irix64" # You can change this to say RHEL, SuSE, Fedora, etc.
   export SO_EXT="so"
   export C_COMPILER=${C_COMPILER:-"gcc"}
   export 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 CXX_COMPILER=${CXX_COMPILER:-"g++"}
   export C_OPT_FLAGS=${C_OPT_FLAGS:-"-O2"}
   export CXX_OPT_FLAGS=${CXX_OPT_FLAGS:-"-O2"}
   export MAKE=${MAKE:-"make"}
   export MESA_TARGET=${MESA_TARGET:-"sunos5-gcc"}
   export QT_PLATFORM="solaris-g++"
else
   export ARCH=${ARCH:-"linux-$(uname -m)"} # You can change this to say RHEL, SuSE, Fedora.
   export SO_EXT="so"
   if [[ "$(uname -m)" == "x86_64" ]] ; then
      C_OPT_FLAGS="$C_OPT_FLAGS -m64 -fPIC"
      CXX_OPT_FLAGS="$CXX_OPT_FLAGS -m64 -fPIC"
      QT_PLATFORM="linux-g++-64"
   fi
   if [[ "$(uname -m)" == "ia64" ]] ; then
      C_OPT_FLAGS="$C_OPT_FLAGS -fPIC"
      CXX_OPT_FLAGS="$CXX_OPT_FLAGS -fPIC"
      QT_PLATFORM="linux-g++-64"
   fi
   export C_COMPILER=${C_COMPILER:-"gcc"}
   export CXX_COMPILER=${CXX_COMPILER:-"g++"}
   export C_OPT_FLAGS=${C_OPT_FLAGS:-"-O2"}
   export CXX_OPT_FLAGS=${CXX_OPT_FLAGS:-"-O2"}
   export QT_PLATFORM=${QT_PLATFORM:-"linux-g++"}
fi
export MAKE=${MAKE:-"make"}
export THIRD_PARTY_PATH=${THIRD_PARTY_PATH:-"./visit"}
export GROUP=${GROUP:-"visit"}
export LOG_FILE=${LOG_FILE:-"${0##*/}_log"}
export SVNREVISION=${SVNREVISION:-"HEAD"}
# Created a temporary value because the user can override most of 
# the components, which for the GUI happens at a later time.
# the tmp value is useful for user feedback.
if [[ $VISITARCH == "" ]] ; then
    export VISITARCHTMP=${ARCH}_${C_COMPILER}
    if [[ "$CXX_COMPILER" == "g++" ]] ; then
        VERSION=$(g++ -v 2>&1 | grep "gcc version" | cut -d' ' -f3 | cut -d'.' -f1-2)
        if [[ ${#VERSION} == 3 ]] ; then
            VISITARCHTMP=${VISITARCHTMP}-${VERSION}
        fi
    fi
else
# use environment variable value
    export VISITARCHTMP=$VISITARCH
fi

REDIRECT_ACTIVE="no"
ANY_ERRORS="no"
#
# OPTIONS
#
export DO_MESA="no"
export ON_MESA="off"
export DO_QT="no"
export ON_QT="off"
export DO_CMAKE="no"
export ON_CMAKE="off"
export DO_VTK="no"
export ON_VTK="off"
export DO_HOSTCONF="yes"
export ON_HOSTCONF="on"

export DO_HDF4="no"
export ON_HDF4="off"
export DO_HDF5="no"
export ON_HDF5="off"
export DO_ADVIO="no"
export ON_ADVIO="off"
export DO_BOXLIB="no"
export ON_BOXLIB="off"
export DO_CGNS="no"
export ON_CGNS="off"
export DO_DEBUG="no"
export ON_DEBUG="off"
export DO_EXODUS="no"
export ON_EXODUS="off"
export DO_CFITSIO="no"
export ON_CFITSIO="off"
export DO_GDAL="no"
export ON_GDAL="off"
export ABS_PATH="yes"
export ON_ABS_PATH="on"
export DO_VISIT="yes"
export ON_VISIT="on"
export DO_REQUIRED_THIRD_PARTY="yes"
export ON_THIRD_PARTY="on"
export DO_GROUP="no"
export ON_GROUP="off"
export DO_MILI="no"
export ON_MILI="off"
export DO_NETCDF="no"
export ON_NETCDF="off"
export DO_LOG="no"
export ON_LOG="off"
parallel="no"
ON_parallel="off"
export DO_H5PART="no"
export ON_H5PART="off"
export DO_FASTBIT="no"
export ON_FASTBIT="off"
export DO_SVN="no"
export DO_SVN_ANON="no"
export ON_SVN="off"
export DO_REVISION="no"
export ON_REVISION="off"
USE_VISIT_FILE="no"
ON_USE_VISIT_FILE="off"
export DO_PATH="no"
export ON_PATH="off"
export DO_VERSION="no"
export ON_VERSION="off"
export DO_MODULE="no"
export ON_MODULE="off"
export DO_VERBOSE="no"
export ON_VERBOSE="off"
export DO_JAVA="no"
export ON_JAVA="off"
export DO_SZIP="no"
export ON_SZIP="off"
export DO_CCMIO="no"
export ON_CCMIO="off"
export DO_ITAPS="no"
export ON_ITAPS="off"
export DO_SILO="no"
export ON_SILO="off"
export DO_SLIVR="no"
export ON_SLIVR="off"
export DO_VISUS="no"
export ON_VISUS="off"
export DO_TCMALLOC="no"
export ON_TCMALLOC="off"
export DO_ICET="no"
export ON_ICET="off"
export PREVENT_ICET="no"
GRAPHICAL="yes"
ON_GRAPHICAL="on"
verify="no"
ON_verify="off"
export DO_OPTIONAL="yes"
export ON_OPTIONAL="on"
export DO_MORE="no"
export ON_MORE="off"
export DO_DBIO_ONLY="no"
export DO_STATIC_BUILD="no"
export USE_VISIBILITY_HIDDEN="no"

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


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

if [[ "$OPSYS" != "Darwin" ]]; then
    WGET_MINOR_VERSION=$(wget --version| head -n 1|cut -d. -f 2)
    # version 1.7 pre-dates ssl integration
    if [[ "${WGET_MINOR_VERSION}" == "8" ]] ; then
       export WGET_OPTS=${WGET_OPTS=""}
    elif [[ "${WGET_MINOR_VERSION}" == "9" ]] ; then
       export WGET_OPTS=${WGET_OPTS:="--sslcheckcert=0"}
    else
       export WGET_OPTS=${WGET_OPTS:-"--no-check-certificate"}
    fi
fi
#
# TARBALL LOCATIONS AND VERSIONS
#
if [[ "$VISIT_FILE" != "" ]] ; then
  USE_VISIT_FILE="yes"
  ON_USE_VISIT_FILE="on"
fi
export VISIT_VERSION=${VISIT_VERSION:-"2.0.0"}
export VISIT_FILE=${VISIT_FILE:-"visit${VISIT_VERSION}.tar.gz"}

export VTK_FILE=${VTK_FILE:-"vtk-5.0.0d.tar.gz"}
export VTK_VERSION=${VTK_VERSION:-"5.0.0d"}
export VTK_BUILD_DIR=${VTK_BUILD_DIR:-"VTK"}

export CMAKE_FILE=${CMAKE_FILE:-"cmake-2.8.0.tar.gz"}
export CMAKE_VERSION=${CMAKE_VERSION:-"2.8.0"}
export CMAKE_BUILD_DIR=${CMAKE_BUILD_DIR:-"cmake-2.8.0"}

export MESA_FILE=${MESA_FILE:-"MesaLib-7.5.tar.gz"}
export MESA_VERSION=${MESA_VERSION:-"7.5"}
export MESA_BUILD_DIR=${MESA_BUILD_DIR:-"Mesa-7.5"}
export MESA_URL="http://downloads.sourceforge.net/project/mesa3d/MesaLib/7.5"

export PYTHON_FILE_SUFFIX="tgz"
export PYTHON_VERSION="2.6.4"
export PYTHON_COMPATIBILITY_VERSION=2.6
export PYTHON_FILE="Python-$PYTHON_VERSION.$PYTHON_FILE_SUFFIX"
export PYTHON_BUILD_DIR="Python-$PYTHON_VERSION"

export PIL_URL=${PIL_URL:-"http://effbot.org/media/downloads"}
export PIL_FILE=${PIL_FILE:-"Imaging-1.1.6.tar.gz"}
export PIL_BUILD_DIR=${PIL_BUILD_DIR:-"Imaging-1.1.6"}

export QT_FILE=${QT_FILE:-"qt-everywhere-opensource-src-4.6.1.tar.gz"}
export QT_VERSION=${QT_VERSION:-"4.6.1"}

export QT_BUILD_DIR=${QT_BUILD_DIR:-"${QT_FILE%.tar*}"}

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 HDF5_VERSION=${HDF5_VERSION:-"1.8.4"}
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 HDF4_FILE=${HDF4_FILE:-"HDF4.2r1.tar.gz"}
export HDF4_VERSION=${HDF4_VERSION:-"4.2.1"}
export HDF4_COMPATIBILITY_VERSION=${HDF4_COMPATIBILITY_VERSION:-"4.0"}
export HDF4_BUILD_DIR=${HDF4_BUILD_DIR:-"HDF4.2r1"}

export MILI_FILE=${MILI_FILE:-"mili-1.10a.tar.gz"}
export MILI_VERSION=${MILI_VERSION:-"1.10.0"}
export MILI_COMPATIBILITY_VERSION=${MILI_COMPATIBILITY_VERSION:-"1.0"}
export MILI_BUILD_DIR=${MILI_BUILD_DIR:-"mili"}

export NETCDF_VERSION=${NETCDF_VERSION-"3.6.3"}
export NETCDF_FILE=${NETCDF_FILE-"netcdf-${NETCDF_VERSION}.tar.gz"}
export NETCDF_COMPATIBILITY_VERSION=${NETCDF_COMPATIBILITY_VERSION-"3.6"}
export NETCDF_BUILD_DIR=${NETCDF_BUILD_DIR-"netcdf-3.6.3"}

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 CGNS_FILE=${CGNS_FILE:-"cgnslib_2.4-3.tar.gz"}
export CGNS_VERSION=${CGNS_VERSION:-"2.4"}
export CGNS_COMPATIBILITY_VERSION=${CGNS_COMPATIBILITY_VERSION:-"2.4"}
export CGNS_BUILD_DIR=${CGNS_BUILD_DIR:-${CGNS_FILE%-3.tar*}}

export GDAL_FILE=${GDAL_FILE:-"gdal-1.7.1.tar.gz"}
export GDAL_VERSION=${GDAL_VERSION:-"1.7.1"}
export GDAL_COMPATIBILITY_VERSION=${GDAL_COMPATIBILITY_VERSION:-"1.7"}
export GDAL_BUILD_DIR=${GDAL_BUILD_DIR:-"gdal-1.7.1"}

export EXODUS_FILE=${EXODUS_FILE:-"exodusii-4.46.tar.gz"}
export EXODUS_VERSION=${EXODUS_VERSION:-"4.46"}
export EXODUS_COMPATIBILITY_VERSION=${EXODUS_COMPATIBILITY_VERSION:-"4.0"}
export EXODUS_BUILD_DIR=${EXODUS_BUILD_DIR:-"exodusii-4.46"}

export BOXLIB_FILE=${BOXLIB_FILE:-"boxlib.tar.gz"}
export BOXLIB_VERSION=${BOXLIB_VERSION:-"2.5"}
export BOXLIB_COMPATIBILITY_VERSION=${BOXLIB_COMPATIBILITY_VERSION:-"2.0"}
export BOXLIB_BUILD_DIR=${BOXLIB_BUILD_DIR:-"CCSEApps/BoxLib"}

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 H5PART_VERSION=${H5PART_VERSION:-"1.6.0"}
export H5PART_FILE=${H5PART_FILE:-"H5Part-${H5PART_VERSION}.tar.gz"}
export H5PART_COMPATIBILITY_VERSION=${H5PART_COMPATIBILITY_VERSION:-"1.6"}
export H5PART_BUILD_DIR=${H5PART_BUILD_DIR:-"H5Part-${H5PART_VERSION}"}

export FASTBIT_VERSION=${FASTBIT_VERSION:-"1.0.9"}
export FASTBIT_FILE=${FASTBIT_FILE:-"fastbit-ibis${FASTBIT_VERSION}.tar.gz"}
# Note: last 2-digit field in URL changes with version.
export FASTBIT_URL=${FASTBIT_URL:-"https://codeforge.lbl.gov/frs/download.php/62"}
export FASTBIT_BUILD_DIR=${FASTBIT_BUILD_DIR:-"fastbit-ibis1.0.9"}

export CCMIO_FILE=${CCMIO_FILE:-"libccmio-2.6.1.tar.gz"}
export CCMIO_VERSION=${CCMIO_VERSION:-"2.6.1"}
export CCMIO_COMPATIBILITY_VERSION=${CCMIO_COMPATIBILITY_VERSION:-"2.0"}
export CCMIO_BUILD_DIR=${CCMIO_BUILD_DIR:-"libccmio-2.6.1"}

export SILO_VERSION=${SILO_VERSION:-"4.7.2"}
export SILO_FILE=${SILO_FILE:-"silo-${SILO_VERSION}.tar.gz"}
export SILO_COMPATIBILITY_VERSION=${SILO_COMPATIBILITY_VERSION:-"4.7.2"}
export SILO_BUILD_DIR=${SILO_BUILD_DIR:-"silo-${SILO_VERSION}"}
export SILO_URL=${SILO_URL:-https://wci.llnl.gov/codes/silo/silo-${SILO_VERSION}}

export ITAPS_MOAB_FILE=${ITAPS_MOAB_FILE:-"ITAPS-MOAB-3.99-20Apr09.tar.gz"}
export ITAPS_MOAB_VERSION=${ITAPS_MOAB_VERSION:-"3.99-20Apr09"}
export ITAPS_MOAB_COMPATIBILITY_VERSION=${ITAPS_MOAB_COMPATIBILITY_VERSION:-"3.99-20Apr09"}
export ITAPS_MOAB_BUILD_DIR=${ITAPS_MOAB_BUILD_DIR:-"${ITAPS_MOAB_FILE%.tar*}"}

export ITAPS_FMDB_FILE=${ITAPS_FMDB_FILE:-"ITAPS-FMDB-1.0-15Apr09.tar.gz"}
export ITAPS_FMDB_VERSION=${ITAPS_FMDB_VERSION:-"1.0-15Apr09"}
export ITAPS_FMDB_COMPATIBILITY_VERSION=${ITAPS_FMDB_COMPATIBILITY_VERSION:-"1.0-15Apr09"}
export ITAPS_FMDB_BUILD_DIR=${ITAPS_FMDB_BUILD_DIR:-"${ITAPS_FMDB_FILE%.tar*}"}

export ITAPS_GRUMMP_FILE=${ITAPS_GRUMMP_FILE:-"ITAPS-GRUMMP-0.5.0-20Apr09.tar.gz"}
export ITAPS_GRUMMP_VERSION=${ITAPS_GRUMMP_VERSION:-"0.5.0-20Apr09"}
export ITAPS_GRUMMP_COMPATIBILITY_VERSION=${ITAPS_GRUMMP_COMPATIBILITY_VERSION:-"0.5.0-20Apr09"}
export ITAPS_GRUMMP_BUILD_DIR=${ITAPS_GRUMMP_BUILD_DIR:-"${ITAPS_GRUMMP_FILE%.tar*}"}

export VISUS_FILE=${VISUS_FILE:-"visus_26Feb07.tar.gz"}
export VISUS_VERSION=${VISUS_VERSION:-"1.0.0"}
export VISUS_COMPATIBILITY_VERSION=${VISUS_COMPATIBILITY_VERSION:-"1.0"}
export VISUS_BUILD_DIR=${VISUS_BUILD_DIR:-"visus"}

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 ICET_FILE=${ICET_FILE:-"IceT-0-5-4.tar.gz"}
export ICET_VERSION=${ICET_VERSION:-"0.5.4"}
export ICET_COMPATIBILITY_VERSION=${ICET_COMPATIBILITY_VERSION:-"0.5.4"}
export ICET_BUILD_DIR=${ICET_BUILD_DIR:-"IceT-0-5-4"}

# Dialog-related variables.
DLG="dialog"
DLG_BACKTITLE="VisIt $VISIT_VERSION Build Process"
DLG_HEIGHT="5"
DLG_WIDTH="60"
DLG_WIDTH_WIDE="80"

# *************************************************************************** #
# 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                                          #
#                                                                             #
# *************************************************************************** #
function warn
{
    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: error                                                             #
#                                                                             #
# Purpose: Report an error message and exit.                                  #
#                                                                             #
# Programmer: Tom Fogal                                                       #
# Date: Fri Oct  3 09:37:51 MDT 2008                                          #
#                                                                             #
# *************************************************************************** #

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 list." 
    fi
    exit 1
}

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

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

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

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

# *************************************************************************** #
# Function: 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"
    else
        warn "unsupported uncompression 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;;
        esac
    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}
               ;;
        esac
    fi
}

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

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

    # Ok, if any of above had succeeded, they would have returned early.
    # So, now try various places listed.
    # try all sites listed incl. falling back to visit's 3rd_party
    for site in $* https://wci.llnl.gov/codes/visit/3rd_party; do
        try_download_file $site/$dfile $dfile
    if [[ $? == 0 ]] ; then
        return 0
    fi
    done
    info "Failed to download $dfile" 
    return 1 
}

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

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

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


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

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

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

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

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

    if [[ $# == 2 ]]; then
        BUILD_VERSION=$2
    fi
    
    if [[ $BUILD_VERSION != "" ]]; then
        INSTALL_DIR=$VISITDIR/$BUILD_NAME/$BUILD_VERSION/$VISITARCH
    else
        INSTALL_DIR=$VISITDIR/$BUILD_NAME/$VISITARCH
    fi
    
    if [[ -d ${INSTALL_DIR} ]] ; then
        return 0
    else
        return 1
    fi
}

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

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


# *************************************************************************** #
# Function: prepare_build_dir                                                 #
#                                                                             #
# Purpose: Helper that prepares a build directory from a src file.            #
#                                                                             #
# Returns:                                                                    #
#          -1 on failure                                                      #
#           0 for success without untar                                       #
#           1 for success with untar                                          #
#                                                                             #
# Programmer: Cyrus Harrison                                                  #
# Date: Thu Nov 13 09:28:26 PST 2008                                          #
#                                                                             #
# *************************************************************************** #
function prepare_build_dir
{
    BUILD_DIR=$1
    SRC_FILE=$2
    
    untarred_src=0
    if [[ -d ${BUILD_DIR} ]] ; then
       info "Found ${BUILD_DIR} . . ."
       untarred_src=0
    elif [[ -f ${SRC_FILE} ]] ; then
       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.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
       check_visit_source_code
       if [[ $? != 0 ]]; then
           return 1
       fi
    fi

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


# *************************************************************************** #
#                    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.                      #
#
# Modifications:                                                              #
#
#    Thomas R. Treadway, Fri Feb  1 15:14:10 PST 2008
#    Check if the directory has already be untarred.
#
#    Cyrus Harrison, Fri Nov 14 08:21:21 PST 2008
#    Use helper function.
#
#    Hank Childs, Tue Nov 10 08:16:21 PST 2009
#    Have CMake, Python, and Mesa be dependencies for VTK.
#
#    Cyrus Harrison, Mon Dec 14 12:55:13 PST 2009
#    Keep dependencies for VTK (CMake, Python, and Mesa) but made sure they
#    are only checked once.
#
# *************************************************************************** #

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

    #
    # Check for required files.
    #

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

    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

    if [[ "$DO_MESA" == "yes" || "$DO_VTK" == "yes" ]] ; then
        ensure_built_or_ready "mesa"   $MESA_VERSION   $MESA_BUILD_DIR   $MESA_FILE $MESA_URL
        if [[ $? != 0 ]] ; then
            return 1
        fi
    fi

    if [[ "$DO_VTK" == "yes" ]] ; then
        ensure_built_or_ready "vtk"    $VTK_VERSION    $VTK_BUILD_DIR    $VTK_FILE
        if [[ $? != 0 ]] ; then
            return 1
        fi
    fi

    if [[ "$DO_QT" == "yes" ]] ; then
        ensure_built_or_ready "qt"     $QT_VERSION    $QT_BUILD_DIR    $QT_FILE
        if [[ $? != 0 ]] ; then
            return 1
        fi
    fi

    return 0
}

# *************************************************************************** #
#                   Function 1.0, check_visit_source_code                     #
# --------------------------------------------------------------------------- #
# This function will check to make sure that the VisIt source code            #
# actually exists.                                                            #
# *************************************************************************** #

function check_visit_source_code
{
    # Check-out the latest svn sources, before building VisIt
    if [[ "$DO_SVN" == "yes" && "$USE_VISIT_FILE" == "no" ]] ; then
        if [[ -d src ]] ; then
           info "Found VisIt SVN src directory, using that . . ."
        else
           # Print a dialog screen
           info "SVN check-out of VisIt . . ."
           if [[ "$DO_REVISION" == "yes" && "$SVNREVISION" != "" ]] ; then
               svn co --quiet --non-interactive --revision "$SVNREVISION" \
                  $SVN_ROOT_PATH/trunk/src
           else
               svn co --quiet --non-interactive $SVN_ROOT_PATH/trunk/src
           fi
           if [[ $? != 0 ]] ; then
               warn "Unable to build VisIt.  SVN download failed."
               return 1
           fi
        fi

    # Build using (the assumed) existing VisIt svn "src" directory
    elif [[ -d src ]] ; then
           info "Found VisIt SVN src directory found, using it."

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

# *************************************************************************** #
#                   Function 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.                  #
#
# Modifications:                                                              #
#
#    Hank Childs, Fri Feb  1 09:38:58 PST 2008
#    Issue a better error message for Mili.
#
#    Thomas R. Treadway, Fri Feb  1 15:14:10 PST 2008
#    Check if the directory has already be untarred.
#
#    Hank Childs, Fri Jun 13 14:31:47 PDT 2008
#    Add support for tcmalloc / google perftools.
#
#    Hank Childs, Tue Jan 27 10:14:53 PST 2009
#    Merge in changes from 1.12RC, including build of FastBit. 
#    Also change code to fail if download is unsuccessful.
#
#    Brad Whitlock, Mon Sep 21 09:57:52 PDT 2009
#    Added AdvIO support.
#
# *************************************************************************** #

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

    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

    if [[ "$DO_BOXLIB" == "yes" ]] ; then
        ensure_built_or_ready "boxlib"  "" $BOXLIB_BUILD_DIR  $BOXLIB_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_BOXLIB="no"
            error "Unable to build Boxlib.  ${BOXLIB_FILE} not found."
        fi
    fi
    
    if [[ "$DO_CCMIO" == "yes" ]] ; then
        ensure_built_or_ready "ccmio"  $CCMIO_VERSION $CCMIO_BUILD_DIR  $CCMIO_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_CCMIO="no"
            error "Unable to build CCMIO.  ${CCMIO_FILE} not found."
        fi
    fi
    
    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
    
    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

    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

    if [[ "$DO_EXODUS" == "yes" ]] ; then
        ensure_built_or_ready "exodus" $EXODUS_VERSION $EXODUS_BUILD_DIR $EXODUS_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_EXODUS="no"
            error "Unable to build ExodusII.  ${EXODUS_FILE} not found."
        fi
    fi
    
    if [[ "$DO_GDAL" == "yes" ]] ; then
        ensure_built_or_ready "gdal" $GDAL_VERSION $GDAL_BUILD_DIR $GDAL_FILE http://dl.maptools.org/dl/gdal
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_GDAL="no"
            error "Unable to build GDAL.  ${GDAL_FILE} not found."
        fi
    fi
    
    if [[ "$DO_H5PART" == "yes" ]] ; then
        ensure_built_or_ready "h5part" $H5PART_VERSION $H5PART_BUILD_DIR $H5PART_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_H5PART="no"
            error "Unable to build H5Part.  ${H5PART_FILE} not found."
        fi
    fi
    
    if [[ "$DO_HDF4" == "yes" ]] ; then
        ensure_built_or_ready "hdf4" $HDF4_VERSION $HDF4_BUILD_DIR $HDF4_FILE http://www.hdfgroup.org/ftp/HDF/prev-releases
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_HDF4="no"
            error "Unable to build HDF4.  ${HDF4_FILE} not found."
        fi
    fi
    
    if [[ "$DO_HDF5" == "yes" ]] ; 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
    
    if [[ "$DO_ITAPS" == "yes" ]] ; then
        ensure_built_or_ready "itaps" $ITAPS_MOAB_VERSION $ITAPS_MOAB_BUILD_DIR  $ITAPS_MOAB_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_ITAPS="no"
            error "Unable to build ITAPS_MOAB.  ${ITAPS_MOAB_FILE} not found."
        fi
        ensure_built_or_ready "itaps" $ITAPS_FMDB_VERSION $ITAPS_FMDB_BUILD_DIR  $ITAPS_FMDB_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_ITAPS="no"
            error "Unable to build ITAPS_FMDB.  ${ITAPS_FMDB_FILE} not found."
        fi
        ensure_built_or_ready "itaps" $ITAPS_GRUMMP_VERSION $ITAPS_GRUMMP_BUILD_DIR  $ITAPS_GRUMMP_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_ITAPS="no"
            error "Unable to build ITAPS_GRUMMP.  ${ITAPS_GRUMMP_FILE} not found."
        fi
    fi
    
    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
    
    if [[ "$DO_NETCDF" == "yes" ]] ; 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
    
    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
    
    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
    
    if [[ "$DO_VISUS" == "yes" ]] ; then
        ensure_built_or_ready "visus" $VISUS_VERSION $VISUS_BUILD_DIR $VISUS_FILE
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_VISUS="no"
            error "Unable to build ViSUS.  ${VISUS_FILE} not found."
        fi
    fi
    
    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
    
    if [[ "$DO_ICET" == "yes" && "$PREVENT_ICET" != "yes" ]] ; then
        ensure_built_or_ready "icet" $ICET_VERSION $ICET_BUILD_DIR $ICET_FILE "http://www.cs.unm.edu/~kmorel/IceT"
        if [[ $? != 0 ]] ; then
            ANY_ERRORS="yes"
            DO_ICET="no"
            error "Unable to build Ice-T.  ${ICET_FILE} not found."
        fi
    fi
}

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

function check_more_options
{

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

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

    return 0
}

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

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

}


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

function check_parallel
{
    rv=0

    #
    # 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=""
        if [[ "$PAR_COMPILER" != "" ]] ; then
            export VISIT_MPI_COMPILER=$PAR_COMPILER
            info \
                "Configuring with mpi compiler wrapper: $VISIT_MPI_COMPILER"
            return 0
        fi

        #
        # Check the environment that mpicc would set up as a first stab.
        #
        MPICC_CPPFLAGS=""
        MPICC_LDFLAGS=""
        MPIWRAPPER=$(which mpic++)
        if [[ "${MPIWRAPPER#no }" != "${MPIWRAPPER}" ]] ; then
           MPIWRAPPER=""
        fi
        if [[ "$MPIWRAPPER" == "" ]] ; then
            MPIWRAPPER=$(which mpicxx)
            if [[ "${MPIWRAPPER#no }" != "${MPIWRAPPER}" ]] ; then
                MPIWRAPPER=""
            fi
            if [[ "$MPIWRAPPER" == "" ]] ; then
                MPIWRAPPER=$(which mpiCC)
                if [[ "${MPIWRAPPER#no }" != "${MPIWRAPPER}" ]] ; then
                    MPIWRAPPER=""
                fi
                if [[ "$MPIWRAPPER" == "" ]] ; then
                    MPIWRAPPER=$(which mpicc)
                    if [[ "${MPIWRAPPER#no }" != "${MPIWRAPPER}" ]] ; then
                        MPIWRAPPER=""
                    fi
                    if [[ "$MPIWRAPPER" == "" ]] ; then
                        warn "Unable to find mpiCC..."
                    fi
                fi
            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
            info \
                "Configuring with mpi compiler wrapper: $VISIT_MPI_COMPILER"
            return 0
        fi

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

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

            PAR_INCLUDE=$PAR_CPPFLAGS

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

            PAR_LIBS=$PAR_LDFLAGS
        fi

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

        # 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 mpic++).
    A mpi compiler wrapper (such as mpic++) to exists in your path.
    The PAR_INCLUDE & PAR_LIBS env vars provide necessary CXX & LDFLAGS to use mpi.

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

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

    return 0
}

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

function check_variables
{

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

           # Remove the extra quoting, new dialog has --single-quoted
           choice="$(cat tmp$$ | sed 's/"//g' )"
           case $retval in
             0)
               for OPTION in $choice
               do
                   case $OPTION in
                     OPSYS)
                        $DLG --backtitle "$DLG_BACKTITLE" \
                           --no-cancel --inputbox \
"Enter $OPTION value:" 0 $DLG_WIDTH_WIDE "$OPSYS" 2> tmp$$
                        OPSYS="$(cat tmp$$)"
                        ;;
                     ARCH)
                        $DLG --backtitle "$DLG_BACKTITLE" \
                           --no-cancel --inputbox \
"Enter $OPTION value:" 0 $DLG_WIDTH_WIDE "$ARCH" 2> tmp$$
                        ARCH="$(cat tmp$$)"
                        ;;
                     C_COMPILER)
                        $DLG --backtitle "$DLG_BACKTITLE" \
                           --no-cancel --inputbox \
"Enter $OPTION value:" 0 $DLG_WIDTH_WIDE "$C_COMPILER" 2> tmp$$
                        C_COMPILER="$(cat tmp$$)"
                        ;;
                     CXX_COMPILER)
                        $DLG --backtitle "$DLG_BACKTITLE" \
                           --no-cancel --inputbox \
"Enter $OPTION value:" 0 $DLG_WIDTH_WIDE "$CXX_COMPILER" 2> tmp$$
                        CXX_COMPILER="$(cat tmp$$)"
                        ;;
                     C_OPT_FLAGS)
                        $DLG --backtitle "$DLG_BACKTITLE" \
                           --no-cancel --inputbox \
"Enter $OPTION value:" 0 $DLG_WIDTH_WIDE "$C_OPT_FLAGS" 2> tmp$$
                        C_OPT_FLAGS="$(cat tmp$$)"
                        ;;
                     CXX_OPT_FLAGS)
                        $DLG --backtitle "$DLG_BACKTITLE" \
                           --no-cancel --inputbox \
"Enter $OPTION value:" 0 $DLG_WIDTH_WIDE "$CXX_OPT_FLAGS" 2> tmp$$
                        CXX_OPT_FLAGS="$(cat tmp$$)"
                        ;;
                     VISITARCH)
                        $DLG --backtitle "$DLG_BACKTITLE" \
                           --no-cancel --inputbox \
"Enter $OPTION value:" 0 $DLG_WIDTH_WIDE "$VISITARCHTMP" 2> tmp$$
                        VISITARCH="$(cat tmp$$)"
                        ;;
                     REVISION)
                        $DLG --backtitle "$DLG_BACKTITLE" \
                           --no-cancel --inputbox \
"Enter $OPTION value:" 0 $DLG_WIDTH_WIDE "$SVNREVISION" 2> tmp$$
                        SVNREVISION="$(cat tmp$$)"
                        DO_SVN="yes"
                        DO_REVISION="yes"
                        ;;
                   esac
               done
               ;;
             1)
               warn "Cancel pressed."
               ;;
             255)
               warn "ESC pressed.";;
             *)
               warn "Unexpected return code: $retval";;
           esac
       fi
       if [[ -e "tmp$$" ]] ; then
           rm tmp$$
       fi
    fi

    return 0
}

function apply_mesa_75_patch_1
{
   patch -p0 <<\EOF
diff -c a/src/mesa/main/config.h Mesa-7.5/src/mesa/main/config.h
*** a/src/mesa/main/config.h
--- Mesa-7.5/src/mesa/main/config.h
***************
*** 138,146 ****
  /** 
   * Maximum viewport/image width. Must accomodate all texture sizes too. 
   */
! #define MAX_WIDTH 4096
  /** Maximum viewport/image height */
! #define MAX_HEIGHT 4096
  
  /** Maxmimum size for CVA.  May be overridden by the drivers.  */
  #define MAX_ARRAY_LOCK_SIZE 3000
--- 138,146 ----
  /** 
   * Maximum viewport/image width. Must accomodate all texture sizes too. 
   */
! #define MAX_WIDTH 16384
  /** Maximum viewport/image height */
! #define MAX_HEIGHT 16384
  
  /** Maxmimum size for CVA.  May be overridden by the drivers.  */
  #define MAX_ARRAY_LOCK_SIZE 3000
EOF
   if [[ $? != 0 ]] ; then
        warn "Unable to apply patch 1 to Mesa 7.5."
        return 1
   else
        return 0
   fi
}

function apply_mesa_75_patch_2
{
    patch -p0 <<\EOF
diff -c a/configure.ac Mesa-7.5/configure.ac
*** a/configure.ac
--- Mesa-7.5/configure.ac
***************
*** 224,229 ****
--- 224,231 ----
          LIB_EXTENSION='dylib' ;;
      cygwin* )
          LIB_EXTENSION='dll' ;;
+     aix* )
+         LIB_EXTENSION='a' ;;
      * )
          LIB_EXTENSION='so' ;;
      esac
EOF

    if [[ $? != 0 ]] ; then
        warn "Unable to apply patch 2 to Mesa 7.5."
        return 1
    else
        return 0
   fi
}

function apply_mesa_75_patch_3
{
    patch -p0 <<\EOF
diff -c a/progs/Makefile Mesa-7.5/progs/Makefile
*** a/progs/Makefile
--- Mesa-7.5/progs/Makefile
***************
*** 4,10 ****
  
  include $(TOP)/configs/current
  
! SUBDIRS = $(PROGRAM_DIRS)
  
  
  default: message subdirs
--- 4,10 ----
  
  include $(TOP)/configs/current
  
! SUBDIRS ="$(PROGRAM_DIRS)"
  
  
  default: message subdirs
***************
*** 15,32 ****
  
  
  subdirs:
! 	@for dir in $(SUBDIRS) ; do \
! 		if [ -d $$dir ] ; then \
! 			(cd $$dir && $(MAKE)) || exit 1 ; \
! 		fi \
! 	done
  
  # Dummy install target
  install:
  
  clean:
! 	-@for dir in $(SUBDIRS) tests ; do \
! 		if [ -d $$dir ] ; then \
! 			(cd $$dir && $(MAKE) clean) ; \
! 		fi \
! 	done
--- 15,36 ----
  
  
  subdirs:
! 	@if test -n "$(SUBDIRS)" ; then \
! 		for dir in $(SUBDIRS) ; do \
! 			if [ -d $$dir ] ; then \
! 				(cd $$dir && $(MAKE)) || exit 1 ; \
! 			fi \
! 		done \
! 	fi
  
  # Dummy install target
  install:
  
  clean:
! 	-@if test -n "$(SUBDIRS)" ; then \
! 		for dir in $(SUBDIRS) tests ; do \
! 			if [ -d $$dir ] ; then \
! 				(cd $$dir && $(MAKE) clean) ; \
! 			fi \
! 		done \
! 	fi
EOF

    if [[ $? != 0 ]] ; then
        warn "Unable to apply patch 3 to Mesa 7.5."
        return 1
    else
        return 0
   fi
}


function apply_mesa_75_patch_4
{
    patch -p0 <<\EOF
diff -c a/src/mesa/main/compiler.h Mesa-7.5/src/mesa/main/compiler.h
*** a/src/mesa/main/compiler.h
--- Mesa-7.5/src/mesa/main/compiler.h
***************
*** 233,239 ****
  #elif defined(__APPLE__)
  #include <CoreFoundation/CFByteOrder.h>
  #define CPU_TO_LE32( x )	CFSwapInt32HostToLittle( x )
! #else /*__linux__ __APPLE__*/
  #include <sys/endian.h>
  #define CPU_TO_LE32( x )	bswap32( x )
  #endif /*__linux__*/
--- 233,244 ----
  #elif defined(__APPLE__)
  #include <CoreFoundation/CFByteOrder.h>
  #define CPU_TO_LE32( x )	CFSwapInt32HostToLittle( x )
! #elif defined(_AIX)
! #define CPU_TO_LE32( x )	x = ((x & 0x000000ff) << 24) | \
! 				    ((x & 0x0000ff00) <<  8) | \
! 				    ((x & 0x00ff0000) >>  8) | \
! 				    ((x & 0xff000000) >> 24);
! #else /*__linux__*/
  #include <sys/endian.h>
  #define CPU_TO_LE32( x )	bswap32( x )
  #endif /*__linux__*/
EOF

    if [[ $? != 0 ]] ; then
        warn "Unable to apply patch 4 to Mesa 7.5."
        return 1
    else
        return 0
   fi
}


function apply_mesa_patch
{
   info "Patching Mesa . . ."
   if [[ ${MESA_VERSION} == 7.5 ]] ; then
      apply_mesa_75_patch_1
      if [[ $? != 0 ]] ; then
        return 1
      fi
      apply_mesa_75_patch_2
      if [[ $? != 0 ]] ; then
        return 1
      fi
      apply_mesa_75_patch_3
      if [[ $? != 0 ]] ; then
        return 1
      fi
      apply_mesa_75_patch_4
      if [[ $? != 0 ]] ; then
        return 1
      fi
   else
       warn "Unsupported Mesa Version ${MESA_VERSION}"
       return 1
   fi

   return 0
}


function build_mesa
{
    #
    # prepare build dir
    #
    prepare_build_dir $MESA_BUILD_DIR $MESA_FILE
    untarred_mesa=$?

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

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

    #
    # Build Mesa.
    #
    info "Building Mesa . . . (~2 minutes)"
    cd $MESA_BUILD_DIR || error "Couldn't cd to mesa build dir."
    PF="${VISITDIR}/mesa/${MESA_VERSION}/${VISITARCH}"

    # We do the build twice due to a VTK issue.  VTK can establish a
    # rendering context via the system's GL using glX, via mangled Mesa
    # using glX, and via offscreen mangled Mesa.  For VisIt, we use
    # either the system's GL, or offscreen mangled Mesa.  To placate
    # VTK, we'll build a mangled+glX version, but then we'll build the
    # offscreen one that we really want.  This ensures we have the 'MesaGL'
    # that VTK needs to link, but if we use 'OSMesa' we get a real, OSMesa
    # library with no glX dependency.
    #
    # Due to this issue, it is imperative that one links "-lOSMesa
    # -lMesaGL" when they want to render/link to an offscreen Mesa
    # context.  The two libraries will have a host of duplicate
    # symbols, and it is important that we pick up the ones from OSMesa.
    info "Configuring Mesa (Mangled glX) ..."
    if [[ "$OPSYS" == "AIX" ]]; then
        export AIX_MESA_CFLAGS="-qcpluscmt -qlanglvl=extc99"
        autoconf
        if [[ $? != 0 ]] ; then
          error "Mesa: AIX autoconf failed!"
        fi
    fi

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

    info 
    
    ./configure \
      CC="${C_COMPILER}" \
      CXX="${CXX_COMPILER}" \
      CFLAGS="${CFLAGS} ${AIX_MESA_CFLAGS} -DUSE_MGL_NAMESPACE"     \
      CXXFLAGS="${CXXFLAGS} -DUSE_MGL_NAMESPACE" \
      --prefix=${PF}               \
      --without-demos              \
      --disable-gallium            \
      --with-driver=xlib           \
      --enable-gl-osmesa           \
      --disable-glw                \
      --disable-glu                \
      --disable-egl ${MESA_STATIC_DYNAMIC}
    if [[ $? != 0 ]] ; then
       warn "Mesa: 'configure' for Mangled glX failed.  Giving up"
       return 1
    fi

    # Make sure we build 'MesaGL*' libraries, to avoid conflict with GL
    # libraries supplied by the vendor.
    cat configs/autoconf | sed -e "s,GL_LIB = GL,GL_LIB=MesaGL,g" > configs/autoconf.edit || return 1
    mv configs/autoconf.edit configs/autoconf
    cat configs/autoconf | sed -e "s,GLU_LIB = GLU,GLU_LIB=MesaGLU,g" > configs/autoconf.edit || return 1
    mv configs/autoconf.edit configs/autoconf

    info "Building Mesa (Mangled glX) ..."
    ${MAKE} ${MAKE_OPT_FLAGS}
    if [[ $? != 0 ]] ; then
       warn "Mesa: 'make' for Mangled glX failed.  Giving up"
       return 1
    fi
    info "Installing Mesa (Mangled glX) ..."
    ${MAKE} install
    if [[ $? != 0 ]] ; then
       warn "Mesa: 'make install' for Mangled glX failed.  Giving up"
       return 1
    fi

    # Now install #2, the OSMesa that we want/need.
    ${MAKE} clean &>/dev/null
    info "Configuring Mesa (Mangled Offscreen) ..."

    # Do not build libMesaGLU unless we're on MacOS X
    DISABLE_GLU="--disable-glu"
    if [[ "$OPSYS" == "Darwin" ]]; then
        DISABLE_GLU=""
        # If we're on 10.4 or earlier, change the GLU exports file
        VER=$(uname -r)
        if [[ ${VER%%.*} -le 9 ]]; then
            rm src/glu/sgi/glu.exports.darwin.edit
            sed "s/_\*/_m/g" src/glu/sgi/glu.exports.darwin > src/glu/sgi/glu.exports.darwin.edit
            cp src/glu/sgi/glu.exports.darwin.edit src/glu/sgi/glu.exports.darwin
        fi
    fi

    ./configure \
      CC="${C_COMPILER}" \
      CXX="${CXX_COMPILER}" \
      CFLAGS="${CFLAGS} ${AIX_MESA_CFLAGS} -DUSE_MGL_NAMESPACE"     \
      CXXFLAGS="${CXXFLAGS} -DUSE_MGL_NAMESPACE" \
      --prefix=${PF}                    \
      --without-demos                   \
      --with-driver=osmesa              \
      --disable-gallium                 \
      --with-max-width=16384            \
      --with-max-height=16384           \
      --disable-glw                     \
      ${DISABLE_GLU}                    \
      --disable-egl  ${MESA_STATIC_DYNAMIC}
    if [[ $? != 0 ]] ; then
       warn "Mesa: 'configure' for Mangled Offscreen failed.  Giving up"
       return 1
    fi
    # Make sure we build 'MesaGL*' libraries, to avoid conflict with GL
    # libraries supplied by the vendor.
    cat configs/autoconf | sed -e "s,GL_LIB = GL,GL_LIB=MesaGL,g" > configs/autoconf.edit || return 1
    mv configs/autoconf.edit configs/autoconf
    cat configs/autoconf | sed -e "s,GLU_LIB = GLU,GLU_LIB=MesaGLU,g" > configs/autoconf.edit || return 1
    mv configs/autoconf.edit configs/autoconf

    info "Building Mesa (Mangled Offscreen) ..."
    ${MAKE} ${MAKE_OPT_FLAGS}
    if [[ $? != 0 ]] ; then
       warn "Mesa: 'make' for Mangled Offscreen failed.  Giving up"
       return 1
    fi
    info "Installing Mesa (Mangled Offscreen) ..."
    ${MAKE} install
    if [[ $? != 0 ]] ; then
       warn "Mesa: 'make install' for Mangled Offscreen failed.  Giving up"
       return 1
    fi

    # Some versions of Mesa erroneously install GLEW as well.  We need to make
    # sure we get VisIt's GLEW when we include it, so remove the ones Mesa
    # installs.
    rm -f ${PF}/include/GL/gl*ew.h

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

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


# *************************************************************************** #
#                          Function 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 Qt4 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://trolltech.com/products/appdev/licensing to view these\
            licenses."

QT_CONFIRM_MSG="VisIt requires Qt4: Please respond with \"yes\" to accept\
                Qt licensing under the terms of the Lesser GNU General \
                Public License (LGPL) version 2.1 or \
                the GNU General Public License (GPL) version 3"
if [[ "$GRAPHICAL" == "yes" ]] ; then
    $DLG --backtitle "$DLG_BACKTITLE" --yesno "$QT_LIC_MSG" 0 0 
    if [[ $? == 1 ]] ; then
        $DLG --backtitle "$DLG_BACKTITLE" --yesno "$QT_CONFIRM_MSG" 0 0 
        if [[ $? == 1 ]] ; then
            return 1
        fi
    fi
else
    info $QT_LIC_MSG
    read RESPONSE
    if [[ "$RESPONSE" != "yes" ]] ; then
        info $QT_CONFIRM_MSG
        read RESPONSE
        if [[ $RESPONSE != "yes" ]] ; then
            return 1
        fi
    fi
fi

return 0
}

function apply_qt_461_patch_1
{
   patch -p0 <<\EOF
diff -c a/src/gui/itemviews/qlistview.cpp qt-everywhere-opensource-src-4.6.1/src/gui/itemviews/qlistview.cpp
*** a/src/gui/itemviews/qlistview.cpp
--- qt-everywhere-opensource-src-4.6.1/src/gui/itemviews/qlistview.cpp
***************
*** 2814,2820 ****
      if (moved.count() != items.count())
          moved.resize(items.count());
  
!     QRect rect(QPoint(), topLeft);
      QListViewItem *item = 0;
      for (int row = info.first; row <= info.last; ++row) {
          item = &items[row];
--- 2814,2821 ----
      if (moved.count() != items.count())
          moved.resize(items.count());
  
!     QPoint zeroPoint;
!     QRect rect(zeroPoint, topLeft);
      QListViewItem *item = 0;
      for (int row = info.first; row <= info.last; ++row) {
          item = &items[row];
EOF
   if [[ $? != 0 ]] ; then
        warn "Unable to apply patch 1 to Qt 4.6.1"
        return 1
   else
        return 0
   fi
}

function apply_qt_461_patch_2
{
   patch -p0 <<\EOF
diff -c a/src/corelib/kernel/qmetaobject.cp qt-everywhere-opensource-src-4.6.1/src/corelib/kernel/qmetaobject.cpp
*** a/src/corelib/kernel/qmetaobject.cpp
--- qt-everywhere-opensource-src-4.6.1/src/corelib/kernel/qmetaobject.cpp
***************
*** 943,949 ****
      if (!type || !*type)
          return result;
  
!     QVarLengthArray<char> stackbuf(int(strlen(type)) + 1);
      qRemoveWhitespace(type, stackbuf.data());
      int templdepth = 0;
      qNormalizeType(stackbuf.data(), templdepth, result);
--- 943,950 ----
      if (!type || !*type)
          return result;
  
!     int len = int(strlen(type)) + 1;
!     QVarLengthArray<char> stackbuf(len);
      qRemoveWhitespace(type, stackbuf.data());
      int templdepth = 0;
      qNormalizeType(stackbuf.data(), templdepth, result);
EOF
   if [[ $? != 0 ]] ; then
        warn "Unable to apply patch 2 to Qt 4.6.1"
        return 1
   else
        return 0
   fi
}

function apply_qt_461_patch_3
{
   patch -p0 <<\EOF
diff -c a/src/corelib/statemachine/qabstractstate_p.h qt-everywhere-opensource-src-4.6.1/src/corelib/statemachine/qabstractstate_p.h
*** a/src/corelib/statemachine/qabstractstate_p.h
--- qt-everywhere-opensource-src-4.6.1/src/corelib/statemachine/qabstractstate_p.h
***************
*** 86,92 ****
      void emitExited();
  
      uint stateType:31;
!     uint isMachine:1;
      mutable QState *parentState;
  };
  
--- 86,92 ----
      void emitExited();
  
      uint stateType:31;
!     bool isMachine;
      mutable QState *parentState;
  };
  
EOF
   if [[ $? != 0 ]] ; then
        warn "Unable to apply patch 3 to Qt 4.6.1"
        return 1
   else
        return 0
   fi
}

function apply_qt_461_patch_4
{
   patch -p0 <<\EOF
diff -c a/src/plugins/graphicssystems/trace/qgraphicssystem_trace.cpp qt-everywhere-opensource-src-4.6.1/src/plugins/graphicssystems/trace/qgraphicssystem_trace.cpp
*** a/src/plugins/graphicssystems/trace/qgraphicssystem_trace.cpp
--- qt-everywhere-opensource-src-4.6.1/src/plugins/graphicssystems/trace/qgraphicssystem_trace.cpp
***************
*** 79,85 ****
  QTraceWindowSurface::~QTraceWindowSurface()
  {
      if (buffer) {
!         QFile outputFile(QString(QLatin1String("qtgraphics-%0.trace")).arg(winId));
          if (outputFile.open(QIODevice::WriteOnly)) {
              QDataStream out(&outputFile);
              out.writeBytes("qttrace", 7);
--- 79,86 ----
  QTraceWindowSurface::~QTraceWindowSurface()
  {
      if (buffer) {
!         QString traceFile = QString(QLatin1String("qtgraphics-%0.trace"));
!         QFile outputFile(traceFile.arg(winId));
          if (outputFile.open(QIODevice::WriteOnly)) {
              QDataStream out(&outputFile);
              out.writeBytes("qttrace", 7);
EOF
   if [[ $? != 0 ]] ; then
        warn "Unable to apply patch 4 to Qt 4.6.1"
        return 1
   else
        return 0
   fi
}

function apply_qt_461_patch
{
   apply_qt_461_patch_1
   if [[ $? != 0 ]] ; then
       return 1
   fi
   apply_qt_461_patch_2
   if [[ $? != 0 ]] ; then
       return 1
   fi
   apply_qt_461_patch_3
   if [[ $? != 0 ]] ; then
       return 1
   fi
   apply_qt_461_patch_4
   if [[ $? != 0 ]] ; then
       return 1
   fi
}

function apply_qt_patch
{
   if [[ ${QT_VERSION} == 4.6.1 ]] ; then
       apply_qt_461_patch
       if [[ $? != 0 ]] ; then
           return 1
       fi
   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 Qt4 build directory. Giving Up!"
       return 1
    fi

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

    cd $QT_BUILD_DIR || error "Can't cd to Qt build dir."

    #
    # Platform specific configuration
    #
    if [[ "$OPSYS" == "Darwin" ]] ; then
        # Determine if we build with Cocoa
        VER=$(uname -r)
        if [[ ${VER%%.*} -ge 10 ]] ; then
            EXTRA_QT_FLAGS="$EXTRA_QT_FLAGS -cocoa"
        fi
        # Figure out whether we need to build 64-bit version of Qt
        echo "int main() {}" >> arch_test.c
        ${C_COMPILER} arch_test.c -o arch_test
        GCC_BUILD_ARCH=$(lipo -info arch_test | sed -e 's/[^x]*//')
        rm arch_test.c arch_test
        if [[ "$GCC_BUILD_ARCH" == "x86_64" ]] ; then
            EXTRA_QT_FLAGS="$EXTRA_QT_FLAGS -arch x86_64"
        fi
    elif [[ "$OPSYS" == "Linux" ]] ; then
         # For OLD versions of linux, disable openssl
        VER=$(uname -r)
        if [[ "${VER:0:3}" == "2.4" ]] ; then
            EXTRA_QT_FLAGS="$EXTRA_QT_FLAGS -no-openssl"
        fi
    fi 

    # We may be building statically.
    if [[ "$DO_STATIC_BUILD" == "yes" ]]; then
        # Protect the build by NOT using the system versions of the I/O libraries.
        EXTRA_QT_FLAGS="$EXTRA_QT_FLAGS -static -qt-libtiff -qt-libpng -qt-libmng -qt-libjpeg"
    fi

    #
    # Call configure
    #
    qt_flags=""
    qt_flags="${qt_flags} -no-qt3support"
    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-xmlpatterns"
    qt_flags="${qt_flags} -no-libtiff"
    qt_flags="${qt_flags} -no-webkit"
    if [[ ${QT_VERSION} == 4.6.1 ]] ; then
        qt_flags="${qt_flags} -no-javascript-jit"
        qt_flags="${qt_flags} -no-script"
        qt_flags="${qt_flags} -no-scripttools"
    fi
    info "Configuring Qt4: ./configure --prefix=${VISITDIR}/qt/${QT_VERSION}/${VISITARCH}/" \
         "-platform ${QT_PLATFORM}" \
         "-make libs -make tools -fast -no-separate-debug-info" \
         "${qt_flags}" \
         "${EXTRA_QT_FLAGS}"
   (echo "o"; echo "yes") | ./configure --prefix=${VISITDIR}/qt/${QT_VERSION}/${VISITARCH}/ \
                    -platform ${QT_PLATFORM} \
                    -make libs -make tools -fast -no-separate-debug-info \
                    ${qt_flags} \
                    ${EXTRA_QT_FLAGS} | tee qt.config.out
    
    if [[ $? != 0 ]] ; then
       warn "Qt4 configure failed. Giving up."
       return 1
    fi

    #
    # Figure out if configure found the OpenGL libraries
    #
    if [[ "${DO_DBIO_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 "Qt4 configure did not find OpenGL." \
                "VisIt needs Qt4 with enabled OpenGL support. Giving up."
          return 1
       fi
    fi

    #
    # Build Qt4. Config options above make sure we only build the libs & tools.
    #
    info "Building Qt4 . . . (~60 minutes)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "Qt4 build failed.  Giving up"
       return 1
    fi

    info "Installing Qt4 . . . "
    $MAKE install

    #
    # 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
    elif [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" && $ABS_PATH == "no" ]]; then
        QtTopDir="${VISITDIR}/qt/${QT_VERSION}/${VISITARCH}"
        QtFrameworks="QtCore QtGui QtNetwork QtOpenGL QtScript QtSvg QtXml"
        for QtFW in $QtFrameworks; do
            filename="$QtTopDir/lib/${QtFW}.framework/${QtFW}"
            debugFilename="${filename}_debug"
            oldSOName=$(otool -D $filename | tail -n -1)
            oldDebugSOName=$(otool -D $debugFilename | tail -n -1)
            internalFWPath=$(echo $oldSOName | sed -e 's/.*\.framework\///')
            internalDebugFWPath=$(echo $oldDebugSOName | sed -e 's/.*\.framework\///')
            newSOName="@executable_path/../lib/${QtFW}.framework/$internalFWPath"
            newDebugSOName="@executable_path/../lib/${QtFW}.framework/$internalDebugFWPath"
            install_name_tool -id $newSOName $filename
            install_name_tool -id $newDebugSOName $debugFilename
            for otherQtFW in $QtFrameworks; do
                install_name_tool -change $oldSOName $newSOName $QtTopDir/lib/${otherQtFW}.framework/${otherQtFW}
                install_name_tool -change $oldSOName $newSOName $QtTopDir/lib/${otherQtFW}.framework/${otherQtFW}_debug
            done
        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 Qt4"

    return 0
}

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

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

    #
    # 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 6, build_vtk                            #
# *************************************************************************** #

function apply_vtk_500d_generic_patch_1
{
  patch -p0 << \EOF
diff -c a/Utilities/DICOMParser/DICOMParser.cxx VTK/Utilities/DICOMParser/DICOMParser.cxx
*** a/Utilities/DICOMParser/DICOMParser.cxx
--- VTK/Utilities/DICOMParser/DICOMParser.cxx
***************
*** 37,42 ****
--- 37,43 ----
  #endif
  
  #include <string>
+ #include <string.h>
  #include <map>
  
  #include "DICOMConfig.h"
EOF
  if [[ $? != 0 ]] ; then
     warn "Unable to patch VTK. Wrong version?"
     return 1
  fi

  return 0
}

function apply_vtk_500d_generic_patch_2
{
   patch -p0 << \EOF
diff -c a/Utilities/DICOMParser/DICOMAppHelper.cxx VTK/Utilities/DICOMParser/DICOMAppHelper.cxx
*** a/Utilities/DICOMParser/DICOMAppHelper.cxx
--- VTK/Utilities/DICOMParser/DICOMAppHelper.cxx
***************
*** 32,37 ****
--- 32,38 ----
  #include <stdlib.h>
  #include <stdio.h>
  #include <string>
+ #include <string.h>
  #include <math.h>
  #include <algorithm>
  
EOF
   if [[ $? != 0 ]] ; then
      warn "Unable to patch VTK. Wrong version?"
      return 1
   fi
}

function apply_vtk_500d_generic_patch_3
{
   patch -p0 << \EOF
diff -c a/Utilities/DICOMParser/DICOMFile.cxx VTK/Utilities/DICOMParser/DICOMFile.cxx
*** a/Utilities/DICOMParser/DICOMFile.cxx
--- VTK/Utilities/DICOMParser/DICOMFile.cxx
***************
*** 24,29 ****
--- 24,30 ----
  
  #include <stdio.h>
  #include <string>
+ #include <string.h>
  
  #include "DICOMConfig.h"
  #include "DICOMFile.h"
EOF
    if [[ $? != 0 ]] ; then
       warn "Unable to patch VTK. Wrong version?"
       return 1
    fi
}

function apply_vtk_500d_generic_patch_4
{
   patch -p0 << \EOF
diff -c a/CMake/cmVTKGenerateJavaDependencies.c VTK/CMake/cmVTKGenerateJavaDependencies.c
*** a/CMake/cmVTKGenerateJavaDependencies.c
--- VTK/CMake/cmVTKGenerateJavaDependencies.c
***************
*** 43,49 ****
    const char *endTempFile;
  
    FILE* outfile = 0;
!   const char* filename = 0;
  
    if(argc < 2 )
      {
--- 43,49 ----
    const char *endTempFile;
  
    FILE* outfile = 0;
!   char* filename = 0;
  
    if(argc < 2 )
      {
EOF
    if [[ $? != 0 ]] ; then
       warn "Unable to patch VTK. Wrong version?"
       return 1
    fi
}

function apply_vtk_500d_generic_patch_5
{
   patch -p0 << \EOF
diff -c a/CMake/cmVTKWrapPython2Command.c VTK/CMake/cmVTKWrapPython2Command.c
*** a/CMake/cmVTKWrapPython2Command.c
--- VTK/CMake/cmVTKWrapPython2Command.c
***************
*** 124,130 ****
      return 0;
      }
    
!   info->CAPI->ExpandSourceListArguments(mf, argc, argv, 
                                          &newArgc, &newArgv, 2);
    
    /* Now check and see if the value has been stored in the cache */
--- 124,130 ----
      return 0;
      }
    
!   info->CAPI->ExpandSourceListArguments(mf, argc, (const char **)argv, 
                                          &newArgc, &newArgv, 2);
    
    /* Now check and see if the value has been stored in the cache */
***************
*** 233,239 ****
    info->CAPI->SourceFileSetProperty(cfile,"ABSTRACT","0");
    newName = (char *)malloc(strlen(newArgv[0]) + 5);
    sprintf(newName,"%sInit",newArgv[0]);
!   CreateInitFile(info,mf,newArgv[0],numClasses,classes);
    info->CAPI->SourceFileSetName2(cfile, newName, 
                                   info->CAPI->GetCurrentOutputDirectory(mf),
                                   "cxx",0);
--- 233,239 ----
    info->CAPI->SourceFileSetProperty(cfile,"ABSTRACT","0");
    newName = (char *)malloc(strlen(newArgv[0]) + 5);
    sprintf(newName,"%sInit",newArgv[0]);
!   CreateInitFile(info,mf,newArgv[0],numClasses,(const char **)classes);
    info->CAPI->SourceFileSetName2(cfile, newName, 
                                   info->CAPI->GetCurrentOutputDirectory(mf),
                                   "cxx",0);
***************
*** 301,307 ****
      numArgs++;
      info->CAPI->AddCustomCommand(mf, args[0],
                         wpython, numArgs, args, numDepends, depends, 
!                        1, &res, cdata->LibraryName);
      free(res);
      }
  }
--- 301,307 ----
      numArgs++;
      info->CAPI->AddCustomCommand(mf, args[0],
                         wpython, numArgs, args, numDepends, depends, 
!                        1, (const char **) &res, cdata->LibraryName);
      free(res);
      }
  }
EOF
    if [[ $? != 0 ]] ; then
       warn "Unable to patch VTK. Wrong version?"
       return 1
    fi
}

function apply_vtk_500d_generic_patch_6
{
   patch -p0 << \EOF
diff -c a/CMake/cmVTKWrapTcl2Command.c VTK/CMake/cmVTKWrapTcl2Command.c
*** a/CMake/cmVTKWrapTcl2Command.c
--- VTK/CMake/cmVTKWrapTcl2Command.c
***************
*** 203,214 ****
    
    if (!strcmp(argv[1],"SOURCES"))
      {
!     info->CAPI->ExpandSourceListArguments(mf, argc, argv, &newArgc, 
                                            &newArgv, 3);
      }
    else
      {
!     info->CAPI->ExpandSourceListArguments(mf, argc, argv, 
                                            &newArgc, &newArgv, 2);
      }
    
--- 203,214 ----
    
    if (!strcmp(argv[1],"SOURCES"))
      {
!     info->CAPI->ExpandSourceListArguments(mf, argc, (const char **)argv, &newArgc, 
                                            &newArgv, 3);
      }
    else
      {
!     info->CAPI->ExpandSourceListArguments(mf, argc, (const char **)argv, 
                                            &newArgc, &newArgv, 2);
      }
    
***************
*** 350,356 ****
      info->CAPI->SourceFileSetProperty(cfile,"ABSTRACT","0");
      newName = (char *)malloc(strlen(argv[0]) + 5);
      sprintf(newName,"%sInit",argv[0]);
!     CreateInitFile(info,mf,argv[0],numConcrete,concrete,numCommands,commands);
      info->CAPI->SourceFileSetName2(cfile, newName, 
                                     info->CAPI->GetCurrentOutputDirectory(mf),
                                     "cxx",0);
--- 350,356 ----
      info->CAPI->SourceFileSetProperty(cfile,"ABSTRACT","0");
      newName = (char *)malloc(strlen(argv[0]) + 5);
      sprintf(newName,"%sInit",argv[0]);
!     CreateInitFile(info,mf,argv[0],numConcrete,(const char **)concrete,numCommands,(const char **)commands);
      info->CAPI->SourceFileSetName2(cfile, newName, 
                                     info->CAPI->GetCurrentOutputDirectory(mf),
                                     "cxx",0);
***************
*** 429,435 ****
      numArgs++;
      info->CAPI->AddCustomCommand(mf, args[0],
                         wtcl, numArgs, args, numDepends, depends, 
!                        1, &res, cdata->LibraryName);
      free(res);
      }
  }
--- 429,435 ----
      numArgs++;
      info->CAPI->AddCustomCommand(mf, args[0],
                         wtcl, numArgs, args, numDepends, depends, 
!                        1, (const char **)&res, cdata->LibraryName);
      free(res);
      }
  }
EOF
    if [[ $? != 0 ]] ; then
       warn "Unable to patch VTK. Wrong version?"
       return 1
    fi
}

function apply_vtk_500d_darwin_patch
{
   patch -p0 << \EOF
diff -rp a/CMakeLists.txt VTK/CMakeLists.txt
*** a/CMakeLists.txt
--- VTK/CMakeLists.txt
*************** ELSE(CMAKE_COMPILER_IS_GNUCXX)
*** 302,312 ****
  ENDIF(CMAKE_COMPILER_IS_GNUCXX)
  
  IF(APPLE)
!   SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS} -Wl,-flat_namespace,-U,_environ")
!   SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -Wl,-flat_namespace,-U,_environ")
    IF(CMAKE_COMPILER_IS_GNUCXX)
!     SET(VTK_REQUIRED_C_FLAGS "${VTK_REQUIRED_C_FLAGS} -no-cpp-precomp")
!     SET(VTK_REQUIRED_CXX_FLAGS "${VTK_REQUIRED_CXX_FLAGS} -no-cpp-precomp")
      IF(VTK_USE_CARBON)
        SET(VTK_REQUIRED_CXX_FLAGS "${VTK_REQUIRED_CXX_FLAGS} -fpascal-strings")
      ENDIF(VTK_USE_CARBON)
--- 301,311 ----
  ENDIF(CMAKE_COMPILER_IS_GNUCXX)
  
  IF(APPLE)
!   SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS} -Wl,-twolevel_namespace,-headerpad_max_install_names")
!   SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -Wl,-twolevel_namespace,-headerpad_max_install_names")
    IF(CMAKE_COMPILER_IS_GNUCXX)
!     SET(VTK_REQUIRED_C_FLAGS "${VTK_REQUIRED_C_FLAGS} -fno-common -fexceptions")
!     SET(VTK_REQUIRED_CXX_FLAGS "${VTK_REQUIRED_CXX_FLAGS} -fno-common -fexceptions")
      IF(VTK_USE_CARBON)
        SET(VTK_REQUIRED_CXX_FLAGS "${VTK_REQUIRED_CXX_FLAGS} -fpascal-strings")
      ENDIF(VTK_USE_CARBON)
--- 1352,1357 ----
diff -rp a/Rendering/vtkImagingFactory.cxx VTK/Rendering/vtkImagingFactory.cxx
*** a/Rendering/vtkImagingFactory.cxx
--- VTK/Rendering/vtkImagingFactory.cxx
*************** vtkObject* vtkImagingFactory::CreateInst
*** 202,215 ****
--- 202,233 ----
      {
      if(strcmp(vtkclassname, "vtkTextMapper") == 0)
        {
+ #if defined(VTK_USE_MANGLED_MESA)
+       if ( vtkImagingFactory::UseMesaClasses )
+         {
+         return vtkMesaFreeTypeTextMapper::New();
+         }
+ #endif
        return vtkOpenGLFreeTypeTextMapper::New();
        }
      if(strcmp(vtkclassname, "vtkImageMapper") == 0)
        {
+ #if defined(VTK_USE_MANGLED_MESA)
+       if ( vtkImagingFactory::UseMesaClasses )
+         {
+         return vtkMesaImageMapper::New();
+         }
+ #endif
        return vtkOpenGLImageMapper::New();
        }
      if(strcmp(vtkclassname, "vtkPolyDataMapper2D") == 0)
        {
+ #if defined(VTK_USE_MANGLED_MESA)
+       if ( vtkImagingFactory::UseMesaClasses )
+         {
+         return vtkMesaPolyDataMapper2D::New();
+         }
+ #endif
        return vtkOpenGLPolyDataMapper2D::New();
        }
      }
diff -rp a/Utilities/ftgl/CMakeLists.txt VTK/Utilities/ftgl/CMakeLists.txt
*** a/Utilities/ftgl/CMakeLists.txt
--- VTK/Utilities/ftgl/CMakeLists.txt
*************** IF(NOT OPENGL_FOUND)
*** 134,144 ****
  ENDIF(NOT OPENGL_FOUND)
  SET (VTKFTGL_LIBS "${VTKFTGL_LIBS};${OPENGL_gl_LIBRARY}")
  
! IF(WIN32)
    IF (FTGL_SUPPORT_MANGLE_MESA)
      SET (VTKFTGL_LIBS "${VTKFTGL_LIBS};${MANGLED_MESA_LIBRARY}")
    ENDIF (FTGL_SUPPORT_MANGLE_MESA)
! ENDIF(WIN32)
  
  #
  # We obviously need FreeType
--- 134,144 ----
  ENDIF(NOT OPENGL_FOUND)
  SET (VTKFTGL_LIBS "${VTKFTGL_LIBS};${OPENGL_gl_LIBRARY}")
  
! IF(APPLE OR WIN32)
    IF (FTGL_SUPPORT_MANGLE_MESA)
      SET (VTKFTGL_LIBS "${VTKFTGL_LIBS};${MANGLED_MESA_LIBRARY}")
    ENDIF (FTGL_SUPPORT_MANGLE_MESA)
! ENDIF(APPLE OR WIN32)
  
  #
  # We obviously need FreeType
EOF
   if [[ $? != 0 ]] ; then
      warn "VTK patch for V5.0.0c and Darwin failed."
      return 1
   fi

   # Check for version 6.x.x (MacOS 10.2, Jaguar)
   VER=$(uname -r)
   if (( ${VER%%.*} < 7 )) ; then
       patch -p0 << \EOF
diff -rp a/Rendering/vtkCarbonRenderWindow.cxx VTK/Rendering/vtkCarbonRenderWindow.cxx
*** a/Rendering/vtkCarbonRenderWindow.cxx
--- VTK/Rendering/vtkCarbonRenderWindow.cxx
*************** void vtkCarbonRenderWindow::CreateAWindo
*** 737,743 ****
        ShowWindow(this->RootWindow);
      }
  
- 
    // install event handler for updating gl region
    // this works for a supplied HIView and an HIView made here
    if(this->WindowId && !this->RegionEventHandler)
--- 737,742 ----
*************** void vtkCarbonRenderWindow::CreateAWindo
*** 745,751 ****
      EventTypeSpec region_events [] = 
        {
          { kEventClassControl, kEventControlOwningWindowChanged},
!         { kEventClassControl, kEventControlVisibilityChanged },
          { kEventClassControl, kEventControlBoundsChanged }
        };
      this->RegionEventHandlerUPP = NewEventHandlerUPP(vtkCarbonRenderWindow::RegionEventProcessor);
--- 744,750 ----
      EventTypeSpec region_events [] = 
        {
          { kEventClassControl, kEventControlOwningWindowChanged},
!         { kEventClassControl, 157 },
          { kEventClassControl, kEventControlBoundsChanged }
        };
      this->RegionEventHandlerUPP = NewEventHandlerUPP(vtkCarbonRenderWindow::RegionEventProcessor);
*************** WindowPtr vtkCarbonRenderWindow::GetRoot
*** 1145,1151 ****
    // if not, then WindowId is set and we're using HIViews.
    // Instead of storing the RootWindow, we ask for it in case of a dynamic 
    // GUI where the root window can change
!   return this->RootWindow ? this->RootWindow : HIViewGetWindow(this->WindowId);
  }
  
  //----------------------------------------------------------------------------
--- 1144,1150 ----
    // if not, then WindowId is set and we're using HIViews.
    // Instead of storing the RootWindow, we ask for it in case of a dynamic 
    // GUI where the root window can change
!   return this->RootWindow ? this->RootWindow : (WindowPtr)this->WindowId;
  }
  
  //----------------------------------------------------------------------------
*************** OSStatus vtkCarbonRenderWindow::RegionEv
*** 1183,1189 ****
        {
        switch (event_kind)
          {
!         case kEventControlVisibilityChanged:
          case kEventControlOwningWindowChanged:
          case kEventControlBoundsChanged:
            vtk_win->UpdateGLRegion();
--- 1182,1188 ----
        {
        switch (event_kind)
          {
!         case 157:
          case kEventControlOwningWindowChanged:
          case kEventControlBoundsChanged:
            vtk_win->UpdateGLRegion();
EOF
     if [[ $? != 0 ]] ; then
        warn "Unable to patch VTK. Wrong version?"
        return 1
     fi
   fi

   return 0
}

function apply_vtk_500d_generic_patches
{
   apply_vtk_500d_generic_patch_1
   if [[ $? != 0 ]] ; then
       return 1
   fi
   apply_vtk_500d_generic_patch_2
   if [[ $? != 0 ]] ; then
       return 1
   fi
   apply_vtk_500d_generic_patch_3
   if [[ $? != 0 ]] ; then
       return 1
   fi
   apply_vtk_500d_generic_patch_4
   if [[ $? != 0 ]] ; then
       return 1
   fi
   apply_vtk_500d_generic_patch_5
   if [[ $? != 0 ]] ; then
       return 1
   fi
   apply_vtk_500d_generic_patch_6
   if [[ $? != 0 ]] ; then
       return 1
   fi
}

function apply_vtk_500d_patch
{
   apply_vtk_500d_generic_patches
   if [[ $? != 0 ]] ; then
       return 1
   fi

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

   return 0
}

function apply_vtk_patch
{
   if [[ ${VTK_VERSION} == 5.0.0d ]] ; then
       apply_vtk_500d_patch
       if [[ $? != 0 ]] ; then
           return 1
       fi
   fi

   return 0
}

function build_vtk
{
    #
    # CMake is the build system for VTK.  Call another script that will build
    # that program.
    #
    CMAKE_INSTALL="$VISITDIR/cmake/${CMAKE_VERSION}/$VISITARCH/bin"
    if [[ -e ${CMAKE_INSTALL}/cmake ]] ; then
       info "VTK: CMake found"
    else
       build_cmake
       if [[ $? != 0 ]] ; then
          warn "Unable to build cmake.  Giving up"
          return 1
       fi
    fi

    #
    # We need python to build the vtk python bindings.
    #
    PYTHON_INSTALL="$VISITDIR/python/${PYTHON_VERSION}/$VISITARCH/bin"
    if [[ -e ${PYTHON_INSTALL}/python ]] ; then
       info "VTK: Python found"
    else
       build_python
       if [[ $? != 0 ]] ; then
          warn "Unable to build python. Giving up"
          return 1
       fi
    fi

    #
    # We need Mesa to build vtk with mangled Mesa.
    #
    MESA_INSTALL="$VISITDIR/mesa/${MESA_VERSION}/$VISITARCH/lib"
    if [[ -e ${MESA_INSTALL} ]] ; then
       info "VTK: Mesa found"
    else
       build_mesa
       if [[ $? != 0 ]] ; then
          warn "Unable to build Mesa. Giving up"
          return 1
       fi
    fi

    if [[ -d $VTK_BUILD_DIR ]] ; then
        if [[ ! -f $VTK_FILE ]] ; then
           if [[ -f vtk-5.0.0c.tar.gz ]] ; then
               warn "I believe your VTK directory is from VTK5.0.0c.  Deleting"
               rm -Rf $VTK_BUILD_DIR
               ensure_built_or_ready "vtk"    $VTK_VERSION    $VTK_BUILD_DIR    $VTK_FILE
           fi
        fi
    fi
    prepare_build_dir $VTK_BUILD_DIR $VTK_FILE
    untarred_vtk=$?
    if [[ $untarred_vtk == -1 ]] ; then
       warn "Unable to prepare VTK build directory. Giving Up!"
       return 1
    fi

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

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

    VISIT_PYTHON_DIR="$VISITDIR/python/${PYTHON_VERSION}/${VISITARCH}"
    if [[ "$OPSYS" == "Darwin" ]]; then
        export DYLD_LIBRARY_PATH="${VISIT_PYTHON_DIR}/lib/:$DYLD_LIBRARY_PATH"
    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

    #
    # Execute CMake, which will set up the Makefiles for VTK.  (like configure)
    #
    # Linking OSMesa for MANGLED_MESA_LIBRARY is correct here; we'll never use
    # MesaGL, as that is a xlib-based software path.  If we have an X context,
    # we always want to use the 'system's GL library.
    info "Executing CMake on VTK"
    cd $VTK_BUILD_DIR || error "Can't cd to VTK build dir."
    CMAKE_BIN=${CMAKE_INSTALL}/cmake
    if [[ "$DO_STATIC_BUILD" == "yes" ]]; then
        VTK_SHARED_LIBS="OFF"
        LIBEXT="a"
    else
        VTK_SHARED_LIBS="ON"
        LIBEXT="${SO_EXT}"
    fi
    if [[ "$OPSYS" == "Darwin" ]]; then
    VER=$(uname -r)
    if [[ ${VER%%.*} -ge 10 ]] ; then
        echo Snow Leopard detected. Disabling Carbon.
        ${CMAKE_BIN} \
            -DCMAKE_INSTALL_PREFIX:PATH="$VISITDIR/vtk/${VTK_VERSION}/${VISITARCH}"\
            -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON \
            -DVTK_USE_CARBON:BOOL=OFF\
            -DVTK_USE_COCOA:BOOL=ON\
            -DBUILD_SHARED_LIBS:BOOL=${VTK_SHARED_LIBS}\
            -DBUILD_TESTING:BOOL=OFF\
            -DUSE_ANSI_STD_LIB:BOOL=ON\
            -DVTK_USE_MANGLED_MESA:BOOL=ON\
            -DVTK_USE_HYBRID:BOOL=ON\
            -DCMAKE_CXX_FLAGS:STRING="${CXX_OPT_FLAGS}"\
            -DCMAKE_CXX_COMPILER:STRING=${CXX_COMPILER}\
            -DCMAKE_C_FLAGS:STRING="${C_OPT_FLAGS}"\
            -DCMAKE_C_COMPILER:STRING=${C_COMPILER}\
            -DCMAKE_SHARED_LINKER_FLAGS:STRING=-Wl,-headerpad_max_install_names,-compatibility_version,5.0,-current_version,5.0.0\
            -DMANGLED_MESA_INCLUDE_DIR:PATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/include"\
            -DMANGLED_MESA_LIBRARY:FILEPATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/lib/libOSMesa.${LIBEXT}"\
            -DMANGLED_OSMESA_INCLUDE_DIR:PATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/include"\
            -DMANGLED_OSMESA_LIBRARY:FILEPATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/lib/libOSMesa.${LIBEXT}"\
            -DVTK_USE_TK:BOOL=OFF\
            -DTK_INCLUDE_PATH:FILEPATH=""\
            -DTK_LIBRARY:FILEPATH=""\
            -DVTK_WRAP_PYTHON:BOOL=ON\
            -DPYTHON_EXECUTABLE:FILEPATH="${VISIT_PYTHON_DIR}/bin/python"\
            -DPYTHON_INCLUDE_PATH:FILEPATH="${VISIT_PYTHON_DIR}/include/python${PYTHON_COMPATIBILITY_VERSION}/"\
            -DPYTHON_LIBRARY:FILEPATH="${VISIT_PYTHON_DIR}/lib/libpython${PYTHON_COMPATIBILITY_VERSION}.${LIBEXT}"\
            -DPYTHON_EXTRA_LIBS:STRING="$VTK_PY_LIBS" \
            .
    elif [[ ${VER%%.*} -ge 9 ]] ; then
        echo "10.5 detected. Enable Python filters"
        ${CMAKE_BIN} \
            -DCMAKE_INSTALL_PREFIX:PATH="$VISITDIR/vtk/${VTK_VERSION}/${VISITARCH}"\
            -DBUILD_SHARED_LIBS:BOOL=${VTK_SHARED_LIBS}\
            -DBUILD_TESTING:BOOL=OFF\
            -DUSE_ANSI_STD_LIB:BOOL=ON\
            -DVTK_USE_MANGLED_MESA:BOOL=ON\
            -DVTK_USE_HYBRID:BOOL=ON\
            -DCMAKE_CXX_FLAGS:STRING="${CXX_OPT_FLAGS}"\
            -DCMAKE_CXX_COMPILER:STRING=${CXX_COMPILER}\
            -DCMAKE_C_FLAGS:STRING="${C_OPT_FLAGS}"\
            -DCMAKE_C_COMPILER:STRING=${C_COMPILER}\
            -DCMAKE_SHARED_LINKER_FLAGS:STRING=-Wl,-headerpad_max_install_names,-compatibility_version,5.0,-current_version,5.0.0\
            -DMANGLED_MESA_INCLUDE_DIR:PATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/include"\
            -DMANGLED_MESA_LIBRARY:FILEPATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/lib/libOSMesa.${LIBEXT}"\
            -DMANGLED_OSMESA_INCLUDE_DIR:PATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/include"\
            -DMANGLED_OSMESA_LIBRARY:FILEPATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/lib/libOSMesa.${LIBEXT}"\
            -DVTK_USE_TK:BOOL=OFF\
            -DTK_INCLUDE_PATH:FILEPATH=""\
            -DTK_LIBRARY:FILEPATH=""\
            -DVTK_WRAP_PYTHON:BOOL=ON\
            -DPYTHON_EXECUTABLE:FILEPATH="${VISIT_PYTHON_DIR}/bin/python"\
            -DPYTHON_INCLUDE_PATH:FILEPATH="${VISIT_PYTHON_DIR}/include/python${PYTHON_COMPATIBILITY_VERSION}/"\
            -DPYTHON_LIBRARY:FILEPATH="${VISIT_PYTHON_DIR}/lib/libpython${PYTHON_COMPATIBILITY_VERSION}.${LIBEXT}"\
            -DPYTHON_EXTRA_LIBS:STRING="$VTK_PY_LIBS" \
            .
    else
        echo "10.4 detected. Disable Python filters"
        ${CMAKE_BIN} \
            -DCMAKE_INSTALL_PREFIX:PATH="$VISITDIR/vtk/${VTK_VERSION}/${VISITARCH}"\
            -DBUILD_SHARED_LIBS:BOOL=${VTK_SHARED_LIBS}\
            -DBUILD_TESTING:BOOL=OFF\
            -DUSE_ANSI_STD_LIB:BOOL=ON\
            -DVTK_USE_MANGLED_MESA:BOOL=ON\
            -DVTK_USE_HYBRID:BOOL=ON\
            -DCMAKE_CXX_FLAGS:STRING="${CXX_OPT_FLAGS}"\
            -DCMAKE_CXX_COMPILER:STRING=${CXX_COMPILER}\
            -DCMAKE_C_FLAGS:STRING="${C_OPT_FLAGS}"\
            -DCMAKE_C_COMPILER:STRING=${C_COMPILER}\
            -DCMAKE_SHARED_LINKER_FLAGS:STRING=-Wl,-headerpad_max_install_names\
            -DMANGLED_MESA_INCLUDE_DIR:PATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/include"\
            -DMANGLED_MESA_LIBRARY:FILEPATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/lib/libOSMesa.${LIBEXT}"\
            -DMANGLED_OSMESA_INCLUDE_DIR:PATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/include"\
            -DMANGLED_OSMESA_LIBRARY:FILEPATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/lib/libOSMesa.${LIBEXT}"\
            -DVTK_USE_TK:BOOL=OFF\
            -DTK_INCLUDE_PATH:FILEPATH=""\
            -DTK_LIBRARY:FILEPATH=""\
            .
    fi
    elif [[ "$OPSYS" == "IRIX64" ]]; then
    ${CMAKE_BIN} \
        -DCMAKE_INSTALL_PREFIX:PATH="$VISITDIR/vtk/${VTK_VERSION}/${VISITARCH}"\
        -DBUILD_SHARED_LIBS:BOOL=${VTK_SHARED_LIBS}\
        -DBUILD_TESTING:BOOL=OFF\
        -DUSE_ANSI_STD_LIB:BOOL=ON\
        -DVTK_USE_MANGLED_MESA:BOOL=ON\
        -DVTK_USE_HYBRID:BOOL=ON\
        -DCMAKE_CXX_FLAGS:STRING="${CXX_OPT_FLAGS} -LANG:std -64"\
        -DCMAKE_CXX_COMPILER:STRING=${CXX_COMPILER}\
        -DCMAKE_C_FLAGS:STRING="${C_OPT_FLAGS}" \
        -DCMAKE_C_COMPILER:STRING=${C_COMPILER}\
        -DCMAKE_EXE_LINKER_FLAGS:STRING=-LANG:std -64\
        -DCMAKE_MODULE_LINKER_FLAGS:STRING=-LANG:std -64\
        -DCMAKE_SHARED_LINKER_FLAGS:STRING=-LANG:std -64\
        -DMANGLED_MESA_INCLUDE_DIR:PATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/include"\
        -DMANGLED_MESA_LIBRARY:FILEPATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/lib/libOSMesa.${LIBEXT}"\
        -DMANGLED_OSMESA_INCLUDE_DIR:PATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/include"\
        -DMANGLED_OSMESA_LIBRARY:FILEPATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/lib/libMesaGL.${LIBEXT}"\
        -DVTK_USE_TK:BOOL=OFF\
        -DTK_INCLUDE_PATH:FILEPATH=""\
        -DTK_LIBRARY:FILEPATH=""\
        -DVTK_WRAP_PYTHON:BOOL=ON\
        -DPYTHON_EXECUTABLE:FILEPATH="${VISIT_PYTHON_DIR}/bin/python"\
        -DPYTHON_INCLUDE_PATH:FILEPATH="${VISIT_PYTHON_DIR}/include/python${PYTHON_COMPATIBILITY_VERSION}/"\
        -DPYTHON_LIBRARY:FILEPATH="${VISIT_PYTHON_DIR}/lib/libpython${PYTHON_COMPATIBILITY_VERSION}.${LIBEXT}"\
        -DPYTHON_EXTRA_LIBS:STRING="$VTK_PY_LIBS" \
        .
    else
       if [[ "$DO_DBIO_ONLY" == "yes" ]]; then
           ${CMAKE_BIN} \
               -DCMAKE_INSTALL_PREFIX:PATH="$VISITDIR/vtk/${VTK_VERSION}/${VISITARCH}"\
               -DBUILD_SHARED_LIBS:BOOL=${VTK_SHARED_LIBS}\
               -DBUILD_TESTING:BOOL=OFF\
               -DUSE_ANSI_STD_LIB:BOOL=ON\
               -DVTK_USE_MANGLED_MESA:BOOL=OFF\
               -DVTK_USE_HYBRID:BOOL=ON\
               -DCMAKE_CXX_FLAGS:STRING="${CXX_OPT_FLAGS}"\
               -DCMAKE_CXX_COMPILER:STRING=${CXX_COMPILER}\
               -DCMAKE_C_FLAGS:STRING="${C_OPT_FLAGS}"\
               -DCMAKE_C_COMPILER:STRING=${C_COMPILER}\
               -DVTK_USE_TK:BOOL=OFF\
               -DTK_INCLUDE_PATH:FILEPATH=""\
               -DTK_LIBRARY:FILEPATH=""\
               -DVTK_WRAP_PYTHON:BOOL=ON\
               -DPYTHON_EXECUTABLE:FILEPATH="${VISIT_PYTHON_DIR}/bin/python"\
               -DPYTHON_INCLUDE_PATH:FILEPATH="${VISIT_PYTHON_DIR}/include/python${PYTHON_COMPATIBILITY_VERSION}/"\
               -DPYTHON_LIBRARY:FILEPATH="${VISIT_PYTHON_DIR}/lib/libpython${PYTHON_COMPATIBILITY_VERSION}.${LIBEXT}"\
               -DPYTHON_EXTRA_LIBS:STRING="$VTK_PY_LIBS" \
               .
       else
           if [[ "$DO_STATIC_BUILD" == "yes" ]]; then
           # We can't build Python wrappers with static
           ${CMAKE_BIN} \
               -DCMAKE_INSTALL_PREFIX:PATH="$VISITDIR/vtk/${VTK_VERSION}/${VISITARCH}"\
               -DBUILD_SHARED_LIBS:BOOL=${VTK_SHARED_LIBS}\
               -DBUILD_TESTING:BOOL=OFF\
               -DUSE_ANSI_STD_LIB:BOOL=ON\
               -DVTK_USE_MANGLED_MESA:BOOL=ON\
               -DVTK_USE_HYBRID:BOOL=ON\
               -DCMAKE_CXX_FLAGS:STRING="${CXX_OPT_FLAGS}"\
               -DCMAKE_CXX_COMPILER:STRING=${CXX_COMPILER}\
               -DCMAKE_C_FLAGS:STRING="${C_OPT_FLAGS}"\
               -DCMAKE_C_COMPILER:STRING=${C_COMPILER}\
               -DMANGLED_MESA_INCLUDE_DIR:PATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/include"\
               -DMANGLED_MESA_LIBRARY:FILEPATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/lib/libMesaGL.${LIBEXT}"\
               -DMANGLED_OSMESA_INCLUDE_DIR:PATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/include"\
               -DMANGLED_OSMESA_LIBRARY:FILEPATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/lib/libOSMesa.${LIBEXT}"\
               -DVTK_USE_TK:BOOL=OFF\
               -DTK_INCLUDE_PATH:FILEPATH=""\
               -DTK_LIBRARY:FILEPATH=""\
               .
           else
           ${CMAKE_BIN} \
               -DCMAKE_INSTALL_PREFIX:PATH="$VISITDIR/vtk/${VTK_VERSION}/${VISITARCH}"\
               -DBUILD_SHARED_LIBS:BOOL=${VTK_SHARED_LIBS}\
               -DBUILD_TESTING:BOOL=OFF\
               -DUSE_ANSI_STD_LIB:BOOL=ON\
               -DVTK_USE_MANGLED_MESA:BOOL=ON\
               -DVTK_USE_HYBRID:BOOL=ON\
               -DCMAKE_CXX_FLAGS:STRING="${CXX_OPT_FLAGS}"\
               -DCMAKE_CXX_COMPILER:STRING=${CXX_COMPILER}\
               -DCMAKE_C_FLAGS:STRING="${C_OPT_FLAGS}"\
               -DCMAKE_C_COMPILER:STRING=${C_COMPILER}\
               -DMANGLED_MESA_INCLUDE_DIR:PATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/include"\
               -DMANGLED_MESA_LIBRARY:FILEPATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/lib/libOSMesa.${LIBEXT}"\
               -DMANGLED_OSMESA_INCLUDE_DIR:PATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/include"\
               -DMANGLED_OSMESA_LIBRARY:FILEPATH="$VISITDIR/mesa/${MESA_VERSION}/${VISITARCH}/lib/libMesaGL.${LIBEXT}"\
               -DVTK_USE_TK:BOOL=OFF\
               -DTK_INCLUDE_PATH:FILEPATH=""\
               -DTK_LIBRARY:FILEPATH=""\
               -DVTK_WRAP_PYTHON:BOOL=ON\
               -DPYTHON_EXECUTABLE:FILEPATH="${VISIT_PYTHON_DIR}/bin/python"\
               -DPYTHON_INCLUDE_PATH:FILEPATH="${VISIT_PYTHON_DIR}/include/python${PYTHON_COMPATIBILITY_VERSION}/"\
               -DPYTHON_LIBRARY:FILEPATH="${VISIT_PYTHON_DIR}/lib/libpython${PYTHON_COMPATIBILITY_VERSION}.${LIBEXT}"\
               -DPYTHON_EXTRA_LIBS:STRING="$VTK_PY_LIBS" \
               .
           fi
       fi
    fi
    if [[ $? != 0 ]] ; then
       warn "Cannot get CMAKE to create the makefiles.  Giving up."
       return 1
    fi

    #
    # Now build VTK.
    #
    info "Building VTK . . . (~20 minutes)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "VTK did not build correctly.  Giving up."
       return 1
    fi

    info "Installing VTK . . . "
    $MAKE install
    if [[ $? != 0 ]] ; then
       warn "VTK did not install correctly.  Giving up."
       return 1
    fi

    #
    # If on Darwin, fix install names
    #
    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
        if [[ $ABS_PATH == "yes" ]]; then
           INSTALLNAMEPATH="$VISITDIR/vtk/${VTK_VERSION}/$VISITARCH/lib"
        else
           INSTALLNAMEPATH="@executable_path/../lib"
        fi
        # fix the internal name with in the libraries
        #
        # first change the libraries name and identification by executing the
        # following bourne shell script
        for i in libvtkCommon libvtkCommonPythonD libvtkDICOMParser libvtkFiltering \
        libvtkFilteringPythonD libvtkGenericFiltering libvtkGenericFilteringPythonD \
        libvtkGraphics libvtkGraphicsPythonD libvtkHybrid libvtkHybridPythonD libvtkIO \
        libvtkIOPythonD libvtkImaging libvtkImagingPythonD libvtkMPEG2Encode libvtkRendering \
        libvtkRenderingPythonD libvtkVolumeRendering libvtkVolumeRenderingPythonD libvtkexpat \
        libvtkfreetype libvtkftgl libvtkjpeg libvtkpng libvtksys \
        libvtktiff libvtkzlib
        do
           install_name_tool -id \
             $INSTALLNAMEPATH/$i.$SO_EXT \
             $VISITDIR/vtk/${VTK_VERSION}/${VISITARCH}/lib/$i.$SO_EXT
        done

        #
        # Next change the dependent libraries names and paths
        for i in libvtkCommon libvtkCommonPythonD libvtkDICOMParser libvtkFiltering \
        libvtkFilteringPythonD libvtkGenericFiltering libvtkGenericFilteringPythonD \
        libvtkGraphics libvtkGraphicsPythonD libvtkHybrid libvtkHybridPythonD libvtkIO \
        libvtkIOPythonD libvtkImaging libvtkImagingPythonD libvtkMPEG2Encode libvtkRendering \
        libvtkRenderingPythonD libvtkVolumeRendering libvtkVolumeRenderingPythonD libvtkexpat \
        libvtkfreetype libvtkftgl libvtkjpeg libvtkpng libvtksys \
        libvtktiff libvtkzlib
        do
          for j in libvtkCommon libvtkCommonPythonD libvtkDICOMParser libvtkFiltering \
          libvtkFilteringPythonD libvtkGenericFiltering libvtkGenericFilteringPythonD \
          libvtkGraphics libvtkGraphicsPythonD libvtkHybrid libvtkHybridPythonD libvtkIO \
          libvtkIOPythonD libvtkImaging libvtkImagingPythonD libvtkMPEG2Encode libvtkRendering \
          libvtkRenderingPythonD libvtkVolumeRendering libvtkVolumeRenderingPythonD libvtkexpat \
          libvtkfreetype libvtkftgl libvtkjpeg libvtkpng libvtksys \
          libvtktiff libvtkzlib
          do
             install_name_tool -change \
                $j.5.0.$SO_EXT \
                $INSTALLNAMEPATH/$j.$SO_EXT \
                $VISITDIR/vtk/${VTK_VERSION}/${VISITARCH}/lib/$i.$SO_EXT
          done
        done

        #
        # Fix vtk python wrapper module intall names.
        #
        for i in libvtkCommonPython.so libvtkFilteringPython.so libvtkGenericFilteringPython.so \
        libvtkGraphicsPython.so libvtkHybridPython.so libvtkIOPython.so libvtkImagingPython.so \
        libvtkRenderingPython.so libvtkVolumeRenderingPython.so 
        do
            install_name_tool -id \
             $INSTALLNAMEPATH/python${PYTHON_COMPATIBILITY_VERSION}/site-packages/vtk/$i \
             $VISITDIR/vtk/${VTK_VERSION}/${VISITARCH}/lib/python${PYTHON_COMPATIBILITY_VERSION}/site-packages/vtk/$i
        done

        #
        # The vtk python module libs depend on the main vtk libs, resolve these install names.
        #
        for i in libvtkCommonPython.so libvtkFilteringPython.so libvtkGenericFilteringPython.so \
        libvtkGraphicsPython.so libvtkHybridPython.so libvtkIOPython.so libvtkImagingPython.so \
        libvtkRenderingPython.so libvtkVolumeRenderingPython.so 
        do
          for j in libvtkCommon libvtkCommonPythonD libvtkDICOMParser libvtkFiltering \
          libvtkFilteringPythonD libvtkGenericFiltering libvtkGenericFilteringPythonD \
          libvtkGraphics libvtkGraphicsPythonD libvtkHybrid libvtkHybridPythonD libvtkIO \
          libvtkIOPythonD libvtkImaging libvtkImagingPythonD libvtkMPEG2Encode libvtkRendering \
          libvtkRenderingPythonD libvtkVolumeRendering libvtkVolumeRenderingPythonD libvtkexpat \
          libvtkfreetype libvtkftgl libvtkjpeg libvtkpng libvtksys \
          libvtktiff libvtkzlib
          do
             install_name_tool -change \
                $j.5.0.$SO_EXT \
                $INSTALLNAMEPATH/$j.$SO_EXT \
                $VISITDIR/vtk/${VTK_VERSION}/${VISITARCH}/lib/python${PYTHON_COMPATIBILITY_VERSION}/site-packages/vtk/$i
          done
        done


    fi

    #
    # Manually install the Mangled Mesa headers
    #
    # The MangleMesa headers have absolute paths.  Correct these headers now for
    # the new location they have been copied into.
    #

    if [[ "$DO_DBIO_ONLY" != "yes" ]]; then
        cd MangleMesaInclude
        export BAD_MESA="$PWD"
        cd ..
        mkdir "$VISITDIR/vtk/${VTK_VERSION}/$VISITARCH/include/MangleMesaInclude"
        cp MangleMesaInclude/*.h  "$VISITDIR/vtk/${VTK_VERSION}/$VISITARCH/include/MangleMesaInclude"
        cd "$VISITDIR/vtk/${VTK_VERSION}/$VISITARCH/include/MangleMesaInclude"
        SED_STR1=$(echo "$BAD_MESA" | sed 's/\//\\\//g')  
        # Converts all '/' to "\/" for later sed'ding 
        SED_STR2=$(echo "$VISITDIR/vtk/${VTK_VERSION}/$VISITARCH/include/MangleMesaInclude" | sed 's/\//\\\//g')
        for i in *.h ; do
           cat $i | sed 's/'${SED_STR1}'/'${SED_STR2}'/g' > tmp.h
           mv -f tmp.h $i
        done
        cd $BAD_MESA
        cd ../
    fi

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


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

function build_python
{
    prepare_build_dir $PYTHON_BUILD_DIR $PYTHON_FILE
    untarred_python=$?
    if [[ $untarred_python == -1 ]] ; then
       warn "Unable to prepare Python build directory. Giving Up!"
       return 1
    fi

    #
    # Call configure
    #
    cd $PYTHON_BUILD_DIR || error "Can't cd to Python build dir."
    cCompiler="${C_COMPILER}"
    cFlags="${C_OPT_FLAGS}"
    cxxCompiler="${CXX_COMPILER}"
    cxxFlags="${CXX_OPT_FLAGS}"
    if [[ "$OPSYS" == "Linux" && "$C_COMPILER" == "xlc" ]]; then
        cCompiler="gxlc"
        cxxCompiler="gxlC"
        cFlags=`echo ${C_OPT_FLAGS} | sed "s/-qpic/-fPIC/g"`
        cxxFlags=`echo ${CXX_OPT_FLAGS} | sed "s/-qpic/-fPIC/g"`
    fi
    PYTHON_OPT="$cFlags"
    PYTHON_LDFLAGS=""
    PYTHON_PREFIX_DIR="$VISITDIR/python/$PYTHON_VERSION/$VISITARCH"
    if [[ "$DO_STATIC_BUILD" == "no" ]]; then
        PYTHON_SHARED="--enable-shared"
        if [[ "$C_COMPILER" == "gcc" ]]; then
            #
            # python's --enable-shared configure flag doesn't link
            # the exes it builds correclty when installed to a non standard
            # prefix. To resolve this we need to add a rpath linker flags.
            #
            mkdir -p ${PYTHON_PREFIX_DIR}/lib/
            if [[ $? != 0 ]] ; then
                 warn "Python configure failed.  Giving up"
            return 1
            fi

            if [[ "$OPSYS" != "Darwin" || ${VER%%.*} -ge 9 ]]; then
                PYTHON_LDFLAGS="-Wl,-rpath,${PYTHON_PREFIX_DIR}/lib/ -pthread"
            fi
        fi
    fi
    if [[ "$OPSYS" == "AIX" ]]; then
        info "Configuring Python (AIX): ./configure OPT=\"$PYTHON_OPT\" CXX=\"$cxxCompiler\" CC=\"$cCompiler\"" \
             "--prefix=\"$PYTHON_PREFIX_DIR\" --disable-ipv6"
        ./configure OPT="$PYTHON_OPT" CXX="$cxxCompiler" CC="$cCompiler" \
                --prefix="$PYTHON_PREFIX_DIR" --disable-ipv6
    else
        info "Configuring Python : ./configure OPT=\"$PYTHON_OPT\" CXX=\"$cxxCompiler\" CC=\"$cCompiler\"" \
             "LDFLAGS=\"$PYTHON_LDFLAGS\""\
             "${PYTHON_SHARED} --prefix=\"$PYTHON_PREFIX_DIR\" --disable-ipv6"
        ./configure OPT="$PYTHON_OPT" CXX="$cxxCompiler" CC="$cCompiler" LDFLAGS="$PYTHON_LDFLAGS" \
                  ${PYTHON_SHARED} \
                --prefix="$PYTHON_PREFIX_DIR" --disable-ipv6
    fi
    if [[ $? != 0 ]] ; then
       warn "Python configure failed.  Giving up"
       return 1
    fi

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


    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "AIX" ]]; then
        # configure flag --enable-shared doesn't work on llnl aix5 systems
        # we need to create the shared lib manually and place it in the
        # proper loc
        mv $VISITDIR/python/$PYTHON_VERSION/$VISITARCH/lib/libpython$PYTHON_COMPATIBILITY_VERSION.$SO_EXT \
           $VISITDIR/python/$PYTHON_VERSION/$VISITARCH/lib/libpython$PYTHON_COMPATIBILITY_VERSION.static.a

        $C_COMPILER -qmkshrobj -lm \
             $VISITDIR/python/$PYTHON_VERSION/$VISITARCH/lib/libpython$PYTHON_COMPATIBILITY_VERSION.static.a \
          -o $VISITDIR/python/$PYTHON_VERSION/$VISITARCH/lib/libpython$PYTHON_COMPATIBILITY_VERSION.$SO_EXT

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

        # we can safely remove this version of the static lib b/c it also exists under python2.6/config/
        rm -f $VISITDIR/python/$PYTHON_VERSION/$VISITARCH/lib/libpython$PYTHON_COMPATIBILITY_VERSION.static.a
    fi


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

    return 0
}

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

    PYHOME="${VISITDIR}/python/${PYTHON_VERSION}/${VISITARCH}"
    pushd $PIL_BUILD_DIR > /dev/null
        info "Building PIL ..."
        ${PYHOME}/bin/python ./setup.py build 
        info "Installing PIL ..."
        ${PYHOME}/bin/python ./setup.py install --prefix="${PYHOME}"
    popd > /dev/null

    # PIL installs into site-packages dir of Visit's Python.
    # Simply re-execute the python perms command.
    if [[ "$DO_GROUP" == "yes" ]] ; then
       chmod -R ug+w,a+rX "$VISITDIR/python"
       chgrp -R ${GROUP} "$VISITDIR/python"
    fi

    info "Done with PIL."
    return 0
}


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

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
    if [[ "$DO_QT" != "yes" || "$OPSYS" == "Darwin" ]] ; then
       WITHSILOQTARG="--disable-silex"
    else
       export SILOQTDIR="${VISITDIR}/qt/${QT_VERSION}/${VISITARCH}"
       WITHSILOQTARG="--with-qt=$SILOQTDIR"
    fi

    info "./configure CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" \
        CFLAGS=\"$C_OPT_FLAGS\" CXXFLAGS=\"$CXX_OPT_FLAGS\" \
        --prefix=\"$VISITDIR/silo/$SILO_VERSION/$VISITARCH\" \
        \"$WITHHDF5ARG\" \"$WITHSZIPARG\" \"$WITHSILOQTARG\" \
        --without-readline --disable-fortran"

    ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" \
        CFLAGS="$C_OPT_FLAGS" CXXFLAGS="$CXX_OPT_FLAGS" \
        --prefix="$VISITDIR/silo/$SILO_VERSION/$VISITARCH" \
        "$WITHHDF5ARG" "$WITHSZIPARG" "$WITHSILOQTARG" \
        --without-readline --disable-fortran

    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"

    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
        mkdir "$VISITDIR/silo"
        mkdir "$VISITDIR/silo/${SILO_VERSION}"
        mkdir "$VISITDIR/silo/${SILO_VERSION}/$VISITARCH"
        mkdir "$VISITDIR/silo/${SILO_VERSION}/$VISITARCH/include"
        mkdir "$VISITDIR/silo/${SILO_VERSION}/$VISITARCH/lib"
        mkdir "$VISITDIR/silo/${SILO_VERSION}/$VISITARCH/bin"
        cp src/silo/silo.h   \
"$VISITDIR/silo/${SILO_VERSION}/$VISITARCH/include"
        cp src/silo/silo.inc \
"$VISITDIR/silo/${SILO_VERSION}/$VISITARCH/include"
        cp src/silo/pmpio.h \
"$VISITDIR/silo/${SILO_VERSION}/$VISITARCH/include"
        cp tools/silex/silex \
"$VISITDIR/silo/${SILO_VERSION}/$VISITARCH/bin"
        cp tools/browser/browser \
"$VISITDIR/silo/${SILO_VERSION}/$VISITARCH/bin"
        cp tools/browser/silodiff \
"$VISITDIR/silo/${SILO_VERSION}/$VISITARCH/bin"
        cp tools/browser/silofile \
"$VISITDIR/silo/${SILO_VERSION}/$VISITARCH/bin"
        cp tools/silock/silock \
"$VISITDIR/silo/${SILO_VERSION}/$VISITARCH/bin"
        #
        # Make dynamic executable
        #
        if [[ $ABS_PATH == "yes" ]]; then
           INSTALLNAMEPATH="$VISITDIR/silo/${SILO_VERSION}/$VISITARCH/lib"
        else
           INSTALLNAMEPATH="@executable_path/../lib"
        fi
        # Remove the tmp directory if it is already present
        if [[ -d tmp ]] ; then
            rm -rf tmp
        fi
        mkdir tmp
        cd tmp
        SILO_H5=""
        if [[ "$DO_HDF5" == "yes" ]] ; then
            SILO_H5="h5"
        fi
        ar x ../src/.libs/libsilo${SILO_H5}.a
        $CXX_COMPILER -dynamiclib -o libsilo${SILO_H5}.${SO_EXT} *.o \
           -Wl,-headerpad_max_install_names \
           -Wl,-install_name,$INSTALLNAMEPATH/libsilo${SILO_H5}.${SO_EXT} \
           -Wl,-compatibility_version,${SILO_COMPATIBILITY_VERSION} \
           -Wl,-current_version,${SILO_VERSION} $SILO_LINK_OPT
        if [[ $? != 0 ]] ; then
           warn "Silo dynamic library build failed.  Giving up"
           return 1
        fi
        cp libsilo${SILO_H5}.${SO_EXT}  \
"$VISITDIR/silo/${SILO_VERSION}/$VISITARCH/lib"
    else
        $MAKE install
        if [[ $? != 0 ]] ; then
           warn "Silo install failed.  Giving up"
           return 1
        fi
    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 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"

    info "./configure CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" LIBS=\"-lm\" \
        CFLAGS=\"$C_OPT_FLAGS\" CXXFLAGS=\"$CXX_OPT_FLAGS\" \
        --prefix=\"$VISITDIR/szip/$SZIP_VERSION/$VISITARCH\""

    ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" LIBS="-lm" \
        CFLAGS="$C_OPT_FLAGS" CXXFLAGS="$CXX_OPT_FLAGS" \
        --prefix="$VISITDIR/szip/$SZIP_VERSION/$VISITARCH"

    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 . . ."
        if [[ $ABS_PATH == "yes" ]]; then
           INSTALLNAMEPATH="$VISITDIR/szip/${SZIP_VERSION}/$VISITARCH/lib"
        else
           INSTALLNAMEPATH="@executable_path/../lib"
        fi
## 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 8.1, build_hdf5                           #
# *************************************************************************** #

function build_hdf5
{
    #
    # Prepare build dir
    #
    prepare_build_dir $HDF5_BUILD_DIR $HDF5_FILE
    untarred_hdf5=$?
    if [[ $untarred_hdf5 == -1 ]] ; then
       warn "Unable to prepare HDF5 Build Directory. Giving Up"
       return 1
    fi

    #
    info "Configuring HDF5 . . ."
    cd $HDF5_BUILD_DIR || error "Can't cd to HDF5 build dir."
    cf_darwin=""
    if [[ "$OPSYS" == "Darwin" ]]; then
        export DYLD_LIBRARY_PATH="$VISITDIR/szip/$SZIP_VERSION/$VISITARCH/lib":$DYLD_LIBRARY_PATH
        if [[ "$DO_STATIC_BUILD" == "no" ]]; then
            cf_darwin="--enable-shared --disable-static"
        fi
    else
        export LD_LIBRARY_PATH="$VISITDIR/szip/$SZIP_VERSION/$VISITARCH/lib":$LD_LIBRARY_PATH
    fi
    info "Invoking command to configure HDF5"
    cf_szip=""
    darwin_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}"
        darwin_szip="-L\"$VISITDIR/szip/$SZIP_VERSION/$VISITARCH/lib\" -lsz"
    fi

    info "./configure CXX=\"$CXX_COMPILER\" CC=\"$C_COMPILER\" \
        CFLAGS=\"$C_OPT_FLAGS\" CXXFLAGS=\"$CXX_OPT_FLAGS\" \
        --prefix=\"$VISITDIR/hdf5/$HDF5_VERSION/$VISITARCH\" \
        ${cf_szip}"

    ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" \
        CFLAGS="$C_OPT_FLAGS" CXXFLAGS="$CXX_OPT_FLAGS" \
        --prefix="$VISITDIR/hdf5/$HDF5_VERSION/$VISITARCH" \
        ${cf_szip} ${cf_darwin}
    if [[ $? != 0 ]] ; then
       warn "HDF5 configure failed.  Giving up"
       return 1
    fi

    #
    # Build HDF5
    #
    info "Building HDF5 . . . (~2 minutes)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "HDF5 build failed.  Giving up"
       return 1
    fi
    #
    # Install into the VisIt third party location.
    #
    info "Installing HDF5 . . ."

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

    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
        #
        # Make dynamic executable, need to patch up the install path and
        # version information.
        #
        info "Creating dynamic libraries for HDF5 . . ."
        if [[ $ABS_PATH == "no" ]]; then
            install_name_tool -id @executable_path/../lib/libhdf5.$SO_EXT $VISITDIR/hdf5/${HDF5_VERSION}/$VISITARCH/lib/libhdf5.$SO_EXT
            install_name_tool -id @executable_path/../lib/libhdf5_hl.$SO_EXT $VISITDIR/hdf5/${HDF5_VERSION}/$VISITARCH/lib/libhdf5_hl.$SO_EXT
        fi
    fi

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


# *************************************************************************** #
#                          Function 8.2, build_mili                           #
# *************************************************************************** #

function apply_mili_110_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 "Mili patch for V1.10 on Darwin failed."
      return 1
   fi

   return 0
}

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

   return 0
}

function apply_mili_patch
{
   if [[ ${MILI_VERSION} == 1.10.0 ]] ; then
       apply_mili_110_patch
       if [[ $? != 0 ]] ; then
           return 1
       fi
   fi

   return 0
}

function build_mili
{
    #
    # Prepare build dir
    #
    prepare_build_dir $MILI_BUILD_DIR $MILI_FILE
    untarred_mili=$?
    if [[ $untarred_mili == -1 ]] ; then
       warn "Unable to prepare Mili Build Directory. Giving Up"
       return 1
    fi

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

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

    info "Invoking command to configure Mili"
    ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" \
        CFLAGS="$C_OPT_FLAGS" CXXFLAGS="$CXX_OPT_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)"

    cd MILI-$OPSYS-*
    cd src
    $C_COMPILER $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
    #
    # 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"
    cp mili.h mili_enum.h  "$VISITDIR/mili/$MILI_VERSION/$VISITARCH/include"
    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
        if [[ $ABS_PATH == "yes" ]]; then
           INSTALLNAMEPATH="$VISITDIR/mili/${MILI_VERSION}/$VISITARCH/lib"
        else
           INSTALLNAMEPATH="@executable_path/../lib"
        fi
        $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
        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
        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"
    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 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_patch
{
   if [[ ${HDF4_VERSION} == 4.2.1 ]] ; then
       apply_hdf4_421_patch
       if [[ $? != 0 ]] ; then
           return 1
       fi
   fi
    if [[ `uname -m` == "ppc64" ]]; then
        apply_hdf4_421_ppc_patch
        apply_hdf4_421_ppc_patch_endianness
    fi

   return 0
}

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

    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
        ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" \
        CFLAGS="$C_OPT_FLAGS" \
        CPPFLAGS="-I$VISITDIR/vtk/${VTK_VERSION}/$VISITARCH/Utilities \
        -I$VISITDIR/vtk/${VTK_VERSION}/$VISITARCH/Utilities/vtkjpeg" \
        --prefix="$VISITDIR/hdf4/$HDF4_VERSION/$VISITARCH" \
        --with-jpeg="$VISITDIR/vtk/${VTK_VERSION}/$VISITARCH" \
        --with-szlib="$VISITDIR/szip/$SZIP_VERSION/$VISITARCH" \
        --disable-fortran --disable-dependency-tracking
        if [[ $? != 0 ]] ; then
           warn "HDF4 configure failed.  Giving up"
           return 1
        fi
        MAKEOPS="-i"
    else
        export LD_LIBRARY_PATH="$VISITDIR/szip/$SZIP_VERSION/$VISITARCH/lib":$LD_LIBRARY_PATH
        ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" \
        CFLAGS="$C_OPT_FLAGS" LIBS="-lm" --disable-fortran \
        --prefix="$VISITDIR/hdf4/$HDF4_VERSION/$VISITARCH" \
        --with-szlib="$VISITDIR/szip/$SZIP_VERSION/$VISITARCH"
        if [[ $? != 0 ]] ; then
           warn "HDF4 configure failed.  Giving up"
           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.
        if [[ $ABS_PATH == "yes" ]]; then
           INSTALLNAMEPATH="$VISITDIR/hdf4/${HDF4_VERSION}/$VISITARCH/lib"
        else
           INSTALLNAMEPATH="@executable_path/../lib"
        fi
        ${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/${VTK_VERSION}/$VISITARCH/lib" \
           -L"$VISITDIR/szip/$SZIP_VERSION/$VISITARCH/lib" \
           -lvtkjpeg -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/${VTK_VERSION}/$VISITARCH/lib" \
           -L"$VISITDIR/szip/$SZIP_VERSION/$VISITARCH/lib" \
           -L"$VISITDIR/hdf4/$HDF4_VERSION/$VISITARCH/lib" \
           -lvtkjpeg -ldf -lsz -lz
        if [[ $? != 0 ]] ; then
           warn \
"HDF4 dynamic library build failed for libmfhdf.${SO_EXT}.  Giving up"
           return 1
        fi
        cp libmfhdf.${SO_EXT} "$VISITDIR/hdf4/$HDF4_VERSION/$VISITARCH/lib"
    fi

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


# *************************************************************************** #
#                         Function 8.4, build_netcdf                          #
# *************************************************************************** #

function apply_netcdf_360_patch
{
  patch -p0 << \EOF
*** netcdf-3.6.0-p1.orig/src/libsrc/netcdf.h	Tue Sep 14 06:41:22 2004
--- netcdf-3.6.0-p1/src/libsrc/netcdf.h	Thu Apr 26 14:14:41 2007
*************** typedef enum {
*** 130,140 ****
   * applications and utilities.  However, nothing is statically allocated to
   * these sizes internally.
   */
! #define NC_MAX_DIMS	512	 /* max dimensions per file */
  #define NC_MAX_ATTRS	4096	 /* max global or per variable attributes */
! #define NC_MAX_VARS	4096	 /* max variables per file */
  #define NC_MAX_NAME	128	 /* max length of a name */
! #define NC_MAX_VAR_DIMS	NC_MAX_DIMS /* max per variable dimensions */
  
  
  /*
--- 130,140 ----
   * 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	4096	 /* max global or per variable attributes */
! #define NC_MAX_VARS	524288	 /* max variables per file */
  #define NC_MAX_NAME	128	 /* max length of a name */
! #define NC_MAX_VAR_DIMS	8 	 /* max per variable dimensions */
  
  
  /*
EOF
  if [[ $? != 0 ]] ; then
      warn "Unable to patch NetCDF. Wrong version?"
      return 1
  fi

  return 0
}

function apply_netcdf_patch
{
   if [[ ${NETCDF_VERSION} == 3.6.0 ]] ; then
       apply_netcdf_360_patch
       if [[ $? != 0 ]] ; then
           return 1
       fi
   fi

   return 0
}

function build_netcdf
{
    # Prepare build dir
    #
    prepare_build_dir $NETCDF_BUILD_DIR $NETCDF_FILE
    untarred_netcdf=$?
    if [[ $untarred_netcdf == -1 ]] ; then
       warn "Unable to prepare NetCDF Build Directory. Giving Up"
       return 1
    fi

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

    info "Configuring NetCDF . . ."
    cd $NETCDF_BUILD_DIR || error "Can't cd to netcdf build dir."
    info "Invoking command to configure NetCDF"
    if [[ "$OPSYS" == "Darwin" ]]; then
        if [[ "$DO_STATIC_BUILD" == "no" ]]; then
            EXTRA_FLAGS="--enable-largefile --enable-shared --disable-static"
        else
            EXTRA_FLAGS="--enable-largefile"
        fi
    else
        EXTRA_FLAGS=""
    fi
    ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" \
        CFLAGS="$C_OPT_FLAGS" CXXFLAGS="$CXX_OPT_FLAGS" \
        FC="" $EXTRA_FLAGS \
        --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 . . ."
        if [[ $ABS_PATH == "no" ]]; then
           install_name_tool -id @executable_path/../lib/libnetcdf.$SO_EXT $VISITDIR/netcdf/$NETCDF_VERSION/$VISITARCH/lib/libnetcdf.$SO_EXT
           install_name_tool -id @executable_path/../lib/libnetcdf_c++.$SO_EXT $VISITDIR/netcdf/$NETCDF_VERSION/$VISITARCH/lib/libnetcdf_c++.$SO_EXT
        fi
    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 8.5, build_cgns                            #
# *************************************************************************** #

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

    #
    info "Configuring CGNS . . ."
    cd $CGNS_BUILD_DIR || error "Can't cd to CGNS build dir."
    info "Invoking command to configure CGNS"
    env CXX="$CXX_COMPILER" CC="$C_COMPILER" \
       CFLAGS="$C_OPT_FLAGS" CXXFLAGS="$CXX_OPT_FLAGS" \
       ./configure --prefix="$VISITDIR/cgns/$CGNS_VERSION/$VISITARCH"
    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 . . ."

        # Check for version >= 8.0.0 (MacOS 10.4, Tiger) for SystemStubs
        VER=$(uname -r)
        if (( ${VER%%.*} > 7 )) ; then
           USESTUBS="-lSystemStubs"
        else
           USESTUBS=""
        fi
        if [[ $ABS_PATH == "yes" ]]; then
           INSTALLNAMEPATH="$VISITDIR/cgns/${CGNS_VERSION}/$VISITARCH/lib"
        else
           INSTALLNAMEPATH="@executable_path/../lib"
        fi
        /usr/bin/libtool -o libcgns.${SO_EXT} -dynamic DARWIN/libcgns.a \
           -lSystem $USESTUBS -headerpad_max_install_names \
           -install_name $INSTALLNAMEPATH/libcgns.${SO_EXT} \
           -compatibility_version $CGNS_COMPATIBILITY_VERSION \
           -current_version $CGNS_VERSION
        if [[ $? != 0 ]] ; then
           warn "CGNS dynamic library creation failed.  Giving up"
           return 1
        fi
        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 8.6, build_gdal                            #
# *************************************************************************** #

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"
       else
           EXTRA_FLAGS="F77=\"\"--enable-static --disable-shared"
       fi
    else
       EXTRA_FLAGS="--enable-static --disable-shared"
    fi

    if [[ "$OPSYS" == "Darwin" ]]; then
        # Check for version 6.x.x (MacOS 10.2, Jaguar)
        VER=$(uname -r)
        if (( ${VER%%.*} < 7 )) ; then
            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
        fi
    fi
    ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" $EXTRA_FLAGS \
       CFLAGS="$C_OPT_FLAGS -DH5_USE_16_API" \
       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 \
       --without-jasper --without-python
    if [[ $? != 0 ]] ; then
       warn "GDAL configure failed.  Giving up"
       return 1
    fi

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

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

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

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

        cp .libs/libgdal.1.10.0.${SO_EXT} libgdal.${SO_EXT}
        if [[ $ABS_PATH == "yes" ]]; then
           INSTALLNAMEPATH="$VISITDIR/gdal/${GDAL_VERSION}/$VISITARCH/lib"
        else
           INSTALLNAMEPATH="@executable_path/../lib"
        fi
        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 8.7, build_exodus                          #
# *************************************************************************** #

function build_exodus
{
    #
    # Prepare build dir
    #
    prepare_build_dir $EXODUS_BUILD_DIR $EXODUS_FILE
    untarred_exodus=$?
    if [[ $untarred_exodus == -1 ]] ; then
       warn "Unable to prepare Exodus Build Directory. Giving Up"
       return 1
    fi

    cd $EXODUS_BUILD_DIR || error "Can't cd to exodus build dir."
    #
    # Build Exodus
    #
    info "Building Exodus . . . (~2 minutes)"

    cd cbind/src
    export NETCDFLIB="$VISITDIR/netcdf/$NETCDF_VERSION/$VISITARCH/lib"
    export NETCDFINC="$VISITDIR/netcdf/$NETCDF_VERSION/$VISITARCH/include"
    ${C_COMPILER} $C_OPT_FLAGS -I../include -I"$NETCDFINC" -c *.c
    if [[ $? != 0 ]] ; then
        warn "Exodus build failed.  Giving up"
        return 1
    fi
    #
    # Install into the VisIt third party location.
    #
    info "Installing Exodus . . ."

    mkdir "$VISITDIR/exodus"
    mkdir "$VISITDIR/exodus/$EXODUS_VERSION"
    mkdir "$VISITDIR/exodus/$EXODUS_VERSION/$VISITARCH"
    mkdir "$VISITDIR/exodus/$EXODUS_VERSION/$VISITARCH/inc"
    mkdir "$VISITDIR/exodus/$EXODUS_VERSION/$VISITARCH/lib"

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

        if [[ $ABS_PATH == "yes" ]]; then
           INSTALLNAMEPATH="$VISITDIR/exodus/${EXODUS_VERSION}/$VISITARCH/lib"
        else
           INSTALLNAMEPATH="@executable_path/../lib"
        fi
        ${C_COMPILER} -dynamiclib -o libexoIIv2c.${SO_EXT} *.o \
           -Wl,-headerpad_max_install_names \
           -Wl,-install_name,$INSTALLNAMEPATH/libexoIIv2c.${SO_EXT} \
           -Wl,-compatibility_version,4.0,-current_version,4.46 \
           -L$NETCDFLIB -lnetcdf
        if [[ $? != 0 ]] ; then
           warn "Creation of dynamic library failed.  Giving up"
           return 1
        fi
        cp libexoIIv2c.${SO_EXT} \
           "$VISITDIR/exodus/$EXODUS_VERSION/$VISITARCH/lib"
        cp ../include/*.h "$VISITDIR/exodus/$EXODUS_VERSION/$VISITARCH/inc"
        cp "$VISITDIR/netcdf/$NETCDF_VERSION/$VISITARCH/include/netcdf.h" \
           "$VISITDIR/exodus/$EXODUS_VERSION/$VISITARCH/inc"
        cp "$VISITDIR/netcdf/$NETCDF_VERSION/$VISITARCH/lib/libnetcdf.${SO_EXT}" \
           "$VISITDIR/exodus/$EXODUS_VERSION/$VISITARCH/lib"
    else
        ar -cr libexoIIv2c.a *.o
        if [[ $? != 0 ]] ; then
           warn "Exodus install failed.  Giving up"
           return 1
        fi
        cp libexoIIv2c.a "$VISITDIR/exodus/$EXODUS_VERSION/$VISITARCH/lib"
        cp ../include/exodusII.h \
           "$VISITDIR/exodus/$EXODUS_VERSION/$VISITARCH/inc"
        cp ../include/exodusII_ext.h \
           "$VISITDIR/exodus/$EXODUS_VERSION/$VISITARCH/inc"
        cp "$VISITDIR/netcdf/$NETCDF_VERSION/$VISITARCH/include/netcdf.h" \
           "$VISITDIR/exodus/$EXODUS_VERSION/$VISITARCH/inc"
        cp "$VISITDIR/netcdf/$NETCDF_VERSION/$VISITARCH/lib/libnetcdf.a" \
           "$VISITDIR/exodus/$EXODUS_VERSION/$VISITARCH/lib"
    fi

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


# *************************************************************************** #
#                         Function 8.8, build_boxlib                          #
# *************************************************************************** #

function apply_boxlib_25_aix_patch
{
   patch -p0 << \EOF
diff -c a/BoxLib/GNUmakefile CCSEApps/BoxLib/GNUmakefile
*** a/BoxLib/GNUmakefile
--- CCSEApps/BoxLib/GNUmakefile
***************
*** 7,16 ****
  TOP = $(PBOXLIB_HOME)
  
  PRECISION = DOUBLE
! DEBUG     = TRUE
  DIM       = 3
! COMP      = KCC
! USE_MPI   = TRUE
  #NAMESPACE = TRUE
  NAMESPACE = FALSE
  
--- 7,16 ----
  TOP = $(PBOXLIB_HOME)
  
  PRECISION = DOUBLE
! DEBUG     = FALSE
  DIM       = 3
! COMP      = xlC
! USE_MPI   = FALSE
  #NAMESPACE = TRUE
  NAMESPACE = FALSE
  
EOF

   if [[ $? != 0 ]] ; then
       warn "Unable to patch Boxlib 3D. Wrong version?"
       return 1
   fi

   return 0
}

function apply_boxlib_25_gcc_patch
{
    patch -p0 << \EOF
diff -c a/BoxLib/GNUmakefile CCSEApps/BoxLib/GNUmakefile
*** a/BoxLib/GNUmakefile
--- CCSEApps/BoxLib/GNUmakefile
*************** PBOXLIB_HOME = ..
*** 7,16 ****
  TOP = $(PBOXLIB_HOME)

  PRECISION = DOUBLE
! DEBUG     = TRUE
  DIM       = 3
! COMP      = KCC
! USE_MPI   = TRUE
  #NAMESPACE = TRUE
  NAMESPACE = FALSE

--- 7,16 ----
  TOP = $(PBOXLIB_HOME)

  PRECISION = DOUBLE
! DEBUG     = FALSE
  DIM       = 3
! COMP      = 
! USE_MPI   = FALSE
  #NAMESPACE = TRUE
  NAMESPACE = FALSE

EOF
   if [[ $? != 0 ]] ; then
       warn "Unable to patch Boxlib 3D. Wrong version?"
       return 1
   fi

   return 0
}

function apply_boxlib_25_darwin_patch
{
   patch -p0 << \EOF
diff -rp a/BoxLib/BaseFab.cpp CCSEApps/BoxLib/BaseFab.cpp
*** a/BoxLib/BaseFab.cpp
--- CCSEApps/BoxLib/BaseFab.cpp
***************
*** 28,34 ****
  #include <BArena.H>
  #include <CArena.H>
  #include <Thread.H>
! #include <SPECIALIZE_F.H>
  
  int BoxLib::BF_init::m_cnt = 0;
  
--- 28,34 ----
  #include <BArena.H>
  #include <CArena.H>
  #include <Thread.H>
! //#include <SPECIALIZE_F.H>
  
  int BoxLib::BF_init::m_cnt = 0;
  
*************** BaseFab<Real>::performCopy (const BaseFa
*** 98,105 ****
  
      BL_PROFILE("template<> BaseFab<Real>::performCopy()");
  
!     if (destbox == domain && srcbox == src.box())
!     {
          Real*       data_dst = dataPtr(destcomp);
          const Real* data_src = src.dataPtr(srccomp);
  
--- 98,105 ----
  
      BL_PROFILE("template<> BaseFab<Real>::performCopy()");
  
! //    if (destbox == domain && srcbox == src.box())
! //    {
          Real*       data_dst = dataPtr(destcomp);
          const Real* data_src = src.dataPtr(srccomp);
  
*************** BaseFab<Real>::performCopy (const BaseFa
*** 107,138 ****
          {
              *data_dst++ = *data_src++;
          }
!     }
!     else
!     {
!         const int* destboxlo  = destbox.loVect();
!         const int* destboxhi  = destbox.hiVect();
!         const int* _th_plo    = loVect();
!         const int* _th_phi    = hiVect();
!         const int* _x_lo      = srcbox.loVect();
!         const int* _x_hi      = srcbox.hiVect(); 
!         const int* _x_plo     = src.loVect();
!         const int* _x_phi     = src.hiVect();
!         Real*       _th_p     = dataPtr(destcomp);
!         const Real* _x_p      = src.dataPtr(srccomp);
! 
!         FORT_FASTCOPY(_th_p,
!                       ARLIM(_th_plo),
!                       ARLIM(_th_phi),
!                       D_DECL(destboxlo[0],destboxlo[1],destboxlo[2]),
!                       D_DECL(destboxhi[0],destboxhi[1],destboxhi[2]),
!                       _x_p,
!                       ARLIM(_x_plo),
!                       ARLIM(_x_phi),
!                       D_DECL(_x_lo[0],_x_lo[1],_x_lo[2]),
!                       D_DECL(_x_hi[0],_x_hi[1],_x_hi[2]),
!                       numcomp);
!     }
  }
  
  template<>
--- 107,138 ----
          {
              *data_dst++ = *data_src++;
          }
! //    }
! //    else
! //    {
! //        const int* destboxlo  = destbox.loVect();
! //        const int* destboxhi  = destbox.hiVect();
! //        const int* _th_plo    = loVect();
! //        const int* _th_phi    = hiVect();
! //        const int* _x_lo      = srcbox.loVect();
! //        const int* _x_hi      = srcbox.hiVect(); 
! //        const int* _x_plo     = src.loVect();
! //        const int* _x_phi     = src.hiVect();
! //        Real*       _th_p     = dataPtr(destcomp);
! //        const Real* _x_p      = src.dataPtr(srccomp);
! //
! //        FORT_FASTCOPY(_th_p,
! //                      ARLIM(_th_plo),
! //                      ARLIM(_th_phi),
! //                      D_DECL(destboxlo[0],destboxlo[1],destboxlo[2]),
! //                      D_DECL(destboxhi[0],destboxhi[1],destboxhi[2]),
! //                      _x_p,
! //                      ARLIM(_x_plo),
! //                      ARLIM(_x_phi),
! //                      D_DECL(_x_lo[0],_x_lo[1],_x_lo[2]),
! //                      D_DECL(_x_hi[0],_x_hi[1],_x_hi[2]),
! //                      numcomp);
! //    }
  }
  
  template<>
*************** BaseFab<Real>::performSetVal (Real      
*** 145,175 ****
      BL_ASSERT(domain.contains(bx));
      BL_ASSERT(ns >= 0 && ns + num <= nvar);
  
!     if (bx == domain)
!     {
          Real* data = &dptr[ns*numpts];
  
          for (long i = 0, N = num*numpts; i < N; i++)
          {
              *data++ = val;
          }
!     }
!     else
!     {
!         const int* _box_lo = bx.loVect();            
!         const int* _box_hi = bx.hiVect();            
!         const int* _th_plo = loVect();                           
!         const int* _th_phi = hiVect();
! 
!         Real* _th_p = dataPtr(ns);
! 
!         FORT_FASTSETVAL(&val,
!                         _box_lo,
!                         _box_hi,
!                         _th_p,
!                         ARLIM(_th_plo),
!                         ARLIM(_th_phi),
!                         num);
!     }
  }
  #endif
--- 145,175 ----
      BL_ASSERT(domain.contains(bx));
      BL_ASSERT(ns >= 0 && ns + num <= nvar);
  
! //    if (bx == domain)
! //    {
          Real* data = &dptr[ns*numpts];
  
          for (long i = 0, N = num*numpts; i < N; i++)
          {
              *data++ = val;
          }
! //    }
! //    else
! //    {
! //        const int* _box_lo = bx.loVect();            
! //        const int* _box_hi = bx.hiVect();            
! //        const int* _th_plo = loVect();                           
! //        const int* _th_phi = hiVect();
! 
! //        Real* _th_p = dataPtr(ns);
! 
! //        FORT_FASTSETVAL(&val,
! //                        _box_lo,
! //                        _box_hi,
! //                        _th_p,
! //                        ARLIM(_th_plo),
! //                        ARLIM(_th_phi),
! //                        num);
! //    }
  }
  #endif
diff -c a/BoxLib/FPC.cpp CCSEApps/BoxLib/FPC.cpp
*** a/BoxLib/FPC.cpp
--- CCSEApps/BoxLib/FPC.cpp
*************** FPC::NativeLongDescriptor ()
*** 64,70 ****
  #endif
  
  #if defined(__sgi) || \
!     defined(__sun) || \
      defined(_AIX)  || \
      defined(_CRAYT3E)  || \
      defined(__hpux)
--- 64,70 ----
  #endif
  
  #if defined(__sgi) || \
!     defined(__sun) || defined(__ppc__) || defined(__ppc64__) || \
      defined(_AIX)  || \
      defined(_CRAYT3E)  || \
      defined(__hpux)
*************** FPC::NativeRealDescriptor ()
*** 91,97 ****
  #endif
  
  #if defined(__sgi) || \
!     defined(__sun) || \
      defined(_AIX)  || \
      defined(_CRAYT3E)  || \
      defined(__hpux)
--- 91,97 ----
  #endif
  
  #if defined(__sgi) || \
!     defined(__sun) || defined(__ppc__) || defined(__ppc64__) || \
      defined(_AIX)  || \
      defined(_CRAYT3E)  || \
      defined(__hpux)
*************** FPC::Ieee64NormalRealDescriptor ()
*** 137,143 ****
        defined(_CRAY1)     || \
        defined(_CRAYT3E)   || \
        defined(__sgi)      || \
!       defined(__sun)      || \
        defined(__i486__)   || \
        defined(i386)       || \
        defined(__i386__)   || \
--- 137,143 ----
        defined(_CRAY1)     || \
        defined(_CRAYT3E)   || \
        defined(__sgi)      || \
!       defined(__sun)      || defined(__ppc__) || defined(__ppc64__) || \
        defined(__i486__)   || \
        defined(i386)       || \
        defined(__i386__)   || \
diff -c a/BoxLib/Make.package CCSEApps/BoxLib/Make.package
*** a/BoxLib/Make.package
--- CCSEApps/BoxLib/Make.package
*************** T_headers += ccse-mpi.H
*** 91,99 ****
  # Fortran interface routines.
  #
  
! f$(BOXLIB_BASE)_sources += BLutil_F.f
! f$(BOXLIB_BASE)_sources += BLParmParse_F.f
! f$(BOXLIB_BASE)_sources += BLBoxLib_F.f
  
! F$(BOXLIB_BASE)_sources += SPECIALIZE_$(DIM)D.F
! F$(BOXLIB_BASE)_headers += SPECIALIZE_F.H
--- 91,99 ----
  # Fortran interface routines.
  #
  
! #f$(BOXLIB_BASE)_sources += BLutil_F.f
! #f$(BOXLIB_BASE)_sources += BLParmParse_F.f
! #f$(BOXLIB_BASE)_sources += BLBoxLib_F.f
  
! #F$(BOXLIB_BASE)_sources += SPECIALIZE_$(DIM)D.F
! #F$(BOXLIB_BASE)_headers += SPECIALIZE_F.H
EOF
    if [[ $? != 0 ]] ; then
       warn "Unable to patch Boxlib 3D. Wrong version?"
       return 1
    fi

    return 0
}

# Modifies the makefile to use `gfortran' instead of `g77'.
function apply_boxlib_25_gfortran_patch
{

    patch -u -p0 << \EOF
--- CCSEApps/mk/Make.Linux	2003-02-05 09:33:24.000000000 -0700
+++ CCSEApps/mk/Make.Linux.gfortran	2008-10-06 16:47:30.000000000 -0600
@@ -51,7 +51,7 @@
   fOPTF += $(INTEL_EXTRA_OPT_FLAGS)
 else
 ifeq ($(FCOMP),f77)
-  FC       := g77 -fno-second-underscore
+  FC       := gfortran -fno-second-underscore
   fC       := $(FC)
   # default g77/f77 version
   FOPTF += -O
EOF
}

# Modifies the makefile to include `-fPIC' int he compiler flags.
function apply_boxlib_25_fPIC_patch
{
    patch -u -p0 << \EOF
--- CCSEApps/mk/Make.Linux	2003-02-05 09:33:24.000000000 -0700
+++ CCSEApps/mk/Make.Linux.fPIC	2008-10-06 16:46:16.000000000 -0600
@@ -54,10 +54,10 @@
   FC       := g77 -fno-second-underscore
   fC       := $(FC)
   # default g77/f77 version
-  FOPTF += -O
-  fOPTF += -O
-  FDEBF += -g
-  fDEBF += -g
+  FOPTF += -O -fPIC
+  fOPTF += -O -fPIC
+  FDEBF += -g -fPIC
+  fDEBF += -g -fPIC
   #DEFINES += -DBL_FORT_USE_UNDERSCORE
   #override XTRALIBS +=  -lf2c
 # LIBRARY_LOCATIONS += /usr/lib/gcc-lib/i386-redhat-linux/2.96
EOF
}

# Adds some defines so that boxlib builds properly on linux-ppc64
function apply_boxlib_25_ppc_patch
{
    patch -u -p1 << \EOF
--- visit-build-old/CCSEApps/BoxLib/FPC.cpp	2006-01-11 14:13:06.000000000 -0500
+++ visit-build/CCSEApps/BoxLib/FPC.cpp	2009-02-19 18:41:26.616492453 -0500
@@ -64,7 +64,7 @@
 #endif
 
 #if defined(__sgi) || \
-    defined(__sun) || \
+    defined(__sun) || defined powerpc || defined __powerpc || defined ppc || defined __ppc || \
     defined(_AIX)  || \
     defined(_CRAYT3E)  || \
     defined(__hpux)
@@ -91,7 +91,7 @@
 #endif
 
 #if defined(__sgi) || \
-    defined(__sun) || \
+    defined(__sun) || defined powerpc || defined __powerpc || defined ppc || defined __ppc || \
     defined(_AIX)  || \
     defined(_CRAYT3E)  || \
     defined(__hpux)
@@ -137,7 +137,7 @@
       defined(_CRAY1)     || \
       defined(_CRAYT3E)   || \
       defined(__sgi)      || \
-      defined(__sun)      || \
+      defined(__sun)      || defined powerpc || defined __powerpc || defined ppc || defined __ppc || \
       defined(__i486__)   || \
       defined(i386)       || \
       defined(__i386__)   || \
EOF
}

# Modifies the VisMF.cpp to use more const.
function apply_boxlib_25_const_patch
{
    patch -u -p0 << \EOF
--- CCSEApps/BoxLib/VisMF.cpp	2010-02-10 22:49:11.728859467 -0800
+++ CCSEApps/BoxLib/VisMF.cpp.const	2010-02-10 22:48:52.828860805 -0800
@@ -343,7 +343,7 @@
 {
     BL_ASSERT(filename[filename.length() - 1] != '/');
 
-    if (char* slash = strrchr(filename.c_str(), '/'))
+    if (const char* slash = strrchr(filename.c_str(), '/'))
     {
         //
         // Got at least one slash -- give'm the following tail.
@@ -368,7 +368,7 @@
 
     const char* str = filename.c_str();    
 
-    if (char* slash = strrchr(str, '/'))
+    if (const char* slash = strrchr(str, '/'))
     {
         //
         // Got at least one slash -- give'm the dirname including last slash.
EOF
}

function apply_boxlib_25_patch
{
   # We start by fixing the Makefiles ... one way for AIX, one way for GCC
   if [[ "$OPSYS" == "AIX" ]]; then
       apply_boxlib_25_aix_patch
       if [[ $? != 0 ]] ; then
           return 1
       fi
   else
       apply_boxlib_25_gcc_patch
       if [[ $? != 0 ]] ; then
           return 1
       fi
       apply_boxlib_25_fPIC_patch
       # Do we need to use gfortran instead of g77?
       if test -z `which g77`; then
           warn "g77 not found; patching BoxLib for gfortran compile."
           apply_boxlib_25_gfortran_patch
       fi
   fi

   # Fix some const
   apply_boxlib_25_const_patch

   # Now make the OPSYS specific changes
   if [[ "$OPSYS" == "Darwin" ]]; then
       apply_boxlib_25_darwin_patch
       if [[ $? != 0 ]] ; then
           return 1
       fi
   elif test `uname -m` = "ppc64" ; then
       apply_boxlib_25_ppc_patch
   fi

   return 0
}

function apply_boxlib_patch
{
   if [[ ${BOXLIB_VERSION} == 2.5 ]] ; then
       apply_boxlib_25_patch
       if [[ $? != 0 ]] ; then
           return 1
       fi
   fi

   return 0
}

function change_boxlib_dim_using_patches
{
    #
    # Apply patches
    #
    if [[ ${BOXLIB_VERSION} == 2.5 ]] ; then
       info "Changing the Boxlib dimension from 3 to 2! Going to $START_DIR"
       cd $START_DIR || error "Can't cd to ${START_DIR}"
       if [[ "$OPSYS" == "AIX" ]]; then
          info "PATCHING AIX"
          patch -p0 << \EOF
diff -c a/BoxLib/GNUmakefile CCSEApps/BoxLib/GNUmakefile
*** a/BoxLib/GNUmakefile
--- CCSEApps/BoxLib/GNUmakefile
*************** TOP = $(PBOXLIB_HOME)
*** 8,14 ****
  
  PRECISION = DOUBLE
  DEBUG     = FALSE
! DIM       = 3
  COMP      = xlC
  USE_MPI   = FALSE
  #NAMESPACE = TRUE
--- 8,14 ----
  
  PRECISION = DOUBLE
  DEBUG     = FALSE
! DIM       = 2
  COMP      = xlC
  USE_MPI   = FALSE
  #NAMESPACE = TRUE
EOF
       else
          info "PATCHING GCC"
          patch -p0 << \EOF
diff -c a/BoxLib/GNUmakefile CCSEApps/BoxLib/GNUmakefile
*** a/BoxLib/GNUmakefile
--- CCSEApps/BoxLib/GNUmakefile
*************** TOP = $(PBOXLIB_HOME)
*** 8,14 ****
  
  PRECISION = DOUBLE
  DEBUG     = FALSE
! DIM       = 3
  COMP      = 
  USE_MPI   = FALSE
  #NAMESPACE = TRUE
--- 8,14 ----
  
  PRECISION = DOUBLE
  DEBUG     = FALSE
! DIM       = 2
  COMP      = 
  USE_MPI   = FALSE
  #NAMESPACE = TRUE
EOF
       fi
       if [[ $? != 0 ]] ; then
           warn "Unable to patch Boxlib 2D. Wrong version?"
           return 1
       fi
    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 which had\n" \
               "already been patched ... that is, that 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 3D
    #
    info "Building Boxlib 3D. . . (~2 minutes)"

    if [[ "$OPSYS" == "Darwin" ]]; then
       cp ../mk/Make.FreeBSD ../mk/Make.Darwin
    fi
    $MAKE -f GNUmakefile CXX="$CXX_COMPILER" CC="$C_COMPILER" \
       CCFLAGS="$C_OPT_FLAGS" CXXFLAGS="$CXX_OPT_FLAGS"
    if [[ $? != 0 ]] ; then
       warn "Boxlib build failed.  Giving up"
       return 1
    fi
    #
    # Install into the VisIt third party location.
    #
    info "Installing Boxlib 3D. . ."

    mkdir "$VISITDIR/boxlib"
    mkdir "$VISITDIR/boxlib/$VISITARCH"
    mkdir "$VISITDIR/boxlib/$VISITARCH/include"
    mkdir "$VISITDIR/boxlib/$VISITARCH/lib"
    mkdir "$VISITDIR/boxlib/$VISITARCH/include/2D"
    mkdir "$VISITDIR/boxlib/$VISITARCH/include/3D"
    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
        if [[ $ABS_PATH == "yes" ]]; then
           INSTALLNAMEPATH="$VISITDIR/boxlib/$VISITARCH/lib"
        else
           INSTALLNAMEPATH="@executable_path/../lib"
        fi
        mkdir tmp
        cd tmp
        ar x ../libbox3d.Darwin.CC.f77.a
        $CXX_COMPILER -dynamiclib -o libbox3D.$SO_EXT *.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
        if [[ $? != 0 ]] ; then
          warn "Creation of dynamic 3D Boxlib library failed.  Giving up"
          return 1
        fi
        cp libbox3D.$SO_EXT "$VISITDIR/boxlib/$VISITARCH/lib/"
        rm *.o
        cd ..
        tar cf Boxlib3D.h.tar *.H
    else
       cp libbox3d*.a \
       "$VISITDIR/boxlib/$VISITARCH/lib/libbox3D.a"
       $TAR cf Boxlib3D.h.tar *.H
       if [[ $? != 0 ]] ; then
          warn "Boxlib install failed.  Giving up"
          return 1
       fi
    fi
    $MAKE clean

    change_boxlib_dim_using_patches

    cd $BOXLIB_BUILD_DIR || error "Can't cd to BoxLib build dir."
    #
    # Build Boxlib 2D
    #
    info "Building Boxlib 2D. . . (~2 minutes)"

    if [[ "$OPSYS" == "Darwin" ]]; then
       cp ../mk/Make.FreeBSD ../mk/Make.Darwin
    fi
    $MAKE -f GNUmakefile CXX="$CXX_COMPILER" CC="$C_COMPILER" \
       CCFLAGS="$C_OPT_FLAGS" CXXFLAGS="$CXX_OPT_FLAGS" 
    if [[ $? != 0 ]] ; then
       warn "Boxlib build failed.  Giving up"
       return 1
    fi
    info "Installing Boxlib 2D. . ." 

    if [[ "$DO_STATIC_BUILD" == "no" && "$OPSYS" == "Darwin" ]]; then
        if [[ $ABS_PATH == "yes" ]]; then
           INSTALLNAMEPATH="$VISITDIR/boxlib/$VISITARCH/lib"
        else
           INSTALLNAMEPATH="@executable_path/../lib"
        fi
        cd tmp
        ar x ../libbox2d.Darwin.CC.f77.a
        $CXX_COMPILER -dynamiclib -o libbox2D.$SO_EXT *.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
        if [[ $? != 0 ]] ; then
          warn "Creation of dynamic 2D Boxlib library failed.  Giving up"
          return 1
        fi
        cp libbox2D.$SO_EXT "$VISITDIR/boxlib/$VISITARCH/lib/"
        rm *.o
        cd ..
        rmdir tmp
        $TAR cf Boxlib2D.h.tar *.H
    else
        cp libbox2d*.a \
        "$VISITDIR/boxlib/$VISITARCH/lib/libbox2D.a"
        $TAR cf Boxlib2D.h.tar *.H
        if [[ $? != 0 ]] ; then
          warn "Boxlib install failed.  Giving up"
          return 1
        fi
    fi

    info "Installing Boxlib includes. . ."

    cp Boxlib2D.h.tar "$VISITDIR/boxlib/$VISITARCH/include/2D"
    cp Boxlib3D.h.tar "$VISITDIR/boxlib/$VISITARCH/include/3D"
    cd "$VISITDIR/boxlib/$VISITARCH/include/2D"
    tar xf Boxlib2D.h.tar
    cd "$VISITDIR/boxlib/$VISITARCH/include/3D"
    tar xf Boxlib3D.h.tar

    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 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="$C_OPT_FLAGS" 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 . . ."

        if [[ $ABS_PATH == "yes" ]]; then
           INSTALLNAMEPATH="$VISITDIR/cfitsio/${CFITSIO_VERSION}/$VISITARCH/lib"
        else
           INSTALLNAMEPATH="@executable_path/../lib"
        fi
## 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 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.
# ***************************************************************************

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

    #
    info "Configuring H5Part . . ."
    cd $H5PART_BUILD_DIR || error "Can't cd to h5part build dir."
    if [[ "$DO_HDF5" == "yes" ]] ; then
       export HDF5ROOT="$VISITDIR/hdf5/$HDF5_VERSION/$VISITARCH"
       export SZIPROOT="$VISITDIR/szip/$SZIP_VERSION/$VISITARCH"
       WITHHDF5ARG="--with-hdf5path=$HDF5ROOT"
       HDF5DYLIB="-L$HDF5ROOT/lib -L$SZIPROOT/lib -lhdf5 -lsz -lz"
    else
       WITHHDF5ARG="--without-hdf5path"
       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
    else
       export LD_LIBRARY_PATH="$VISITDIR/hdf5/$HDF5_VERSION/$VISITARCH/lib":\
"$VISITDIR/szip/$SZIP_VERSION/$VISITARCH/lib":\
$LD_LIBRARY_PATH
    fi
    info "Invoking command to configure H5Part"
    ./configure ${WITHHDF5ARG} ${OPTIONAL} CXX="$CXX_COMPILER" \
       CC="$C_COMPILER" CFLAGS="$C_OPT_FLAGS" CXXFLAGS="$CXX_OPT_FLAGS" \
       --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
        #
        info "Creating dynamic libraries for H5Part . . ."

        if [[ $ABS_PATH == "yes" ]]; then
           INSTALLNAMEPATH="$VISITDIR/h5part/${H5PART_VERSION}/$VISITARCH/lib"
        else
           INSTALLNAMEPATH="@executable_path/../lib"
        fi
        VER=$(uname -r)
        if (( ${VER%%.*} > 7 )) ; then
           USEGCC="-lSystemStubs"
        else
           USEGCC="-lgcc"
        fi
##        /usr/bin/libtool -o libH5Part.$SO_EXT -dynamic src/libH5Part.a \
##        -lSystem -headerpad_max_install_names \
##        -install_name $INSTALLNAMEPATH/libH5Part.$SO_EXT \
##        -compatibility_version $H5PART_COMPATIBILITY_VERSION \
##        -current_version $H5PART_VERSION ${HDF5DYLIB} ${USEGCC}
        gcc -o libH5Part.$SO_EXT -dynamiclib src/*.o -lSystem \
           -Wl,-headerpad_max_install_names \
           -Wl,-install_name,$INSTALLNAMEPATH/libH5Part.$SO_EXT \
           -Wl,-compatibility_version,$H5PART_COMPATIBILITY_VERSION \
           -Wl,-current_version,$H5PART_VERSION ${HDF5DYLIB}
        if [[ $? != 0 ]] ; then
           warn "Creating dynamic H5Part library failed.  Giving up"
           return 1
        fi
        cp libH5Part.$SO_EXT "$VISITDIR/h5part/$H5PART_VERSION/$VISITARCH/lib"
    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 8.11, build_ccmio                         #
# *************************************************************************** #

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

   return 0
}

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

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

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

   return 0
}

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

   return 0
}

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

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

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

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

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

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

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

        if [[ $ABS_PATH == "yes" ]]; then
           INSTALLNAMEPATH="$VISITDIR/ccmio/${CCMIO_VERSION}/$VISITARCH/lib"
        else
           INSTALLNAMEPATH="@executable_path/../lib"
        fi
        cp lib/release-shared/libadf.dylib .
        cp lib/release-shared/libccmio.dylib .
        install_name_tool -id \
          "$INSTALLNAMEPATH/libadf.$SO_EXT" "libadf.$SO_EXT"
        install_name_tool -id \
          "$INSTALLNAMEPATH/libccmio.$SO_EXT" "libccmio.$SO_EXT"
        install_name_tool -change \
          libadf.dylib.5.01.000 "$INSTALLNAMEPATH/libadf.$SO_EXT" \
         "libccmio.$SO_EXT"
        cp "libadf.$SO_EXT" \
          "$VISITDIR/ccmio/${CCMIO_VERSION}/$VISITARCH/lib/libadf.$SO_EXT"
        cp "libccmio.$SO_EXT" \
          "$VISITDIR/ccmio/${CCMIO_VERSION}/$VISITARCH/lib/libccmio.$SO_EXT"
    else
        cp `ls lib/*/release-static/libadf.a` \
           $VISITDIR/ccmio/${CCMIO_VERSION}/$VISITARCH/lib
        cp `ls lib/*/release-static/libccmio.a` \
           $VISITDIR/ccmio/${CCMIO_VERSION}/$VISITARCH/lib
    fi

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

# *************************************************************************** #
#                         Function 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 8.13, build_icet                         #
# *************************************************************************** #

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/mpic++" ]]; then
            PAR_INCLUDE_STRING="-I/usr/include/"
        else
            PAR_INCLUDE_STRING=`$PAR_COMPILER --showme:compile`    
        fi
    fi
    
    if [[ "$PAR_INCLUDE_STRING" == "" ]] ; then
       warn "You must set either the PAR_COMPILER or PAR_INCLUDE environment variable to be Ice-T."
       warn "PAR_COMPILER should be of the form \"/path/to/mpi/bin/mpic++\""
       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.

    # split string at space, grab the front/first string in it.
    PAR_INCLUDE_DIR=""
    for arg in $PAR_INCLUDE_STRING ; do
       if [[ "$arg" != "${arg#-I}" ]] ; then
          PAR_INCLUDE_DIR=${arg#-I}
          break
       fi
    done
    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 \"mpicxx -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="$VISITDIR/cmake/${CMAKE_VERSION}/$VISITARCH/bin/cmake"
    if [[ ! -f ${CMAKE_BIN} ]] ; then
       warn "Unable to locate CMake.  Giving Up!"
       return 1
    fi

    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

    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}
    ${CMAKE_BIN} \
        -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="-DUSE_MGL_NAMESPACE ${C_OPT_FLAGS}"\
        -DMPI_INCLUDE_PATH:PATH="${PAR_INCLUDE_DIR}"\
        -DMPI_LIBRARY:FILEPATH="./fakempi.${LIBEXT}"\
        -DBUILD_TESTING:BOOL=OFF\
        .
    rm fakempi.${LIBEXT}

    if [[ $? != 0 ]] ; then
       warn "Cannot get CMAKE to create the makefiles.  Giving up."
       return 1
    fi

    #
    # Now build Ice-T.
    #
    info "Building Ice-T . . . (~2 minutes)"
    $MAKE $MAKE_OPT_FLAGS
    if [[ $? != 0 ]] ; then
       warn "Ice-T did not build correctly.  Giving up."
       return 1
    fi

    info "Installing Ice-T . . ."

    $MAKE install
    if [[ $? != 0 ]] ; then
       warn "Ice-T: 'make install' failed.  Giving up"
       return 1
    fi

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

    cd "$START_DIR"
    echo "Done with Ice-T"
    return 0
}


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

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

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

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

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

# *************************************************************************** #
#                          Function 8.15, build_itaps_moab                    #
# *************************************************************************** #

function build_itaps_moab
{
    #
    # Prepare build dir
    #
    prepare_build_dir $ITAPS_MOAB_BUILD_DIR $ITAPS_MOAB_FILE
    untarred_itaps_moab=$?
    if [[ $untarred_itaps_moab == -1 ]] ; then
       warn "Unable to prepare ITAPS_MOAB build directory. Giving Up!"
       return 1
    fi
    
    #
    # Call configure
    #
    info "Configuring ITAPS_MOAB. . ."
    cd $ITAPS_MOAB_BUILD_DIR || error "Cannot cd to $ITAPS_MOAB_BUILD_DIR build dir."
    info "Invoking command to configure ITAPS_MOAB"
    if [[ "$DO_HDF5" == "yes" ]] ; then
       WITHHDF5ARG="--with-hdf5=$VISITDIR/hdf5/$HDF5_VERSION/$VISITARCH --with-hdf5-ldflags=-lz"
    else
       WITHHDF5ARG="--without-hdf5"
    fi
    if [[ "$DO_SZIP" == "yes" ]] ; then
       WITHSZIPARG="--with-szip=$VISITDIR/szip/$SZIP_VERSION/$VISITARCH"
    else
       WITHSZIPARG="--without-szip"
    fi
    if [[ "$DO_NETCDF" == "yes" ]] ; then
       WITHNETCDFARG="--with-netcdf=$VISITDIR/netcdf/$NETCDF_VERSION/$VISITARCH"
    else
       WITHNETCDFARG="--without-netcdf"
    fi
    ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" \
        CFLAGS="$C_OPT_FLAGS" CXXFLAGS="$CXX_OPT_FLAGS" \
        --prefix="$VISITDIR/itaps/MOAB/$ITAPS_MOAB_VERSION/$VISITARCH" \
        --enable-imesh=nofortran --with-zlib \
        $WITHHDF5ARG "$WITHSZIPARG" "$WITHNETCDFARG"
    if [[ $? != 0 ]] ; then
       warn "ITAPS_MOAB configure failed.  Giving up"
       return 1
    fi

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

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

    if [[ "$OPSYS" == "Darwin" ]]; then
        warn "I do not know how to install ITAPS_MOAB on a Mac. Giving up"
    else
        $MAKE install
        if [[ $? != 0 ]] ; then
           warn "ITAPS_MOAB install failed.  Giving up"
           return 1
        fi
        # To make it easier to package this build up, ensure we don't wind up
        # liking to shared libraries.
        find $VISITDIR/itaps/MOAB/$ITAPS_MOAB_VERSION/$VISITARCH -name 'lib*.so*' -exec rm -f {} \;
    fi

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

# *************************************************************************** #
#                          Function 8.16, build_itaps_fmdb                    #
# *************************************************************************** #

function build_itaps_fmdb
{
    #
    # Prepare build dir
    #
    prepare_build_dir $ITAPS_FMDB_BUILD_DIR $ITAPS_FMDB_FILE
    untarred_itaps_fmdb=$?
    if [[ $untarred_itaps_fmdb == -1 ]] ; then
       warn "Unable to prepare ITAPS_FMDB build directory. Giving Up!"
       return 1
    fi
    
    #
    # Call configure
    #
    info "Configuring ITAPS_FMDB. . ."
    cd $ITAPS_FMDB_BUILD_DIR || error "Cannot cd to $ITAPS_FMDB_BUILD_DIR build dir."
    info "Invoking command to configure ITAPS_FMDB"
    ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" \
        CFLAGS="$C_OPT_FLAGS" CXXFLAGS="$CXX_OPT_FLAGS" \
        --prefix="$VISITDIR/itaps/FMDB/$ITAPS_FMDB_VERSION/$VISITARCH" \
        --enable-iMesh
    if [[ $? != 0 ]] ; then
       warn "ITAPS_FMBD configure failed.  Giving up"
       return 1
    fi

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

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

    if [[ "$OPSYS" == "Darwin" ]]; then
        warn "I do not know how to install ITAPS_FMDB on a Mac. Giving up"
    else
        $MAKE install
        if [[ $? != 0 ]] ; then
           warn "ITAPS_FMDB install failed.  Giving up"
           return 1
        fi
        # To make it easier to package this build up, ensure we don't wind up
        # liking to shared libraries.
        find $VISITDIR/itaps/FMDB/$ITAPS_FMDB_VERSION/$VISITARCH -name 'lib*.so*' -exec rm -f {} \;
    fi

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

# *************************************************************************** #
#                       Function 8.16, build_itaps_grummp                     #
# *************************************************************************** #

function build_itaps_grummp
{
    #
    # Prepare build dir
    #
    prepare_build_dir $ITAPS_GRUMMP_BUILD_DIR $ITAPS_GRUMMP_FILE
    untarred_itaps_grummp=$?
    if [[ $untarred_itaps_grummp == -1 ]] ; then
       warn "Unable to prepare ITAPS_GRUMMP build directory. Giving Up!"
       return 1
    fi
    
    #
    # Call configure
    #
    info "Configuring ITAPS_GRUMMP. . ."
    cd $ITAPS_GRUMMP_BUILD_DIR || error "Cannot cd to $ITAPS_GRUMMP_BUILD_DIR build dir."
    info "Invoking command to configure ITAPS_GRUMMP"
    ./configure CXX="$CXX_COMPILER" CC="$C_COMPILER" \
        CFLAGS="$C_OPT_FLAGS" CXXFLAGS="$CXX_OPT_FLAGS" \
        --prefix="$VISITDIR/itaps/GRUMMP/$ITAPS_GRUMMP_VERSION/$VISITARCH" \
        --enable-itaps
    if [[ $? != 0 ]] ; then
       warn "ITAPS_GRUMMP configure failed.  Giving up"
       return 1
    fi

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

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

    if [[ "$OPSYS" == "Darwin" ]]; then
        warn "I do not know how to install ITAPS_GRUMMP on a Mac. Giving up"
    else
        $MAKE install
        if [[ $? != 0 ]] ; then
           warn "ITAPS_GRUMMP install failed.  Giving up"
           return 1
        fi
        # To make it easier to package this build up, ensure we don't wind up
        # liking to shared libraries.
        find $VISITDIR/itaps/GRUMMP/$ITAPS_GRUMMP_VERSION/$VISITARCH -name 'lib*.so*' -exec rm -f {} \;
    fi

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

# *************************************************************************** #
#                         Function 8.18, build_advio                          #
# *************************************************************************** #

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

    # 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="$C_OPT_FLAGS" 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 9, build_hostconf                         #
# *************************************************************************** #

function build_hostconf
{
    #
    # Set up environment variables for the configure step.
    #
    PARFLAGS=""
    CXXFLAGS="$CXX_OPT_FLAGS"
    CFLAGS="$C_OPT_FLAGS"
    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"
    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)
    echo "#$THIRD_PARTY_ABS_PATH/cmake/$CMAKE_VERSION/$VISITARCH/bin/cmake" > $HOSTCONF
    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 "##" >> $HOSTCONF
    echo \
"## Specify the location of the mesa." >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "VISIT_OPTION_DEFAULT(VISIT_MESA_DIR \${VISITHOME}/mesa/$MESA_VERSION/\${VISITARCH})" >> $HOSTCONF
    echo >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo \
"## Specify the location of the vtk." >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "VISIT_OPTION_DEFAULT(VISIT_VTK_DIR \${VISITHOME}/vtk/$VTK_VERSION/\${VISITARCH}/lib/vtk-5.0/)" >> $HOSTCONF
    echo >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "## Specify the Qt4 binary dir. " >> $HOSTCONF
    echo "## (qmake us used to locate & setup Qt4 dependencies)" >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "VISIT_OPTION_DEFAULT(VISIT_QT_BIN \${VISITHOME}/qt/$QT_VERSION/\${VISITARCH}/bin)" >> $HOSTCONF
    echo >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo \
"## Specify the location of the python." >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "VISIT_OPTION_DEFAULT(VISIT_PYTHON_DIR \${VISITHOME}/python/$PYTHON_VERSION/\${VISITARCH})" >> $HOSTCONF
    echo >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "## Compiler flags." >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "VISIT_OPTION_DEFAULT(VISIT_C_COMPILER $C_COMPILER)">> $HOSTCONF
    echo "VISIT_OPTION_DEFAULT(VISIT_CXX_COMPILER $CXX_COMPILER)" >> $HOSTCONF

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

    if [[ "$parallel" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## Parallel Build Setup." >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_PARALLEL ON)" >> $HOSTCONF
        # we either set an mpi wrapper compiler in the host conf
        if [[ "$VISIT_MPI_COMPILER" != "" ]] ; then
            echo "## (configured w/ mpi compiler wrapper)" >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(VISIT_MPI_COMPILER $VISIT_MPI_COMPILER)"  >> $HOSTCONF
        else
            # or we just set the flags.
            echo "## (configued w/ user provided CXX (PAR_INCLUDE) & LDFLAGS (PAR_LIBS) flags)" \
             >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(VISIT_MPI_CXX_FLAGS \"$PAR_INCLUDE\")"     >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(VISIT_MPI_LD_FLAGS  \"$PAR_LINKER_FLAGS\")" >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(VISIT_MPI_LIBS        $PAR_LIBRARY_NAMES)" >> $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)" >> $HOSTCONF
    fi

    echo >> $HOSTCONF
    echo \
"##############################################################" >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "## Database reader plugin support libraries" >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo \
"##############################################################" >> $HOSTCONF

    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

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

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

    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

    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
    fi

    if [[ "$DO_EXODUS" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## Exodus" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_EXODUSII_DIR \${VISITHOME}/exodus/$EXODUS_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
    fi

    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

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

    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 /usr/lib jpeg)" \
            >> $HOSTCONF
        else
            echo \
            "VISIT_OPTION_DEFAULT(VISIT_HDF4_LIBDEP jpeg)" \
            >> $HOSTCONF
        fi
        >> $HOSTCONF
    fi

    if [[ "$DO_HDF5" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## HDF5" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_HDF5_DIR \${VISITHOME}/hdf5/$HDF5_VERSION/\${VISITARCH})" \
        >> $HOSTCONF 
        if [[ "$DO_SZIP" == "yes" ]] ; then
            echo \
            "VISIT_OPTION_DEFAULT(VISIT_HDF5_LIBDEP \${VISITHOME}/szip/$SZIP_VERSION/\${VISITARCH}/lib sz)" \
            >> $HOSTCONF
        fi
    fi

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

    fi

    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

    if [[ "$DO_NETCDF" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## NetCDF" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_NETCDF_DIR \${VISITHOME}/netcdf/$NETCDF_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
    fi

    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

    if [[ "$DO_SILO" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## Silo" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_SILO_DIR \${VISITHOME}/silo/$SILO_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
        if [[ "$DO_HDF5" == "yes" ]] ; then
            echo \
            "VISIT_OPTION_DEFAULT(VISIT_SILO_LIBDEP HDF5_LIBRARY_DIR hdf5 \${VISIT_HDF5_LIBDEP})" \
            >> $HOSTCONF
        fi
    fi
    if [[ "$DO_VISUS" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## Visus" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_VISUS_DIR \${VISITHOME}/visus/$VISUS_VERSION/\${VISITARCH})" \
        >> $HOSTCONF
    fi
    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
    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

    if [[ "$DO_ITAPS" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## ITAPS" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## MOAB implementation" >> $HOSTCONF
        echo "ITAPS_INCLUDE_DIRECTORIES(MOAB \${VISITHOME}/itaps/MOAB/$ITAPS_MOAB_VERSION/\${VISITARCH}/include)" \
        >> $HOSTCONF
        echo "ITAPS_FILE_PATTERNS(MOAB *.cub)" >> $HOSTCONF
        echo "ITAPS_LINK_LIBRARIES(MOAB iMesh MOAB hdf5 sz z netcdf_c++ netcdf vtkGraphics)" \
        >> $HOSTCONF
        echo "ITAPS_LINK_DIRECTORIES(MOAB " \
             "\${VISITHOME}/itaps/MOAB/$ITAPS_MOAB_VERSION/\${VISITARCH}/lib " \
             "\${VISITHOME}/hdf5/${HDF5_VERSION}/\${VISITARCH}/lib " \
             "\${VISITHOME}/szip/${SZIP_VERSION}/\${VISITARCH}/lib " \
             "\${VISITHOME}/netcdf/${NETCDF_VERSION}/\${VISITARCH}/lib)" >> $HOSTCONF
        echo "## FMDB implementation" >> $HOSTCONF
        echo "ITAPS_INCLUDE_DIRECTORIES(FMDB \${VISITHOME}/itaps/FMDB/$ITAPS_FMDB_VERSION/\${VISITARCH}/include/FMDB)" \
        >> $HOSTCONF
        echo "ITAPS_FILE_PATTERNS(FMDB *.sms)" >> $HOSTCONF
        echo "ITAPS_LINK_LIBRARIES(FMDB FMDB SCORECModel SCORECUtil vtkGraphics)" >> $HOSTCONF
        echo "ITAPS_LINK_DIRECTORIES(FMDB \${VISITHOME}/itaps/FMDB/$ITAPS_FMDB_VERSION/\${VISITARCH}/lib)" >> $HOSTCONF
        echo "## GRUMMP implementation" >> $HOSTCONF
        echo "ITAPS_INCLUDE_DIRECTORIES(GRUMMP \${VISITHOME}/itaps/GRUMMP/$ITAPS_GRUMMP_VERSION/\${VISITARCH}/include)" \
        >> $HOSTCONF
        echo "ITAPS_FILE_PATTERNS(GRUMMP *.bdry *.smesh *.vmesh)" >> $HOSTCONF
        echo "ITAPS_LINK_LIBRARIES(GRUMMP iMesh_GRUMMP GR_3D GR_surf GR_2D GR_base SUMAAlog_lite OptMS vtkGraphics)" \
        >> $HOSTCONF
        echo "ITAPS_LINK_DIRECTORIES(GRUMMP \${VISITHOME}/itaps/GRUMMP/$ITAPS_GRUMMP_VERSION/\${VISITARCH}/lib)" \
        >> $HOSTCONF
    fi
    echo >> $HOSTCONF
    cd "$START_DIR"
    echo "Done creating $HOSTCONF"
    return 0
}

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

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

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

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

    #
    # Call configure
    # 
    info "Configuring VisIt . . ."
    EXTRA_FEATURES=""
    if [[ "${DO_MODULE}" == "yes" ]] ; then
       EXTRA_FEATURES="${EXTRA_FEATURES} --enable-visitmodule"
    fi
    if [[ "${DO_JAVA}" == "yes" ]] ; then
       EXTRA_FEATURES="${EXTRA_FEATURES} --enable-java"
    fi
    if [[ "${DO_SLIVR}" == "yes" ]] ; then
       EXTRA_FEATURES="${EXTRA_FEATURES} --enable-slivr"
    fi
    # A dbio-only build disables pretty much everything else.
    if [[ "${DO_DBIO_ONLY}" == "yes" ]] ; then
       EXTRA_FEATURES="--enable-dbio-only"
    fi
    ./configure ${PARFLAGS} ${EXTRA_FEATURES}
    if [[ $? != 0 ]] ; then
       echo "VisIt configure failed.  Giving up"
       return 1
    fi

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

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

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

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" "C_OPT_FLAGS=" "${C_OPT_FLAGS}"
  printf "%s%s\n" "CXX_OPT_FLAGS=" "${CXX_OPT_FLAGS}"
  printf "%s%s\n" "PAR_INCLUDE=" "${PAR_INCLUDE}"
  printf "%s%s\n" "PAR_LIBS=" "${PAR_LIBS}"

  printf "%s%s\n" "MAKE=" "${MAKE}"
  printf "%s%s\n" "THIRD_PARTY_PATH=" "${THIRD_PARTY_PATH}"
  printf "%s%s\n" "GROUP=" "${GROUP}"
  printf "%s%s\n" "LOG_FILE=" "${LOG_FILE}"
  printf "%s%s\n" "LOG_FILE=" "${LOG_FILE}"
  printf "%s%s\n" "WGET_OPTS=" "${WGET_OPTS}"
  printf "%s%s\n" "SVNREVISION=" "${SVNREVISION}"
  printf "%s%s\n" "VISIT_FILE=" "${VISIT_FILE}"

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

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

  printf "%s%s\n" "MESA_FILE=" "${MESA_FILE}"
  printf "%s%s\n" "MESA_VERSION=" "${MESA_VERSION}"
  printf "%s%s\n" "MESA_TARGET=" "${MESA_TARGET}"
  printf "%s%s\n" "MESA_BUILD_DIR=" "${MESA_BUILD_DIR}"

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

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

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

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

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

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

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

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

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

  printf "%s%s\n" "EXODUS_FILE=" "${EXODUS_FILE}"
  printf "%s%s\n" "EXODUS_VERSION=" "${EXODUS_VERSION}"
  printf "%s%s\n" "EXODUS_COMPATIBILITY_VERSION=" "${EXODUS_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "EXODUS_BUILD_DIR=" "${EXODUS_BUILD_DIR}"

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

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

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

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

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

  printf "%s%s\n" "ITAPS_MOAB_FILE=" "${ITAPS_MOAB_FILE}"
  printf "%s%s\n" "ITAPS_MOAB_VERSION=" "${ITAPS_MOAB_VERSION}"
  printf "%s%s\n" "ITAPS_MOAB_COMPATIBILITY_VERSION=" "${ITAPS_MOAB_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "ITAPS_MOAB_BUILD_DIR=" "${ITAPS_MOAB_BUILD_DIR}"

  printf "%s%s\n" "ITAPS_FMDB_FILE=" "${ITAPS_FMDB_FILE}"
  printf "%s%s\n" "ITAPS_FMDB_VERSION=" "${ITAPS_FMDB_VERSION}"
  printf "%s%s\n" "ITAPS_FMDB_COMPATIBILITY_VERSION=" "${ITAPS_FMDB_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "ITAPS_FMDB_BUILD_DIR=" "${ITAPS_FMDB_BUILD_DIR}"

  printf "%s%s\n" "ITAPS_GRUMMP_FILE=" "${ITAPS_GRUMMP_FILE}"
  printf "%s%s\n" "ITAPS_GRUMMP_VERSION=" "${ITAPS_GRUMMP_VERSION}"
  printf "%s%s\n" "ITAPS_GRUMMP_COMPATIBILITY_VERSION=" "${ITAPS_GRUMMP_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "ITAPS_GRUMMP_BUILD_DIR=" "${ITAPS_GRUMMP_BUILD_DIR}"

  printf "%s%s\n" "VISUS_FILE=" "${VISUS_FILE}"
  printf "%s%s\n" "VISUS_VERSION=" "${VISUS_VERSION}"
  printf "%s%s\n" "VISUS_COMPATIBILITY_VERSION=" "${VISUS_COMPATIBILITY_VERSION}"
  printf "%s%s\n" "VISUS_BUILD_DIR=" "${VISUS_BUILD_DIR}"

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

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

  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}"
}
usage () {
  printf "Usage: %s [options]\n" $0
  printf "A download attempt will be made for all files which do not exist."
  printf "\n\n"
  printf "BOOLEAN FLAGS\n"
  printf "\tThese are used to enable or disable specific functionality.  They do not take option values.\n\n"
  printf "%-15s %s [%s]\n" "--advio"   "Build AdvIO" "$DO_ADVIO"
  printf "%-15s %s [%s]\n" "--boxlib"  "Build Boxlib" "$DO_BOXLIB"
  printf "%-15s %s [%s]\n" "--ccmio"   "Build Star-CD support" "$DO_CCMIO"
  printf "%-15s %s [%s]\n" "--cfitsio" "Build CFITSIO" "$DO_CFITSIO"
  printf "%-15s %s [%s]\n" "--cgns"    "Build CGNS" "$DO_CGNS"
  printf "%-15s %s [%s]\n" "--cmake"   "Build CMake" "built by default unless --no-thirdparty flag is used"
  printf "%-15s %s [%s]\n" "--console" "Do not use dialog ('graphical') interface" "!$GRAPHICAL"
  printf "%-15s %s [%s]\n" "--debug"   "Enable debugging for this script" "false"
  printf "%-15s %s [%s]\n" "--exodus" "Build Exodus (requires NetCDF)" "$DO_EXODUS"
  printf "%-15s %s [%s]\n" "--fastbit" "Build FastBit" "$DO_FASTBIT"
  printf "%-15s %s [%s]\n" "--flags-debug" "Add '-g' to C[XX]FLAGS" "false"
  printf "%-15s %s [%s]\n" "--gdal" "Build GDAL" "$DO_GDAL"
  printf "%-15s %s [%s]\n" "--group" "Group name of installed libraries" "$GROUP"
  printf "%-15s %s [%s]\n" "--h5part" "Build H5Part" "$DO_H5PART"
  printf "%-15s %s [%s]\n" "--hdf4" "Build HDF4" "${DO_HDF4}"
  printf "%-15s %s [%s]\n" "--hdf5" "Build HDF5" "${DO_HDF5}"
  printf "%-15s %s [%s]\n" "-h" "Display this help message." "false"
  printf "%-15s %s [%s]\n" "--help" "Display this help message." "false"
  printf "%-15s %s [%s]\n" "--icet" "Build Ice-T (parallel rendering lib)" "$DO_ICET"
  printf "%-15s %s [%s]\n" "--itaps" "Build ITAPS" "${DO_ITAPS}"
  printf "%-15s %s [%s]\n" "--java" "Build with the Java client library" "${DO_JAVA}"
  printf "%-15s %s [%s]\n" "--mesa" "Build Mesa" "built by default unless --no-thirdparty flag is used"
  printf "%-15s %s [%s]\n" "--mili" "Build Mili" "$DO_MILI"
  printf "\t\t%15s\n" "NOTE: not available for download from web"
  printf "%-15s %s [%s]\n" "--netcdf" "Build NetCDF" "${DO_NETCDF}"
  printf "%-15s %s [%s]\n" "--no-visit" "Do not build VisIt, build 3rd party libraries only" "$DO_VISIT"
  printf "%-15s %s [%s]\n" "--no-thirdparty" "Do not build required 3rd party libraries" "$ON_THIRD_PARTY"
  printf "%-15s %s [%s]\n" "--no-icet" "Ice-T is automatically built with --enable-parallel.  Prevent it from being built" "$PREVENT_ICET"
  printf "%-15s %s [%s]\n" "--no-hostconf" "Do not create host.conf file." "$ON_HOSTCONF"
  printf "%-15s %s [%s]\n" "--parallel" "Enable parallel build, display MPI prompt" "$parallel"
  printf "%-15s %s [%s]\n" "--print-vars" "Display user settable environment variables" "false"
  printf "%-15s %s [%s]\n" "--python" "Build Python" "built by default unless --no-thirdparty flag is used"
  printf "%-15s %s [%s]\n" "--python-module" "Build with the VisIt Python module" "$DO_MODULE"
  printf "%-15s %s [%s]\n" "--qt" "Build Qt" "built by default unless --no-thirdparty flag is used"
  printf "%-15s %s [%s]\n" "--silo" "Build Silo support" "$DO_SILO"
  printf "%-15s %s [%s]\n" "--slivr" "Build with SLIVR shader support" "$DO_SLIVR"
  printf "%-15s %s [%s]\n" "--static" "Build using static linking" "$DO_STATIC_BUILD"
  printf "%-15s %s [%s]\n" "--stdout" "Write build log to stdout" "$LOG_FILE"
  printf "%-15s %s [%s]\n" "--szip" "Build with SZIP" "$DO_SZIP"
  printf "%-15s %s [%s]\n" "--tcmalloc" "Build tcmalloc from Google's perftools" "$DO_TCMALLOC"
  printf "\t\t%15s\n" "NOTE: not available for download from web"
  printf "%-15s %s [%s]\n" "--visus" "Build ViSUS (experimental!)" "$DO_VISUS"
  printf "%-15s %s [%s]\n" "--vtk" "Build VTK" "built by default unless --no-thirdparty flag is used"
  printf "%-15s %s [%s]\n" "--dbio-only" "Disables EVERYTHING but I/O." "$DO_DBIO_ONLY"
  printf "%s\n" ""
  printf "OPTIONS\n"
  printf "These values all take a special value.  If given, they require an associated value to be provided as well.\n\n"
  printf "%-12s %s [%s]\n" "--absolute" \
    "Change the behavior of the install name path for
             the Darwin dynamic libraries. Enabling this flag
             will use the absolute THIRD_PARTY_PATH path for 
             each library's install name directory instead of
             the relative path (@executable_relative/../lib).
             This is the opposite of --relative." "$ON_ABS_PATH"
  printf "%-12s %s \n" "--relative" \
    "Use @executable_relative/../lib for the library
             install name directory on Darwin. This is the
             opposite of using --absolute."
  printf "%s <%s> %s [%s]\n" "--arch" "architecture" "Set architecture" "$VISITARCHTMP"
  printf "\t  %s\n" "   This variable is used in constructing the 3rd party"
  printf "\t  %s\n" "   library path; usually set to something like"
  printf "\t  %s\n" "   'linux_gcc-3.4.6' or 'Darwin_gcc-4.0.1'"
  printf "%-11s %s [%s]\n" "--cflag"   "Append a flag to CFLAGS" "${CFLAGS}"
  printf "%-11s %s [%s]\n" "--cxxflag" "Append a flag to CXXFLAGS" "$CXXFLAGS"
  printf "%-11s %s [%s]\n" "--cflags"  "Explicitly set CFLAGS" "$CFLAGS"
  printf "%-11s %s [%s]\n" "--cxxflags" "Explicitly set CXXFLAGS" "$CXXFLAGS"
  printf "%-11s %s [%s]\n" "--cc"  "Explicitly set C_COMPILER" "$C_COMPILER"
  printf "%-11s %s [%s]\n" "--cxx" "Explicitly set CXX_COMPILER" "$CXX_COMPILER"
  printf "%-11s <%s> %s [%s]\n" "--makeflags" "flags" "Flags to 'make'" "$MAKE_OPT_FLAGS"
  printf "%s <%s> %s\n" "--svn" \
    "Obtain VisIt source code and third party libraries from the SVN server"
  printf "\t%s\n" "    [svn co $SVN_REPO_ROOT_PATH/trunk/src]"
  printf "%s <%s> %s\n" "--svn-anonymous" \
    "Obtain VisIt source code and third party libraries using the anonymous SVN mirror."
  printf "\t%s\n" "    [svn co $SVN_ANON_ROOT_PATH/trunk/src]"
  printf "%s <%s> %s\n" "--svn-revision" "revision" \
    "Specify the SVN revision of the VisIt source code and third party libraries to download.  Used in conjunction with --svn or --svn-anonymous."
  printf "%s <%s> %s [%s]\n" "--tarball" "file" "tarball to extract VisIt from" "$VISIT_FILE"
  printf "%-11s <%s> \n%s [%s]\n" "--thirdparty-path" "/path/to/directory" \
    "             Specify the root directory name under which the 3rd party
             libraries have been installed.  If defined, it would typically
             mean the 3rd party libraries are pre-built and are installed
             somewhere like /usr/gapps/visit." "${THIRD_PARTY_PATH}"
  printf "%s <%s> %s [%s]\n" "--version" "version" "The VisIt version to build" "$VISIT_VERSION"
}

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

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

# Fix the arguments: cram quoted strings into a single argument.
declare -a arguments
quoting="" # temp buffer for concatenating quoted args
state=0    # 0 is the default state, for grabbing std arguments.
           # 1 is for when we've seen a quote, and are currently "cramming"
for arg in $@ ; do
    case $state in
        0)
            if $(starts_with_quote "$arg") ; then
                state=1
                quoting="${arg}"
            else
                state=0
                tval="${arg}"
                arguments[${#arguments[@]}]=$tval
            fi
            ;;
        1)
            if $(starts_with_quote "$arg") ; then
                state=0
                arguments="${quoting}"
            elif $(ends_with_quote "$arg") ; then
                quoting="${quoting} ${arg}"
                tval="${quoting}"
                arguments[${#arguments[@]}]=$tval
                state=0
            else
                quoting="${quoting} ${arg}"
            fi
            ;;
        *) error "invalid state.";;
    esac
done

# 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=""
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
            append-cflags) C_OPT_FLAGS="${C_OPT_FLAGS} ${arg}";;
            append-cxxflags) CXX_OPT_FLAGS="${CXX_OPT_FLAGS} ${arg}";;
            arch) VISITARCH="${arg}";;
            cflags) C_OPT_FLAGS=$(strip_quotes "${arg}");;
            cxxflags) CXX_OPT_FLAGS=$(strip_quotes "${arg}");;
            cc) C_COMPILER="${arg}";;
            cxx) CXX_COMPILER="${arg}";;
            flags-debug) C_OPT_FLAGS="${C_OPT_FLAGS} -g"
                         CXX_OPT_FLAGS="${CXX_OPT_FLAGS} -g";;
            makeflags) MAKE_OPT_FLAGS="${arg}";;
            group) GROUP="${arg}";;
            svn) SVNREVISION="${arg}";;
            tarball) VISIT_FILE="${arg}";;
            thirdparty-path) THIRD_PARTY_PATH="${arg}";;
            version) VISIT_VERSION="${arg}"
                     VISIT_FILE="visit${VISIT_VERSION}.tar.gz";;
            *) error "Unknown next_arg value '$next_arg'!"
        esac
        # Make sure we process the next option as an option and not an
        # argument to an option.
        next_arg=""
        continue
    fi
    case $arg in
        --absolute) ABS_PATH="yes"; ON_ABS_PATH="on";;
        --advio) DO_ADVIO="yes"; ON_ADVIO="on";;
        --arch) next_arg="arch";;
        --boxlib) DO_BOXLIB="yes"; ON_BOXLIB="on";;
        --ccmio) DO_CCMIO="yes"; ON_CCMIO="on";;
        --cfitsio) DO_CFITSIO="yes"; ON_CFITSIO="on";;
        --cflag) next_arg="append-cflags";;
        --cflags) next_arg="cflags";;
        --cgns) DO_CGNS="yes"; ON_CGNS="on";;
        --cmake) DO_CMAKE="yes"; ON_CMAKE="on";;
        --cxxflag) next_arg="append-cxxflags";;
        --cxxflags) next_arg="cxxflags";;
        --cc) next_arg="cc";;
        --cxx) next_arg="cxx";;
        --console) GRAPHICAL="no"; ON_GRAPHICAL="off";;
        --debug) set -vx;;
        --fastbit) DO_FASTBIT="yes"; ON_FASTBIT="on"
                  DO_HDF5="yes"; ON_HDF5="on";;
        --exodus) DO_EXODUS="yes"; ON_EXODUS="on"
                  DO_NETCDF="yes"; ON_NETCDF="on";;
        --flags-debug) next_arg="flags-debug";;
        --gdal) DO_GDAL="yes"; ON_GDAL="on";;
        --group) next_arg="group"; DO_GROUP="yes"; ON_GROUP="on";;
        --h5part) DO_H5PART="yes"; ON_H5PART="on"
                  DO_HDF5="yes"; ON_HDF5="on"
                  DO_SZIP="yes"; ON_SZIP="on";;
        --hdf4) DO_HDF4="yes"; ON_HDF4="on"
                DO_SZIP="yes"; ON_SZIP="on";;
        --hdf5) DO_HDF5="yes"; ON_HDF5="on";;
        -h|--help) next_action="help";;
        --icet) DO_ICET="yes"; ON_ICET="on";;
        --itaps) DO_ITAPS="yes"; ON_ITAPS="on";;
        --java) DO_JAVA="yes"; ON_JAVA="on";;
        --makeflags) next_arg="makeflags";;
        --mesa) DO_MESA="yes"; ON_MESA="on";;
        --mili) DO_MILI="yes"; ON_MILI="on";;
        --netcdf) DO_NETCDF="yes"; ON_NETCDF="on";;
        --no-visit) DO_VISIT="no"; ON_VISIT="off";;
        --no-thirdparty) DO_REQUIRED_THIRD_PARTY="no"; ON_THIRD_PARTY="off";;
        --no-hostconf) DO_HOSTCONF="no"; ON_HOSTCONF="off";;
        --no-icet) PREVENT_ICET="yes";;
        --parallel) parallel="yes"; DO_ICET="yes"; ON_parallel="ON";;
        --print-vars) next_action="print-vars";;
        --python) DO_PYTHON="yes"; ON_PYTHON="on";;
        --python-module) DO_MODULE="yes"; ON_MODULE="on";;
        --qt) DO_QT="yes"; ON_QT="on";;
        --relative) ABS_PATH="no"; ON_ABS_PATH="off";;
        --silo) DO_SILO="yes"; ON_SILO="on";;
        --szip) DO_SZIP="yes"; ON_SZIP="on";;
        --slivr) DO_SLIVR="yes"; ON_SLIVR="on";;
        --static) DO_STATIC_BUILD="yes";;
        --stdout) LOG_FILE="/dev/tty";;
        --svn) DO_SVN="yes"; export SVN_ROOT_PATH=$SVN_REPO_ROOT_PATH;;
        --svn-anon) DO_SVN="yes"; DO_SVN_ANON="yes" ; export SVN_ROOT_PATH=$SVN_ANON_ROOT_PATH ;;
        --svn-anonymous) DO_SVN="yes"; DO_SVN_ANON="yes" ; export SVN_ROOT_PATH=$SVN_ANON_ROOT_PATH ;;
        --svn-revision) next_arg="svn"; DO_SVN="yes"; DO_REVISION="yes"; DO_SVN_ANON="yes" ; export SVN_ROOT_PATH=$SVN_ANON_ROOT_PATH ;;
        --tarball) next_arg="tarball"
                   USE_VISIT_FILE="yes"
                   ON_USE_VISIT_FILE="on";;
        --tcmalloc) DO_TCMALLOC="yes"; ON_TCMALLOC="on";;
        --thirdparty-path) next_arg="thirdparty-path"
                           ON_THIRD_PARTY_PATH="on";;
        --visus) DO_VISUS="yes"; ON_VISUS="on";;
        --version) next_arg="version";;
        --vtk) DO_VTK="yes"; ON_VTK="on";;
        --dbio-only) DO_DBIO_ONLY="yes";;
        -4) deprecated="${deprecated} --hdf4";;
        -5) deprecated="${deprecated} --hdf5";;
        -c) deprecated="${deprecated} --cgns";;
        -C) deprecated="${deprecated} --ccmio";;
        -d) deprecated="${deprecated} --cflags '$C_OPT_FLAGS -g'";;
        -D) deprecated="${deprecated} --cflags '$C_OPT_FLAGS -g#'";;
        -E) deprecated="${deprecated} --print-vars";;
        -e) deprecated="${deprecated} --exodus";;
        -H) deprecated="${deprecated} --help";;
        -i) deprecated="${deprecated} --absolute";;
        -J) deprecated="${deprecated} --makeflags '-j <something>'";;
        -j) deprecated="${deprecated} --no-visit";;
        -m) deprecated="${deprecated} --mili";;
        -M) deprecated="${deprecated} --tcmalloc";;
        -r) deprecated="${deprecated} --h5part";;
        -R) deprecated="${deprecated} --svn <REVISION>";;
        -s) deprecated="${deprecated} --svn HEAD";;
        -S) deprecated="${deprecated} --slivr";;
        -t) deprecated="${deprecated} --tarball '<file>'";;
        -v) deprecated="${deprecated} --tarball 'visit<version>.tar.gz'";;
        -V) deprecated="${deprecated} --visus";;
        -b|-B) deprecated="${deprecated} --boxlib";;
        -f|-F) deprecated="${deprecated} --cfitsio";;
        -g|-G) deprecated="${deprecated} --gdal";;
        -k|-K) deprecated="${deprecated} --no-thirdparty";;
        -l|-L) deprecated="${deprecated} --group '<arg>'";;
        -n|-N) deprecated="${deprecated} --netcdf";;
        -o|-O) deprecated="${deprecated} --stdout";;
        -p|-P) deprecated="${deprecated} --parallel";;
        -u|-U) deprecated="${deprecated} --thirdparty-path <path>";;
        -w|-W) deprecated="${deprecated} --python";;
        -y|-Y) deprecated="${deprecated} --java";;
        -z|-Z) deprecated="${deprecated} --console";;
        *)
            echo "Unrecognized option '${arg}'."
            ANY_ERRORS="yes";;
    esac
done
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}"
    error ""
fi
if test -n "${next_action}" ; then
    case ${next_action} in
        print-vars) printvariables; exit 2;;
        help) usage; exit 2;;
    esac
fi

#
# As a temporary convenience, for a dbio-only build, we turn on almost all
# of the 3rd party I/O libs used by database plugins.
#
if [[ "$DO_DBIO_ONLY" == "yes" ]]; then
    DO_HDF4="yes"
    ON_HDF4="on"
    DO_HDF5="yes"
    ON_HDF5="on"
    DO_BOXLIB="yes"
    ON_BOXLIB="on"
    DO_CGNS="yes"
    ON_CGNS="on"
    DO_EXODUS="yes"
    ON_EXODUS="on"
    DO_CFITSIO="yes"
    ON_CFITSIO="on"
    DO_GDAL="yes"
    ON_GDAL="on"
    DO_NETCDF="yes"
    ON_NETCDF="on"
    DO_H5PART="yes"
    ON_H5PART="on"
    DO_SZIP="yes"
    ON_SZIP="on"
    DO_CCMIO="yes"
    ON_CCMIO="on"
    DO_ITAPS="yes"
    ON_ITAPS="on"
    DO_SILO="yes"
    ON_SILO="on"

    #
    # Any plugin for this yet?
    #
#    DO_FASTBIT="yes"
#    ON_FASTBIT="on"

    #
    # Releasibility of these libs is not yet understood
    #
#    DO_MILI="yes"
#    ON_MILI="on"
#    DO_VISUS="yes"
#    ON_VISUS="on"
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

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

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

    # Remove the extra quoting, new dialog has --single-quoted
    choice="$(cat tmp$$ | sed 's/"//g' )"
    case $retval in
      0)
        DO_OPTIONAL="no"
        DO_SVN="no"
        USE_VISIT_FILE="no"
        parallel="no"
        DO_MODULE="no"
        DO_JAVA="no"
        DO_SLIVR="no"
        verify="no"
        DO_MORE="no"
        for OPTION in $choice
        do
            case $OPTION in
              Optional)
                 DO_OPTIONAL="yes";;
              SVN)
                 DO_SVN="yes";DO_SVN_ANON="yes";export SVN_ROOT_PATH=$SVN_ANON_ROOT_PATH ;;
              Tarball)
                 $DLG --backtitle "$DLG_BACKTITLE" \
                    --no-cancel --inputbox \
"Enter $OPTION value:" 0 $DLG_WIDTH_WIDE "$VISIT_FILE" 2> tmp$$
                 VISIT_FILE="$(cat tmp$$)"
                 USE_VISIT_FILE="yes";;
              Parallel)
                 parallel="yes"; DO_ICET="yes";;
              PythonModule)
                 DO_MODULE="yes";;
              Java)
                 DO_JAVA="yes";;
              SLIVR)
                 DO_SLIVR="yes";;
              Variables)
                 verify="yes";;
              More)
                 DO_MORE="yes";;
            esac
        done
        ;;
      1)
        warn "Cancel pressed."
        exit 1;;
      255)
        warn "ESC pressed.";;
      *)
        warn "Unexpected return code: $retval";;
    esac
fi
if [[ -e "tmp$$" ]] ; then
    rm tmp$$
fi

if [[ "$DO_OPTIONAL" == "yes" && "$GRAPHICAL" == "yes" ]] ; then
    $DLG --backtitle "$DLG_BACKTITLE" \
    --title "Select 3rd party libraries" \
    --checklist \
"Select the optional 3rd party libraries "\
"to be built and installed:" 0 0 0 \
           "AdvIO"    "$ADVIO_VERSION    $ADVIO_FILE (not available from the web)"      $ON_ADVIO \
           "Boxlib"   "$BOXLIB_VERSION    $BOXLIB_FILE"    $ON_BOXLIB \
           "CCMIO"    "$CCMIO_VERSION  $CCMIO_FILE"     $ON_CCMIO \
           "CFITSIO"  "$CFITSIO_VERSION   $CFITSIO_FILE"   $ON_CFITSIO \
           "CGNS"     "$CGNS_VERSION    $CGNS_FILE"      $ON_CGNS \
           "ExodusII" "$EXODUS_VERSION   $EXODUS_FILE"    $ON_EXODUS \
           "FastBit"  "$FASTBIT_VERSION  $FASTBIT_FILE"   $ON_FASTBIT \
           "GDAL"     "$GDAL_VERSION  $GDAL_FILE"      $ON_GDAL \
           "H5Part"   "$H5PART_VERSION  $H5PART_FILE"    $ON_H5PART \
           "HDF4"     "$HDF4_VERSION  $HDF4_FILE"      $ON_HDF4 \
           "HDF5"     "$HDF5_VERSION  $HDF5_FILE"      $ON_HDF5 \
           "IceT"     "$ICET_VERSION  $ICET_FILE"      $ON_ICET \
           "ITAPS"    "15Apr09 Versions of MOAB, FMDB, GRUMMP"    $ON_ITAPS \
           "Mili"     "$MILI_VERSION $MILI_FILE (not available from the web)"      $ON_MILI \
           "TCMALLOC" "$TCMALLOC_VERSION   $TCMALLOC_FILE (not available from the web)"      $ON_TCMALLOC \
           "Silo"     "$SILO_VERSION    $SILO_FILE"      $ON_SILO \
           "SZip"     "$SZIP_VERSION    $SZIP_FILE"      $ON_SZIP \
           "NetCDF"   "$NETCDF_VERSION  $NETCDF_FILE"    $ON_NETCDF 2> tmp$$
    retval=$?

    # Remove the extra quoting, new dialog has --single-quoted
    choice="$(cat tmp$$ | sed 's/"//g' )"
    case $retval in
      0)
        DO_ADVIO="no"
        DO_BOXLIB="no"
        DO_CCMIO="no"
        DO_CFITSIO="no"
        DO_CGNS="no"
        DO_EXODUS="no"
        DO_FASTBIT="no"
        DO_GDAL="no"
        DO_H5PART="no"
        DO_HDF4="no"
        DO_HDF5="no"
        DO_ICET="no"
        DO_MILI="no"
        DO_NETCDF="no"
        DO_SILO="no"
        DO_SZIP="no"
        DO_ITAPS="no"
        for OPTION in $choice
        do
            case $OPTION in
              AdvIO)
                 DO_ADVIO="yes";;
              Boxlib)
                 DO_BOXLIB="yes";;
              CCMIO)
                 DO_CCMIO="yes";;
              CFITSIO)
                 DO_CFITSIO="yes";;
              CGNS)
                 DO_CGNS="yes";;
              ExodusII)
                 DO_EXODUS="yes"
                 DO_NETCDF="yes";;
              FastBit)
                 DO_HDF5="yes"
                 DO_FASTBIT="yes";;
              GDAL)
                 DO_GDAL="yes";;
              H5Part)
                 DO_H5PART="yes"
                 DO_HDF5="yes"
                 DO_SZIP="yes";;
              HDF4)
                 DO_HDF4="yes"
                 DO_SZIP="yes";;
              HDF5)
                 DO_HDF5="yes";;
              IceT)
                 DO_ICET="yes";;
              Mili)
                 DO_MILI="yes";;
              NetCDF)
                 DO_NETCDF="yes";;
              Silo)
                 DO_SILO="yes";;
              SZip)
                 DO_SZIP="yes";;
              ITAPS)
                 DO_ITAPS="yes";;
            esac
        done
        ;;
      1)
        warn "Cancel pressed."
        exit 1;;
      255)
        warn "ESC pressed.";;
      *)
        warn "Unexpected return code: $retval";;
    esac
fi
if [[ -e "tmp$$" ]] ; then
    rm tmp$$
fi

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

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

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


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

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
      error "The location to install the third party libraries does not exit." \
            "Bailing out"
   fi
fi

START_DIR="$PWD"
cd "$THIRD_PARTY_PATH"
if [[ $? != 0 ]] ; then
   error "Unable to access the third party location. Bailing out."
fi
export VISITDIR=${VISITDIR:-$(pwd)}


if [[ "$DO_REQUIRED_THIRD_PARTY" == "yes" ]] ; then
    DO_MESA="yes"
    DO_QT="yes"
    DO_CMAKE="yes"
    DO_VTK="yes"
    DO_PYTHON="yes"
    if [[ "$DO_DBIO_ONLY" == "yes" ]]; then
        DO_MESA="no"
        DO_QT="no"
        DO_PYTHON="no"
    fi
fi
if [[ "$DO_ICET" == "yes" && "$PREVENT_ICET" != "yes" ]] ; then
    DO_CMAKE="yes"
fi


cd "$START_DIR"


#
# Later we will build Qt.  We are going to bypass their licensing agreement,
# so echo it here.
#

check_if_installed "qt" $QT_VERSION
if [[ $? == 0 ]] ; then
   DO_QT="no"
fi

if [[ "$DO_QT" == "yes" ]] ; then
    qt_license_prompt
    if [[ $? != 0 ]] ;then
        error "Qt4 Open Source Edition License Declined. Bailing out."
    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

#
# Log the start time.  Especially helpful if there are multiple starts
# dumped into the same log.
#
LINES="------------------------------------------------------------" 
echo $LINES
echo "Starting $0 at " $(date)
echo $LINES 

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

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


#
# We are now ready to build.
#

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

#
# Build Python
#
cd "$START_DIR"
if [[ "$DO_PYTHON" == "yes" ]] ; then
    check_if_installed "python" $PYTHON_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping Python build.  Python is already installed."
    else
        info "Building Python (~3 minutes)"
        build_python
        if [[ $? != 0 ]] ; then
            error "Unable to build or install Python.  Bailing out."
        fi
        info "Done building Python"

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

#
# Build Mesa
#
cd "$START_DIR"
if [[ "$DO_MESA" == "yes" ]] ; then
    check_if_installed "mesa" $MESA_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping Mesa build.  Mesa is already installed."
    else
        info "Building Mesa (~2 minutes)"
        build_mesa
        if [[ $? != 0 ]] ; then
            error "Unable to build or install Mesa.  Bailing out."
        fi
        info "Done building Mesa"
    fi
fi

#
# Build VTK
#
cd "$START_DIR"
if [[ "$DO_VTK" == "yes" ]] ; then
    check_if_installed "vtk" $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

#
# Build Qt
#
cd "$START_DIR"
if [[ "$DO_QT" == "yes" ]] ; then
        check_if_installed "qt" $QT_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping Qt4 build.  Qt4 is already installed."
   else
      info "Building Qt4 (~60 minutes)"
      build_qt
      if [[ $? != 0 ]] ; then
         error "Unable to build or install Qt4.  Bailing out."
      fi
      info "Done building Qt4"
   fi
fi

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

cd "$START_DIR"

if [[ "$DO_HDF5" == "yes" ]] ; then
    check_if_installed "hdf5" $HDF5_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping HDF5 build.  HDF5 is already installed."
    else
        info "Building HDF5 (~2 minutes)"
        build_hdf5
        if [[ $? != 0 ]] ; then
            error "Unable to build or install HDF5.  Bailing out."
        fi
        info "Done building HDF5"
    fi
fi

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

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

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

cd "$START_DIR"
if [[ "$DO_NETCDF" == "yes" ]] ; then
    check_if_installed "netcdf" $NETCDF_VERSION
   if [[ $? == 0 ]] ; then
        info "Skipping NetCDF build.  NetCDF is already installed."
   else
        info "Building NetCDF (~2 minutes)"
        build_netcdf
        if [[ $? != 0 ]] ; then
            error "Unable to build or install NetCDF.  Bailing out."
        fi
        info "Done building NetCDF"
   fi
fi

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

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

cd "$START_DIR"
if [[ "$DO_EXODUS" == "yes" ]] ; then
    check_if_installed "exodus" $EXODUS_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping EXODUS build.  EXODUS is already installed."
    else
        info "Building EXODUS (~2 minutes)"
        build_exodus
        if [[ $? != 0 ]] ; then
            error "Unable to build or install EXODUS.  Bailing out."
        fi
        info "Done building EXODUS"
    fi
fi

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

cd "$START_DIR"
if [[ "$DO_BOXLIB" == "yes" ]] ; then
    check_if_installed "boxlib"
    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

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

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

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

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

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

cd "$START_DIR"
if [[ "$DO_ITAPS" == "yes" ]] ; then

    # handle MOAB implementation of ITAPS
    check_if_installed "itaps/MOAB" $ITAPS_MOAB_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping ITAPS_MOAB build.  ITAPS_MOAB is already installed."
    else
        info "Building ITAPS_MOAB (~10 minutes)"
        build_itaps_moab
        if [[ $? != 0 ]] ; then
            error "Unable to build or install ITAPS_MOAB.  Bailing out."
        fi
        info "Done building ITAPS_MOAB"
    fi
    # Setup the _IMPL symbol for ITAPS_MOAB
    export ITAPS_MOAB_IMPL="MOAB:cub:-I\$VISITHOME/itaps/MOAB/$ITAPS_MOAB_VERSION/\$VISITARCH/include:-L\$VISITHOME/itaps/MOAB/$ITAPS_MOAB_VERSION/\$VISITARCH/lib,-liMesh,-lMOAB,-lvtkGraphics"
    if [[ "$DO_HDF5" == "yes" ]] ; then
       ITAPS_MOAB_IMPL="$ITAPS_MOAB_IMPL,-L\$VISITHOME/hdf5/$HDF5_VERSION/\$VISITARCH/lib,-lhdf5,-lz"
    fi
    if [[ "$DO_SZIP" == "yes" ]] ; then
       ITAPS_MOAB_IMPL="$ITAPS_MOAB_IMPL,-L\$VISITHOME/szip/$SZIP_VERSION/\$VISITARCH/lib,-lsz"
    fi
    if [[ "$DO_NETCDF" == "yes" ]] ; then
       ITAPS_MOAB_IMPL="$ITAPS_MOAB_IMPL,-L\$VISITHOME/netcdf/$NETCDF_VERSION/\$VISITARCH/lib,-lnetcdf_c++,-lnetcdf"
    fi

    # handle FMDB implementation of ITAPS
    check_if_installed "itaps/FMDB" $ITAPS_FMDB_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping ITAPS_FMDB build.  ITAPS_FMDB is already installed."
    else
        info "Building ITAPS_FMDB (~10 minutes)"
        build_itaps_fmdb
        if [[ $? != 0 ]] ; then
            error "Unable to build or install ITAPS_FMDB.  Bailing out."
        fi
        info "Done building ITAPS_FMDB"
    fi
    # Setup the _IMPL symbol for ITAPS_FMDB
    export ITAPS_FMDB_IMPL="FMDB:sms:-I\$VISITHOME/itaps/FMDB/$ITAPS_FMDB_VERSION/\$VISITARCH/include/FMDB:-L\$VISITHOME/itaps/FMDB/$ITAPS_FMDB_VERSION/\$VISITARCH/lib,-lFMDB,-lSCORECModel,-lSCORECUtil,-lvtkGraphics"

    # handle GRUMMP implementation ot ITAPS
    check_if_installed "itaps/GRUMMP" $ITAPS_GRUMMP_VERSION
    if [[ $? == 0 ]] ; then
        info "Skipping ITAPS_GRUMMP build.  ITAPS_GRUMMP is already installed."
    else
        info "Building ITAPS_GRUMMP (~10 minutes)"
        build_itaps_grummp
        if [[ $? != 0 ]] ; then
            error "Unable to build or install ITAPS_GRUMMP.  Bailing out."
        fi
        info "Done building ITAPS_GRUMMP"
    fi
    # Setup the _IMPL symbol for ITAPS_GRUMMP
    export ITAPS_GRUMMP_IMPL="GRUMMP:bdry,smesh,vmesh:-I\$VISITHOME/itaps/GRUMMP/$ITAPS_GRUMMP_VERSION/\$VISITARCH/include:-L\$VISITHOME/itaps/GRUMMP/$ITAPS_GRUMMP_VERSION/\$VISITARCH/lib,-L\$VISITHOME/itaps/GRUMMP/$ITAPS_GRUMMP_VERSION/\$VISITARCH/lib,-liMesh_GRUMMP,-lGR_3D,-lGR_surf,-lGR_2D,-lGR_base,-lSUMAAlog_lite,-lOptMS,-lvtkGraphics"
fi

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

#
# Create the host.conf file
#

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

#
# 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
    info "Done building VisIt"
    if [[ "$DO_SVN" == "yes" && "$USE_VISIT_FILE" == "no" ]] ; then
        echo \
        "You may now try to run VisIt by cd'ing into the src/bin"
    else
        echo \
        "You may now try to run VisIt by cd'ing into the ${VISIT_FILE%.tar*}/src/bin"
    fi
    echo "directory and invoking \"visit\"."
    echo 
    echo "To create a binary distribution tarball from this build, cd to"
    if [[ "$DO_SVN" == "yes" && "$USE_VISIT_FILE" == "no" ]] ; then
        echo "${START_DIR}/src"
    else
        echo "${START_DIR}/${VISIT_FILE%.tar*}/src"
    fi
    echo "then enter: \"svn_bin/visit-bin-dist\""
    echo "Will produce a tarball called visitVERSION.ARCH.tar.gz, where"
    echo "VERSION is the version number, and ARCH is the OS architecure."
    echo 
    echo "To install the above tarball in a directory called "INSTALL_DIR_PATH","
    echo "enter: svn_bin/visit-install VERSION ARCH INSTALL_DIR_PATH"
    echo 
    echo "If you run into problems, contact visit-users@ornl.gov"
else
    if [[ $ANY_ERRORS == "no" ]] ; then
        echo "Finished!"
    else
        echo "Finished with Errors"
    fi
fi

exit 0
