Skip to content

Commit cb40d55

Browse files
WangNan0acmel
authored andcommitted
tools build: Add feature detection for LLVM
Check if basic LLVM compiling environment is ready. Use llvm-config to detect include and library directories. Avoid using 'llvm-config --cxxflags' because its result contain some unwanted flags like --sysroot (if LLVM is built by yocto). Use '?=' to set LLVM_CONFIG, so explicitly passing LLVM_CONFIG to make would override it. Use 'llvm-config --libs BPF' to check if BPF backend is compiled in. Since now BPF bytecode is the only required backend, no need to waste time linking llvm and clang if BPF backend is missing. This also introduce an implicit requirement that LLVM should be new enough. Old LLVM doesn't support BPF backend. Signed-off-by: Wang Nan <wangnan0@huawei.com> Cc: Alexei Starovoitov <ast@fb.com> Cc: He Kuang <hekuang@huawei.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Joe Stringer <joe@ovn.org> Cc: Zefan Li <lizefan@huawei.com> Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/20161126070354.141764-8-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 2bd42de commit cb40d55

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎tools/build/feature/Makefile‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ FILES := $(addprefix $(OUTPUT),$(FILES))
5555
CC := $(CROSS_COMPILE)gcc -MD
5656
CXX := $(CROSS_COMPILE)g++ -MD
5757
PKG_CONFIG := $(CROSS_COMPILE)pkg-config
58+
LLVM_CONFIG ?= llvm-config
5859

5960
all: $(FILES)
6061

@@ -229,6 +230,13 @@ $(OUTPUT)test-cxx.bin:
229230
$(OUTPUT)test-jvmti.bin:
230231
$(BUILD)
231232

233+
$(OUTPUT)test-llvm.bin:
234+
$(BUILDXX) -std=gnu++11 \
235+
-I$(shell $(LLVM_CONFIG) --includedir) \
236+
-L$(shell $(LLVM_CONFIG) --libdir) \
237+
$(shell $(LLVM_CONFIG) --libs Core BPF) \
238+
$(shell $(LLVM_CONFIG) --system-libs)
239+
232240
-include $(OUTPUT)*.d
233241

234242
###############################

‎tools/build/feature/test-llvm.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "llvm/Support/ManagedStatic.h"
2+
#include "llvm/Support/raw_ostream.h"
3+
int main()
4+
{
5+
llvm::errs() << "Hello World!\n";
6+
llvm::llvm_shutdown();
7+
return 0;
8+
}

0 commit comments

Comments
 (0)