From a368d456ba1e9198fd8f473b7e82c0e066e4eb82 Mon Sep 17 00:00:00 2001
From: Felix Fietkau <nbd@nbd.name>
Date: Mon, 1 Nov 2021 18:40:03 +0100
Subject: [PATCH 054/102] build: fix bpf toolchain dependency for qosify

Add hidden symbols to fix defaults with CONFIG_DEVEL unset

Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
 include/bpf.mk      |  2 ++
 toolchain/Config.in | 45 +++++++++++++++++++++++++++++++++++++++++++++
 tools/Makefile      |  2 +-
 3 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/include/bpf.mk b/include/bpf.mk
index 3dc65c7685..5211ec4434 100644
--- a/include/bpf.mk
+++ b/include/bpf.mk
@@ -1,3 +1,5 @@
+BPF_DEPENDS := @HAS_BPF_TOOLCHAIN
+
 ifneq ($(CONFIG_BPF_TOOLCHAIN_HOST),)
   BPF_TOOLCHAIN_HOST_PATH:=$(call qstrip,$(CONFIG_BPF_TOOLCHAIN_HOST_PATH))
   ifneq ($(BPF_TOOLCHAIN_HOST_PATH),)
diff --git a/toolchain/Config.in b/toolchain/Config.in
index 9062d6f65e..997cff59e4 100644
--- a/toolchain/Config.in
+++ b/toolchain/Config.in
@@ -44,6 +44,32 @@ config BUILD_LLVM_BPF
 	  If this is not enabled, eBPF packages can only be built if the host
 	  has a suitable toolchain
 
+	choice BPF_TOOLCHAIN
+		prompt "BPF toolchain" if DEVEL
+		default BPF_TOOLCHAIN_NONE
+
+		config BPF_TOOLCHAIN_NONE
+			bool "None"
+
+		config BPF_TOOLCHAIN_HOST
+			select USE_LLVM_HOST
+			bool "Use host LLVM toolchain"
+
+		config BPF_TOOLCHAIN_BUILD_LLVM
+			select USE_LLVM_BUILD
+			bool "Build LLVM toolchain for eBPF"
+			help
+			  If enabled, a LLVM toolchain for building eBPF binaries will be built.
+			  If this is not enabled, eBPF packages can only be built if the host
+			  has a suitable toolchain
+	endchoice
+
+	config BPF_TOOLCHAIN_HOST_PATH
+		string
+		depends on BPF_TOOLCHAIN_HOST
+		prompt "Host LLVM toolchain path (prefix)" if DEVEL
+		default "/usr/local/opt/llvm" if HOST_OS_MACOS
+		default ""
 
 menuconfig EXTERNAL_TOOLCHAIN
 	bool
@@ -266,6 +292,25 @@ config GDB
 	help
 	  Enable if you want to build the gdb.
 
+config GDB_PYTHON
+	bool
+	depends on GDB
+	prompt "Build gdb with python binding"
+	
+	help
+	  Enable the python bindings for GDB to allow using python in the gdb shell.
+
+config HAS_BPF_TOOLCHAIN
+	bool
+
+config USE_LLVM_HOST
+	select HAS_BPF_TOOLCHAIN
+	bool
+
+config USE_LLVM_BUILD
+	select HAS_BPF_TOOLCHAIN
+	bool
+
 config USE_GLIBC
 	default y if !TOOLCHAINOPTS && !EXTERNAL_TOOLCHAIN && !NATIVE_TOOLCHAIN && (arc)
 	bool
diff --git a/tools/Makefile b/tools/Makefile
index 83147014c6..ae3cc5dfd6 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -35,7 +35,7 @@ tools-$(CONFIG_TARGET_mxs) += elftosb sdimage
 tools-$(CONFIG_TARGET_tegra) += cbootimage cbootimage-configs
 tools-$(CONFIG_USES_MINOR) += kernel2minor
 tools-$(CONFIG_USE_SPARSE) += sparse
-tools-$(CONFIG_BUILD_LLVM_BPF) += llvm-bpf
+tools-$(CONFIG_USE_LLVM_BUILD) += llvm-bpf
 
 # builddir dependencies
 $(curdir)/autoconf/compile := $(curdir)/m4/compile
-- 
2.25.1

