ramips: add encrypted SGE factory image for D-Link devices
[openwrt/openwrt.git] / include / bpf.mk
index d9f1153cba9324d744785bf70601b403be77db1c..a3357f0e297f08b88b54c120d7f8298c731ac82c 100644 (file)
@@ -10,7 +10,7 @@ ifneq ($(CONFIG_USE_LLVM_HOST),)
   else
     BPF_PATH:=$(PATH)
   endif
-  CLANG:=$(firstword $(shell PATH='$(BPF_PATH)' which clang clang-13 clang-12 clang-11))
+  CLANG:=$(firstword $(shell PATH='$(BPF_PATH)' command -v clang clang-13 clang-12 clang-11))
   LLVM_VER:=$(subst clang,,$(notdir $(CLANG)))
 endif
 ifneq ($(CONFIG_USE_LLVM_PREBUILT),)
@@ -27,13 +27,13 @@ LLVM_OPT:=$(LLVM_PATH)/opt$(LLVM_VER)
 LLVM_STRIP:=$(LLVM_PATH)/llvm-strip$(LLVM_VER)
 
 BPF_KARCH:=mips
-BPF_ARCH:=mips$(if $(CONFIG_BIG_ENDIAN),,el)
+BPF_ARCH:=mips$(if $(CONFIG_ARCH_64BIT),64)$(if $(CONFIG_BIG_ENDIAN),,el)
 BPF_TARGET:=bpf$(if $(CONFIG_BIG_ENDIAN),eb,el)
 
 BPF_HEADERS_DIR:=$(STAGING_DIR)/bpf-headers
 
 BPF_KERNEL_INCLUDE := \
-       -nostdinc -isystem $(TOOLCHAIN_DIR)/include \
+       -nostdinc -isystem $(TOOLCHAIN_INC_DIRS) \
        -I$(BPF_HEADERS_DIR)/arch/$(BPF_KARCH)/include \
        -I$(BPF_HEADERS_DIR)/arch/$(BPF_KARCH)/include/asm/mach-generic \
        -I$(BPF_HEADERS_DIR)/arch/$(BPF_KARCH)/include/generated \
@@ -49,7 +49,7 @@ BPF_KERNEL_INCLUDE := \
 
 BPF_CFLAGS := \
        $(BPF_KERNEL_INCLUDE) -I$(PKG_BUILD_DIR) \
-       -D__KERNEL__ -D__BPF_TRACING__ \
+       -D__KERNEL__ -D__BPF_TRACING__ -DCONFIG_GENERIC_CSUM \
        -D__TARGET_ARCH_${BPF_KARCH} \
        -m$(if $(CONFIG_BIG_ENDIAN),big,little)-endian \
        -fno-stack-protector -Wall \
@@ -63,20 +63,23 @@ BPF_CFLAGS := \
        -Wno-unused-label \
        -O2 -emit-llvm -Xclang -disable-llvm-passes
 
-ifeq ($(DUMP),)
+ifneq ($(CONFIG_HAS_BPF_TOOLCHAIN),)
+ifeq ($(DUMP)$(filter download refresh,$(MAKECMDGOALS)),)
   CLANG_VER:=$(shell $(CLANG) -dM -E - < /dev/null | grep __clang_major__ | cut -d' ' -f3)
   CLANG_VER_VALID:=$(shell [ "$(CLANG_VER)" -ge "$(CLANG_MIN_VER)" ] && echo 1 )
   ifeq ($(CLANG_VER_VALID),)
     $(error ERROR: LLVM/clang version too old. Minimum required: $(CLANG_MIN_VER), found: $(CLANG_VER))
   endif
 endif
+endif
 
 define CompileBPF
        $(CLANG) -g -target $(BPF_ARCH)-linux-gnu $(BPF_CFLAGS) $(2) \
                -c $(1) -o $(patsubst %.c,%.bc,$(1))
        $(LLVM_OPT) -O2 -mtriple=$(BPF_TARGET) < $(patsubst %.c,%.bc,$(1)) > $(patsubst %.c,%.opt,$(1))
        $(LLVM_DIS) < $(patsubst %.c,%.opt,$(1)) > $(patsubst %.c,%.S,$(1))
-       $(LLVM_LLC) -march=$(BPF_TARGET) -filetype=obj -o $(patsubst %.c,%.o,$(1)) < $(patsubst %.c,%.S,$(1))
+       $(LLVM_LLC) -march=$(BPF_TARGET) -mcpu=v3 -filetype=obj -o $(patsubst %.c,%.o,$(1)) < $(patsubst %.c,%.S,$(1))
+       $(CP) $(patsubst %.c,%.o,$(1)) $(patsubst %.c,%.debug.o,$(1))
        $(LLVM_STRIP) --strip-debug $(patsubst %.c,%.o,$(1))
 endef