From e28785321b1b66c36572fc6ce00da6edb7a0a115 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowski Date: Tue, 18 Oct 2016 09:56:57 -0700 Subject: [PATCH] Add clang configuration for ninja build scripts Test: compile with ninja Change-Id: I0f2ff28a03de05ea96bed5ba43eace9609d8deb0 --- build/config/BUILDCONFIG.gn | 2 +- build/toolchain/clang/BUILD.gn | 97 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 build/toolchain/clang/BUILD.gn diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn index 419d62fad..fb71af5fe 100644 --- a/build/config/BUILDCONFIG.gn +++ b/build/config/BUILDCONFIG.gn @@ -14,7 +14,7 @@ # limitations under the License. # -set_default_toolchain("//build/toolchain/gcc") +set_default_toolchain("//build/toolchain/clang") set_defaults("executable") { configs = [ diff --git a/build/toolchain/clang/BUILD.gn b/build/toolchain/clang/BUILD.gn new file mode 100644 index 000000000..7035c380b --- /dev/null +++ b/build/toolchain/clang/BUILD.gn @@ -0,0 +1,97 @@ +# +# Copyright (C) 2016 Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +clang = "clang" +clangxx = "clang++" + +toolchain("clang") { + tool("cc") { + depfile = "{{output}}.d" + command = "$clang -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" + depsformat = "gcc" + description = "CC {{output}}" + outputs = [ + "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", + ] + } + + tool("cxx") { + depfile = "{{output}}.d" + command = "$clangxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}" + depsformat = "gcc" + description = "CXX {{output}}" + outputs = [ + "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", + ] + } + + tool("alink") { + rspfile = "{{output}}.rsp" + command = "rm -f {{output}} && ar rcs {{output}} @$rspfile" + description = "AR {{target_output_name}}{{output_extension}}" + rspfile_content = "{{inputs}}" + outputs = [ + "{{target_out_dir}}/{{target_output_name}}{{output_extension}}", + ] + default_output_extension = ".a" + + output_prefix = "lib" + } + + tool("solink") { + soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". + rspfile = soname + ".rsp" + + command = + "$clangxx -shared {{ldflags}} -o $soname -Wl,-soname=$soname @$rspfile" + rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}" + + description = "SOLINK $soname" + + # Use this for {{output_extension}} expansions unless a target manually + # overrides it (in which case {{output_extension}} will be what the target + # specifies). + default_output_extension = ".so" + + outputs = [ + soname, + ] + link_output = soname + depend_output = soname + + output_prefix = "lib" + } + + tool("link") { + outfile = "{{target_output_name}}{{output_extension}}" + rspfile = "$outfile.rsp" + command = "$clangxx {{ldflags}} -o $outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group {{libs}}" + description = "LINK $outfile" + rspfile_content = "{{inputs}}" + outputs = [ + outfile, + ] + } + + tool("stamp") { + command = "touch {{output}}" + description = "STAMP {{output}}" + } + + tool("copy") { + command = "cp -af {{source}} {{output}}" + description = "COPY {{source}} {{output}}" + } +} -- 2.11.0