blob: 6ce4e3b12323c18c4de854c76b7f3600525ed59d [file] [log] [blame]
developerdd386532022-07-26 17:14:47 +08001diff --git a/target/Makefile b/target/Makefile
2index 7ad26c71..83f9c4b0 100644
3--- a/target/Makefile
4+++ b/target/Makefile
5@@ -7,9 +7,14 @@
6 curdir:=target
7
8 $(curdir)/subtargets:=install
9-$(curdir)/builddirs:=linux sdk imagebuilder toolchain
10+$(curdir)/builddirs:=linux sdk imagebuilder toolchain llvm-bpf
11 $(curdir)/builddirs-default:=linux
12-$(curdir)/builddirs-install:=linux $(if $(CONFIG_SDK),sdk) $(if $(CONFIG_IB),imagebuilder) $(if $(CONFIG_MAKE_TOOLCHAIN),toolchain)
13+$(curdir)/builddirs-install:=\
14+ linux \
15+ $(if $(CONFIG_SDK),sdk) \
16+ $(if $(CONFIG_IB),imagebuilder) \
17+ $(if $(CONFIG_MAKE_TOOLCHAIN),toolchain) \
18+ $(if $(CONFIG_SDK_LLVM_BPF),llvm-bpf)
19
20 $(curdir)/sdk/install:=$(curdir)/linux/install
21 $(curdir)/imagebuilder/install:=$(curdir)/linux/install
22diff --git a/toolchain/Config.in b/toolchain/Config.in
23index 6dda9af9..221e25f2 100644
24--- a/toolchain/Config.in
25+++ b/toolchain/Config.in
26@@ -37,6 +37,39 @@ menuconfig TARGET_OPTIONS
27
28 Most people will answer N.
29
30+ choice BPF_TOOLCHAIN
31+ prompt "BPF toolchain" if DEVEL
32+ default BPF_TOOLCHAIN_BUILD_LLVM if BUILDBOT
33+ default BPF_TOOLCHAIN_PREBUILT if HAS_PREBUILT_LLVM_TOOLCHAIN
34+ default BPF_TOOLCHAIN_NONE
35+
36+ config BPF_TOOLCHAIN_NONE
37+ bool "None"
38+
39+ config BPF_TOOLCHAIN_PREBUILT
40+ bool "Use prebuilt LLVM toolchain"
41+ depends on HAS_PREBUILT_LLVM_TOOLCHAIN
42+ select USE_LLVM_PREBUILT
43+
44+ config BPF_TOOLCHAIN_HOST
45+ select USE_LLVM_HOST
46+ bool "Use host LLVM toolchain"
47+
48+ config BPF_TOOLCHAIN_BUILD_LLVM
49+ select USE_LLVM_BUILD
50+ bool "Build LLVM toolchain for eBPF"
51+ help
52+ If enabled, a LLVM toolchain for building eBPF binaries will be built.
53+ If this is not enabled, eBPF packages can only be built if the host
54+ has a suitable toolchain
55+ endchoice
56+
57+ config BPF_TOOLCHAIN_HOST_PATH
58+ string
59+ depends on BPF_TOOLCHAIN_HOST
60+ prompt "Host LLVM toolchain path (prefix)" if DEVEL
61+ default "/usr/local/opt/llvm" if HOST_OS_MACOS
62+ default ""
63
64 menuconfig EXTERNAL_TOOLCHAIN
65 bool
66@@ -259,6 +292,26 @@ config GDB
67 help
68 Enable if you want to build the gdb.
69
70+config HAS_BPF_TOOLCHAIN
71+ bool
72+
73+config HAS_PREBUILT_LLVM_TOOLCHAIN
74+ def_bool $(shell, [ -f llvm-bpf/.llvm-version ] && echo y || echo n)
75+
76+config USE_LLVM_HOST
77+ select HAS_BPF_TOOLCHAIN
78+ bool
79+
80+config USE_LLVM_PREBUILT
81+ select HAS_BPF_TOOLCHAIN
82+ default y if !DEVEL && !BUILDBOT && HAS_PREBUILT_LLVM_TOOLCHAIN
83+ bool
84+
85+config USE_LLVM_BUILD
86+ default y if !DEVEL && BUILDBOT
87+ select HAS_BPF_TOOLCHAIN
88+ bool
89+
90 config USE_GLIBC
91 default y if !TOOLCHAINOPTS && !EXTERNAL_TOOLCHAIN && !NATIVE_TOOLCHAIN && (arc)
92 bool
93diff --git a/tools/Makefile b/tools/Makefile
94index 29309ec4..84f984dd 100644
95--- a/tools/Makefile
96+++ b/tools/Makefile
97@@ -37,6 +37,7 @@ tools-$(CONFIG_TARGET_mxs) += elftosb sdimage
98 tools-$(CONFIG_TARGET_tegra) += cbootimage cbootimage-configs
99 tools-$(CONFIG_USES_MINOR) += kernel2minor
100 tools-$(CONFIG_USE_SPARSE) += sparse
101+tools-$(CONFIG_USE_LLVM_BUILD) += llvm-bpf
developer16b22152023-06-01 13:48:39 +0800102 tools-y += openssl
103 tools-y += aesgcm
developerdd386532022-07-26 17:14:47 +0800104
developerdd386532022-07-26 17:14:47 +0800105@@ -59,6 +60,7 @@ $(curdir)/libelf/compile := $(curdir)/libtool/compile
106 $(curdir)/libressl/compile := $(curdir)/pkgconf/compile
107 $(curdir)/libtool/compile := $(curdir)/m4/compile $(curdir)/autoconf/compile $(curdir)/automake/compile $(curdir)/missing-macros/compile
108 $(curdir)/lzma-old/compile := $(curdir)/zlib/compile
109+$(curdir)/llvm-bpf/compile := $(curdir)/cmake/compile
110 $(curdir)/make-ext4fs/compile := $(curdir)/zlib/compile
111 $(curdir)/missing-macros/compile := $(curdir)/autoconf/compile
112 $(curdir)/mkimage/compile += $(curdir)/libressl/compile
113diff --git a/tools/llvm-bpf/Makefile b/tools/llvm-bpf/Makefile
114index 527b3578..53b7347a 100644
115--- a/tools/llvm-bpf/Makefile
116+++ b/tools/llvm-bpf/Makefile
117@@ -26,7 +26,7 @@ include $(INCLUDE_DIR)/cmake.mk
118
119 LLVM_BPF_PREFIX = llvm-bpf-$(PKG_VERSION).$(HOST_OS)-$(HOST_ARCH)
120
121-CMAKE_HOST_INSTALL_PREFIX = $(STAGING_DIR_HOST)/$(LLVM_BPF_PREFIX)
122+HOST_BUILD_PREFIX = $(STAGING_DIR_HOST)/$(LLVM_BPF_PREFIX)
123
124 CMAKE_HOST_OPTIONS += \
125 -DLLVM_ENABLE_BINDINGS=OFF \
126@@ -46,7 +46,7 @@ define Host/Install
127 $(Host/Install/Default)
128 ln -s $(LLVM_BPF_PREFIX) $(STAGING_DIR_HOST)/llvm-bpf
129 STRIP_KMOD= PATCHELF= STRIP=strip $(SCRIPT_DIR)/rstrip.sh $(STAGING_DIR_HOST)/llvm-bpf
130- echo "$(PKG_VERSION)" > $(CMAKE_HOST_INSTALL_PREFIX)/.llvm-version
131+ echo "$(PKG_VERSION)" > $(HOST_BUILD_PREFIX)/.llvm-version
132 endef
133
134 define Host/Uninstall