lib-link.m4
Upload User: wmy0603
Upload Date: 2022-05-02
Package Size: 1808k
Code Size: 32k
Development Platform:

Visual C++

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