forked from inspektor-gadget/inspektor-gadget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.btfgen
54 lines (43 loc) · 1.69 KB
/
Makefile.btfgen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
# disable builtin rules (avoid trying to run cc for .o files)
MAKEFLAGS += --no-builtin-rules
ifndef BTFHUB_ARCHIVE
$(error BTFHUB_ARCHIVE is undefined)
endif
ifndef ARCH
$(error ARCH is undefined)
endif
# architecture naming is a mess:
# - Golang uses amd64 and arm64
# - btfhub uses x86_64 and arm64
# - bpf2go uses x86 and arm64
ARCH_CLEANED = $(subst amd64,x86,$(ARCH))
OUTPUT ?= pkg/btfgen/btfs
SOURCE_BTF_FILES = $(shell find $(BTFHUB_ARCHIVE)/ -iregex ".*$(subst x86,x86_64,$(ARCH_CLEANED)).*" -type f -name '*.btf.tar.xz')
MIN_CORE_BTF_FILES = $(patsubst $(BTFHUB_ARCHIVE)/%.btf.tar.xz, $(OUTPUT)/$(ARCH_CLEANED)/%.btf, $(SOURCE_BTF_FILES))
BPF_ALL_O_FILES = $(shell find pkg/ -type f -regex ".*\($(ARCH_CLEANED)\|bpfel\).o")
# Filter out BPF objects that only contain BPF maps without BPF programs
BPF_PROGS_O_FILES = $(filter-out pkg/gadgettracermanager/containers-map/containersmap_bpfel%,$(BPF_ALL_O_FILES))
.PHONY: all
all: $(MIN_CORE_BTF_FILES)
ifeq ($(V),1)
Q =
msg =
else
Q = @
msg = @printf ' %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))";
MAKEFLAGS += --no-print-directory
endif
$(MIN_CORE_BTF_FILES): $(BPF_PROGS_O_FILES)
$(OUTPUT)/$(ARCH_CLEANED)/%.btf: BTF_FILE = $(<:.tar.xz=)
$(OUTPUT)/$(ARCH_CLEANED)/%.btf: $(BTFHUB_ARCHIVE)/%.btf.tar.xz
$(call msg,UNTAR,$@)
$(Q)tar xvfJ $< -C "$(dir $<)" --touch > /dev/null
$(call msg,BTFGEN,$@)
$(Q)mkdir -p "$(@D)"
$(Q)if [ -f $(BTF_FILE) ]; then $(BPFTOOL) gen min_core_btf $(BTF_FILE) $@ $(BPF_PROGS_O_FILES); else echo "$(BTF_FILE) does not exist!" >&2; fi
$(Q)rm -fr $(BTF_FILE)
# delete failed targets
.DELETE_ON_ERROR:
# keep intermediate (.skel.h, .bpf.o, etc) targets
.SECONDARY: