# Copyright (c) 2021 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/update/updater/updater_default_cfg.gni")
import("//build/ohos.gni")

updater_path = rebase_path("${updater_absolutely_path}", ".")
config("updater_config") {
  visibility = [ ":*" ]
  include_dirs = [
    "${updater_path}/interfaces/kits/include",
    "${updater_path}/services",
    "${updater_path}/services/common",
    "${updater_path}/services/flow_update",
    "${updater_path}/services/include/package",
    "${updater_path}/services/include/script",
    "${updater_path}/services/include/log",
    "${updater_path}/services/include",
    "${updater_path}/utils/include",
    "${updater_path}/utils/json",
    "${updater_path}/services/include/applypatch",
  ]
}

config("updater_binary_lc++") {
  ldflags = [ "-lc++" ]
}

updater_gen("updater_binary") {
  deps = [ "${updater_path}/services/updater_binary:libupdater_binary" ]
  configs = [ ":updater_binary_lc++" ]
  part_name = "updater"
  subsystem_name = "updater"
}

ohos_static_library("libupdater_binary") {
  sources = [
    "${updater_path}/services/updater_binary/main.cpp",
    "${updater_path}/services/updater_binary/update_image_block.cpp",
    "${updater_path}/services/updater_binary/update_image_patch.cpp",
    "${updater_path}/services/updater_binary/update_partitions.cpp",
    "${updater_path}/services/updater_binary/update_processor.cpp",
    "${updater_path}/services/updater_binary/update_processor_stream.cpp",
  ]
  public_configs = [ ":updater_config" ]

  ldflags = [ "-Wl -std=c++11" ]

  deps = [
    "${updater_path}/interfaces/kits/misc_info:libmiscinfo",
    "${updater_path}/services/applypatch:libapplypatch",
    "${updater_path}/services/diffpatch/patch:libpatch",
    "${updater_path}/services/flow_update/update_bin:libBinFlowUpdate",
    "${updater_path}/services/fs_manager:libfsmanager",
    "${updater_path}/services/log:libupdaterlog",
    "${updater_path}/services/package:libupdaterpackage",
    "${updater_path}/services/script:libupdaterscript",
    "${updater_path}/services/stream_update:libbinchunkupdate",
    "${updater_path}/utils:libutils",
  ]

  defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ]

  if (defined(use_ptable)) {
    include_dirs = [ "${updater_path}/services/ptable_parse" ]
    deps += [ "${updater_path}/services/ptable_parse:libptableparse" ]
    defines += [ "UPDATER_USE_PTABLE" ]
  }

  external_deps = [
    "bounds_checking_function:libsec_static",
    "bzip2:libbz2",
    "cJSON:cjson_static",
    "init:libbegetutil_static",
    "init:libfsmanager_static_real",
    "lz4:liblz4_static",
    "openssl:libcrypto_static",
    "openssl:libssl_static",
    "zlib:libz",
  ]

  part_name = "updater"
  subsystem_name = "updater"
}