1# Copyright (c) 2020 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14template("clang_toolchain") { 15 toolchain(target_name) { 16 assert(defined(invoker.cc), "clang toolchain must specify a \"cc\" value") 17 assert(defined(invoker.cxx), "clang toolchain must specify a \"cxx\" value") 18 assert(defined(invoker.ar), "clang toolchain must specify a \"ar\" value") 19 assert(defined(invoker.ld), "clang toolchain must specify a \"ld\" value") 20 21 cc = invoker.cc 22 cxx = invoker.cxx 23 ar = invoker.ar 24 ld = invoker.ld 25 26 need_strip = false 27 if (defined(invoker.strip)) { 28 strip = invoker.strip 29 need_strip = true 30 } 31 32 tool("cc") { 33 command = "$cc {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" 34 description = "clang {{output}}" 35 outputs = 36 [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ] 37 } 38 tool("cxx") { 39 depfile = "{{output}}.d" 40 command = "$cxx {{defines}} {{include_dirs}} {{cflags_cc}} -c {{source}} -o {{output}}" 41 description = "clang++ {{output}}" 42 outputs = 43 [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ] 44 } 45 tool("asm") { 46 depfile = "{{output}}.d" 47 command = "$cc {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}" 48 description = "ASM {{output}}" 49 outputs = 50 [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ] 51 } 52 tool("alink") { 53 outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" 54 rspfile = "{{output}}.rsp" 55 rspfile_content = "{{inputs}}" 56 command = "$ar -cr {{output}} @\"$rspfile\"" 57 description = "AR {{output}}" 58 outputs = [ outfile ] 59 default_output_dir = "{{root_out_dir}}/libs" 60 default_output_extension = ".a" 61 output_prefix = "lib" 62 } 63 tool("solink") { 64 outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" 65 unstripped_outfile = outfile 66 67 rspfile = "$outfile.rsp" 68 rspfile_content = "{{inputs}}" 69 command = "" 70 if (need_strip) { 71 unstripped_outfile = "{{output_dir}}/unstripped/usr/lib/{{target_output_name}}{{output_extension}}" 72 } 73 74 command += 75 "$ld -shared {{ldflags}} {{inputs}} {{libs}} -o $unstripped_outfile" 76 if (need_strip) { 77 command += " && $strip \"$unstripped_outfile\" -o \"$outfile\"" 78 } 79 80 default_output_extension = ".so" 81 description = "SOLINK $outfile" 82 default_output_dir = "{{root_out_dir}}" 83 output_prefix = "lib" 84 outputs = [ outfile ] 85 if (unstripped_outfile != outfile) { 86 outputs += [ unstripped_outfile ] 87 } 88 } 89 tool("link") { 90 outfile = "{{output_dir}}/bin/{{target_output_name}}{{output_extension}}" 91 unstripped_outfile = outfile 92 93 rspfile = "$outfile.rsp" 94 custom_ld_flags = " " 95 command = "" 96 if (need_strip) { 97 unstripped_outfile = "{{output_dir}}/unstripped/bin/{{target_output_name}}{{output_extension}}" 98 } 99 command += "$ld {{ldflags}} {{inputs}} {{libs}} $custom_ld_flags -o $unstripped_outfile" 100 if (need_strip) { 101 command += " && $strip \"$unstripped_outfile\" -o \"$outfile\"" 102 } 103 104 description = "LLVM LINK $outfile" 105 default_output_dir = "{{root_out_dir}}" 106 rspfile_content = "{{inputs}}" 107 outputs = [ outfile ] 108 if (unstripped_outfile != outfile) { 109 outputs += [ unstripped_outfile ] 110 } 111 } 112 tool("stamp") { 113 if (host_os == "win") { 114 command = "cmd /c type nul > \"{{output}}\"" 115 } else { 116 command = "/usr/bin/touch {{output}}" 117 } 118 description = "STAMP {{output}}" 119 } 120 121 tool("copy") { 122 command = "cp -afd {{source}} {{output}}" 123 description = "COPY {{source}} {{output}}" 124 } 125 } 126} 127