Skip to content

Commit c7fb4f6

Browse files
WangNan0acmel
authored andcommitted
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>
1 parent cb40d55 commit c7fb4f6

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎tools/build/feature/Makefile‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,16 @@ $(OUTPUT)test-llvm.bin:
237237
$(shell $(LLVM_CONFIG) --libs Core BPF) \
238238
$(shell $(LLVM_CONFIG) --system-libs)
239239

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+
240250
-include $(OUTPUT)*.d
241251

242252
###############################

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}

0 commit comments

Comments
 (0)