Commit cb40d55b595cd117ef7c1880247605875b2115e8

Authored by Wang Nan
Committed by Arnaldo Carvalho de Melo
1 parent 2bd42de0e1

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>

Showing 2 changed files with 16 additions and 0 deletions Side-by-side Diff

tools/build/feature/Makefile
... ... @@ -55,6 +55,7 @@
55 55 CC := $(CROSS_COMPILE)gcc -MD
56 56 CXX := $(CROSS_COMPILE)g++ -MD
57 57 PKG_CONFIG := $(CROSS_COMPILE)pkg-config
  58 +LLVM_CONFIG ?= llvm-config
58 59  
59 60 all: $(FILES)
60 61  
... ... @@ -228,6 +229,13 @@
228 229  
229 230 $(OUTPUT)test-jvmti.bin:
230 231 $(BUILD)
  232 +
  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)
231 239  
232 240 -include $(OUTPUT)*.d
233 241  
tools/build/feature/test-llvm.cpp
  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 +}