Skip to contentSkip to conversation

Require a compiler with support for C++11 features

PATCH Superseded Dario Binacchi 2 participants 3 messages May 23, 2023 – May 24, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Require a compiler with support for C++11 features

Just like the kernel, which has been using -std=gnu11 for about a year, we also require a C11 compiler for ethtool.

The addition of m4 macros allows the package to be compiled even if they are not present in the autoconf-archive.

---
 configure.ac                   |    3 +
 m4/ax_cxx_compile_stdcxx.m4    | 1009 ++++++++++++++++++++++++++++++++
 m4/ax_cxx_compile_stdcxx_11.m4 |   39 ++
 3 files changed, 1051 insertions(+)
 create mode 100644 m4/ax_cxx_compile_stdcxx.m4
 create mode 100644 m4/ax_cxx_compile_stdcxx_11.m4
configure.ac +3 -0
index c1e001247138..133749468bde 100644
@@ -4,6 +4,7 @@ AC_PREREQ(2.52)
 AC_CONFIG_SRCDIR([ethtool.c])
 AM_INIT_AUTOMAKE([gnu subdir-objects])
 AC_CONFIG_HEADERS([ethtool-config.h])
+AC_CONFIG_MACRO_DIR([m4])
 
 AM_MAINTAINER_MODE
 
@@ -13,6 +14,8 @@ AC_PROG_GCC_TRADITIONAL
 AM_PROG_CC_C_O
 PKG_PROG_PKG_CONFIG
 
+AX_CXX_COMPILE_STDCXX_11(,[mandatory])
+
 dnl Checks for libraries.
 
 dnl Checks for header files.
m4/ax_cxx_compile_stdcxx.m4 new file +1009 -0

1,009 lines not on this page · raw message

m4/ax_cxx_compile_stdcxx_11.m4 new file +39 -0
new file mode 100644
index 000000000000..1733fd85f959
@@ -0,0 +1,39 @@
+# =============================================================================
+#  https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
+# =============================================================================
+#
+# SYNOPSIS
+#
+#   AX_CXX_COMPILE_STDCXX_11([ext|noext], [mandatory|optional])
+#
+# DESCRIPTION
+#
+#   Check for baseline language coverage in the compiler for the C++11
+#   standard; if necessary, add switches to CXX and CXXCPP to enable
+#   support.
+#
+#   This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX
+#   macro with the version set to C++11.  The two optional arguments are
+#   forwarded literally as the second and third argument respectively.
+#   Please see the documentation for the AX_CXX_COMPILE_STDCXX macro for
+#   more information.  If you want to use this macro, you also need to
+#   download the ax_cxx_compile_stdcxx.m4 file.
+#
+# LICENSE
+#
+#   Copyright (c) 2008 Benjamin Kosnik <[email protected]>
+#   Copyright (c) 2012 Zack Weinberg <[email protected]>
+#   Copyright (c) 2013 Roy Stogner <[email protected]>
+#   Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov <[email protected]>
+#   Copyright (c) 2015 Paul Norman <[email protected]>
+#   Copyright (c) 2015 Moritz Klammler <[email protected]>
+#
+#   Copying and distribution of this file, with or without modification, are
+#   permitted in any medium without royalty provided the copyright notice
+#   and this notice are preserved. This file is offered as-is, without any
+#   warranty.
+
+#serial 18
+
+AX_REQUIRE_DEFINED([AX_CXX_COMPILE_STDCXX])
+AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [AX_CXX_COMPILE_STDCXX([11], [$1], [$2])])
Signature · 1 line
2.32.0
#1 lore raw
Quoted 8 lines · Dario Binacchi

Just like the kernel, which has been using -std=gnu11 for about a year, we also require a C11 compiler for ethtool.

The addition of m4 macros allows the package to be compiled even if they are not present in the autoconf-archive.

---

m4/ax_cxx_compile_stdcxx.m4 line 14

Quoted 10 lines
m4/ax_cxx_compile_stdcxx.m4 new file +10 -0
+# SYNOPSIS
+#
+#   AX_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional])
+#
+# DESCRIPTION
+#
+#   Check for baseline language coverage in the compiler for the specified
+#   version of the C++ standard.  If necessary, add switches to CXX and
+#   CXXCPP to enable support.  VERSION may be '11', '14', '17', or '20' for
+#   the respective C++ standard version.

Is this the correct macro? We need C compiler, not C++, so we probably rather need something like AX_CHECK_COMPILE_FLAG().

Or maybe even that is an overkill and just AC_COMPILE_IFELSE() with an empty source and enforced "-std=c11" in CFLAGS might suffice.

Michal

#2 lore raw
Quoted 23 lines · Michal Kubecek
Quoted 8 lines · Dario Binacchi

Just like the kernel, which has been using -std=gnu11 for about a year, we also require a C11 compiler for ethtool.

The addition of m4 macros allows the package to be compiled even if they are not present in the autoconf-archive.

---

Review

Quoted 10 lines
(quoted diff) +10 -0
+# SYNOPSIS
+#
+#   AX_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional])
+#
+# DESCRIPTION
+#
+#   Check for baseline language coverage in the compiler for the specified
+#   version of the C++ standard.  If necessary, add switches to CXX and
+#   CXXCPP to enable support.  VERSION may be '11', '14', '17', or '20' for
+#   the respective C++ standard version.

Is this the correct macro? We need C compiler, not C++, so we probably rather need something like AX_CHECK_COMPILE_FLAG().

Quoted 2 lines

Or maybe even that is an overkill and just AC_COMPILE_IFELSE() with an empty source and enforced "-std=c11" in CFLAGS might suffice.

I experimented a bit and this seems to do the trick:

------------------------------------------------------------------------

configure.ac +7 -0
@@ -13,6 +13,13 @@ AC_PROG_GCC_TRADITIONAL
 AM_PROG_CC_C_O
 PKG_PROG_PKG_CONFIG
 
+AC_LANG(C)
+saved_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -std=c11"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],,
+	AC_MSG_FAILURE([The compiler does not support C11 standard.]))
+CFLAGS="$saved_CFLAGS"
+
 dnl Checks for libraries.
 
 dnl Checks for header files.

------------------------------------------------------------------------

(Plus some message on success, of course.)

Michal

Note to self: configure.ac would certainly deserve a review and cleanup.
Examples: strtol() is guaranteed by C11 (and probably long before that), with included copy of linux/types.h there is no need to check for __be16/__be32 any more and AC_PROG_GCC_TRADITIONAL is also unlikely to be still of any use.