#!/bin/csh -f
###############################################################################
# Purpose:
#    This script creates bundle directories, which are required for VisIt to
#    run correctly on MacOS X. Without bundles, VisIt can't respond to mouse
#    input.
#
# Programmer: Brad Whitlock
# Date:       Fri Aug 29 13:46:10 PST 2003
#
# Modifications:
#   Brad Whitlock, Thu May 27 12:10:02 PDT 2004
#   I rewrote it so it uses code that is more similar to visit-bin-dist.
#
#   Brad Whitlock, Thu Jan 6 16:44:08 PST 2005
#   I changed the symlinks that we make to account for the executables moving
#   to a different directory. I also made the bundles be put in the exe
#   directory.
#
###############################################################################

set VISITTOP = `pwd`
set VISITEXE = "$VISITTOP/exe"
set VISITLIB = "$VISITTOP/lib"
set VISITINCLUDE = "$VISITTOP/include"
set VISITICONDIR = "$VISITTOP/common/icons"

if -e $VISITEXE then
    # Get the version and cd into the exe directory.
    set VERSION = `cat VERSION`
    cd $VISITEXE

    ##
    ## Create the various application bundles.
    ##
    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)
        echo "Making application bundle for $app"

        if -e $app.app then
            rm -f $app.app/Contents/{bin,lib}
            rm -rf $app.app
        endif

        mkdir $app.app
        mkdir $app.app/Contents
        mkdir $app.app/Contents/MacOS
        mkdir $app.app/Contents/Resources
        cd $app.app/Contents
        ln -s ../../../lib  lib
        cd MacOS
        ln -s ../../../../exe/$app  $app
        ln -s ../../../../bin/visit visit
        cd $pwd
        cp $VISITICONDIR/$iconFiles[$i].icns $app.app/Contents/Resources
        sed "s/PROGRAMNAME/$menuNames[$i]/g" $VISITINCLUDE/$plist[$i] | sed "s/VERSION/$VERSION/g" | sed "s/CREATORCODE/$creatorCodes[$i]/g" | sed "s/ICONFILE/$iconFiles[$i]/g" > $app.app/Contents/Info.plist
        echo "APPL$creatorCodes[$i]" > $app.app/Contents/PkgInfo
        @ i++
    end
else
    @echo "The makebundles script must be run from the top level VisIt directory."
endif
