Blame m4/lib-ld.m4

Packit 33f14e
# lib-ld.m4 serial 7
Packit 33f14e
dnl Copyright (C) 1996-2003, 2009-2017 Free Software Foundation, Inc.
Packit 33f14e
dnl This file is free software; the Free Software Foundation
Packit 33f14e
dnl gives unlimited permission to copy and/or distribute it,
Packit 33f14e
dnl with or without modifications, as long as this notice is preserved.
Packit 33f14e
Packit 33f14e
dnl Subroutines of libtool.m4,
Packit 33f14e
dnl with replacements s/_*LT_PATH/AC_LIB_PROG/ and s/lt_/acl_/ to avoid
Packit 33f14e
dnl collision with libtool.m4.
Packit 33f14e
Packit 33f14e
dnl From libtool-2.4. Sets the variable with_gnu_ld to yes or no.
Packit 33f14e
AC_DEFUN([AC_LIB_PROG_LD_GNU],
Packit 33f14e
[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], [acl_cv_prog_gnu_ld],
Packit 33f14e
[# I'd rather use --version here, but apparently some GNU lds only accept -v.
Packit 33f14e
case `$LD -v 2>&1 
Packit 33f14e
*GNU* | *'with BFD'*)
Packit 33f14e
  acl_cv_prog_gnu_ld=yes
Packit 33f14e
  ;;
Packit 33f14e
*)
Packit 33f14e
  acl_cv_prog_gnu_ld=no
Packit 33f14e
  ;;
Packit 33f14e
esac])
Packit 33f14e
with_gnu_ld=$acl_cv_prog_gnu_ld
Packit 33f14e
])
Packit 33f14e
Packit 33f14e
dnl From libtool-2.4. Sets the variable LD.
Packit 33f14e
AC_DEFUN([AC_LIB_PROG_LD],
Packit 33f14e
[AC_REQUIRE([AC_PROG_CC])dnl
Packit 33f14e
AC_REQUIRE([AC_CANONICAL_HOST])dnl
Packit 33f14e
Packit 33f14e
AC_ARG_WITH([gnu-ld],
Packit 33f14e
    [AS_HELP_STRING([--with-gnu-ld],
Packit 33f14e
        [assume the C compiler uses GNU ld [default=no]])],
Packit 33f14e
    [test "$withval" = no || with_gnu_ld=yes],
Packit 33f14e
    [with_gnu_ld=no])dnl
Packit 33f14e
Packit 33f14e
# Prepare PATH_SEPARATOR.
Packit 33f14e
# The user is always right.
Packit 33f14e
if test "${PATH_SEPARATOR+set}" != set; then
Packit 33f14e
  # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which
Packit 33f14e
  # contains only /bin. Note that ksh looks also at the FPATH variable,
Packit 33f14e
  # so we have to set that as well for the test.
Packit 33f14e
  PATH_SEPARATOR=:
Packit 33f14e
  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
Packit 33f14e
    && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
Packit 33f14e
           || PATH_SEPARATOR=';'
Packit 33f14e
       }
Packit 33f14e
fi
Packit 33f14e
Packit 33f14e
if test -n "$LD"; then
Packit 33f14e
  AC_MSG_CHECKING([for ld])
Packit 33f14e
elif test "$GCC" = yes; then
Packit 33f14e
  AC_MSG_CHECKING([for ld used by $CC])
Packit 33f14e
elif test "$with_gnu_ld" = yes; then
Packit 33f14e
  AC_MSG_CHECKING([for GNU ld])
Packit 33f14e
else
Packit 33f14e
  AC_MSG_CHECKING([for non-GNU ld])
Packit 33f14e
fi
Packit 33f14e
if test -n "$LD"; then
Packit 33f14e
  # Let the user override the test with a path.
Packit 33f14e
  :
Packit 33f14e
else
Packit 33f14e
  AC_CACHE_VAL([acl_cv_path_LD],
Packit 33f14e
  [
Packit 33f14e
    acl_cv_path_LD= # Final result of this test
Packit 33f14e
    ac_prog=ld # Program to search in $PATH
Packit 33f14e
    if test "$GCC" = yes; then
Packit 33f14e
      # Check if gcc -print-prog-name=ld gives a path.
Packit 33f14e
      case $host in
Packit 33f14e
        *-*-mingw*)
Packit 33f14e
          # gcc leaves a trailing carriage return which upsets mingw
Packit 33f14e
          acl_output=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
Packit 33f14e
        *)
Packit 33f14e
          acl_output=`($CC -print-prog-name=ld) 2>&5` ;;
Packit 33f14e
      esac
Packit 33f14e
      case $acl_output in
Packit 33f14e
        # Accept absolute paths.
Packit 33f14e
        [[\\/]]* | ?:[[\\/]]*)
Packit 33f14e
          re_direlt='/[[^/]][[^/]]*/\.\./'
Packit 33f14e
          # Canonicalize the pathname of ld
Packit 33f14e
          acl_output=`echo "$acl_output" | sed 's%\\\\%/%g'`
Packit 33f14e
          while echo "$acl_output" | grep "$re_direlt" > /dev/null 2>&1; do
Packit 33f14e
            acl_output=`echo $acl_output | sed "s%$re_direlt%/%"`
Packit 33f14e
          done
Packit 33f14e
          # Got the pathname. No search in PATH is needed.
Packit 33f14e
          acl_cv_path_LD="$acl_output"
Packit 33f14e
          ac_prog=
Packit 33f14e
          ;;
Packit 33f14e
        "")
Packit 33f14e
          # If it fails, then pretend we aren't using GCC.
Packit 33f14e
          ;;
Packit 33f14e
        *)
Packit 33f14e
          # If it is relative, then search for the first ld in PATH.
Packit 33f14e
          with_gnu_ld=unknown
Packit 33f14e
          ;;
Packit 33f14e
      esac
Packit 33f14e
    fi
Packit 33f14e
    if test -n "$ac_prog"; then
Packit 33f14e
      # Search for $ac_prog in $PATH.
Packit 33f14e
      acl_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
Packit 33f14e
      for ac_dir in $PATH; do
Packit 33f14e
        IFS="$acl_save_ifs"
Packit 33f14e
        test -z "$ac_dir" && ac_dir=.
Packit 33f14e
        if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
Packit 33f14e
          acl_cv_path_LD="$ac_dir/$ac_prog"
Packit 33f14e
          # Check to see if the program is GNU ld.  I'd rather use --version,
Packit 33f14e
          # but apparently some variants of GNU ld only accept -v.
Packit 33f14e
          # Break only if it was the GNU/non-GNU ld that we prefer.
Packit 33f14e
          case `"$acl_cv_path_LD" -v 2>&1 
Packit 33f14e
            *GNU* | *'with BFD'*)
Packit 33f14e
              test "$with_gnu_ld" != no && break
Packit 33f14e
              ;;
Packit 33f14e
            *)
