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