#!/bin/sh
#
#  Copyright(c) 1995 Sun Microsystems, Inc.
#  All rights reserved.

#ident  "@(#)testrm  1.9  95/11/16  SMI"


# ----------------------------------------------------------------
# testrm script removes testname_info.o from the VTS shared object
# library libvtsinfo.so, and libvtsinfo.a too.
#
# Usage: testrm <testname> [<vtsinfo_directory>]
# ----------------------------------------------------------------

usage_error()
{
    echo Usage: $0 "<testname> [<vtsinfo_directory>]"
    exit
}

tname=${1}_info.o
libdir=`pwd`
lib=vtsinfo
AR=/usr/ccs/bin/ar
LD=/usr/ccs/bin/ld

#set -x

case  $# in
0)      usage_error ;;
2)	if [ -d $2 ] 
	then
	    libdir=$2
	else
	    echo "Error: "$2" is not a directory!" 
	    exit
	fi ;;
esac

for i
do case $i in
    -*) echo 'unknown flag '$i''
	usage_error ;;
   esac
done

$AR t ${libdir}/${lib}.a > /dev/null
if [ $? -ne 0 ]
then
    echo "ar error! "${lib}".a may not exist."
    exit
fi

if ($AR t ${libdir}/${lib}.a $tname > /dev/null 2>&1)
then 
    cd $libdir
    rm -rf tmp
    mkdir tmp
    cp -p ${lib}.a ${lib}.a.save
    $AR x ${lib}.a $tname
    $AR d ${lib}.a $tname
else
    echo $tname "does not exist in "$lib".a."
    exit
fi


cd tmp
$AR x ../${lib}.a		#extract all .o flies to tmp
$LD -dy -G -o ${lib}.so *.o > /dev/null 2>&1
cd ..
mv ${lib}.so ${lib}.so.save
if [ -f tmp/${lib}.so ] 
then
    cp tmp/${lib}.so .
fi
rm -rf tmp
echo $tname "was removed from ${lib}.a."
echo $1 was removed from SunVTS.
