3 dnl Copyright (C) 2001-2024 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.
12 dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and
13 dnl the libraries corresponding to explicit and implicit dependencies.
14 dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and
15 dnl augments the CPPFLAGS variable.
16 dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname
17 dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
18 AC_DEFUN([AC_LIB_LINKFLAGS],
20 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
21 AC_REQUIRE([AC_LIB_RPATH])
22 pushdef([Name],[m4_translit([$1],[./+-], [____])])
23 pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-],
24 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
25 AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [
26 AC_LIB_LINKFLAGS_BODY([$1], [$2])
27 ac_cv_lib[]Name[]_libs="$LIB[]NAME"
28 ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME"
29 ac_cv_lib[]Name[]_cppflags="$INC[]NAME"
30 ac_cv_lib[]Name[]_prefix="$LIB[]NAME[]_PREFIX"
32 LIB[]NAME="$ac_cv_lib[]Name[]_libs"
33 LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs"
34 INC[]NAME="$ac_cv_lib[]Name[]_cppflags"
35 LIB[]NAME[]_PREFIX="$ac_cv_lib[]Name[]_prefix"
36 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
39 AC_SUBST([LIB]NAME[_PREFIX])
40 dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the
41 dnl results of this search when this library appears as a dependency.
47 dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode, [missing-message])
48 dnl searches for libname and the libraries corresponding to explicit and
49 dnl implicit dependencies, together with the specified include files and
50 dnl the ability to compile and link the specified testcode. The missing-message
51 dnl defaults to 'no' and may contain additional hints for the user.
52 dnl If found, it sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME}
53 dnl and LTLIB${NAME} variables and augments the CPPFLAGS variable, and
54 dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs
55 dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty.
56 dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname
57 dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
58 AC_DEFUN([AC_LIB_HAVE_LINKFLAGS],
60 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
61 AC_REQUIRE([AC_LIB_RPATH])
62 pushdef([Name],[m4_translit([$1],[./+-], [____])])
63 pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-],
64 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
66 dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME
68 AC_LIB_LINKFLAGS_BODY([$1], [$2])
70 dnl Add $INC[]NAME to CPPFLAGS before performing the following checks,
71 dnl because if the user has installed lib[]Name and not disabled its use
72 dnl via --without-lib[]Name-prefix, he wants to use it.
73 acl_saved_CPPFLAGS="$CPPFLAGS"
74 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
76 AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [
77 acl_saved_LIBS="$LIBS"
78 dnl If $LIB[]NAME contains some -l options, add it to the end of LIBS,
79 dnl because these -l options might require -L options that are present in
80 dnl LIBS. -l options benefit only from the -L options listed before it.
81 dnl Otherwise, add it to the front of LIBS, because it may be a static
82 dnl library that depends on another static library that is present in LIBS.
83 dnl Static libraries benefit only from the static libraries listed after
86 *" -l"*) LIBS="$LIBS $LIB[]NAME" ;;
87 *) LIBS="$LIB[]NAME $LIBS" ;;
90 [AC_LANG_PROGRAM([[$3]], [[$4]])],
91 [ac_cv_lib[]Name=yes],
92 [ac_cv_lib[]Name='m4_if([$5], [], [no], [[$5]])'])
93 LIBS="$acl_saved_LIBS"
95 if test "$ac_cv_lib[]Name" = yes; then
97 AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the lib][$1 library.])
98 AC_MSG_CHECKING([how to link with lib[]$1])
99 AC_MSG_RESULT([$LIB[]NAME])
102 dnl If $LIB[]NAME didn't lead to a usable library, we don't need
103 dnl $INC[]NAME either.
104 CPPFLAGS="$acl_saved_CPPFLAGS"
109 AC_SUBST([HAVE_LIB]NAME)
111 AC_SUBST([LTLIB]NAME)
112 AC_SUBST([LIB]NAME[_PREFIX])
117 dnl Determine the platform dependent parameters needed to use rpath:
120 dnl acl_libname_spec,
121 dnl acl_library_names_spec,
122 dnl acl_hardcode_libdir_flag_spec,
123 dnl acl_hardcode_libdir_separator,
124 dnl acl_hardcode_direct,
125 dnl acl_hardcode_minus_L.
126 AC_DEFUN([AC_LIB_RPATH],
128 dnl Complain if config.rpath is missing.
129 AC_REQUIRE_AUX_FILE([config.rpath])
130 AC_REQUIRE([AC_PROG_CC]) dnl we use $CC, $GCC, $LDFLAGS
131 AC_REQUIRE([AC_LIB_PROG_LD]) dnl we use $LD, $with_gnu_ld
132 AC_REQUIRE([AC_CANONICAL_HOST]) dnl we use $host
133 AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir
134 AC_CACHE_CHECK([for shared library run path origin], [acl_cv_rpath], [
135 CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \
136 ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh
142 acl_libext="$acl_cv_libext"
143 acl_shlibext="$acl_cv_shlibext"
144 acl_libname_spec="$acl_cv_libname_spec"
145 acl_library_names_spec="$acl_cv_library_names_spec"
146 acl_hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec"
147 acl_hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator"
148 acl_hardcode_direct="$acl_cv_hardcode_direct"
149 acl_hardcode_minus_L="$acl_cv_hardcode_minus_L"
150 dnl Determine whether the user wants rpath handling at all.
151 AC_ARG_ENABLE([rpath],
152 [ --disable-rpath do not hardcode runtime library paths],
156 dnl AC_LIB_FROMPACKAGE(name, package)
157 dnl declares that libname comes from the given package. The configure file
158 dnl will then not have a --with-libname-prefix option but a
159 dnl --with-package-prefix option. Several libraries can come from the same
160 dnl package. This declaration must occur before an AC_LIB_LINKFLAGS or similar
161 dnl macro call that searches for libname.
162 AC_DEFUN([AC_LIB_FROMPACKAGE],
164 pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-],
165 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
166 define([acl_frompackage_]NAME, [$2])
169 pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-],
170 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
171 define([acl_libsinpackage_]PACKUP,
172 m4_ifdef([acl_libsinpackage_]PACKUP, [m4_defn([acl_libsinpackage_]PACKUP)[, ]],)[lib$1])
177 dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and
178 dnl the libraries corresponding to explicit and implicit dependencies.
179 dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables.
180 dnl Also, sets the LIB${NAME}_PREFIX variable to nonempty if libname was found
181 dnl in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
182 AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
184 AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
185 pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-],
186 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
187 pushdef([PACK],[m4_ifdef([acl_frompackage_]NAME, [acl_frompackage_]NAME, lib[$1])])
188 pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-],
189 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
190 pushdef([PACKLIBS],[m4_ifdef([acl_frompackage_]NAME, [acl_libsinpackage_]PACKUP, lib[$1])])
191 dnl By default, look in $includedir and $libdir.
193 AC_LIB_WITH_FINAL_PREFIX([
194 eval additional_includedir=\"$includedir\"
195 eval additional_libdir=\"$libdir\"
196 eval additional_libdir2=\"$exec_prefix/$acl_libdirstem2\"
197 eval additional_libdir3=\"$exec_prefix/$acl_libdirstem3\"
199 AC_ARG_WITH(PACK[-prefix],
200 [[ --with-]]PACK[[-prefix[=DIR] search for ]]PACKLIBS[[ in DIR/include and DIR/lib
201 --without-]]PACK[[-prefix don't search for ]]PACKLIBS[[ in includedir and libdir]],
203 if test "X$withval" = "Xno"; then
206 if test "X$withval" = "X"; then
207 AC_LIB_WITH_FINAL_PREFIX([
208 eval additional_includedir=\"$includedir\"
209 eval additional_libdir=\"$libdir\"
210 eval additional_libdir2=\"$exec_prefix/$acl_libdirstem2\"
211 eval additional_libdir3=\"$exec_prefix/$acl_libdirstem3\"
214 additional_includedir="$withval/include"
215 additional_libdir="$withval/$acl_libdirstem"
216 additional_libdir2="$withval/$acl_libdirstem2"
217 additional_libdir3="$withval/$acl_libdirstem3"
221 if test "X$additional_libdir2" = "X$additional_libdir"; then
224 if test "X$additional_libdir3" = "X$additional_libdir"; then
227 dnl Search the library and its dependencies in $additional_libdir and
228 dnl $LDFLAGS. Use breadth-first search.
233 dnl HAVE_LIB${NAME} is an indicator that LIB${NAME}, LTLIB${NAME} have been
234 dnl computed. So it has to be reset here.
238 names_already_handled=
239 names_next_round='$1 $2'
240 while test -n "$names_next_round"; do
241 names_this_round="$names_next_round"
243 for name in $names_this_round; do
245 for n in $names_already_handled; do
246 if test "$n" = "$name"; then
251 if test -z "$already_handled"; then
252 names_already_handled="$names_already_handled $name"
253 dnl See if it was already located by an earlier AC_LIB_LINKFLAGS
254 dnl or AC_LIB_HAVE_LINKFLAGS call.
255 uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./+-|ABCDEFGHIJKLMNOPQRSTUVWXYZ____|'`
256 eval value=\"\$HAVE_LIB$uppername\"
257 if test -n "$value"; then
258 if test "$value" = yes; then
259 eval value=\"\$LIB$uppername\"
260 test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value"
261 eval value=\"\$LTLIB$uppername\"
262 test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value"
264 dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined
265 dnl that this library doesn't exist. So just drop it.
269 dnl Search the library lib$name in $additional_libdir and $LDFLAGS
270 dnl and the already constructed $LIBNAME/$LTLIBNAME.
275 eval libname=\"$acl_libname_spec\" # typically: libname=lib$name
276 if test -n "$acl_shlibext"; then
277 shrext=".$acl_shlibext" # typically: shrext=.so
281 if test $use_additional = yes; then
282 for additional_libdir_variable in additional_libdir additional_libdir2 additional_libdir3; do
283 if test "X$found_dir" = "X"; then
284 eval dir=\$$additional_libdir_variable
285 if test -n "$dir"; then
286 dnl The same code as in the loop below:
287 dnl First look for a shared library.
288 if test -n "$acl_shlibext"; then
289 if test -f "$dir/$libname$shrext" && acl_is_expected_elfclass < "$dir/$libname$shrext"; then
291 found_so="$dir/$libname$shrext"
293 if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then
295 for f in "$libname$shrext".*; do echo "$f"; done \
296 | sed -e "s,^$libname$shrext\\\\.,," \
297 | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \
298 | sed 1q ) 2>/dev/null`
299 if test -n "$ver" && test -f "$dir/$libname$shrext.$ver" && acl_is_expected_elfclass < "$dir/$libname$shrext.$ver"; then
301 found_so="$dir/$libname$shrext.$ver"
304 eval library_names=\"$acl_library_names_spec\"
305 for f in $library_names; do
306 if test -f "$dir/$f" && acl_is_expected_elfclass < "$dir/$f"; then
315 dnl Then look for a static library.
316 if test "X$found_dir" = "X"; then
317 if test -f "$dir/$libname.$acl_libext" && ${AR-ar} -p "$dir/$libname.$acl_libext" | acl_is_expected_elfclass; then
319 found_a="$dir/$libname.$acl_libext"
322 if test "X$found_dir" != "X"; then
323 if test -f "$dir/$libname.la"; then
324 found_la="$dir/$libname.la"
331 if test "X$found_dir" = "X"; then
332 for x in $LDFLAGS $LTLIB[]NAME; do
333 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
336 dir=`echo "X$x" | sed -e 's/^X-L//'`
337 dnl First look for a shared library.
338 if test -n "$acl_shlibext"; then
339 if test -f "$dir/$libname$shrext" && acl_is_expected_elfclass < "$dir/$libname$shrext"; then
341 found_so="$dir/$libname$shrext"
343 if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then
345 for f in "$libname$shrext".*; do echo "$f"; done \
346 | sed -e "s,^$libname$shrext\\\\.,," \
347 | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \
348 | sed 1q ) 2>/dev/null`
349 if test -n "$ver" && test -f "$dir/$libname$shrext.$ver" && acl_is_expected_elfclass < "$dir/$libname$shrext.$ver"; then
351 found_so="$dir/$libname$shrext.$ver"
354 eval library_names=\"$acl_library_names_spec\"
355 for f in $library_names; do
356 if test -f "$dir/$f" && acl_is_expected_elfclass < "$dir/$f"; then
365 dnl Then look for a static library.
366 if test "X$found_dir" = "X"; then
367 if test -f "$dir/$libname.$acl_libext" && ${AR-ar} -p "$dir/$libname.$acl_libext" | acl_is_expected_elfclass; then
369 found_a="$dir/$libname.$acl_libext"
372 if test "X$found_dir" != "X"; then
373 if test -f "$dir/$libname.la"; then
374 found_la="$dir/$libname.la"
379 if test "X$found_dir" != "X"; then
384 if test "X$found_dir" != "X"; then
385 dnl Found the library.
386 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name"
387 if test "X$found_so" != "X"; then
388 dnl Linking with a shared library. We attempt to hardcode its
389 dnl directory into the executable's runpath, unless it's the
390 dnl standard /usr/lib.
391 if test "$enable_rpath" = no \
392 || test "X$found_dir" = "X/usr/$acl_libdirstem" \
393 || test "X$found_dir" = "X/usr/$acl_libdirstem2" \
394 || test "X$found_dir" = "X/usr/$acl_libdirstem3"; then
395 dnl No hardcoding is needed.
396 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
398 dnl Use an explicit option to hardcode DIR into the resulting
400 dnl Potentially add DIR to ltrpathdirs.
401 dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
403 for x in $ltrpathdirs; do
404 if test "X$x" = "X$found_dir"; then
409 if test -z "$haveit"; then
410 ltrpathdirs="$ltrpathdirs $found_dir"
412 dnl The hardcoding into $LIBNAME is system dependent.
413 if test "$acl_hardcode_direct" = yes; then
414 dnl Using DIR/libNAME.so during linking hardcodes DIR into the
415 dnl resulting binary.
416 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
418 if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then
419 dnl Use an explicit option to hardcode DIR into the resulting
421 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
422 dnl Potentially add DIR to rpathdirs.
423 dnl The rpathdirs will be appended to $LIBNAME at the end.
425 for x in $rpathdirs; do
426 if test "X$x" = "X$found_dir"; then
431 if test -z "$haveit"; then
432 rpathdirs="$rpathdirs $found_dir"
435 dnl Rely on "-L$found_dir".
436 dnl But don't add it if it's already contained in the LDFLAGS
437 dnl or the already constructed $LIBNAME
439 for x in $LDFLAGS $LIB[]NAME; do
440 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
441 if test "X$x" = "X-L$found_dir"; then
446 if test -z "$haveit"; then
447 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir"
449 if test "$acl_hardcode_minus_L" != no; then
450 dnl FIXME: Not sure whether we should use
451 dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
453 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
455 dnl We cannot use $acl_hardcode_runpath_var and LD_RUN_PATH
456 dnl here, because this doesn't fit in flags passed to the
457 dnl compiler. So give up. No hardcoding. This affects only
458 dnl very old systems.
459 dnl FIXME: Not sure whether we should use
460 dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
462 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
468 if test "X$found_a" != "X"; then
469 dnl Linking with a static library.
470 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a"
472 dnl We shouldn't come here, but anyway it's good to have a
474 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name"
477 dnl Assume the include files are nearby.
478 additional_includedir=
480 */$acl_libdirstem | */$acl_libdirstem/)
481 basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'`
482 if test "$name" = '$1'; then
483 LIB[]NAME[]_PREFIX="$basedir"
485 additional_includedir="$basedir/include"
487 */$acl_libdirstem2 | */$acl_libdirstem2/)
488 basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem2/"'*$,,'`
489 if test "$name" = '$1'; then
490 LIB[]NAME[]_PREFIX="$basedir"
492 additional_includedir="$basedir/include"
494 */$acl_libdirstem3 | */$acl_libdirstem3/)
495 basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem3/"'*$,,'`
496 if test "$name" = '$1'; then
497 LIB[]NAME[]_PREFIX="$basedir"
499 additional_includedir="$basedir/include"
502 if test "X$additional_includedir" != "X"; then
503 dnl Potentially add $additional_includedir to $INCNAME.
505 dnl 1. if it's the standard /usr/include,
506 dnl 2. if it's /usr/local/include and we are using GCC on Linux,
507 dnl 3. if it's already present in $CPPFLAGS or the already
508 dnl constructed $INCNAME,
509 dnl 4. if it doesn't exist as a directory.
510 if test "X$additional_includedir" != "X/usr/include"; then
512 if test "X$additional_includedir" = "X/usr/local/include"; then
513 if test -n "$GCC"; then
515 linux* | gnu* | k*bsd*-gnu) haveit=yes;;
519 if test -z "$haveit"; then
520 for x in $CPPFLAGS $INC[]NAME; do
521 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
522 if test "X$x" = "X-I$additional_includedir"; then
527 if test -z "$haveit"; then
528 if test -d "$additional_includedir"; then
529 dnl Really add $additional_includedir to $INCNAME.
530 INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir"
536 dnl Look for dependencies.
537 if test -n "$found_la"; then
538 dnl Read the .la file. It defines the variables
539 dnl dlname, library_names, old_library, dependency_libs, current,
540 dnl age, revision, installed, dlopen, dlpreopen, libdir.
541 saved_libdir="$libdir"
543 */* | *\\*) . "$found_la" ;;
544 *) . "./$found_la" ;;
546 libdir="$saved_libdir"
547 dnl We use only dependency_libs.
548 for dep in $dependency_libs; do
551 dependency_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
552 dnl Potentially add $dependency_libdir to $LIBNAME and $LTLIBNAME.
554 dnl 1. if it's the standard /usr/lib,
555 dnl 2. if it's /usr/local/lib and we are using GCC on Linux,
556 dnl 3. if it's already present in $LDFLAGS or the already
557 dnl constructed $LIBNAME,
558 dnl 4. if it doesn't exist as a directory.
559 if test "X$dependency_libdir" != "X/usr/$acl_libdirstem" \
560 && test "X$dependency_libdir" != "X/usr/$acl_libdirstem2" \
561 && test "X$dependency_libdir" != "X/usr/$acl_libdirstem3"; then
563 if test "X$dependency_libdir" = "X/usr/local/$acl_libdirstem" \
564 || test "X$dependency_libdir" = "X/usr/local/$acl_libdirstem2" \
565 || test "X$dependency_libdir" = "X/usr/local/$acl_libdirstem3"; then
566 if test -n "$GCC"; then
568 linux* | gnu* | k*bsd*-gnu) haveit=yes;;
572 if test -z "$haveit"; then
574 for x in $LDFLAGS $LIB[]NAME; do
575 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
576 if test "X$x" = "X-L$dependency_libdir"; then
581 if test -z "$haveit"; then
582 if test -d "$dependency_libdir"; then
583 dnl Really add $dependency_libdir to $LIBNAME.
584 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$dependency_libdir"
588 for x in $LDFLAGS $LTLIB[]NAME; do
589 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
590 if test "X$x" = "X-L$dependency_libdir"; then
595 if test -z "$haveit"; then
596 if test -d "$dependency_libdir"; then
597 dnl Really add $dependency_libdir to $LTLIBNAME.
598 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$dependency_libdir"
605 dir=`echo "X$dep" | sed -e 's/^X-R//'`
606 if test "$enable_rpath" != no; then
607 dnl Potentially add DIR to rpathdirs.
608 dnl The rpathdirs will be appended to $LIBNAME at the end.
610 for x in $rpathdirs; do
611 if test "X$x" = "X$dir"; then
616 if test -z "$haveit"; then
617 rpathdirs="$rpathdirs $dir"
619 dnl Potentially add DIR to ltrpathdirs.
620 dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
622 for x in $ltrpathdirs; do
623 if test "X$x" = "X$dir"; then
628 if test -z "$haveit"; then
629 ltrpathdirs="$ltrpathdirs $dir"
634 dnl Handle this in the next round.
635 dnl But on GNU systems, ignore -lc options, because
636 dnl - linking with libc is the default anyway,
637 dnl - linking with libc.a may produce an error
638 dnl "/usr/bin/ld: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/usr/lib/libc.a(strcmp.o)' can not be used when making an executable; recompile with -fPIE and relink with -pie"
639 dnl or may produce an executable that always crashes, see
640 dnl <https://lists.gnu.org/archive/html/grep-devel/2020-09/msg00052.html>.
641 dep=`echo "X$dep" | sed -e 's/^X-l//'`
642 if test "X$dep" != Xc \
644 linux* | gnu* | k*bsd*-gnu) false ;;
647 names_next_round="$names_next_round $dep"
651 dnl Handle this in the next round. Throw away the .la's
652 dnl directory; it is already contained in a preceding -L
654 names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
657 dnl Most likely an immediate library name.
658 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep"
659 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep"
665 dnl Didn't find the library; assume it is in the system directories
666 dnl known to the linker and runtime loader. (All the system
667 dnl directories known to the linker should also be known to the
668 dnl runtime loader, otherwise the system is severely misconfigured.)
669 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
670 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name"
676 if test "X$rpathdirs" != "X"; then
677 if test -n "$acl_hardcode_libdir_separator"; then
678 dnl Weird platform: only the last -rpath option counts, the user must
679 dnl pass all path elements in one option. We can arrange that for a
680 dnl single library, but not when more than one $LIBNAMEs are used.
682 for found_dir in $rpathdirs; do
683 alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$found_dir"
685 dnl Note: acl_hardcode_libdir_flag_spec uses $libdir and $wl.
686 acl_saved_libdir="$libdir"
688 eval flag=\"$acl_hardcode_libdir_flag_spec\"
689 libdir="$acl_saved_libdir"
690 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
692 dnl The -rpath options are cumulative.
693 for found_dir in $rpathdirs; do
694 acl_saved_libdir="$libdir"
696 eval flag=\"$acl_hardcode_libdir_flag_spec\"
697 libdir="$acl_saved_libdir"
698 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
702 if test "X$ltrpathdirs" != "X"; then
703 dnl When using libtool, the option that works for both libraries and
704 dnl executables is -R. The -R options are cumulative.
705 for found_dir in $ltrpathdirs; do
706 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir"
715 dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR,
716 dnl unless already present in VAR.
717 dnl Works only for CPPFLAGS, not for LIB* variables because that sometimes
718 dnl contains two or three consecutive elements that belong together.
719 AC_DEFUN([AC_LIB_APPENDTOVAR],
721 for element in [$2]; do
724 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
725 if test "X$x" = "X$element"; then
730 if test -z "$haveit"; then
731 [$1]="${[$1]}${[$1]:+ }$element"
736 dnl For those cases where a variable contains several -L and -l options
737 dnl referring to unknown libraries and directories, this macro determines the
738 dnl necessary additional linker options for the runtime path.
739 dnl AC_LIB_LINKFLAGS_FROM_LIBS([LDADDVAR], [LIBSVALUE], [USE-LIBTOOL])
740 dnl sets LDADDVAR to linker options needed together with LIBSVALUE.
741 dnl If USE-LIBTOOL evaluates to non-empty, linking with libtool is assumed,
742 dnl otherwise linking without libtool is assumed.
743 AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS],
745 AC_REQUIRE([AC_LIB_RPATH])
746 AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
748 if test "$enable_rpath" != no; then
749 if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then
750 dnl Use an explicit option to hardcode directories into the resulting
755 if test -n "$next"; then
757 dnl No need to hardcode the standard /usr/lib.
758 if test "X$dir" != "X/usr/$acl_libdirstem" \
759 && test "X$dir" != "X/usr/$acl_libdirstem2" \
760 && test "X$dir" != "X/usr/$acl_libdirstem3"; then
761 rpathdirs="$rpathdirs $dir"
767 -L*) dir=`echo "X$opt" | sed -e 's,^X-L,,'`
768 dnl No need to hardcode the standard /usr/lib.
769 if test "X$dir" != "X/usr/$acl_libdirstem" \
770 && test "X$dir" != "X/usr/$acl_libdirstem2" \
771 && test "X$dir" != "X/usr/$acl_libdirstem3"; then
772 rpathdirs="$rpathdirs $dir"
779 if test "X$rpathdirs" != "X"; then
780 if test -n ""$3""; then
781 dnl libtool is used for linking. Use -R options.
782 for dir in $rpathdirs; do
783 $1="${$1}${$1:+ }-R$dir"
786 dnl The linker is used for linking directly.
787 if test -n "$acl_hardcode_libdir_separator"; then
788 dnl Weird platform: only the last -rpath option counts, the user
789 dnl must pass all path elements in one option.
791 for dir in $rpathdirs; do
792 alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$dir"
794 acl_saved_libdir="$libdir"
796 eval flag=\"$acl_hardcode_libdir_flag_spec\"
797 libdir="$acl_saved_libdir"
800 dnl The -rpath options are cumulative.
801 for dir in $rpathdirs; do
802 acl_saved_libdir="$libdir"
804 eval flag=\"$acl_hardcode_libdir_flag_spec\"
805 libdir="$acl_saved_libdir"
806 $1="${$1}${$1:+ }$flag"