libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

mhd_find_add_cc_cflag.m4 (3671B)


      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 
     36 #serial 2
     37 
     38 AC_DEFUN([MHD_FIND_ADD_CC_CFLAG],[dnl
     39 _MHD_FIND_ADD_CC_XFLAG([[CFLAGS]],[],[],$@)])
     40 
     41 
     42 # SYNOPSIS
     43 #
     44 #   _MHD_FIND_ADD_CC_XFLAG([CFLAGS|LDFLAGS],
     45 #                          [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
     46 #                          [VARIABLE-TO-EXTEND],
     47 #                          [FLAG1-TO-TEST], [FLAG2-TO-TEST], ...)
     48 #
     49 AC_DEFUN([_MHD_FIND_ADD_CC_XFLAG],[dnl
     50   AC_PREREQ([2.64])dnl for m4_ifnblank
     51   AC_LANG_ASSERT([C])dnl
     52   m4_if(m4_eval([$# >= 5]), [0], [m4_fatal([$0: Macro must have at least five parameters])])dnl
     53   m4_ifblank([$5],[m4_fatal([$0: Fifth macro argument must not be empty])])dnl
     54   m4_ifnblank([$2$3],[m4_newline([m4_n([AS_UNSET([mhd_cc_found_flag])])])])dnl
     55   m4_bmatch(_mhd_norm_expd([$1]), [^\(CFLAGS\|LDFLAGS\)$],[],dnl
     56    [m4_fatal([$0: First macro argument must be either 'CFLAGS' or 'LDFLAGS; ']_mhd_norm_expd([$1])[' is not supported])])dnl
     57   m4_ifnblank([$4],[_MHD_FIND_ADD_CC_XFLAG_BODY(m4_ifnblank([$2$3],[mhd_cc_found_flag]),[$1],[$4],m4_shiftn([4],$@))],dnl
     58   [_MHD_FIND_ADD_CC_XFLAG_BODY(m4_ifnblank([$2$3],[mhd_cc_found_flag]),[$1],[$1],m4_shiftn([4],$@))])dnl
     59   m4_ifnblank([$2$3],[
     60     AS_IF([test -n "${mhd_cc_found_flag}"],[$2],[$3])
     61     AS_UNSET([mhd_cc_found_flag])
     62     ])dnl
     63   ])dnl
     64 ])
     65 
     66 
     67 # SYNOPSIS
     68 #
     69 #   _MHD_FIND_ADD_CC_XFLAG_BODY([VAR-TO-SET],
     70 #                               [CFLAGS|LDFLAGS],
     71 #                               [VARIABLE-TO-EXTEND],
     72 #                               [FLAG1-TO-TEST], [FLAG2-TO-TEST], ...)
     73 #
     74 m4_define([_MHD_FIND_ADD_CC_XFLAG_BODY],[dnl
     75 m4_version_prereq([2.64])dnl for m4_ifnblank
     76 m4_if([$#],[0],[m4_fatal([$0: no parameters])])dnl
     77 m4_bmatch(_mhd_norm_expd([$2]),[^\(CFLAGS\|LDFLAGS\)$],[],dnl
     78 [m4_fatal([$0: Second macro argument must be either 'CFLAGS' or 'LDFLAGS; ']_mhd_norm_expd([$2])[' is not supported])])dnl
     79 m4_if([$#],[1],[m4_fatal([$0: not enough parameters])])dnl
     80 m4_if([$#],[2],[m4_fatal([$0: not enough parameters])])dnl
     81 m4_if([$#],[3],[m4_fatal([$0: not enough parameters])])dnl
     82 m4_if([$#],[4],[m4_ifnblank([$4],[_MHD_CHECK_ADD_CC_XFLAG([$4],[$3],m4_ifnblank([$1],[$1="_mhd_norm_expd([$4])"]),[],[$2])])],
     83 [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])],
     84 [$0([$1],[$2],[$3],m4_shiftn([4],$@))])])dnl
     85 ])