mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-13 14:24:11 +08:00
edd75c8028
Building BPF selftests with custom HOSTCFLAGS yields an error:
# make HOSTCFLAGS="-O2"
[...]
HOSTCC ./tools/testing/selftests/bpf/tools/build/resolve_btfids/main.o
main.c:73:10: fatal error: linux/rbtree.h: No such file or directory
73 | #include <linux/rbtree.h>
| ^~~~~~~~~~~~~~~~
The reason is that tools/bpf/resolve_btfids/Makefile passes header
include paths by extending HOSTCFLAGS which is overridden by setting
HOSTCFLAGS in the make command (because of Makefile rules [1]).
This patch fixes the above problem by passing the include paths via
`HOSTCFLAGS_resolve_btfids` which is used by tools/build/Build.include
and can be combined with overridding HOSTCFLAGS.
[1] https://www.gnu.org/software/make/manual/html_node/Overriding.html
Fixes: 56a2df7615
("tools/resolve_btfids: Compile resolve_btfids as host program")
Signed-off-by: Viktor Malik <vmalik@redhat.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/bpf/20230530123352.1308488-1-vmalik@redhat.com
113 lines
3.1 KiB
Makefile
113 lines
3.1 KiB
Makefile
# SPDX-License-Identifier: GPL-2.0-only
|
|
include ../../scripts/Makefile.include
|
|
include ../../scripts/Makefile.arch
|
|
|
|
srctree := $(abspath $(CURDIR)/../../../)
|
|
|
|
ifeq ($(V),1)
|
|
Q =
|
|
msg =
|
|
else
|
|
Q = @
|
|
ifeq ($(silent),1)
|
|
msg =
|
|
else
|
|
msg = @printf ' %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))";
|
|
endif
|
|
MAKEFLAGS=--no-print-directory
|
|
endif
|
|
|
|
# Overrides for the prepare step libraries.
|
|
HOST_OVERRIDES := AR="$(HOSTAR)" CC="$(HOSTCC)" LD="$(HOSTLD)" ARCH="$(HOSTARCH)" \
|
|
CROSS_COMPILE="" EXTRA_CFLAGS="$(HOSTCFLAGS)"
|
|
|
|
RM ?= rm
|
|
HOSTCC ?= gcc
|
|
HOSTLD ?= ld
|
|
HOSTAR ?= ar
|
|
CROSS_COMPILE =
|
|
|
|
OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/
|
|
|
|
LIBBPF_SRC := $(srctree)/tools/lib/bpf/
|
|
SUBCMD_SRC := $(srctree)/tools/lib/subcmd/
|
|
|
|
BPFOBJ := $(OUTPUT)/libbpf/libbpf.a
|
|
LIBBPF_OUT := $(abspath $(dir $(BPFOBJ)))/
|
|
SUBCMDOBJ := $(OUTPUT)/libsubcmd/libsubcmd.a
|
|
SUBCMD_OUT := $(abspath $(dir $(SUBCMDOBJ)))/
|
|
|
|
LIBBPF_DESTDIR := $(LIBBPF_OUT)
|
|
LIBBPF_INCLUDE := $(LIBBPF_DESTDIR)include
|
|
|
|
SUBCMD_DESTDIR := $(SUBCMD_OUT)
|
|
SUBCMD_INCLUDE := $(SUBCMD_DESTDIR)include
|
|
|
|
BINARY := $(OUTPUT)/resolve_btfids
|
|
BINARY_IN := $(BINARY)-in.o
|
|
|
|
all: $(BINARY)
|
|
|
|
prepare: $(BPFOBJ) $(SUBCMDOBJ)
|
|
|
|
$(OUTPUT) $(OUTPUT)/libsubcmd $(LIBBPF_OUT):
|
|
$(call msg,MKDIR,,$@)
|
|
$(Q)mkdir -p $(@)
|
|
|
|
$(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd
|
|
$(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(SUBCMD_OUT) \
|
|
DESTDIR=$(SUBCMD_DESTDIR) $(HOST_OVERRIDES) prefix= subdir= \
|
|
$(abspath $@) install_headers
|
|
|
|
$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OUT)
|
|
$(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(LIBBPF_OUT) \
|
|
DESTDIR=$(LIBBPF_DESTDIR) $(HOST_OVERRIDES) prefix= subdir= \
|
|
$(abspath $@) install_headers
|
|
|
|
LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null)
|
|
LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf)
|
|
|
|
HOSTCFLAGS_resolve_btfids += -g \
|
|
-I$(srctree)/tools/include \
|
|
-I$(srctree)/tools/include/uapi \
|
|
-I$(LIBBPF_INCLUDE) \
|
|
-I$(SUBCMD_INCLUDE) \
|
|
$(LIBELF_FLAGS)
|
|
|
|
LIBS = $(LIBELF_LIBS) -lz
|
|
|
|
export srctree OUTPUT HOSTCFLAGS_resolve_btfids Q HOSTCC HOSTLD HOSTAR
|
|
include $(srctree)/tools/build/Makefile.include
|
|
|
|
$(BINARY_IN): fixdep FORCE prepare | $(OUTPUT)
|
|
$(Q)$(MAKE) $(build)=resolve_btfids
|
|
|
|
$(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN)
|
|
$(call msg,LINK,$@)
|
|
$(Q)$(HOSTCC) $(BINARY_IN) $(KBUILD_HOSTLDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS)
|
|
|
|
clean_objects := $(wildcard $(OUTPUT)/*.o \
|
|
$(OUTPUT)/.*.o.cmd \
|
|
$(OUTPUT)/.*.o.d \
|
|
$(LIBBPF_OUT) \
|
|
$(LIBBPF_DESTDIR) \
|
|
$(SUBCMD_OUT) \
|
|
$(SUBCMD_DESTDIR) \
|
|
$(OUTPUT)/resolve_btfids)
|
|
|
|
ifneq ($(clean_objects),)
|
|
clean: fixdep-clean
|
|
$(call msg,CLEAN,$(BINARY))
|
|
$(Q)$(RM) -rf $(clean_objects)
|
|
else
|
|
clean:
|
|
endif
|
|
|
|
tags:
|
|
$(call msg,GEN,,tags)
|
|
$(Q)ctags -R . $(LIBBPF_SRC) $(SUBCMD_SRC)
|
|
|
|
FORCE:
|
|
|
|
.PHONY: all FORCE clean tags prepare
|