#!/bin/sh
#
# $Id: genoccish.sh /aix64/2 2009/09/11 06:12:57 akaimale Exp $
#
# genoccish.sh
#
# Copyright (c) 2002, 2009, Oracle and/or its affiliates. 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)
#    akaimale    09/11/09 - Generate shared archive on AIX
#    spattnay    12/05/08 - Clean up 32bit reference
#    akaimale    09/13/07 - Add default path for xlC in PATH
#    jboyce      02/13/08 - 10->11
#    spattnay    03/08/07 - Bugz#21162
#    spattnay    03/01/07 - Bugz#21064
#    ppallapo    03/10/06 - exit gracefully if xlC is not installed
#    ppallapo    08/11/04 - Exit if the static library does not exist 
#    ppallapo    03/05/15 - Remove -h option 
#    mkrohan     03/31/03 - Update version to 10.1
#    sawadhwa    03/28/02 - AIX-specific changes.
#    vvinay      03/05/02 - vvinay_fix2141259
#    vvinay      02/26/02 - Creation
#

#Below has been commented to clean up 32bit reference
#if [ "$1" = "-32" ] ; then
#    LIB=lib32
#    LOOP="DONE"
#    OBJECT_MODE=32
#else
#    LIB=lib
#    # Set object mode in customer environment
#    [ -z "${SRCHOME}" ] && OBJECT_MODE=64
#fi

LIB=lib
# Set object mode in customer environment
[ -z "${SRCHOME}" ] && OBJECT_MODE=64
export OBJECT_MODE

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

#
# 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}.a                       # name of symlink to library
OCCI_ARC=lib${OCCI_NAM}${OCCI_VERS}.a
OCCI_LIB=lib${OCCI_NAM}.so
LIB_DIR=${ORACLE_HOME}/${LIB}                   # lib. destination directory

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

SHARED_OBJ=${LIB_DIR}/shr.o                     # shared obj for library

PATH=/usr/vacpp/bin:${PATH}
export PATH

if [ -f /usr/local/packages/vac/usr/vacpp/bin/xlC ]; then
   XLC=/usr/local/packages/vac/usr/vacpp/bin/xlC
else
   XLC=`/usr/bin/which xlC 2>&1`
fi

#exit from script if xlC is not present
[ ! -f "${XLC}" ] && echo "libocci.so.11.1 not regenerated. xlC not found" && exit;

#
# If in ADE, the library may be a symlink to the label server.  If so,
# pull it over...
if [ -h ${LIB_DIR}/${OCCI_LIB} ]
then
        echo "Copying ${OCCI_LIB} to local disk"
        cp -p ${LIB_DIR}/${OCCI_LIB} ${LIB_DIR}/${OCCI_LIB}.tmp
        rm -f ${LIB_DIR}/${OCCI_LIB}
        mv ${LIB_DIR}/${OCCI_LIB}.tmp ${LIB_DIR}/${OCCI_LIB}
        chmod +w ${LIB_DIR}/${OCCI_LIB}
fi


# Exit if the static library does not exist
if [ ! -s ${LIB_DIR}/${OCCI_ARC} ]
then
  exit 0
fi

#
# Linker command and options
LD_RTL="${XLC} -qmkshrobj -o ${LIB_DIR}/${OCCI_LIB} ${LIB_DIR}/${OCCI_ARC} \
    -L${OLIB} -L${LIB_DIR} -lclntsh -brtl"
LD_NORTL="${XLC} -qmkshrobj -o ${SHARED_OBJ} ${LIB_DIR}/${OCCI_ARC} \
    -L${OLIB} -L${LIB_DIR} -lclntsh"   

# Create library
/bin/rm -f ${LIB_DIR}/${OCCI_LIB} ${LIB_DIR}/${OCCI_LNK} ${SHARED_OBJ}
${LD_RTL}
${LD_NORTL}
cd ${LIB_DIR}
ar crl ${LIB_DIR}/${OCCI_LNK} ${SHARED_OBJ}
/bin/rm -f ${SHARED_OBJ}


#Below has been commented to clean up 32bit reference
# Create 32bit library
#if [ -z "${SRCHOME}" -a -d ${ORACLE_HOME}/lib32 -a "$LOOP" != "DONE" ]
#then
#    ${ORACLE_HOME}/bin/genoccish -32
#fi
exit 0
