1# 2# Copyright 2016 Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at: 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16clang_suffix = exec_script("get_clang_suffix.py", [], "list lines") 17clang_suffix = clang_suffix[0] 18assert(clang_suffix != "None", 19 "Cannot find clang, please install clang 3.5 or above") 20if (clang_suffix != "") { 21 clang_suffix = "-" + clang_suffix 22} 23clang = "clang$clang_suffix" 24clangxx = "clang++$clang_suffix" 25 26config("clang_config") { 27 include_dirs = [ 28 "/usr/include/libcxxabi", 29 ] 30 cflags_cc = [ 31 "-stdlib=libc++", 32 ] 33 ldflags = [ 34 "-stdlib=libc++", 35 ] 36} 37 38toolchain("clang") { 39 tool("cc") { 40 depfile = "{{output}}.d" 41 command = "$clang -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" 42 depsformat = "gcc" 43 description = "CC {{output}}" 44 outputs = [ 45 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", 46 ] 47 } 48 49 tool("cxx") { 50 depfile = "{{output}}.d" 51 command = "$clangxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}" 52 depsformat = "gcc" 53 description = "CXX {{output}}" 54 outputs = [ 55 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", 56 ] 57 } 58 59 tool("alink") { 60 rspfile = "{{output}}.rsp" 61 command = "rm -f {{output}} && ar rcs {{output}} @$rspfile" 62 description = "AR {{target_output_name}}{{output_extension}}" 63 rspfile_content = "{{inputs}}" 64 outputs = [ 65 "{{target_out_dir}}/{{target_output_name}}{{output_extension}}", 66 ] 67 default_output_extension = ".a" 68 69 output_prefix = "lib" 70 } 71 72 tool("solink") { 73 soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". 74 rspfile = soname + ".rsp" 75 76 command = 77 "$clangxx -shared {{ldflags}} -o $soname -Wl,-soname=$soname @$rspfile" 78 rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}" 79 80 description = "SOLINK $soname" 81 82 # Use this for {{output_extension}} expansions unless a target manually 83 # overrides it (in which case {{output_extension}} will be what the target 84 # specifies). 85 default_output_extension = ".so" 86 87 outputs = [ 88 soname, 89 ] 90 link_output = soname 91 depend_output = soname 92 93 output_prefix = "lib" 94 } 95 96 tool("link") { 97 outfile = "{{target_output_name}}{{output_extension}}" 98 rspfile = "$outfile.rsp" 99 command = "$clangxx {{ldflags}} -o $outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group {{libs}}" 100 description = "LINK $outfile" 101 rspfile_content = "{{inputs}}" 102 outputs = [ 103 outfile, 104 ] 105 } 106 107 tool("stamp") { 108 command = "touch {{output}}" 109 description = "STAMP {{output}}" 110 } 111 112 tool("copy") { 113 command = "cp -af {{source}} {{output}}" 114 description = "COPY {{source}} {{output}}" 115 } 116} 117