Include screen.h in dialog.h for definition of WScreen
[wmaker-crm.git] / m4 / wm_prog_cc_c11.m4
bloba841e6eabf7136e06cd465f08475a70806760036
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 # WM_PROG_CC_C11
21 # --------------
23 # Check if the compiler supports C11 standard natively, or if any
24 # option may help enabling the support
25 # This is (in concept) similar to AC_PROG_CC_C11, which is unfortunately
26 # not yet available in autotools; as a side effect we only check for
27 # compiler's acknowledgement and a few features instead of full support
28 AC_DEFUN_ONCE([WM_PROG_CC_C11],
29 [AC_CACHE_CHECK([for C11 standard support], [wm_cv_prog_cc_c11],
30     [wm_cv_prog_cc_c11=no
31      wm_save_CFLAGS="$CFLAGS"
32      for wm_arg in dnl
33 "% native"   dnl
34 "-std=c11"
35      do
36          CFLAGS="$wm_save_CFLAGS `echo $wm_arg | sed -e 's,%.*,,' `"
37          AC_COMPILE_IFELSE(
38              [AC_LANG_PROGRAM([], [dnl
39 #if __STDC_VERSION__ < 201112L
40 fail_because_stdc_version_is_older_than_C11;
41 #endif
42 ])],
43              [wm_cv_prog_cc_c11="`echo $wm_arg | sed -e 's,.*% *,,' `" ; break])
44      done
45      CFLAGS="$wm_save_CFLAGS"])
46 AS_CASE([$wm_cv_prog_cc_c11],
47     [no|native], [],
48     [CFLAGS="$CFLAGS $wm_cv_prog_cc_c11"])
52 # WM_PROG_CC_NESTEDFUNC
53 # ---------------------
55 # Check if the compiler support declaring Nested Functions (that means
56 # declaring a function inside another function).
58 # If the compiler does not support them, then the Automake conditional
59 # USE_NESTED_FUNC will be set to false, in which case the Makefile will
60 # use the script 'scripts/nested-func-to-macro.sh' to generate a modified
61 # source with the nested function transformed into a Preprocessor Macro.
62 AC_DEFUN_ONCE([WM_PROG_CC_NESTEDFUNC],
63 [AC_CACHE_CHECK([if compiler supports nested functions], [wm_cv_prog_cc_nestedfunc],
64     [AC_COMPILE_IFELSE(
65         [AC_LANG_SOURCE([[
66 int main(int narg, char **argv)
68         int local_variable;
70         int nested_function(int argument)
71         {
72                 /* Checking we have access to upper level's scope, otherwise it is of no use */
73                 return local_variable + argument;
74         }
76         /* To avoid a warning for unused parameter, that may falsely fail */
77         (void) argv;
79         /* Initialise using the parameter to main so the compiler won't be tempted to optimise too much */
80         local_variable = narg + 1;
82         return nested_function(2);
83 }]]) ],
84         [wm_cv_prog_cc_nestedfunc=yes],
85         [wm_cv_prog_cc_nestedfunc=no]) ])
86 AM_CONDITIONAL([USE_NESTED_FUNC], [test "x$wm_cv_prog_cc_nestedfunc" != "xno"])dnl