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