Debian Codegraph @

m4/lib-link.m4

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