#!/bin/sh 
#
#	$Id: //depot/idl/IDL_70/idldir/bin/unix/bridge_post_unpack#1 $
#
# unpack_idl
#
# This script expects to be run from the top level ITT directory
# after IDL has been unpacked from the distribution media. It performs
# tasks that need to be run on the target machine to complete localization.
#
#	$1 - If $1 is non-empty, this script assumes that it's being
#	     run directly from the tty and offers the user the option
#	     of trimming excess binaries from the IDL tree. Otherwise, it
#	     limits itself to non-interactive setup tasks.

VERSION=70

IDL_DIR=`pwd`/idl$VERSION
IDL_BIN=`pwd`/idl$VERSION/bin
UDIR=`pwd`
ITT_DIR=`pwd`
UNAME=`uname`


# Create the shell scripts bridge_setup, bridge_setup.ksh and 
# bridge_setup.bash, which can be used to set up the environment variables 
# required by the IDL connectivity bridges.
#
# C shell users should source bridge_setup from their .cshrc files,
# using the full path to the IDL directory as follows:
#    source full_path_to_IDL_Directory/idl_setup
# Korn shell users should run bridge_setup.ksh from their
# .profile file (using the ". bridge_setup.ksh" notation), as follows:
#    . full_path_to_IDL_Directory/bridge_setup.ksh
# Bash shell users should source bridge_setup from their .bashrc files,
# using the full path to the IDL directory as follows:
#    . full_path_to_IDL_Directory/bridge_setup.bash

echo "
# Korn and Bash shell commands to define IDL environment variables for the 
# connectivity bridges.
#
# These scripts can be used by IDL users who use ksh or bash as their 
# interactive shell to define the environment variables required 
# by IDL connectivity bridges using the following command:
#
# Korn shell users should run bridge_setup.ksh from their .profile file,
# using the full path the the IDL directory as follows:
#    . $IDL_DIR/bin/bridge_setup.ksh
# Bash shell users should source bridge_setup.bash from their .bashrc files,
# using the full path to the IDL directory as follows:
#    . $IDL_DIR/bin/bridge_setup.bash
#

ITT_DIR=$ITT_DIR
IDL_DIR=$IDL_DIR
export ITT_DIR IDL_DIR

