From 34089d766156c119dc73bea3e85bf5ae451fa23a Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sun, 9 Jun 2013 19:21:15 +0200 Subject: [PATCH] Configure: Added check for compiler attribute 'noreturn' This attribute for functions was not standard until recently, so there are a few different possible syntax. With this patch, the configure script will search for the proper syntax, and define what is needed to have the attribute compile correctly. Signed-off-by: Christophe CURIS --- configure.ac | 1 + m4/wm_attributes.m4 | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 m4/wm_attributes.m4 diff --git a/configure.ac b/configure.ac index 3feeaaeb..2f04b02c 100644 --- a/configure.ac +++ b/configure.ac @@ -247,6 +247,7 @@ dnl ============================================================== AC_DECL_SYS_SIGLIST AC_C_CONST AC_C_INLINE +WM_C_NORETURN AC_TYPE_SIZE_T AC_TYPE_PID_T AC_TYPE_SIGNAL diff --git a/m4/wm_attributes.m4 b/m4/wm_attributes.m4 new file mode 100644 index 00000000..545fe820 --- /dev/null +++ b/m4/wm_attributes.m4 @@ -0,0 +1,92 @@ +# wm_attributes.m4 - Macros to check compiler attributes and define macros +# +# Copyright (c) 2013 Christophe Curis +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# WM_C_NORETURN +# ------------- +# +# Checks if the compiler supports ISO C11 noreturn attribute, if not +# try to define the keyword to a known syntax that does the job, or +# if nothing works sets it to empty to, at least, be able to +# compile the sources +AC_DEFUN_ONCE([WM_C_NORETURN], +[AC_REQUIRE([_WM_SHELLFN_FUNCATTR]) +AC_CACHE_CHECK([for noreturn], [wm_cv_c_noreturn], + [wm_cv_c_noreturn=no + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [#include +#include + +/* Attribute in the prototype of the function */ +noreturn int test_function(void); + +/* Attribute on the function itself */ +noreturn int test_function(void) { + _exit(1); +} +], [ test_function();])], + [wm_cv_c_noreturn=stdnoreturn], + [for wm_attr in dnl + "__attribute__((noreturn))" dnl for modern GCC-like compilers + "__attribute__((__noreturn__))" dnl for older GCC-like compilers + "__declspec(noreturn)" dnl for some other compilers + ; do + AS_IF([wm_fn_c_try_compile_funcattr "$wm_attr"], + [wm_cv_c_noreturn="$wm_attr" ; break]) + done]) dnl + ]) +AS_CASE([$wm_cv_c_noreturn], + [stdnoreturn], + [AC_DEFINE([HAVE_STDNORETURN], 1, + [Defined if header "stdnoreturn.h" exists, it defines ISO C11 attribute 'noreturn' and it works])], + [no], + [AC_DEFINE([noreturn], [], + [Defines the attribute to tell the compiler that a function never returns, if the ISO C11 attribute does not work])], + [AC_DEFINE_UNQUOTED([noreturn], [${wm_cv_c_noreturn}], + [Defines the attribute to tell the compiler that a function never returns, if the ISO C11 attribute does not work])]) +]) + +# _WM_SHELLFN_FUNCATTRIBUTE +# ---------------------- +# (internal shell function only!) +# +# Create a shell function to check if we can compile with special +# function attributes +AC_DEFUN([_WM_SHELLFN_FUNCATTR], +[@%:@ wm_fn_c_try_compile_funcattr ATTRIBUTE +@%:@ --------------------------------------- +@%:@ Try compiling a function with the attribute ATTRIBUTE +wm_fn_c_try_compile_funcattr () +{ + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [ +/* Attribute in the prototype of the function */ +int test_function(int arg) $[]1; + +/* Attribute on the function itself */ +$[]1 int test_function(int arg) { + return arg - 1; +}], [int val; +val = test_function(1); +return val;])], + [wm_retval=0], + [wm_retval=1]) + AS_SET_STATUS([$wm_retval]) +} +]) -- 2.11.4.GIT