• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
14import("//build/lite/config/toolchain/config.gni")
15
16template("iccarm_toolchain") {
17  toolchain(target_name) {
18    assert(defined(invoker.ar), "gcc_toolchain() must specify a \"ar\" value")
19    assert(defined(invoker.cc), "gcc_toolchain() must specify a \"cc\" value")
20    assert(defined(invoker.cxx), "gcc_toolchain() must specify a \"cxx\" value")
21    assert(defined(invoker.ld), "gcc_toolchain() must specify a \"ld\" value")
22
23    cc = invoker.cc
24    cxx = invoker.cxx
25    as = invoker.as
26    ar = invoker.ar
27    ld = invoker.ld
28
29    need_strip = false
30    if (defined(invoker.strip)) {
31      strip = invoker.strip
32      need_strip = true
33    }
34
35    if (defined(invoker.extra_ldflags) && invoker.extra_ldflags != "") {
36      extra_ldflags = " " + invoker.extra_ldflags
37    } else {
38      extra_ldflags = ""
39    }
40
41    tool("cc") {
42      command = "$cc {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
43      if (enable_save_temps) {
44        preprocess_outfile = "{{output}}.i"
45        list_outfile = "{{output}}.lst"
46        asm_outfile = "{{output}}.s"
47        command += " --preprocess $preprocess_outfile -lCN $list_outfile -lA $asm_outfile"
48      }
49      description = "iccarm CC {{output}}"
50      outputs =
51          [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ]
52    }
53    tool("cxx") {
54      depfile = "{{output}}.d"
55      command = "$cxx {{defines}} {{include_dirs}} {{cflags_cc}} -c {{source}} -o {{output}}"
56      if (enable_save_temps) {
57        preprocess_outfile = "{{output}}.i"
58        list_outfile = "{{output}}.lst"
59        asm_outfile = "{{output}}.s"
60        command += " --preprocess $preprocess_outfile -lCN $list_outfile -lA $asm_outfile"
61      }
62      description = "iccarm CXX {{output}}"
63      outputs =
64          [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ]
65    }
66    tool("asm") {
67      depfile = "{{output}}.d"
68      command = "$as {{defines}} {{include_dirs}} {{asmflags}} {{source}} -o {{output}}"
69      description = "iccarm ASM {{output}}"
70      outputs =
71          [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ]
72    }
73    tool("alink") {
74      outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
75      rspfile = "{{output}}.rsp"
76      rspfile_content = "{{inputs}}"
77      command = "rm -f {{output}} && $ar {{inputs}} -o {{output}}"
78
79      description = "iccarm AR {{output}}"
80      outputs = [ outfile ]
81
82      default_output_dir = "{{root_out_dir}}/libs"
83      default_output_extension = ".a"
84      output_prefix = "lib"
85    }
86    tool("solink") {
87      outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
88      unstripped_outfile = outfile
89
90      rspfile = "$outfile.rsp"
91      rspfile_content = "{{inputs}}"
92      command = ""
93      if (need_strip) {
94        unstripped_outfile = "{{output_dir}}/unstripped/usr/lib/{{target_output_name}}{{output_extension}}"
95      }
96      command += "$ld -shared {{ldflags}} $extra_ldflags " + "-Wl, --start-group {{inputs}} {{libs}} -Wl, --end-group -o $unstripped_outfile"
97      if (need_strip) {
98        command += " && $strip \"$unstripped_outfile\" \"$outfile\""
99      }
100      description = "iccarm SOLINK $outfile"
101      outputs = [ outfile ]
102      if (unstripped_outfile != outfile) {
103        outputs += [ unstripped_outfile ]
104      }
105      default_output_dir = "{{root_out_dir}}"
106      default_output_extension = ".so"
107      output_prefix = "lib"
108    }
109    tool("link") {
110      outfile = "{{output_dir}}/bin/{{target_output_name}}{{output_extension}}"
111      unstripped_outfile = outfile
112
113      rspfile = "$outfile.rsp"
114      command = ""
115      if (need_strip) {
116        unstripped_outfile = "{{output_dir}}/unstripped/bin/{{target_output_name}}{{output_extension}}"
117      }
118
119      if (enable_iccarm_link_helper) {
120        link_helper =
121            rebase_path("//build/lite/toolchain/iccarm_link_helper.sh")
122        command += "$ld {{ldflags}} $extra_ldflags \$($link_helper {{inputs}} {{libs}}) -o $unstripped_outfile"
123      } else {
124        command += "$ld {{ldflags}} $extra_ldflags " +
125                   "{{inputs}} {{libs}} -o $unstripped_outfile"
126      }
127      if (need_strip) {
128        command += " && $strip \"$unstripped_outfile\" \"$outfile\""
129      }
130
131      description = "iccarm LINK $outfile"
132      default_output_dir = "{{root_out_dir}}"
133      rspfile_content = "{{inputs}}"
134      outputs = [ outfile ]
135      if (unstripped_outfile != outfile) {
136        outputs += [ unstripped_outfile ]
137      }
138    }
139    tool("stamp") {
140      if (host_os == "win") {
141        command = "cmd /c type nul > \"{{output}}\""
142      } else {
143        command = "/usr/bin/touch {{output}}"
144      }
145      description = "STAMP {{output}}"
146    }
147    tool("copy") {
148      if (host_os == "win") {
149        command = "python $ohos_root_path/build/lite/copy_files.py --src_type=file --src={{source}} --dest_dir={{output}}"
150      } else if (host_os == "linux") {
151        command = "cp -afd {{source}} {{output}}"
152      }
153      description = "COPY {{source}} {{output}}"
154    }
155  }
156}
157