1# Copyright (c) 2021-2022 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("gcc_toolchain") { 15 assert(defined(invoker.ar)) 16 assert(defined(invoker.cc)) 17 assert(defined(invoker.cxx)) 18 assert(defined(invoker.ld)) 19 20 ar = invoker.ar 21 cc = invoker.cc 22 cxx = invoker.cxx 23 ld = invoker.ld 24 25 if (!defined(invoker.asm)) { 26 asm = cc 27 } else { 28 asm = invoker.asm 29 } 30 31 if (defined(invoker.extra_cppflags)) { 32 extra_cppflags = invoker.extra_cppflags 33 } else { 34 extra_cppflags = "" 35 } 36 37 if (defined(invoker.extra_asmflags)) { 38 extra_asmflags = invoker.extra_asmflags 39 } else { 40 extra_asmflags = "" 41 } 42 43 if (defined(invoker.extra_ldflags)) { 44 extra_ldflags = invoker.extra_ldflags 45 } else { 46 extra_ldflags = "" 47 } 48 49 object_subdir = "{{source_out_dir}}/{{label_name}}" 50 51 toolchain(target_name) { 52 tool("cc") { 53 depfile = "{{output}}.d" 54 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} ${extra_cppflags} -c {{source}} -o {{output}}" 55 depsformat = "gcc" 56 description = "CC {{output}}" 57 outputs = 58 [ "$object_subdir/{{target_output_name}}.{{source_name_part}}.o" ] 59 } 60 61 tool("cxx") { 62 depfile = "{{output}}.d" 63 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} ${extra_cppflags} -c {{source}} -o {{output}}" 64 depsformat = "gcc" 65 description = "CXX {{output}}" 66 outputs = 67 [ "$object_subdir/{{target_output_name}}.{{source_name_part}}.o" ] 68 } 69 70 tool("asm") { 71 depfile = "{{output}}.d" 72 command = "$asm -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} ${extra_asmflags} -c {{source}} -o {{output}}" 73 depsformat = "gcc" 74 description = "ASM {{output}}" 75 outputs = 76 [ "$object_subdir/{{target_output_name}}.{{source_name_part}}.o" ] 77 } 78 79 tool("alink") { 80 command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}" 81 description = "AR {{target_output_name}}{{output_extension}}" 82 83 outputs = [ "{{output_dir}}/{{target_output_name}}{{output_extension}}" ] 84 default_output_dir = "{{target_out_dir}}" 85 default_output_extension = ".a" 86 output_prefix = "lib" 87 } 88 89 tool("solink") { 90 soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". 91 sofile = "{{output_dir}}/$soname" 92 rspfile = soname + ".rsp" 93 94 os_specific_option = "-Wl,-soname=$soname" 95 rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}" 96 97 command = "$ld -shared {{ldflags}} ${extra_ldflags} -o $sofile $os_specific_option @$rspfile" 98 99 description = "SOLINK $soname" 100 101 # Use this for {{output_extension}} expansions unless a target manually 102 # overrides it (in which case {{output_extension}} will be what the target 103 # specifies). 104 default_output_extension = ".so" 105 106 # Use this for {{output_dir}} expansions unless a target manually overrides 107 # it (in which case {{output_dir}} will be what the target specifies). 108 default_output_dir = "{{root_out_dir}}" 109 110 outputs = [ sofile ] 111 link_output = sofile 112 depend_output = sofile 113 output_prefix = "lib" 114 } 115 116 tool("link") { 117 outfile = "{{target_output_name}}{{output_extension}}" 118 rspfile = "$outfile.rsp" 119 command = "$ld {{ldflags}} -o $outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group {{libs}}" 120 description = "LINK $outfile" 121 default_output_dir = "{{root_out_dir}}" 122 rspfile_content = "{{inputs}}" 123 outputs = [ outfile ] 124 } 125 126 tool("stamp") { 127 command = "touch {{output}}" 128 description = "STAMP {{output}}" 129 } 130 131 tool("copy") { 132 command = "cp -af {{source}} {{output}}" 133 description = "COPY {{source}} {{output}}" 134 } 135 } 136} 137 138gcc_toolchain("clang-9") { 139 cc = "clang-9" 140 cxx = "clang++-9" 141 ar = "ar" 142 ld = cxx 143} 144