Commit | Line | Data |
---|---|---|
edae34a3 LW |
1 | # SPDX-License-Identifier: GPL-2.0 |
2 | ||
3 | CLANG ?= clang | |
837a3d66 BT |
4 | SCRATCH_DIR := $(OUTPUT)/tools |
5 | BUILD_DIR := $(SCRATCH_DIR)/build | |
6 | BPFDIR := $(abspath ../../../lib/bpf) | |
7 | APIDIR := $(abspath ../../../include/uapi) | |
8 | ||
edae34a3 LW |
9 | CCINCLUDE += -I../../bpf |
10 | CCINCLUDE += -I../../../../../usr/include/ | |
837a3d66 BT |
11 | CCINCLUDE += -I$(SCRATCH_DIR)/include |
12 | ||
13 | BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a | |
14 | ||
15 | MAKE_DIRS := $(BUILD_DIR)/libbpf | |
16 | $(MAKE_DIRS): | |
17 | mkdir -p $@ | |
edae34a3 LW |
18 | |
19 | TEST_CUSTOM_PROGS = $(OUTPUT)/bpf/nat6to4.o | |
20 | all: $(TEST_CUSTOM_PROGS) | |
21 | ||
837a3d66 BT |
22 | # Get Clang's default includes on this system, as opposed to those seen by |
23 | # '-target bpf'. This fixes "missing" files on some architectures/distros, | |
24 | # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc. | |
25 | # | |
26 | # Use '-idirafter': Don't interfere with include mechanics except where the | |
27 | # build would have failed anyways. | |
28 | define get_sys_includes | |
29 | $(shell $(1) $(2) -v -E - </dev/null 2>&1 \ | |
30 | | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \ | |
31 | $(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') | |
32 | endef | |
33 | ||
34 | ifneq ($(CROSS_COMPILE),) | |
35 | CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%)) | |
36 | endif | |
37 | ||
38 | CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH)) | |
39 | ||
40 | $(TEST_CUSTOM_PROGS): $(BPFOBJ) | |
41 | $(CLANG) -O2 -target bpf -c $(@:.o=.c) $(CCINCLUDE) $(CLANG_SYS_INCLUDES) -o $@ | |
42 | ||
43 | $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \ | |
44 | $(APIDIR)/linux/bpf.h \ | |
45 | | $(BUILD_DIR)/libbpf | |
46 | $(MAKE) $(submake_extras) -C $(BPFDIR) OUTPUT=$(BUILD_DIR)/libbpf/ \ | |
47 | EXTRA_CFLAGS='-g -O0' \ | |
48 | DESTDIR=$(SCRATCH_DIR) prefix= all install_headers | |
49 | ||
50 | EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(SCRATCH_DIR) | |
edae34a3 | 51 |