csomh / source-git / rpm

Forked from source-git/rpm 4 years ago
Clone
2ff057
# lib-link.m4 serial 9 (gettext-0.16)
2ff057
dnl Copyright (C) 2001-2006 Free Software Foundation, Inc.
2ff057
dnl This file is free software; the Free Software Foundation
2ff057
dnl gives unlimited permission to copy and/or distribute it,
2ff057
dnl with or without modifications, as long as this notice is preserved.
2ff057
2ff057
dnl From Bruno Haible.
2ff057
2ff057
AC_PREREQ(2.50)
2ff057
2ff057
dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and
2ff057
dnl the libraries corresponding to explicit and implicit dependencies.
2ff057
dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and
2ff057
dnl augments the CPPFLAGS variable.
2ff057
AC_DEFUN([AC_LIB_LINKFLAGS],
2ff057
[
2ff057
  AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
2ff057
  AC_REQUIRE([AC_LIB_RPATH])
2ff057
  define([Name],[translit([$1],[./-], [___])])
2ff057
  define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
2ff057
                               [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
2ff057
  AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [
2ff057
    AC_LIB_LINKFLAGS_BODY([$1], [$2])
2ff057
    ac_cv_lib[]Name[]_libs="$LIB[]NAME"
2ff057
    ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME"
2ff057
    ac_cv_lib[]Name[]_cppflags="$INC[]NAME"
2ff057
  ])
2ff057
  LIB[]NAME="$ac_cv_lib[]Name[]_libs"
2ff057
  LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs"
2ff057
  INC[]NAME="$ac_cv_lib[]Name[]_cppflags"
2ff057
  AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
2ff057
  AC_SUBST([LIB]NAME)
2ff057
  AC_SUBST([LTLIB]NAME)
2ff057
  dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the
2ff057
  dnl results of this search when this library appears as a dependency.
2ff057
  HAVE_LIB[]NAME=yes
2ff057
  undefine([Name])
2ff057
  undefine([NAME])
2ff057
])
2ff057
2ff057
dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode)
2ff057
dnl searches for libname and the libraries corresponding to explicit and
2ff057
dnl implicit dependencies, together with the specified include files and
2ff057
dnl the ability to compile and link the specified testcode. If found, it
2ff057
dnl sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME} and
2ff057
dnl LTLIB${NAME} variables and augments the CPPFLAGS variable, and
2ff057
dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs
2ff057
dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty.
2ff057
AC_DEFUN([AC_LIB_HAVE_LINKFLAGS],
2ff057
[
2ff057
  AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
2ff057
  AC_REQUIRE([AC_LIB_RPATH])
2ff057
  define([Name],[translit([$1],[./-], [___])])
2ff057
  define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
2ff057
                               [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
2ff057
2ff057
  dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME
2ff057
  dnl accordingly.
2ff057
  AC_LIB_LINKFLAGS_BODY([$1], [$2])
2ff057
2ff057
  dnl Add $INC[]NAME to CPPFLAGS before performing the following checks,
2ff057
  dnl because if the user has installed lib[]Name and not disabled its use
2ff057
  dnl via --without-lib[]Name-prefix, he wants to use it.
2ff057
  ac_save_CPPFLAGS="$CPPFLAGS"
2ff057
  AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
2ff057
2ff057
  AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [
2ff057
    ac_save_LIBS="$LIBS"
2ff057
    LIBS="$LIBS $LIB[]NAME"
2ff057
    AC_TRY_LINK([$3], [$4], [ac_cv_lib[]Name=yes], [ac_cv_lib[]Name=no])
2ff057
    LIBS="$ac_save_LIBS"
2ff057
  ])
2ff057
  if test "$ac_cv_lib[]Name" = yes; then
2ff057
    HAVE_LIB[]NAME=yes
2ff057
    AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the $1 library.])
2ff057
    AC_MSG_CHECKING([how to link with lib[]$1])
2ff057
    AC_MSG_RESULT([$LIB[]NAME])
2ff057
  else
2ff057
    HAVE_LIB[]NAME=no
2ff057
    dnl If $LIB[]NAME didn't lead to a usable library, we don't need
2ff057
    dnl $INC[]NAME either.
2ff057
    CPPFLAGS="$ac_save_CPPFLAGS"
