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("//build/config/clang/clang.gni")
15import("//build/config/python.gni")
16import("//build/templates/common/copy.gni")
17
18template("js_declaration") {
19  group(target_name) {
20    not_needed(invoker, "*")
21  }
22}
23
24template("gen_js_obj") {
25  name = target_name
26  action("gen_js_obj_" + name) {
27    visibility = [ ":*" ]
28
29    objcopy_tool = "${clang_base_path}/bin/llvm-objcopy"
30    platform = "${current_os}_${current_cpu}"
31    if (platform == "mingw_x86_64") {
32      script = "//build/scripts/run_objcopy_pc_mac.py"
33    } else if (platform == "mac_x64") {
34      script = "//build/scripts/run_objcopy_pc_mac.py"
35    } else if (platform == "linux_x64") {
36      script = "//build/scripts/run_objcopy_pc_mac.py"
37    } else if (target_cpu == "x86_64") {
38      script = "//build/scripts/run_objcopy.py"
39    } else if (target_cpu == "arm" || target_cpu == "arm64" ||
40               target_cpu == "riscv64" || target_cpu == "loongarch64") {
41      script = "//build/scripts/run_objcopy.py"
42    }
43
44    args = [
45      "--objcopy",
46      rebase_path(objcopy_tool),
47      "--input",
48      rebase_path(invoker.input),
49      "--output",
50      rebase_path(invoker.output),
51      "--arch",
52      current_cpu,
53    ]
54
55    deps = []
56    if (defined(invoker.dep)) {
57      deps += [ invoker.dep ]
58    }
59
60    inputs = [ invoker.input ]
61    outputs = [ invoker.output ]
62  }
63
64  source_set(name) {
65    sources = [ invoker.output ]
66    deps = [ ":gen_js_obj_" + name ]
67  }
68}
69