# Copyright (c) 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")
import("//build/ohos/taihe_idl/taihe.gni")

copy_taihe_idl("copy_systemCapability") {
  sources = [ "idl/ohos.systemCapability.taihe" ] 
}
subsystem_name = "developtools"
part_name = "syscap_codec"
taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name"

ohos_taihe("run_taihe") {
  taihe_generated_file_path = "$taihe_generated_file_path"
  deps = [ ":copy_systemCapability" ]
  outputs = [
    "$taihe_generated_file_path/src/ohos.systemCapability.ani.cpp",
    "$taihe_generated_file_path/src/ohos.systemCapability.abi.c",
  ]
}

taihe_shared_library("systemCapability_taihe_native") {
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    debug = false
  }
  taihe_generated_file_path = "$taihe_generated_file_path"
  part_name = "$part_name"
  subsystem_name = "$subsystem_name"
  sources = get_target_outputs(":run_taihe")
  include_dirs = [
    "../../src",
    "../../interfaces/inner_api",
    "../../include",
    "../../include/codec_config"
  ]
  sources += [
    "src/ani_constructor.cpp",
    "src/ohos.systemCapability.impl.cpp",
    "../../src/syscap_tool.c",
    "../../src/create_pcid.c",
    "../../src/endian_internal.c",
    "../../src/common_method.c",
    "../../src/context_tool.c",
    "../../interfaces/inner_api/syscap_interface.c",
  ]
  deps = [
    ":run_taihe",
  ]
  external_deps = [
    "bounds_checking_function:libsec_shared",
  ]
  if (defined(ohos_lite)) {
    deps += [ "//build/lite/config/component/cJSON:cjson_static" ]
  } else {
    external_deps += [ "cJSON:cjson_static" ]
  }
}

generate_static_abc("systemCapability") {
  base_url = "$taihe_generated_file_path"
  files = [ "$taihe_generated_file_path/@ohos.systemCapability.ets" ]
  is_boot_abc = "True"
  device_dst_file = "/system/framework/systemCapability.abc"
  dependencies = [ ":run_taihe" ]
}

ohos_prebuilt_etc("systemCapability_etc") {
  source = "$target_out_dir/systemCapability.abc"           
  module_install_dir = "framework"
  part_name = "$part_name"
  subsystem_name = "$subsystem_name"
  deps = [ ":systemCapability" ]
}