# Copyright (C) 2021-2022 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/es2abc_config.gni")
import("//build/ohos.gni")
import("//build/ohos/ace/ace.gni")
import("//build/templates/abc/ohos_abc.gni")
import("../../callmanager.gni")

SUBSYSTEM_DIR = "../../.."
config("call_manager_js_config") {
  include_dirs = [ "napi/include" ]
}

jspath = "napi/src/call.js"

# compile .js to .abc.
es2abc_gen_abc("gen_call_abc") {
  src_js = rebase_path(jspath)
  dst_file = rebase_path(target_out_dir + "/call.abc")
  in_puts = [ jspath ]
  out_puts = [ target_out_dir + "/call.abc" ]
  extra_args = [ "--module" ]
}

base_output_path = get_label_info(":call_js", "target_out_dir")
call_obj_path = base_output_path + "/call.o"
gen_js_obj("call_js") {
  input = jspath
  output = call_obj_path
  dep = ":gen_call_abc"
}

abc_output_path = get_label_info(":call_abc", "target_out_dir")
call_abc_obj_path = abc_output_path + "/call_abc.o"
gen_js_obj("call_abc") {
  input = "$target_out_dir/call.abc"
  output = call_abc_obj_path
  dep = ":gen_call_abc"
}

ohos_shared_library("call") {
  sanitize = {
    cfi = true
    cfi_cross_dso = true
    cfi_no_nvcall = true
    debug = false
  }
  branch_protector_ret = "pac_ret"
  sources = [
    "napi/src/napi_call_ability_callback.cpp",
    "napi/src/napi_call_manager.cpp",
    "napi/src/napi_call_manager_callback.cpp",
    "napi/src/napi_call_manager_utils.cpp",
    "napi/src/native_module.cpp",
  ]

  public_configs = [ ":call_manager_js_config" ]

  deps = [
    ":call_abc",
    ":call_js",
    "$SUBSYSTEM_DIR/call_manager/frameworks/native:tel_call_manager_api",
  ]

  external_deps = [
    "ability_base:base",
    "ability_base:want",
    "ability_runtime:ability_manager",
    "ability_runtime:napi_common",
    "c_utils:utils",
    "core_service:libtel_common",
    "core_service:tel_core_service_api",
    "hilog:libhilog",
    "image_framework:image",
    "image_framework:image_native",
    "init:libbegetutil",
    "ipc:ipc_single",
    "libuv:uv",
    "ffrt:libffrt",
    "napi:ace_napi",
  ]

  cflags_cc = [
    "-Wunused",
    "-Wunreachable-code",
    "-fno-exceptions",
    "-fno-rtti",
    "-fstack-protector-all",
    "-Os",
    "-flto",
    "-Wno-unused-but-set-variable",
    "-fdata-sections",
    "-ffunction-sections",
    "-fno-asynchronous-unwind-tables",
    "-fno-unwind-tables",
  ]

  ldflags = [
    "-flto",
    "-Wl,--gc-sections",
  ]

  defines = [
    "TELEPHONY_LOG_TAG = \"CallManagerJsApi\"",
    "LOG_DOMAIN = 0xD001F10",
  ]

  defines += call_manager_defines
  
  part_name = "call_manager"
  subsystem_name = "telephony"
  relative_install_dir = "module/telephony"
}