# Copyright (c) 2024-2025 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build/config/components/ets_frontend/ets2abc_config.gni")
import("//build/ohos.gni")
if ((defined(ark_standalone_build) && ark_standalone_build) ||
    (defined(ark_static_standalone_build) && ark_static_standalone_build)) {
  import("//arkcompiler/runtime_core/static_core/ark_config.gni")
} else {
  import(
      "//build/config/components/runtime_core/static_core/ark_common_config.gni")
}

ohos_executable("dependency_analyzer") {
  sources = [
    "dep_analyzer.cpp",
    "main.cpp",
  ]

  include_dirs = [ "$target_gen_dir" ]
  if ((defined(ark_standalone_build) && ark_standalone_build) ||
      (defined(ark_static_standalone_build) && ark_static_standalone_build)) {
    configs = [ "$ark_root:ark_config" ]
  } else {
    configs = [
      "//build/config/components/runtime_core/static_core:ark_common_config",
    ]
  }
  configs += [ "$ark_es2panda_root:libes2panda_public_config" ]

  deps = [
    "$ark_es2panda_root:libes2panda_frontend_static",
    "$ark_es2panda_root:libes2panda_public_frontend_static",
  ]

  if (ark_standalone_build) {
    deps += [
      "$ark_root/bytecode_optimizer:libarktsbytecodeopt_package",
      "$ark_root/libarkbase:libarktsbase_package",
      "$ark_root/libarkfile:libarktsfile_package",
    ]
  }

  external_deps = [
    "runtime_core:assembler_headers",
    "runtime_core:libarktsassembler_package",
    "runtime_core:libarktsbase_package",
    "runtime_core:libarktsbytecodeopt_package",
    "runtime_core:libarktscompiler_package",
    "runtime_core:libarktsfile_package",
    "runtime_core:libpandabase_headers",
    "runtime_core:libpandafile_headers",
    sdk_libc_secshared_dep,
  ]

  use_exceptions = true
  libs = platform_libs
  ldflags = platform_ldflags
  if (is_linux) {
    libs += [ "stdc++fs" ]
  }

  install_enable = true
  part_name = "ets_frontend"
  subsystem_name = "arkcompiler"
}

ohos_copy("ohos_ets_dependency_analyzer") {
  if (is_mingw) {
    sources =
        [ "$root_out_dir/arkcompiler/ets_frontend/dependency_analyzer.exe" ]
  } else {
    sources = [ "$root_out_dir/arkcompiler/ets_frontend/dependency_analyzer" ]
  }
  if (is_linux || is_mac) {
    outputs = [ ohos_ets_dependency_analyzer_path ]
  } else {
    outputs = [ "$target_out_dir/$target_name/dependency_analyzer" ]
  }
  deps = [ ":dependency_analyzer" ]
  part_name = "ets_frontend"
  subsystem_name = "arkcompiler"
}