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