#!/bin/sh
:	'(c) Copyright	Empress Software Inc.	1983, 2000'

if test "$EMPRESSPATH" = "" 
then
	echo "EMPRESSPATH not set"
	exit 1

elif test ! -d $EMPRESSPATH
then
	echo "invalid EMPRESSPATH"
	exit 1
fi

. $EMPRESSPATH/config/options

USAGE="*** Usage ***  $0 : list_of_libraries list_of_library_paths"

case $# in
 2)	LIBLIST=$1
	LIBPATHLIST=$2
	;;
 *)
	echo "$USAGE"
	exit 1
	;;
esac

#
# In the case of IRIX n32 we don't want to pass in the lib path. West
# want the system to figure it out for us. 
#
case "$LIBPATHLIST" in
	"")
		echo $LIBLIST
		exit 0;
	;;
esac


$EMPRESSPATH/common/sys_bin/echon

test "$MSTMPDIR" = "" && MSTMPDIR=$TMPDIR
test "$MSTMPDIR" = "" && MSTMPDIR=/tmp

TRUE=yes
FALSE=no
TMP=$MSTMPDIR/temp$$

IFS=" "
SYSLIBLIST=

for J in $LIBLIST
do
  case $J in
    -l*)
	TEMP=`echo "$J" | sed -e "s/-l\(.*\)/\1/"`

	case "$MSSYS_PLATFORM" in
	  SYS_OS_UNIX_QNX)	FILENAME=${TEMP}3r	;;
	  *)			FILENAME=lib${TEMP}	;;
	esac
	IFS=":"
	for I in $LIBPATHLIST
	do
		case "$MSSYS_PLATFORM" in
		  SYS_OS_UNIX_QNX)
			ONE_OR_MORE_FILES=`(ls $I/$FILENAME.lib 2> /dev/null)`
			;;
		  *)
			ONE_OR_MORE_FILES=`(ls $I/$FILENAME.[sa]* 2> /dev/null)`
			;;
		esac

		case $ONE_OR_MORE_FILES in
		   "")	;;
		   *)	SYSLIBLIST="${SYSLIBLIST} ${MSSYS_CCLIBDIROPT}${I} ${J}"
			break
			;;
		esac
	done

	IFS="
"
	;;
    /*)
	FILENAME=`echo "$J" | sed -e "s/.*\/\(.*\)/\1/"`
	if test -f $J
	then
		SYSLIBLIST="${SYSLIBLIST} ${J}"
	fi
	;;
    *)
	continue
	;;
  esac

done

IFS="
"

echo $SYSLIBLIST
exit 0
