libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

mhd_find_add_cc_cflag.m4 (3706B)


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