mhd_find_lib.m4 (5346B)
1 # SYNOPSIS 2 # 3 # MHD_FIND_LIB([FUNCTION_NAME], 4 # [INCLUDES=AC_INCLUDES_DEFAULT], [CHECK_CODE], 5 # [LIBS_TO_CHECK], 6 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND], 7 # [VAR_TO_PREPEND_LIB=LIBS], [ADDITIONAL_LIBS]) 8 # 9 # DESCRIPTION 10 # 11 # This macro checks for presence of specific function by including 12 # specified headers and compiling and linking CHECK_CODE. 13 # This checks both the declaration and the presence in library. 14 # If declaration is not found in headers then libraries are not 15 # checked. 16 # LIBS_TO_CHECK is whitespace-separated list of libraries to check. 17 # The macro first tries to link without any library, and if it fails 18 # the libraries are checked one by one. 19 # The required library (if any) prepended to VAR_TO_PREPEND_LIB (or 20 # to the LIBS variable if VAR_TO_APPEND_LIB is not specified). 21 # By using definition from provided headers, this macro ensures that 22 # correct calling convention is used for detection. 23 # 24 # Example usage: 25 # 26 # MHD_FIND_LIB([clock_gettime], 27 # [[#include <time.h>]], 28 # [[struct timespec tp; 29 # if (0 > clock_gettime(CLOCK_REALTIME, &tp)) return 3;]], 30 # [rt], 31 # [var_use_gettime='yes'],[var_use_gettime='no']) 32 # 33 # Defined cache variable used in the check so if any test will not 34 # work correctly on some platform, a user may simply fix it by giving 35 # cache variable in configure parameters, for example: 36 # 37 # ./configure mhd_cv_find_clock_gettime=no 38 # 39 # This simplifies building from source on exotic platforms as patching 40 # of configure.ac is not required to change results of tests. 41 # 42 # LICENSE 43 # 44 # Copyright (c) 2023 Karlson2k (Evgeny Grin) <k2k@narod.ru> 45 # 46 # Copying and distribution of this file, with or without modification, are 47 # permitted in any medium without royalty provided the copyright notice 48 # and this notice are preserved. This file is offered as-is, without any 49 # warranty. 50 51 #serial 1 52 53 AC_DEFUN([MHD_FIND_LIB],[dnl 54 AC_PREREQ([2.64])dnl for AS_VAR_IF, m4_ifblank, m4_ifnblank 55 m4_newline([[# Expansion of $0 macro starts here]]) 56 AC_LANG_ASSERT([C])dnl 57 m4_ifblank(m4_translit([$1],[()],[ ]), [m4_fatal([First macro argument FUNCTION_NAME must not be empty])])dnl 58 m4_ifblank([$3], [m4_fatal([Third macro argument CHECK_CODE must not be empty])])dnl 59 m4_bmatch(m4_normalize([$1]), [\s],dnl 60 [m4_fatal([First macro argument FUNCTION_NAME must not contain whitespaces])])dnl 61 m4_if(m4_index([$3], m4_normalize(m4_translit([$1],[()],[ ]))), [-1], dnl 62 [m4_fatal([CHECK_CODE parameter (third macro argument) does not contain ']m4_normalize([$1])[' token])])dnl 63 m4_bmatch([$7], [\$], [m4_fatal([$0: Seventh macro argument VAR_TO_PREPEND_LIB must not contain '$'])])dnl 64 _MHD_FIND_LIB_BODY([$1],[$2],[$3],[$4],[$5],[$6],m4_default_nblank(_mhd_norm_expd([$7]),[LIBS]),[$8])dnl 65 ])dnl AC_DEFUN MHD_FIND_LIB 66 67 # SYNOPSIS 68 # 69 # _MHD_FIND_LIB_BODY([1_FUNCTION_NAME], 70 # [2_INCLUDES=AC_INCLUDES_DEFAULT], [3_CHECK_CODE], 71 # [4_LIBS_TO_CHECK], 72 # [5_ACTION-IF-FOUND], [6_ACTION-IF-NOT-FOUND], 73 # [7_VAR_TO_PREPEND_LIB=LIBS], [8_ADDITIONAL_LIBS]) 74 75 AC_DEFUN([_MHD_FIND_LIB_BODY],[dnl 76 AS_VAR_PUSHDEF([decl_cv_Var],[ac_cv_have_decl_]m4_bpatsubst(_mhd_norm_expd(m4_translit([$1],[()],[ ])),[[^a-zA-Z0-9]],[_]))dnl 77 AS_VAR_PUSHDEF([cv_Var], [mhd_cv_find_lib_]m4_bpatsubst(_mhd_norm_expd(m4_translit([$1],[()],[ ])),[[^a-zA-Z0-9]],[_]))dnl 78 AS_VAR_SET_IF([cv_Var],[],[AC_CHECK_DECL(_mhd_norm_expd([$1]),[],[],[$2])]) 79 AC_CACHE_CHECK([for library containing function $1], [cv_Var], 80 [ 81 AS_VAR_IF([decl_cv_Var],["yes"],dnl 82 [dnl 83 mhd_find_lib_SAVE_LIBS="$LIBS" 84 m4_if([$7],LIBS,[dnl 85 mhd_find_lib_CHECK_LIBS="_mhd_norm_expd([$8]) $LIBS" 86 ],[dnl 87 mhd_find_lib_CHECK_LIBS="[$]$7 _mhd_norm_expd([$8]) $LIBS" 88 ] 89 ) 90 # Reuse the same source file 91 AC_LANG_CONFTEST( 92 [AC_LANG_SOURCE([ 93 m4_default_nblank([$2],[AC_INCLUDES_DEFAULT]) 94 95 [int main(void) 96 { 97 98 ]$3[ 99 100 return 0; 101 } 102 ]]) 103 ] 104 ) 105 for mhd_find_lib_LIB in '' $4 106 do 107 AS_IF([test -z "${mhd_find_lib_LIB}"], 108 [LIBS="${mhd_find_lib_CHECK_LIBS}"], 109 [LIBS="-l${mhd_find_lib_LIB} ${mhd_find_lib_CHECK_LIBS}"] 110 ) 111 AC_LINK_IFELSE([], 112 [ 113 AS_IF([test -z "${mhd_find_lib_LIB}"], 114 [AS_VAR_SET([cv_Var],["none required"])], 115 [AS_VAR_SET([cv_Var],["-l${mhd_find_lib_LIB}"])] 116 ) 117 ] 118 ) 119 AS_VAR_SET_IF([cv_Var],[break]) 120 done 121 AS_UNSET([mhd_find_lib_LIB]) 122 rm -f conftest.$ac_ext 123 LIBS="${mhd_find_lib_SAVE_LIBS}" 124 AS_UNSET([mhd_find_lib_SAVE_LIBS]) 125 ] 126 ) 127 AS_VAR_SET_IF([cv_Var],[:],[AS_VAR_SET([cv_Var],["no"])]) 128 ] 129 ) 130 AS_IF([test "x${cv_Var}" != "xno"], 131 [dnl 132 AS_VAR_IF([cv_Var],["none required"],[:], 133 [ 134 AS_IF([test -z "[$]$7"],[$7="${cv_Var}"],[$7="${cv_Var} [$]$7"]) 135 ] 136 ) 137 m4_n([$5])dnl 138 ],[$6])dnl AS_VAR_SET_IF cv_Var 139 AS_VAR_POPDEF([cv_Var])dnl 140 AS_VAR_POPDEF([decl_cv_Var])dnl 141 m4_newline([[# Expansion of $0 macro ends here]]) 142 ])dnl AC_DEFUN MHD_CHECK_FUNC