#!/bin/sh
#
# $Header: genclntsh.sh@@/main/osdo_7.3.2/pl_osdo_sosd/3 \
# Checked in on Thu Mar 14 12:04:24 PST 1996 by jboyce \
# Copyright (c) 1996, 1997, 1998, 1999 by Oracle Corporation. All Rights Reserved. \
# $
#
# set -x
# genclntsh.sh	(for Solaris 2.x)	# prerelease version 0.1
# Script to create single shared client library for OCI, Pro*C, and XA

# Modification history
#
#	25-Nov-1998	rachacos
#	use naming adapter libraries
#
#	30-Jul-1998	rachacos
#	use GS LDAP package
#
#	xx-Yyy-199z	user
#	Change, reason for change.
#
#       12-November-1997 hpiao
#       Make libcommon$$.a writable
#   
#       30-Jun-1997     jweisz
#       ADE support: if lib is symlink, copy it before doing anything
#
#	30-May-1997	mluong
#	Modify to read list of entry points from $PRODUCT/admin/shrept.lst
#
#       04-April-1997 hpiao
#       Modify for 803
#   
#	01-May-1995	dkozlows
#	File created.

listf_rdbms() {
	entryList=$ORACLE_HOME/rdbms/admin/shrept.lst
	grep -v '#' $entryList | grep rdbms | awk '{print $3}'
}

listf_precomp() {
	entryList=$ORACLE_HOME/precomp/admin/shrept.lst
	grep -v '#' $entryList | grep precomp | awk '{print $3}'
}

listf_plsql() {
	entryList=$ORACLE_HOME/plsql/admin/shrept.lst
	grep -v '#' $entryList | grep plsql | awk '{print $3}'
}

#listf_ldap() {
#	entryList=$ORACLE_HOME/ldap/admin/shrept.lst
#	grep -v '#' $entryList | grep ldap | awk '{print $3}'
#}

listf_network() {
	entryList=$ORACLE_HOME/network/admin/shrept.lst
	grep -v '#' $entryList | grep network | awk '{print $3}'
}

#
# Function used to convert lists of symbols to proper format for linker

fmt_syms() { awk '/[ \t]*#/	{next}\
				{printf " -u %s", $1}' ; }

#
# Main line starts here
#

#
# Explicit path to ensure that we're using the correct commands
PATH=/usr/bin:/usr/ccs/bin	export PATH

#
# each product MUST provide a $PRODUCT/admin/shrept.lst
#

#PRODUCTS="rdbms precomp plsql ldap network";
PRODUCTS="rdbms plsql network";
errCount=0

for product in $PRODUCTS
do
	SHREPT=$ORACLE_HOME/$product/admin/shrept.lst

	if [ ! -f $SHREPT ]; then
		echo "Error: could not locate $SHREPT file"
		errCount=1
	fi
done

if [ "$errCount" != "0" ]; then
	exit 1
fi

#
# library definitions
#

LSQL="-lsql8"

LPLSQL="-lpls8"

LMM="-lmm"
LCLIENT="-lclient8"
LCOMMON="-lcommon8"
LGENERIC="-lgeneric8"

LNLSRTL="-lnls8"

LCORE="-lcore8"

LTRACE="-ltrace8"

#LLDAP="-lldapclnt8"

LWTC="-lwtc8"

LDFLAGS="`cat ${ORACLE_HOME}/lib/ldflags`"
LNETWORK="${LDFLAGS} -ln8 -lnl8 -lnro8 ${LDFLAGS}"

#
# Create lists of symbols to pass to ld
#

SYMS_OCIC="`listf_rdbms | fmt_syms` ${LCLIENT}"
SYMS_SQL="`listf_precomp | fmt_syms` ${LSQL}"
SYMS_PLSQL="`listf_plsql | fmt_syms` ${LPLSQL}"
#SYMS_LDAP="`listf_ldap | fmt_syms` ${LLDAP}"
SYMS_NETWORK="`listf_network | fmt_syms` ${LNETWORK}"

#
# Library names and locations

CLNT_NAM=clntsh					# (short) library name
CLNT_VER=8.0					# library version number

CLNT_LNK=lib${CLNT_NAM}.so			# name of symlink to library
CLNT_LIB=${CLNT_LNK}.${CLNT_VER}		# actual library file name

#

if [ "$SRCHOME" != "" ]; then
	LIB_DIR=${SRCHOME}/rdbms/lib		# lib. destination directory
else
	LIB_DIR=${ORACLE_HOME}/lib		# lib. destination directory
fi

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


#
# Linker command and options

LD="ld -i -G -z text -L${ORACLE_HOME}/lib"	# shared library link command
LD_RUNTIME="-R${ORACLE_HOME}/lib"
LD_OPT="-h ${CLNT_LIB}"				# name inserted into library
LD_OUT="-o ${LIB_DIR}/${CLNT_LIB}"		# output specification
LD_SELF_CONTAINED="-z defs"


#
# Oracle library dependencies

DEF_ON="${ORACLE_HOME}/rdbms/lib/kpudfo.o"
SSDBED="${ORACLE_HOME}/rdbms/lib/ssdbaed.o"
NAUTAB="${ORACLE_HOME}/lib/nautab.o"
NAETAB="${ORACLE_HOME}/lib/naeet.o ${ORACLE_HOME}/lib/naect.o"
NAEDHS="${ORACLE_HOME}/lib/naedhs.o" 

OLIBS="${LCLIENT} ${LSQL} ${LNETWORK} ${LCLIENT} ${LCOMMON} ${LGENERIC} ${LMM} ${ORACLE_HOME}/rdbms/lib/xaondy.o ${LNLSRTL} ${LCORE} ${LNLSRTL} ${LCORE} ${LNLSRTL} ${LWTC} ${LNETWORK} ${LCLIENT} ${LCOMMON} ${LGENERIC} ${LTRACE} ${LNLSRTL} ${LCORE} ${LNLSRTL} ${LCORE} ${LNLSRTL}"

SYSLIBS=`cat ${ORACLE_HOME}/lib/sysliblist`" -laio -lm -lc"

# Create library

/bin/rm -f ${LIB_DIR}/${CLNT_LIB}
${LD} ${LD_RUNTIME} ${LD_OPT} ${LD_OUT} ${LD_SELF_CONTAINED} \
${DEF_ON} ${SSDBED} ${NAUTAB} ${NAETAB} ${NAEDHS} ${SYMS_SQL} \
${SYMS_PLSQL} ${SYMS_OCIC} ${SYMS_LDAP} ${SYMS_NETWORK} ${OLIBS} ${SYSLIBS}

# Create ".so" link to library

if [ "${SRCHOME}" != "" ]; then
	#
	# do nothing in development environment.  There should be a symlink
	# from $SRCHOME/oracle/lib to $SRCHOME/rdbms/lib for the output
	#

	true
else
	cd ${LIB_DIR}
	if [ -s ${CLNT_LIB} ]; then
		if [ -f ${CLNT_LNK} ]; then
		rm -f ${CLNT_LNK}
		fi
		ln -s ${CLNT_LIB} ${CLNT_LNK}
	fi
fi

exit 0
# genclntsh.sh	xx-May-1995	- d.k.
