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