mhd_check_link_run.m4 (2775B)
1 # SPDX-License-Identifier: FSFAP 2 # 3 # SYNOPSIS 4 # 5 # MHD_CHECK_LINK_RUN(MESSAGE, CACHE_ID, COMMAND_IF_CROSS_COMPILING, INPUT, 6 # [ACTION_IF_SUCCEED], [ACTION_IF_FAILED]) 7 # 8 # DESCRIPTION 9 # 10 # Improved version of AC_RUN_IFELSE macro. 11 # Unlike AC_RUN_IFELSE, this macro tries to link the code if cross-compiling. 12 # Action COMMAND_IF_CROSS_COMPILING is executed only if link is succeed, 13 # otherwise CACHE_ID variable set to "no". 14 # COMMAND_IF_CROSS_COMPILING action must set CACHE_ID variable to "yes", "no", 15 # "assuming yes" or "assuming no". 16 # ACTION_IF_SUCCEED is executed if result is "yes" or "assuming yes". 17 # ACTION_IF_FAILED is executed if result is "no" or "assuming no". 18 # 19 # Example usage: 20 # 21 # MHD_CHECK_LINK_RUN([for valid snprintf()], [mhd_cv_snprintf_valid], 22 # [mhd_cv_snprintf_valid='assuming no'], 23 # [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], 24 # [if (4 != snprintf(NULL, 0, "test")) 25 # return 2;])]) 26 # 27 # 28 # LICENSE 29 # 30 # Copyright (c) 2022 Karlson2k (Evgeny Grin) <k2k@narod.ru> 31 # 32 # Copying and distribution of this file, with or without modification, are 33 # permitted in any medium without royalty provided the copyright notice 34 # and this notice are preserved. This file is offered as-is, without any 35 # warranty. 36 37 #serial 3 38 39 AC_DEFUN([MHD_CHECK_LINK_RUN],[dnl 40 m4_ifblank([$1],[m4_fatal([$0: The first macro argument ("MESSAGE") must not be empty])])dnl 41 m4_ifblank([$2],[m4_fatal([$0: The second macro argument ("CACHE_ID") must not be empty])])dnl 42 m4_ifblank([$3],[m4_fatal([$0: The third macro argument ("COMMAND_IF_CROSS_COMPILING") ]dnl 43 [must not be empty])])dnl 44 m4_ifblank([$4],[m4_fatal([$0: The fourth macro argument ("INPUT") must not be empty])])dnl 45 m4_bmatch(_mhd_norm_expd([$2]),[\s],dnl 46 [m4_fatal([$0: The second macro argument ("CACHE_ID") must not contain whitespaces])])dnl 47 m4_bmatch(_mhd_norm_expd([$3]),[\<]m4_re_escape(_mhd_norm_expd([$2]))[\>],[],dnl 48 [m4_fatal([$0: The third macro argument ("COMMAND_IF_CROSS_COMPILING") must assign ]dnl 49 [a value to the cache variable ']_mhd_norm_expd([$2])['])])dnl 50 m4_pushdef([cacheVar],_mhd_norm_expd([$2]))dnl 51 AC_CACHE_CHECK([$1],[$2], 52 [ 53 AC_LANG_CONFTEST([$4]) 54 AS_VAR_IF([cross_compiling],["yes"], 55 [AC_LINK_IFELSE([],[ 56 $3 57 ],[cacheVar='no'])dnl AC_LINK_IFELSE 58 ],dnl 59 [AC_RUN_IFELSE([],[cacheVar='yes'],[cacheVar='no'],[[# Dummy placeholder]]) 60 ]) 61 rm -f conftest.$ac_ext 62 ]) 63 m4_ifnblank([$5],[ 64 AS_IF([test "x$cacheVar" = "xyes" || test "x$cacheVar" = "xassuming yes"],[$5])dnl AS_IF 65 ])dnl m4_ifnblank 66 m4_ifnblank([$6],[ 67 AS_IF([test "x$cacheVar" = "xno" || test "x$cacheVar" = "xassuming no"],[$6])dnl AS_IF 68 ])dnl m4_ifnblank 69 ])dnl AC_DEFUN