# Copyright (c) 2021-2023 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/ohos.gni")
import("./../../../adapter/uhdf2/uhdf.gni")

group("uhdf_hidl_pkg") {
  deps = [ ":libhdi" ]
}

hdf_framework_path = "./../../../framework"
hdf_interface_path = "./../../../interfaces"
hdf_uhdf_path = "./.."

config("libhdi_pub_config") {
  visibility = [ ":*" ]

  include_dirs = [
    "$hdf_interface_path/inner_api/hdi",
    "$hdf_interface_path/inner_api/hdi/base",
    "$hdf_interface_path/inner_api/core",
  ]
}
if (defined(ohos_lite)) {
  ohos_shared_library("libhdi") {
    output_extension = "z.so"

    defines = []
    if (target_cpu == "arm64" || target_cpu == "x86_64") {
      defines += [ "__ARCH64__" ]
    }

    include_dirs = [
      "$hdf_interface_path/inner_api/utils",
      "$hdf_interface_path/inner_api/osal/uhdf",
    ]
    public_configs = [ ":libhdi_pub_config" ]
    sources = [ "src/hdi_support.cpp" ]

    deps = [
      "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
      "//third_party/bounds_checking_function:libsec_shared",
    ]

    defines += [ "__USER__" ]

    # install_images = [ system_base_dir ]
    subsystem_name = "hdf"
    part_name = "hdf_core"
  }
} else {
  ohos_shared_library("libhdi") {
    branch_protector_ret = "pac_ret"
    if (target_cpu == "arm64" || target_cpu == "x86_64") {
      defines = [ "__ARCH64__" ]
    }

    include_dirs = [
      "$hdf_framework_path/core/shared/include",
      "$hdf_framework_path/core/host/include",
      "$hdf_framework_path/core/manager/include",
      "$hdf_framework_path/include/utils",
      "$hdf_framework_path/include/osal",
      "$hdf_framework_path/utils/include",
      "$hdf_framework_path/include/core",
      "$hdf_uhdf_path/include/devhost",
      "$hdf_uhdf_path/devhost/include",
      "$hdf_uhdf_path/devmgr/include",
      "$hdf_uhdf_path/host/include",
      "$hdf_uhdf_path/manager/include",
      "$hdf_uhdf_path/include/hdi",
      "$hdf_uhdf_path/ipc/include",
      "$hdf_interface_path/inner_api/ipc",
      "$hdf_interface_path/inner_api/utils",
      "$hdf_interface_path/inner_api/host/shared",
      "$hdf_interface_path/inner_api/host/uhdf",
    ]
    public_configs = [ ":libhdi_pub_config" ]
    sources = [
      "$hdf_framework_path/core/shared/src/service_status.c",
      "src/buffer_util.c",
      "src/devmgr_client.c",
      "src/hdi_smq_syncer.cpp",
      "src/hdi_support.cpp",
      "src/idevmgr_client.cpp",
      "src/iservmgr_client.cpp",
      "src/native_buffer.cpp",
      "src/object_collector.cpp",
      "src/servmgr_client.c",
      "src/servstat_listener.c",
      "src/servstat_listener_stub.cpp",
      "src/stub_collector.cpp",
    ]

    if (is_standard_system) {
      deps = [
        "../ipc:libhdf_ipc_adapter",
        "../pub_utils:libpub_utils",
      ]
      external_deps = [
        "c_utils:utils",
        "hilog:libhilog",
        "ipc:ipc_single",
        "samgr:samgr_proxy",
      ]
    } else {
      external_deps = [
        "hilog:libhilog",
        "ipc:ipc_single",
        "samgr:samgr_proxy",
      ]
    }

    innerapi_tags = [
      "chipsetsdk",
      "platformsdk_indirect",
    ]
    install_images = [
      system_base_dir,
      updater_base_dir,
    ]
    subsystem_name = "hdf"
    part_name = "hdf_core"
  }
}