mhd_find_add_cc_cflag.m4 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # SYNOPSIS
  2. #
  3. # MHD_FIND_ADD_CC_CFLAG([VARIABLE-TO-EXTEND],
  4. # [FLAG1-TO-TEST], [FLAG2-TO-TEST], ...)
  5. #
  6. # DESCRIPTION
  7. #
  8. # This macro checks whether the specific compiler flags are supported.
  9. # The flags are checked one-by-one. The checking is stopped when the first
  10. # supported flag found.
  11. # The checks are performing by appending FLAGx-TO-TEST to the value of
  12. # VARIABLE-TO-EXTEND (CFLAGS if not specified), then prepending result to
  13. # CFLAGS (unless VARIABLE-TO-EXTEND is CFLAGS), and then performing compile
  14. # and link test. If test succeed without warnings, then the flag is added to
  15. # VARIABLE-TO-EXTEND and next flags are not checked. If compile-link cycle
  16. # cannot be performed without warning with all tested flags, no flag is
  17. # added to the VARIABLE-TO-EXTEND.
  18. #
  19. # Example usage:
  20. #
  21. # MHD_CHECK_CC_CFLAG([additional_CFLAGS],
  22. # [-ggdb3], [-g3], [-ggdb], [-g])
  23. #
  24. # Note: Unlike others MHD_CHECK_*CC_CFLAG* macro, this macro uses another
  25. # order of parameters.
  26. #
  27. # LICENSE
  28. #
  29. # Copyright (c) 2022 Karlson2k (Evgeny Grin) <k2k@narod.ru>
  30. #
  31. # Copying and distribution of this file, with or without modification, are
  32. # permitted in any medium without royalty provided the copyright notice
  33. # and this notice are preserved. This file is offered as-is, without any
  34. # warranty.
  35. #serial 2
  36. AC_DEFUN([MHD_FIND_ADD_CC_CFLAG],[dnl
  37. _MHD_FIND_ADD_CC_XFLAG([[CFLAGS]],[],[],$@)])
  38. # SYNOPSIS
  39. #
  40. # _MHD_FIND_ADD_CC_XFLAG([CFLAGS|LDFLAGS],
  41. # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
  42. # [VARIABLE-TO-EXTEND],
  43. # [FLAG1-TO-TEST], [FLAG2-TO-TEST], ...)
  44. #
  45. AC_DEFUN([_MHD_FIND_ADD_CC_XFLAG],[dnl
  46. AC_PREREQ([2.64])dnl for m4_ifnblank
  47. AC_LANG_ASSERT([C])dnl
  48. m4_if(m4_eval([$# >= 5]), [0], [m4_fatal([$0: Macro must have at least five parameters])])dnl
  49. m4_ifblank([$5],[m4_fatal([$0: Fifth macro argument must not be empty])])dnl
  50. m4_ifnblank([$2$3],[m4_newline([m4_n([AS_UNSET([mhd_cc_found_flag])])])])dnl
  51. m4_bmatch(_mhd_norm_expd([$1]), [^\(CFLAGS\|LDFLAGS\)$],[],dnl
  52. [m4_fatal([$0: First macro argument must be either 'CFLAGS' or 'LDFLAGS; ']_mhd_norm_expd([$1])[' is not supported])])dnl
  53. m4_ifnblank([$4],[_MHD_FIND_ADD_CC_XFLAG_BODY(m4_ifnblank([$2$3],[mhd_cc_found_flag]),[$1],[$4],m4_shiftn([4],$@))],dnl
  54. [_MHD_FIND_ADD_CC_XFLAG_BODY(m4_ifnblank([$2$3],[mhd_cc_found_flag]),[$1],[$1],m4_shiftn([4],$@))])dnl
  55. m4_ifnblank([$2$3],[
  56. AS_IF([test -n "${mhd_cc_found_flag}"],[$2],[$3])
  57. AS_UNSET([mhd_cc_found_flag])
  58. ])dnl
  59. ])dnl
  60. ])
  61. # SYNOPSIS
  62. #
  63. # _MHD_FIND_ADD_CC_XFLAG_BODY([VAR-TO-SET],
  64. # [CFLAGS|LDFLAGS],
  65. # [VARIABLE-TO-EXTEND],
  66. # [FLAG1-TO-TEST], [FLAG2-TO-TEST], ...)
  67. #
  68. m4_define([_MHD_FIND_ADD_CC_XFLAG_BODY],[dnl
  69. m4_version_prereq([2.64])dnl for m4_ifnblank
  70. m4_if([$#],[0],[m4_fatal([$0: no parameters])])dnl
  71. m4_bmatch(_mhd_norm_expd([$2]),[^\(CFLAGS\|LDFLAGS\)$],[],dnl
  72. [m4_fatal([$0: Second macro argument must be either 'CFLAGS' or 'LDFLAGS; ']_mhd_norm_expd([$2])[' is not supported])])dnl
  73. m4_if([$#],[1],[m4_fatal([$0: not enough parameters])])dnl
  74. m4_if([$#],[2],[m4_fatal([$0: not enough parameters])])dnl
  75. m4_if([$#],[3],[m4_fatal([$0: not enough parameters])])dnl
  76. m4_if([$#],[4],[m4_ifnblank([$4],[_MHD_CHECK_ADD_CC_XFLAG([$4],[$3],m4_ifnblank([$1],[$1="_mhd_norm_expd([$4])"]),[],[$2])])],
  77. [m4_ifnblank([$4],[_MHD_CHECK_ADD_CC_XFLAG([$4],[$3],m4_ifnblank([$1],[$1="_mhd_norm_expd([$4])"]),[$0([$1],[$2],[$3],m4_shiftn([4],$@))],[$2])],
  78. [$0([$1],[$2],[$3],m4_shiftn([4],$@))])])dnl
  79. ])