1b1994897Sopenharmony_ci# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
2b1994897Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
3b1994897Sopenharmony_ci# you may not use this file except in compliance with the License.
4b1994897Sopenharmony_ci# You may obtain a copy of the License at
5b1994897Sopenharmony_ci#
6b1994897Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0
7b1994897Sopenharmony_ci#
8b1994897Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
9b1994897Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
10b1994897Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11b1994897Sopenharmony_ci# See the License for the specific language governing permissions and
12b1994897Sopenharmony_ci# limitations under the License.
13b1994897Sopenharmony_ci
14b1994897Sopenharmony_citemplate("gcc_toolchain") {
15b1994897Sopenharmony_ci  assert(defined(invoker.ar))
16b1994897Sopenharmony_ci  assert(defined(invoker.cc))
17b1994897Sopenharmony_ci  assert(defined(invoker.cxx))
18b1994897Sopenharmony_ci  assert(defined(invoker.ld))
19b1994897Sopenharmony_ci
20b1994897Sopenharmony_ci  ar = invoker.ar
21b1994897Sopenharmony_ci  cc = invoker.cc
22b1994897Sopenharmony_ci  cxx = invoker.cxx
23b1994897Sopenharmony_ci  ld = invoker.ld
24b1994897Sopenharmony_ci
25b1994897Sopenharmony_ci  if (!defined(invoker.asm)) {
26b1994897Sopenharmony_ci    asm = cc
27b1994897Sopenharmony_ci  } else {
28b1994897Sopenharmony_ci    asm = invoker.asm
29b1994897Sopenharmony_ci  }
30b1994897Sopenharmony_ci
31b1994897Sopenharmony_ci  if (defined(invoker.extra_cppflags)) {
32b1994897Sopenharmony_ci    extra_cppflags = invoker.extra_cppflags
33b1994897Sopenharmony_ci  } else {
34b1994897Sopenharmony_ci    extra_cppflags = ""
35b1994897Sopenharmony_ci  }
36b1994897Sopenharmony_ci
37b1994897Sopenharmony_ci  if (defined(invoker.extra_asmflags)) {
38b1994897Sopenharmony_ci    extra_asmflags = invoker.extra_asmflags
39b1994897Sopenharmony_ci  } else {
40b1994897Sopenharmony_ci    extra_asmflags = ""
41b1994897Sopenharmony_ci  }
42b1994897Sopenharmony_ci
43b1994897Sopenharmony_ci  if (defined(invoker.extra_ldflags)) {
44b1994897Sopenharmony_ci    extra_ldflags = invoker.extra_ldflags
45b1994897Sopenharmony_ci  } else {
46b1994897Sopenharmony_ci    extra_ldflags = ""
47b1994897Sopenharmony_ci  }
48b1994897Sopenharmony_ci
49b1994897Sopenharmony_ci  object_subdir = "{{source_out_dir}}/{{label_name}}"
50b1994897Sopenharmony_ci
51b1994897Sopenharmony_ci  toolchain(target_name) {
52b1994897Sopenharmony_ci    tool("cc") {
53b1994897Sopenharmony_ci      depfile = "{{output}}.d"
54b1994897Sopenharmony_ci      command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} ${extra_cppflags} -c {{source}} -o {{output}}"
55b1994897Sopenharmony_ci      depsformat = "gcc"
56b1994897Sopenharmony_ci      description = "CC {{output}}"
57b1994897Sopenharmony_ci      outputs =
58b1994897Sopenharmony_ci          [ "$object_subdir/{{target_output_name}}.{{source_name_part}}.o" ]
59b1994897Sopenharmony_ci    }
60b1994897Sopenharmony_ci
61b1994897Sopenharmony_ci    tool("cxx") {
62b1994897Sopenharmony_ci      depfile = "{{output}}.d"
63b1994897Sopenharmony_ci      command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} ${extra_cppflags} -c {{source}} -o {{output}}"
64b1994897Sopenharmony_ci      depsformat = "gcc"
65b1994897Sopenharmony_ci      description = "CXX {{output}}"
66b1994897Sopenharmony_ci      outputs =
67b1994897Sopenharmony_ci          [ "$object_subdir/{{target_output_name}}.{{source_name_part}}.o" ]
68b1994897Sopenharmony_ci    }
69b1994897Sopenharmony_ci
70b1994897Sopenharmony_ci    tool("asm") {
71b1994897Sopenharmony_ci      depfile = "{{output}}.d"
72b1994897Sopenharmony_ci      command = "$asm -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} ${extra_asmflags} -c {{source}} -o {{output}}"
73b1994897Sopenharmony_ci      depsformat = "gcc"
74b1994897Sopenharmony_ci      description = "ASM {{output}}"
75b1994897Sopenharmony_ci      outputs =
76b1994897Sopenharmony_ci          [ "$object_subdir/{{target_output_name}}.{{source_name_part}}.o" ]
77b1994897Sopenharmony_ci    }
78b1994897Sopenharmony_ci
79b1994897Sopenharmony_ci    tool("alink") {
80b1994897Sopenharmony_ci      command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}"
81b1994897Sopenharmony_ci      description = "AR {{target_output_name}}{{output_extension}}"
82b1994897Sopenharmony_ci
83b1994897Sopenharmony_ci      outputs = [ "{{output_dir}}/{{target_output_name}}{{output_extension}}" ]
84b1994897Sopenharmony_ci      default_output_dir = "{{target_out_dir}}"
85b1994897Sopenharmony_ci      default_output_extension = ".a"
86b1994897Sopenharmony_ci      output_prefix = "lib"
87b1994897Sopenharmony_ci    }
88b1994897Sopenharmony_ci
89b1994897Sopenharmony_ci    tool("solink") {
90b1994897Sopenharmony_ci      soname = "{{target_output_name}}{{output_extension}}"  # e.g. "libfoo.so".
91b1994897Sopenharmony_ci      sofile = "{{output_dir}}/$soname"
92b1994897Sopenharmony_ci      rspfile = soname + ".rsp"
93b1994897Sopenharmony_ci
94b1994897Sopenharmony_ci      os_specific_option = "-Wl,-soname=$soname"
95b1994897Sopenharmony_ci      rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}"
96b1994897Sopenharmony_ci
97b1994897Sopenharmony_ci      command = "$ld -shared {{ldflags}} ${extra_ldflags} -o $sofile $os_specific_option @$rspfile"
98b1994897Sopenharmony_ci
99b1994897Sopenharmony_ci      description = "SOLINK $soname"
100b1994897Sopenharmony_ci
101b1994897Sopenharmony_ci      # Use this for {{output_extension}} expansions unless a target manually
102b1994897Sopenharmony_ci      # overrides it (in which case {{output_extension}} will be what the target
103b1994897Sopenharmony_ci      # specifies).
104b1994897Sopenharmony_ci      default_output_extension = ".so"
105b1994897Sopenharmony_ci
106b1994897Sopenharmony_ci      # Use this for {{output_dir}} expansions unless a target manually overrides
107b1994897Sopenharmony_ci      # it (in which case {{output_dir}} will be what the target specifies).
108b1994897Sopenharmony_ci      default_output_dir = "{{root_out_dir}}"
109b1994897Sopenharmony_ci
110b1994897Sopenharmony_ci      outputs = [ sofile ]
111b1994897Sopenharmony_ci      link_output = sofile
112b1994897Sopenharmony_ci      depend_output = sofile
113b1994897Sopenharmony_ci      output_prefix = "lib"
114b1994897Sopenharmony_ci    }
115b1994897Sopenharmony_ci
116b1994897Sopenharmony_ci    tool("link") {
117b1994897Sopenharmony_ci      outfile = "{{target_output_name}}{{output_extension}}"
118b1994897Sopenharmony_ci      rspfile = "$outfile.rsp"
119b1994897Sopenharmony_ci      command = "$ld {{ldflags}} -o $outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group {{libs}}"
120b1994897Sopenharmony_ci      description = "LINK $outfile"
121b1994897Sopenharmony_ci      default_output_dir = "{{root_out_dir}}"
122b1994897Sopenharmony_ci      rspfile_content = "{{inputs}}"
123b1994897Sopenharmony_ci      outputs = [ outfile ]
124b1994897Sopenharmony_ci    }
125b1994897Sopenharmony_ci
126b1994897Sopenharmony_ci    tool("stamp") {
127b1994897Sopenharmony_ci      command = "touch {{output}}"
128b1994897Sopenharmony_ci      description = "STAMP {{output}}"
129b1994897Sopenharmony_ci    }
130b1994897Sopenharmony_ci
131b1994897Sopenharmony_ci    tool("copy") {
132b1994897Sopenharmony_ci      command = "cp -af {{source}} {{output}}"
133b1994897Sopenharmony_ci      description = "COPY {{source}} {{output}}"
134b1994897Sopenharmony_ci    }
135b1994897Sopenharmony_ci  }
136b1994897Sopenharmony_ci}
137b1994897Sopenharmony_ci
138b1994897Sopenharmony_cigcc_toolchain("clang-9") {
139b1994897Sopenharmony_ci  cc = "clang-9"
140b1994897Sopenharmony_ci  cxx = "clang++-9"
141b1994897Sopenharmony_ci  ar = "ar"
142b1994897Sopenharmony_ci  ld = cxx
143b1994897Sopenharmony_ci}
144