# 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 2>/dev/null`
    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

tmp=
if test "$GNULDused" = "yes"; then
  case "$osname" in
    cygwin|mingw) tmp=--enable-auto-import ;; # PE does not support --export-dynamic
    *) tmp=--export-dynamic ;;
  esac
else
  case "$osname-$arch" in
    aix-*)  tmp=-brtl ;; # in case we link against a shared library
    hpux-*) tmp=-E ;;
  esac
fi
case "$osname" in
  darwin) tmp="$tmp -search_paths_first";;
esac

if test -n "$tmp"; then
  tmp=`./ldflags "$LDneedsWl" $tmp`
  ldflags="$ldflags $tmp"
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
