Skip to content

Commit

Permalink
build: overridable configuration variables
Browse files Browse the repository at this point in the history
The Makeconfig checks are purely compile-time, so should always work: but
sometimes there are multiple choices, and if they choose an option the user
dislikes, the user might well want to override them (e.g. picking FUSE 2
even though FUSE 3 is already present).

This change causes every check-* invocation in Makeconfig to respond to
HAVE_* make variables set on the command line, and also to produce a line in
'make help' of the general form

HAVE_LIBSYSTEMD=[yes/no]	Override check for presence of sd_notify in libsystemd

etc.

(The escaping in make-override-help to figure out how many tabs to insert to
properly align the help will make your eyes bleed. One $ for every nested
$(eval $(call ...)): thank goodness they're all at the same level!)

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
  • Loading branch information
nickalcock committed Jan 26, 2024
1 parent 347ad8a commit c9d864c
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 32 deletions.
108 changes: 83 additions & 25 deletions 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, 2023, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2011, 2024, 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 All @@ -10,6 +10,26 @@
CONFIG_H = $(objdir)/config.h
CONFIG_MK = $(objdir)/config.mk

# Emit a help rule for an override.
#
# Syntax: $(call make-override-help,var,help-string)
define make-override-help
help::
width=$$$$(printf '$(1)=[yes/no]' | wc -c); \
tabs="\t\t\t\t"; \
if [[ $$$${width} -gt 31 ]]; then \
tabs=' '; \
elif [[ $$$${width} -gt 23 ]]; then \
tabs='\t'; \
elif [[ $$$${width} -gt 15 ]]; then \
tabs='\t\t'; \
elif [[ $$$${width} -gt 7 ]]; then \
tabs='\t\t\t'; \
fi; \
printf "$(1)=[yes/no]$$$${tabs}Override check for%s\n" \
"$$$$(printf "%s" "$(2)" | sed 's,(.*),,g')" >&2
endef

# 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.
Expand All @@ -20,14 +40,25 @@ CONFIG_MK = $(objdir)/config.mk
# 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
val="$(HAVE_$(1))"; \
if [[ x$(HAVE_$(1)) = x ]]; then \
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 \
val=yes; \
else \
val=no; \
fi; \
fi; \
case $$$$val in \
yes) echo '#define HAVE_$(1) 1' > $(objdir)/.config/config.$(1).h; \
echo 'HAVE_$(1)=y' > $(objdir)/.config/config.$(1).mk;; \
no) echo '/* #undef HAVE_$(1) */' > $(objdir)/.config/config.$(1).h; \
echo '# HAVE_$(1) undefined' > $(objdir)/.config/config.$(1).mk;; \
*) echo "HAVE_$(1) must be yes or no, not $(HAVE_$(1))" >&2; \
false;; \
esac

$(eval $(call make-override-help,HAVE_$(1), presence of $(2) in $(3).h))

$(CONFIG_H): $(objdir)/.config/config.$(1).h
$(CONFIG_MK): $(objdir)/.config/config.$(1).mk
Expand All @@ -43,14 +74,25 @@ endef
# Syntax: $(call check-symbol,name,symbol,library)
define check-symbol-rule
$(objdir)/.config/config.$(1).h $(objdir)/.config/config.$(1).mk: $(objdir)/.config/.dir.stamp
if echo 'void $(2)(); int main(void) { $(2)(); }' | \
$(CC) $(filter-out --coverage,$(CFLAGS) $(LDFLAGS)) -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
val="$(HAVE_$(1))"; \
if [[ x$(HAVE_$(1)) = x ]]; then \
if echo 'void $(2)(); int main(void) { $(2)(); }' | \
$(CC) $(filter-out --coverage,$(CFLAGS) $(LDFLAGS)) -o /dev/null -x c - -l$(3) >/dev/null 2>&1; then \
val=yes; \
else \
val=no; \
fi; \
fi; \
case $$$$val in \
yes) echo '#define HAVE_$(1) 1' > $(objdir)/.config/config.$(1).h; \
echo 'HAVE_$(1)=y' > $(objdir)/.config/config.$(1).mk;; \
no) echo '/* #undef HAVE_$(1) */' > $(objdir)/.config/config.$(1).h; \
echo '# HAVE_$(1) undefined' > $(objdir)/.config/config.$(1).mk;; \
*) echo "HAVE_$(1) must be yes or no, not $(HAVE_$(1))" >&2; \
false;; \
esac

$(eval $(call make-override-help,HAVE_$(1), presence of $(2) in lib$(3)))

$(CONFIG_H): $(objdir)/.config/config.$(1).h
$(CONFIG_MK): $(objdir)/.config/config.$(1).mk
Expand All @@ -66,14 +108,24 @@ endef
# 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
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 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;; \
*) echo "HAVE_$(1) must be yes or no, not $(HAVE_$(1))" >&2; \
false;; \
esac

$(eval $(call make-override-help,HAVE_$(1), presence of $(2) in lib$(3) and $(4).h))

$(CONFIG_H): $(objdir)/.config/config.$(1).h
$(CONFIG_MK): $(objdir)/.config/config.$(1).mk
Expand All @@ -92,6 +144,9 @@ $(CONFIG_MK):
echo 'CONFIGURED := yes' >> $(objdir)/config.mk
cat $(objdir)/.config/*.mk >> $(objdir)/config.mk 2>/dev/null || true

help::
printf "Overrides for library and symbol searches:\n\n" >&2

$(eval $(call check-symbol-rule,ELF_GETSHDRSTRNDX,elf_getshdrstrndx,elf))
$(eval $(call check-symbol-rule,LIBCTF,ctf_open,ctf))
$(eval $(call check-symbol-rule,STRRSTR,strrstr,c))
Expand All @@ -103,3 +158,6 @@ endif
$(eval $(call check-header-rule,FUSE_NUMA,fuse_set_numa,fuse/fuse_lowlevel))
$(eval $(call check-header-symbol-rule,CLOSE_RANGE,close_range(3,~0U,0),c,unistd))
$(eval $(call check-header-rule,GETTID,gettid,unistd))

help::
printf "\n" >&2
13 changes: 6 additions & 7 deletions Makeoptions
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# The implementation of the configurable make options.
#
# Oracle Linux DTrace.
# Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2011, 2023, 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 All @@ -13,13 +13,12 @@ libfuse2 ?= no

help::
@printf "Options:\n\n" >&2
@printf "make debugging=yes [targets] Disable optimization to make debugger use easier\n" >&2
@printf "make coverage=yes [targets] Turn on coverage support in the testsuite\n" >&2
@printf "make verbose=yes [target] Enable verbose building\n" >&2
@printf "make dof_dbg=yes [targets] Turn on especially noisy DOF parser debugging\n\n" >&2
@printf "make debugging=yes [targets]\tDisable optimization to make debugger use easier\n" >&2
@printf "make coverage=yes [targets]\tTurn on coverage support in the testsuite\n" >&2
@printf "make verbose=yes [target]\tEnable verbose building\n" >&2
@printf "make dof_dbg=yes [targets]\tTurn on especially noisy DOF parser debugging\n\n" >&2
@printf "Dependencies:\n\n" >&2
@printf "make libfuse2=yes [targets] Build against libfuse 2 even if libfuse 3 is found\n" >&2
@printf "\n" >&2
@printf "make libfuse2=yes [targets]\tBuild against libfuse 2 even if libfuse 3 is found\n\n" >&2

ifneq ($(debugging),no)
override CFLAGS += -O0 -g
Expand Down

0 comments on commit c9d864c

Please sign in to comment.