UNAME=\`uname\`

case \$UNAME in
	\"SunOS\")
            BIN_ARCH=/usr/bin/arch
            if [ -x /usr/bin/arch ]; then
                BIN_ARCH=/usr/bin/arch
            elif [ -x /usr/ucb/arch ]; then
                BIN_ARCH=/usr/ucb/arch
            fi
            if [ \`\$BIN_ARCH\` = i86pc ]; then
              ARCH=\".x86\"
            else
              # If the system is running the 64-bit SunOS kernel, a 64-bit
              # IDL is installed, and either 32-bit IDL is NOT installed or
              # 32-bit IDL is installed and the user specified the 
              # IDL_PREFER_64 environment variable, use the 64-bit version.
              # Otherwise use the 32-bit version since it will work on all
              # supported Sun machines and 32-bit Java is more common.
              ARCH=\".sparc\"
              if [ -x /bin/isainfo ]; then
                if [ \`/bin/isainfo -b\` = \"64\" ] && \\
                    [ -f \$IDL_DIR/bin/bin.solaris2.sparc64/idl ]; then
                  if [ ! -f \$IDL_DIR/bin/bin.solaris2.sparc/idl ] || \\
                       ( [ -f \$IDL_DIR/bin/bin.solaris2.sparc/idl ] && \\
                         [ \$IDL_PREFER_64 ] ) ; then
                    ARCH=\".sparc64\"
                  fi
                fi
              fi
            fi
            BIN_DIR=\"\$IDL_DIR/bin/bin.solaris2\$ARCH\"
            if [ \"\$LD_LIBRARY_PATH\" = \"\" ]; then
                LD_LIBRARY_PATH=\$BIN_DIR
            else
                LD_LIBRARY_PATH=\"\$BIN_DIR\":\"\$LD_LIBRARY_PATH\"
            fi
           export LD_LIBRARY_PATH
        ;;

	\"Linux\")
           BIN_ARCH=/bin/arch
           ARCH=\".x86\"
           if [ -x \$BIN_ARCH ]; then
              if [ \`\$BIN_ARCH\` = \"x86_64\" ] && \\
                 [ -f \$IDL_DIR/bin/bin.linux.x86_64/idl ]; then
                 if [ ! -f \$IDL_DIR/bin/bin.linux.x86/idl ] || \\
                    ( [ -f \$IDL_DIR/bin/bin.linux.x86/idl ] && \\
                      [ \$IDL_PREFER_64 ] ) ; then
                    ARCH=\".x86_64\"
                 fi
              fi
           fi
           BIN_DIR=\"\$IDL_DIR/bin/bin.linux\$ARCH\"
           if [ \"\$LD_LIBRARY_PATH\" = \"\" ]; then
               LD_LIBRARY_PATH=\"\$BIN_DIR\"
           else
               LD_LIBRARY_PATH=\"\$BIN_DIR\":\"\$LD_LIBRARY_PATH\"
           fi
           export LD_LIBRARY_PATH
        ;;

	\"Darwin\")
           BIN_ARCH=/usr/bin/arch
           if [ \`\$BIN_ARCH\` = i386 ]; then
              ARCH=\".i386\"
           else
              ARCH=\".ppc\"
           fi
 	   BIN_DIR=\"\$IDL_DIR/bin/bin.darwin\$ARCH\"
           if [ \"\$DYLD_LIBRARY_PATH\" = \"\" ]; then
               DYLD_LIBRARY_PATH=\"\$BIN_DIR\"
           else
               DYLD_LIBRARY_PATH=\"\$BIN_DIR\":\"\$DYLD_LIBRARY_PATH\"
           fi
           export DYLD_LIBRARY_PATH
        ;;

        *)
        ;;
    
esac

PATH=\"\$PATH:\$BIN_DIR\"
export PATH

if [ \$CLASSPATH ];  then
    CLASSPATH=\"\$CLASSPATH\":.:\"\$IDL_DIR/resource/bridges/export/java/javaidlb.jar\"
else
    CLASSPATH=\".:\$IDL_DIR/resource/bridges/export/java/javaidlb.jar\"
fi
export CLASSPATH

" > $IDL_BIN/bridge_setup.ksh
chmod 755 $IDL_BIN/bridge_setup.ksh
cp $IDL_BIN/bridge_setup.ksh $IDL_BIN/bridge_setup.bash
chmod 755 $IDL_BIN/bridge_setup.bash

#-----------------------------------------------------------------

echo "
# C shell commands to define IDL environment variables for the 
# connectivity bridges.
#
# This script can be used by IDL users who use csh as their interactive shell
# to define the environment variables required by IDL connectivity bridges
# using the following command:
#
#    source $IDL_DIR/bin/bridge_setup


setenv ITT_DIR $ITT_DIR
setenv IDL_DIR $IDL_DIR

set UNAME=\`uname\`

switch (\$UNAME)
	case \"SunOS\":
            set BIN_ARCH=/usr/bin/arch
            if ( -x /usr/bin/arch ) then
                set BIN_ARCH=/usr/bin/arch
            else if ( -x /usr/ucb/arch ) then
                set BIN_ARCH=/usr/ucb/arch
            endif
            if ( \`\$BIN_ARCH\` == i86pc ) then
              set ARCH=\".x86\"
            else
              # If the system is running the 64-bit SunOS kernel, a 64-bit
              # IDL is installed, and either 32-bit IDL is NOT installed or
              # 32-bit IDL is installed and the user specified the 
	      # IDL_PREFER_64 environment variable, use the 64-bit version.
              # Otherwise use the 32-bit version since it will work on all
              # supported Sun machines and 32-bit Java is more common.
              set ARCH=\".sparc\"
              if ( -x /bin/isainfo ) then
                if (( \`/bin/isainfo -b\` == 64 ) && \\
                    ( -f \$IDL_DIR/bin/bin.solaris2.sparc64/idl)) then
                  if ( ( ! -f \$IDL_DIR/bin/bin.solaris2.sparc/idl ) || \\
                       ( ( -f \$IDL_DIR/bin/bin.solaris2.sparc/idl ) && \\
                         ( \$?IDL_PREFER_64 ) ) ) then
                    set ARCH=\".sparc64\"
                  endif
                endif
              endif
            endif
            set BIN_DIR=\"\$IDL_DIR/bin/bin.solaris2\$ARCH\"
            if (\$?LD_LIBRARY_PATH == 0 ) then
                setenv LD_LIBRARY_PATH \$BIN_DIR
            else
                setenv LD_LIBRARY_PATH \"\$BIN_DIR\":\"\$LD_LIBRARY_PATH\"
            endif
        breaksw

 	case \"Linux\":
           set ARCH=\".x86\"
           if ( -x /bin/arch ) then
              if (( \`/bin/arch \` == \"x86_64\" ) && \\
                  ( -f \$IDL_DIR/bin/bin.linux.x86_64/idl)) then
                if ( ( ! -f \$IDL_DIR/bin/bin.linux.x86/idl ) || \\
                     ( ( -f \$IDL_DIR/bin/bin.linux.x86/idl ) && \\
                       ( \$?IDL_PREFER_64 ) ) ) then
                  set ARCH=\".x86_64\"
                endif
              endif
           endif
           set BIN_DIR=\"\$IDL_DIR/bin/bin.linux\$ARCH\"
           if (\$?LD_LIBRARY_PATH == 0 )  then
               setenv LD_LIBRARY_PATH \"\$BIN_DIR\"
           else
               setenv LD_LIBRARY_PATH \"\$BIN_DIR\":\"\$LD_LIBRARY_PATH\"
           endif
        breaksw

	case \"Darwin\":
           set BIN_ARCH=/usr/bin/arch
           if ( \`\$BIN_ARCH\` == i386 ) then
              set ARCH=\".i386\"
           else
              set ARCH=\".ppc\"
           endif
 	   set	BIN_DIR=\"\$IDL_DIR/bin/bin.darwin\$ARCH\"
           if (\$?DYLD_LIBRARY_PATH == 0)  then
               setenv DYLD_LIBRARY_PATH \"\$BIN_DIR\"
           else
               setenv DYLD_LIBRARY_PATH \"\$BIN_DIR\":\"\$DYLD_LIBRARY_PATH\"
           endif
        breaksw

        default:
endsw

set path = (\$path \$BIN_DIR)

if (\$?CLASSPATH == 0)  then
    setenv CLASSPATH \".:\$IDL_DIR/resource/bridges/export/java/javaidlb.jar\"
else
    setenv CLASSPATH \"\$CLASSPATH\":.:\"\$IDL_DIR/resource/bridges/export/java/javaidlb.jar\"
endif

" > $IDL_BIN/bridge_setup
chmod 755 $IDL_BIN/bridge_setup
