[DTrace-devel] [PATCH 1/3] build: add header-only checking

Kris Van Hees kris.van.hees at oracle.com
Tue Nov 8 05:42:38 UTC 2022


On Mon, Nov 07, 2022 at 10:09:20PM +0000, Nick Alcock via DTrace-devel wrote:
> The check-header-rule Makeconfig macro lets you check if a given
> identifier compiles after #including a given header without trying to
> link it.  This is useful for things that are distinguished by the
> presence of a given identifier in the headers, where that identifier
> corresponds to a symbol that won't actually link if used, perhaps
> because of symbol versioning.
> 
> Signed-off-by: Nick Alcock <nick.alcock at oracle.com>

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

> ---
>  Makeconfig | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/Makeconfig b/Makeconfig
> index cc20ef4c296d..15614384fd94 100644
> --- a/Makeconfig
> +++ b/Makeconfig
> @@ -10,6 +10,29 @@
>  CONFIG_H = $(objdir)/config.h
>  CONFIG_MK = $(objdir)/config.mk
>  
> +# Generate a makefile rule to check for the presence of FUNCTION
> +# in HEADER 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-header-rule,name,function,header)
> +define check-header-rule
> +$(objdir)/.config/config.$(1).h $(objdir)/.config/config.$(1).mk: $(objdir)/.config/.dir.stamp
> +	if printf '#include <%s.h>\nint main(void) { %s; }' "$(3)" "$(2)" | \
> +		$(CC) $(filter-out --coverage,$(CFLAGS) $(LDFLAGS)) -D_GNU_SOURCE -Werror=implicit-function-declaration -c -o /dev/null -x c - >/dev/null 2>&1; then \
> +	    echo '#define HAVE_$(1) 1' > $(objdir)/.config/config.$(1).h; \
> +	    echo 'HAVE_$(1)=y' > $(objdir)/.config/config.$(1).mk; \
> +	else \
> +	    echo '/* #undef HAVE_$(1) */' > $(objdir)/.config/config.$(1).h; \
> +	    echo '# HAVE_$(1) undefined' > $(objdir)/.config/config.$(1).mk; \
> +	fi
> +
> +$(CONFIG_H): $(objdir)/.config/config.$(1).h
> +$(CONFIG_MK): $(objdir)/.config/config.$(1).mk
> +endef
> +
>  # Generate a makefile rule to check for the presence of SYMBOL
>  # in LIBRARY and emit an appropriate header file fragment into
>  # a file under $(objdir)/.config.
> -- 
> 2.35.1
> 
> 
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel



More information about the DTrace-devel mailing list