:
# 
# Copyright (c) 1995, 2004, Oracle. All rights reserved.  
# 

#
# NAME
#   gensnalib
# DESCRIPTION
#   This is a shell script to generate a list of system libraries required
#   for linking the Oracle Transparent Gateway for DRDA. The list is added
#   to the linker argument list during the make process. The script produces
#   a file, $ORACLE_HOME/tg4drda/lib/snaliblist, which is the list of libraries
#   that are required that do not already appear in the Oracle Server list
#   in $ORACLE_HOME/rdbms/lib/sysliblist. snaliblist is 'cat'ed in the make
#   file for the gateway.
# PARAMETERS
#   Takes as input a single parameter to indicate which SNA network package
#   to use.
# RETURNS
#   Output is to file $ORACLE_HOME/tg4drda/lib/snaliblist
# NOTES
#   See case statement below for supported list
# MODIFIED
#    pcastro    09/01/04 - 
#    pcastro    07/29/02 - add Linux-SNA support
#    pcastro    02/21/02 - add TCP/IP support
#    pcastro    07/10/01 - add SNAP-IX support
#    pcastro  06/26/2001 - changed to case for matches, part of move to
#                          include all ported platforms
#    pcastro  05/06/2001 - changed parm values
#    mwhite     10/19/95 - created
#

SYSLIBNAMES=
MISSING=FALSE

# Check the parameter passed, and set up a string containing the libraries
# required to link the gateway

case "$1" in

SUNLINK8*|sunlink8*)	# [sol] SunLink SNA Peer-to-Peer V8.x
	echo "Using SunLink SNA Peer-to-Peer 8.x libraries"
	LU62LIBS="/opt/SUNWconn/lib/libcpic.a /opt/SUNWconn/lib/libappc_api.a"
	LINKLINE="-L/opt/SUNWconn/lib -lcpic -lappc_api"
	;;

SUNLINK*|sunlink*)	# [sol] SunLink SNA Peer-to-Peer V9.x
	echo "Using SunLink SNA Peer-to-Peer 9.x libraries"
	if [ -d /opt/SUNWappc ] ; then
	  LU62LIBS="/opt/SUNWappc/libsunp2p.so /opt/SUNWappc/liblu62.so"
	  LINKLINE=$LU62LIBS
	else
	  LU62LIBS="/opt/SUNWlu62/libsunp2p.so /opt/SUNWlu62/liblu62.so"
	  LINKLINE=$LU62LIBS
	fi
	;;

SNAPIX*|snapix*)	# [sol] Data Connections SNAP-IX V6
	echo "Using Data Connections SNAP-IX V6"
	LU62LIBS="/opt/sna/lib/libcpic.so /opt/sna/lib/libappc.so /opt/sna/lib/libnof.so /opt/sna/lib/libsna.so"
	LINKLINE=$LU62LIBS
	;;

AIXCOMMSERV*|aixcommserv*)	# [aix] IBM Communications Server for AIX V6
	aixver=`uname -v`
	case "$aixver" in
	4)	# AIX V4
	  echo "Using IBM Communications Server V6 for AIX V4"
	  LU62LIBS="/usr/lib/sna/cpic64.exp"
	  LINKLINE="-bI:/usr/lib/sna/cpic64.exp"
	  ;;
	5)	# AIX V5L
	  echo "Using IBM Communications Server V6 for AIX V5L"
	  LU62LIBS="/usr/lib/sna/cpic64_5.exp"
	  LINKLINE="-bI:/usr/lib/sna/cpic64_5.exp"
	  ;;
	*)	# default case, no support
	  echo "Unsupported version ($aixver) of AIX."
	  exit 16
	  ;;
	esac
	;;

HPUXSNAPLUS2*|hpuxsnaplus2*)	# [hpux] SNAplus2 R6
	echo "Using SNAplus2 R6"
	LU62LIBS="/opt/sna/lib/pa20_64/libcpic.sl /opt/sna/lib/pa20_64/libsna.sl"
	LINKLINE="-L/opt/sna/lib/pa20_64 -lcpic -lsna"
	;;

LINUXCOMMSERV*|linuxcommserv*)	# [linux] IBM Communications Server V6
	echo "Using IBM Communications Server V6 for Linux"
	LU62LIBS="/opt/ibm/sna/lib/libcpic.so /opt/ibm/sna/lib/libappc.so /opt/ibm/sna/lib/libsna.so /opt/ibm/sna/lib/libnof.so"
	LINKLINE="-L/opt/ibm/sna/lib -lcpic -lappc -lsna -lnof -Wl,-rpath,/opt/ibm/sna/lib"
	for f in /opt/ibm/sna/lib /usr/local/lib /usr/lib
	do
	 if [ -f $f/libpLiS.so ]; then
	   LU62LIBS="$LU62LIBS $f/libpLiS.so"
	   LINKLINE="$LINKLINE -L$f -lpLiS -Wl,-rpath,$f"
           break;
	 fi
	done
	;;

LINUXSNA|LINUX-SNA|linuxsna|linux-sna)	# [linux] Linux-SNA Project
	echo "Using Linux-SNA"
	# check a few places
	for f in /usr/local/sna/lib /usr/local/lib /var/lib /opt/lib /usr/sna/lib /usr/lib /lib
	do
	 if [ -f $f/libcpic.so ]; then
	   LU62LIBS="$f/libcpic.so"
	   LINKLINE="-L$f -lcpic"
	 fi
	done
	;;

TCPIP|tcpip)	# TCP/IP is built in
	echo "Using TCP/IP"
	LU62LIBS=""
	LINKLINE=""
	;;

*)		# default case, no support
	echo "Unsupported version ($1) passed to $0."
	exit 16
	;;
esac

# Loop through all the libraries, and make sure that they exist. If any are
# not found, set MISSING to TRUE.

for slib in $LU62LIBS
do

   if [ "`echo $slib | grep '^/'`" = "" ]; then # first char different from /

      if [ ! -f /lib/lib${slib}.a -a ! -f /usr/lib/lib${slib}.a \
	   -a ! -f /usr/lib/lib${slib}.so -a ! -f /lib/lib${slib}.so ]; then
         echo ""
         echo "Cannot locate /lib/lib${slib}.{a,so} nor /usr/lib/lib${slib}.{a,so}."
         MISSING=TRUE
      fi
   else	    # if library name starts with "/", it is a full pathname
      if [ ! -f $slib ] ; then
         echo "Cannot locate $slib."
	 MISSING=TRUE
      fi
   fi

done

# Now check to be sure that all required libraries were found. If any were not
# found, MISSING will be TRUE, and messages are issued.

if [ "$MISSING" = "TRUE" ]; then
  echo "Gateway server installation failed due to missing libraries."
  echo "Check that the required SNA software is installed properly."
  exit 16
fi

# All libraries were found. Create the $ORACLE_HOME/tg4drda/lib/snaliblist
# file with all the libraries listed.

cat <<! >$ORACLE_HOME/tg4drda/lib/snaliblist
$LINKLINE
!
