From 22b3476400679f9bffb6bbc38de7b684b313324d Mon Sep 17 00:00:00 2001 From: "brettw@chromium.org" Date: Mon, 3 Feb 2014 12:11:38 +0000 Subject: [PATCH] Work on Clang for pure GN build. This hooks up Clang in the pure GN build (not the hybrid GYP mode). Clang gave some warnings about compiler flags which made me realize that we were giving linker flags to the compiler in some cases. So I enhanced our pkg-config wrapper to to add libraries to the cflags (missing else), return ldflags separately, and also strip out -pthread which was getting included over and over. BUG= Review URL: https://codereview.chromium.org/147923010 git-svn-id: http://src.chromium.org/svn/trunk/src/build@248477 4ff67af0-8c30-449e-8e8b-ad334ec8d88c --- config/linux/pkg-config.py | 16 +++++++++---- config/linux/pkg_config.gni | 1 + toolchain/linux/BUILD.gn | 46 ++++++++++++++++++++++++++----------- 3 files changed, 46 insertions(+), 17 deletions(-) diff --git a/config/linux/pkg-config.py b/config/linux/pkg-config.py index c1c0dc4f5..70cb5e961 100644 --- a/config/linux/pkg-config.py +++ b/config/linux/pkg-config.py @@ -12,8 +12,8 @@ from optparse import OptionParser # This script runs pkg-config, optionally filtering out some results, and # returns the result. # -# The result will be [ , , , ] where each -# member is itself a list of strings. +# The result will be [ , , , , ] +# where each member is itself a list of strings. # # You can filter out matches using "-v " where all results from # pkgconfig matching the given regular expression will be ignored. You can @@ -138,6 +138,7 @@ includes = [] cflags = [] libs = [] lib_dirs = [] +ldflags = [] for flag in all_flags[:]: if len(flag) == 0 or MatchesAnyRegexp(flag, strip_out): @@ -145,14 +146,21 @@ for flag in all_flags[:]: if flag[:2] == '-l': libs.append(RewritePath(flag[2:], prefix, sysroot)) - if flag[:2] == '-L': + elif flag[:2] == '-L': lib_dirs.append(RewritePath(flag[2:], prefix, sysroot)) elif flag[:2] == '-I': includes.append(RewritePath(flag[2:], prefix, sysroot)) + elif flag[:3] == '-Wl': + ldflags.append(flag) + elif flag == '-pthread': + # Many libs specify "-pthread" which we don't need since we always include + # this anyway. Removing it here prevents a bunch of duplicate inclusions on + # the command line. + pass else: cflags.append(flag) # Output a GN array, the first one is the cflags, the second are the libs. The # JSON formatter prints GN compatible lists when everything is a list of # strings. -print json.dumps([includes, cflags, libs, lib_dirs]) +print json.dumps([includes, cflags, libs, lib_dirs, ldflags]) diff --git a/config/linux/pkg_config.gni b/config/linux/pkg_config.gni index dd592236a..fdd31ba84 100644 --- a/config/linux/pkg_config.gni +++ b/config/linux/pkg_config.gni @@ -34,5 +34,6 @@ template("pkg_config") { cflags = pkgresult[1] libs = pkgresult[2] lib_dirs = pkgresult[3] + ldflags = pkgresult[4] } } diff --git a/toolchain/linux/BUILD.gn b/toolchain/linux/BUILD.gn index 74d287fec..38f4b184c 100644 --- a/toolchain/linux/BUILD.gn +++ b/toolchain/linux/BUILD.gn @@ -2,10 +2,10 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -import("../clang.gni") -import("../goma.gni") -import("../gcc_toolchain.gni") import("//build/config/sysroot.gni") +import("//build/toolchain/clang.gni") +import("//build/toolchain/gcc_toolchain.gni") +import("//build/toolchain/goma.gni") if (is_gyp) { # Set the compilers for GYP to use. This logic is only relevant to GYP where @@ -47,8 +47,6 @@ if (is_gyp) { } } -# ARM -------------------------------------------------------------------------- - gcc_toolchain("arm") { cc = "arm-linux-gnueabi-gcc" cxx = "arm-linux-gnueabi-g++" @@ -59,11 +57,22 @@ gcc_toolchain("arm") { toolchain_os = "linux" } -# 32-bit ----------------------------------------------------------------------- - gcc_toolchain("x86") { - cc = "gcc" - cxx = "g++" + if (is_clang) { + if (use_clang_type_profiler) { + prefix = rebase_path("//third_party/llvm-allocated-type/Linux_ia32/bin", + ".", root_build_dir) + } else { + prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin", + ".", root_build_dir) + } + cc = "$prefix/clang" + cxx = "$prefix/clang++" + } else { + cc = "gcc" + cxx = "g++" + } + ar = "ar" ld = cxx @@ -72,8 +81,21 @@ gcc_toolchain("x86") { } gcc_toolchain("x64") { - cc = "gcc" - cxx = "g++" + if (is_clang) { + if (use_clang_type_profiler) { + prefix = rebase_path("//third_party/llvm-allocated-type/Linux_x64/bin", + ".", root_build_dir) + } else { + prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin", + ".", root_build_dir) + } + cc = "$prefix/clang" + cxx = "$prefix/clang++" + } else { + cc = "gcc" + cxx = "g++" + } + ar = "ar" ld = cxx @@ -81,8 +103,6 @@ gcc_toolchain("x64") { toolchain_os = "linux" } -# MIPS ----------------------------------------------------------------------- - gcc_toolchain("mipsel") { cc = "mipsel-linux-gnu-gcc" cxx = "mipsel-linux-gnu-g++"