[DTrace-devel] [PATCH 1/2] config: add rule to check gcc option

Nick Alcock nick.alcock at oracle.com
Thu Feb 22 16:03:24 UTC 2024


On 22 Feb 2024, Kris Van Hees via DTrace-devel stated:

> Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>

I was just wondering if it was time to add something like this!

> ---
>  Makeconfig | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
>
> diff --git a/Makeconfig b/Makeconfig
> index 0f7c4364..332e9519 100644
> --- a/Makeconfig
> +++ b/Makeconfig
> @@ -163,6 +163,39 @@ $(CONFIG_H): $(objdir)/.config/config.$(1).h
>  $(CONFIG_MK): $(objdir)/.config/config.$(1).mk
>  endef
>  
> +# Generate a makefile rule to check for support for  OPTION in gcc and emit an
> +# appropriate header file fragment into a file under $(objdir)/.config.
> +#
> +# The first argument must be suitable for a filename fragment, for a makefile
> +# rule name and for a #define.
> +#
> +# Syntax: $(call check-gcc-option-rule,name,option)
> +define check-gcc-option-rule
> +$(objdir)/.config/config.$(1).h $(objdir)/.config/config.$(1).mk: $(objdir)/.config/.dir.stamp
> +	case x$(HAVE_$(1)) in \
> +	xyes) echo '#define HAVE_$(1) 1' > $(objdir)/.config/config.$(1).h; \
> +	     echo 'HAVE_$(1)=y' > $(objdir)/.config/config.$(1).mk;; \
> +	xno) echo '/* #undef HAVE_$(1) */' > $(objdir)/.config/config.$(1).h; \
> +	     echo '# HAVE_$(1) undefined' > $(objdir)/.config/config.$(1).mk;; \
> +	*) if $(BPFC) --help $(2) 2>&1 >/dev/null | grep error; then \

This only works for options that do not take arguments and don't produce
errors for other reasons when specified alone. e.g.

compiler at loom 503 /usr/src/llvm/llvm/lldb% gcc --help -o 2>&1 | grep error:
gcc: error: missing filename after ‘-o’

Maybe that's good enough, I don't know. In general it's probably better
to try to add the option to $(CC) $(CFLAGS) and try to compile
something, like the other tests do, since a lot of options are only
valid when actually compiling or are only considered valid for
particular frontends (and GCC doesn't know what frontend it's using
unless you specify it with -x c or whatever). So at the very least using
-x c would probably be a good idea.

More generally, this is misnamed: it's not checking a GCC option, it's
checking for a *BPFC* option. This is probably best fixed by adding
another parameter which is the compiler to use, so we can pass in either
$(BPFC) or $(CC).

-- 
NULL && (void)



More information about the DTrace-devel mailing list