#!/bin/sh
# -------------------------------------------------------------------
# @(#)ddlgen		Sybase, Inc.
# -------------------------------------------------------------------
# Start DDL Generator Java Edition.
# -------------------------------------------------------------------
# Sybase, Incorporated CONFIDENTIAL and PROPRIETARY material.
#
# Copyright (C) 1994-2003. Sybase Inc., All rights reserved.
#
# Sybase, Incorporated.
# One Sybase Drive
# Dublin, CA, USA  94568
#
# The object version of this software is furnished to purchaser under a
# license for use on a single computer system.  Such executable code can
# be copied (with the inclusion of Sybase' copyright notice) only for
# licensed use in such a system, except as may be otherwise provided in
# writing by Sybase Incorporated.
#
# The information in this program source code is subject to change without
# notice and should not be construed as a commitment by Sybase,
# Incorporated.  Sybase, Incorporated assumes no responsibility for any
# errors that may appear in, or result from the use of this program.  
# Sybase cannot assume any responsibility for the use of any portion of
# this software on any equipment not supplied or approved by Sybase
# Incorporated.
#
# This source code contains commercially valuable and substantial trade
# secrets of Sybase, the design and development of which reflect the
# effort of skilled development experts employed by Sybase Incorporated.
# No permission is granted for viewing or copying this source code unless
# permission in writing is explicitly given to a purchaser by Sybase,
# Incorporated.
#---------------------------------------------------------------------

# PATH is fine even $SYBASE not defined
PATH="/bin:/usr/bin:/etc:$PATH:/usr/sbin:$SYBASE/bin"; export PATH

# ... Find the SYBROOT Home directory ...............................

PLATFORM=`uname -s`

if [ "$SYBROOT" = "" ]
then
   if [ "$PLATFORM" = Darwin ]
   then
       SYBROOT=$SYBASE
   else
       echo "Error: \$SYBROOT variable not set"
       exit 1
   fi 
fi

# ... Environment settings ..........................................

LIB_CONN="$SYBROOT/shared/lib"
export LIB_CONN

if [ ! -f "$LIB_CONN/jconn3.jar" ] 
then
    echo "
	Error: 	Unable to find the Connectivity Library.
		Please check that \$SYBROOT has been set correctly and 
		that the file '$LIB_CONN/jconn3.jar' exists.\n
		\$SYBROOT currently set to '$SYBROOT'\n"
			exit 1
fi

if [ ! -f "$LIB_CONN/DDLGen.jar" ] 
then
    echo "
        Error:  Unable to find the DDLGen Binary.
                Please check that \$SYBROOT has been set correctly and
                that the file '$LIB_CONN/DDLGen.jar' exists.\n
                \$SYBROOT currently set to '$SYBROOT'\n"
                        exit 1
fi


# ... Find the JRE and set JAVA_HOME .............................
# no SYBASE_JRE6 needed for MacOSX
if [ ! $PLATFORM = Darwin ]
then

# Set JRE directory
if [ "$SYBASE_JRE6" = "" ]
then
   echo "
	Error: 	You need to set \$SYBASE_JRE6 to the directory where your Java JRE is installed."
	exit 1
fi

if [ -f "$SYBASE_JRE6/bin/java" ]
then
    PATH="${SYBASE_JRE6}/bin:$PATH"  # PATH to local JRE first
    export PATH
    export SYBASE_JRE6
else
    echo "
	Error: 	Unable to find the Java Binary.
		Please check that \$SYBROOT has been set correctly and 
		that the file '$SYBASE_JRE6/bin/java exists' exists.\n
		\$SYBROOT currently set to '$SYBROOT'\n"
    exit 1
fi

fi
# ... Start DDLGEN ...............................................

if [ $PLATFORM = AIX ]
then 	
	LIBPATH="$SYBASE_JRE6/bin:$SYBASE_JRE6/bin/classic"
	export LIBPATH
fi

# MacOSX uses built-in java
JAVA=$SYBASE_JRE6/bin/java
if [ $PLATFORM = Darwin ]
    then JAVA=java
fi

eval "$JAVA" -ms15m -mx500m -classpath "$LIB_CONN/jconn3.jar:$LIB_CONN/dsparser.jar:$LIB_CONN/DDLGen.jar" com.sybase.ddlgen.DDLGenerator $* 

# ... eof ...

