• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2021 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("//gn/wasm.gni")
15declare_args() {
16  if (target_os == "linux" || target_os == "wasm" || target_os == "test") {
17    cc = "/usr/bin/clang"
18    cxx = "/usr/bin/clang++"
19  } else if (target_os == "windows") {
20    cc = "~/mingw-w64/ohos/linux-x86_64/clang-mingw/bin/clang"
21    cxx = "~/mingw-w64/ohos/linux-x86_64/clang-mingw/bin/clang++"
22  }
23  if (use_wasm == true) {
24    print("make_wasm")
25  } else if (use_wasm == false) {
26    print("no make_wasm")
27  }
28  cc_wrapper = ""
29  is_mac = false
30}
31toolchain("wasm") {
32  # emsdk_dir and em_config are defined in wasm.gni.
33  print("use gcc_like_chain wasm")
34  ar = "$emsdk_dir/emscripten/emar --em-config $em_config"
35  cc = "$emsdk_dir/emscripten/emcc --em-config $em_config"
36  cxx = "$emsdk_dir/emscripten/em++ --em-config $em_config"
37
38  lib_switch = "-l"
39  ld_arg = ""
40  lib_dir_switch = "-L"
41  external_cxxflags = ""
42  external_cflags = ""
43  external_ldflags = ""
44  if (defined(linker) && linker != "") {
45    ld_arg = "-fuse-ld=$_invoker_linker"
46    _invoker_linker = linker
47  }
48  if (defined(sysroot) && sysroot != "") {
49    _invoker_sysroot = sysroot
50    cxx = "$cxx --sysroot=$_invoker_sysroot"
51    cc = "$cc --sysroot=$_invoker_sysroot"
52  }
53  if (defined(gcc_toolchain) && gcc_toolchain != "") {
54    ld_arg = "$ld_arg --gcc-toolchain=$gcc_toolchain"
55  }
56  if (defined(external_cxxflags)) {
57    print("defined external_cxxflags")
58    external_cxxflags = external_cxxflags
59  }
60  if (defined(external_cflags)) {
61    external_cflags = external_cflags
62  }
63
64  tool("cc") {
65    depfiles = "{{output}}.d"
66    command = "$cc_wrapper $cc -MMD -MF $depfiles {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} ${external_cflags} -c {{source}} -o {{output}}"
67    outputfiles =
68        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o"
69    outputs = [ outputfiles ]
70    description = "step: compile {{source}}"
71  }
72
73  tool("cxx") {
74    depfiles = "{{output}}.d"  # must be defined
75    command = "$cc_wrapper $cxx -MMD -MF $depfiles {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}  ${external_cflags} ${external_cxxflags} -c {{source}} -o {{output}}"
76
77    outputfiles =
78        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o"
79    outputs = [ outputfiles ]
80    description = "step: compile {{source}}"
81  }
82  tool("alink") {
83    rspfile = "{{output}}.rsp"  # must be defined
84    rspfile_content = "{{inputs}}"
85    command = "rm -rf {{output}} && $ar rcsD {{output}} @$rspfile"
86    outputfiles = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
87    outputs = [ outputfiles ]
88    output_prefix = "lib"
89    default_output_extension = ".a"
90    description = "step: link {{output}}"
91  }
92  tool("solink") {
93    sonames = "{{target_output_name}}{{output_extension}}"
94    outputfiles = "{{root_out_dir}}/$sonames"
95    unstripped_so = outputfiles
96    rpath = ""
97    outputs = [ outputfiles ]
98    command = "$cc_wrapper $cxx $ld_arg -shared {{ldflags}} ${external_ldflags} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
99    output_prefix = "lib"
100    description = "step: link $unstripped_so"
101    default_output_extension = ".so"
102  }
103
104  tool("link") {
105    outputfiles = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
106    outputs = [ outputfiles ]
107    command = "$cc_wrapper $cxx $ld_arg {{ldflags}} ${external_ldflags} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
108    description = "step:link {{output}}"
109  }
110
111  tool("stamp") {
112    description = "step: stamp {{output}}"
113    command = "touch {{output}}"
114  }
115
116  tool("copy") {
117    description = "step: COPY files from {{source}} to {{output}}"
118    command = "cp -arf {{source}} {{output}}"
119  }
120}
121toolchain("gcc_like") {
122  lib_switch = "-l"
123  lib_dir_switch = "-L"
124
125  tool("cxx") {
126    depfile = "{{output}}.d"  # must be defined
127    command = "$cxx -o {{output}} -MMD -MF $depfile {{defines}} -fPIC {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}}"
128    outputfiles =
129        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o"
130    outputs = [ outputfiles ]
131    description = "step: compile {{source}}"
132  }
133
134  tool("cc") {
135    depfile = "{{output}}.d"
136    command = "$cc -o {{output}} -MMD -MF $depfile {{defines}} -fPIC {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}}"
137    outputfiles =
138        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o"
139    outputs = [ outputfiles ]
140    description = "step: compile {{source}}"
141  }
142  tool("alink") {
143    rspfile = "{{output}}.rsp"  # this must be defined
144    rspfile_content = "{{inputs}}"  # this must be defined
145    command = "rm -f {{output}} && $ar rcsD {{output}} @$rspfile"
146    outputsfiles = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
147    outputs = [ outputsfiles ]
148    default_output_extension = ".a"
149    output_prefix = "lib"
150    description = "step: link {{output}}"
151  }
152
153  tool("link") {
154    command = "$cxx -o {{output}} {{ldflags}} {{inputs}} {{solibs}} {{libs}}"
155    outputsfiles = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
156    outputs = [ outputsfiles ]
157    description = "step: link {{output}}"
158  }
159  tool("solink") {
160    default_output_extension = ".so"
161    command =
162        "$cxx -o {{output}} {{ldflags}} {{inputs}}  {{solibs}} {{libs}} -shared"
163    outputsfiles = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
164    outputs = [ outputsfiles ]
165    description = "step: solink {{output}}"
166  }
167
168  tool("stamp") {
169    print("need do nothing")
170    description = "step: touch {{output}}"
171    command = "touch {{output}}"
172  }
173
174  tool("copy") {
175    description = "COPY files from  {{source}} to {{output}}"
176    command = "cp -arf {{source}} {{output}}"
177  }
178}
179