2ff057
    LIB[]NAME=
2ff057
    LTLIB[]NAME=
2ff057
  fi
2ff057
  AC_SUBST([HAVE_LIB]NAME)
2ff057
  AC_SUBST([LIB]NAME)
2ff057
  AC_SUBST([LTLIB]NAME)
2ff057
  undefine([Name])
2ff057
  undefine([NAME])
2ff057
])
2ff057
2ff057
dnl Determine the platform dependent parameters needed to use rpath:
2ff057
dnl libext, shlibext, hardcode_libdir_flag_spec, hardcode_libdir_separator,
2ff057
dnl hardcode_direct, hardcode_minus_L.
2ff057
AC_DEFUN([AC_LIB_RPATH],
2ff057
[
2ff057
  dnl Tell automake >= 1.10 to complain if config.rpath is missing.
2ff057
  m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([config.rpath])])
2ff057
  AC_REQUIRE([AC_PROG_CC])                dnl we use $CC, $GCC, $LDFLAGS
2ff057
  AC_REQUIRE([AC_LIB_PROG_LD])            dnl we use $LD, $with_gnu_ld
2ff057
  AC_REQUIRE([AC_CANONICAL_HOST])         dnl we use $host
2ff057
  AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir
2ff057
  AC_CACHE_CHECK([for shared library run path origin], acl_cv_rpath, [
2ff057
    CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \
2ff057
    ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh
2ff057
    . ./conftest.sh
2ff057
    rm -f ./conftest.sh
2ff057
    acl_cv_rpath=done
2ff057
  ])
2ff057
  wl="$acl_cv_wl"
2ff057
  libext="$acl_cv_libext"
2ff057
  shlibext="$acl_cv_shlibext"
2ff057
  hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec"
2ff057
  hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator"
2ff057
  hardcode_direct="$acl_cv_hardcode_direct"
2ff057
  hardcode_minus_L="$acl_cv_hardcode_minus_L"
2ff057
  dnl Determine whether the user wants rpath handling at all.
2ff057
  AC_ARG_ENABLE(rpath,
2ff057
    [  --disable-rpath         do not hardcode runtime library paths],
2ff057
    :, enable_rpath=yes)
