Blame m4/lib-ld.m4

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