#!/bin/sh
#
#   Copyright (c) International Business Machines  Corp., 2000
#
#   This program is free software;  you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
#   the GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this pronram;  if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
#
#  FILE   : ldd01
#
#  PURPOSE: To test the basic functionality of the `ldd` command.
#
#  HISTORY:
#    06/01 Robbie Williamson (robbiew@us.ibm.com)
#     -Ported
#
#
#---------------------------------------------------------------------------
#Uncomment line below for debug output
#trace_logic=${trace_logic:-"set -x"}
$trace_logic

TCdat=${TCdat:-`pwd`}
TCtmp=${TCtmp:-/tmp/ldd01-$$}

do_cleanup()
{
rm -rf $TCtmp
}

do_setup()
{
mkdir $TCtmp

# Check for ppc64 architecture
file lddfile1.o | grep PowerPC | grep 64-bit >/dev/null 2>&1
if [ $? -eq 0 ]; then
  cc -m64 -shared -o $TCtmp/lddfile1.o.so $TCdat/lddfile1.o
  cc -m64 -shared -o $TCtmp/lddfile2.o.so $TCdat/lddfile2.o
  cc -m64 -shared -o $TCtmp/lddfile3.o.so $TCdat/lddfile3.o
  cc -m64 -shared -o $TCtmp/lddfile4.o.so $TCdat/lddfile4.o
  cc -m64 -shared -o $TCtmp/lddfile5.o.so $TCdat/lddfile5.o
  cc -m64 -O -o $TCtmp/a.out $TCtmp/lddfile*.o.so $TCdat/main.o
else
  cc -shared -o $TCtmp/lddfile1.o.so $TCdat/lddfile1.o
  cc -shared -o $TCtmp/lddfile2.o.so $TCdat/lddfile2.o
  cc -shared -o $TCtmp/lddfile3.o.so $TCdat/lddfile3.o
  cc -shared -o $TCtmp/lddfile4.o.so $TCdat/lddfile4.o
  cc -shared -o $TCtmp/lddfile5.o.so $TCdat/lddfile5.o
  cc -O -o $TCtmp/a.out $TCtmp/lddfile*.o.so $TCdat/main.o
fi
} 

do_test()
{
echo "  ASSERTION 1  "

ldd $TCtmp/a.out | grep -E "lddfile1.o.so|lddfile2.o.so|lddfile3.o.so|lddfile4.o.so|lddfile5.o.so" 
if [ $? -eq 0 ]
then
	echo "ASSERTION #1 PASS"
else
	echo "ASSERTION #1 FAIL"
	do_cleanup
	return 1
fi

echo " ASSERTION 2  "

ldd -v $TCtmp/a.out | grep -E "GLIBC|lddfile1.o.so|lddfile2.o.so|lddfile3.o.so|lddfile4.o.so|lddfile5.o.so" 
if [ $? -eq 0 ]
then
	echo "ASSERTION #2 PASS"
else
	echo "ASSERTION #2 FAIL"
	do_cleanup
	return 1
fi

echo "TEST PASSES"
do_cleanup
return 0

}
do_setup
do_test
