#!/bin/sh -f

#set -x
export LC_ALL=C
: ${CMTMSGPREFIX:=$0:}

lib=$1

d=`/bin/pwd`
a=`basename $d`
if test "${a}" = "shlib" ; then
  cd ..
fi

if test `uname` = "HP-UX" ; then
  mkdir -p shlib
  /bin/rm -f shlib/*

  /bin/rm -f lib${lib}.sl
  
  cd shlib
  ar x ../lib${lib}.a
#####   ld -b -a shared -o ../lib${lib}.sl `ls` $2
  aCC -Wl,-a,shared -b +Z -q -Wl,+s -Wl,+vallcompatwarnings -o ../lib${lib}.sl `ls` $2

  cd ../

  /bin/rm -rf shlib

fi

if test `uname` = "OSF1" ; then
  /bin/rm -f lib${lib}.so
  ld -expect_unresolved '*' -shared -o lib${lib}.so -all lib${lib}.a \
    $2 -rpath `/bin/pwd`
fi

if test `uname` = "Linux" ; then
if test "${cmtmsg}"; then
  echo "${CMTMSGPREFIX}" "BUILDING SHARED LIBRARY ${lib}"
fi
# ATTEMPT 2: temp for sharedlin force
#   cp lib${lib}.a lib${lib}.so

# ATTEMPT 1:
#  mkdir -p tmpShlib
#  cd tmpShlib
#  /bin/rm -f lib${lib}.so
#
#  ld -shared -o lib${lib}.so --whole-archive ../lib${lib}.a $2 -rpath `/bin/pwd`
#  mv lib${lib}.so ..
#  cd ../
#  /bin/rm -rf tmpShlib

# ATTEMPT 3: (Time consummibg but seems to work...)
# CMT should do this differently!!!!
  /bin/rm -f lib${lib}.so
  mkdir -p tmpShlib
  cd tmpShlib
  ar x ../lib${lib}.a

#  ld -shared -o lib${lib}.so `ls` $2 -rpath `/bin/pwd`
  g++ -shared `ls` $2 -o lib${lib}.so 
  mv lib${lib}.so ..
  cd ../
  /bin/rm -rf tmpShlib

fi

if test `uname` = "SunOS" ; then
  echo 'not yet implemented on SunOS'
#  objs=`ls *.o`
#  if test ! "$objs" = "" ; then
#    /bin/rm -f *.o
#  endif
#  ar x ../lib${lib}.a
#  $CILINK -o lib${lib}.so *.o $2 -lc
#  /bin/rm -f *.o
fi


