#!/bin/sh
#
# $Id: genoccish.sh 24-jan-2007.16:51:52 mpradeep Exp $
#
# genoccish.sh
#
# Copyright (c) 2002, 2007, Oracle. All rights reserved.  
#
#    NAME
#      genoccish.sh - Generate the occi shared object
#
#    DESCRIPTION
#      Script to generate the occi shared object
#      Assumes that the .a file has already been created
#
#    MODIFIED   (MM/DD/YY)
#    mpradeep    01/24/07 - Backport mpradeep_bug-5240469 from main
#    shiyer      01/31/05 - OCCI gcc 2.96 support 
#    jboyce      10/11/04 - Remove irrelevant instantiation of soft-linked file
#    mkrohan     03/31/03 - Update version to 10.1
#    vvinay      03/05/02 - vvinay_fix2141259
#    vvinay      02/26/02 - Creation
#

ULIB="lib"
CALL32=
LDFLAGS_ARCH=

if [ "`uname -m`" = "s390x" -o "`uname -m`" = "x86_64" ] ; then
  if [ "$1" = "32" -o "$1" = "-32" -o `basename $0` = "genclntst32" ] ; then
    ULIB="lib32"
  else
    if [ -d "${ORACLE_HOME}/lib32" ] ; then
      CALL32=1
    fi
  fi

  #
  # If linking 32 bit in install environment or linking 32 bit in src environment
  #
   if [ "${ULIB}" = "lib32" ] && [ "`uname -m`" = "s390x" ] ; then
    LDFLAGS_ARCH=-m31
  elif  [ "${ULIB}" = "lib32" ] && [ "`uname -m`" = "x86_64" ] ; then
    LDFLAGS_ARCH=-m32
  else
    LDFLAGS_ARCH=-m64
  fi
fi

#
# library definitions
OLIB=${ORACLE_HOME}/${ULIB}

#
# Library names and locations
OCCI_NAM=occi                                   # (short) library name
OCCI_VER=10.1                                   # library version number
OCCI_VERS=10
OCCI_LNK=lib${OCCI_NAM}.so                      # name of symlink to library
OCCI_LIB=${OCCI_LNK}.${OCCI_VER}                # actual library file name
OCCI_ARC=lib${OCCI_NAM}${OCCI_VERS}.a
LIB_DIR=${ORACLE_HOME}/${ULIB}                  # lib. destination directory

if [ ! -z "$SRCHOME" ]
then
        LIB_DIR=${SRCHOME}/rdbms/${ULIB}        # lib. destination directory
fi


#For customers using Rel4 gcc version 3.4.5 throws errors. So they
# were recommended to use the 3.2.3 which is  installed as g++32.
if [ -f /usr/bin/g++32 ]
 then
   GCC=g++32
 else
   GCC=g++
fi 

#if using gcc 2.96 then set environment variable BUILD_CCC296 to 1 before
#running this script
if [ ! -z "${BUILD_CCC296}" ]
then
   GCC=/usr/bin/g++296
   OCCI_LIB=libocci10_296.so.10.1
   OCCI_ARC=libocci10_296.a
fi

#
# If in ADE, the library may be a symlink to the label server.  If so,
# pull it over...
# jeb: NO! We delete it later, so the copy is a waste.  
#      (And cp -p hangs on RHEL 3)

#
# Linker command and options
LD="${GCC} -Wl,-soname=${OCCI_LIB} ${LDFLAGS_ARCH} -o ${LIB_DIR}/${OCCI_LIB} -shared \
    -Wl,--whole-archive ${LIB_DIR}/${OCCI_ARC} -Wl,--no-whole-archive"

# Create library
/bin/rm -f ${LIB_DIR}/${OCCI_LIB}
${LD}

# Create ".so" link to library in a non-development environment only
if [ -z "${SRCHOME}" ]
then
        if [ -s ${LIB_DIR}/${OCCI_LIB} ]
        then
                cd ${LIB_DIR}
                rm -f ${OCCI_LNK}
                ln -s ${OCCI_LIB} ${OCCI_LNK}
        fi
fi

if [ "$CALL32" = "1" ] ; then
  ${ORACLE_HOME}/bin/genoccish 32
fi

exit 0
