Commit c7fb4f62e2a97bd25d555263ef501fe053edcbb6

Authored by Wang Nan
Committed by Arnaldo Carvalho de Melo
1 parent cb40d55b59

tools build: Add feature detection for clang

Check if basic clang compiling environment is ready.

Doesn't like 'llvm-config --libs' which can returns llvm libraries in right
order and duplicates some libraries if necessary, there's no correspondence for
clang libraries (-lclangxxx). to avoid extra complexity and to avoid new clang
breaking libraries ordering, use --start-group and --end-group.

In this test case, manually identify required clang libs and hope it to be
stable. Putting all clang libraries here is possible (use make's wildcard), but
then feature checking becomes very slow.

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-9-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

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

tools/build/feature/Makefile
... ... @@ -237,6 +237,16 @@
237 237 $(shell $(LLVM_CONFIG) --libs Core BPF) \
238 238 $(shell $(LLVM_CONFIG) --system-libs)
239 239  
  240 +$(OUTPUT)test-clang.bin:
  241 + $(BUILDXX) -std=gnu++11 \
  242 + -I$(shell $(LLVM_CONFIG) --includedir) \
  243 + -L$(shell $(LLVM_CONFIG) --libdir) \
  244 + -Wl,--start-group -lclangBasic -lclangDriver \
  245 + -lclangFrontend -lclangEdit -lclangLex \
  246 + -lclangAST -Wl,--end-group \
  247 + $(shell $(LLVM_CONFIG) --libs Core option) \
  248 + $(shell $(LLVM_CONFIG) --system-libs)
  249 +
240 250 -include $(OUTPUT)*.d
241 251  
242 252 ###############################
tools/build/feature/test-clang.cpp
  1 +#include "clang/Basic/VirtualFileSystem.h"
  2 +#include "clang/Driver/Driver.h"
  3 +#include "clang/Frontend/TextDiagnosticPrinter.h"
  4 +#include "llvm/ADT/IntrusiveRefCntPtr.h"
  5 +#include "llvm/Support/ManagedStatic.h"
  6 +#include "llvm/Support/raw_ostream.h"
  7 +
  8 +using namespace clang;
  9 +using namespace clang::driver;
  10 +
  11 +int main()
  12 +{
  13 + IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
  14 + IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
  15 +
  16 + DiagnosticsEngine Diags(DiagID, &*DiagOpts);
  17 + Driver TheDriver("test", "bpf-pc-linux", Diags);
  18 +
  19 + llvm::llvm_shutdown();
  20 + return 0;
  21 +}