#!/bin/sh
#
# $Id: genoccish.sh 20-feb-2007.10:22:12 mlfallon 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)
#    jboyce      02/13/08 - 10->11
#    mlfallon    02/20/07 - adding libipgo.a
#    jboyce      09/21/06 - #5551059: fix typo: -m31 -> -m32
#    pmagapu     12/27/05 - 4765143: Check if g++ is in the path (3403600) 
#    shiyer      09/26/05 - #4586893:add libirc
#    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" ] ; 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" ] || [ -n "${SRCHOME}" -a -z "$BUILD64" ] ; 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=11.1                                   # library version number
OCCI_VERS=11
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


#if using gcc 2.96 then set environment variable BUILD_CCC296 to 1 before
#running this script

GPLUSPLUS=`/usr/bin/which g++ 2>&1`

if [ ! -z "${BUILD_CCC296}" ]
then
   GPLUSPLUS=/usr/bin/g++296
   OCCI_LIB=libocci11_296.so.11.1
   OCCI_ARC=libocci11_296.a
fi

SYSLIBLIST="-lirc -lipgo"

[ ! -f "${GPLUSPLUS}" ] && echo "libocci.so.11.1 not regenerated. g++ not found" && exit;

#
# 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="${GPLUSPLUS} -Wl,-soname=${OCCI_LIB} ${LDFLAGS_ARCH} -o ${LIB_DIR}/${OCCI_LIB} -shared \
    -Wl,--whole-archive ${LIB_DIR}/${OCCI_ARC} -L${OLIB} -Wl,--no-whole-archive ${SYSLIBLIST}"

# 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