2ff057
])
2ff057
2ff057
dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and
2ff057
dnl the libraries corresponding to explicit and implicit dependencies.
2ff057
dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables.
2ff057
AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
2ff057
[
2ff057
  AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
2ff057
  define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
2ff057
                               [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
2ff057
  dnl By default, look in $includedir and $libdir.
2ff057
  use_additional=yes
2ff057
  AC_LIB_WITH_FINAL_PREFIX([
2ff057
    eval additional_includedir=\"$includedir\"
2ff057
    eval additional_libdir=\"$libdir\"
2ff057
  ])
2ff057
  AC_LIB_ARG_WITH([lib$1-prefix],
2ff057
[  --with-lib$1-prefix[=DIR]  search for lib$1 in DIR/include and DIR/lib
2ff057
  --without-lib$1-prefix     don't search for lib$1 in includedir and libdir],
2ff057
[
2ff057
    if test "X$withval" = "Xno"; then
2ff057
      use_additional=no
2ff057
    else
2ff057
      if test "X$withval" = "X"; then
2ff057
        AC_LIB_WITH_FINAL_PREFIX([
2ff057
          eval additional_includedir=\"$includedir\"
2ff057
          eval additional_libdir=\"$libdir\"
2ff057
        ])
2ff057
      else
2ff057
        additional_includedir="$withval/include"
2ff057
        additional_libdir="$withval/$acl_libdirstem"
2ff057
      fi
2ff057
    fi
2ff057
])
2ff057
  dnl Search the library and its dependencies in $additional_libdir and
2ff057
  dnl $LDFLAGS. Using breadth-first-seach.
2ff057
  LIB[]NAME=
2ff057
  LTLIB[]NAME=
2ff057
  INC[]NAME=
2ff057
  rpathdirs=
2ff057
  ltrpathdirs=
2ff057
  names_already_handled=
2ff057
  names_next_round='$1 $2'
2ff057
  while test -n "$names_next_round"; do
2ff057
    names_this_round="$names_next_round"
2ff057
    names_next_round=
2ff057
    for name in $names_this_round; do
2ff057
      already_handled=
2ff057
      for n in $names_already_handled; do
2ff057
        if test "$n" = "$name"; then
2ff057
          already_handled=yes
2ff057
          break
2ff057
        fi
2ff057
      done
2ff057
      if test -z "$already_handled"; then
2ff057
        names_already_handled="$names_already_handled $name"
2ff057
        dnl See if it was already located by an earlier AC_LIB_LINKFLAGS
2ff057
        dnl or AC_LIB_HAVE_LINKFLAGS call.
2ff057
        uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'`
2ff057
        eval value=\"\$HAVE_LIB$uppername\"
2ff057
        if test -n "$value"; then
2ff057
          if test "$value" = yes; then
2ff057
            eval value=\"\$LIB$uppername\"
2ff057
            test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value"
2ff057
            eval value=\"\$LTLIB$uppername\"
2ff057
            test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value"
2ff057
          else
2ff057
            dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined
2ff057
            dnl that this library doesn't exist. So just drop it.
2ff057
            :
2ff057
          fi
2ff057
        else
2ff057
          dnl Search the library lib$name in $additional_libdir and $LDFLAGS
2ff057
          dnl and the already constructed $LIBNAME/$LTLIBNAME.
2ff057
          found_dir=
2ff057
          found_la=
2ff057
          found_so=
2ff057
          found_a=
2ff057
          if test $use_additional = yes; then
2ff057
            if test -n "$shlibext" \
2ff057
               && { test -f "$additional_libdir/lib$name.$shlibext" \
2ff057
                    || { test "$shlibext" = dll \
2ff057
                         && test -f "$additional_libdir/lib$name.dll.a"; }; }; then
2ff057
              found_dir="$additional_libdir"
2ff057
              if test -f "$additional_libdir/lib$name.$shlibext"; then
2ff057
                found_so="$additional_libdir/lib$name.$shlibext"
2ff057
              else
2ff057
                found_so="$additional_libdir/lib$name.dll.a"
2ff057
              fi
2ff057
              if test -f "$additional_libdir/lib$name.la"; then
2ff057
                found_la="$additional_libdir/lib$name.la"
2ff057
              fi
2ff057
            else
2ff057
              if test -f "$additional_libdir/lib$name.$libext"; then
2ff057
                found_dir="$additional_libdir"
2ff057
                found_a="$additional_libdir/lib$name.$libext"
2ff057
                if test -f "$additional_libdir/lib$name.la"; then
2ff057
                  found_la="$additional_libdir/lib$name.la"
2ff057
                fi
2ff057
              fi
2ff057
            fi
2ff057
          fi
2ff057
          if test "X$found_dir" = "X"; then
2ff057
            for x in $LDFLAGS $LTLIB[]NAME; do
2ff057
              AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
2ff057
              case "$x" in
2ff057
                -L*)
2ff057
                  dir=`echo "X$x" | sed -e 's/^X-L//'`
2ff057
                  if test -n "$shlibext" \
2ff057
                     && { test -f "$dir/lib$name.$shlibext" \
2ff057
                          || { test "$shlibext" = dll \
2ff057
                               && test -f "$dir/lib$name.dll.a"; }; }; then
2ff057
                    found_dir="$dir"
2ff057
                    if test -f "$dir/lib$name.$shlibext"; then
2ff057
                      found_so="$dir/lib$name.$shlibext"
2ff057
                    else
2ff057
                      found_so="$dir/lib$name.dll.a"
2ff057
                    fi
2ff057
                    if test -f "$dir/lib$name.la"; then
2ff057
                      found_la="$dir/lib$name.la"
2ff057
                    fi
2ff057
                  else
2ff057
                    if test -f "$dir/lib$name.$libext"; then
2ff057
                      found_dir="$dir"
2ff057
                      found_a="$dir/lib$name.$libext"
2ff057
                      if test -f "$dir/lib$name.la"; then
2ff057
                        found_la="$dir/lib$name.la"
2ff057
                      fi
2ff057
                    fi
2ff057
                  fi
2ff057
                  ;;
2ff057
              esac
2ff057
              if test "X$found_dir" != "X"; then
2ff057
                break
2ff057
              fi
2ff057
            done
2ff057
          fi
2ff057
          if test "X$found_dir" != "X"; then
2ff057
            dnl Found the library.
2ff057
            LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name"
2ff057
            if test "X$found_so" != "X"; then
2ff057
              dnl Linking with a shared library. We attempt to hardcode its
2ff057
              dnl directory into the executable's runpath, unless it's the
2ff057
              dnl standard /usr/lib.
2ff057
              if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/$acl_libdirstem"; then
2ff057
                dnl No hardcoding is needed.
2ff057
                LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
2ff057
              else
2ff057
                dnl Use an explicit option to hardcode DIR into the resulting
2ff057
                dnl binary.
2ff057
                dnl Potentially add DIR to ltrpathdirs.
2ff057
                dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
2ff057
                haveit=
2ff057
                for x in $ltrpathdirs; do
2ff057
                  if test "X$x" = "X$found_dir"; then
2ff057
                    haveit=yes
2ff057
                    break
2ff057
                  fi
2ff057
                done
2ff057
                if test -z "$haveit"; then
2ff057
                  ltrpathdirs="$ltrpathdirs $found_dir"
2ff057
                fi
2ff057
                dnl The hardcoding into $LIBNAME is system dependent.
2ff057
                if test "$hardcode_direct" = yes; then
2ff057
                  dnl Using DIR/libNAME.so during linking hardcodes DIR into the
2ff057
                  dnl resulting binary.
2ff057
                  LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
2ff057
                else
2ff057
                  if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then
2ff057
                    dnl Use an explicit option to hardcode DIR into the resulting
2ff057
                    dnl binary.
2ff057
                    LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
2ff057
                    dnl Potentially add DIR to rpathdirs.
2ff057
                    dnl The rpathdirs will be appended to $LIBNAME at the end.
2ff057
                    haveit=
2ff057
                    for x in $rpathdirs; do
2ff057
                      if test "X$x" = "X$found_dir"; then
2ff057
                        haveit=yes
2ff057
                        break
2ff057
                      fi
2ff057
                    done
2ff057
                    if test -z "$haveit"; then
2ff057
                      rpathdirs="$rpathdirs $found_dir"
2ff057
                    fi
2ff057
                  else
2ff057
                    dnl Rely on "-L$found_dir".
2ff057
                    dnl But don't add it if it's already contained in the LDFLAGS
2ff057
                    dnl or the already constructed $LIBNAME
2ff057
                    haveit=
2ff057
                    for x in $LDFLAGS $LIB[]NAME; do
2ff057
                      AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
2ff057
                      if test "X$x" = "X-L$found_dir"; then
2ff057
                        haveit=yes
2ff057
                        break
2ff057
                      fi
2ff057
                    done
2ff057
                    if test -z "$haveit"; then
2ff057
                      LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir"
2ff057
                    fi
2ff057
                    if test "$hardcode_minus_L" != no; then
2ff057
                      dnl FIXME: Not sure whether we should use
2ff057
                      dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
2ff057
                      dnl here.
2ff057
                      LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
2ff057
                    else
2ff057
                      dnl We cannot use $hardcode_runpath_var and LD_RUN_PATH
2ff057
                      dnl here, because this doesn't fit in flags passed to the
2ff057
                      dnl compiler. So give up. No hardcoding. This affects only
2ff057
                      dnl very old systems.
2ff057
                      dnl FIXME: Not sure whether we should use
2ff057
                      dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
2ff057
                      dnl here.
2ff057
                      LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
2ff057
                    fi
2ff057
                  fi
2ff057
                fi
2ff057
              fi
2ff057
            else
2ff057
              if test "X$found_a" != "X"; then
2ff057
                dnl Linking with a static library.
2ff057
                LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a"
2ff057
              else
2ff057
                dnl We shouldn't come here, but anyway it's good to have a
2ff057
                dnl fallback.
2ff057
                LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name"
2ff057
              fi
2ff057
            fi
2ff057
            dnl Assume the include files are nearby.
2ff057
            additional_includedir=
2ff057
            case "$found_dir" in
2ff057
              */$acl_libdirstem | */$acl_libdirstem/)
2ff057
                basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'`
2ff057
                additional_includedir="$basedir/include"
2ff057
                ;;
2ff057
            esac
2ff057
            if test "X$additional_includedir" != "X"; then
2ff057
              dnl Potentially add $additional_includedir to $INCNAME.
2ff057
              dnl But don't add it
2ff057
              dnl   1. if it's the standard /usr/include,
2ff057
              dnl   2. if it's /usr/local/include and we are using GCC on Linux,
2ff057
              dnl   3. if it's already present in $CPPFLAGS or the already
2ff057
              dnl      constructed $INCNAME,
2ff057
              dnl   4. if it doesn't exist as a directory.
2ff057
              if test "X$additional_includedir" != "X/usr/include"; then
2ff057
                haveit=
2ff057
                if test "X$additional_includedir" = "X/usr/local/include"; then
2ff057
                  if test -n "$GCC"; then
2ff057
                    case $host_os in
2ff057
                      linux* | gnu* | k*bsd*-gnu) haveit=yes;;
