Skip to content

Commit

Permalink
build: add header+symbol checking
Browse files Browse the repository at this point in the history
The new check-header-symbol-rule Makeconfig rule allows checking to see
whether a header #inclusion plus a symbol usage plus a given -l library
usage compiles and links successfully.  It's analogous to the Autoconf
AC_TRY_COMPILE macro.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
nickalcock authored and kvanhees committed Oct 25, 2022
1 parent 0ca8be9 commit 4bf7eea
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Makeconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Determine properties of the system and write a config.h.
#
# Oracle Linux DTrace.
# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.

Expand Down Expand Up @@ -33,6 +33,29 @@ $(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 HEADER and LIBRARY 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-symbol-rule,name,symbol,library,header)
define check-header-symbol-rule
$(objdir)/.config/config.$(1).h $(objdir)/.config/config.$(1).mk: $(objdir)/.config/.dir.stamp
if printf '#include <%s.h>\nint main(void) { %s; }' "$(4)" "$(2)" | \
$(CC) $(filter-out --coverage,$(CFLAGS) $(LDFLAGS)) -D_GNU_SOURCE -Werror=implicit-function-declaration -o /dev/null -x c - -l$(3) >/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

$(objdir)/.config/.dir.stamp:
mkdir -p $(objdir)/.config
touch $(objdir)/.config/.dir.stamp
Expand Down

0 comments on commit 4bf7eea

Please sign in to comment.