Skip to content

Commit c9d864c

Browse files
committed
build: overridable configuration variables
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>
1 parent 347ad8a commit c9d864c

File tree

2 files changed

+89
-32
lines changed

2 files changed

+89
-32
lines changed

Makeconfig

Lines changed: 83 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Determine properties of the system and write a config.h.
22
#
33
# Oracle Linux DTrace.
4-
# Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
4+
# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
55
# Licensed under the Universal Permissive License v 1.0 as shown at
66
# http://oss.oracle.com/licenses/upl.
77

@@ -10,6 +10,26 @@
1010
CONFIG_H = $(objdir)/config.h
1111
CONFIG_MK = $(objdir)/config.mk
1212

13+
# Emit a help rule for an override.
14+
#
15+
# Syntax: $(call make-override-help,var,help-string)
16+
define make-override-help
17+
help::
18+
width=$$$$(printf '$(1)=[yes/no]' | wc -c); \
19+
tabs="\t\t\t\t"; \
20+
if [[ $$$${width} -gt 31 ]]; then \
21+
tabs=' '; \
22+
elif [[ $$$${width} -gt 23 ]]; then \
23+
tabs='\t'; \
24+
elif [[ $$$${width} -gt 15 ]]; then \
25+
tabs='\t\t'; \
26+
elif [[ $$$${width} -gt 7 ]]; then \
27+
tabs='\t\t\t'; \
28+
fi; \
29+
printf "$(1)=[yes/no]$$$${tabs}Override check for%s\n" \
30+
"$$$$(printf "%s" "$(2)" | sed 's,(.*),,g')" >&2
31+
endef
32+
1333
# Generate a makefile rule to check for the presence of FUNCTION
1434
# in HEADER and emit an appropriate header file fragment into a
1535
# file under $(objdir)/.config.
@@ -20,14 +40,25 @@ CONFIG_MK = $(objdir)/config.mk
2040
# Syntax: $(call check-header-rule,name,function,header)
2141
define check-header-rule
2242
$(objdir)/.config/config.$(1).h $(objdir)/.config/config.$(1).mk: $(objdir)/.config/.dir.stamp
23-
if printf '#include <%s.h>\nint main(void) { %s; }' "$(3)" "$(2)" | \
24-
$(CC) $(filter-out --coverage,$(CFLAGS) $(LDFLAGS)) -D_GNU_SOURCE -Werror=implicit-function-declaration -c -o /dev/null -x c - >/dev/null 2>&1; then \
25-
echo '#define HAVE_$(1) 1' > $(objdir)/.config/config.$(1).h; \
26-
echo 'HAVE_$(1)=y' > $(objdir)/.config/config.$(1).mk; \
27-
else \
28-
echo '/* #undef HAVE_$(1) */' > $(objdir)/.config/config.$(1).h; \
29-
echo '# HAVE_$(1) undefined' > $(objdir)/.config/config.$(1).mk; \
30-
fi
43+
val="$(HAVE_$(1))"; \
44+
if [[ x$(HAVE_$(1)) = x ]]; then \
45+
if printf '#include <%s.h>\nint main(void) { %s; }' "$(3)" "$(2)" | \
46+
$(CC) $(filter-out --coverage,$(CFLAGS) $(LDFLAGS)) -D_GNU_SOURCE -Werror=implicit-function-declaration -c -o /dev/null -x c - >/dev/null 2>&1; then \
47+
val=yes; \
48+
else \
49+
val=no; \
50+
fi; \
51+
fi; \
52+
case $$$$val in \
53+
yes) echo '#define HAVE_$(1) 1' > $(objdir)/.config/config.$(1).h; \
54+
echo 'HAVE_$(1)=y' > $(objdir)/.config/config.$(1).mk;; \
55+
no) echo '/* #undef HAVE_$(1) */' > $(objdir)/.config/config.$(1).h; \
56+
echo '# HAVE_$(1) undefined' > $(objdir)/.config/config.$(1).mk;; \
57+
*) echo "HAVE_$(1) must be yes or no, not $(HAVE_$(1))" >&2; \
58+
false;; \
59+
esac
60+
61+
$(eval $(call make-override-help,HAVE_$(1), presence of $(2) in $(3).h))
3162

