[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20230524092204.jvq2l23xkcqgah2x@lion.mk-sys.cz>
Date: Wed, 24 May 2023 11:22:04 +0200
From: Michal Kubecek <mkubecek@...e.cz>
To: netdev@...r.kernel.org
Cc: Dario Binacchi <dario.binacchi@...rulasolutions.com>
Subject: Re: [PATCH ethtool] Require a compiler with support for C++11
features
On Wed, May 24, 2023 at 10:24:07AM +0200, Michal Kubecek wrote:
> On Tue, May 23, 2023 at 07:19:08PM +0200, Dario Binacchi wrote:
> > 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.
> >
> > Signed-off-by: Dario Binacchi <dario.binacchi@...rulasolutions.com>
> > ---
> > +# 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.
I experimented a bit and this seems to do the trick:
------------------------------------------------------------------------
--- a/configure.ac
+++ b/configure.ac
@@ -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.
Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)
Powered by blists - more mailing lists