| 1 |
# =========================================================================== |
| 2 |
# tl_search_libs_source.m4 |
| 3 |
# =========================================================================== |
| 4 |
# |
| 5 |
# SYNOPSIS |
| 6 |
# |
| 7 |
# TL_SEARCH_LIBS_SOURCE(FUNCTION, LIBRARIES, |
| 8 |
# [OTHER-LIBRARIES], [SOURCE]) |
| 9 |
# |
| 10 |
# Extend `AC_SEARCH_LIBS' by calling SOURCE, if given, to test for the |
| 11 |
# availability of FUNCTION. |
| 12 |
# |
| 13 |
# Search for a library defining FUNCTION if it is not already |
| 14 |
# available. If SOURCE is not given, this equates to calling |
| 15 |
# `AC_LINK_IFELSE([AC_LANG_CALL([], [FUNCTION])])' first with no |
| 16 |
# libraries, then for each library listed in LIBRARIES and with each |
| 17 |
# search path in SEARCH-PATHS. If SOURCE is given, call |
| 18 |
# `AC_LINK_IFELSE([AC_LANG_SOURCE([$5])])'. |
| 19 |
# |
| 20 |
# Prepend `-lLIBRARY' to `LIBS' for the first library found to contain |
| 21 |
# FUNCTION. |
| 22 |
# |
| 23 |
# The result of this test is cached in the `tl_cv_search_source_FUNCTION' |
| 24 |
# variable as `none required' if FUNCTION is already available, as `no' |
| 25 |
# if no library containing FUNCTION was found, otherwise as the |
| 26 |
# `-lLIBRARY' option that needs to be prepended to `LIBS'. |
| 27 |
# |
| 28 |
# Example: |
| 29 |
# |
| 30 |
# On Darwin, iconv.h typedef's iconv() to libiconv(). Therefore, one |
| 31 |
# must include <iconv.h> in the test program to check for iconv(). |
| 32 |
# |
| 33 |
# TL_SEARCH_LIBS_SOURCE([iconv], [iconv], [], |
| 34 |
# [#include <iconv.h> |
| 35 |
# int main(void) |
| 36 |
# {char *a; return iconv(0, &a, (size_t*)a, &a, (size_t*)a);}]) |
| 37 |
# |
| 38 |
# |
| 39 |
# LICENSE |
| 40 |
# |
| 41 |
# Copyright (c) 2018 Thomas Loimer <[email protected]> |
| 42 |
# |
| 43 |
# Copying and distribution of this file, with or without modification, are |
| 44 |
# permitted in any medium without royalty provided the copyright notice |
| 45 |
# and this notice are preserved. This file is offered as-is, without any |
| 46 |
# warranty. |
| 47 |
|
| 48 |
|
| 49 |
# TL_SEARCH_LIBS_SOURCE(FUNCTION, LIBRARIES, |
| 50 |
# [OTHER-LIBRARIES], [SOURCE]) |
| 51 |
# |
| 52 |
AC_DEFUN([TL_SEARCH_LIBS_SOURCE], |
| 53 |
[AS_VAR_PUSHDEF([tl_Search], [tl_cv_search_source_$1])dnl |
| 54 |
AC_CACHE_CHECK([for library providing $1], [tl_Search], |
| 55 |
[m4_ifval([$4],dnl AS_VAR_SET_IF expands to a shell construct |
| 56 |
[AC_LANG_CONFTEST([AC_LANG_SOURCE([$4])])], |
| 57 |
[AC_LANG_CONFTEST([AC_LANG_CALL([], [$1])])]) |
| 58 |
tl_libs_source_save_LIBS=$LIBS |
| 59 |
for tl_lib in '' $2; do |
| 60 |
if test -z "$tl_lib"; then |
| 61 |
tl_res="none required" |
| 62 |
else |
| 63 |
tl_res=-l$tl_lib |
| 64 |
LIBS="-l$tl_lib $3 $tl_libs_source_save_LIBS" |
| 65 |
fi |
| 66 |
AC_LINK_IFELSE([], [AS_VAR_SET([tl_Search], [$tl_res])]) |
| 67 |
AS_VAR_SET_IF([tl_Search], [break]) |
| 68 |
done |
| 69 |
AS_VAR_SET_IF([tl_Search], , [AS_VAR_SET([tl_Search], [no])]) |
| 70 |
rm conftest.$ac_ext |
| 71 |
LIBS=$tl_libs_source_save_LIBS]) |
| 72 |
AS_VAR_COPY([tl_res], [tl_Search]) |
| 73 |
AS_IF([test "$tl_res" != no], |
| 74 |
[test "$tl_res" = "none required" || LIBS="$tl_res $LIBS"]) |
| 75 |
AS_VAR_POPDEF([tl_Search])dnl |
| 76 |
]) |