3263
$(CONFIG_H): $(objdir)/.config/config.$(1).h
3364
$(CONFIG_MK): $(objdir)/.config/config.$(1).mk
@@ -43,14 +74,25 @@ endef
4374
# Syntax: $(call check-symbol,name,symbol,library)
4475
define check-symbol-rule
4576
$(objdir)/.config/config.$(1).h $(objdir)/.config/config.$(1).mk: $(objdir)/.config/.dir.stamp
46-
if echo 'void $(2)(); int main(void) { $(2)(); }' | \
47-
$(CC) $(filter-out --coverage,$(CFLAGS) $(LDFLAGS)) -o /dev/null -x c - -l$(3) >/dev/null 2>&1; then \
48-
echo '#define HAVE_$(1) 1' > $(objdir)/.config/config.$(1).h; \
49-
echo 'HAVE_$(1)=y' > $(objdir)/.config/config.$(1).mk; \
50-
else \
51-
echo '/* #undef HAVE_$(1) */' > $(objdir)/.config/config.$(1).h; \
52-
echo '# HAVE_$(1) undefined' > $(objdir)/.config/config.$(1).mk; \
53-
fi
77+
val="$(HAVE_$(1))"; \
78+
if [[ x$(HAVE_$(1)) = x ]]; then \
79+
if echo 'void $(2)(); int main(void) { $(2)(); }' | \
80+
$(CC) $(filter-out --coverage,$(CFLAGS) $(LDFLAGS)) -o /dev/null -x c - -l$(3) >/dev/null 2>&1; then \
81+
val=yes; \
82+
else \
83+
val=no; \
84+
fi; \
85+
fi; \
86+
case $$$$val in \
87+
yes) echo '#define HAVE_$(1) 1' > $(objdir)/.config/config.$(1).h; \
88+
echo 'HAVE_$(1)=y' > $(objdir)/.config/config.$(1).mk;; \
89+
no) echo '/* #undef HAVE_$(1) */' > $(objdir)/.config/config.$(1).h; \
90+
echo '# HAVE_$(1) undefined' > $(objdir)/.config/config.$(1).mk;; \
91+
*) echo "HAVE_$(1) must be yes or no, not $(HAVE_$(1))" >&2; \
92+
false;; \
93+
esac
94+
95+
$(eval $(call make-override-help,HAVE_$(1), presence of $(2) in lib$(3)))
5496

5597
$(CONFIG_H): $(objdir)/.config/config.$(1).h
5698
$(CONFIG_MK): $(objdir)/.config/config.$(1).mk
@@ -66,14 +108,24 @@ endef
66108
# Syntax: $(call check-header-symbol-rule,name,symbol,library,header)
67109
define check-header-symbol-rule
68110
$(objdir)/.config/config.$(1).h $(objdir)/.config/config.$(1).mk: $(objdir)/.config/.dir.stamp
69-
if printf '#include <%s.h>\nint main(void) { %s; }' "$(4)" "$(2)" | \
70-
$(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 \
71-
echo '#define HAVE_$(1) 1' > $(objdir)/.config/config.$(1).h; \
72-
echo 'HAVE_$(1)=y' > $(objdir)/.config/config.$(1).mk; \
73-
else \
74-
echo '/* #undef HAVE_$(1) */' > $(objdir)/.config/config.$(1).h; \
75-
echo '# HAVE_$(1) undefined' > $(objdir)/.config/config.$(1).mk; \
76-
fi
111+
case x$(HAVE_$(1)) in \
112+
xyes) echo '#define HAVE_$(1) 1' > $(objdir)/.config/config.$(1).h; \
113+
echo 'HAVE_$(1)=y' > $(objdir)/.config/config.$(1).mk;; \
114+
xno) echo '/* #undef HAVE_$(1) */' > $(objdir)/.config/config.$(1).h; \
115+
echo '# HAVE_$(1) undefined' > $(objdir)/.config/config.$(1).mk;; \
116+
*) if printf '#include <%s.h>\nint main(void) { %s; }' "$(4)" "$(2)" | \
117+
$(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 \
118+
echo '#define HAVE_$(1) 1' > $(objdir)/.config/config.$(1).h; \
119+
echo 'HAVE_$(1)=y' > $(objdir)/.config/config.$(1).mk; \
120+
else \
121+
echo '/* #undef HAVE_$(1) */' > $(objdir)/.config/config.$(1).h; \
122+
echo '# HAVE_$(1) undefined' > $(objdir)/.config/config.$(1).mk; \
123+
fi;; \
124+
*) echo "HAVE_$(1) must be yes or no, not $(HAVE_$(1))" >&2; \
125+
false;; \
126+
esac
127+
128+
$(eval $(call make-override-help,HAVE_$(1), presence of $(2) in lib$(3) and $(4).h))
77129

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

147+
help::
148+
printf "Overrides for library and symbol searches:\n\n" >&2
149+
95150
$(eval $(call check-symbol-rule,ELF_GETSHDRSTRNDX,elf_getshdrstrndx,elf))
96151
$(eval $(call check-symbol-rule,LIBCTF,ctf_open,ctf))
97152
$(eval $(call check-symbol-rule,STRRSTR,strrstr,c))
@@ -103,3 +158,6 @@ endif
103158
$(eval $(call check-header-rule,FUSE_NUMA,fuse_set_numa,fuse/fuse_lowlevel))
104159
$(eval $(call check-header-symbol-rule,CLOSE_RANGE,close_range(3,~0U,0),c,unistd))
105160
$(eval $(call check-header-rule,GETTID,gettid,unistd))
161+
162+
help::
163+
printf "\n" >&2

Makeoptions

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# The implementation of the configurable make options.
22
#
33
# Oracle Linux DTrace.
4-
# Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
4+
# Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
55
# Licensed under the Universal Permissive License v 1.0 as shown at
66
# http://oss.oracle.com/licenses/upl.
77

@@ -13,13 +13,12 @@ libfuse2 ?= no
1313

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

2423
ifneq ($(debugging),no)
2524
override CFLAGS += -O0 -g

0 commit comments

Comments
 (0)