1*eda14cbcSMatt Macy# lib-ld.m4 serial 9 2*eda14cbcSMatt Macydnl Copyright (C) 1996-2003, 2009-2019 Free Software Foundation, Inc. 3*eda14cbcSMatt Macydnl This file is free software; the Free Software Foundation 4*eda14cbcSMatt Macydnl gives unlimited permission to copy and/or distribute it, 5*eda14cbcSMatt Macydnl with or without modifications, as long as this notice is preserved. 6*eda14cbcSMatt Macy 7*eda14cbcSMatt Macydnl Subroutines of libtool.m4, 8*eda14cbcSMatt Macydnl with replacements s/_*LT_PATH/AC_LIB_PROG/ and s/lt_/acl_/ to avoid 9*eda14cbcSMatt Macydnl collision with libtool.m4. 10*eda14cbcSMatt Macy 11*eda14cbcSMatt Macydnl From libtool-2.4. Sets the variable with_gnu_ld to yes or no. 12*eda14cbcSMatt MacyAC_DEFUN([AC_LIB_PROG_LD_GNU], 13*eda14cbcSMatt Macy[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], [acl_cv_prog_gnu_ld], 14*eda14cbcSMatt Macy[# I'd rather use --version here, but apparently some GNU lds only accept -v. 15*eda14cbcSMatt Macycase `$LD -v 2>&1 </dev/null` in 16*eda14cbcSMatt Macy*GNU* | *'with BFD'*) 17*eda14cbcSMatt Macy acl_cv_prog_gnu_ld=yes 18*eda14cbcSMatt Macy ;; 19*eda14cbcSMatt Macy*) 20*eda14cbcSMatt Macy acl_cv_prog_gnu_ld=no 21*eda14cbcSMatt Macy ;; 22*eda14cbcSMatt Macyesac]) 23*eda14cbcSMatt Macywith_gnu_ld=$acl_cv_prog_gnu_ld 24*eda14cbcSMatt Macy]) 25*eda14cbcSMatt Macy 26*eda14cbcSMatt Macydnl From libtool-2.4. Sets the variable LD. 27*eda14cbcSMatt MacyAC_DEFUN([AC_LIB_PROG_LD], 28*eda14cbcSMatt Macy[AC_REQUIRE([AC_PROG_CC])dnl 29*eda14cbcSMatt MacyAC_REQUIRE([AC_CANONICAL_HOST])dnl 30*eda14cbcSMatt Macy 31*eda14cbcSMatt MacyAC_ARG_WITH([gnu-ld], 32*eda14cbcSMatt Macy [AS_HELP_STRING([--with-gnu-ld], 33*eda14cbcSMatt Macy [assume the C compiler uses GNU ld [default=no]])], 34*eda14cbcSMatt Macy [test "$withval" = no || with_gnu_ld=yes], 35*eda14cbcSMatt Macy [with_gnu_ld=no])dnl 36*eda14cbcSMatt Macy 37*eda14cbcSMatt Macy# Prepare PATH_SEPARATOR. 38*eda14cbcSMatt Macy# The user is always right. 39*eda14cbcSMatt Macyif test "${PATH_SEPARATOR+set}" != set; then 40*eda14cbcSMatt Macy # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which 41*eda14cbcSMatt Macy # contains only /bin. Note that ksh looks also at the FPATH variable, 42*eda14cbcSMatt Macy # so we have to set that as well for the test. 43*eda14cbcSMatt Macy PATH_SEPARATOR=: 44*eda14cbcSMatt Macy (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \ 45*eda14cbcSMatt Macy && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \ 46*eda14cbcSMatt Macy || PATH_SEPARATOR=';' 47*eda14cbcSMatt Macy } 48*eda14cbcSMatt Macyfi 49*eda14cbcSMatt Macy 50*eda14cbcSMatt Macyif test -n "$LD"; then 51*eda14cbcSMatt Macy AC_MSG_CHECKING([for ld]) 52*eda14cbcSMatt Macyelif test "$GCC" = yes; then 53*eda14cbcSMatt Macy AC_MSG_CHECKING([for ld used by $CC]) 54*eda14cbcSMatt Macyelif test "$with_gnu_ld" = yes; then 55*eda14cbcSMatt Macy AC_MSG_CHECKING([for GNU ld]) 56*eda14cbcSMatt Macyelse 57*eda14cbcSMatt Macy AC_MSG_CHECKING([for non-GNU ld]) 58*eda14cbcSMatt Macyfi 59*eda14cbcSMatt Macyif test -n "$LD"; then 60*eda14cbcSMatt Macy # Let the user override the test with a path. 61*eda14cbcSMatt Macy : 62*eda14cbcSMatt Macyelse 63*eda14cbcSMatt Macy AC_CACHE_VAL([acl_cv_path_LD], 64*eda14cbcSMatt Macy [ 65*eda14cbcSMatt Macy acl_cv_path_LD= # Final result of this test 66*eda14cbcSMatt Macy ac_prog=ld # Program to search in $PATH 67*eda14cbcSMatt Macy if test "$GCC" = yes; then 68*eda14cbcSMatt Macy # Check if gcc -print-prog-name=ld gives a path. 69*eda14cbcSMatt Macy case $host in 70*eda14cbcSMatt Macy *-*-mingw*) 71*eda14cbcSMatt Macy # gcc leaves a trailing carriage return which upsets mingw 72*eda14cbcSMatt Macy acl_output=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; 73*eda14cbcSMatt Macy *) 74*eda14cbcSMatt Macy acl_output=`($CC -print-prog-name=ld) 2>&5` ;; 75*eda14cbcSMatt Macy esac 76*eda14cbcSMatt Macy case $acl_output in 77*eda14cbcSMatt Macy # Accept absolute paths. 78*eda14cbcSMatt Macy [[\\/]]* | ?:[[\\/]]*) 79*eda14cbcSMatt Macy re_direlt='/[[^/]][[^/]]*/\.\./' 80*eda14cbcSMatt Macy # Canonicalize the pathname of ld 81*eda14cbcSMatt Macy acl_output=`echo "$acl_output" | sed 's%\\\\%/%g'` 82*eda14cbcSMatt Macy while echo "$acl_output" | grep "$re_direlt" > /dev/null 2>&1; do 83*eda14cbcSMatt Macy acl_output=`echo $acl_output | sed "s%$re_direlt%/%"` 84*eda14cbcSMatt Macy done 85*eda14cbcSMatt Macy # Got the pathname. No search in PATH is needed. 86*eda14cbcSMatt Macy acl_cv_path_LD="$acl_output" 87*eda14cbcSMatt Macy ac_prog= 88*eda14cbcSMatt Macy ;; 89*eda14cbcSMatt Macy "") 90*eda14cbcSMatt Macy # If it fails, then pretend we aren't using GCC. 91*eda14cbcSMatt Macy ;; 92*eda14cbcSMatt Macy *) 93*eda14cbcSMatt Macy # If it is relative, then search for the first ld in PATH. 94*eda14cbcSMatt Macy with_gnu_ld=unknown 95*eda14cbcSMatt Macy ;; 96*eda14cbcSMatt Macy esac 97*eda14cbcSMatt Macy fi 98*eda14cbcSMatt Macy if test -n "$ac_prog"; then 99*eda14cbcSMatt Macy # Search for $ac_prog in $PATH. 100*eda14cbcSMatt Macy acl_save_ifs="$IFS"; IFS=$PATH_SEPARATOR 101*eda14cbcSMatt Macy for ac_dir in $PATH; do 102*eda14cbcSMatt Macy IFS="$acl_save_ifs" 103*eda14cbcSMatt Macy test -z "$ac_dir" && ac_dir=. 104*eda14cbcSMatt Macy if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then 105*eda14cbcSMatt Macy acl_cv_path_LD="$ac_dir/$ac_prog" 106*eda14cbcSMatt Macy # Check to see if the program is GNU ld. I'd rather use --version, 107*eda14cbcSMatt Macy # but apparently some variants of GNU ld only accept -v. 108*eda14cbcSMatt Macy # Break only if it was the GNU/non-GNU ld that we prefer. 109*eda14cbcSMatt Macy case `"$acl_cv_path_LD" -v 2>&1 </dev/null` in 110*eda14cbcSMatt Macy *GNU* | *'with BFD'*) 111*eda14cbcSMatt Macy test "$with_gnu_ld" != no && break 112*eda14cbcSMatt Macy ;; 113*eda14cbcSMatt Macy *) 114*eda14cbcSMatt Macy test "$with_gnu_ld" != yes && break 115*eda14cbcSMatt Macy ;; 116*eda14cbcSMatt Macy esac 117*eda14cbcSMatt Macy fi 118*eda14cbcSMatt Macy done 119*eda14cbcSMatt Macy IFS="$acl_save_ifs" 120*eda14cbcSMatt Macy fi 121*eda14cbcSMatt Macy case $host in 122*eda14cbcSMatt Macy *-*-aix*) 123*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 124*eda14cbcSMatt Macy [AC_LANG_SOURCE( 125*eda14cbcSMatt Macy [[#if defined __powerpc64__ || defined _ARCH_PPC64 126*eda14cbcSMatt Macy int ok; 127*eda14cbcSMatt Macy #else 128*eda14cbcSMatt Macy error fail 129*eda14cbcSMatt Macy #endif 130*eda14cbcSMatt Macy ]])], 131*eda14cbcSMatt Macy [# The compiler produces 64-bit code. Add option '-b64' so that the 132*eda14cbcSMatt Macy # linker groks 64-bit object files. 133*eda14cbcSMatt Macy case "$acl_cv_path_LD " in 134*eda14cbcSMatt Macy *" -b64 "*) ;; 135*eda14cbcSMatt Macy *) acl_cv_path_LD="$acl_cv_path_LD -b64" ;; 136*eda14cbcSMatt Macy esac 137*eda14cbcSMatt Macy ], []) 138*eda14cbcSMatt Macy ;; 139*eda14cbcSMatt Macy sparc64-*-netbsd*) 140*eda14cbcSMatt Macy AC_COMPILE_IFELSE( 141*eda14cbcSMatt Macy [AC_LANG_SOURCE( 142*eda14cbcSMatt Macy [[#if defined __sparcv9 || defined __arch64__ 143*eda14cbcSMatt Macy int ok; 144*eda14cbcSMatt Macy #else 145*eda14cbcSMatt Macy error fail 146*eda14cbcSMatt Macy #endif 147*eda14cbcSMatt Macy ]])], 148*eda14cbcSMatt Macy [], 149*eda14cbcSMatt Macy [# The compiler produces 32-bit code. Add option '-m elf32_sparc' 150*eda14cbcSMatt Macy # so that the linker groks 32-bit object files. 151*eda14cbcSMatt Macy case "$acl_cv_path_LD " in 152*eda14cbcSMatt Macy *" -m elf32_sparc "*) ;; 153*eda14cbcSMatt Macy *) acl_cv_path_LD="$acl_cv_path_LD -m elf32_sparc" ;; 154*eda14cbcSMatt Macy esac 155*eda14cbcSMatt Macy ]) 156*eda14cbcSMatt Macy ;; 157*eda14cbcSMatt Macy esac 158*eda14cbcSMatt Macy ]) 159*eda14cbcSMatt Macy LD="$acl_cv_path_LD" 160*eda14cbcSMatt Macyfi 161*eda14cbcSMatt Macyif test -n "$LD"; then 162*eda14cbcSMatt Macy AC_MSG_RESULT([$LD]) 163*eda14cbcSMatt Macyelse 164*eda14cbcSMatt Macy AC_MSG_RESULT([no]) 165*eda14cbcSMatt Macy AC_MSG_ERROR([no acceptable ld found in \$PATH]) 166*eda14cbcSMatt Macyfi 167*eda14cbcSMatt MacyAC_LIB_PROG_LD_GNU 168*eda14cbcSMatt Macy]) 169