lib-ld.m4 3.6 KB
Newer Older
1 2
# lib-ld.m4 serial 6
dnl Copyright (C) 1996-2003, 2009-2013 Free Software Foundation, Inc.
3 4 5 6 7
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

dnl Subroutines of libtool.m4,
8 9
dnl with replacements s/_*LT_PATH/AC_LIB_PROG/ and s/lt_/acl_/ to avoid
dnl collision with libtool.m4.
10

11
dnl From libtool-2.4. Sets the variable with_gnu_ld to yes or no.
12 13
AC_DEFUN([AC_LIB_PROG_LD_GNU],
[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], [acl_cv_prog_gnu_ld],
14
[# I'd rather use --version here, but apparently some GNU lds only accept -v.
15 16
case `$LD -v 2>&1 </dev/null` in
*GNU* | *'with BFD'*)
17 18
  acl_cv_prog_gnu_ld=yes
  ;;
19
*)
20 21
  acl_cv_prog_gnu_ld=no
  ;;
22 23 24 25
esac])
with_gnu_ld=$acl_cv_prog_gnu_ld
])

26
dnl From libtool-2.4. Sets the variable LD.
27
AC_DEFUN([AC_LIB_PROG_LD],
28
[AC_REQUIRE([AC_PROG_CC])dnl
29
AC_REQUIRE([AC_CANONICAL_HOST])dnl
30 31 32 33 34 35 36

AC_ARG_WITH([gnu-ld],
    [AS_HELP_STRING([--with-gnu-ld],
        [assume the C compiler uses GNU ld [default=no]])],
    [test "$withval" = no || with_gnu_ld=yes],
    [with_gnu_ld=no])dnl

37 38 39 40 41 42 43 44 45 46 47 48
# Prepare PATH_SEPARATOR.
# The user is always right.
if test "${PATH_SEPARATOR+set}" != set; then
  # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which
  # contains only /bin. Note that ksh looks also at the FPATH variable,
  # so we have to set that as well for the test.
  PATH_SEPARATOR=:
  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
    && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
           || PATH_SEPARATOR=';'
       }
fi
49

50 51 52
ac_prog=ld
if test "$GCC" = yes; then
  # Check if gcc -print-prog-name=ld gives a path.
53
  AC_MSG_CHECKING([for ld used by $CC])
54 55 56 57 58 59 60 61 62
  case $host in
  *-*-mingw*)
    # gcc leaves a trailing carriage return which upsets mingw
    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
  *)
    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
  esac
  case $ac_prog in
    # Accept absolute paths.
63 64 65 66 67
    [[\\/]]* | ?:[[\\/]]*)
      re_direlt='/[[^/]][[^/]]*/\.\./'
      # Canonicalize the pathname of ld
      ac_prog=`echo "$ac_prog"| sed 's%\\\\%/%g'`
      while echo "$ac_prog" | grep "$re_direlt" > /dev/null 2>&1; do
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
        ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"`
      done
      test -z "$LD" && LD="$ac_prog"
      ;;
  "")
    # If it fails, then pretend we aren't using GCC.
    ac_prog=ld
    ;;
  *)
    # If it is relative, then search for the first ld in PATH.
    with_gnu_ld=unknown
    ;;
  esac
elif test "$with_gnu_ld" = yes; then
  AC_MSG_CHECKING([for GNU ld])
else
  AC_MSG_CHECKING([for non-GNU ld])
fi
AC_CACHE_VAL([acl_cv_path_LD],
[if test -z "$LD"; then
88
  acl_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
89
  for ac_dir in $PATH; do
90
    IFS="$acl_save_ifs"
91 92 93 94
    test -z "$ac_dir" && ac_dir=.
    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
      acl_cv_path_LD="$ac_dir/$ac_prog"
      # Check to see if the program is GNU ld.  I'd rather use --version,
95
      # but apparently some variants of GNU ld only accept -v.
96
      # Break only if it was the GNU/non-GNU ld that we prefer.
97
      case `"$acl_cv_path_LD" -v 2>&1 </dev/null` in
98
      *GNU* | *'with BFD'*)
99 100
        test "$with_gnu_ld" != no && break
        ;;
101
      *)
102 103
        test "$with_gnu_ld" != yes && break
        ;;
104 105 106
      esac
    fi
  done
107
  IFS="$acl_save_ifs"
108 109 110 111 112 113 114 115 116 117 118 119
else
  acl_cv_path_LD="$LD" # Let the user override the test with a path.
fi])
LD="$acl_cv_path_LD"
if test -n "$LD"; then
  AC_MSG_RESULT([$LD])
else
  AC_MSG_RESULT([no])
fi
test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
AC_LIB_PROG_LD_GNU
])