From patchwork Tue Nov 15 04:05:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 82251 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp1342468qge; Mon, 14 Nov 2016 20:15:31 -0800 (PST) X-Received: by 10.107.170.231 with SMTP id g100mr28970192ioj.32.1479183331712; Mon, 14 Nov 2016 20:15:31 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 35si14602744iol.81.2016.11.14.20.15.31; Mon, 14 Nov 2016 20:15:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966428AbcKOEP1 (ORCPT + 26 others); Mon, 14 Nov 2016 23:15:27 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:25178 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755275AbcKOEIO (ORCPT ); Mon, 14 Nov 2016 23:08:14 -0500 Received: from 172.24.1.136 (EHLO SZXEML429-HUB.china.huawei.com) ([172.24.1.136]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CLJ01958; Tue, 15 Nov 2016 12:08:05 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by SZXEML429-HUB.china.huawei.com (10.82.67.184) with Microsoft SMTP Server id 14.3.235.1; Tue, 15 Nov 2016 12:07:56 +0800 From: Wang Nan To: , CC: , , , , Wang Nan , Jiri Olsa Subject: [PATCH 12/34] tools build: Add feature detection for clang Date: Tue, 15 Nov 2016 04:05:55 +0000 Message-ID: <20161115040617.69788-13-wangnan0@huawei.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161115040617.69788-1-wangnan0@huawei.com> References: <20161115040617.69788-1-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Alexei Starovoitov Cc: He Kuang Cc: Jiri Olsa Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1474874832-134786-5-git-send-email-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/build/feature/Makefile | 10 ++++++++++ tools/build/feature/test-clang.cpp | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tools/build/feature/test-clang.cpp -- 2.10.1 diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index c09de59..871d553 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile @@ -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 index 0000000..e23c1b1 --- /dev/null +++ b/tools/build/feature/test-clang.cpp @@ -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 DiagID(new DiagnosticIDs()); + IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); + + DiagnosticsEngine Diags(DiagID, &*DiagOpts); + Driver TheDriver("test", "bpf-pc-linux", Diags); + + llvm::llvm_shutdown(); + return 0; +}