Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools build: Correct bpf fixdep dependencies

The dependencies in tools/lib/bpf/Makefile are incorrect. Before we
recurse to build $(BPF_IN_STATIC), we need to build its 'fixdep'
executable.

I can't use the usual shortcut from Makefile.include:

<target>: <sources> fixdep

because its 'fixdep' target relies on $(OUTPUT), and $(OUTPUT) differs
in the parent 'make' versus the child 'make' -- so I imitate it via
open-coding.

I tweak a few $(MAKE) invocations while I'm at it, because
1. I'm adding a new recursive make; and
2. these recursive 'make's print spurious lines about files that are "up
to date" (which isn't normally a feature in Kbuild subtargets) or
"jobserver not available" (see [1])

I also need to tweak the assignment of the OUTPUT variable, so that
relative path builds work. For example, for 'make tools/lib/bpf', OUTPUT
is unset, and is usually treated as "cwd" -- but recursive make will
change cwd and so OUTPUT has a new meaning. For consistency, I ensure
OUTPUT is always an absolute path.

And $(Q) gets a backup definition in tools/build/Makefile.include,
because Makefile.include is sometimes included without
tools/build/Makefile, so the "quiet command" stuff doesn't actually work
consistently without it.

After this change, top-level builds result in an empty grep result from:

$ grep 'cannot find fixdep' $(find tools/ -name '*.cmd')

[1] https://www.gnu.org/software/make/manual/html_node/MAKE-Variable.html
If we're not using $(MAKE) directly, then we need to use more '+'.

Signed-off-by: Brian Norris <briannorris@chromium.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Ian Rogers <irogers@google.com>
Cc: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Link: https://lore.kernel.org/r/20240715203325.3832977-4-briannorris@chromium.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Brian Norris and committed by
Arnaldo Carvalho de Melo
dbb2a7a9 ea974028

+22 -4
+11 -1
tools/build/Makefile.include
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 build := -f $(srctree)/tools/build/Makefile.build dir=. obj 3 3 4 + # More than just $(Q), we sometimes want to suppress all command output from a 5 + # recursive make -- even the 'up to date' printout. 6 + ifeq ($(V),1) 7 + Q ?= 8 + SILENT_MAKE = +$(Q)$(MAKE) 9 + else 10 + Q ?= @ 11 + SILENT_MAKE = +$(Q)$(MAKE) --silent 12 + endif 13 + 4 14 fixdep: 5 - $(Q)$(MAKE) -C $(srctree)/tools/build CFLAGS= LDFLAGS= $(OUTPUT)fixdep 15 + $(SILENT_MAKE) -C $(srctree)/tools/build CFLAGS= LDFLAGS= $(OUTPUT)fixdep 6 16 7 17 fixdep-clean: 8 18 $(Q)$(MAKE) -C $(srctree)/tools/build clean
+1
tools/lib/bpf/.gitignore
··· 5 5 tags 6 6 cscope.* 7 7 /bpf_helper_defs.h 8 + fixdep
+10 -3
tools/lib/bpf/Makefile
··· 108 108 109 109 all: 110 110 111 + OUTPUT ?= ./ 112 + OUTPUT := $(abspath $(OUTPUT))/ 111 113 export srctree OUTPUT CC LD CFLAGS V 112 114 include $(srctree)/tools/build/Makefile.include 113 115 ··· 143 141 144 142 all_cmd: $(CMD_TARGETS) check 145 143 146 - $(BPF_IN_SHARED): force $(BPF_GENERATED) 144 + $(SHARED_OBJDIR) $(STATIC_OBJDIR): 145 + $(Q)mkdir -p $@ 146 + 147 + $(BPF_IN_SHARED): force $(BPF_GENERATED) | $(SHARED_OBJDIR) 147 148 @(test -f ../../include/uapi/linux/bpf.h -a -f ../../../include/uapi/linux/bpf.h && ( \ 148 149 (diff -B ../../include/uapi/linux/bpf.h ../../../include/uapi/linux/bpf.h >/dev/null) || \ 149 150 echo "Warning: Kernel ABI header at 'tools/include/uapi/linux/bpf.h' differs from latest version at 'include/uapi/linux/bpf.h'" >&2 )) || true ··· 156 151 @(test -f ../../include/uapi/linux/if_xdp.h -a -f ../../../include/uapi/linux/if_xdp.h && ( \ 157 152 (diff -B ../../include/uapi/linux/if_xdp.h ../../../include/uapi/linux/if_xdp.h >/dev/null) || \ 158 153 echo "Warning: Kernel ABI header at 'tools/include/uapi/linux/if_xdp.h' differs from latest version at 'include/uapi/linux/if_xdp.h'" >&2 )) || true 154 + $(SILENT_MAKE) -C $(srctree)/tools/build CFLAGS= LDFLAGS= OUTPUT=$(SHARED_OBJDIR) $(SHARED_OBJDIR)fixdep 159 155 $(Q)$(MAKE) $(build)=libbpf OUTPUT=$(SHARED_OBJDIR) CFLAGS="$(CFLAGS) $(SHLIB_FLAGS)" 160 156 161 - $(BPF_IN_STATIC): force $(BPF_GENERATED) 157 + $(BPF_IN_STATIC): force $(BPF_GENERATED) | $(STATIC_OBJDIR) 158 + $(SILENT_MAKE) -C $(srctree)/tools/build CFLAGS= LDFLAGS= OUTPUT=$(STATIC_OBJDIR) $(STATIC_OBJDIR)fixdep 162 159 $(Q)$(MAKE) $(build)=libbpf OUTPUT=$(STATIC_OBJDIR) 163 160 164 161 $(BPF_HELPER_DEFS): $(srctree)/tools/include/uapi/linux/bpf.h ··· 270 263 271 264 install: install_lib install_pkgconfig install_headers 272 265 273 - clean: 266 + clean: fixdep-clean 274 267 $(call QUIET_CLEAN, libbpf) $(RM) -rf $(CMD_TARGETS) \ 275 268 *~ .*.d .*.cmd LIBBPF-CFLAGS $(BPF_GENERATED) \ 276 269 $(SHARED_OBJDIR) $(STATIC_OBJDIR) \