Home | History | Annotate | Line # | Download | only in m4
lib-link.m4 revision 1.1
      1  1.1  christos # lib-link.m4 serial 7 (gettext-0.15)
      2  1.1  christos dnl Copyright (C) 2001-2005 Free Software Foundation, Inc.
      3  1.1  christos dnl This file is free software; the Free Software Foundation
      4  1.1  christos dnl gives unlimited permission to copy and/or distribute it,
      5  1.1  christos dnl with or without modifications, as long as this notice is preserved.
      6  1.1  christos 
      7  1.1  christos dnl From Bruno Haible.
      8  1.1  christos 
      9  1.1  christos AC_PREREQ(2.50)
     10  1.1  christos 
     11  1.1  christos dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and
     12  1.1  christos dnl the libraries corresponding to explicit and implicit dependencies.
     13  1.1  christos dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and
     14  1.1  christos dnl augments the CPPFLAGS variable.
     15  1.1  christos AC_DEFUN([AC_LIB_LINKFLAGS],
     16  1.1  christos [
     17  1.1  christos   AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
     18  1.1  christos   AC_REQUIRE([AC_LIB_RPATH])
     19  1.1  christos   define([Name],[translit([$1],[./-], [___])])
     20  1.1  christos   define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
     21  1.1  christos                                [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
     22  1.1  christos   AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [
     23  1.1  christos     AC_LIB_LINKFLAGS_BODY([$1], [$2])
     24  1.1  christos     ac_cv_lib[]Name[]_libs="$LIB[]NAME"
     25  1.1  christos     ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME"
     26  1.1  christos     ac_cv_lib[]Name[]_cppflags="$INC[]NAME"
     27  1.1  christos   ])
     28  1.1  christos   LIB[]NAME="$ac_cv_lib[]Name[]_libs"
     29  1.1  christos   LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs"
     30  1.1  christos   INC[]NAME="$ac_cv_lib[]Name[]_cppflags"
     31  1.1  christos   AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
     32  1.1  christos   AC_SUBST([LIB]NAME)
     33  1.1  christos   AC_SUBST([LTLIB]NAME)
     34  1.1  christos   dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the
     35  1.1  christos   dnl results of this search when this library appears as a dependency.
     36  1.1  christos   HAVE_LIB[]NAME=yes
     37  1.1  christos   undefine([Name])
     38  1.1  christos   undefine([NAME])
     39  1.1  christos ])
     40  1.1  christos 
     41  1.1  christos dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode)
     42  1.1  christos dnl searches for libname and the libraries corresponding to explicit and
     43  1.1  christos dnl implicit dependencies, together with the specified include files and
     44  1.1  christos dnl the ability to compile and link the specified testcode. If found, it
     45  1.1  christos dnl sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME} and
     46  1.1  christos dnl LTLIB${NAME} variables and augments the CPPFLAGS variable, and
     47  1.1  christos dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs
     48  1.1  christos dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty.
     49  1.1  christos AC_DEFUN([AC_LIB_HAVE_LINKFLAGS],
     50  1.1  christos [
     51  1.1  christos   AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
     52  1.1  christos   AC_REQUIRE([AC_LIB_RPATH])
     53  1.1  christos   define([Name],[translit([$1],[./-], [___])])
     54  1.1  christos   define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
     55  1.1  christos                                [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
     56  1.1  christos 
     57  1.1  christos   dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME
     58  1.1  christos   dnl accordingly.
     59  1.1  christos   AC_LIB_LINKFLAGS_BODY([$1], [$2])
     60  1.1  christos 
     61  1.1  christos   dnl Add $INC[]NAME to CPPFLAGS before performing the following checks,
     62  1.1  christos   dnl because if the user has installed lib[]Name and not disabled its use
     63  1.1  christos   dnl via --without-lib[]Name-prefix, he wants to use it.
     64  1.1  christos   ac_save_CPPFLAGS="$CPPFLAGS"
     65  1.1  christos   AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
     66  1.1  christos 
     67  1.1  christos   AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [
     68  1.1  christos     ac_save_LIBS="$LIBS"
     69  1.1  christos     LIBS="$LIBS $LIB[]NAME"
     70  1.1  christos     AC_TRY_LINK([$3], [$4], [ac_cv_lib[]Name=yes], [ac_cv_lib[]Name=no])
     71  1.1  christos     LIBS="$ac_save_LIBS"
     72  1.1  christos   ])
     73  1.1  christos   if test "$ac_cv_lib[]Name" = yes; then
     74  1.1  christos     HAVE_LIB[]NAME=yes
     75  1.1  christos     AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the $1 library.])
     76  1.1  christos     AC_MSG_CHECKING([how to link with lib[]$1])
     77  1.1  christos     AC_MSG_RESULT([$LIB[]NAME])
     78  1.1  christos   else
     79  1.1  christos     HAVE_LIB[]NAME=no
     80  1.1  christos     dnl If $LIB[]NAME didn't lead to a usable library, we don't need
     81  1.1  christos     dnl $INC[]NAME either.
     82  1.1  christos     CPPFLAGS="$ac_save_CPPFLAGS"
     83  1.1  christos     LIB[]NAME=
     84  1.1  christos     LTLIB[]NAME=
     85  1.1  christos   fi
     86  1.1  christos   AC_SUBST([HAVE_LIB]NAME)
     87  1.1  christos   AC_SUBST([LIB]NAME)
     88  1.1  christos   AC_SUBST([LTLIB]NAME)
     89  1.1  christos   undefine([Name])
     90  1.1  christos   undefine([NAME])
     91  1.1  christos ])
     92  1.1  christos 
     93  1.1  christos dnl Determine the platform dependent parameters needed to use rpath:
     94  1.1  christos dnl libext, shlibext, hardcode_libdir_flag_spec, hardcode_libdir_separator,
     95  1.1  christos dnl hardcode_direct, hardcode_minus_L.
     96  1.1  christos AC_DEFUN([AC_LIB_RPATH],
     97  1.1  christos [
     98  1.1  christos   dnl Tell automake >= 1.10 to complain if config.rpath is missing.
     99  1.1  christos   m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([config.rpath])])
    100  1.1  christos   AC_REQUIRE([AC_PROG_CC])                dnl we use $CC, $GCC, $LDFLAGS
    101  1.1  christos   AC_REQUIRE([AC_LIB_PROG_LD])            dnl we use $LD, $with_gnu_ld
    102  1.1  christos   AC_REQUIRE([AC_CANONICAL_HOST])         dnl we use $host
    103  1.1  christos   AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir
    104  1.1  christos   AC_CACHE_CHECK([for shared library run path origin], acl_cv_rpath, [
    105  1.1  christos     CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \
    106  1.1  christos     ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh
    107  1.1  christos     . ./conftest.sh
    108  1.1  christos     rm -f ./conftest.sh
    109  1.1  christos     acl_cv_rpath=done
    110  1.1  christos   ])
    111  1.1  christos   wl="$acl_cv_wl"
    112  1.1  christos   libext="$acl_cv_libext"
    113  1.1  christos   shlibext="$acl_cv_shlibext"
    114  1.1  christos   hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec"
    115  1.1  christos   hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator"
    116  1.1  christos   hardcode_direct="$acl_cv_hardcode_direct"
    117  1.1  christos   hardcode_minus_L="$acl_cv_hardcode_minus_L"
    118  1.1  christos   dnl Determine whether the user wants rpath handling at all.
    119  1.1  christos   AC_ARG_ENABLE(rpath,
    120  1.1  christos     [  --disable-rpath         do not hardcode runtime library paths],
    121  1.1  christos     :, enable_rpath=yes)
    122  1.1  christos ])
    123  1.1  christos 
    124  1.1  christos dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and
    125  1.1  christos dnl the libraries corresponding to explicit and implicit dependencies.
    126  1.1  christos dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables.
    127  1.1  christos AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
    128  1.1  christos [
    129  1.1  christos   AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
    130  1.1  christos   define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
    131  1.1  christos                                [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
    132  1.1  christos   dnl By default, look in $includedir and $libdir.
    133  1.1  christos   use_additional=yes
    134  1.1  christos   AC_LIB_WITH_FINAL_PREFIX([
    135  1.1  christos     eval additional_includedir=\"$includedir\"
    136  1.1  christos     eval additional_libdir=\"$libdir\"
    137  1.1  christos   ])
    138  1.1  christos   AC_LIB_ARG_WITH([lib$1-prefix],
    139  1.1  christos [  --with-lib$1-prefix[=DIR]  search for lib$1 in DIR/include and DIR/lib
    140  1.1  christos   --without-lib$1-prefix     don't search for lib$1 in includedir and libdir],
    141  1.1  christos [
    142  1.1  christos     if test "X$withval" = "Xno"; then
    143  1.1  christos       use_additional=no
    144  1.1  christos     else
    145  1.1  christos       if test "X$withval" = "X"; then
    146  1.1  christos         AC_LIB_WITH_FINAL_PREFIX([
    147  1.1  christos           eval additional_includedir=\"$includedir\"
    148  1.1  christos           eval additional_libdir=\"$libdir\"
    149  1.1  christos         ])
    150  1.1  christos       else
    151  1.1  christos         additional_includedir="$withval/include"
    152  1.1  christos         additional_libdir="$withval/$acl_libdirstem"
    153  1.1  christos       fi
    154  1.1  christos     fi
    155  1.1  christos ])
    156  1.1  christos   dnl Search the library and its dependencies in $additional_libdir and
    157  1.1  christos   dnl $LDFLAGS. Using breadth-first-seach.
    158  1.1  christos   LIB[]NAME=
    159  1.1  christos   LTLIB[]NAME=
    160  1.1  christos   INC[]NAME=
    161  1.1  christos   rpathdirs=
    162  1.1  christos   ltrpathdirs=
    163  1.1  christos   names_already_handled=
    164  1.1  christos   names_next_round='$1 $2'
    165  1.1  christos   while test -n "$names_next_round"; do
    166  1.1  christos     names_this_round="$names_next_round"
    167  1.1  christos     names_next_round=
    168  1.1  christos     for name in $names_this_round; do
    169  1.1  christos       already_handled=
    170  1.1  christos       for n in $names_already_handled; do
    171  1.1  christos         if test "$n" = "$name"; then
    172  1.1  christos           already_handled=yes
    173  1.1  christos           break
    174  1.1  christos         fi
    175  1.1  christos       done
    176  1.1  christos       if test -z "$already_handled"; then
    177  1.1  christos         names_already_handled="$names_already_handled $name"
    178  1.1  christos         dnl See if it was already located by an earlier AC_LIB_LINKFLAGS
    179  1.1  christos         dnl or AC_LIB_HAVE_LINKFLAGS call.
    180  1.1  christos         uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'`
    181  1.1  christos         eval value=\"\$HAVE_LIB$uppername\"
    182  1.1  christos         if test -n "$value"; then
    183  1.1  christos           if test "$value" = yes; then
    184  1.1  christos             eval value=\"\$LIB$uppername\"
    185  1.1  christos             test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value"
    186  1.1  christos             eval value=\"\$LTLIB$uppername\"
    187  1.1  christos             test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value"
    188  1.1  christos           else
    189  1.1  christos             dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined
    190  1.1  christos             dnl that this library doesn't exist. So just drop it.
    191  1.1  christos             :
    192  1.1  christos           fi
    193  1.1  christos         else
    194  1.1  christos           dnl Search the library lib$name in $additional_libdir and $LDFLAGS
    195  1.1  christos           dnl and the already constructed $LIBNAME/$LTLIBNAME.
    196  1.1  christos           found_dir=
    197  1.1  christos           found_la=
    198  1.1  christos           found_so=
    199  1.1  christos           found_a=
    200  1.1  christos           if test $use_additional = yes; then
    201  1.1  christos             if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then
    202  1.1  christos               found_dir="$additional_libdir"
    203  1.1  christos               found_so="$additional_libdir/lib$name.$shlibext"
    204  1.1  christos               if test -f "$additional_libdir/lib$name.la"; then
    205  1.1  christos                 found_la="$additional_libdir/lib$name.la"
    206  1.1  christos               fi
    207  1.1  christos             else
    208  1.1  christos               if test -f "$additional_libdir/lib$name.$libext"; then
    209  1.1  christos                 found_dir="$additional_libdir"
    210  1.1  christos                 found_a="$additional_libdir/lib$name.$libext"
    211  1.1  christos                 if test -f "$additional_libdir/lib$name.la"; then
    212  1.1  christos                   found_la="$additional_libdir/lib$name.la"
    213  1.1  christos                 fi
    214  1.1  christos               fi
    215  1.1  christos             fi
    216  1.1  christos           fi
    217  1.1  christos           if test "X$found_dir" = "X"; then
    218  1.1  christos             for x in $LDFLAGS $LTLIB[]NAME; do
    219  1.1  christos               AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
    220  1.1  christos               case "$x" in
    221  1.1  christos                 -L*)
    222  1.1  christos                   dir=`echo "X$x" | sed -e 's/^X-L//'`
    223  1.1  christos                   if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then
    224  1.1  christos                     found_dir="$dir"
    225  1.1  christos                     found_so="$dir/lib$name.$shlibext"
    226  1.1  christos                     if test -f "$dir/lib$name.la"; then
    227  1.1  christos                       found_la="$dir/lib$name.la"
    228  1.1  christos                     fi
    229  1.1  christos                   else
    230  1.1  christos                     if test -f "$dir/lib$name.$libext"; then
    231  1.1  christos                       found_dir="$dir"
    232  1.1  christos                       found_a="$dir/lib$name.$libext"
    233  1.1  christos                       if test -f "$dir/lib$name.la"; then
    234  1.1  christos                         found_la="$dir/lib$name.la"
    235  1.1  christos                       fi
    236  1.1  christos                     fi
    237  1.1  christos                   fi
    238  1.1  christos                   ;;
    239  1.1  christos               esac
    240  1.1  christos               if test "X$found_dir" != "X"; then
    241  1.1  christos                 break
    242  1.1  christos               fi
    243  1.1  christos             done
    244  1.1  christos           fi
    245  1.1  christos           if test "X$found_dir" != "X"; then
    246  1.1  christos             dnl Found the library.
    247  1.1  christos             LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name"
    248  1.1  christos             if test "X$found_so" != "X"; then
    249  1.1  christos               dnl Linking with a shared library. We attempt to hardcode its
    250  1.1  christos               dnl directory into the executable's runpath, unless it's the
    251  1.1  christos               dnl standard /usr/lib.
    252  1.1  christos               if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/$acl_libdirstem"; then
    253  1.1  christos                 dnl No hardcoding is needed.
    254  1.1  christos                 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
    255  1.1  christos               else
    256  1.1  christos                 dnl Use an explicit option to hardcode DIR into the resulting
    257  1.1  christos                 dnl binary.
    258  1.1  christos                 dnl Potentially add DIR to ltrpathdirs.
    259  1.1  christos                 dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
    260  1.1  christos                 haveit=
    261  1.1  christos                 for x in $ltrpathdirs; do
    262  1.1  christos                   if test "X$x" = "X$found_dir"; then
    263  1.1  christos                     haveit=yes
    264  1.1  christos                     break
    265  1.1  christos                   fi
    266  1.1  christos                 done
    267  1.1  christos                 if test -z "$haveit"; then
    268  1.1  christos                   ltrpathdirs="$ltrpathdirs $found_dir"
    269  1.1  christos                 fi
    270  1.1  christos                 dnl The hardcoding into $LIBNAME is system dependent.
    271  1.1  christos                 if test "$hardcode_direct" = yes; then
    272  1.1  christos                   dnl Using DIR/libNAME.so during linking hardcodes DIR into the
    273  1.1  christos                   dnl resulting binary.
    274  1.1  christos                   LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
    275  1.1  christos                 else
    276  1.1  christos                   if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then
    277  1.1  christos                     dnl Use an explicit option to hardcode DIR into the resulting
    278  1.1  christos                     dnl binary.
    279  1.1  christos                     LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
    280  1.1  christos                     dnl Potentially add DIR to rpathdirs.
    281  1.1  christos                     dnl The rpathdirs will be appended to $LIBNAME at the end.
    282  1.1  christos                     haveit=
    283  1.1  christos                     for x in $rpathdirs; do
    284  1.1  christos                       if test "X$x" = "X$found_dir"; then
    285  1.1  christos                         haveit=yes
    286  1.1  christos                         break
    287  1.1  christos                       fi
    288  1.1  christos                     done
    289  1.1  christos                     if test -z "$haveit"; then
    290  1.1  christos                       rpathdirs="$rpathdirs $found_dir"
    291  1.1  christos                     fi
    292  1.1  christos                   else
    293  1.1  christos                     dnl Rely on "-L$found_dir".
    294  1.1  christos                     dnl But don't add it if it's already contained in the LDFLAGS
    295  1.1  christos                     dnl or the already constructed $LIBNAME
    296  1.1  christos                     haveit=
    297  1.1  christos                     for x in $LDFLAGS $LIB[]NAME; do
    298  1.1  christos                       AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
    299  1.1  christos                       if test "X$x" = "X-L$found_dir"; then
    300  1.1  christos                         haveit=yes
    301  1.1  christos                         break
    302  1.1  christos                       fi
    303  1.1  christos                     done
    304  1.1  christos                     if test -z "$haveit"; then
    305  1.1  christos                       LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir"
    306  1.1  christos                     fi
    307  1.1  christos                     if test "$hardcode_minus_L" != no; then
    308  1.1  christos                       dnl FIXME: Not sure whether we should use
    309  1.1  christos                       dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
    310  1.1  christos                       dnl here.
    311  1.1  christos                       LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
    312  1.1  christos                     else
    313  1.1  christos                       dnl We cannot use $hardcode_runpath_var and LD_RUN_PATH
    314  1.1  christos                       dnl here, because this doesn't fit in flags passed to the
    315  1.1  christos                       dnl compiler. So give up. No hardcoding. This affects only
    316  1.1  christos                       dnl very old systems.
    317  1.1  christos                       dnl FIXME: Not sure whether we should use
    318  1.1  christos                       dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
    319  1.1  christos                       dnl here.
    320  1.1  christos                       LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
    321  1.1  christos                     fi
    322  1.1  christos                   fi
    323  1.1  christos                 fi
    324  1.1  christos               fi
    325  1.1  christos             else
    326  1.1  christos               if test "X$found_a" != "X"; then
    327  1.1  christos                 dnl Linking with a static library.
    328  1.1  christos                 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a"
    329  1.1  christos               else
    330  1.1  christos                 dnl We shouldn't come here, but anyway it's good to have a
    331  1.1  christos                 dnl fallback.
    332  1.1  christos                 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name"
    333  1.1  christos               fi
    334  1.1  christos             fi
    335  1.1  christos             dnl Assume the include files are nearby.
    336  1.1  christos             additional_includedir=
    337  1.1  christos             case "$found_dir" in
    338  1.1  christos               */$acl_libdirstem | */$acl_libdirstem/)
    339  1.1  christos                 basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'`
    340  1.1  christos                 additional_includedir="$basedir/include"
    341  1.1  christos                 ;;
    342  1.1  christos             esac
    343  1.1  christos             if test "X$additional_includedir" != "X"; then
    344  1.1  christos               dnl Potentially add $additional_includedir to $INCNAME.
    345  1.1  christos               dnl But don't add it
    346  1.1  christos               dnl   1. if it's the standard /usr/include,
    347  1.1  christos               dnl   2. if it's /usr/local/include and we are using GCC on Linux,
    348  1.1  christos               dnl   3. if it's already present in $CPPFLAGS or the already
    349  1.1  christos               dnl      constructed $INCNAME,
    350  1.1  christos               dnl   4. if it doesn't exist as a directory.
    351  1.1  christos               if test "X$additional_includedir" != "X/usr/include"; then
    352  1.1  christos                 haveit=
    353  1.1  christos                 if test "X$additional_includedir" = "X/usr/local/include"; then
    354  1.1  christos                   if test -n "$GCC"; then
    355  1.1  christos                     case $host_os in
    356  1.1  christos                       linux* | gnu* | k*bsd*-gnu) haveit=yes;;
    357  1.1  christos                     esac
    358  1.1  christos                   fi
    359  1.1  christos                 fi
    360  1.1  christos                 if test -z "$haveit"; then
    361  1.1  christos                   for x in $CPPFLAGS $INC[]NAME; do
    362  1.1  christos                     AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
    363  1.1  christos                     if test "X$x" = "X-I$additional_includedir"; then
    364  1.1  christos                       haveit=yes
    365  1.1  christos                       break
    366  1.1  christos                     fi
    367  1.1  christos                   done
    368  1.1  christos                   if test -z "$haveit"; then
    369  1.1  christos                     if test -d "$additional_includedir"; then
    370  1.1  christos                       dnl Really add $additional_includedir to $INCNAME.
    371  1.1  christos                       INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir"
    372  1.1  christos                     fi
    373  1.1  christos                   fi
    374  1.1  christos                 fi
    375  1.1  christos               fi
    376  1.1  christos             fi
    377  1.1  christos             dnl Look for dependencies.
    378  1.1  christos             if test -n "$found_la"; then
    379  1.1  christos               dnl Read the .la file. It defines the variables
    380  1.1  christos               dnl dlname, library_names, old_library, dependency_libs, current,
    381  1.1  christos               dnl age, revision, installed, dlopen, dlpreopen, libdir.
    382  1.1  christos               save_libdir="$libdir"
    383  1.1  christos               case "$found_la" in
    384  1.1  christos                 */* | *\\*) . "$found_la" ;;
    385  1.1  christos                 *) . "./$found_la" ;;
    386  1.1  christos               esac
    387  1.1  christos               libdir="$save_libdir"
    388  1.1  christos               dnl We use only dependency_libs.
    389  1.1  christos               for dep in $dependency_libs; do
    390  1.1  christos                 case "$dep" in
    391  1.1  christos                   -L*)
    392  1.1  christos                     additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
    393  1.1  christos                     dnl Potentially add $additional_libdir to $LIBNAME and $LTLIBNAME.
    394  1.1  christos                     dnl But don't add it
    395  1.1  christos                     dnl   1. if it's the standard /usr/lib,
    396  1.1  christos                     dnl   2. if it's /usr/local/lib and we are using GCC on Linux,
    397  1.1  christos                     dnl   3. if it's already present in $LDFLAGS or the already
    398  1.1  christos                     dnl      constructed $LIBNAME,
    399  1.1  christos                     dnl   4. if it doesn't exist as a directory.
    400  1.1  christos                     if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then
    401  1.1  christos                       haveit=
    402  1.1  christos                       if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then
    403  1.1  christos                         if test -n "$GCC"; then
    404  1.1  christos                           case $host_os in
    405  1.1  christos                             linux* | gnu* | k*bsd*-gnu) haveit=yes;;
    406  1.1  christos                           esac
    407  1.1  christos                         fi
    408  1.1  christos                       fi
    409  1.1  christos                       if test -z "$haveit"; then
    410  1.1  christos                         haveit=
    411  1.1  christos                         for x in $LDFLAGS $LIB[]NAME; do
    412  1.1  christos                           AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
    413  1.1  christos                           if test "X$x" = "X-L$additional_libdir"; then
    414  1.1  christos                             haveit=yes
    415  1.1  christos                             break
    416  1.1  christos                           fi
    417  1.1  christos                         done
    418  1.1  christos                         if test -z "$haveit"; then
    419  1.1  christos                           if test -d "$additional_libdir"; then
    420  1.1  christos                             dnl Really add $additional_libdir to $LIBNAME.
    421  1.1  christos                             LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$additional_libdir"
    422  1.1  christos                           fi
    423  1.1  christos                         fi
    424  1.1  christos                         haveit=
    425  1.1  christos                         for x in $LDFLAGS $LTLIB[]NAME; do
    426  1.1  christos                           AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
    427  1.1  christos                           if test "X$x" = "X-L$additional_libdir"; then
    428  1.1  christos                             haveit=yes
    429  1.1  christos                             break
    430  1.1  christos                           fi
    431  1.1  christos                         done
    432  1.1  christos                         if test -z "$haveit"; then
    433  1.1  christos                           if test -d "$additional_libdir"; then
    434  1.1  christos                             dnl Really add $additional_libdir to $LTLIBNAME.
    435  1.1  christos                             LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$additional_libdir"
    436  1.1  christos                           fi
    437  1.1  christos                         fi
    438  1.1  christos                       fi
    439  1.1  christos                     fi
    440  1.1  christos                     ;;
    441  1.1  christos                   -R*)
    442  1.1  christos                     dir=`echo "X$dep" | sed -e 's/^X-R//'`
    443  1.1  christos                     if test "$enable_rpath" != no; then
    444  1.1  christos                       dnl Potentially add DIR to rpathdirs.
    445  1.1  christos                       dnl The rpathdirs will be appended to $LIBNAME at the end.
    446  1.1  christos                       haveit=
    447  1.1  christos                       for x in $rpathdirs; do
    448  1.1  christos                         if test "X$x" = "X$dir"; then
    449  1.1  christos                           haveit=yes
    450  1.1  christos                           break
    451  1.1  christos                         fi
    452  1.1  christos                       done
    453  1.1  christos                       if test -z "$haveit"; then
    454  1.1  christos                         rpathdirs="$rpathdirs $dir"
    455  1.1  christos                       fi
    456  1.1  christos                       dnl Potentially add DIR to ltrpathdirs.
    457  1.1  christos                       dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
    458  1.1  christos                       haveit=
    459  1.1  christos                       for x in $ltrpathdirs; do
    460  1.1  christos                         if test "X$x" = "X$dir"; then
    461  1.1  christos                           haveit=yes
    462  1.1  christos                           break
    463  1.1  christos                         fi
    464  1.1  christos                       done
    465  1.1  christos                       if test -z "$haveit"; then
    466  1.1  christos                         ltrpathdirs="$ltrpathdirs $dir"
    467  1.1  christos                       fi
    468  1.1  christos                     fi
    469  1.1  christos                     ;;
    470  1.1  christos                   -l*)
    471  1.1  christos                     dnl Handle this in the next round.
    472  1.1  christos                     names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
    473  1.1  christos                     ;;
    474  1.1  christos                   *.la)
    475  1.1  christos                     dnl Handle this in the next round. Throw away the .la's
    476  1.1  christos                     dnl directory; it is already contained in a preceding -L
    477  1.1  christos                     dnl option.
    478  1.1  christos                     names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
    479  1.1  christos                     ;;
    480  1.1  christos                   *)
    481  1.1  christos                     dnl Most likely an immediate library name.
    482  1.1  christos                     LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep"
    483  1.1  christos                     LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep"
    484  1.1  christos                     ;;
    485  1.1  christos                 esac
    486  1.1  christos               done
    487  1.1  christos             fi
    488  1.1  christos           else
    489  1.1  christos             dnl Didn't find the library; assume it is in the system directories
    490  1.1  christos             dnl known to the linker and runtime loader. (All the system
    491  1.1  christos             dnl directories known to the linker should also be known to the
    492  1.1  christos             dnl runtime loader, otherwise the system is severely misconfigured.)
    493  1.1  christos             LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
    494  1.1  christos             LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name"
    495  1.1  christos           fi
    496  1.1  christos         fi
    497  1.1  christos       fi
    498  1.1  christos     done
    499  1.1  christos   done
    500  1.1  christos   if test "X$rpathdirs" != "X"; then
    501  1.1  christos     if test -n "$hardcode_libdir_separator"; then
    502  1.1  christos       dnl Weird platform: only the last -rpath option counts, the user must
    503  1.1  christos       dnl pass all path elements in one option. We can arrange that for a
    504  1.1  christos       dnl single library, but not when more than one $LIBNAMEs are used.
    505  1.1  christos       alldirs=
    506  1.1  christos       for found_dir in $rpathdirs; do
    507  1.1  christos         alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$found_dir"
    508  1.1  christos       done
    509  1.1  christos       dnl Note: hardcode_libdir_flag_spec uses $libdir and $wl.
    510  1.1  christos       acl_save_libdir="$libdir"
    511  1.1  christos       libdir="$alldirs"
    512  1.1  christos       eval flag=\"$hardcode_libdir_flag_spec\"
    513  1.1  christos       libdir="$acl_save_libdir"
    514  1.1  christos       LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
    515  1.1  christos     else
    516  1.1  christos       dnl The -rpath options are cumulative.
    517  1.1  christos       for found_dir in $rpathdirs; do
    518  1.1  christos         acl_save_libdir="$libdir"
    519  1.1  christos         libdir="$found_dir"
    520  1.1  christos         eval flag=\"$hardcode_libdir_flag_spec\"
    521  1.1  christos         libdir="$acl_save_libdir"
    522  1.1  christos         LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
    523  1.1  christos       done
    524  1.1  christos     fi
    525  1.1  christos   fi
    526  1.1  christos   if test "X$ltrpathdirs" != "X"; then
    527  1.1  christos     dnl When using libtool, the option that works for both libraries and
    528  1.1  christos     dnl executables is -R. The -R options are cumulative.
    529  1.1  christos     for found_dir in $ltrpathdirs; do
    530  1.1  christos       LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir"
    531  1.1  christos     done
    532  1.1  christos   fi
    533  1.1  christos ])
    534  1.1  christos 
    535  1.1  christos dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR,
    536  1.1  christos dnl unless already present in VAR.
    537  1.1  christos dnl Works only for CPPFLAGS, not for LIB* variables because that sometimes
    538  1.1  christos dnl contains two or three consecutive elements that belong together.
    539  1.1  christos AC_DEFUN([AC_LIB_APPENDTOVAR],
    540  1.1  christos [
    541  1.1  christos   for element in [$2]; do
    542  1.1  christos     haveit=
    543  1.1  christos     for x in $[$1]; do
    544  1.1  christos       AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
    545  1.1  christos       if test "X$x" = "X$element"; then
    546  1.1  christos         haveit=yes
    547  1.1  christos         break
    548  1.1  christos       fi
    549  1.1  christos     done
    550  1.1  christos     if test -z "$haveit"; then
    551  1.1  christos       [$1]="${[$1]}${[$1]:+ }$element"
    552  1.1  christos     fi
    553  1.1  christos   done
    554  1.1  christos ])
    555