tools build: Add feature detection for clang
authorWang Nan <wangnan0@huawei.com>
Sat, 26 Nov 2016 07:03:32 +0000 (07:03 +0000)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 5 Dec 2016 18:51:43 +0000 (15:51 -0300)
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>
tools/build/feature/Makefile
tools/build/feature/test-clang.cpp [new file with mode: 0644]

index c09de59affc972d8afbf8e4351967d75690641ec..871d5536951d1c1cef762431bde75e8677071949 100644 (file)
@@ -237,6 +237,16 @@ $(OUTPUT)test-llvm.bin:
                $(shell $(LLVM_CONFIG) --libs Core BPF)         \
                $(shell $(LLVM_CONFIG) --system-libs)
 
+$(OUTPUT)test-clang.bin:
+       $(BUILDXX) -std=gnu++11                                         \
+               -I$(shell $(LLVM_CONFIG) --includedir)          \
+               -L$(shell $(LLVM_CONFIG) --libdir)              \
+               -Wl,--start-group -lclangBasic -lclangDriver    \
+                 -lclangFrontend -lclangEdit -lclangLex        \
+                 -lclangAST -Wl,--end-group                    \
+               $(shell $(LLVM_CONFIG) --libs Core option)      \
+               $(shell $(LLVM_CONFIG) --system-libs)
+
 -include $(OUTPUT)*.d
 
 ###############################
diff --git a/tools/build/feature/test-clang.cpp b/tools/build/feature/test-clang.cpp
new file mode 100644 (file)
index 0000000..e23c1b1
--- /dev/null
@@ -0,0 +1,21 @@
+#include "clang/Basic/VirtualFileSystem.h"
+#include "clang/Driver/Driver.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace clang;
+using namespace clang::driver;
+
+int main()
+{
+       IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
+       IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
+
+       DiagnosticsEngine Diags(DiagID, &*DiagOpts);
+       Driver TheDriver("test", "bpf-pc-linux", Diags);
+
+       llvm::llvm_shutdown();
+       return 0;
+}