1# SPDX-License-Identifier: GPL-2.0
2OUTPUT := .output
3CLANG ?= clang
4LLC ?= llc
5LLVM_STRIP ?= llvm-strip
6DEFAULT_BPFTOOL := $(OUTPUT)/sbin/bpftool
7BPFTOOL ?= $(DEFAULT_BPFTOOL)
8LIBBPF_SRC := $(abspath ../../../../tools/lib/bpf)
9BPFOBJ := $(OUTPUT)/libbpf.a
10BPF_INCLUDE := $(OUTPUT)
11INCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../../../tools/lib)        \
12       -I$(abspath ../../../../tools/include/uapi)
13CFLAGS := -g -Wall
14
15abs_out := $(abspath $(OUTPUT))
16ifeq ($(V),1)
17Q =
18msg =
19else
20Q = @
21msg = @printf '  %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))";
22MAKEFLAGS += --no-print-directory
23submake_extras := feature_display=0
24endif
25
26.DELETE_ON_ERROR:
27
28.PHONY: all clean
29
30all: iterators.skel.h
31
32clean:
33	$(call msg,CLEAN)
34	$(Q)rm -rf $(OUTPUT) iterators
35
36iterators.skel.h: $(OUTPUT)/iterators.bpf.o | $(BPFTOOL)
37	$(call msg,GEN-SKEL,$@)
38	$(Q)$(BPFTOOL) gen skeleton $< > $@
39
40
41$(OUTPUT)/iterators.bpf.o: iterators.bpf.c $(BPFOBJ) | $(OUTPUT)
42	$(call msg,BPF,$@)
43	$(Q)$(CLANG) -g -O2 -target bpf $(INCLUDES)			      \
44		 -c $(filter %.c,$^) -o $@ &&				      \
45	$(LLVM_STRIP) -g $@
46
47$(OUTPUT):
48	$(call msg,MKDIR,$@)
49	$(Q)mkdir -p $(OUTPUT)
50
51$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)
52	$(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC)			       \
53		    OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
54
55$(DEFAULT_BPFTOOL):
56	$(Q)$(MAKE) $(submake_extras) -C ../../../../tools/bpf/bpftool			      \
57		    prefix= OUTPUT=$(abs_out)/ DESTDIR=$(abs_out) install
58