#!/bin/csh -f
#-----------------------------------------------------------------------
#
# VISIT-WINDOWS-DIST - Build a tar file that contains the VisIt source
#                      code and Windows project files.
#
# Author: Brad Whitlock
# Date:   Fri Jul 5 14:34:16 PST 2002
#
# Usage:
#    visit-windows-dist 
#
#
# Modifications:
#   Brad Whitlock, Mon Jul 15 15:29:37 PST 2002
#   I made it distribute help files.
#
#   Brad Whitlock, Wed Dec 10 09:32:39 PDT 2003
#   I rewrote it so it includes more recent project files and installtion
#   files. It also puts the core header files into a single include directory
#   so you don't have to add tons of include directories in MSVC.
#
#   Brad Whitlock, Thu Jan 8 11:15:13 PDT 2004
#   I added BUILD_NOTES.txt.
#
#   Brad Whitlock, Tue Feb 24 09:00:27 PDT 2004
#   I changed the script so some files are copied using converttextfile, which
#   copies text files but also converts the end of line from UNIX to Windows.
#   This allows me to use the UNIX config files but make them Windows friendly
#   when creating the Windows distribution.
#
#   Brad Whitlock, Fri Mar 5 10:32:41 PDT 2004
#   I changed the script so it copies the lite PDB header files into the new
#   include directory before the old directory gets blown away.
#
#   Brad Whitlock, Thu May 27 14:26:41 PST 2004
#   Changed to account for the new location of winutil.
#
#   Brad Whitlock, Tue Jun 29 10:12:12 PDT 2004
#   I made the Windows version get its own config files.
#
#   Brad Whitlock, Thu Aug 12 12:26:57 PDT 2004
#   I added support for the MSVC7.Net compiler suite.
#
#------------------------------------------------------------------------------

if(`pwd` != "/data_vobs/VisIt") then
    echo "The visit-windows-dist script must be run from the top level VOB directory."
    exit(-1)
endif

# Set some directory variables.
set TOPDIR = "/data_vobs/VisIt"
set SCRIPTDIR = "/data_vobs/VisIt/clearcase_bin"

set VERSION = `cat $TOPDIR/VERSION`
set VisItDev = "$TOPDIR/VisItDev$VERSION"
set VISITSRC="visit"

# Run the visit-dist script so it creates a source distribution
echo "Creating intermediate source package..."
$SCRIPTDIR/visit-dist -withhelp $VISITSRC

# Create a directory to contain the VisIt source distribution.
echo "Creating $VisItDev directory..."
mkdir $VisItDev
cp $VISITSRC.tar.gz $VisItDev
cd $VisItDev

# Put the source into the development directory.
echo "Untarring intermediate source package..."
gunzip $VISITSRC.tar.gz
tar xvf $VISITSRC.tar > /dev/null
rm $VISITSRC.tar

# Remove the tools/mpeg_encode directory since it does not build on Windows
# and it creates a name conflict with the prep tool.
rm -rf $VISITSRC/tools/mpeg_encode

# Copy windowsbuild/VisItBuildInstructionsOnWindows.doc to $VisItDev
cp $TOPDIR/windowsbuild/VisItBuildInstructionsOnWindows.doc .
cp $TOPDIR/windowsbuild/BUILD_NOTES.txt .

# Move windowsbuild/include to $VisItDev/include.
cp -R $TOPDIR/windowsbuild/include .

#
# Set up a new include directory.
#
echo "Creating new visit include directory..."
mkdir include/VisIt
# Copy the lite PDB headers from the include/visit directory before
# blowing it away.
cp $VISITSRC/include/visit/lite_pdb.h include/VisIt
cp $VISITSRC/include/visit/lite_score.h include/VisIt
# Remove the $VISITSRC/include/visit directory since it's full of symlinks and Windows
# will not honor them.
echo "Removing old visit include directory..."
rm -rf $VISITSRC/include/visit
#
# Move a bunch of the core header files to the new visit directory
#
foreach srcdir (common components gui viewer engine mdserver launcher visitpy visit_vtk vtkqt winutil)
    foreach srcfile (`find $VISITSRC/$srcdir -name "*.h"`)
        mv $srcfile include/VisIt
    end
end

#
# Remove SiloObj's Field.h since it will mess up the build for the XML tools.
#
rm -f include/VisIt/Field.h

#
# Copy the XPM files into include/VisIt and remove the copy directories that
# used to be symlinks to common/icons. Also, since the GUI and viewer seem
# to reference the icons using slightly different directory schemes, we
# have to duplicate them for now. The source code should probably be fixed
# at some point so it references the XPM files consistently so we can
# remove the need to duplicate the XPM files like this.
#
echo "Copying icons to include/VisIt..."
mkdir include/VisIt/icons
foreach xpmfile (`find $VISITSRC/common/icons -name "*.xpm"`)
    cp $xpmfile include/VisIt
    mv $xpmfile include/VisIt/icons
end
rm -rf $VISITSRC/gui/icons
rm -rf $VISITSRC/viewer/main/icons

# Replace the version in visit-config.h with the current version and move
# visit-config.h into the include/visit directory
sed -e "s/XXX/$VERSION/" include/visit-config.h > include/VisIt/visit-config.h
rm -f include/visit-config.h

echo "Copying tool include files to include/Tools...".
# Move a bunch of the tool header files to the new tool directory
mkdir include/Tools
foreach tooldir (qtssh silex xml xmledit)
    foreach hdrfile (`find $VISITSRC/tools/$tooldir -name "*.h"`)
        mv $hdrfile include/Tools
    end
end

#
# Put the VTK header files into include/VTK
#
echo "Copying VTK include files to include/VTK..."
foreach hdrdir (Common Filtering Graphics Hybrid IO Imaging Rendering)
    foreach hdrfile (`find $TOPDIR/include/vtk/$hdrdir -name "*.h"`)
        cp $hdrfile include/VTK
    end
end
mkdir include/VTK/MangleMesaInclude
cp $TOPDIR/include/vtk/MangleMesaInclude/*.h include/VTK/MangleMesaInclude

#
# Copy the vtkCamera.h header from include/visit to include/VTK since
# our vtkCamera was built into VTK on Windows.
#
rm -f include/VTK/vtkCamera.h
mv include/VisIt/vtkCamera.h include/VTK

#
# Create an include/Mesa directory and copy the Mesa files to it.
#
echo "Copying Mesa include files to include/Mesa..."
mkdir include/Mesa
mkdir include/Mesa/GL
cp $TOPDIR/include/mesa/GL/*.h include/Mesa/GL

cd $VisItDev

#
# Move windowsbuild/bin up to $VisItDev and add the plugin directories into
# it so that we have some place to store them when we build.
#
echo "Creating bin directory..."
cp -R $TOPDIR/windowsbuild/bin .
foreach configdir (Debug Release MSVC7.Net/Debug MSVC7.Net/Release)
    # Copy the makemovie script to the right bin dir.
    cp $VISITSRC/bin/makemovie.py bin/$configdir
    # Copy the host config files to the right bin dir.
    $SCRIPTDIR/converttextfile $SCRIPTDIR/visit-config-open.ini   bin/$configdir/visit-config-open.ini
    $SCRIPTDIR/converttextfile $SCRIPTDIR/visit-config-closed.ini bin/$configdir/visit-config-closed.ini
    mkdir bin/$configdir/help
    cp $VISITSRC/help/*.{html,helpml} bin/$configdir/help
    mkdir bin/$configdir/databases
    mkdir bin/$configdir/operators
    mkdir bin/$configdir/plots
    # Create small placeholder files or the directory will not be preserved
    # when extracting the distribution since empty directories tend to be
    # removed on Windows.
    echo "Directory for database plugins." > bin/$configdir/databases/README.txt
    echo "Directory for operator plugins." > bin/$configdir/operators/README.txt
    echo "Directory for plot plugins." > bin/$configdir/plots/README.txt
end

#
# We don't maintain all DLLs for the MSVC7.Net distribution so add the rest 
# of the DLLs from the MSVC 6 distribution into the MSVC7.Net directory.
#
foreach buildmode (Debug Release)
    cd $VisItDev/bin/$buildmode
    foreach DLL (MesaGL.dll hdf5dll.dll osmesa.dll silohdf5.dll sziplib.dll zlib.dll)
        cp $DLL ../MSVC7.Net/$buildmode
    end
end
cd $VisItDev

# Unzip the Python tar file in bin/Release so we have Python 2.3.4 modules
# available when we try to distribute VisIt on Windows.
cd bin/Release
gunzip PythonModules.tar.gz
tar xvf PythonModules.tar
rm -f PythonModules.tar
cd $VisItDev

# Unzip the Python tar file in bin/MSVC7.Net/Release so we have Python modules
# available when we try to distribute VisIt on Windows.
cd bin/MSVC7.Net/Release
gunzip PythonModules-2.3.4.tar.gz
tar xvf PythonModules-2.3.4.tar
rm -f PythonModules-2.3.4.tar
cd $VisItDev

# Remove the help files since we've copied them into different directories.
rm $VISITSRC/help/*.{html,helpml}

# Move windowsbuild/lib directory up to $VisItDev.
echo "Creating lib directory..."
cp -R $TOPDIR/windowsbuild/lib .
foreach buildmode (Debug Release)
    # Copy import libraries
    cd $VisItDev/lib/$buildmode
    foreach DLL (MesaGL.lib hdf5dll.lib osmesa.lib silohdf5.lib zlib.lib)
        cp $DLL ../MSVC7.Net/$buildmode
    end
end
cd $VisItDev

# Move windowsbuild/resources directory up to $VisItDev.
echo "Creating resources directory..."
cp -R $TOPDIR/windowsbuild/resources .

# Move windowsbuild/installation directory up to $VisItDev.
echo "Creating installation directory..."
cp -R $TOPDIR/windowsbuild/installation .

# Move the windowsbuild/projects directory up to $VisItDev.
echo "Creating projects directory..."
cp -R $TOPDIR/windowsbuild/projects .

# Move the windowsbuild/projects directory up to $VisItDev.
echo "Creating projects-MSVC7.Net directory..."
cp -R $TOPDIR/windowsbuild/projects-MSVC7.Net .

# Copy the windowsbuild/script directory up to $VisItDev.
echo "Creating script directory..."
cp -R $TOPDIR/windowsbuild/script .

# Create the new distribution
echo "Creating tar file distribution..."
cd $TOPDIR
set VisItDev = "VisItDev$VERSION"
tar cf $VisItDev.tar $VisItDev

# Cleanup
echo "Cleaning up..."
rm -rf $VisItDev
