libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

lib-link.m4 (35796B)


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