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