From 46f900c065f65013ae58a97f3b991a7e0c5ab669 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Fri, 8 Jan 2021 02:24:51 -0500 Subject: sim: require a C11 compiler With GDB requiring a C++11 compiler now, this hopefully shouldn't be a big deal. It's been 10 years since C11 came out, so should be plenty of time to upgrade. This will allow us to start cleaning up random header logic and many of our non-standard custom types. --- sim/common/ChangeLog | 6 ++++++ sim/common/Make-common.in | 3 ++- sim/common/acinclude.m4 | 26 ++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) (limited to 'sim/common') diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index 05948f2..df78108 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,3 +1,9 @@ +2021-01-08 Mike Frysinger + + * Make-common.in (C_DIALECT): Define. + (COMPILE.pre): Append $(C_DIALECT). + * acinclude.m4 (SIM_AC_COMMON): Probe C11 to define C_DIALECT. + 2021-01-07 Mike Frysinger * sim-core.c (sim_memory_map): Define. diff --git a/sim/common/Make-common.in b/sim/common/Make-common.in index 21e1d99..6e71930 100644 --- a/sim/common/Make-common.in +++ b/sim/common/Make-common.in @@ -70,6 +70,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_DATA = @INSTALL_DATA@ CC = @CC@ +C_DIALECT = @C_DIALECT@ CC_FOR_BUILD = @CC_FOR_BUILD@ CFLAGS = @CFLAGS@ CPPFLAGS = @CPPFLAGS@ @@ -107,7 +108,7 @@ depcomp = $(SHELL) $(srcroot)/depcomp # Note that these are overridden by GNU make-specific code below if # GNU make is used. The overrides implement dependency tracking. -COMPILE.pre = $(CC) +COMPILE.pre = $(CC) $(C_DIALECT) COMPILE.post = -c -o $@ COMPILE = $(COMPILE.pre) $(ALL_CFLAGS) $(COMPILE.post) POSTCOMPILE = @true diff --git a/sim/common/acinclude.m4 b/sim/common/acinclude.m4 index ff7e1ac..49d56b9 100644 --- a/sim/common/acinclude.m4 +++ b/sim/common/acinclude.m4 @@ -56,6 +56,32 @@ AR=${AR-ar} AC_SUBST(AR) AC_PROG_RANLIB +# Require C11 or newer. Autoconf-2.70 provides ac_cv_prog_cc_c11 when using +# AC_PROG_CC, but we're still using Autoconf-2.69, and the newest it understands +# is C99. So handle it ourselves. +m4_version_prereq([2.70], [AC_MSG_ERROR([clean this up!])], [:]) +C_DIALECT= +AC_MSG_CHECKING([whether C11 is supported by default]) +AC_COMPILE_IFELSE([AC_LANG_SOURCE([ +#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L +# error "C11 support not found" +#endif +])], [AC_MSG_RESULT([yes])], [ + AC_MSG_RESULT([no]) + AC_MSG_CHECKING([for -std=c11 support]) + ac_save_CC="$CC" + CC="$CC -std=c11" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ +#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L +# error "C11 support not found" +#endif +])], [ + AC_MSG_RESULT([yes]) + CC="$ac_save_CC" + C_DIALECT="-std=c11" +], [AC_MSG_ERROR([C11 is required])])]) +AC_SUBST(C_DIALECT) + # Some of the common include files depend on bfd.h, and bfd.h checks # that config.h is included first by testing that the PACKAGE macro # is defined. -- cgit v1.1