1 # wm_prog_cc_c11.m4 - Macros to see if compiler may support STD C11
3 # Copyright (c) 2013 Christophe CURIS
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 # ---------------------
22 # Check if the compiler supports C11 standard natively, or if any
23 # option may help enabling the support
24 # This is (in concept) similar to AC_PROG_CC_C11, which is unfortunately
25 # not yet available in autotools; as a side effect we only check for
26 # compiler's acknowledgement and a few features instead of full support
27 AC_DEFUN_ONCE([WM_PROG_CC_C11],
28 [AC_CACHE_CHECK([for C11 standard support], [wm_cv_prog_cc_c11],
30 wm_save_CFLAGS="$CFLAGS"
35 CFLAGS="$wm_save_CFLAGS `echo $wm_arg | sed -e 's,%.*,,' `"
37 [AC_LANG_PROGRAM([], [dnl
38 #if __STDC_VERSION__ < 201112L
39 fail_because_stdc_version_is_older_than_C11;
42 [wm_cv_prog_cc_c11="`echo $wm_arg | sed -e 's,.*% *,,' `" ; break])
44 CFLAGS="$wm_save_CFLAGS"])
45 AS_CASE([$wm_cv_prog_cc_c11],
47 [CFLAGS="$CFLAGS $wm_cv_prog_cc_c11"])
51 # WM_PROG_CC_NESTEDFUNC
52 # ---------------------
54 # Check if the compiler support declaring Nested Functions (that means
55 # declaring a function inside another function).
57 # If the compiler does not support them, then the Automake conditional
58 # USE_NESTED_FUNC will be set to false, in which case the Makefile will
59 # use the script 'scripts/nested-func-to-macro.sh' to generate a modified
60 # source with the nested function transformed into a Preprocessor Macro.
61 AC_DEFUN_ONCE([WM_PROG_CC_NESTEDFUNC],
62 [AC_CACHE_CHECK([if compiler supports nested functions], [wm_cv_prog_cc_nestedfunc],
65 int main(int narg, char **argv)
69 int nested_function(int argument)
71 /* Checking we have access to upper level's scope, otherwise it is of no use */
72 return local_variable + argument;
75 /* To avoid a warning for unused parameter, that may falsely fail */
78 /* Initialise using the parameter to main so the compiler won't be tempted to optimise too much */
79 local_variable = narg + 1;
81 return nested_function(2);
83 [wm_cv_prog_cc_nestedfunc=yes],
84 [wm_cv_prog_cc_nestedfunc=no]) ])
85 AM_CONDITIONAL([USE_NESTED_FUNC], [test "x$wm_cv_prog_cc_nestedfunc" != "xno"])dnl