# Which Executable Linker ?
#
_ld_list='LD LDFLAGS LIBS runpathprexix LDneedsWl LDused GNULDused'
case "$osname" in
  darwin) LIBS= ;;
  osf1)   LIBS='-lm -lots';;
  *)      LIBS=-lm;;
esac

if test -z "$LD"; then LD=$CC; fi

if test "$fastread" != yes; then
  echo $n ..."Which linker for building executables ? $c"
  dflt=$LD; rep=; . ./myread
  LD=$ans
fi
LDused=$LD

# Which Flags for Executable Linker?
ldflags=
GNULDused=
if test "$LD" = "$CC"; then
  ldflags=$CFLAGS
  if test -n "$__gnuc__"; then
    LDused=`$CC -print-prog-name=ld`
    LDneedsWl=yes
  else
    if test "$osname" = hpux; then LDneedsWl=yes; fi
  fi
fi
if ($LDused -v 2>&1 | grep GNU > /dev/null); then GNULDused=yes; fi

if test "$GNULDused" = "yes"; then
  tmp=`./ldflags "$LDneedsWl" "--export-dynamic"`
  ldflags="$ldflags $tmp"
else
  case "$osname-$arch" in
    aix-*) ldflags='-brtl' ;; # in case we link against a shared library
    hpux-*) ldflags='-Wl,-E' ;;
  esac
fi
case "$osname-$arch" in
  os2-*)  ldflags="$ldflags -Zexe"
          if test "$optimization" = "full"; then ldflags="$ldflags -s"; fi
esac

LDFLAGS="$ldflags $LDFLAGS"

if test "$fastread" != yes; then
  echo $n ..."With which flags ? $c"
  dflt=$LDFLAGS; rep=; . ./myread
  LDFLAGS=$ans
fi

echo "Executable linker is   $LD  $LDFLAGS"

if test "$GNULDused" = yes; then
  runpathprefix='-rpath '
else # guess...
  case "$osname" in
    gnu|osf1|linux|cygwin*|freebsd|netbsd) runpathprefix='-rpath ' ;;
    solaris) runpathprefix='-R ' ;;
    hpux) runpathprefix='+b ' ;;
    aix) runpathprefix='-blibpath:' ;;
  esac
fi
