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 14ohos_build_compiler = "clang" 15ohos_build_compiler_dir_linux = rebase_path("//clang/bin", root_build_dir) 16ohos_build_compiler_dir_win = rebase_path("//clang/bin", root_build_dir) 17ohos_build_compiler_prefix = "clang" 18ohos_build_compiler_so_strip = "llvm-objcopy --strip-all" 19ohos_build_compiler_bin_strip = "llvm-objcopy --strip-all" 20 21template("clang_toolchain") { 22 toolchain(target_name) { 23 assert(defined(invoker.cc), "clang toolchain must specify a \"cc\" value") 24 assert(defined(invoker.cxx), "clang toolchain must specify a \"cxx\" value") 25 assert(defined(invoker.ar), "clang toolchain must specify a \"ar\" value") 26 assert(defined(invoker.as), "clang toolchain must specify a \"as\" value") 27 assert(defined(invoker.ld), "clang toolchain must specify a \"ld\" value") 28 29 cc = invoker.cc 30 cxx = invoker.cxx 31 ar = invoker.ar 32 as = invoker.as 33 ld = invoker.ld 34 35 need_strip = false 36 if (defined(invoker.strip)) { 37 strip = invoker.strip 38 need_strip = true 39 } 40 41 tool("cc") { 42 command = "$cc {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" 43 depsformat = "gcc" 44 description = "clang {{output}}" 45 outputs = [ "{{source_out_dir}}/{{source_name_part}}.o" ] 46 } 47 tool("cxx") { 48 depfile = "{{output}}.d" 49 command = "$cxx {{defines}} {{include_dirs}} {{cflags_cc}} -c {{source}} -o {{output}}" 50 depsformat = "gcc" 51 description = "clang++ {{output}}" 52 outputs = [ "{{source_out_dir}}/{{source_name_part}}.o" ] 53 } 54 tool("asm") { 55 depfile = "{{output}}.d" 56 command = "$as {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}" 57 depsformat = "gcc" 58 description = "ASM {{output}}" 59 outputs = [ "{{source_out_dir}}/{{source_name_part}}.o" ] 60 } 61 tool("alink") { 62 outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" 63 rspfile = "{{output}}.rsp" 64 rspfile_content = "{{inputs}}" 65 command = "$ar -r {{output}} @\"$rspfile\"" 66 description = "AR {{output}}" 67 outputs = [ outfile ] 68 default_output_dir = "{{root_out_dir}}/libs" 69 default_output_extension = ".a" 70 output_prefix = "lib" 71 } 72 tool("solink") { 73 outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" 74 rspfile = "$outfile.rsp" 75 rspfile_content = "{{inputs}}" 76 command = "$ld -shared {{ldflags}} {{inputs}} -o $outfile" 77 if (need_strip) { 78 unstripped_outfile = outfile 79 command += " && $strip" + " \"$unstripped_outfile\" \"$outfile\"" 80 } 81 default_output_extension = ".so" 82 description = "SOLINK $outfile" 83 default_output_dir = "{{root_out_dir}}" 84 output_prefix = "lib" 85 outputs = [ outfile ] 86 } 87 tool("link") { 88 outfile = "bin/{{target_output_name}}{{output_extension}}" 89 rspfile = "$outfile.rsp" 90 custom_ld_flags = " " 91 command = "$ld {{ldflags}} {{inputs}} $custom_ld_flags -o $outfile" 92 if (need_strip) { 93 command += " && $strip $outfile" 94 } 95 96 description = "LLVM LINK $outfile" 97 default_output_dir = "{{root_out_dir}}/bin" 98 rspfile_content = "{{inputs}}" 99 outputs = [ outfile ] 100 } 101 tool("stamp") { 102 if (host_os == "win") { 103 command = "cmd /c type nul > \"{{output}}\"" 104 } else { 105 command = "/usr/bin/touch {{output}}" 106 } 107 description = "STAMP {{output}}" 108 } 109 110 tool("copy") { 111 command = "cp -afd {{source}} {{output}}" 112 description = "COPY {{source}} {{output}}" 113 } 114 } 115} 116