xref: /aosp_15_r20/external/bcc/libbpf-tools/Makefile.btfgen (revision 387f9dfdfa2baef462e92476d413c7bc2470293e)
1# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2SOURCE_BTF_FILES = $(shell find $(BTFHUB_ARCHIVE)/ -iregex ".*$(subst x86,x86_64,$(ARCH)).*" -type f -name '*.btf.tar.xz')
3MIN_CORE_BTF_FILES = $(patsubst $(BTFHUB_ARCHIVE)/%.btf.tar.xz, $(OUTPUT)/min_core_btfs/%.btf, $(SOURCE_BTF_FILES))
4BPF_O_FILES = $(patsubst %,$(OUTPUT)/%.bpf.o,$(APPS))
5
6.PHONY: all
7all: $(OUTPUT)/min_core_btf_tar.o
8
9ifeq ($(V),1)
10Q =
11msg =
12else
13Q = @
14msg = @printf '  %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))";
15MAKEFLAGS += --no-print-directory
16endif
17
18$(BTFHUB_ARCHIVE)/%.btf: $(BTFHUB_ARCHIVE)/%.btf.tar.xz
19	$(call msg,UNTAR,$@)
20	$(Q)tar xvfJ $< -C "$(@D)" > /dev/null
21	$(Q)touch $@
22
23$(MIN_CORE_BTF_FILES): $(BPF_O_FILES)
24
25# Create reduced version of BTF files to be embedded within the tools executables
26$(OUTPUT)/min_core_btfs/%.btf: $(BTFHUB_ARCHIVE)/%.btf
27	$(call msg,BTFGEN,$@)
28	$(Q)mkdir -p "$(@D)"
29	$(Q)$(BPFTOOL) gen min_core_btf $< $@ $(OUTPUT)/*.bpf.o
30
31# Compress reduced BTF files and create an object file with its content
32$(OUTPUT)/min_core_btf_tar.o: $(MIN_CORE_BTF_FILES)
33	$(call msg,TAR,$@)
34	$(Q)tar c --gz -f $(OUTPUT)/min_core_btfs.tar.gz -C $(OUTPUT)/min_core_btfs/ .
35	$(Q)cd $(OUTPUT) && ld -r -b binary min_core_btfs.tar.gz -o $@
36
37# delete failed targets
38.DELETE_ON_ERROR:
39# keep intermediate (.skel.h, .bpf.o, etc) targets
40.SECONDARY:
41