Update `NEWS'.
[bpt/guile.git] / m4 / lib-link.m4
CommitLineData
24d56127
LC
1# lib-link.m4 serial 19 (gettext-0.18)
2dnl Copyright (C) 2001-2009 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7dnl From Bruno Haible.
8
9AC_PREREQ([2.54])
10
11dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and
12dnl the libraries corresponding to explicit and implicit dependencies.
13dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and
14dnl augments the CPPFLAGS variable.
15dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname
16dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
17AC_DEFUN([AC_LIB_LINKFLAGS],
18[
19 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
20 AC_REQUIRE([AC_LIB_RPATH])
21 pushdef([Name],[translit([$1],[./-], [___])])
22 pushdef([NAME],[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"
30 ])
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)
36 AC_SUBST([LIB]NAME)
37 AC_SUBST([LTLIB]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.
41 HAVE_LIB[]NAME=yes
42 popdef([NAME])
43 popdef([Name])
44])
45
46dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode, [missing-message])
47dnl searches for libname and the libraries corresponding to explicit and
48dnl implicit dependencies, together with the specified include files and
49dnl the ability to compile and link the specified testcode. The missing-message
50dnl defaults to 'no' and may contain additional hints for the user.
51dnl If found, it sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME}
52dnl and LTLIB${NAME} variables and augments the CPPFLAGS variable, and
53dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs
54dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty.
55dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname
56dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
57AC_DEFUN([AC_LIB_HAVE_LINKFLAGS],
58[
59 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
60 AC_REQUIRE([AC_LIB_RPATH])
61 pushdef([Name],[translit([$1],[./-], [___])])
62 pushdef([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
63 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
64
65 dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME
66 dnl accordingly.
67 AC_LIB_LINKFLAGS_BODY([$1], [$2])
68
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)
74
75 AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [
76 ac_save_LIBS="$LIBS"
77 LIBS="$LIBS $LIB[]NAME"
78 AC_TRY_LINK([$3], [$4],
79 [ac_cv_lib[]Name=yes],
80 [ac_cv_lib[]Name='m4_if([$5], [], [no], [[$5]])'])
81 LIBS="$ac_save_LIBS"
82 ])
83 if test "$ac_cv_lib[]Name" = yes; then
84 HAVE_LIB[]NAME=yes
85 AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the lib[]$1 library.])
86 AC_MSG_CHECKING([how to link with lib[]$1])
87 AC_MSG_RESULT([$LIB[]NAME])
88 else
89 HAVE_LIB[]NAME=no
90 dnl If $LIB[]NAME didn't lead to a usable library, we don't need
91 dnl $INC[]NAME either.
92 CPPFLAGS="$ac_save_CPPFLAGS"
93 LIB[]NAME=
94 LTLIB[]NAME=
95 LIB[]NAME[]_PREFIX=
96 fi
97 AC_SUBST([HAVE_LIB]NAME)
98 AC_SUBST([LIB]NAME)
99 AC_SUBST([LTLIB]NAME)
100 AC_SUBST([LIB]NAME[_PREFIX])
101 popdef([NAME])
102 popdef([Name])
103])
104
105dnl Determine the platform dependent parameters needed to use rpath:
106dnl acl_libext,
107dnl acl_shlibext,
108dnl acl_hardcode_libdir_flag_spec,
109dnl acl_hardcode_libdir_separator,
110dnl acl_hardcode_direct,
111dnl acl_hardcode_minus_L.
112AC_DEFUN([AC_LIB_RPATH],
113[
114 dnl Tell automake >= 1.10 to complain if config.rpath is missing.
115 m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([config.rpath])])
116 AC_REQUIRE([AC_PROG_CC]) dnl we use $CC, $GCC, $LDFLAGS
117 AC_REQUIRE([AC_LIB_PROG_LD]) dnl we use $LD, $with_gnu_ld
118 AC_REQUIRE([AC_CANONICAL_HOST]) dnl we use $host
119 AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir
120 AC_CACHE_CHECK([for shared library run path origin], [acl_cv_rpath], [
121 CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \
122 ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh
123 . ./conftest.sh
124 rm -f ./conftest.sh
125 acl_cv_rpath=done
126 ])
127 wl="$acl_cv_wl"
128 acl_libext="$acl_cv_libext"
129 acl_shlibext="$acl_cv_shlibext"
130 acl_libname_spec="$acl_cv_libname_spec"
131 acl_library_names_spec="$acl_cv_library_names_spec"
132 acl_hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec"
133 acl_hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator"
134 acl_hardcode_direct="$acl_cv_hardcode_direct"
135 acl_hardcode_minus_L="$acl_cv_hardcode_minus_L"
136 dnl Determine whether the user wants rpath handling at all.
137 AC_ARG_ENABLE([rpath],
138 [ --disable-rpath do not hardcode runtime library paths],
139 :, enable_rpath=yes)
140])
141
142dnl AC_LIB_FROMPACKAGE(name, package)
143dnl declares that libname comes from the given package. The configure file
144dnl will then not have a --with-libname-prefix option but a
145dnl --with-package-prefix option. Several libraries can come from the same
146dnl package. This declaration must occur before an AC_LIB_LINKFLAGS or similar
147dnl macro call that searches for libname.
148AC_DEFUN([AC_LIB_FROMPACKAGE],
149[
150 pushdef([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
151 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
152 define([acl_frompackage_]NAME, [$2])
153 popdef([NAME])
154 pushdef([PACK],[$2])
155 pushdef([PACKUP],[translit(PACK,[abcdefghijklmnopqrstuvwxyz./-],
156 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
157 define([acl_libsinpackage_]PACKUP,
158 m4_ifdef([acl_libsinpackage_]PACKUP, [acl_libsinpackage_]PACKUP[[, ]],)[lib$1])
159 popdef([PACKUP])
160 popdef([PACK])
161])
162
163dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and
164dnl the libraries corresponding to explicit and implicit dependencies.
165dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables.
166dnl Also, sets the LIB${NAME}_PREFIX variable to nonempty if libname was found
167dnl in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
168AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
169[
170 AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
171 pushdef([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
172 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
173 pushdef([PACK],[m4_ifdef([acl_frompackage_]NAME, [acl_frompackage_]NAME, lib[$1])])
174 pushdef([PACKUP],[translit(PACK,[abcdefghijklmnopqrstuvwxyz./-],
175 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
176 pushdef([PACKLIBS],[m4_ifdef([acl_frompackage_]NAME, [acl_libsinpackage_]PACKUP, lib[$1])])
177 dnl Autoconf >= 2.61 supports dots in --with options.
178 pushdef([P_A_C_K],[m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.61]),[-1],[translit(PACK,[.],[_])],PACK)])
179 dnl By default, look in $includedir and $libdir.
180 use_additional=yes
181 AC_LIB_WITH_FINAL_PREFIX([
182 eval additional_includedir=\"$includedir\"
183 eval additional_libdir=\"$libdir\"
184 ])
185 AC_ARG_WITH(P_A_C_K[-prefix],
186[[ --with-]]P_A_C_K[[-prefix[=DIR] search for ]PACKLIBS[ in DIR/include and DIR/lib
187 --without-]]P_A_C_K[[-prefix don't search for ]PACKLIBS[ in includedir and libdir]],
188[
189 if test "X$withval" = "Xno"; then
190 use_additional=no
191 else
192 if test "X$withval" = "X"; then
193 AC_LIB_WITH_FINAL_PREFIX([
194 eval additional_includedir=\"$includedir\"
195 eval additional_libdir=\"$libdir\"
196 ])
197 else
198 additional_includedir="$withval/include"
199 additional_libdir="$withval/$acl_libdirstem"
200 if test "$acl_libdirstem2" != "$acl_libdirstem" \
201 && ! test -d "$withval/$acl_libdirstem"; then
202 additional_libdir="$withval/$acl_libdirstem2"
203 fi
204 fi
205 fi
206])
207 dnl Search the library and its dependencies in $additional_libdir and
208 dnl $LDFLAGS. Using breadth-first-seach.
209 LIB[]NAME=
210 LTLIB[]NAME=
211 INC[]NAME=
212 LIB[]NAME[]_PREFIX=
213 rpathdirs=
214 ltrpathdirs=
215 names_already_handled=
216 names_next_round='$1 $2'
217 while test -n "$names_next_round"; do
218 names_this_round="$names_next_round"
219 names_next_round=
220 for name in $names_this_round; do
221 already_handled=
222 for n in $names_already_handled; do
223 if test "$n" = "$name"; then
224 already_handled=yes
225 break
226 fi
227 done
228 if test -z "$already_handled"; then
229 names_already_handled="$names_already_handled $name"
230 dnl See if it was already located by an earlier AC_LIB_LINKFLAGS
231 dnl or AC_LIB_HAVE_LINKFLAGS call.
232 uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'`
233 eval value=\"\$HAVE_LIB$uppername\"
234 if test -n "$value"; then
235 if test "$value" = yes; then
236 eval value=\"\$LIB$uppername\"
237 test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value"
238 eval value=\"\$LTLIB$uppername\"
239 test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value"
240 else
241 dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined
242 dnl that this library doesn't exist. So just drop it.
243 :
244 fi
245 else
246 dnl Search the library lib$name in $additional_libdir and $LDFLAGS
247 dnl and the already constructed $LIBNAME/$LTLIBNAME.
248 found_dir=
249 found_la=
250 found_so=
251 found_a=
252 eval libname=\"$acl_libname_spec\" # typically: libname=lib$name
253 if test -n "$acl_shlibext"; then
254 shrext=".$acl_shlibext" # typically: shrext=.so
255 else
256 shrext=
257 fi
258 if test $use_additional = yes; then
259 dir="$additional_libdir"
260 dnl The same code as in the loop below:
261 dnl First look for a shared library.
262 if test -n "$acl_shlibext"; then
263 if test -f "$dir/$libname$shrext"; then
264 found_dir="$dir"
265 found_so="$dir/$libname$shrext"
266 else
267 if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then
268 ver=`(cd "$dir" && \
269 for f in "$libname$shrext".*; do echo "$f"; done \
270 | sed -e "s,^$libname$shrext\\\\.,," \
271 | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \
272 | sed 1q ) 2>/dev/null`
273 if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then
274 found_dir="$dir"
275 found_so="$dir/$libname$shrext.$ver"
276 fi
277 else
278 eval library_names=\"$acl_library_names_spec\"
279 for f in $library_names; do
280 if test -f "$dir/$f"; then
281 found_dir="$dir"
282 found_so="$dir/$f"
283 break
284 fi
285 done
286 fi
287 fi
288 fi
289 dnl Then look for a static library.
290 if test "X$found_dir" = "X"; then
291 if test -f "$dir/$libname.$acl_libext"; then
292 found_dir="$dir"
293 found_a="$dir/$libname.$acl_libext"
294 fi
295 fi
296 if test "X$found_dir" != "X"; then
297 if test -f "$dir/$libname.la"; then
298 found_la="$dir/$libname.la"
299 fi
300 fi
301 fi
302 if test "X$found_dir" = "X"; then
303 for x in $LDFLAGS $LTLIB[]NAME; do
304 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
305 case "$x" in
306 -L*)
307 dir=`echo "X$x" | sed -e 's/^X-L//'`
308 dnl First look for a shared library.
309 if test -n "$acl_shlibext"; then
310 if test -f "$dir/$libname$shrext"; then
311 found_dir="$dir"
312 found_so="$dir/$libname$shrext"
313 else
314 if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then
315 ver=`(cd "$dir" && \
316 for f in "$libname$shrext".*; do echo "$f"; done \
317 | sed -e "s,^$libname$shrext\\\\.,," \
318 | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \
319 | sed 1q ) 2>/dev/null`
320 if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then
321 found_dir="$dir"
322 found_so="$dir/$libname$shrext.$ver"
323 fi
324 else
325 eval library_names=\"$acl_library_names_spec\"
326 for f in $library_names; do
327 if test -f "$dir/$f"; then
328 found_dir="$dir"
329 found_so="$dir/$f"
330 break
331 fi
332 done
333 fi
334 fi
335 fi
336 dnl Then look for a static library.
337 if test "X$found_dir" = "X"; then
338 if test -f "$dir/$libname.$acl_libext"; then
339 found_dir="$dir"
340 found_a="$dir/$libname.$acl_libext"
341 fi
342 fi
343 if test "X$found_dir" != "X"; then
344 if test -f "$dir/$libname.la"; then
345 found_la="$dir/$libname.la"
346 fi
347 fi
348 ;;
349 esac
350 if test "X$found_dir" != "X"; then
351 break
352 fi
353 done
354 fi
355 if test "X$found_dir" != "X"; then
356 dnl Found the library.
357 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name"
358 if test "X$found_so" != "X"; then
359 dnl Linking with a shared library. We attempt to hardcode its
360 dnl directory into the executable's runpath, unless it's the
361 dnl standard /usr/lib.
362 if test "$enable_rpath" = no \
363 || test "X$found_dir" = "X/usr/$acl_libdirstem" \
364 || test "X$found_dir" = "X/usr/$acl_libdirstem2"; then
365 dnl No hardcoding is needed.
366 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
367 else
368 dnl Use an explicit option to hardcode DIR into the resulting
369 dnl binary.
370 dnl Potentially add DIR to ltrpathdirs.
371 dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
372 haveit=
373 for x in $ltrpathdirs; do
374 if test "X$x" = "X$found_dir"; then
375 haveit=yes
376 break
377 fi
378 done
379 if test -z "$haveit"; then
380 ltrpathdirs="$ltrpathdirs $found_dir"
381 fi
382 dnl The hardcoding into $LIBNAME is system dependent.
383 if test "$acl_hardcode_direct" = yes; then
384 dnl Using DIR/libNAME.so during linking hardcodes DIR into the
385 dnl resulting binary.
386 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
387 else
388 if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then
389 dnl Use an explicit option to hardcode DIR into the resulting
390 dnl binary.
391 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
392 dnl Potentially add DIR to rpathdirs.
393 dnl The rpathdirs will be appended to $LIBNAME at the end.
394 haveit=
395 for x in $rpathdirs; do
396 if test "X$x" = "X$found_dir"; then
397 haveit=yes
398 break
399 fi
400 done
401 if test -z "$haveit"; then
402 rpathdirs="$rpathdirs $found_dir"
403 fi
404 else
405 dnl Rely on "-L$found_dir".
406 dnl But don't add it if it's already contained in the LDFLAGS
407 dnl or the already constructed $LIBNAME
408 haveit=
409 for x in $LDFLAGS $LIB[]NAME; do
410 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
411 if test "X$x" = "X-L$found_dir"; then
412 haveit=yes
413 break
414 fi
415 done
416 if test -z "$haveit"; then
417 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir"
418 fi
419 if test "$acl_hardcode_minus_L" != no; then
420 dnl FIXME: Not sure whether we should use
421 dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
422 dnl here.
423 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
424 else
425 dnl We cannot use $acl_hardcode_runpath_var and LD_RUN_PATH
426 dnl here, because this doesn't fit in flags passed to the
427 dnl compiler. So give up. No hardcoding. This affects only
428 dnl very old systems.
429 dnl FIXME: Not sure whether we should use
430 dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
431 dnl here.
432 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
433 fi
434 fi
435 fi
436 fi
437 else
438 if test "X$found_a" != "X"; then
439 dnl Linking with a static library.
440 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a"
441 else
442 dnl We shouldn't come here, but anyway it's good to have a
443 dnl fallback.
444 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name"
445 fi
446 fi
447 dnl Assume the include files are nearby.
448 additional_includedir=
449 case "$found_dir" in
450 */$acl_libdirstem | */$acl_libdirstem/)
451 basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'`
452 if test "$name" = '$1'; then
453 LIB[]NAME[]_PREFIX="$basedir"
454 fi
455 additional_includedir="$basedir/include"
456 ;;
457 */$acl_libdirstem2 | */$acl_libdirstem2/)
458 basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem2/"'*$,,'`
459 if test "$name" = '$1'; then
460 LIB[]NAME[]_PREFIX="$basedir"
461 fi
462 additional_includedir="$basedir/include"
463 ;;
464 esac
465 if test "X$additional_includedir" != "X"; then
466 dnl Potentially add $additional_includedir to $INCNAME.
467 dnl But don't add it
468 dnl 1. if it's the standard /usr/include,
469 dnl 2. if it's /usr/local/include and we are using GCC on Linux,
470 dnl 3. if it's already present in $CPPFLAGS or the already
471 dnl constructed $INCNAME,
472 dnl 4. if it doesn't exist as a directory.
473 if test "X$additional_includedir" != "X/usr/include"; then
474 haveit=
475 if test "X$additional_includedir" = "X/usr/local/include"; then
476 if test -n "$GCC"; then
477 case $host_os in
478 linux* | gnu* | k*bsd*-gnu) haveit=yes;;
479 esac
480 fi
481 fi
482 if test -z "$haveit"; then
483 for x in $CPPFLAGS $INC[]NAME; do
484 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
485 if test "X$x" = "X-I$additional_includedir"; then
486 haveit=yes
487 break
488 fi
489 done
490 if test -z "$haveit"; then
491 if test -d "$additional_includedir"; then
492 dnl Really add $additional_includedir to $INCNAME.
493 INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir"
494 fi
495 fi
496 fi
497 fi
498 fi
499 dnl Look for dependencies.
500 if test -n "$found_la"; then
501 dnl Read the .la file. It defines the variables
502 dnl dlname, library_names, old_library, dependency_libs, current,
503 dnl age, revision, installed, dlopen, dlpreopen, libdir.
504 save_libdir="$libdir"
505 case "$found_la" in
506 */* | *\\*) . "$found_la" ;;
507 *) . "./$found_la" ;;
508 esac
509 libdir="$save_libdir"
510 dnl We use only dependency_libs.
511 for dep in $dependency_libs; do
512 case "$dep" in
513 -L*)
514 additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
515 dnl Potentially add $additional_libdir to $LIBNAME and $LTLIBNAME.
516 dnl But don't add it
517 dnl 1. if it's the standard /usr/lib,
518 dnl 2. if it's /usr/local/lib and we are using GCC on Linux,
519 dnl 3. if it's already present in $LDFLAGS or the already
520 dnl constructed $LIBNAME,
521 dnl 4. if it doesn't exist as a directory.
522 if test "X$additional_libdir" != "X/usr/$acl_libdirstem" \
523 && test "X$additional_libdir" != "X/usr/$acl_libdirstem2"; then
524 haveit=
525 if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem" \
526 || test "X$additional_libdir" = "X/usr/local/$acl_libdirstem2"; then
527 if test -n "$GCC"; then
528 case $host_os in
529 linux* | gnu* | k*bsd*-gnu) haveit=yes;;
530 esac
531 fi
532 fi
533 if test -z "$haveit"; then
534 haveit=
535 for x in $LDFLAGS $LIB[]NAME; do
536 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
537 if test "X$x" = "X-L$additional_libdir"; then
538 haveit=yes
539 break
540 fi
541 done
542 if test -z "$haveit"; then
543 if test -d "$additional_libdir"; then
544 dnl Really add $additional_libdir to $LIBNAME.
545 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$additional_libdir"
546 fi
547 fi
548 haveit=
549 for x in $LDFLAGS $LTLIB[]NAME; do
550 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
551 if test "X$x" = "X-L$additional_libdir"; then
552 haveit=yes
553 break
554 fi
555 done
556 if test -z "$haveit"; then
557 if test -d "$additional_libdir"; then
558 dnl Really add $additional_libdir to $LTLIBNAME.
559 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$additional_libdir"
560 fi
561 fi
562 fi
563 fi
564 ;;
565 -R*)
566 dir=`echo "X$dep" | sed -e 's/^X-R//'`
567 if test "$enable_rpath" != no; then
568 dnl Potentially add DIR to rpathdirs.
569 dnl The rpathdirs will be appended to $LIBNAME at the end.
570 haveit=
571 for x in $rpathdirs; do
572 if test "X$x" = "X$dir"; then
573 haveit=yes
574 break
575 fi
576 done
577 if test -z "$haveit"; then
578 rpathdirs="$rpathdirs $dir"
579 fi
580 dnl Potentially add DIR to ltrpathdirs.
581 dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
582 haveit=
583 for x in $ltrpathdirs; do
584 if test "X$x" = "X$dir"; then
585 haveit=yes
586 break
587 fi
588 done
589 if test -z "$haveit"; then
590 ltrpathdirs="$ltrpathdirs $dir"
591 fi
592 fi
593 ;;
594 -l*)
595 dnl Handle this in the next round.
596 names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
597 ;;
598 *.la)
599 dnl Handle this in the next round. Throw away the .la's
600 dnl directory; it is already contained in a preceding -L
601 dnl option.
602 names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
603 ;;
604 *)
605 dnl Most likely an immediate library name.
606 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep"
607 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep"
608 ;;
609 esac
610 done
611 fi
612 else
613 dnl Didn't find the library; assume it is in the system directories
614 dnl known to the linker and runtime loader. (All the system
615 dnl directories known to the linker should also be known to the
616 dnl runtime loader, otherwise the system is severely misconfigured.)
617 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
618 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name"
619 fi
620 fi
621 fi
622 done
623 done
624 if test "X$rpathdirs" != "X"; then
625 if test -n "$acl_hardcode_libdir_separator"; then
626 dnl Weird platform: only the last -rpath option counts, the user must
627 dnl pass all path elements in one option. We can arrange that for a
628 dnl single library, but not when more than one $LIBNAMEs are used.
629 alldirs=
630 for found_dir in $rpathdirs; do
631 alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$found_dir"
632 done
633 dnl Note: acl_hardcode_libdir_flag_spec uses $libdir and $wl.
634 acl_save_libdir="$libdir"
635 libdir="$alldirs"
636 eval flag=\"$acl_hardcode_libdir_flag_spec\"
637 libdir="$acl_save_libdir"
638 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
639 else
640 dnl The -rpath options are cumulative.
641 for found_dir in $rpathdirs; do
642 acl_save_libdir="$libdir"
643 libdir="$found_dir"
644 eval flag=\"$acl_hardcode_libdir_flag_spec\"
645 libdir="$acl_save_libdir"
646 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
647 done
648 fi
649 fi
650 if test "X$ltrpathdirs" != "X"; then
651 dnl When using libtool, the option that works for both libraries and
652 dnl executables is -R. The -R options are cumulative.
653 for found_dir in $ltrpathdirs; do
654 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir"
655 done
656 fi
657 popdef([P_A_C_K])
658 popdef([PACKLIBS])
659 popdef([PACKUP])
660 popdef([PACK])
661 popdef([NAME])
662])
663
664dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR,
665dnl unless already present in VAR.
666dnl Works only for CPPFLAGS, not for LIB* variables because that sometimes
667dnl contains two or three consecutive elements that belong together.
668AC_DEFUN([AC_LIB_APPENDTOVAR],
669[
670 for element in [$2]; do
671 haveit=
672 for x in $[$1]; do
673 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
674 if test "X$x" = "X$element"; then
675 haveit=yes
676 break
677 fi
678 done
679 if test -z "$haveit"; then
680 [$1]="${[$1]}${[$1]:+ }$element"
681 fi
682 done
683])
684
685dnl For those cases where a variable contains several -L and -l options
686dnl referring to unknown libraries and directories, this macro determines the
687dnl necessary additional linker options for the runtime path.
688dnl AC_LIB_LINKFLAGS_FROM_LIBS([LDADDVAR], [LIBSVALUE], [USE-LIBTOOL])
689dnl sets LDADDVAR to linker options needed together with LIBSVALUE.
690dnl If USE-LIBTOOL evaluates to non-empty, linking with libtool is assumed,
691dnl otherwise linking without libtool is assumed.
692AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS],
693[
694 AC_REQUIRE([AC_LIB_RPATH])
695 AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
696 $1=
697 if test "$enable_rpath" != no; then
698 if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then
699 dnl Use an explicit option to hardcode directories into the resulting
700 dnl binary.
701 rpathdirs=
702 next=
703 for opt in $2; do
704 if test -n "$next"; then
705 dir="$next"
706 dnl No need to hardcode the standard /usr/lib.
707 if test "X$dir" != "X/usr/$acl_libdirstem" \
708 && test "X$dir" != "X/usr/$acl_libdirstem2"; then
709 rpathdirs="$rpathdirs $dir"
710 fi
711 next=
712 else
713 case $opt in
714 -L) next=yes ;;
715 -L*) dir=`echo "X$opt" | sed -e 's,^X-L,,'`
716 dnl No need to hardcode the standard /usr/lib.
717 if test "X$dir" != "X/usr/$acl_libdirstem" \
718 && test "X$dir" != "X/usr/$acl_libdirstem2"; then
719 rpathdirs="$rpathdirs $dir"
720 fi
721 next= ;;
722 *) next= ;;
723 esac
724 fi
725 done
726 if test "X$rpathdirs" != "X"; then
727 if test -n ""$3""; then
728 dnl libtool is used for linking. Use -R options.
729 for dir in $rpathdirs; do
730 $1="${$1}${$1:+ }-R$dir"
731 done
732 else
733 dnl The linker is used for linking directly.
734 if test -n "$acl_hardcode_libdir_separator"; then
735 dnl Weird platform: only the last -rpath option counts, the user
736 dnl must pass all path elements in one option.
737 alldirs=
738 for dir in $rpathdirs; do
739 alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$dir"
740 done
741 acl_save_libdir="$libdir"
742 libdir="$alldirs"
743 eval flag=\"$acl_hardcode_libdir_flag_spec\"
744 libdir="$acl_save_libdir"
745 $1="$flag"
746 else
747 dnl The -rpath options are cumulative.
748 for dir in $rpathdirs; do
749 acl_save_libdir="$libdir"
750 libdir="$dir"
751 eval flag=\"$acl_hardcode_libdir_flag_spec\"
752 libdir="$acl_save_libdir"
753 $1="${$1}${$1:+ }$flag"
754 done
755 fi
756 fi
757 fi
758 fi
759 fi
760 AC_SUBST([$1])
761])