15bebb993Sopenharmony_ci# Copyright (c) 2024 Huawei Device Co., Ltd.
25bebb993Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
35bebb993Sopenharmony_ci# you may not use this file except in compliance with the License.
45bebb993Sopenharmony_ci# You may obtain a copy of the License at
55bebb993Sopenharmony_ci#
65bebb993Sopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
75bebb993Sopenharmony_ci#
85bebb993Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
95bebb993Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
105bebb993Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
115bebb993Sopenharmony_ci# See the License for the specific language governing permissions and
125bebb993Sopenharmony_ci# limitations under the License.
135bebb993Sopenharmony_ci
145bebb993Sopenharmony_ciimport("//build/config/clang/clang.gni")
155bebb993Sopenharmony_ciimport("//build/ohos.gni")
165bebb993Sopenharmony_ci
175bebb993Sopenharmony_ciace_root = "//foundation/arkui/ace_engine"
185bebb993Sopenharmony_ciis_ohos_standard_system = is_standard_system && !is_arkui_x
195bebb993Sopenharmony_ciuse_mingw_win = "${current_os}_${current_cpu}" == "mingw_x86_64"
205bebb993Sopenharmony_ciuse_mac = "${current_os}_${current_cpu}" == "mac_x64" ||
215bebb993Sopenharmony_ci          "${current_os}_${current_cpu}" == "mac_arm64"
225bebb993Sopenharmony_ciuse_ios = "${current_os}_${current_cpu}" == "ios_x64" ||
235bebb993Sopenharmony_ci          "${current_os}_${current_cpu}" == "ios_arm64"
245bebb993Sopenharmony_ciuse_linux = "${current_os}_${current_cpu}" == "linux_x64"
255bebb993Sopenharmony_ciwindows_buildtool = "//build/toolchain/mingw:mingw_x86_64"
265bebb993Sopenharmony_ci
275bebb993Sopenharmony_ciif (!defined(default_phone_source_dir)) {
285bebb993Sopenharmony_ci  default_phone_source_dir = "/"
295bebb993Sopenharmony_ci}
305bebb993Sopenharmony_ciobjcopy_default = "${default_phone_source_dir}/prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8/x86_64-w64-mingw32/bin/objcopy"
315bebb993Sopenharmony_ciobjcopy_mingw = "${default_phone_source_dir}/prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8/x86_64-w64-mingw32/bin/objcopy"
325bebb993Sopenharmony_ciobjcopy_x86_64 = "${default_clang_base_path}/bin/llvm-objcopy"
335bebb993Sopenharmony_ciif ("${current_os}_${current_cpu}" == "mac_arm64") {
345bebb993Sopenharmony_ci  mac_buildtool = "//build/toolchain/mac:clang_arm64"
355bebb993Sopenharmony_ci} else if ("${current_os}_${current_cpu}" == "mac_x64") {
365bebb993Sopenharmony_ci  mac_buildtool = "//build/toolchain/mac:clang_x64"
375bebb993Sopenharmony_ci}
385bebb993Sopenharmony_ciobjcopy_clang = "$clang_base_path/bin/llvm-objcopy"
395bebb993Sopenharmony_ciif (is_ohos_standard_system) {
405bebb993Sopenharmony_ci  objcopy_default = "//prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-objcopy"
415bebb993Sopenharmony_ci} else if (is_arkui_x) {
425bebb993Sopenharmony_ci  if (host_os == "mac") {
435bebb993Sopenharmony_ci    objcopy_default = objcopy_clang
445bebb993Sopenharmony_ci  } else if (defined(phone_objcopy)) {
455bebb993Sopenharmony_ci    objcopy_default = phone_objcopy
465bebb993Sopenharmony_ci  }
475bebb993Sopenharmony_ci}
485bebb993Sopenharmony_ci
495bebb993Sopenharmony_citemplate("gen_obj") {
505bebb993Sopenharmony_ci  name = target_name
515bebb993Sopenharmony_ci  action("gen_obj_" + name) {
525bebb993Sopenharmony_ci    visibility = [ ":*" ]  # Only targets in this file can depend on this.
535bebb993Sopenharmony_ci
545bebb993Sopenharmony_ci    if (use_mingw_win) {
555bebb993Sopenharmony_ci      objcopy_tool = objcopy_mingw
565bebb993Sopenharmony_ci      script = "$ace_root/build/tools/build_resource_to_bytecode.py"
575bebb993Sopenharmony_ci    } else if (use_mac || target_os == "ios") {
585bebb993Sopenharmony_ci      objcopy_tool = objcopy_clang
595bebb993Sopenharmony_ci      script = "$ace_root/build/tools/build_resource_to_bytecode.py"
605bebb993Sopenharmony_ci    } else if (use_linux) {
615bebb993Sopenharmony_ci      objcopy_tool = objcopy_x86_64
625bebb993Sopenharmony_ci      script = "$ace_root/build/tools/build_resource_to_bytecode.py"
635bebb993Sopenharmony_ci    } else if (target_cpu == "x86_64") {
645bebb993Sopenharmony_ci      objcopy_tool = objcopy_x86_64
655bebb993Sopenharmony_ci      script = "$ace_root/build/tools/run_objcopy.py"
665bebb993Sopenharmony_ci    } else {
675bebb993Sopenharmony_ci      objcopy_tool = objcopy_default
685bebb993Sopenharmony_ci      script = "$ace_root/build/tools/run_objcopy.py"
695bebb993Sopenharmony_ci    }
705bebb993Sopenharmony_ci
715bebb993Sopenharmony_ci    args = [
725bebb993Sopenharmony_ci      "--objcopy",
735bebb993Sopenharmony_ci      rebase_path(objcopy_tool),
745bebb993Sopenharmony_ci      "--input",
755bebb993Sopenharmony_ci      rebase_path(invoker.input),
765bebb993Sopenharmony_ci      "--output",
775bebb993Sopenharmony_ci      rebase_path(invoker.output),
785bebb993Sopenharmony_ci      "--arch",
795bebb993Sopenharmony_ci      current_cpu,
805bebb993Sopenharmony_ci    ]
815bebb993Sopenharmony_ci
825bebb993Sopenharmony_ci    deps = []
835bebb993Sopenharmony_ci    deps += invoker.snapshot_dep
845bebb993Sopenharmony_ci
855bebb993Sopenharmony_ci    inputs = [ invoker.input ]
865bebb993Sopenharmony_ci    outputs = [ invoker.output ]
875bebb993Sopenharmony_ci  }
885bebb993Sopenharmony_ci
895bebb993Sopenharmony_ci  source_set("gen_obj_src_" + name) {
905bebb993Sopenharmony_ci    sources = [ invoker.output ]
915bebb993Sopenharmony_ci    deps = [ ":gen_obj_" + name ]
925bebb993Sopenharmony_ci  }
935bebb993Sopenharmony_ci}
94