Packit 33f14e
              test "$with_gnu_ld" != yes && break
Packit 33f14e
              ;;
Packit 33f14e
          esac
Packit 33f14e
        fi
Packit 33f14e
      done
Packit 33f14e
      IFS="$acl_save_ifs"
Packit 33f14e
    fi
Packit 33f14e
    case $host in
Packit 33f14e
      *-*-aix*)
Packit 33f14e
        AC_EGREP_CPP([yes],
Packit 33f14e
          [#if defined __powerpc64__ || defined _ARCH_PPC64
Packit 33f14e
           yes
Packit 33f14e
           #endif
Packit 33f14e
          ],
Packit 33f14e
          [# The compiler produces 64-bit code. Add option '-b64' so that the
Packit 33f14e
           # linker groks 64-bit object files.
Packit 33f14e
           case "$acl_cv_path_LD " in
Packit 33f14e
             *" -b64 "*) ;;
Packit 33f14e
             *) acl_cv_path_LD="$acl_cv_path_LD -b64" ;;
Packit 33f14e
           esac
Packit 33f14e
          ], [])
Packit 33f14e
        ;;
Packit 33f14e
    esac
Packit 33f14e
  ])
Packit 33f14e
  LD="$acl_cv_path_LD"
Packit 33f14e
fi
Packit 33f14e
if test -n "$LD"; then
Packit 33f14e
  AC_MSG_RESULT([$LD])
Packit 33f14e
else
Packit 33f14e
  AC_MSG_RESULT([no])
Packit 33f14e
  AC_MSG_ERROR([no acceptable ld found in \$PATH])
Packit 33f14e
fi
Packit 33f14e
AC_LIB_PROG_LD_GNU
Packit 33f14e
])