xref: /aosp_15_r20/external/flac/m4/lib-ld.m4 (revision 600f14f40d737144c998e2ec7a483122d3776fbc)
1*600f14f4SXin Li# lib-ld.m4 serial 6
2*600f14f4SXin Lidnl Copyright (C) 1996-2003, 2009-2012 Free Software Foundation, Inc.
3*600f14f4SXin Lidnl This file is free software; the Free Software Foundation
4*600f14f4SXin Lidnl gives unlimited permission to copy and/or distribute it,
5*600f14f4SXin Lidnl with or without modifications, as long as this notice is preserved.
6*600f14f4SXin Li
7*600f14f4SXin Lidnl Subroutines of libtool.m4,
8*600f14f4SXin Lidnl with replacements s/_*LT_PATH/AC_LIB_PROG/ and s/lt_/acl_/ to avoid
9*600f14f4SXin Lidnl collision with libtool.m4.
10*600f14f4SXin Li
11*600f14f4SXin Lidnl From libtool-2.4. Sets the variable with_gnu_ld to yes or no.
12*600f14f4SXin LiAC_DEFUN([AC_LIB_PROG_LD_GNU],
13*600f14f4SXin Li[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], [acl_cv_prog_gnu_ld],
14*600f14f4SXin Li[# I'd rather use --version here, but apparently some GNU lds only accept -v.
15*600f14f4SXin Licase `$LD -v 2>&1 </dev/null` in
16*600f14f4SXin Li*GNU* | *'with BFD'*)
17*600f14f4SXin Li  acl_cv_prog_gnu_ld=yes
18*600f14f4SXin Li  ;;
19*600f14f4SXin Li*)
20*600f14f4SXin Li  acl_cv_prog_gnu_ld=no
21*600f14f4SXin Li  ;;
22*600f14f4SXin Liesac])
23*600f14f4SXin Liwith_gnu_ld=$acl_cv_prog_gnu_ld
24*600f14f4SXin Li])
25*600f14f4SXin Li
26*600f14f4SXin Lidnl From libtool-2.4. Sets the variable LD.
27*600f14f4SXin LiAC_DEFUN([AC_LIB_PROG_LD],
28*600f14f4SXin Li[AC_REQUIRE([AC_PROG_CC])dnl
29*600f14f4SXin LiAC_REQUIRE([AC_CANONICAL_HOST])dnl
30*600f14f4SXin Li
31*600f14f4SXin LiAC_ARG_WITH([gnu-ld],
32*600f14f4SXin Li    [AS_HELP_STRING([--with-gnu-ld],
33*600f14f4SXin Li        [assume the C compiler uses GNU ld [default=no]])],
34*600f14f4SXin Li    [test "$withval" = no || with_gnu_ld=yes],
35*600f14f4SXin Li    [with_gnu_ld=no])dnl
36*600f14f4SXin Li
37*600f14f4SXin Li# Prepare PATH_SEPARATOR.
38*600f14f4SXin Li# The user is always right.
39*600f14f4SXin Liif test "${PATH_SEPARATOR+set}" != set; then
40*600f14f4SXin Li  # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which
41*600f14f4SXin Li  # contains only /bin. Note that ksh looks also at the FPATH variable,
42*600f14f4SXin Li  # so we have to set that as well for the test.
43*600f14f4SXin Li  PATH_SEPARATOR=:
44*600f14f4SXin Li  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
45*600f14f4SXin Li    && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
46*600f14f4SXin Li           || PATH_SEPARATOR=';'
47*600f14f4SXin Li       }
48*600f14f4SXin Lifi
49*600f14f4SXin Li
50*600f14f4SXin Liac_prog=ld
51*600f14f4SXin Liif test "$GCC" = yes; then
52*600f14f4SXin Li  # Check if gcc -print-prog-name=ld gives a path.
53*600f14f4SXin Li  AC_MSG_CHECKING([for ld used by $CC])
54*600f14f4SXin Li  case $host in
55*600f14f4SXin Li  *-*-mingw*)
56*600f14f4SXin Li    # gcc leaves a trailing carriage return which upsets mingw
57*600f14f4SXin Li    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
58*600f14f4SXin Li  *)
59*600f14f4SXin Li    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
60*600f14f4SXin Li  esac
61*600f14f4SXin Li  case $ac_prog in
62*600f14f4SXin Li    # Accept absolute paths.
63*600f14f4SXin Li    [[\\/]]* | ?:[[\\/]]*)
64*600f14f4SXin Li      re_direlt='/[[^/]][[^/]]*/\.\./'
65*600f14f4SXin Li      # Canonicalize the pathname of ld
66*600f14f4SXin Li      ac_prog=`echo "$ac_prog"| sed 's%\\\\%/%g'`
67*600f14f4SXin Li      while echo "$ac_prog" | grep "$re_direlt" > /dev/null 2>&1; do
68*600f14f4SXin Li        ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"`
69*600f14f4SXin Li      done
70*600f14f4SXin Li      test -z "$LD" && LD="$ac_prog"
71*600f14f4SXin Li      ;;
72*600f14f4SXin Li  "")
73*600f14f4SXin Li    # If it fails, then pretend we aren't using GCC.
74*600f14f4SXin Li    ac_prog=ld
75*600f14f4SXin Li    ;;
76*600f14f4SXin Li  *)
77*600f14f4SXin Li    # If it is relative, then search for the first ld in PATH.
78*600f14f4SXin Li    with_gnu_ld=unknown
79*600f14f4SXin Li    ;;
80*600f14f4SXin Li  esac
81*600f14f4SXin Lielif test "$with_gnu_ld" = yes; then
82*600f14f4SXin Li  AC_MSG_CHECKING([for GNU ld])
83*600f14f4SXin Lielse
84*600f14f4SXin Li  AC_MSG_CHECKING([for non-GNU ld])
85*600f14f4SXin Lifi
86*600f14f4SXin LiAC_CACHE_VAL([acl_cv_path_LD],
87*600f14f4SXin Li[if test -z "$LD"; then
88*600f14f4SXin Li  acl_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
89*600f14f4SXin Li  for ac_dir in $PATH; do
90*600f14f4SXin Li    IFS="$acl_save_ifs"
91*600f14f4SXin Li    test -z "$ac_dir" && ac_dir=.
92*600f14f4SXin Li    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
93*600f14f4SXin Li      acl_cv_path_LD="$ac_dir/$ac_prog"
94*600f14f4SXin Li      # Check to see if the program is GNU ld.  I'd rather use --version,
95*600f14f4SXin Li      # but apparently some variants of GNU ld only accept -v.
96*600f14f4SXin Li      # Break only if it was the GNU/non-GNU ld that we prefer.
97*600f14f4SXin Li      case `"$acl_cv_path_LD" -v 2>&1 </dev/null` in
98*600f14f4SXin Li      *GNU* | *'with BFD'*)
99*600f14f4SXin Li        test "$with_gnu_ld" != no && break
100*600f14f4SXin Li        ;;
101*600f14f4SXin Li      *)
102*600f14f4SXin Li        test "$with_gnu_ld" != yes && break
103*600f14f4SXin Li        ;;
104*600f14f4SXin Li      esac
105*600f14f4SXin Li    fi
106*600f14f4SXin Li  done
107*600f14f4SXin Li  IFS="$acl_save_ifs"
108*600f14f4SXin Lielse
109*600f14f4SXin Li  acl_cv_path_LD="$LD" # Let the user override the test with a path.
110*600f14f4SXin Lifi])
111*600f14f4SXin LiLD="$acl_cv_path_LD"
112*600f14f4SXin Liif test -n "$LD"; then
113*600f14f4SXin Li  AC_MSG_RESULT([$LD])
114*600f14f4SXin Lielse
115*600f14f4SXin Li  AC_MSG_RESULT([no])
116*600f14f4SXin Lifi
117*600f14f4SXin Litest -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
118*600f14f4SXin LiAC_LIB_PROG_LD_GNU
119*600f14f4SXin Li])
120