#!/bin/sh

# ld replacement for programs to be checkpointed. 
#

if [ "$LSF_ENVDIR" = "" ] ; then
    if [ ! -f /etc/lsf.conf ] ; then
        echo Cannot locate lsf.conf. Please setenv LSF_ENVDIR to point to the
        echo directory where lsf.conf is.
        exit 1
    fi
fi

if [ "$LSF_ENVDIR" = "" ] ; then
    . /etc/lsf.conf
else
    . $LSF_ENVDIR/lsf.conf
fi

CKPT_CLIB=${LSF_LIBDIR}/libckpt.a
CKPT_CRT0=${LSF_LIBDIR}/ckpt_crt0.o

#
###############################################

#
# Remove explicit use of libc switch -lc
# Remove explicit use of /lib/crt0.o
#	We take the above two out mainly for f77 since we will be adding
#	the checkpoint versions back in.
#
# When using f77 the fortran 77 switch -tl,ckpt_ld switch must be used to
# force this script to be used in place of the standard /bin/ld.
#
arg=`echo "S$*" | sed "s/^S//; s/[ 	]-lc[ 	]/ /; s/[	 ]\/lib\/crt0.o[	 ]/ /"`

if [ -d /opt/SUNWspro/SC4.? ]; then
    #get the latest version of /opt/SUNWspro/SC4.?
    a="/opt/SUNWspro/SC4.?"
    sunpath=`echo $a | awk '{ print $(NF) }'`

    /usr/ccs/bin/ld -Bstatic $sunpath/lib/crti.o \
    ${CKPT_CRT0} $sunpath/lib/values-xt.o $arg ${CKPT_CLIB} \
    -Y P,$sunpath/bin/../lib:/usr/ccs/lib:/usr/lib -Qy \
    $sunpath/lib/libM77.a -lF77 -lsunmath -lm -lc \
    -lmalloc -lsocket -lnsl -lc -lintl -lc -Bdynamic -ldl -Bstatic \
    $sunpath/bin/../lib/crtn.o -z muldefs
else
    /usr/ccs/bin/ld -Bstatic /opt/SUNWspro/SC3.0/bin/../lib/crti.o \
    ${CKPT_CRT0} /opt/SUNWspro/SC3.0/bin/../lib/__fstd.o \
    /opt/SUNWspro/SC3.0/bin/../lib/values-xt.o $arg ${CKPT_CLIB} \
    -Y P,/opt/SUNWspro/SC3.0/bin/../lib:/usr/ccs/lib:/usr/lib -Qy \
    /opt/SUNWspro/SC3.0/lib/libM77.a -lF77 -lsunmath -lm -lc \
    -lmalloc -lsocket -lnsl -lc -lintl -lc -Bdynamic -ldl -Bstatic \
    /opt/SUNWspro/SC3.0/bin/../lib/crtn.o
fi
