# 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("//base/print/print_fwk/print.gni")
import("//build/config/components/idl_tool/idl.gni")
import("//build/ohos.gni")

cflags_cc = []

idl_interface_sources = [
  "${target_gen_dir}/sane_backends_proxy.cpp",
  "${target_gen_dir}/sane_backends_stub.cpp",
]

idl_gen_interface("sane_backends_interface") {
  src_idl = rebase_path("ISaneBackends.idl")
  dst_file = string_join(",", idl_interface_sources)
  log_domainid = "0xD001C00"
  log_tag = "scankit"
}

config("sane_config") {
  include_dirs = [
    "include",
    "${target_gen_dir}",
    "${print_utils_path}/include",
  ]
  cflags_cc += [
    "-fno-exceptions",
    "-fdata-sections",
    "-ffunction-sections",
    "-fno-asynchronous-unwind-tables",
    "-fno-unwind-tables",
    "-Os",
  ]
  if (target_cpu == "arm") {
    cflags = [ "-DBINDER_IPC_32BIT" ]
  }
}

ohos_shared_library("sane_backends") {
  public_configs = [ ":sane_config" ]
  branch_protector_ret = "pac_ret"
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    debug = false
  }
  output_values = get_target_outputs(":sane_backends_interface")
  sources = [
    "src/sane_control_param.cpp",
    "src/sane_device.cpp",
    "src/sane_option_descriptor.cpp",
    "src/sane_out_param.cpp",
    "src/sane_parameters.cpp",
    "src/sane_picture_data.cpp",
  ]
  sources += filter_include(output_values, [ "*.cpp" ])
  defines = [ "AMS_LOG_TAG = \"scankit\"" ]
  deps = [ ":sane_backends_interface" ]
  external_deps = [
    "ability_base:want",
    "bundle_framework:appexecfwk_base",
    "bundle_framework:appexecfwk_core",
    "c_utils:utils",
    "hilog:libhilog",
    "ipc:ipc_single",
    "jsoncpp:jsoncpp",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]
  innerapi_tags = [ "platformsdk" ]
  subsystem_name = "print"
  part_name = "print_fwk"
}