#! /bin/sh -f

args=''
outfile=''
ofiles=''
libdirs=''
nolibs='n'

die () {
  echo "$1" >&2
  exit 1
}

for arg in ` echo "$LIBRARY_PATH" | tr : ' ' `
do
  libdirs="$libdirs '-L$arg'"
done

while [ $# -gt 0 ]
do
  case "$1" in
  -o)
    shift
    test $# -gt 0 || die "missing arg for -o"
    outfile="$1"
    ;;
  *.o | *.o0)
    ofiles="$ofiles '$1'"
    args="$args '$1'"
    ;;
  -L*)
    libdirs="$libdirs '$1'"
    ;;
  -nolibs)
    nolibs='y'
    ;;
  -l*)
    test "$nolibs" = n && args="$args '$1'"
    ;;
  *)
    args="$args '$1'"
    ;;
  esac
  shift
done

test "X$ofiles"  != X || die "no input files"
test "X$outfile" != X || die "no output file"

outfile=` echo "$outfile" | sed -e 's/\.\(so\|o\)$//' `'.@SOEXT@'

ldcmd="@SHARED_CC@ @PICFLAGS@ @LDSOFLAGS@ @DLFLAGS@ $libdirs @LDFLAGS@ -o $outfile \
 $args" # @LIBS@

echo "$ldcmd"
eval "$ldcmd" || exit

# for HP-UX
chmod 555 "$outfile"
