lib-link.m4
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:29k
源码类别:

midi

开发平台:

Unix_Linux

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