2ff057
                    esac
2ff057
                  fi
2ff057
                fi
2ff057
                if test -z "$haveit"; then
2ff057
                  for x in $CPPFLAGS $INC[]NAME; do
2ff057
                    AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
2ff057
                    if test "X$x" = "X-I$additional_includedir"; then
2ff057
                      haveit=yes
2ff057
                      break
2ff057
                    fi
2ff057
                  done
2ff057
                  if test -z "$haveit"; then
2ff057
                    if test -d "$additional_includedir"; then
2ff057
                      dnl Really add $additional_includedir to $INCNAME.
2ff057
                      INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir"
2ff057
                    fi
2ff057
                  fi
2ff057
                fi
2ff057
              fi
2ff057
            fi
2ff057
            dnl Look for dependencies.
2ff057
            if test -n "$found_la"; then
2ff057
              dnl Read the .la file. It defines the variables
2ff057
              dnl dlname, library_names, old_library, dependency_libs, current,
2ff057
              dnl age, revision, installed, dlopen, dlpreopen, libdir.
2ff057
              save_libdir="$libdir"
2ff057
              case "$found_la" in
2ff057
                */* | *\\*) . "$found_la" ;;
2ff057
                *) . "./$found_la" ;;
2ff057
              esac
2ff057
              libdir="$save_libdir"
2ff057
              dnl We use only dependency_libs.
2ff057
              for dep in $dependency_libs; do
2ff057
                case "$dep" in
2ff057
                  -L*)
2ff057
                    additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
2ff057
                    dnl Potentially add $additional_libdir to $LIBNAME and $LTLIBNAME.
2ff057
                    dnl But don't add it
2ff057
                    dnl   1. if it's the standard /usr/lib,
2ff057
                    dnl   2. if it's /usr/local/lib and we are using GCC on Linux,
2ff057
                    dnl   3. if it's already present in $LDFLAGS or the already
2ff057
                    dnl      constructed $LIBNAME,
2ff057
                    dnl   4. if it doesn't exist as a directory.
2ff057
                    if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then
2ff057
                      haveit=
2ff057
                      if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then
2ff057
                        if test -n "$GCC"; then
2ff057
                          case $host_os in
2ff057
                            linux* | gnu* | k*bsd*-gnu) haveit=yes;;
2ff057
                          esac
2ff057
                        fi
2ff057
                      fi
2ff057
                      if test -z "$haveit"; then
2ff057
                        haveit=
2ff057
                        for x in $LDFLAGS $LIB[]NAME; do
2ff057
                          AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
2ff057
                          if test "X$x" = "X-L$additional_libdir"; then
2ff057
                            haveit=yes
2ff057
                            break
2ff057
                          fi
2ff057
                        done
2ff057
                        if test -z "$haveit"; then
2ff057
                          if test -d "$additional_libdir"; then
2ff057
                            dnl Really add $additional_libdir to $LIBNAME.
2ff057
                            LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$additional_libdir"
2ff057
                          fi
2ff057
                        fi
2ff057
                        haveit=
2ff057
                        for x in $LDFLAGS $LTLIB[]NAME; do
2ff057
                          AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
2ff057
                          if test "X$x" = "X-L$additional_libdir"; then
2ff057
                            haveit=yes
2ff057
                            break
2ff057
                          fi
2ff057
                        done
2ff057
                        if test -z "$haveit"; then
2ff057
                          if test -d "$additional_libdir"; then
2ff057
                            dnl Really add $additional_libdir to $LTLIBNAME.
2ff057
                            LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$additional_libdir"
2ff057
                          fi
2ff057
                        fi
2ff057
                      fi
2ff057
                    fi
2ff057
                    ;;
2ff057
                  -R*)
2ff057
                    dir=`echo "X$dep" | sed -e 's/^X-R//'`
2ff057
                    if test "$enable_rpath" != no; then
2ff057
                      dnl Potentially add DIR to rpathdirs.
2ff057
                      dnl The rpathdirs will be appended to $LIBNAME at the end.
2ff057
                      haveit=
2ff057
                      for x in $rpathdirs; do
2ff057
                        if test "X$x" = "X$dir"; then
2ff057
                          haveit=yes
2ff057
                          break
2ff057
                        fi
2ff057
                      done
2ff057
                      if test -z "$haveit"; then
2ff057
                        rpathdirs="$rpathdirs $dir"
2ff057
                      fi
2ff057
                      dnl Potentially add DIR to ltrpathdirs.
2ff057
                      dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
2ff057
                      haveit=
2ff057
                      for x in $ltrpathdirs; do
2ff057
                        if test "X$x" = "X$dir"; then
2ff057
                          haveit=yes
2ff057
                          break
2ff057
                        fi
2ff057
                      done
2ff057
                      if test -z "$haveit"; then
2ff057
                        ltrpathdirs="$ltrpathdirs $dir"
2ff057
                      fi
2ff057
                    fi
2ff057
                    ;;
2ff057
                  -l*)
2ff057
                    dnl Handle this in the next round.
2ff057
                    names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
2ff057
                    ;;
2ff057
                  *.la)
2ff057
                    dnl Handle this in the next round. Throw away the .la's
2ff057
                    dnl directory; it is already contained in a preceding -L
2ff057
                    dnl option.
2ff057
                    names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
2ff057
                    ;;
2ff057
                  *)
2ff057
                    dnl Most likely an immediate library name.
2ff057
                    LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep"
2ff057
                    LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep"
2ff057
                    ;;
2ff057
                esac
2ff057
              done
2ff057
            fi
2ff057
          else
2ff057
            dnl Didn't find the library; assume it is in the system directories
2ff057
            dnl known to the linker and runtime loader. (All the system
2ff057
            dnl directories known to the linker should also be known to the
2ff057
            dnl runtime loader, otherwise the system is severely misconfigured.)
2ff057
            LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
2ff057
            LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name"
2ff057
          fi
2ff057
        fi
2ff057
      fi
2ff057
    done
2ff057
  done
2ff057
  if test "X$rpathdirs" != "X"; then
2ff057
    if test -n "$hardcode_libdir_separator"; then
2ff057
      dnl Weird platform: only the last -rpath option counts, the user must
2ff057
      dnl pass all path elements in one option. We can arrange that for a
2ff057
      dnl single library, but not when more than one $LIBNAMEs are used.
2ff057
      alldirs=
2ff057
      for found_dir in $rpathdirs; do
2ff057
        alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$found_dir"
2ff057
      done
2ff057
      dnl Note: hardcode_libdir_flag_spec uses $libdir and $wl.
2ff057
      acl_save_libdir="$libdir"
2ff057
      libdir="$alldirs"
2ff057
      eval flag=\"$hardcode_libdir_flag_spec\"
2ff057
      libdir="$acl_save_libdir"
2ff057
      LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
2ff057
    else
2ff057
      dnl The -rpath options are cumulative.
2ff057
      for found_dir in $rpathdirs; do
2ff057
        acl_save_libdir="$libdir"
2ff057
        libdir="$found_dir"
2ff057
        eval flag=\"$hardcode_libdir_flag_spec\"
2ff057
        libdir="$acl_save_libdir"
2ff057
        LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
2ff057
      done
2ff057
    fi
2ff057
  fi
2ff057
  if test "X$ltrpathdirs" != "X"; then
2ff057
    dnl When using libtool, the option that works for both libraries and
2ff057
    dnl executables is -R. The -R options are cumulative.
2ff057
    for found_dir in $ltrpathdirs; do
2ff057
      LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir"
2ff057
    done
2ff057
  fi
2ff057
])
2ff057
2ff057
dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR,
2ff057
dnl unless already present in VAR.
2ff057
dnl Works only for CPPFLAGS, not for LIB* variables because that sometimes
2ff057
dnl contains two or three consecutive elements that belong together.
2ff057
AC_DEFUN([AC_LIB_APPENDTOVAR],
2ff057
[
2ff057
  for element in [$2]; do
2ff057
    haveit=
2ff057
    for x in $[$1]; do
2ff057
      AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
2ff057
      if test "X$x" = "X$element"; then
2ff057
        haveit=yes
2ff057
        break
2ff057
      fi
2ff057
    done
2ff057
    if test -z "$haveit"; then
2ff057
      [$1]="${[$1]}${[$1]:+ }$element"
2ff057
    fi
2ff057
  done
2ff057
])
2ff057
2ff057
dnl For those cases where a variable contains several -L and -l options
2ff057
dnl referring to unknown libraries and directories, this macro determines the
2ff057
dnl necessary additional linker options for the runtime path.
2ff057
dnl AC_LIB_LINKFLAGS_FROM_LIBS([LDADDVAR], [LIBSVALUE], [USE-LIBTOOL])
2ff057
dnl sets LDADDVAR to linker options needed together with LIBSVALUE.
2ff057
dnl If USE-LIBTOOL evaluates to non-empty, linking with libtool is assumed,
2ff057
dnl otherwise linking without libtool is assumed.
2ff057
AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS],
2ff057
[
2ff057
  AC_REQUIRE([AC_LIB_RPATH])
2ff057
  AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
2ff057
  $1=
2ff057
  if test "$enable_rpath" != no; then
2ff057
    if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then
2ff057
      dnl Use an explicit option to hardcode directories into the resulting
2ff057
      dnl binary.
2ff057
      rpathdirs=
2ff057
      next=
2ff057
      for opt in $2; do
2ff057
        if test -n "$next"; then
2ff057
          dir="$next"
2ff057
          dnl No need to hardcode the standard /usr/lib.
2ff057
          if test "X$dir" != "X/usr/$acl_libdirstem"; then
2ff057
            rpathdirs="$rpathdirs $dir"
2ff057
          fi
2ff057
          next=
2ff057
        else
2ff057
          case $opt in
2ff057
            -L) next=yes ;;
2ff057
            -L*) dir=`echo "X$opt" | sed -e 's,^X-L,,'`
2ff057
                 dnl No need to hardcode the standard /usr/lib.
2ff057
                 if test "X$dir" != "X/usr/$acl_libdirstem"; then
2ff057
                   rpathdirs="$rpathdirs $dir"
2ff057
                 fi
2ff057
                 next= ;;
2ff057
            *) next= ;;
2ff057
          esac
2ff057
        fi
2ff057
      done
2ff057
      if test "X$rpathdirs" != "X"; then
2ff057
        if test -n ""$3""; then
2ff057
          dnl libtool is used for linking. Use -R options.
2ff057
          for dir in $rpathdirs; do
2ff057
            $1="${$1}${$1:+ }-R$dir"
2ff057
          done
2ff057
        else
2ff057
          dnl The linker is used for linking directly.
2ff057
          if test -n "$hardcode_libdir_separator"; then
2ff057
            dnl Weird platform: only the last -rpath option counts, the user
2ff057
            dnl must pass all path elements in one option.
2ff057
            alldirs=
2ff057
            for dir in $rpathdirs; do
2ff057
              alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$dir"
2ff057
            done
2ff057
            acl_save_libdir="$libdir"
2ff057
            libdir="$alldirs"
2ff057
            eval flag=\"$hardcode_libdir_flag_spec\"
2ff057
            libdir="$acl_save_libdir"
2ff057
            $1="$flag"
2ff057
          else
2ff057
            dnl The -rpath options are cumulative.
2ff057
            for dir in $rpathdirs; do
2ff057
              acl_save_libdir="$libdir"
2ff057
              libdir="$dir"
2ff057
              eval flag=\"$hardcode_libdir_flag_spec\"
2ff057
              libdir="$acl_save_libdir"
2ff057
              $1="${$1}${$1:+ }$flag"
2ff057
            done
2ff057
          fi
2ff057
        fi
2ff057
      fi
2ff057
    fi
2ff057
  fi
2ff057
  AC_SUBST([$1])
2ff057
])