1# SPDX-License-Identifier: GPL-2.0
2
3LIBBPF_SRCS = $(srctree)/tools/lib/bpf/
4LIBBPF_OUT = $(abspath $(obj))/libbpf
5LIBBPF_A = $(LIBBPF_OUT)/libbpf.a
6LIBBPF_DESTDIR = $(LIBBPF_OUT)
7LIBBPF_INCLUDE = $(LIBBPF_DESTDIR)/include
8
9# Although not in use by libbpf's Makefile, set $(O) so that the "dummy" test
10# in tools/scripts/Makefile.include always succeeds when building the kernel
11# with $(O) pointing to a relative path, as in "make O=build bindeb-pkg".
12$(LIBBPF_A): | $(LIBBPF_OUT)
13	$(Q)$(MAKE) -C $(LIBBPF_SRCS) O=$(LIBBPF_OUT)/ OUTPUT=$(LIBBPF_OUT)/   \
14		DESTDIR=$(LIBBPF_DESTDIR) prefix=			       \
15		$(LIBBPF_OUT)/libbpf.a install_headers
16
17libbpf_hdrs: $(LIBBPF_A)
18
19.PHONY: libbpf_hdrs
20
21$(LIBBPF_OUT):
22	$(call msg,MKDIR,$@)
23	$(Q)mkdir -p $@
24
25userccflags += -I $(srctree)/tools/include/ -I $(srctree)/tools/include/uapi \
26	-I $(LIBBPF_INCLUDE) -Wno-unused-result
27
28userprogs := bpf_preload_umd
29
30clean-files := libbpf/
31
32$(obj)/iterators/iterators.o: | libbpf_hdrs
33
34bpf_preload_umd-objs := iterators/iterators.o
35bpf_preload_umd-userldlibs := $(LIBBPF_A) -lelf -lz
36
37$(obj)/bpf_preload_umd: $(LIBBPF_A)
38
39$(obj)/bpf_preload_umd_blob.o: $(obj)/bpf_preload_umd
40
41obj-$(CONFIG_BPF_PRELOAD_UMD) += bpf_preload.o
42bpf_preload-objs += bpf_preload_kern.o bpf_preload_umd_blob.o
43