#!/bin/csh -f
#-----------------------------------------------------------------------
#
# VISIT-BIN-DIST - Build a compressed tar file from the visit executable
#                  built in the dev directory.
#
# Author: Eric Brugger
# Date:   October 26, 2000
#
# Usage:
#    visit-bin-dist [-c] [-g] [-h] [-make <make_command>] [-md <visit_dir>]
#                   [-nd] [-nmesa] [-npython] [-nqt] [-nstrip] [-nvtk]
#                   [-os <operating_system>] [-compiler <compiler>]
#                   [-arch <architecture>] [-max_silo_bytes <one> <tot>]
#                   [-norel]
#
# Modifications:
#    Jeremy Meredith, Fri May 11 14:15:01 PDT 2001
#    Added distribution of VTK, shared libraries, and plot plugins.
#
#    Jeremy Meredith, Mon Jun 25 21:39:53 PDT 2001
#    Changed the finding of Qt to be independent of its version.
#    Made it look for engine_par and engine_ser.
#    Fixed a couple bugs for solaris.
#
#    Jeremy Meredith, Thu Jul 26 09:20:24 PDT 2001
#    Added distribution of operator plugins.
#
#    Eric Brugger, Wed Sep  5 07:49:38 PDT 2001
#    Added distribution of the splash screen.
#
#    Brad Whitlock, Tue Nov 13 10:07:47 PDT 2001
#    Added python to the package.
#
#    Hank Chlids, Fri Dec 21 09:32:45 PST 2001
#    Add support for the new VTK.
#
#    Jeremy Meredith, Wed Jan  9 14:16:26 PST 2002
#    Removed AIX strangeness.
#
#    Eric Brugger, Wed Feb 20 10:39:56 PST 2002
#    Add support for distributing sample data files.
#
#    Eric Brugger, Wed Apr 10 10:01:25 PDT 2002
#    Add the cli to the list of executables to distribute.  Correct
#    the distribution of the vtk libraries.
#
#    Eric Brugger, Tue Apr 16 10:54:25 PDT 2002
#    Add support for distributing the mesa libraries.
#
#    Jeremy Meredith, Wed Apr 17 12:44:19 PDT 2002
#    Made it assume the test binaries get put into VisItDir/data
#    instead of VisItDir/bin.
#
#    Eric Brugger, Fri May 10 10:37:52 PDT 2002
#    Add support for stripping the executables and shared libraries.
#
#    Brad Whitlock, Tue Jun 4 11:34:16 PDT 2002
#    Checked the Qt version when creating the Qt links.
#
#    Jeremy Meredith, Mon Jun 17 15:42:28 PDT 2002
#    Split linux into intel and alpha versions.  Made some repetitive
#    code use loops.  Accomplished all chmods by a single call to
#    chmod -R.   Added the python tree to the distribution.
#
#    Brad Whitlock, Fri Jun 21 15:42:28 PDT 2002
#    Added tire and noise databases.
#
#    Jeremy Meredith, Fri Jul 12 14:39:37 PDT 2002
#    Added distribution of our include files, as well as qt's moc.
#    Added distribution of the plugin creation tools.
#
#    Brad Whitlock, Fri Jul 12 18:17:29 PST 2002
#    Added help files to the distribution.
#
#    Jeremy Meredith, Thu Jul 18 16:30:47 PDT 2002
#    Made the python library in the lib directory be a symlink.
#    Prevented one error message from the Qt library.
#
#    Jeremy Meredith, Mon Jul 22 12:44:16 PDT 2002
#    Added silex and curv3dprep.
#
#    Brad Whitlock, Fri Aug 16 10:09:07 PDT 2002
#    I added a directory for the Java/VisIt class files.
#
#    Jeremy Meredith, Tue Aug 27 21:27:03 PDT 2002
#    I added datbase plugins.
#
#    Jeremy Meredith, Sat Sep 21 08:57:35 PDT 2002
#    I made the search for Qt library a little more restrictive.
#    
#    Jeremy Meredith, Thu Oct 17 16:40:31 PDT 2002
#    Added xmltest and the xml editor to the distribution.
#
#    Eric Brugger, Fri Jan 10 09:02:16 PST 2003
#    Added libvtkfreetype.so and libvtkftgl.so to the distribution.
#
#    Eric Brugger, Mon Mar 10 08:13:17 PST 2003
#    Added text2polys and time_annotation to the distribution.
#
#    Eric Brugger, Thu Mar 13 08:13:29 PST 2003
#    Added a "current" link to distribution.
#
#    Eric Brugger, Wed Apr 16 11:03:53 PDT 2003
#    Change MangledMesaInclude to MangleMesaInclude.
#
#    Jeremy Meredith, Wed May  7 14:36:35 PDT 2003
#    Split include/visit/*.h into two parts to it doesn't overflow
#    argument lists.
#
#    Eric Brugger, Wed May 14 08:59:59 PDT 2003
#    Added vcl to the distribution.
#
#    Eric Brugger, Thu Jul  3 08:15:29 PDT 2003
#    Remove the version number option and make it determine the version
#    number from the version file. Add a help option.
#
#    Eric Brugger, Tue Jul 22 08:31:45 PDT 2003
#    Add visit-config-open and visit-config-closed to the distribution.
#
#    Brad Whitlock, Thu Jun 19 13:16:57 PST 2003
#    Removed splashscreen from the distribution.
#
#    Eric Brugger, Tue Jul 29 08:23:32 PDT 2003
#    Added makemili to the distribution.
#
#    Brad Whitlock, Wed Jul 30 13:12:14 PST 2003
#    Added mpeg_encode and makemovie.py to the distribution.
#
#    Eric Brugger, Tue Aug 26 09:04:30 PDT 2003
#    Added surfcomp to the distribution.
#
#    Hank Childs, Fri Sep 12 16:35:02 PDT 2003
#    Added convert to the distribution.
#
#    Eric Brugger, Tue Sep 23 15:36:07 PDT 2003
#    Added a missing endif.
#
#    Jeremy Meredith, Thu Oct  9 15:44:43 PDT 2003
#    Added ia64 linux machine name.
#
#    Brad Whitlock, Wed Oct 8 09:33:44 PDT 2003
#    Added support for MacOS X. Added darwin-ppc and removed
#    tflops-intel-ppro since we probably won't ever run there.
#
#    Eric Brugger, Fri Oct 17 16:51:29 PDT 2003
#    I split some copy commands into multiple commands to avoid
#    argument length problems with some implementations of csh.
#
#    Eric Brugger, Thu Nov 13 07:53:25 PST 2003
#    When I split some copy commands, I introduced a bug where not all
#    the help files were copied to the distribution.  I corrected this.
#
#    Eric Brugger, Thu Nov 20 09:05:18 PST 2003
#    Modified the script to handle the absence of the help directory.
#    Added libvtkDICOMParser to the distribution.
#
#    Jeremy Meredith, Mon Dec  1 12:40:51 PST 2003
#    We aren't using the Qt Free version on Mac, so I prevented it from
#    copying the Qt include files when os==darwin.  I also put the 
#    Qt license in an obvious spot, and fixed a typo with copying
#    duplicates.
#
#    Brad Whitlock, Thu Jan 29 10:50:56 PDT 2004
#    I added support for Linux running AMD Opteron 64 (x86_64). I also
#    changed the name of the distribution file on Linux if the processor
#    is IA64, Alpha, or x86_64.
#
#    Eric Brugger, Fri Jan 30 09:23:45 PST 2004
#    Modified the script to also distribute libvtk_sl_io.
#
#    Eric Brugger, Tue Mar 16 13:30:42 PST 2004
#    Modified the script to also distribute libqtviswindow.so.
#
#    Brad Whitlock, Wed Apr 28 19:55:27 PST 2004
#    I changed it so we copy the Qt/Mac header files since we're now using
#    Qt/Mac free edition.
#
#    Brad Whitlock, Thu May 27 11:58:01 PDT 2004
#    I added support for using different Info.plist files so the viewer gets
#    its own plist file that prevents it from getting its own menu.
#
#    Brad Whitlock, Tue Jun 29 12:05:42 PDT 2004
#    Some help files were not being copied so I added commands to make sure
#    they get copied.
#
#    Jeremy Meredith, Tue Nov  2 09:51:52 PST 2004
#    Added command to copy private Qt headers.
#
#    Jeremy Meredith, Tue Nov  9 14:31:08 PST 2004
#    Allowed distinction of 64-bit objects on IBM AIX systems.
#
#    Jeremy Meredith, Fri Dec 10 13:34:55 PST 2004
#    Added support for version-specific visit scripts and the ability to
#    launch tools without passing them as an argument to the visit script.
#
#    Jeremy Meredith, Tue Feb 22 18:55:53 PST 2005
#    Renamed convert to the more unique visitconvert.
#
#    Jeremy Meredith, Thu Mar 17 11:31:49 PST 2005
#    Added xml2plugin back into the distribution.
#
#    Jeremy Meredith, Mon Apr 25 10:48:08 PDT 2005
#    Added some basic multi-compiler support.
#
#    Brad Whitlock, Thu May 12 11:30:24 PDT 2005
#    Added code to copy MacOS X address computation script and address file.
#
#    Brad Whitlock, Thu Jun 23 17:11:21 PST 2005
#    Made it copy makemoviemain.py
#
#    Jeremy Meredith, Wed Jul  6 14:46:56 PDT 2005
#    Added xlc compiler-specific support.
#
#    Brad Whitlock, Fri Oct 7 13:16:49 PST 2005
#    Copy dbA00.pdb and dbB00.pdb to the distribution.
#
#    Mark C. Miller, Tue Nov 22 09:42:57 PST 2005
#    Removed refs to sl_io library
#
#    Eric Brugger, Mon Jan 30 14:52:21 PST 2006
#    I added the -make argument, which allows the user to specify the make
#    command.
#
#    Brad Whitlock, Fri Feb 3 08:30:30 PDT 2006
#    I added Qt's qui library to the distribution.
#
#    Eric Brugger, Mon Feb  6 10:52:03 PST 2006
#    Make some corrections for libqui.  Split some commands to overcome line
#    length restrictions on old Irix systems.  Add links for libqt.a and
#    libqui.a.
#
#    Eric Brugger, Fri Mar 10 09:40:34 PST 2006
#    I added visit-config-nersc and visit-config-ornl to the distrtibution.
#
#    Eric Brugger, Fri Mar 17 09:42:22 PST 2006
#    I corrected an error setting the symbolic link libqui.a.
#
#    Eric Brugger, Wed Jun  7 16:26:14 PDT 2006
#    I modified the script to handle the new vtk library naming conventions.
#
#    Hank Childs, Tue Jun 13 14:43:52 PDT 2006
#    Copy over .txx files from VTK headers.
#
#    Eric Brugger, Mon Jul 17 13:01:02 PDT 2006
#    Copy the include/vtk/{GenericFiltering,Utilities} headers and txx files.
#
#    Brad Whitlock, Fri Sep 15 10:28:51 PDT 2006
#    I added support for the GLEW library.
#
#    Brad Whitlock, Wed Sep 20 11:45:24 PDT 2006
#    I made it use mpeg2encode and I added code to copy the movietemplates
#    directory. I also added code to copy missing Python XML modules.
#
#    Eric Brugger, Fri Sep 22 12:01:25 PDT 2006
#    Copy the gcc libraries if they are present.
#
#    Eric Brugger, Fri Nov 17 12:42:20 PST 2006
#    I added the -switch option.  I removed support for linux-alpha.  I
#    modified the script to only create the platform directory for the
#    platform that the distribution includes instead of all the platforms.
#
#    Mark C. Miller, Thu Jan 25 20:15:18 PST 2007
#    Added mkgrdbl to the distribution.
#
#    Eric Brugger, Wed Feb 21 15:07:24 PST 2007
#    Added the header files in include/vtk/Utilities/{expat,vtktiff,vtkzlib}
#    to the distribution.
#
#    Eric Brugger, Tue Mar 13 08:34:59 PDT 2007
#    Deleted the vtk exodus and netcdf libraries from the list of required
#    vtk libraries.
#
#    Thomas R. Treadway, Wed Apr  4 12:40:20 PDT 2007
#    Modified Mac (Darwin) procession to created darwin, darwin-i386,
#    darwin-x86_64, darwin-ppc, darwin-ppc_64, depending on the machine
#    architecture, or if a universal binary (as determined by qt library).
#    Added argument "arch" for setting "osver" and "visitbindir" to allow 
#    cross compiles and builds.
#    Added more checks to removed the "cp: No match." conditions.
#
#    Thomas R. Treadway, Tue Apr 10 11:30:28 PDT 2007
#    Replaced "uname -m" with "uname -p" for darwin.
#
#    Thomas R. Treadway, Wed May 23 17:04:07 PDT 2007
#    FreeBSD patches from Nathan Lay <nlay@scs.fsu.edu>
#
#    Mark C. Miller, Tue Jun 19 17:26:56 PDT 2007
#    Added visit_plugin
#
#    Eric Brugger, Thu Jul  5 13:07:18 PDT 2007
#    Modified to copy the multi-threaded qt library (libqt-mt) if the
#    regular one (libqt) is missing.  Modified so that it would work
#    correctly with the source tree organization of the subversion repository.
#
#    Thomas R. Treadway, Mon Jul 16 14:44:47 PDT 2007
#    Added DYLD_LIBRARY_PATH so Mac can find libraries when generating
#    data files, now that the execuate path has changed.
#
#    Eric Brugger, Tue Jul 24 16:12:06 PDT 2007
#    Corrected the setting of the links for the multi-threaded qt library.
#
#    Kathleen Bonnell, Thu Aug 16 14:49:43 PDT 2007 
#    Modified MesaOSMesaLibName and MesaMesaGLLibName to handle possible 
#    version numbers on non-darwin platforms.
#
#    Mark C. Miller, Mon Aug 20 14:42:56 PDT 2007
#    Added visitdiff.py script.
#
#    Thomas R. Treadway, Tue Sep 11 10:33:03 PDT 2007
#    Modified the visitmodule naming for the Mac
#
#    Hank Childs, Thu Sep 20 22:09:43 PDT 2007
#    Distribute visit_writer.so if it exists.
#
#    Hank Childs, Wed Oct 17 08:39:39 PDT 2007
#    Improve existence test.  Also cut down on error messages from strip.
#
#    Brad Whitlock, Mon Dec 10 14:19:45 PST 2007
#    Added visitprotocol.
#
#    Gunther H. Weber, Thu Feb  7 14:45:22 PST 2008
#    Added a "-configuration" option that specifies which configuration
#    referenced by the default configuration symbolic link. Check for a
#    default guiconfig and visitrc as well and add symbolic links as
#    necessary. If no "-configuration" option is specified then default to
#    the "open" configuration as before.
#
#    Hank Childs, Sat Feb  9 14:18:54 PST 2008
#    Change clearcase_bin to svn_bin.
#
#    Hank Childs, Mon Aug 11 14:48:51 PDT 2008
#    Add support for libtcmalloc.
#
#    Brad Whitlock, Thu Aug 21 10:21:12 PDT 2008
#    Added code to copy translation files.
#
#    Brad Whitlock, Thu Sep 11 09:58:11 PDT 2008
#    Added code to copy the Python lib-tk modules.
#
#    Brad Whitlock, Thu Oct  2 14:52:53 PDT 2008
#    Qt 4. Added -norel
#
#    Eric Brugger, Fri Oct 10 16:27:33 PDT 2008
#    I removed the -switch option.
#
#    Mark C. Miller, Tue Oct 21 09:14:47 PDT 2008
#    Modified to support shared HDF5 library (and possible szip).
#    Elminated data bloat when creating a distribution from an
#    instance in which 'make test' has been performed in data dir.
#    Simplifed some regular expression logic for filtering lib names
#    to copy to distro.
#
#    Mark C. Miller, Tue Oct 21 18:47:08 PDT 2008
#    Fixed code to copy files to keep it from copying links and big files.
#
#    Eric Brugger, Wed Oct 22 16:21:42 PDT 2008
#    I changed the script so that it would no longer abort if the shared
#    version of the hdf5 library wasn't present and only try to copy the
#    shared version of the hdf5 and szip libraries if they were present.
#    I also removed a message that normally printed out that gave the
#    impression that something had failed.
#
#    Mark C. Miller, Thu Nov 13 21:06:30 PST 2008
#    Added -max_silo_bytes command-line argument. Improved logic to copy
#    Silo files to distro to copy all files up to some maximum number of
#    total bytes and to skip single files larger than some other maximum
#    setting.
#
#    Hank Childs, Tue Jan 20 15:18:10 PST 2009
#    Copy over the Princeton config files.
#
#    Brad Whitlock, Fri Feb  6 14:50:41 PST 2009
#    Added installation of libsimV2.
#
#    Patrick Shinpaugh, Wed Mar 11 11:34:16 MST 2009
#    Fix directories to account for linux-ppc64.
#
#    Mark C. Miller, Wed Apr  8 11:06:38 PDT 2009
#    Added minimum possible logic for dbio-only distros. Many commands fail
#    in this mode. But, those failures are harmless and the script should
#    continue on to complete the creation of a binary distro.
#
#    Kathleen Bonnell, Wed Apr 22 16:46:53 PDT 2009
#    Add ultrawapper files, pyparsing files.
#
#    Hank Childs, Sat May  2 10:59:41 CDT 2009
#    Added configs for TACC.  Also change incorrect "fi" to be an "endif".
#
#    Brad Whitlock, Wed Jun 3 16:53:34 PST 2009
#    I added conditional tests to prevent unwanted pieces from being copied
#    into the distribution in the event that there are missing pieces. For
#    example, don't copy help files if there's no GUI. Don't make symlinks
#    to an app if it does not exist.
#
#    Gunther H. Weber, Fri Jul 17 15:19:41 PDT 2009
#    Determine HDF5 and Szip major relase version via readlink and cut instead
#    of using hardcoded values of 5 and 2 respectively. Replaced invokation of
#    grep with egrep to prevent copying of shared libraries for which we want
#    to create symbolic links at a later time.
#    MERGE CHANGE: Reverted to grep in merge.
#   
#    Gunther H. Weber, Wed Jul 22 15:56:01 PDT 2009
#    Use/copy libtcmalloc_minimal instead of libtcmalloc to avoid dependency
#    on libunwind on 64-bit machines.
#
#    Eric Brugger, Tue Aug  4 16:13:48 PDT 2009
#    I modified the logic that packages up the help files to avoid using
#    the "-maxdepth" option to find, since it is not supported on AIX.
#
#    Gunther H. Weber, Thu Sep  3 10:16:24 PDT 2009
#    Do not copy QtHelp and QtXmlPatterns, since we do not set appropriate
#    install names in build_visit. Furthermore, QtHelp depends on libQtCLucene
#    (at least on Macs), which we do not copy. Since we do not link to QtHelp
#    or QtXmlPatterns, I commented out the iines copying them.
#    Gunther H. Weber, Tue Sep 22 14:42:47 PDT 2009
#    Determine Mesa and OSMesa major release version via readlink and cut
#    since old method did not work for Mesa 7.5. Do not copy python or qt
#    when npython or nqt options are used.
#
#------------------------------------------------------------------------------


#------------------------------------------------------------------------------
#                        THIS SCRIPT IS OBSOLETE
#------------------------------------------------------------------------------
echo "***"
echo "*** The visit-bin-dist script is obsolete. Run 'make package' from the src directory instead."
echo "***"
exit 0

set DataFiles = "TRUE"
set QtLibs = "TRUE"
set MesaLibs = "TRUE"
set VTKLibs = "TRUE"
set PythonExe = "TRUE"
set Compress = GZIP
set VisItDir = `pwd`
set OSGiven = "FALSE"
set CompilerGiven = "FALSE"
set compiler = ""
set SwitchGiven = "FALSE"
set ArchGiven = "FALSE"
set Strip = "TRUE"
set Make = "make"
set Help = "FALSE"
set Configuration = "open"
set makerelative = "TRUE"
set max_one_silo_bytes = 2000000  #  2e6 bytes (about 2 megabytes)
set max_tot_silo_bytes = 20000000 # 20e6 bytes (about 20 megabytes)
set dbioOnly = "FALSE"

#
# Parse the argument list.
#
while ($#argv >= 1)
   switch ($1)
      case -c:
               set Compress = COMPRESS
               breaksw

      case -g:
               set Compress = GZIP
               breaksw

      case -h:
      case -help:
               set Help = TRUE
               breaksw

      case -make:
               shift
               set Make = $1
               breaksw

      case -md:
               shift
               set VisItDir = $1
               breaksw

      case -nd:
               set DataFiles = FALSE
               breaksw

      case -nmesa:
      case -nomesa:
               set MesaLibs = FALSE
               breaksw

      case -npython:
      case -nopython:
               set PythonExe = FALSE
               breaksw

      case -nqt:
      case -noqt:
               set QtLibs = FALSE
               breaksw

      case -nstrip:
      case -nostrip:
               set Strip = FALSE
               breaksw

      case -nvtk:
      case -novtk:
               set VTKLibs = FALSE
               breaksw

      case -os:
               shift
               set os = $1
               set OSGiven = TRUE
               breaksw

      case -compiler:
               shift
               set compiler = $1
               set CompilerGiven = TRUE
               breaksw

      case -arch:
               shift
               set osver = $1
               set visitbindir = $1
               set ArchGiven = TRUE
               breaksw

      case -configuration:
               shift
               set Configuration = $1
               breaksw

      case -norel:
               set makerelative = FALSE
               breaksw

      case -max_silo_bytes:
               shift
               set max_one_silo_bytes = $1
               shift
               set max_tot_silo_bytes = $1
               breaksw
 
      case -dbio-only:
               set dbioOnly = TRUE
               set DataFiles = FALSE 
               set QtLibs = FALSE
               set MesaLibs = FALSE 
               set VTKLibs = TRUE
               set PythonExe = FALSE 
               set max_one_silo_bytes = 0 
               set max_tot_silo_bytes = 0 
               breaksw

      default:
               echo " "
               echo ">>>>>>>>>>  Illegal option $1  <<<<<<<<<<"
               echo " "
               breaksw
   endsw
   shift
end

if ($Help == TRUE) then
   echo "Usage: visit-bin-dist [-c] [-g] [-h] [-make <make_command>]"
   echo "                      [-md <visit_dir>] [-nd] [-nmesa]"
   echo "                      [-npython] [-nqt] [-nstrip] [-nvtk]"
   echo "                      [-os <operating_system>] [-compiler <compiler>]"
   echo "                      [-arch <architecture>]"
   echo ""
   echo "       -c             Compress the resultant package."
   echo "       -g             Gzip the resultant package.  (default)"
   echo "       -h             Print this message."
   echo "       -make make     Make command."
   echo "       -md dir        Set where to find the distribution."
   echo "       -nd            No data files."
   echo "       -nmesa         No Mesa libraries."
   echo "       -npython       No Python executable."
   echo "       -nqt           No Qt libraries."
   echo "       -nstrip        Do not strip the execubles and libraries."
   echo "       -nvtk          No VTK libraries."
   echo "       -os os         Operating system."
   echo "       -compiler cc   Compiler."
   echo "       -arch architecture Force architecture package."
   echo "       -norel         Skip the pass on the Mac that makes sure "
   echo "                      libraries are relative to @executable_path."
   echo "       -max_silo_bytes  <one-file> <total>"
   echo "       -dbio-only     Prepare a dbio-only distribution." 
   exit (1)
endif

#
# Determine the operating system.
#
if("$OSGiven" == "FALSE") then
    if(-e /bin/uname) then 
        set os = `/bin/uname -s | tr "[A-Z]" "[a-z]" | tr -d "[0-9]"`
    else if(-e /usr/bin/uname) then
        set os = `/usr/bin/uname -s | tr "[A-Z]" "[a-z]" | tr -d "[0-9]"`
    else
        echo "Can't find uname program!"
        exit
    endif
endif

#
# Set up the distribution directory and get rid of any old versions
#
rm -rf distribution
mkdir distribution

#
# Check that the version exists.
#
if (! -e $VisItDir/VERSION) then
   echo " "
   echo "Error: The file $VisItDir/VERSION does not exist. aborting ..."
   echo " "
   exit (1)
endif

#
# Check that the launch script exists.
#
if (! -e $VisItDir/bin/visit) then
   echo " "
   echo "Error: The file $VisItDir/bin/visit does not exist. aborting ..."
   echo " "
   exit (1)
endif

#
# Check that the data directory exists so that the data files can be created.
#
if (("$DataFiles" == "TRUE") && (! -e $VisItDir/../data)) then
   echo "The directory $VisItDir/../data does not exist."
   echo "Distribution will not contain sample data files."
   set DataFiles = "FALSE"
endif

#
# Deterime the version number.
#
set Version = `cat $VisItDir/VERSION`

#
# Determine the shared library extension
#
if("$os" == "darwin") then
    set SHLIB_SOEXT = "dylib"
else
    set SHLIB_SOEXT = "so"
endif

#
# Determine the name of the Qt shared libraries
#
if ("$os" == "darwin") then
    set QtCore        = "QtCore.framework"
    set QtGui         = "QtGui.framework"
    #set QtHelp        = "QtHelp.framework"
    set QtNetwork     = "QtNetwork.framework"
    set QtOpenGL      = "QtOpenGL.framework"
    set QtScript      = "QtScript.framework"
    set QtSvg         = "QtSvg.framework"
    set QtXml         = "QtXml.framework"
    #set QtXmlPatterns = "QtXmlPatterns.framework"
    set QtUiTools     = "libQtUiTools.a"
else
    set QtCore        = `cd $VisItDir/lib && ls libQtCore.$SHLIB_SOEXT.?.?.?`
    set QtGui         = `cd $VisItDir/lib && ls libQtGui.$SHLIB_SOEXT.?.?.?`
    #set QtHelp        = `cd $VisItDir/lib && ls libQtHelp.$SHLIB_SOEXT.?.?.?`
    set QtNetwork     = `cd $VisItDir/lib && ls libQtNetwork.$SHLIB_SOEXT.?.?.?`
    set QtOpenGL      = `cd $VisItDir/lib && ls libQtOpenGL.$SHLIB_SOEXT.?.?.?`
    set QtScript      = `cd $VisItDir/lib && ls libQtScript.$SHLIB_SOEXT.?.?.?`
    set QtSvg         = `cd $VisItDir/lib && ls libQtSvg.$SHLIB_SOEXT.?.?.?`
    set QtXml         = `cd $VisItDir/lib && ls libQtXml.$SHLIB_SOEXT.?.?.?`
    #set QtXmlPatterns = `cd $VisItDir/lib && ls libQtXmlPatterns.$SHLIB_SOEXT.?.?.?`
    set QtUiTools     = "libQtUiTools.a"
endif

#
# Check that the Qt libraries exist.
#
if ("$QtLibs" == "TRUE") then
    foreach qlib ($QtCore $QtGui $QtNetwork $QtOpenGL $QtScript $QtSvg $QtXml $QtUiTools)
        if (! -e $VisItDir/lib/$qlib) then
            echo " "
            echo "Error: The file $VisItDir/lib/$qlib does not exist. aborting ..."
            echo " "
            exit (1)
        endif
    end
endif

#
# Determine the names of the Mesa shared libraries.
#
if ("$os" == "darwin") then
    set MesaOSMesaLibName = "libOSMesa.$SHLIB_SOEXT"
    set MesaMesaGLLibName = "libMesaGL.$SHLIB_SOEXT"
else 
    set MesaOSMesaLibFile = `readlink -f $VisItDir/lib/libOSMesa.$SHLIB_SOEXT`
    set MesaMesaGLLibFile = `readlink -f $VisItDir/lib/libMesaGL.$SHLIB_SOEXT`
    set MesaOSMesaLibName = `basename $MesaOSMesaLibFile`
    set MesaMesaGLLibName = `basename $MesaMesaGLLibFile`
    if ("$MesaOSMesaLibName" == "") then
        set MesaOSMesaLibName = "libOSMesa.$SHLIB_SOEXT"
        set MesaMesaGLLibName = "libMesaGL.$SHLIB_SOEXT"
    endif
endif

#
# Check that the Mesa libraries exist.
#
if (("$MesaLibs" == "TRUE") && \
    ((! -e $VisItDir/lib/$MesaOSMesaLibName) || \
     (! -e $VisItDir/lib/$MesaMesaGLLibName))) then
   echo " "
   echo "Error: Missing Mesa libraries in $VisItDir/lib. aborting ..."
   echo " "
   exit (1)
endif

#
# Determine the name of the GLEW library.
#
set GLEWLibName = "libGLEW.$SHLIB_SOEXT"

#
# Set the names of the VTK shared libraries.
#
set vtklibs="libvtkCommon libvtkDICOMParser libvtkFiltering libvtkGraphics libvtkHybrid libvtkIO libvtkImaging libvtkMPEG2Encode libvtkRendering libvtkexpat libvtkfreetype libvtkftgl libvtkjpeg libvtkpng libvtksys libvtktiff libvtkzlib"

#
# Check that the VTK libraries exist.
#
if ("$VTKLibs" == "TRUE") then
    foreach vtklib ($vtklibs)
       if (! -e $VisItDir/lib/$vtklib.$SHLIB_SOEXT) then
           echo " "
           echo "Error: Missing VTK libraries in $VisItDir/lib. aborting ..."
           echo " "
           exit (1)
       endif
    end
endif

#
# Determine the names of the hdf5 shared libraries.
#
set HdfHDF5LibName = "libhdf5.$SHLIB_SOEXT"
set HdfSzipLibName = "libsz.$SHLIB_SOEXT"

#
# Determine the os version string and hardware os string.
#
if ("$ArchGiven" == "FALSE") then
  switch ($os)
   case freebsd:
      echo "Found a FreeBSD version of visit"
      set version = `uname -r`
      set mach = `uname -m`
      set osver = FreeBSD
      set visitbindir = FreeBSD-$version-$mach
      breaksw

   case hp-ux:
      echo "Found an HP-UX version of visit"
      set osver = hp
      set visitbindir = hp-hpux-pa
      breaksw

   case irix:
      set version = `/bin/uname -r`
      set osver = irix`expr $version : '\([456]\).*'`
      if ($osver == irix6) then
         echo "Found an IRIX 6 version of visit"
         set osver = irix6
         set visitbindir = sgi-irix6-mips2
      endif
      breaksw

   case sunos:
      echo "Found a Solaris version of visit"
      set version = '/bin/uname -r'
      set osver = sunos5
      set visitbindir = sun4-sunos5-sparc
      breaksw

   case aix:
      echo "Found an AIX version of visit"
      if ("${?OBJECT_MODE}") then
          if ("${OBJECT_MODE}" == "64") then
              if (("$CompilerGiven" == "TRUE") && ("$compiler" == "xlc")) then
                  set osver = aix64-xlc
                  set visitbindir = ibm-aix-pwr64-xlc
              else
                  set osver = aix64
                  set visitbindir = ibm-aix-pwr64
              endif
          else
              if (("$CompilerGiven" == "TRUE") && ("$compiler" == "xlc")) then
                  set osver = aix-xlc
                  set visitbindir = ibm-aix-pwr-xlc
              else
                  set osver = aix
                  set visitbindir = ibm-aix-pwr
              endif
          endif
      else
          set osver = aix
          set visitbindir = ibm-aix-pwr
      endif
      breaksw

   case osf:
      echo "Found an OSF1 version of visit"
      set osver = osf1
      set visitbindir = dec-osf1-alpha
      breaksw

   case linux:
      echo "Found a Linux version of visit"
      set arch = `/bin/uname -m`
      switch ($arch)
         case i486:
         case i586:
         case i686:
            if (("$CompilerGiven" == "TRUE") && ("$compiler" == "icc")) then
                set osver = linux-icc
                set visitbindir = linux-intel-icc
            else
                set osver = linux
                set visitbindir = linux-intel
            endif
            breaksw
         case ia64:
            set osver = linux-ia64
            set visitbindir = linux-ia64
            breaksw
         case x86_64:
            set osver = linux-x86_64
            set visitbindir = linux-x86_64
            breaksw
         case ppc64:
            set osver = linux-ppc64
            set visitbindir = linux-ppc64
            breaksw
      endsw
      breaksw

   case darwin:
      echo "Found a MacOS X version of visit"
      set archBins = `file $VisItDir/lib/$MesaMesaGLLibName | head -n 1`
      if (`echo "$archBins" | grep "universal"` == "") then
         set arch = `/usr/bin/uname -p`
         switch ($arch)
            case i386:
            case i486:
            case i586:
            case i686:
               set osver = darwin-i386
               set visitbindir = darwin-i386
               breaksw
            case x86_64:
               set osver = darwin-x86_64
               set visitbindir = darwin-x86_64
               breaksw
            case powerpc:
               set osver = darwin-ppc
               set visitbindir = darwin-ppc
               breaksw
            case ppc_64:
               set osver = darwin-ppc_64
               set visitbindir = darwin-ppc_64
               breaksw

         endsw
      else
         set osver = darwin
         set visitbindir = darwin
      endif
      breaksw
  endsw
endif
#
# Set a bunch of paths used later in the script.
#
set verdir = distribution/visit/$Version
set bindir = distribution/visit/$Version/$visitbindir/bin
set libdir = distribution/visit/$Version/$visitbindir/lib
set incdir = distribution/visit/$Version/$visitbindir/include
set helpdir = distribution/visit/$Version/$visitbindir/help
set plugindir = distribution/visit/$Version/$visitbindir/plugins
set javadir = distribution/visit/$Version/$visitbindir/java
set simv1dir = distribution/visit/$Version/$visitbindir/libsim/V1
set simv2dir = distribution/visit/$Version/$visitbindir/libsim/V2
set frameworkdir = distribution/visit/$Version/$visitbindir/Frameworks
set ultradir = distribution/visit/$Version/$visitbindir/ultrawrapper

#
# Make the directory structure shell.
#
mkdir distribution/visit
mkdir distribution/visit/bin
if ($DataFiles == "TRUE") then
   mkdir distribution/visit/data
endif

mkdir distribution/visit/$Version
mkdir distribution/visit/$Version/bin
ln -s $Version distribution/visit/current
mkdir distribution/visit/$Version/$visitbindir
mkdir distribution/visit/$Version/$visitbindir/bin
mkdir distribution/visit/$Version/$visitbindir/bin/movietemplates
mkdir distribution/visit/$Version/$visitbindir/bin/translations
mkdir distribution/visit/$Version/$visitbindir/lib
mkdir distribution/visit/$Version/$visitbindir/include
mkdir distribution/visit/$Version/$visitbindir/help
mkdir distribution/visit/$Version/$visitbindir/plugins
mkdir distribution/visit/$Version/$visitbindir/plugins/plots
mkdir distribution/visit/$Version/$visitbindir/plugins/operators
mkdir distribution/visit/$Version/$visitbindir/plugins/databases
mkdir distribution/visit/$Version/$visitbindir/java
mkdir distribution/visit/$Version/$visitbindir/libsim
mkdir distribution/visit/$Version/$visitbindir/libsim/V1
mkdir distribution/visit/$Version/$visitbindir/libsim/V1/include
mkdir distribution/visit/$Version/$visitbindir/libsim/V1/lib
mkdir distribution/visit/$Version/$visitbindir/ultrawrapper

#
# Create and copy in the sample data files.
#
if ($DataFiles == "TRUE") then
   echo "Creating data generation programs..."
   set pwd = `pwd`
   cd $VisItDir/../data
   $Make
   echo "Generating data files..."
   if ("$os" == "darwin") then
      setenv DYLD_LIBRARY_PATH $VisItDir/lib
   endif
   # try to do globe on HDF5 driver, fall back to PDB
   ./globe -driver DB_HDF5 >& /dev/null
   if (! -e globe.silo) then
       ./globe >& /dev/null
   endif
   ./multi_test -noHalfMesh -noTimeInvariantMultimesh -noCycles >& /dev/null
   ./testall >& /dev/null
   # try to do noise on HDF5 driver, fall back to PDB
   ./noise -driver DB_HDF5 >& /dev/null
   if (! -e noise.silo) then
      ./noise >& /dev/null
   endif
   ./tire >& /dev/null

   # Copy all silo files such that no single silo file is larger
   # than max_one_silo_bytes and total size of all silo files
   # is less than max_tot_silo_bytes. However, exclude known
   # series such as wave* and multi*.
   echo "Copying Silo files that fit in size limits..."
   set silo_files = `ls -1rsSk *.silo | grep -v wave\\\|multi | sed -e 's/^ *//' | tr ' ' '@'`
   set silo_bytes = 0
   foreach f ($silo_files)
       set fsize = `echo $f | cut -d'@' -f1`
       set fsize = `expr $fsize \* 1000`
       set fname = `echo $f | cut -d'@' -f2`
       if ($silo_bytes > $max_tot_silo_bytes) then
           echo "Over total silo bytes limit: not copying silo file $fname"
       else
           if ($fsize > $max_one_silo_bytes) then
               echo "Over single silo byte limit: not copying silo file $fname"
               continue
           endif
           cp $fname $pwd/distribution/visit/data
           set silo_bytes = `expr $silo_bytes + $fsize`
       endif
   end

   # Copy anything else important above loop won't catch
   # The set echo = 1 is so that any specific files will
   # will be printed to stdout
   echo "Copying other specific Silo files..."
   set echo = 1
   cp noise.silo $pwd/distribution/visit/data
   cp multi_ucd3d.silo $pwd/distribution/visit/data
   unset echo

   if (-e ./correlationtest) then
      ./correlationtest >& /dev/null
       cp db{A,B}00.pdb $pwd/distribution/visit/data
   endif
   if ("$os" == "darwin") then
      unsetenv DYLD_LIBRARY_PATH
   endif
   cd $pwd/distribution/visit/data
   cd $pwd
endif

#
# Copy the launch scripts
#
cp $VisItDir/bin/legacylauncher    distribution/visit/bin/
cp $VisItDir/bin/frontendlauncher  distribution/visit/bin/

# copy xml2plugin
cp $VisItDir/bin/xml2plugin        distribution/visit/bin/

# copy mkgrdbl
cp $VisItDir/bin/mkgrdbl           distribution/visit/bin/

# copy visit_plugin
cp $VisItDir/bin/visit_plugin      distribution/visit/bin/

# Copy the version-specific visit script
cp $VisItDir/bin/internallauncher $verdir/bin/

#
# Copy the executables to the distribution.
#
echo "Copying executables to the distribution..."
set gui_exists="FALSE"
set cli_exists="FALSE"
if(-e $VisItDir/exe/cli) then
   cp $VisItDir/exe/cli           $bindir/cli
   set cli_exists="TRUE"
endif
cp $VisItDir/exe/engine_ser    $bindir/engine_ser
if(-e $VisItDir/exe/engine_par) then
   cp $VisItDir/exe/engine_par $bindir/engine_par
endif
if(-e $VisItDir/exe/gui) then
   cp $VisItDir/exe/gui           $bindir/gui
   set gui_exists="TRUE"
endif
if(-e $VisItDir/exe/mdserver) then
   cp $VisItDir/exe/mdserver      $bindir/mdserver
endif
if(-e $VisItDir/exe/vcl) then
   cp $VisItDir/exe/vcl           $bindir/vcl
endif
if(-e $VisItDir/exe/viewer) then
   cp $VisItDir/exe/viewer        $bindir/viewer
endif
if(-e $VisItDir/bin/depcomp) then
   cp $VisItDir/bin/depcomp       $bindir/depcomp
endif
# copy qt's moc, too
cp $VisItDir/bin/moc           $bindir/moc
# copy the xml plugin creation tools
cp $VisItDir/exe/xml2*         $bindir
if(-e $bindir/xml2atts) then
   ln -s frontendlauncher distribution/visit/bin/xml2atts
   ln -s frontendlauncher distribution/visit/bin/xml2avt
   ln -s frontendlauncher distribution/visit/bin/xml2info
   ln -s frontendlauncher distribution/visit/bin/xml2java
   ln -s frontendlauncher distribution/visit/bin/xml2projectfile
   ln -s frontendlauncher distribution/visit/bin/xml2python
   ln -s frontendlauncher distribution/visit/bin/xml2window
endif
if(-e $VisItDir/exe/xmltest) then
   cp $VisItDir/exe/xmltest       $bindir
   ln -s frontendlauncher distribution/visit/bin/xmltest
endif
if(-e $VisItDir/exe/xmledit) then
   cp $VisItDir/exe/xmledit       $bindir
   ln -s frontendlauncher distribution/visit/bin/xmledit
endif
# copy silex
if(-e $VisItDir/exe/silex) then
   cp $VisItDir/exe/silex         $bindir
   ln -s frontendlauncher distribution/visit/bin/silex
endif
# copy curv3dprep
if(-e $VisItDir/exe/curv3dprep) then
   cp $VisItDir/exe/curv3dprep    $bindir
   ln -s frontendlauncher distribution/visit/bin/curv3dprep
endif
# copy text2polys and time_annotation
if(-e $VisItDir/exe/text2polys) then
   cp $VisItDir/exe/text2polys    $bindir
   ln -s frontendlauncher distribution/visit/bin/text2polys
endif
if(-e $VisItDir/exe/time_annotation) then
   cp $VisItDir/exe/time_annotation $bindir
   ln -s frontendlauncher distribution/visit/bin/time_annotation
endif
if(-e $VisItDir/exe/visitconvert_ser) then
   cp $VisItDir/exe/visitconvert_ser $bindir
   ln -s frontendlauncher distribution/visit/bin/visitconvert
endif
if(-e $VisItDir/exe/visitconvert_ser_lite) then
   cp $VisItDir/exe/visitconvert_ser_lite $bindir
endif
if(-e $VisItDir/exe/visitconvert_par) then
   cp $VisItDir/exe/visitconvert_par $bindir/visitconvert_par
endif
if(-e $VisItDir/exe/visit_composite) then
   cp $VisItDir/exe/visit_composite  $bindir
   ln -s frontendlauncher distribution/visit/bin/visit_composite
endif
if(-e $VisItDir/exe/visit_transition) then
   cp $VisItDir/exe/visit_transition $bindir
   ln -s frontendlauncher distribution/visit/bin/visit_transition
endif
if(-e $VisItDir/exe/makemili_ser) then
   cp $VisItDir/exe/makemili_ser $bindir/makemili_ser
   ln -s frontendlauncher distribution/visit/bin/makemili
endif
if(-e $VisItDir/exe/visit_writer.so) then
   cp $VisItDir/exe/visit_writer.so $bindir/visit_writer.so
endif
# Copy the MPEG encoder and the makemovie script.
if(-e $VisItDir/exe/mpeg2encode) then
   cp $VisItDir/exe/mpeg2encode   $bindir
endif
cp $VisItDir/bin/makemovie.py  $bindir
cp $VisItDir/bin/makemoviemain.py  $bindir
# copy surfcomp
if(-e $VisItDir/exe/surfcomp) then
   cp $VisItDir/exe/surfcomp      $bindir
   ln -s frontendlauncher distribution/visit/bin/surfcomp
endif
# Copy the movie templates
cp $VisItDir/bin/movietemplates/*.mt  $bindir/movietemplates
cp $VisItDir/bin/movietemplates/*.ui  $bindir/movietemplates
cp $VisItDir/bin/movietemplates/*.py  $bindir/movietemplates
cp $VisItDir/bin/movietemplates/*.{bmp,jpg,gif,tif} $bindir/movietemplates
# Copy the visitdiff script
cp $VisItDir/bin/visitdiff.py  $bindir
# Copy the visitprotocol program.
cp $VisItDir/exe/visitprotocol $bindir
# Copy the language translations
cp $VisItDir/bin/translations/*.qm $bindir/translations
cp $VisItDir/bin/translations/*.ts $bindir/translations

#
# Make symlinks for the programs
#
ln -s frontendlauncher distribution/visit/bin/visit
ln -s frontendlauncher distribution/visit/bin/xml2makefile


# If we're on Darwin, Make some bundles so VisIt can run when it's unpackaged
if("$os" == "darwin") then
    set graphicalApps="gui viewer silex xmledit"
    set menuNames = ("VisIt" "VisIt Viewer" "Silex" "XmlEdit")
    set creatorCodes = ("VISI" "VISV" "SILX" "XEDT")
    set plist = ("Info.plist" "ViewerInfo.plist" "Info.plist" "Info.plist")
    # change these when there are more icons
    set iconFiles = ("VisItIcon" "VisItIcon" "VisItIcon" "VisItIcon")
    @ i = 1
    set pwd = `pwd`
    foreach app ($graphicalApps)
        if(-e $bindir/$app) then
            echo "Making application bundle for $app"
            mkdir $bindir/$app.app
            mkdir $bindir/$app.app/Contents
            mkdir $bindir/$app.app/Contents/MacOS
            mkdir $bindir/$app.app/Contents/Resources
            cd $bindir/$app.app/Contents
            ln -s ../../../lib  lib
            cd MacOS
            ln -s ../../../$app  $app
            ln -s ../../../../../../bin/visit visit
            cd $pwd
            cp $VisItDir/common/icons/$iconFiles[$i].icns $bindir/$app.app/Contents/Resources
            sed "s/PROGRAMNAME/$menuNames[$i]/g" $VisItDir/include/$plist[$i] | sed "s/VERSION/$Version/g" | sed "s/CREATORCODE/$creatorCodes[$i]/g" | sed "s/ICONFILE/$iconFiles[$i]/g" > $bindir/$app.app/Contents/Info.plist
            echo "APPL$creatorCodes[$i]" > $bindir/$app.app/Contents/PkgInfo
        endif
        @ i++
    end
endif

#
# Copy the gcc libraries to the distribution if present.
#
echo "Copying libraries to the distribution..."
if ((-e $VisItDir/lib/libgcc_s.so.1) || (-e $VisItDir/lib/libgcc_s.a)) then
    cp $VisItDir/lib/libgcc_s* $libdir
    cp $VisItDir/lib/libstdc++* $libdir
endif
# Add support for all the tcmalloc libs ... meaning libtcmalloc.so, 
# libtcmalloc.so.0, & libtcmalloc.so.0.0.0.
if (-e $VisItDir/lib/libtcmalloc_minimal.so) then
    cp $VisItDir/lib/libtcmalloc_minimal* $libdir
endif

#
# Copy the VisIt libraries to the distribution.
#
cp `ls $VisItDir/lib/*.$SHLIB_SOEXT | grep -v libvtk\\\|libQt\\\|libpython\\\|libMesaGL\\\|libOSMesa\\\|libhdf\\\|libsz` $libdir
cp $VisItDir/lib/libvtkqt.$SHLIB_SOEXT $libdir
cp $VisItDir/lib/libqtviswindow.$SHLIB_SOEXT $libdir
if("$os" == "darwin") then
# include the python libraries, visit.so and visitmodule.so
   if (-e $VisItDir/lib/visit.so) then
      cp $VisItDir/lib/visit.so $libdir
   endif
   if (-e $VisItDir/lib/visitmodule.so) then
      cp $VisItDir/lib/visitmodule.so $libdir
   endif
# include the non-shared
   cp `ls $VisItDir/lib/*.a` $libdir
endif

#
# Copy the Qt libraries to the distribution.
#
if("$QtLibs" == "TRUE") then
    foreach qlib ($QtCore $QtGui $QtNetwork $QtOpenGL $QtScript $QtSvg $QtXml $QtUiTools)
        if ("$os" != "darwin") then
            cp $VisItDir/lib/$qlib $libdir
            set libnoext = `echo $qlib | awk '{i=index($1,".so"); print substr($1,1,i-1)}'`
            set majorVersion = `echo $qlib | awk '{i=index($1,"so."); split(substr($1,i+3),v,"."); print v[1]}'`
            set minorVersion = `echo $qlib | awk '{i=index($1,"so."); split(substr($1,i+3),v,"."); print v[2]}'`
            pushd . > /dev/null
            cd $libdir
            if (! -e $libnoext.so.$majorVersion.$minorVersion) then
                ln -s $qlib $libnoext.so.$majorVersion.$minorVersion
            endif
            if (! -e $libnoext.so.$majorVersion) then
                ln -s $qlib $libnoext.so.$majorVersion
            endif
            if (! -e $libnoext.so) then
                ln -s $qlib $libnoext.so
            endif
            if (-e $VisItDir/lib/$libnoext.a) then
                ln -s $qlib $libnoext.a
            endif
            popd > /dev/null
        else
            if(-d $VisItDir/lib/$qlib) then
                # Copy the framework directory. Since it can have symlinks and all 
                # sorts of stuff in it, use tar to copy the contents.
                set startdir=`pwd`
                mkdir "$libdir/$qlib"
                cd $VisItDir/lib/$qlib
                tar cf $startdir/frameworktmp.tar * > /dev/null
                cd $startdir
                cd $libdir/$qlib
                tar xvf $startdir/frameworktmp.tar > /dev/null
                cd $startdir
                rm -f frameworktmp.tar
            else
                cp $VisItDir/lib/$qlib $libdir
            endif
        endif
    end
endif

#
# Copy the Mesa libraries to the distribution.
#
cp $VisItDir/lib/$MesaOSMesaLibName $libdir/$MesaOSMesaLibName
cp $VisItDir/lib/$MesaMesaGLLibName $libdir/$MesaMesaGLLibName

if ("$os" != "darwin") then
    set OSMesaMajorVersion = `echo $MesaOSMesaLibName | cut -c 14`
    set MesaGLMajorVersion = `echo $MesaMesaGLLibName | cut -c 14`

    if ("$OSMesaMajorVersion" != "") then
        ln -s $MesaOSMesaLibName $libdir/libOSMesa.so.$OSMesaMajorVersion
        ln -s libOSMesa.so.$OSMesaMajorVersion $libdir/libOSMesa.so
        ln -s $MesaMesaGLLibName $libdir/libMesaGL.so.$MesaGLMajorVersion
        ln -s libMesaGL.so.$MesaGLMajorVersion $libdir/libMesaGL.so
    endif
endif

#
# Copy the GLEW library, if it exists, to the distribution.
#
if(-e $VisItDir/lib/$GLEWLibName) then
    cp $VisItDir/lib/$GLEWLibName $libdir/$GLEWLibName
endif

#
# Copy Python to the distribution
#
if(("$PythonExe" == "TRUE") && "$cli_exists" == "TRUE") then
    set pyver = `basename $VisItDir/lib/python/lib/python?.?`;
    mkdir $libdir/python
    mkdir $libdir/python/lib
    mkdir $libdir/python/lib/$pyver
    mkdir $libdir/python/lib/$pyver/config
    mkdir $libdir/python/lib/$pyver/lib-dynload
    mkdir $libdir/python/lib/$pyver/lib-tk
    #mkdir $libdir/python/lib/$pyver/plat-...?
    mkdir $libdir/python/lib/$pyver/site-packages
    mkdir $libdir/python/lib/$pyver/site-packages/PIL
    mkdir $libdir/python/lib/$pyver/xml
    mkdir $libdir/python/lib/$pyver/xml/dom
    mkdir $libdir/python/lib/$pyver/xml/parsers
    mkdir $libdir/python/lib/$pyver/xml/sax
    cp $VisItDir/lib/python/lib/$pyver/*.txt                $libdir/python/lib/$pyver
    cp $VisItDir/lib/python/lib/$pyver/*.py                 $libdir/python/lib/$pyver
    cp $VisItDir/lib/python/lib/$pyver/*.pyc                $libdir/python/lib/$pyver
    cp $VisItDir/lib/python/lib/$pyver/*.pyo                $libdir/python/lib/$pyver
    ls $VisItDir/lib/python/lib/$pyver/*.$SHLIB_SOEXT >& /dev/null
    if ($status == 0) then
      cp $VisItDir/lib/python/lib/$pyver/*.$SHLIB_SOEXT     $libdir/python/lib/$pyver
    endif
    cp $VisItDir/lib/python/lib/$pyver/config/*             $libdir/python/lib/$pyver/config
    cp $VisItDir/lib/python/lib/$pyver/lib-dynload/*        $libdir/python/lib/$pyver/lib-dynload
    cp $VisItDir/lib/python/lib/$pyver/lib-tk/*             $libdir/python/lib/$pyver/lib-tk
    ls $VisItDir/lib/python/lib/$pyver/site-packages/PIL.* >& /dev/null
    if ($status == 0) then
      cp $VisItDir/lib/python/lib/$pyver/site-packages/PIL.* $libdir/python/lib/$pyver/site-packages
    endif
    ls $VisItDir/lib/python/lib/$pyver/site-packages/PIL/* >& /dev/null
    if ($status == 0) then
      cp $VisItDir/lib/python/lib/$pyver/site-packages/PIL/*  $libdir/python/lib/$pyver/site-packages/PIL
    endif
    ls $VisItDir/lib/python/lib/$pyver/site-packages/pyparsing* >& /dev/null
    if ($status == 0) then
      cp $VisItDir/lib/python/lib/$pyver/site-packages/pyparsing.* $libdir/python/lib/$pyver/site-packages
    endif
    cp $VisItDir/lib/python/lib/$pyver/xml/*.{py,pyc,pyo}         $libdir/python/lib/$pyver/xml
    cp $VisItDir/lib/python/lib/$pyver/xml/dom/*.{py,pyc,pyo}     $libdir/python/lib/$pyver/xml/dom
    cp $VisItDir/lib/python/lib/$pyver/xml/parsers/*.{py,pyc,pyo} $libdir/python/lib/$pyver/xml/parsers
    cp $VisItDir/lib/python/lib/$pyver/xml/sax/*.{py,pyc,pyo}     $libdir/python/lib/$pyver/xml/sax

    ln -s "python/lib/$pyver/config/lib${pyver}.$SHLIB_SOEXT" $libdir
endif

#
# Copy the VTK libraries to the distribution.
#
if ("$VTKLibs" == "TRUE") then
    foreach vtklib ($vtklibs)
       if ("$SHLIB_SOEXT" == "so") then
           if ("$os" == "aix" || "$os" == "osf") then
               cp $VisItDir/lib/$vtklib.so $libdir/$vtklib.so
           else
               cp $VisItDir/lib/$vtklib.so.5.0.0 $libdir/$vtklib.so.5.0.0
               ln -s $vtklib.so.5.0.0 $libdir/$vtklib.so.5.0
               ln -s $vtklib.so.5.0.0 $libdir/$vtklib.so
           endif
       else
           cp $VisItDir/lib/$vtklib.dylib $libdir/$vtklib.dylib
       endif
    end
endif

#
# Copy the HDF5 (and szip) library, if it exists, to the distribution.
#
if(-e $VisItDir/lib/$HdfHDF5LibName) then
    if ("$SHLIB_SOEXT" == "so") then
       if ("$os" == "aix" || "$os" == "osf") then
           cp $VisItDir/lib/libhdf5.so $libdir/libhdf5.so
       else
           ls -l $libdir/*hdf5*
           set HDF5LibFile = `readlink -f $VisItDir/lib/libhdf5.so`
           set HDF5Filename = `basename $HDF5LibFile`
           set HDF5MajorVersion = `echo $HDF5Filename | cut -c 12`
           echo $HDF5LibFile $libdir/
           cp $HDF5LibFile $libdir/
           ln -s $HDF5Filename $libdir/libhdf5.so.$HDF5MajorVersion
           ln -s $HDF5Filename $libdir/libhdf5.so
       endif
    else
        cp $VisItDir/lib/$HdfHDF5LibName $libdir/$HdfHDF5LibName
    endif
endif
if(-e $VisItDir/lib/$HdfSzipLibName) then
    if ("$SHLIB_SOEXT" == "so") then
       if ("$os" == "aix" || "$os" == "osf") then
           cp $VisItDir/lib/libsz.so $libdir/libsz.so
       else
           set SZipLibFile = `readlink -f $VisItDir/lib/libsz.so`
           set SZipFilename = `basename $SZipLibFile`
           set SZipMajorVersion = `echo $SZipFilename | cut -c 10`
           cp $SZipLibFile $libdir/
           ln -s $SZipFilename $libdir/libsz.so.$SZipMajorVersion
           ln -s $SZipFilename $libdir/libsz.so
       endif
    else
        cp $VisItDir/lib/$HdfSzipLibName $libdir/$HdfSzipLibName
    endif
endif

#
# Copy the plugins to the distribution.
#
echo "Copying plugins to the distribution..."
cp $VisItDir/plugins/plots/*.$SHLIB_SOEXT         $plugindir/plots
cp $VisItDir/plugins/operators/libE*.$SHLIB_SOEXT $plugindir/operators
cp $VisItDir/plugins/operators/libG*.$SHLIB_SOEXT $plugindir/operators
cp $VisItDir/plugins/operators/libI*.$SHLIB_SOEXT $plugindir/operators
cp $VisItDir/plugins/operators/libS*.$SHLIB_SOEXT $plugindir/operators
cp $VisItDir/plugins/operators/libV*.$SHLIB_SOEXT $plugindir/operators
cp $VisItDir/plugins/databases/*.$SHLIB_SOEXT     $plugindir/databases

#
# Copy includes
#
echo "Copying include files to the distribution..."
mkdir $incdir/visit
mkdir $incdir/mesa
mkdir $incdir/mesa/GL
mkdir $incdir/vtk
mkdir $incdir/vtk/Common
mkdir $incdir/vtk/Filtering
mkdir $incdir/vtk/GenericFiltering
mkdir $incdir/vtk/Graphics
mkdir $incdir/vtk/Hybrid
mkdir $incdir/vtk/IO
mkdir $incdir/vtk/Imaging
mkdir $incdir/vtk/MangleMesaInclude
mkdir $incdir/vtk/Rendering
mkdir $incdir/vtk/Utilities
mkdir $incdir/vtk/Utilities/vtkexpat
mkdir $incdir/vtk/Utilities/vtktiff
mkdir $incdir/vtk/Utilities/vtkzlib
mkdir $incdir/vtk/vtkstd
mkdir $incdir/python
mkdir $incdir/qt
mkdir $incdir/qt/private

cp $VisItDir/include/*.h                        $incdir
cp $VisItDir/include/make*                      $incdir
cp $VisItDir/include/visit/[A-M]*.h             $incdir/visit
cp $VisItDir/include/visit/[N-Q]*.h             $incdir/visit
cp $VisItDir/include/visit/[R-Z]*.h             $incdir/visit
cp $VisItDir/include/visit/a[a-uw-zA-Z]*.h      $incdir/visit
ls $VisItDir/include/visit/av[a-su-zA-Z]*.h >& /dev/null
if ($status == 0) then
  cp $VisItDir/include/visit/av[a-su-zA-Z]*.h   $incdir/visit
endif
cp $VisItDir/include/visit/avt[a-z]*.h          $incdir/visit
cp $VisItDir/include/visit/avt[A-M]*.h          $incdir/visit
cp $VisItDir/include/visit/avt[N-Z]*.h          $incdir/visit
cp $VisItDir/include/visit/[b-z]*.h             $incdir/visit
cp $VisItDir/include/mesa/GL/*.h                $incdir/mesa/GL
cp $VisItDir/include/vtk/*.h                    $incdir/vtk
ls $VisItDir/include/vtk/*.txx >& /dev/null
if ($status == 0) then
  cp $VisItDir/include/vtk/*.txx                $incdir/vtk
endif
ls $VisItDir/include/vtk/Common/[a-uw-zA-Z]*.h >& /dev/null
if ($status == 0) then
  cp $VisItDir/include/vtk/Common/[a-uw-zA-Z]*.h   $incdir/visit
endif
ls $VisItDir/include/vtk/Common/[a-uw-zA-Z]*.txx >& /dev/null
if ($status == 0) then
  cp $VisItDir/include/vtk/Common/[a-uw-zA-Z]*.txx $incdir/visit
endif
ls $VisItDir/include/vtk/Common/v[a-su-zA-Z]*.h >& /dev/null
if ($status == 0) then
  cp $VisItDir/include/vtk/Common/v[a-su-zA-Z]*.h  $incdir/visit
endif
ls $VisItDir/include/vtk/Common/v[a-su-zA-Z]*.txx >& /dev/null
if ($status == 0) then
  cp $VisItDir/include/vtk/Common/v[a-su-zA-Z]*.txx $incdir/visit
endif
ls $VisItDir/include/vtk/Common/vt[a-jl-zA-Z]*.h >& /dev/null
if ($status == 0) then
  cp $VisItDir/include/vtk/Common/vt[a-jl-zA-Z]*.h $incdir/vtk/Common
endif
ls $VisItDir/include/vtk/Common/vt[a-jl-zA-Z]*.txx >& /dev/null
if ($status == 0) then
  cp $VisItDir/include/vtk/Common/vt[a-jl-zA-Z]*.txx $incdir/vtk/Common
endif
cp $VisItDir/include/vtk/Common/vtk[a-zA-J]*.h   $incdir/vtk/Common
cp $VisItDir/include/vtk/Common/vtk[a-zA-J]*.txx $incdir/vtk/Common
cp $VisItDir/include/vtk/Common/vtk[K-Z_]*.h      $incdir/vtk/Common
ls $VisItDir/include/vtk/Common/vtk[K-Z]*.txx >& /dev/null
if ($status == 0) then
  cp $VisItDir/include/vtk/Common/vtk[K-Z]*.txx $incdir/vtk/Common
endif
cp $VisItDir/include/vtk/Filtering/*.h          $incdir/vtk/Filtering
cp $VisItDir/include/vtk/Filtering/*.txx        $incdir/vtk/Filtering
cp $VisItDir/include/vtk/GenericFiltering/*.h   $incdir/vtk/GenericFiltering
ls $VisItDir/include/vtk/GenericFiltering/*.txx >& /dev/null
if ($status == 0) then
  cp $VisItDir/include/vtk/GenericFiltering/*.txx $incdir/vtk/GenericFiltering
endif
cp $VisItDir/include/vtk/Graphics/*.h           $incdir/vtk/Graphics
ls $VisItDir/include/vtk/Graphics/*.txx >& /dev/null
if ($status == 0) then
  cp $VisItDir/include/vtk/Graphics/*.txx       $incdir/vtk/Graphics
endif
cp $VisItDir/include/vtk/Hybrid/*.h             $incdir/vtk/Hybrid
ls $VisItDir/include/vtk/Hybrid/*.txx >& /dev/null
if ($status == 0) then
  cp $VisItDir/include/vtk/Hybrid/*.txx         $incdir/vtk/Hybrid
endif
cp $VisItDir/include/vtk/IO/*.h                 $incdir/vtk/IO
ls $VisItDir/include/vtk/IO/*.txx >& /dev/null
if ($status == 0) then
  cp $VisItDir/include/vtk/IO/*.txx             $incdir/vtk/IO
endif
cp $VisItDir/include/vtk/Imaging/*.h            $incdir/vtk/Imaging
ls $VisItDir/include/vtk/Imaging/*.txx >& /dev/null
if ($status == 0) then
  cp $VisItDir/include/vtk/Imaging/*.txx        $incdir/vtk/Imaging
endif
cp $VisItDir/include/vtk/MangleMesaInclude/*.h  $incdir/vtk/MangleMesaInclude
ls $VisItDir/include/vtk/MangleMesaInclude/*.txx >& /dev/null
if ($status == 0) then
  cp $VisItDir/include/vtk/MangleMesaInclude/*.txx $incdir/vtk/MangleMesaInclude
endif
cp $VisItDir/include/vtk/Rendering/*.h          $incdir/vtk/Rendering
ls $VisItDir/include/vtk/Rendering/*.txx >& /dev/null
if ($status == 0) then
  cp $VisItDir/include/vtk/Rendering/*.txx      $incdir/vtk/Rendering
endif
cp $VisItDir/include/vtk/Utilities/*.h          $incdir/vtk/Utilities
ls $VisItDir/include/vtk/Utilities/*.txx >& /dev/null
if ($status == 0) then
  cp $VisItDir/include/vtk/Utilities/*.txx      $incdir/vtk/Utilities
endif
cp $VisItDir/include/vtk/Utilities/vtkexpat/*.h $incdir/vtk/Utilities/vtkexpat
cp $VisItDir/include/vtk/Utilities/vtktiff/*.h  $incdir/vtk/Utilities/vtktiff
cp $VisItDir/include/vtk/Utilities/vtkzlib/*.h  $incdir/vtk/Utilities/vtkzlib
cp $VisItDir/include/vtk/vtkstd/*               $incdir/vtk/vtkstd
cp $VisItDir/include/python/*.h                 $incdir/python

#
# Copy the QT headers to the include directory if we are using the
# Free edition.  Copy the license there as well.
#
cp $VisItDir/include/qt/[a-pr-zA-Z]*.h          $incdir/qt
cp $VisItDir/include/qt/q[a-l]*.h               $incdir/qt
cp $VisItDir/include/qt/q[m-zA-Z]*.h            $incdir/qt
cp $VisItDir/svn_bin/QTLICENSE.*          $incdir/qt
cp $VisItDir/include/qt/private/*.h             $incdir/qt/private

#
# Copy the help files to the distribution.
#
if (-e $VisItDir/help && "$gui_exists" == "TRUE") then
   set tmpDir = `pwd`
   cd $VisItDir/help
   set translations=`find . -type d`
   cd $tmpDir
   foreach t1 ($translations)
       set t2=`echo $t1 | sed "s/.\///g"`
       set translation=`echo $t2 | grep -v "\.svn"`
       if ("$translation" != ""  && "$translation" != ".") then
           echo "Copying $translation help files to the distribution..." 
           mkdir $helpdir/$translation

           cp $VisItDir/help/$translation/[a-gi-z]*.html    $helpdir/$translation
           ls $VisItDir/help/$translation/h[a-df-z]*.html >& /dev/null
           if ($status == 0) then
             cp $VisItDir/help/$translation/h[a-df-z]*.html $helpdir/$translation
           endif
           ls $VisItDir/help/$translation/he[a-km-z]*.html >& /dev/null
           if ($status == 0) then
             cp $VisItDir/help/$translation/he[a-km-z]*.html $helpdir/$translation
           endif
           ls $VisItDir/help/$translation/hel[a-oq-z]*.html >& /dev/null
           if ($status == 0) then
             cp $VisItDir/help/$translation/hel[a-oq-z]*.html $helpdir/$translation
           endif
           ls $VisItDir/help/$translation/help[a-z]*.html >& /dev/null
           if ($status == 0) then
             cp $VisItDir/help/$translation/help[a-z]*.html $helpdir/$translation
           endif
           cp $VisItDir/help/$translation/help0[01]*.html   $helpdir/$translation
           cp $VisItDir/help/$translation/help0[23]*.html   $helpdir/$translation
           cp $VisItDir/help/$translation/help0[45]*.html   $helpdir/$translation
           ls "$VisItDir/help/$translation/help0[67]*.html" >& /dev/null
           if ($status == 0) then
             cp $VisItDir/help/$translation/help0[67]*.html $helpdir/$translation
           endif
           if (-e $VisItDir/help/$translation/visit.helpml) then
              cp $VisItDir/help/$translation/visit.helpml $helpdir/$translation
           endif
       endif
   end
endif

#
# Copy the Java class files to the distribution.
#
if (-e $VisItDir/java/llnl/visit/ViewerProxy.class) then
   cp -R $VisItDir/java/llnl $javadir
endif
if (-e $VisItDir/java/RunViewer.class) then
   cp -R $VisItDir/java/RunViewer.class $javadir
endif

#
# Install libsim
#
if (-e $VisItDir/archives/libsim.a) then
    cp $VisItDir/archives/libsim.a $simv1dir/lib
    cp $VisItDir/sim/lib/VisItControlInterface_V1.h $simv1dir/include
    cp $VisItDir/sim/lib/visitfortransiminterface.inc $simv1dir/include
    cp $VisItDir/databases/SimV1/VisItDataInterface_V1.h $simv1dir/include
endif
if (-e $VisItDir/archives/libsimf.a) then
    cp $VisItDir/archives/libsimf.a $simv1dir/lib
endif
#
# Install libsim V2
#
if (-e $VisItDir/archives/libsimV2.a) then
    cp $VisItDir/archives/libsimV2.a $simv2dir/lib
    cp $VisItDir/sim/lib/VisItControlInterface_V2.h $simv2dir/include
    cp $VisItDir/sim/lib/visitfortransimV2interface.inc $simv2dir/include
    cp $VisItDir/databases/SimV2/VisItDataInterface_V2.h $simv2dir/include
endif
if (-e $VisItDir/archives/libsimV2f.a) then
    cp $VisItDir/archives/libsimV2f.a $simv2dir/lib
endif

#
# Copy the ultra wrapper files
#
cp $VisItDir/ultrawrapper/*.py $ultradir/

#
# Copy the configuration files.
#
mkdir $verdir/.visit
cp $VisItDir/svn_bin/visit-config-llnl_closed $verdir/.visit
cp $VisItDir/svn_bin/visit-config-nersc  $verdir/.visit
cp $VisItDir/svn_bin/visit-config-llnl_open   $verdir/.visit
cp $VisItDir/svn_bin/visit-config-ornl   $verdir/.visit
cp $VisItDir/svn_bin/visit-config-anag   $verdir/.visit
cp $VisItDir/svn_bin/visit-config-anl    $verdir/.visit
cp $VisItDir/svn_bin/visit-config-princeton    $verdir/.visit
cp $VisItDir/svn_bin/visit-config-tacc    $verdir/.visit
cp $VisItDir/svn_bin/visit-config-tacc_internal    $verdir/.visit
if (-e $verdir/.visit/visit-config-$Configuration) then
    ln -s visit-config-$Configuration $verdir/.visit/config
endif

#
# Copy the guiconfig files
#
cp $VisItDir/svn_bin/visit-guiconfig-anag $verdir/.visit
if (-e $verdir/.visit/visit-guiconfig-$Configuration) then
    ln -s visit-guiconfig-$Configuration $verdir/.visit/guiconfig
endif

#
# Copy the visitrc files.
#
cp $VisItDir/svn_bin/visit-visitrc-anag   $verdir/.visit
if (-e $verdir/.visit/visit-visitrc-$Configuration) then
    ln -s visit-visitrc-$Configuration $verdir/.visit/visitrc
endif

#
# Strip the executables and shared libraries.
#
if ($Strip == "TRUE") then
    if("$os" == "darwin") then
        echo "We don't do library stripping on MacOS X."
    else
        strip $bindir/* >& /dev/null
        strip $libdir/* >& /dev/null
        strip $plugindir/plots/* >& /dev/null
        strip $plugindir/operators/* >& /dev/null
        strip $plugindir/databases/* >& /dev/null
    endif
endif

#
# On the Mac, we may be using libraries and frameworks that are not using
# @executable_path/../lib so let's make sure that we are by modifying
# them.
#
if("$os" == "darwin" && $makerelative == "TRUE") then
    # Gather the list of files that we're going to change to @executable_path/../lib
    set candidates = ()
    foreach f (`ls $libdir`)
        set dylib = `echo $f | awk '{i=index($1,".dylib"); if(i>1)print 1;else print 0;}'`
        if($dylib == 1) then
            set candidates = ($candidates $libdir/$f)
        else
            set framework = `echo $f | awk '{i=index($1,".framework"); if(i>1)print substr($1,1,i-1);else print "";}'`
            if($framework != "") then
                set candidates = ($candidates $libdir/$framework.framework/$framework)
            endif
        endif
    end
    foreach f (`ls $bindir`)
        set exetype = `file $bindir/$f | awk '{print $2 $3}'`
        if($exetype == "Mach-Oexecutable") then
            set candidates = ($candidates $bindir/$f)
        endif
    end
    # In principle we should check all plugins but for now, let's just check the
    # libG,libV plugins for plots and operators since it should speed up the
    # checks
    foreach ptype (plots operators)
        foreach f (`ls $plugindir/$ptype/lib{G,V}*.dylib`)
            set candidates = ($candidates $f)
        end
    end

    # For each candidate, make sure that any VisIt-related library that we use is
    # referenced relative to @executable_path/../lib instead of using the whole
    # path, which won't likely exist on the target machine. Of course, we're
    # assuming that the library is named like "/path/...visit...", which is
    # unlikely if the developer is using a library or framework that has been
    # installed globally on the system.
    foreach dyobj ($candidates)
        set dyname=""
        set installprefix = ""
        foreach f (`otool -L $dyobj`)
            # Determine whether the line contains "visit" and begins with "/"
            set notlibrel = `echo $f | awk '{i=index($1,"visit");j=index($1,"/");if((i>1)&&(j==1))print 1;else print 0;}'`
            if($notlibrel == 1) then
                # Determine whether the line ends with ":". If so, then the line is the 
                # name of the library/framework we're inspecting.
                set tmpinstallprefix = `echo $f | awk '{i=index($1,":");if(i>1){j=index($1,"/lib/");print substr($1,1,j+4);}else print ""}'`
                if($tmpinstallprefix != "") then
                    set installprefix = $tmpinstallprefix
                    set dyname = `echo $f | awk '{i=index($1,":");if(i>1){j=index($1,"/lib/");print substr($1,j+5,length($1)-j-5);}else print ""}'`
                else
                    set depname = `echo $f | awk '{i=index($1,"/lib/");print substr($1,i+5,length($1)-i-3)}'`
                    set contains_dyname = `echo $f $dyname | awk '{i=index($1,$2);if(i>=1)print 1;else print 0}'`
                    set match = `echo $depname $dyname | awk '{split($1,a,"/");split($2,b,"/");c=-1;for(i=0;i<length(a);++i)for(j=0;j<length(b);++j)if(a[i]==b[j]){c++};print c}'`
                    if($match > 0) then
                        #echo "install_name_tool -id @executable_path/../lib/$depname $installprefix$depname"
                        install_name_tool -id @executable_path/../lib/$depname $installprefix$depname
                    else
                        #echo "install_name_tool -change $f @executable_path/../lib/$depname $installprefix$dyname"
                        install_name_tool -change $f @executable_path/../lib/$depname $installprefix$dyname
                    endif
                endif
            endif
        end
    end
endif

#
# Change the permissions so that they are correct.
#
chmod -R go+rX distribution

#
# Build the compressed tar file.
#
set fname = visit`echo $Version | tr "." "_"`.$osver.tar

cd distribution
if ($Compress == "COMPRESS") then
   tar cvbf 20 $fname visit
   compress $fname
   mv $fname.Z ..
else
   tar cvbf 20 - visit | gzip > ../$fname.gz
endif
cd ..

#
# Clean up the temporary directories.
#
rm -rf distribution
