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