Support for library names with dots.
[gnulib.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.54)
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 Autoconf >= 2.61 supports dots in --with options.
133   define([N_A_M_E],[m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.61]),[-1],[translit([$1],[.],[_])],[$1])])
134   dnl By default, look in $includedir and $libdir.
135   use_additional=yes
136   AC_LIB_WITH_FINAL_PREFIX([
137     eval additional_includedir=\"$includedir\"
138     eval additional_libdir=\"$libdir\"
139   ])
140   AC_LIB_ARG_WITH([lib]N_A_M_E[-prefix],
141 [  --with-lib]N_A_M_E[-prefix[=DIR]  search for lib$1 in DIR/include and DIR/lib
142   --without-lib]N_A_M_E[-prefix     don't search for lib$1 in includedir and libdir],
143 [
144     if test "X$withval" = "Xno"; then
145       use_additional=no
146     else
147       if test "X$withval" = "X"; then
148         AC_LIB_WITH_FINAL_PREFIX([
149           eval additional_includedir=\"$includedir\"
150           eval additional_libdir=\"$libdir\"
151         ])
152       else
153         additional_includedir="$withval/include"
154         additional_libdir="$withval/$acl_libdirstem"
155       fi
156     fi
157 ])
158   dnl Search the library and its dependencies in $additional_libdir and
159   dnl $LDFLAGS. Using breadth-first-seach.
160   LIB[]NAME=
161   LTLIB[]NAME=
162   INC[]NAME=
163   rpathdirs=
164   ltrpathdirs=
165   names_already_handled=
166   names_next_round='$1 $2'
167   while test -n "$names_next_round"; do
168     names_this_round="$names_next_round"
169     names_next_round=
170     for name in $names_this_round; do
171       already_handled=
172       for n in $names_already_handled; do
173         if test "$n" = "$name"; then
174           already_handled=yes
175           break
176         fi
177       done
178       if test -z "$already_handled"; then
179         names_already_handled="$names_already_handled $name"
180         dnl See if it was already located by an earlier AC_LIB_LINKFLAGS
181         dnl or AC_LIB_HAVE_LINKFLAGS call.
182         uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'`
183         eval value=\"\$HAVE_LIB$uppername\"
184         if test -n "$value"; then
185           if test "$value" = yes; then
186             eval value=\"\$LIB$uppername\"
187             test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value"
188             eval value=\"\$LTLIB$uppername\"
189             test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value"
190           else
191             dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined
192             dnl that this library doesn't exist. So just drop it.
193             :
194           fi
195         else
196           dnl Search the library lib$name in $additional_libdir and $LDFLAGS
197           dnl and the already constructed $LIBNAME/$LTLIBNAME.
198           found_dir=
199           found_la=
200           found_so=
201           found_a=
202           if test $use_additional = yes; then
203             if test -n "$shlibext" \
204                && { test -f "$additional_libdir/lib$name.$shlibext" \
205                     || { test "$shlibext" = dll \
206                          && test -f "$additional_libdir/lib$name.dll.a"; }; }; then
207               found_dir="$additional_libdir"
208               if test -f "$additional_libdir/lib$name.$shlibext"; then
209                 found_so="$additional_libdir/lib$name.$shlibext"
210               else
211                 found_so="$additional_libdir/lib$name.dll.a"
212               fi
213               if test -f "$additional_libdir/lib$name.la"; then
214                 found_la="$additional_libdir/lib$name.la"
215               fi
216             else
217               if test -f "$additional_libdir/lib$name.$libext"; then
218                 found_dir="$additional_libdir"
219                 found_a="$additional_libdir/lib$name.$libext"
220                 if test -f "$additional_libdir/lib$name.la"; then
221                   found_la="$additional_libdir/lib$name.la"
222                 fi
223               fi
224             fi
225           fi
226           if test "X$found_dir" = "X"; then
227             for x in $LDFLAGS $LTLIB[]NAME; do
228               AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
229               case "$x" in
230                 -L*)
231                   dir=`echo "X$x" | sed -e 's/^X-L//'`
232                   if test -n "$shlibext" \
233                      && { test -f "$dir/lib$name.$shlibext" \
234                           || { test "$shlibext" = dll \
235                                && test -f "$dir/lib$name.dll.a"; }; }; then
236                     found_dir="$dir"
237                     if test -f "$dir/lib$name.$shlibext"; then
238                       found_so="$dir/lib$name.$shlibext"
239                     else
240                       found_so="$dir/lib$name.dll.a"
241                     fi
242                     if test -f "$dir/lib$name.la"; then
243                       found_la="$dir/lib$name.la"
244                     fi
245                   else
246                     if test -f "$dir/lib$name.$libext"; then
247                       found_dir="$dir"
248                       found_a="$dir/lib$name.$libext"
249                       if test -f "$dir/lib$name.la"; then
250                         found_la="$dir/lib$name.la"
251                       fi
252                     fi
253                   fi
254                   ;;
255               esac
256               if test "X$found_dir" != "X"; then
257                 break
258               fi
259             done
260           fi
261           if test "X$found_dir" != "X"; then
262             dnl Found the library.
263             LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name"
264             if test "X$found_so" != "X"; then
265               dnl Linking with a shared library. We attempt to hardcode its
266               dnl directory into the executable's runpath, unless it's the
267               dnl standard /usr/lib.
268               if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/$acl_libdirstem"; then
269                 dnl No hardcoding is needed.
270                 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
271               else
272                 dnl Use an explicit option to hardcode DIR into the resulting
273                 dnl binary.
274                 dnl Potentially add DIR to ltrpathdirs.
275                 dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
276                 haveit=
277                 for x in $ltrpathdirs; do
278                   if test "X$x" = "X$found_dir"; then
279                     haveit=yes
280                     break
281                   fi
282                 done
283                 if test -z "$haveit"; then
284                   ltrpathdirs="$ltrpathdirs $found_dir"
285                 fi
286                 dnl The hardcoding into $LIBNAME is system dependent.
287                 if test "$hardcode_direct" = yes; then
288                   dnl Using DIR/libNAME.so during linking hardcodes DIR into the
289                   dnl resulting binary.
290                   LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
291                 else
292                   if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then
293                     dnl Use an explicit option to hardcode DIR into the resulting
294                     dnl binary.
295                     LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
296                     dnl Potentially add DIR to rpathdirs.
297                     dnl The rpathdirs will be appended to $LIBNAME at the end.
298                     haveit=
299                     for x in $rpathdirs; do
300                       if test "X$x" = "X$found_dir"; then
301                         haveit=yes
302                         break
303                       fi
304                     done
305                     if test -z "$haveit"; then
306                       rpathdirs="$rpathdirs $found_dir"
307                     fi
308                   else
309                     dnl Rely on "-L$found_dir".
310                     dnl But don't add it if it's already contained in the LDFLAGS
311                     dnl or the already constructed $LIBNAME
312                     haveit=
313                     for x in $LDFLAGS $LIB[]NAME; do
314                       AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
315                       if test "X$x" = "X-L$found_dir"; then
316                         haveit=yes
317                         break
318                       fi
319                     done
320                     if test -z "$haveit"; then
321                       LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir"
322                     fi
323                     if test "$hardcode_minus_L" != no; then
324                       dnl FIXME: Not sure whether we should use
325                       dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
326                       dnl here.
327                       LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
328                     else
329                       dnl We cannot use $hardcode_runpath_var and LD_RUN_PATH
330                       dnl here, because this doesn't fit in flags passed to the
331                       dnl compiler. So give up. No hardcoding. This affects only
332                       dnl very old systems.
333                       dnl FIXME: Not sure whether we should use
334                       dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
335                       dnl here.
336                       LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
337                     fi
338                   fi
339                 fi
340               fi
341             else
342               if test "X$found_a" != "X"; then
343                 dnl Linking with a static library.
344                 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a"
345               else
346                 dnl We shouldn't come here, but anyway it's good to have a
347                 dnl fallback.
348                 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name"
349               fi
350             fi
351             dnl Assume the include files are nearby.
352             additional_includedir=
353             case "$found_dir" in
354               */$acl_libdirstem | */$acl_libdirstem/)
355                 basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'`
356                 additional_includedir="$basedir/include"
357                 ;;
358             esac
359             if test "X$additional_includedir" != "X"; then
360               dnl Potentially add $additional_includedir to $INCNAME.
361               dnl But don't add it
362               dnl   1. if it's the standard /usr/include,
363               dnl   2. if it's /usr/local/include and we are using GCC on Linux,
364               dnl   3. if it's already present in $CPPFLAGS or the already
365               dnl      constructed $INCNAME,
366               dnl   4. if it doesn't exist as a directory.
367               if test "X$additional_includedir" != "X/usr/include"; then
368                 haveit=
369                 if test "X$additional_includedir" = "X/usr/local/include"; then
370                   if test -n "$GCC"; then
371                     case $host_os in
372                       linux* | gnu* | k*bsd*-gnu) haveit=yes;;
373                     esac
374                   fi
375                 fi
376                 if test -z "$haveit"; then
377                   for x in $CPPFLAGS $INC[]NAME; do
378                     AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
379                     if test "X$x" = "X-I$additional_includedir"; then
380                       haveit=yes
381                       break
382                     fi
383                   done
384                   if test -z "$haveit"; then
385                     if test -d "$additional_includedir"; then
386                       dnl Really add $additional_includedir to $INCNAME.
387                       INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir"
388                     fi
389                   fi
390                 fi
391               fi
392             fi
393             dnl Look for dependencies.
394             if test -n "$found_la"; then
395               dnl Read the .la file. It defines the variables
396               dnl dlname, library_names, old_library, dependency_libs, current,
397               dnl age, revision, installed, dlopen, dlpreopen, libdir.
398               save_libdir="$libdir"
399               case "$found_la" in
400                 */* | *\\*) . "$found_la" ;;
401                 *) . "./$found_la" ;;
402               esac
403               libdir="$save_libdir"
404               dnl We use only dependency_libs.
405               for dep in $dependency_libs; do
406                 case "$dep" in
407                   -L*)
408                     additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
409                     dnl Potentially add $additional_libdir to $LIBNAME and $LTLIBNAME.
410                     dnl But don't add it
411                     dnl   1. if it's the standard /usr/lib,
412                     dnl   2. if it's /usr/local/lib and we are using GCC on Linux,
413                     dnl   3. if it's already present in $LDFLAGS or the already
414                     dnl      constructed $LIBNAME,
415                     dnl   4. if it doesn't exist as a directory.
416                     if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then
417                       haveit=
418                       if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then
419                         if test -n "$GCC"; then
420                           case $host_os in
421                             linux* | gnu* | k*bsd*-gnu) haveit=yes;;
422                           esac
423                         fi
424                       fi
425                       if test -z "$haveit"; then
426                         haveit=
427                         for x in $LDFLAGS $LIB[]NAME; do
428                           AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
429                           if test "X$x" = "X-L$additional_libdir"; then
430                             haveit=yes
431                             break
432                           fi
433                         done
434                         if test -z "$haveit"; then
435                           if test -d "$additional_libdir"; then
436                             dnl Really add $additional_libdir to $LIBNAME.
437                             LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$additional_libdir"
438                           fi
439                         fi
440                         haveit=
441                         for x in $LDFLAGS $LTLIB[]NAME; do
442                           AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
443                           if test "X$x" = "X-L$additional_libdir"; then
444                             haveit=yes
445                             break
446                           fi
447                         done
448                         if test -z "$haveit"; then
449                           if test -d "$additional_libdir"; then
450                             dnl Really add $additional_libdir to $LTLIBNAME.
451                             LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$additional_libdir"
452                           fi
453                         fi
454                       fi
455                     fi
456                     ;;
457                   -R*)
458                     dir=`echo "X$dep" | sed -e 's/^X-R//'`
459                     if test "$enable_rpath" != no; then
460                       dnl Potentially add DIR to rpathdirs.
461                       dnl The rpathdirs will be appended to $LIBNAME at the end.
462                       haveit=
463                       for x in $rpathdirs; do
464                         if test "X$x" = "X$dir"; then
465                           haveit=yes
466                           break
467                         fi
468                       done
469                       if test -z "$haveit"; then
470                         rpathdirs="$rpathdirs $dir"
471                       fi
472                       dnl Potentially add DIR to ltrpathdirs.
473                       dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
474                       haveit=
475                       for x in $ltrpathdirs; do
476                         if test "X$x" = "X$dir"; then
477                           haveit=yes
478                           break
479                         fi
480                       done
481                       if test -z "$haveit"; then
482                         ltrpathdirs="$ltrpathdirs $dir"
483                       fi
484                     fi
485                     ;;
486                   -l*)
487                     dnl Handle this in the next round.
488                     names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
489                     ;;
490                   *.la)
491                     dnl Handle this in the next round. Throw away the .la's
492                     dnl directory; it is already contained in a preceding -L
493                     dnl option.
494                     names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
495                     ;;
496                   *)
497                     dnl Most likely an immediate library name.
498                     LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep"
499                     LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep"
500                     ;;
501                 esac
502               done
503             fi
504           else
505             dnl Didn't find the library; assume it is in the system directories
506             dnl known to the linker and runtime loader. (All the system
507             dnl directories known to the linker should also be known to the
508             dnl runtime loader, otherwise the system is severely misconfigured.)
509             LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
510             LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name"
511           fi
512         fi
513       fi
514     done
515   done
516   if test "X$rpathdirs" != "X"; then
517     if test -n "$hardcode_libdir_separator"; then
518       dnl Weird platform: only the last -rpath option counts, the user must
519       dnl pass all path elements in one option. We can arrange that for a
520       dnl single library, but not when more than one $LIBNAMEs are used.
521       alldirs=
522       for found_dir in $rpathdirs; do
523         alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$found_dir"
524       done
525       dnl Note: hardcode_libdir_flag_spec uses $libdir and $wl.
526       acl_save_libdir="$libdir"
527       libdir="$alldirs"
528       eval flag=\"$hardcode_libdir_flag_spec\"
529       libdir="$acl_save_libdir"
530       LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
531     else
532       dnl The -rpath options are cumulative.
533       for found_dir in $rpathdirs; do
534         acl_save_libdir="$libdir"
535         libdir="$found_dir"
536         eval flag=\"$hardcode_libdir_flag_spec\"
537         libdir="$acl_save_libdir"
538         LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
539       done
540     fi
541   fi
542   if test "X$ltrpathdirs" != "X"; then
543     dnl When using libtool, the option that works for both libraries and
544     dnl executables is -R. The -R options are cumulative.
545     for found_dir in $ltrpathdirs; do
546       LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir"
547     done
548   fi
549 ])
550
551 dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR,
552 dnl unless already present in VAR.
553 dnl Works only for CPPFLAGS, not for LIB* variables because that sometimes
554 dnl contains two or three consecutive elements that belong together.
555 AC_DEFUN([AC_LIB_APPENDTOVAR],
556 [
557   for element in [$2]; do
558     haveit=
559     for x in $[$1]; do
560       AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
561       if test "X$x" = "X$element"; then
562         haveit=yes
563         break
564       fi
565     done
566     if test -z "$haveit"; then
567       [$1]="${[$1]}${[$1]:+ }$element"
568     fi
569   done
570 ])
571
572 dnl For those cases where a variable contains several -L and -l options
573 dnl referring to unknown libraries and directories, this macro determines the
574 dnl necessary additional linker options for the runtime path.
575 dnl AC_LIB_LINKFLAGS_FROM_LIBS([LDADDVAR], [LIBSVALUE], [USE-LIBTOOL])
576 dnl sets LDADDVAR to linker options needed together with LIBSVALUE.
577 dnl If USE-LIBTOOL evaluates to non-empty, linking with libtool is assumed,
578 dnl otherwise linking without libtool is assumed.
579 AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS],
580 [
581   AC_REQUIRE([AC_LIB_RPATH])
582   AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
583   $1=
584   if test "$enable_rpath" != no; then
585     if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then
586       dnl Use an explicit option to hardcode directories into the resulting
587       dnl binary.
588       rpathdirs=
589       next=
590       for opt in $2; do
591         if test -n "$next"; then
592           dir="$next"
593           dnl No need to hardcode the standard /usr/lib.
594           if test "X$dir" != "X/usr/$acl_libdirstem"; then
595             rpathdirs="$rpathdirs $dir"
596           fi
597           next=
598         else
599           case $opt in
600             -L) next=yes ;;
601             -L*) dir=`echo "X$opt" | sed -e 's,^X-L,,'`
602                  dnl No need to hardcode the standard /usr/lib.
603                  if test "X$dir" != "X/usr/$acl_libdirstem"; then
604                    rpathdirs="$rpathdirs $dir"
605                  fi
606                  next= ;;
607             *) next= ;;
608           esac
609         fi
610       done
611       if test "X$rpathdirs" != "X"; then
612         if test -n ""$3""; then
613           dnl libtool is used for linking. Use -R options.
614           for dir in $rpathdirs; do
615             $1="${$1}${$1:+ }-R$dir"
616           done
617         else
618           dnl The linker is used for linking directly.
619           if test -n "$hardcode_libdir_separator"; then
620             dnl Weird platform: only the last -rpath option counts, the user
621             dnl must pass all path elements in one option.
622             alldirs=
623             for dir in $rpathdirs; do
624               alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$dir"
625             done
626             acl_save_libdir="$libdir"
627             libdir="$alldirs"
628             eval flag=\"$hardcode_libdir_flag_spec\"
629             libdir="$acl_save_libdir"
630             $1="$flag"
631           else
632             dnl The -rpath options are cumulative.
633             for dir in $rpathdirs; do
634               acl_save_libdir="$libdir"
635               libdir="$dir"
636               eval flag=\"$hardcode_libdir_flag_spec\"
637               libdir="$acl_save_libdir"
638               $1="${$1}${$1:+ }$flag"
639             done
640           fi
641         fi
642       fi
643     fi
644   fi
645   AC_SUBST([$1])
646 ])