# Copyright (c) 2021-2022 Huawei Device Co., Ltd. # 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. template("gcc_toolchain") { assert(defined(invoker.ar)) assert(defined(invoker.cc)) assert(defined(invoker.cxx)) assert(defined(invoker.ld)) ar = invoker.ar cc = invoker.cc cxx = invoker.cxx ld = invoker.ld if (!defined(invoker.asm)) { asm = cc } else { asm = invoker.asm } if (defined(invoker.extra_cppflags)) { extra_cppflags = invoker.extra_cppflags } else { extra_cppflags = "" } if (defined(invoker.extra_asmflags)) { extra_asmflags = invoker.extra_asmflags } else { extra_asmflags = "" } if (defined(invoker.extra_ldflags)) { extra_ldflags = invoker.extra_ldflags } else { extra_ldflags = "" } object_subdir = "{{source_out_dir}}/{{label_name}}" toolchain(target_name) { tool("cc") { depfile = "{{output}}.d" command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} ${extra_cppflags} -c {{source}} -o {{output}}" depsformat = "gcc" description = "CC {{output}}" outputs = [ "$object_subdir/{{target_output_name}}.{{source_name_part}}.o" ] } tool("cxx") { depfile = "{{output}}.d" command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} ${extra_cppflags} -c {{source}} -o {{output}}" depsformat = "gcc" description = "CXX {{output}}" outputs = [ "$object_subdir/{{target_output_name}}.{{source_name_part}}.o" ] } tool("asm") { depfile = "{{output}}.d" command = "$asm -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} ${extra_asmflags} -c {{source}} -o {{output}}" depsformat = "gcc" description = "ASM {{output}}" outputs = [ "$object_subdir/{{target_output_name}}.{{source_name_part}}.o" ] } tool("alink") { command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}" description = "AR {{target_output_name}}{{output_extension}}" outputs = [ "{{output_dir}}/{{target_output_name}}{{output_extension}}" ] default_output_dir = "{{target_out_dir}}" default_output_extension = ".a" output_prefix = "lib" } tool("solink") { soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". sofile = "{{output_dir}}/$soname" rspfile = soname + ".rsp" os_specific_option = "-Wl,-soname=$soname" rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}" command = "$ld -shared {{ldflags}} ${extra_ldflags} -o $sofile $os_specific_option @$rspfile" 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" # Use this for {{output_dir}} expansions unless a target manually overrides # it (in which case {{output_dir}} will be what the target specifies). default_output_dir = "{{root_out_dir}}" outputs = [ sofile ] link_output = sofile depend_output = sofile output_prefix = "lib" } tool("link") { outfile = "{{target_output_name}}{{output_extension}}" rspfile = "$outfile.rsp" command = "$ld {{ldflags}} -o $outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group {{libs}}" description = "LINK $outfile" default_output_dir = "{{root_out_dir}}" rspfile_content = "{{inputs}}" outputs = [ outfile ] } tool("stamp") { command = "touch {{output}}" description = "STAMP {{output}}" } tool("copy") { command = "cp -af {{source}} {{output}}" description = "COPY {{source}} {{output}}" } } } gcc_toolchain("clang-9") { cc = "clang-9" cxx = "clang++-9" ar = "ar" ld = cxx }