1 # SPDX-License-Identifier: GPL-2.0
2 # Rules to generate bpf objs
4 SCRATCH_DIR
:= $(OUTPUT
)/tools
5 BUILD_DIR
:= $(SCRATCH_DIR
)/build
6 BPFDIR
:= $(top_srcdir
)/tools
/lib
/bpf
7 APIDIR
:= $(top_srcdir
)/tools
/include/uapi
9 CCINCLUDE
+= -I
$(selfdir
)/bpf
10 CCINCLUDE
+= -I
$(top_srcdir
)/usr
/include/
11 CCINCLUDE
+= -I
$(SCRATCH_DIR
)/include
13 BPFOBJ
:= $(BUILD_DIR
)/libbpf
/libbpf.a
15 MAKE_DIRS
:= $(BUILD_DIR
)/libbpf
20 # Get Clang's default includes on this system, as opposed to those seen by
21 # '--target=bpf'. This fixes "missing" files on some architectures/distros,
22 # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
24 # Use '-idirafter': Don't interfere with include mechanics except where the
25 # build would have failed anyways.
26 define get_sys_includes
27 $(shell $(1) $(2) -v
-E
- </dev
/null
2>&1 \
28 | sed
-n
'/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
29 $(shell $(1) $(2) -dM
-E
- </dev
/null | grep
'__riscv_xlen ' | awk
'{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}')
32 ifneq ($(CROSS_COMPILE
),)
33 CLANG_TARGET_ARCH
= --target
=$(notdir $(CROSS_COMPILE
:%-=%))
36 CLANG_SYS_INCLUDES
= $(call get_sys_includes
,$(CLANG
),$(CLANG_TARGET_ARCH
))
38 BPF_PROG_OBJS
:= $(patsubst %.c
,$(OUTPUT
)/%.o
,$(wildcard *.bpf.c
))
40 $(BPF_PROG_OBJS
): $(OUTPUT
)/%.o
: %.c
$(BPFOBJ
) |
$(MAKE_DIRS
)
41 $(call msg
,BPF_PROG
,,$@
)
42 $(Q
)$(CLANG
) -O2
-g
--target
=bpf
$(CCINCLUDE
) $(CLANG_SYS_INCLUDES
) \
45 $(BPFOBJ
): $(wildcard $(BPFDIR
)/*.
[ch
] $(BPFDIR
)/Makefile
) \
46 $(APIDIR
)/linux
/bpf.h \
49 $(Q
)$(MAKE
) $(submake_extras
) -C
$(BPFDIR
) OUTPUT
=$(BUILD_DIR
)/libbpf
/ \
50 EXTRA_CFLAGS
='-g -O0' \
51 DESTDIR
=$(SCRATCH_DIR
) prefix= all install_headers
53 EXTRA_CLEAN
+= $(SCRATCH_DIR
)