1 # lib-link.m4 serial 31
2 dnl Copyright (C) 2001-2020 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
11 dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and
12 dnl the libraries corresponding to explicit and implicit dependencies.
13 dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and
14 dnl augments the CPPFLAGS variable.
15 dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname
16 dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
17 AC_DEFUN([AC_LIB_LINKFLAGS],
19 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
20 AC_REQUIRE([AC_LIB_RPATH])
21 pushdef([Name],[m4_translit([$1],[./+-], [____])])
22 pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-],
23 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
24 AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [
25 AC_LIB_LINKFLAGS_BODY([$1], [$2])
26 ac_cv_lib[]Name[]_libs="$LIB[]NAME"
27 ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME"
28 ac_cv_lib[]Name[]_cppflags="$INC[]NAME"
29 ac_cv_lib[]Name[]_prefix="$LIB[]NAME[]_PREFIX"
31 LIB[]NAME="$ac_cv_lib[]Name[]_libs"
32 LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs"
33 INC[]NAME="$ac_cv_lib[]Name[]_cppflags"
34 LIB[]NAME[]_PREFIX="$ac_cv_lib[]Name[]_prefix"
35 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
38 AC_SUBST([LIB]NAME[_PREFIX])
39 dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the
40 dnl results of this search when this library appears as a dependency.
46 dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode, [missing-message])
47 dnl searches for libname and the libraries corresponding to explicit and
48 dnl implicit dependencies, together with the specified include files and
49 dnl the ability to compile and link the specified testcode. The missing-message
50 dnl defaults to 'no' and may contain additional hints for the user.
51 dnl If found, it sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME}
52 dnl and LTLIB${NAME} variables and augments the CPPFLAGS variable, and
53 dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs
54 dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty.
55 dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname
56 dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
57 AC_DEFUN([AC_LIB_HAVE_LINKFLAGS],
59 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
60 AC_REQUIRE([AC_LIB_RPATH])
61 pushdef([Name],[m4_translit([$1],[./+-], [____])])
62 pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-],
63 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
65 dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME
67 AC_LIB_LINKFLAGS_BODY([$1], [$2])
69 dnl Add $INC[]NAME to CPPFLAGS before performing the following checks,
70 dnl because if the user has installed lib[]Name and not disabled its use
71 dnl via --without-lib[]Name-prefix, he wants to use it.
72 ac_save_CPPFLAGS="$CPPFLAGS"
73 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
75 AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [
77 dnl If $LIB[]NAME contains some -l options, add it to the end of LIBS,
78 dnl because these -l options might require -L options that are present in
79 dnl LIBS. -l options benefit only from the -L options listed before it.
80 dnl Otherwise, add it to the front of LIBS, because it may be a static
81 dnl library that depends on another static library that is present in LIBS.
82 dnl Static libraries benefit only from the static libraries listed after
85 *" -l"*) LIBS="$LIBS $LIB[]NAME" ;;
86 *) LIBS="$LIB[]NAME $LIBS" ;;
89 [AC_LANG_PROGRAM([[$3]], [[$4]])],
90 [ac_cv_lib[]Name=yes],
91 [ac_cv_lib[]Name='m4_if([$5], [], [no], [[$5]])'])
94 if test "$ac_cv_lib[]Name" = yes; then
96 AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the lib][$1 library.])
97 AC_MSG_CHECKING([how to link with lib[]$1])
98 AC_MSG_RESULT([$LIB[]NAME])
101 dnl If $LIB[]NAME didn't lead to a usable library, we don't need
102 dnl $INC[]NAME either.
103 CPPFLAGS="$ac_save_CPPFLAGS"
108 AC_SUBST([HAVE_LIB]NAME)
110 AC_SUBST([LTLIB]NAME)
111 AC_SUBST([LIB]NAME[_PREFIX])
116 dnl Determine the platform dependent parameters needed to use rpath:
119 dnl acl_libname_spec,
120 dnl acl_library_names_spec,
121 dnl acl_hardcode_libdir_flag_spec,
122 dnl acl_hardcode_libdir_separator,
123 dnl acl_hardcode_direct,
124 dnl acl_hardcode_minus_L.
125 AC_DEFUN([AC_LIB_RPATH],
127 dnl Complain if config.rpath is missing.
128 AC_REQUIRE_AUX_FILE([config.rpath])
129 AC_REQUIRE([AC_PROG_CC]) dnl we use $CC, $GCC, $LDFLAGS
130 AC_REQUIRE([AC_LIB_PROG_LD]) dnl we use $LD, $with_gnu_ld
131 AC_REQUIRE([AC_CANONICAL_HOST]) dnl we use $host
132 AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir
133 AC_CACHE_CHECK([for shared library run path origin], [acl_cv_rpath], [
134 CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \
135 ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh
141 acl_libext="$acl_cv_libext"
142 acl_shlibext="$acl_cv_shlibext"
143 acl_libname_spec="$acl_cv_libname_spec"
144 acl_library_names_spec="$acl_cv_library_names_spec"
145 acl_hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec"
146 acl_hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator"
147 acl_hardcode_direct="$acl_cv_hardcode_direct"
148 acl_hardcode_minus_L="$acl_cv_hardcode_minus_L"
149 dnl Determine whether the user wants rpath handling at all.
150 AC_ARG_ENABLE([rpath],
151 [ --disable-rpath do not hardcode runtime library paths],
155 dnl AC_LIB_FROMPACKAGE(name, package)
156 dnl declares that libname comes from the given package. The configure file
157 dnl will then not have a --with-libname-prefix option but a
158 dnl --with-package-prefix option. Several libraries can come from the same
159 dnl package. This declaration must occur before an AC_LIB_LINKFLAGS or similar
160 dnl macro call that searches for libname.
161 AC_DEFUN([AC_LIB_FROMPACKAGE],
163 pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-],
164 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
165 define([acl_frompackage_]NAME, [$2])
168 pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-],
169 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
170 define([acl_libsinpackage_]PACKUP,
171 m4_ifdef([acl_libsinpackage_]PACKUP, [m4_defn([acl_libsinpackage_]PACKUP)[, ]],)[lib$1])
176 dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and
177 dnl the libraries corresponding to explicit and implicit dependencies.
178 dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables.
179 dnl Also, sets the LIB${NAME}_PREFIX variable to nonempty if libname was found
180 dnl in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
181 AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
183 AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
184 pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-],
185 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
186 pushdef([PACK],[m4_ifdef([acl_frompackage_]NAME, [acl_frompackage_]NAME, lib[$1])])
187 pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-],
188 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
189 pushdef([PACKLIBS],[m4_ifdef([acl_frompackage_]NAME, [acl_libsinpackage_]PACKUP, lib[$1])])
190 dnl By default, look in $includedir and $libdir.
192 AC_LIB_WITH_FINAL_PREFIX([
193 eval additional_includedir=\"$includedir\"
194 eval additional_libdir=\"$libdir\"
195 eval additional_libdir2=\"$exec_prefix/$acl_libdirstem2\"
196 eval additional_libdir3=\"$exec_prefix/$acl_libdirstem3\"
198 AC_ARG_WITH(PACK[-prefix],
199 [[ --with-]]PACK[[-prefix[=DIR] search for ]PACKLIBS[ in DIR/include and DIR/lib
200 --without-]]PACK[[-prefix don't search for ]PACKLIBS[ in includedir and libdir]],
202 if test "X$withval" = "Xno"; then
205 if test "X$withval" = "X"; then
206 AC_LIB_WITH_FINAL_PREFIX([
207 eval additional_includedir=\"$includedir\"
208 eval additional_libdir=\"$libdir\"
209 eval additional_libdir2=\"$exec_prefix/$acl_libdirstem2\"
210 eval additional_libdir3=\"$exec_prefix/$acl_libdirstem3\"
213 additional_includedir="$withval/include"
214 additional_libdir="$withval/$acl_libdirstem"
215 additional_libdir2="$withval/$acl_libdirstem2"
216 additional_libdir3="$withval/$acl_libdirstem3"
220 if test "X$additional_libdir2" = "X$additional_libdir"; then
223 if test "X$additional_libdir3" = "X$additional_libdir"; then
226 dnl Search the library and its dependencies in $additional_libdir and
227 dnl $LDFLAGS. Using breadth-first-seach.
232 dnl HAVE_LIB${NAME} is an indicator that LIB${NAME}, LTLIB${NAME} have been
233 dnl computed. So it has to be reset here.
237 names_already_handled=
238 names_next_round='$1 $2'
239 while test -n "$names_next_round"; do
240 names_this_round="$names_next_round"
242 for name in $names_this_round; do
244 for n in $names_already_handled; do
245 if test "$n" = "$name"; then
250 if test -z "$already_handled"; then
251 names_already_handled="$names_already_handled $name"
252 dnl See if it was already located by an earlier AC_LIB_LINKFLAGS
253 dnl or AC_LIB_HAVE_LINKFLAGS call.
254 uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./+-|ABCDEFGHIJKLMNOPQRSTUVWXYZ____|'`
255 eval value=\"\$HAVE_LIB$uppername\"
256 if test -n "$value"; then
257 if test "$value" = yes; then
258 eval value=\"\$LIB$uppername\"
259 test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value"
260 eval value=\"\$LTLIB$uppername\"
261 test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value"
263 dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined
264 dnl that this library doesn't exist. So just drop it.
268 dnl Search the library lib$name in $additional_libdir and $LDFLAGS
269 dnl and the already constructed $LIBNAME/$LTLIBNAME.
274 eval libname=\"$acl_libname_spec\" # typically: libname=lib$name
275 if test -n "$acl_shlibext"; then
276 shrext=".$acl_shlibext" # typically: shrext=.so
280 if test $use_additional = yes; then
281 for additional_libdir_variable in additional_libdir additional_libdir2 additional_libdir3; do
282 if test "X$found_dir" = "X"; then
283 eval dir=\$$additional_libdir_variable
284 if test -n "$dir"; then
285 dnl The same code as in the loop below:
286 dnl First look for a shared library.
287 if test -n "$acl_shlibext"; then
288 if test -f "$dir/$libname$shrext" && acl_is_expected_elfclass < "$dir/$libname$shrext"; then
290 found_so="$dir/$libname$shrext"
292 if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then
294 for f in "$libname$shrext".*; do echo "$f"; done \
295 | sed -e "s,^$libname$shrext\\\\.,," \
296 | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \
297 | sed 1q ) 2>/dev/null`
298 if test -n "$ver" && test -f "$dir/$libname$shrext.$ver" && acl_is_expected_elfclass < "$dir/$libname$shrext.$ver"; then
300 found_so="$dir/$libname$shrext.$ver"
303 eval library_names=\"$acl_library_names_spec\"
304 for f in $library_names; do
305 if test -f "$dir/$f" && acl_is_expected_elfclass < "$dir/$f"; then
314 dnl Then look for a static library.
315 if test "X$found_dir" = "X"; then
316 if test -f "$dir/$libname.$acl_libext" && ${AR-ar} -p "$dir/$libname.$acl_libext" | acl_is_expected_elfclass; then
318 found_a="$dir/$libname.$acl_libext"
321 if test "X$found_dir" != "X"; then
322 if test -f "$dir/$libname.la"; then
323 found_la="$dir/$libname.la"
330 if test "X$found_dir" = "X"; then
331 for x in $LDFLAGS $LTLIB[]NAME; do
332 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
335 dir=`echo "X$x" | sed -e 's/^X-L//'`
336 dnl First look for a shared library.
337 if test -n "$acl_shlibext"; then
338 if test -f "$dir/$libname$shrext" && acl_is_expected_elfclass < "$dir/$libname$shrext"; then
340 found_so="$dir/$libname$shrext"
342 if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then
344 for f in "$libname$shrext".*; do echo "$f"; done \
345 | sed -e "s,^$libname$shrext\\\\.,," \
346 | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \
347 | sed 1q ) 2>/dev/null`
348 if test -n "$ver" && test -f "$dir/$libname$shrext.$ver" && acl_is_expected_elfclass < "$dir/$libname$shrext.$ver"; then
350 found_so="$dir/$libname$shrext.$ver"
353 eval library_names=\"$acl_library_names_spec\"
354 for f in $library_names; do
355 if test -f "$dir/$f" && acl_is_expected_elfclass < "$dir/$f"; then
364 dnl Then look for a static library.
365 if test "X$found_dir" = "X"; then
366 if test -f "$dir/$libname.$acl_libext" && ${AR-ar} -p "$dir/$libname.$acl_libext" | acl_is_expected_elfclass; then
368 found_a="$dir/$libname.$acl_libext"
371 if test "X$found_dir" != "X"; then
372 if test -f "$dir/$libname.la"; then
373 found_la="$dir/$libname.la"
378 if test "X$found_dir" != "X"; then
383 if test "X$found_dir" != "X"; then
384 dnl Found the library.
385 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name"
386 if test "X$found_so" != "X"; then
387 dnl Linking with a shared library. We attempt to hardcode its
388 dnl directory into the executable's runpath, unless it's the
389 dnl standard /usr/lib.
390 if test "$enable_rpath" = no \
391 || test "X$found_dir" = "X/usr/$acl_libdirstem" \
392 || test "X$found_dir" = "X/usr/$acl_libdirstem2" \
393 || test "X$found_dir" = "X/usr/$acl_libdirstem3"; then
394 dnl No hardcoding is needed.
395 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
397 dnl Use an explicit option to hardcode DIR into the resulting
399 dnl Potentially add DIR to ltrpathdirs.
400 dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
402 for x in $ltrpathdirs; do
403 if test "X$x" = "X$found_dir"; then
408 if test -z "$haveit"; then
409 ltrpathdirs="$ltrpathdirs $found_dir"
411 dnl The hardcoding into $LIBNAME is system dependent.
412 if test "$acl_hardcode_direct" = yes; then
413 dnl Using DIR/libNAME.so during linking hardcodes DIR into the
414 dnl resulting binary.
415 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
417 if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then
418 dnl Use an explicit option to hardcode DIR into the resulting
420 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
421 dnl Potentially add DIR to rpathdirs.
422 dnl The rpathdirs will be appended to $LIBNAME at the end.
424 for x in $rpathdirs; do
425 if test "X$x" = "X$found_dir"; then
430 if test -z "$haveit"; then
431 rpathdirs="$rpathdirs $found_dir"
434 dnl Rely on "-L$found_dir".
435 dnl But don't add it if it's already contained in the LDFLAGS
436 dnl or the already constructed $LIBNAME
438 for x in $LDFLAGS $LIB[]NAME; do
439 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
440 if test "X$x" = "X-L$found_dir"; then
445 if test -z "$haveit"; then
446 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir"
448 if test "$acl_hardcode_minus_L" != no; then
449 dnl FIXME: Not sure whether we should use
450 dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
452 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
454 dnl We cannot use $acl_hardcode_runpath_var and LD_RUN_PATH
455 dnl here, because this doesn't fit in flags passed to the
456 dnl compiler. So give up. No hardcoding. This affects only
457 dnl very old systems.
458 dnl FIXME: Not sure whether we should use
459 dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
461 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
467 if test "X$found_a" != "X"; then
468 dnl Linking with a static library.
469 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a"
471 dnl We shouldn't come here, but anyway it's good to have a
473 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name"
476 dnl Assume the include files are nearby.
477 additional_includedir=
479 */$acl_libdirstem | */$acl_libdirstem/)
480 basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'`
481 if test "$name" = '$1'; then
482 LIB[]NAME[]_PREFIX="$basedir"
484 additional_includedir="$basedir/include"
486 */$acl_libdirstem2 | */$acl_libdirstem2/)
487 basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem2/"'*$,,'`
488 if test "$name" = '$1'; then
489 LIB[]NAME[]_PREFIX="$basedir"
491 additional_includedir="$basedir/include"
493 */$acl_libdirstem3 | */$acl_libdirstem3/)
494 basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem3/"'*$,,'`
495 if test "$name" = '$1'; then
496 LIB[]NAME[]_PREFIX="$basedir"
498 additional_includedir="$basedir/include"
501 if test "X$additional_includedir" != "X"; then
502 dnl Potentially add $additional_includedir to $INCNAME.
504 dnl 1. if it's the standard /usr/include,
505 dnl 2. if it's /usr/local/include and we are using GCC on Linux,
506 dnl 3. if it's already present in $CPPFLAGS or the already
507 dnl constructed $INCNAME,
508 dnl 4. if it doesn't exist as a directory.
509 if test "X$additional_includedir" != "X/usr/include"; then
511 if test "X$additional_includedir" = "X/usr/local/include"; then
512 if test -n "$GCC"; then
514 linux* | gnu* | k*bsd*-gnu) haveit=yes;;
518 if test -z "$haveit"; then
519 for x in $CPPFLAGS $INC[]NAME; do
520 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
521 if test "X$x" = "X-I$additional_includedir"; then
526 if test -z "$haveit"; then
527 if test -d "$additional_includedir"; then
528 dnl Really add $additional_includedir to $INCNAME.
529 INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir"
535 dnl Look for dependencies.
536 if test -n "$found_la"; then
537 dnl Read the .la file. It defines the variables
538 dnl dlname, library_names, old_library, dependency_libs, current,
539 dnl age, revision, installed, dlopen, dlpreopen, libdir.
540 save_libdir="$libdir"
542 */* | *\\*) . "$found_la" ;;
543 *) . "./$found_la" ;;
545 libdir="$save_libdir"
546 dnl We use only dependency_libs.
547 for dep in $dependency_libs; do
550 dependency_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
551 dnl Potentially add $dependency_libdir to $LIBNAME and $LTLIBNAME.
553 dnl 1. if it's the standard /usr/lib,
554 dnl 2. if it's /usr/local/lib and we are using GCC on Linux,
555 dnl 3. if it's already present in $LDFLAGS or the already
556 dnl constructed $LIBNAME,
557 dnl 4. if it doesn't exist as a directory.
558 if test "X$dependency_libdir" != "X/usr/$acl_libdirstem" \
559 && test "X$dependency_libdir" != "X/usr/$acl_libdirstem2" \
560 && test "X$dependency_libdir" != "X/usr/$acl_libdirstem3"; then
562 if test "X$dependency_libdir" = "X/usr/local/$acl_libdirstem" \
563 || test "X$dependency_libdir" = "X/usr/local/$acl_libdirstem2" \
564 || test "X$dependency_libdir" = "X/usr/local/$acl_libdirstem3"; then
565 if test -n "$GCC"; then
567 linux* | gnu* | k*bsd*-gnu) haveit=yes;;
571 if test -z "$haveit"; then
573 for x in $LDFLAGS $LIB[]NAME; do
574 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
575 if test "X$x" = "X-L$dependency_libdir"; then
580 if test -z "$haveit"; then
581 if test -d "$dependency_libdir"; then
582 dnl Really add $dependency_libdir to $LIBNAME.
583 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$dependency_libdir"
587 for x in $LDFLAGS $LTLIB[]NAME; do
588 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
589 if test "X$x" = "X-L$dependency_libdir"; then
594 if test -z "$haveit"; then
595 if test -d "$dependency_libdir"; then
596 dnl Really add $dependency_libdir to $LTLIBNAME.
597 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$dependency_libdir"
604 dir=`echo "X$dep" | sed -e 's/^X-R//'`
605 if test "$enable_rpath" != no; then
606 dnl Potentially add DIR to rpathdirs.
607 dnl The rpathdirs will be appended to $LIBNAME at the end.
609 for x in $rpathdirs; do
610 if test "X$x" = "X$dir"; then
615 if test -z "$haveit"; then
616 rpathdirs="$rpathdirs $dir"
618 dnl Potentially add DIR to ltrpathdirs.
619 dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
621 for x in $ltrpathdirs; do
622 if test "X$x" = "X$dir"; then
627 if test -z "$haveit"; then
628 ltrpathdirs="$ltrpathdirs $dir"
633 dnl Handle this in the next round.
634 names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
637 dnl Handle this in the next round. Throw away the .la's
638 dnl directory; it is already contained in a preceding -L
640 names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
643 dnl Most likely an immediate library name.
644 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep"
645 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep"
651 dnl Didn't find the library; assume it is in the system directories
652 dnl known to the linker and runtime loader. (All the system
653 dnl directories known to the linker should also be known to the
654 dnl runtime loader, otherwise the system is severely misconfigured.)
655 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
656 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name"
662 if test "X$rpathdirs" != "X"; then
663 if test -n "$acl_hardcode_libdir_separator"; then
664 dnl Weird platform: only the last -rpath option counts, the user must
665 dnl pass all path elements in one option. We can arrange that for a
666 dnl single library, but not when more than one $LIBNAMEs are used.
668 for found_dir in $rpathdirs; do
669 alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$found_dir"
671 dnl Note: acl_hardcode_libdir_flag_spec uses $libdir and $wl.
672 acl_save_libdir="$libdir"
674 eval flag=\"$acl_hardcode_libdir_flag_spec\"
675 libdir="$acl_save_libdir"
676 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
678 dnl The -rpath options are cumulative.
679 for found_dir in $rpathdirs; do
680 acl_save_libdir="$libdir"
682 eval flag=\"$acl_hardcode_libdir_flag_spec\"
683 libdir="$acl_save_libdir"
684 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
688 if test "X$ltrpathdirs" != "X"; then
689 dnl When using libtool, the option that works for both libraries and
690 dnl executables is -R. The -R options are cumulative.
691 for found_dir in $ltrpathdirs; do
692 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir"
701 dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR,
702 dnl unless already present in VAR.
703 dnl Works only for CPPFLAGS, not for LIB* variables because that sometimes
704 dnl contains two or three consecutive elements that belong together.
705 AC_DEFUN([AC_LIB_APPENDTOVAR],
707 for element in [$2]; do
710 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
711 if test "X$x" = "X$element"; then
716 if test -z "$haveit"; then
717 [$1]="${[$1]}${[$1]:+ }$element"
722 dnl For those cases where a variable contains several -L and -l options
723 dnl referring to unknown libraries and directories, this macro determines the
724 dnl necessary additional linker options for the runtime path.
725 dnl AC_LIB_LINKFLAGS_FROM_LIBS([LDADDVAR], [LIBSVALUE], [USE-LIBTOOL])
726 dnl sets LDADDVAR to linker options needed together with LIBSVALUE.
727 dnl If USE-LIBTOOL evaluates to non-empty, linking with libtool is assumed,
728 dnl otherwise linking without libtool is assumed.
729 AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS],
731 AC_REQUIRE([AC_LIB_RPATH])
732 AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
734 if test "$enable_rpath" != no; then
735 if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then
736 dnl Use an explicit option to hardcode directories into the resulting
741 if test -n "$next"; then
743 dnl No need to hardcode the standard /usr/lib.
744 if test "X$dir" != "X/usr/$acl_libdirstem" \
745 && test "X$dir" != "X/usr/$acl_libdirstem2" \
746 && test "X$dir" != "X/usr/$acl_libdirstem3"; then
747 rpathdirs="$rpathdirs $dir"
753 -L*) dir=`echo "X$opt" | sed -e 's,^X-L,,'`
754 dnl No need to hardcode the standard /usr/lib.
755 if test "X$dir" != "X/usr/$acl_libdirstem" \
756 && test "X$dir" != "X/usr/$acl_libdirstem2" \
757 && test "X$dir" != "X/usr/$acl_libdirstem3"; then
758 rpathdirs="$rpathdirs $dir"
765 if test "X$rpathdirs" != "X"; then
766 if test -n ""$3""; then
767 dnl libtool is used for linking. Use -R options.
768 for dir in $rpathdirs; do
769 $1="${$1}${$1:+ }-R$dir"
772 dnl The linker is used for linking directly.
773 if test -n "$acl_hardcode_libdir_separator"; then
774 dnl Weird platform: only the last -rpath option counts, the user
775 dnl must pass all path elements in one option.
777 for dir in $rpathdirs; do
778 alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$dir"
780 acl_save_libdir="$libdir"
782 eval flag=\"$acl_hardcode_libdir_flag_spec\"
783 libdir="$acl_save_libdir"
786 dnl The -rpath options are cumulative.
787 for dir in $rpathdirs; do
788 acl_save_libdir="$libdir"
790 eval flag=\"$acl_hardcode_libdir_flag_spec\"
791 libdir="$acl_save_libdir"
792 $1="${$1}${$1:+ }$flag"