Include screen.h in dialog.h for definition of WScreen
[wmaker-crm.git] / m4 / wm_attributes.m4
blob3b4c8712f74fb08d04cce7ce33da05911e5c8acf
1 # wm_attributes.m4 - Macros to check compiler attributes and define macros
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_C_NORETURN
21 # -------------
23 # Checks if the compiler supports ISO C11 noreturn attribute, if not
24 # try to define the keyword to a known syntax that does the job, or
25 # if nothing works sets it to empty to, at least, be able to
26 # compile the sources
27 AC_DEFUN_ONCE([WM_C_NORETURN],
28 [AC_REQUIRE([_WM_SHELLFN_FUNCATTR])
29 AC_CACHE_CHECK([for noreturn], [wm_cv_c_noreturn],
30     [wm_cv_c_noreturn=no
31      AC_COMPILE_IFELSE(
32       [AC_LANG_PROGRAM(
33           [#include <unistd.h>
34 #include <stdnoreturn.h>
36 /* Attribute in the prototype of the function */
37 noreturn int test_function(void);
39 /* Attribute on the function itself */
40 noreturn int test_function(void) {
41   _exit(1);
43 ], [  test_function();])],
44           [wm_cv_c_noreturn=stdnoreturn],
45           [for wm_attr in  dnl
46              "__attribute__((noreturn))"   dnl for modern GCC-like compilers
47              "__attribute__((__noreturn__))"   dnl for older GCC-like compilers
48              "__declspec(noreturn)"   dnl for some other compilers
49            ; do
50              AS_IF([wm_fn_c_try_compile_funcattr "$wm_attr"],
51                  [wm_cv_c_noreturn="$wm_attr" ; break])
52            done]) dnl
53     ])
54 AS_CASE([$wm_cv_c_noreturn],
55     [stdnoreturn],
56         [AC_DEFINE([HAVE_STDNORETURN], 1,
57             [Defined if header "stdnoreturn.h" exists, it defines ISO C11 attribute 'noreturn' and it works])],
58     [no],
59         [AC_DEFINE([noreturn], [],
60             [Defines the attribute to tell the compiler that a function never returns, if the ISO C11 attribute does not work])],
61     [AC_DEFINE_UNQUOTED([noreturn], [${wm_cv_c_noreturn}],
62         [Defines the attribute to tell the compiler that a function never returns, if the ISO C11 attribute does not work])])
66 # _WM_SHELLFN_FUNCATTRIBUTE
67 # -------------------------
68 # (internal shell function only!)
70 # Create a shell function to check if we can compile with special
71 # function attributes
72 AC_DEFUN([_WM_SHELLFN_FUNCATTR],
73 [@%:@ wm_fn_c_try_compile_funcattr ATTRIBUTE
74 @%:@ ---------------------------------------
75 @%:@ Try compiling a function with the attribute ATTRIBUTE
76 wm_fn_c_try_compile_funcattr ()
78   AC_COMPILE_IFELSE(
79       [AC_LANG_PROGRAM(
80           [
81 /* Attribute in the prototype of the function */
82 int test_function(int arg) $[]1;
84 /* Attribute on the function itself */
85 $[]1 int test_function(int arg) {
86   return arg - 1;
87 }], [int val;
88 val = test_function(1);
89 return val;])],
90       [wm_retval=0],
91       [wm_retval=1])
92   AS_SET_STATUS([$wm_retval])