# 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("../wlan.gni")

config("wifi_driver_hdi_client_public_config") {
  include_dirs = [ "include" ]
}

if (defined(ohos_lite)) {
  ohos_shared_library("wifi_driver_client") {
    output_extension = "z.so"
    sources = [ "src/wifi_driver_client.c" ]
    sources += [
      "src/sbuf/sbuf_cmd_adapter.c",
      "src/sbuf/sbuf_common_adapter.c",
      "src/sbuf/sbuf_event_adapter.c",
      "src/sbuf/sbuf_wpa_cmd_adapter.c",
    ]

    include_dirs = [ "include" ]

    external_deps = [
      "hdf_core:libhdf_utils",
      "hilog_lite:hilog_shared",
      "bounds_checking_function:libsec_shared"
    ]

    defines = [ "__USER__" ]

    cflags = [
      "-Wall",
      "-Wextra",
      "-Werror",
      "-fsigned-char",
      "-fno-common",
      "-fno-strict-aliasing",
      "-Wno-format",
      "-Wno-format-extra-args",
    ]

    subsystem_name = "hdf"
    part_name = "drivers_peripheral_wlan"
    install_images = [ "system" ]
  }
} else {
  CLIENT_ROOT_DIR = "./.."
  sources = [
    "src/sbuf/sbuf_common_adapter.c",
    "src/sbuf/sbuf_wpa_cmd_adapter.c",
    "src/wifi_driver_client.c",
  ]
  ohos_shared_library("wifi_driver_client") {
    branch_protector_ret = "pac_ret"
    sanitize = {
      cfi = true  # Enable/disable control flow integrity detection
      boundary_sanitize = false  # Enable boundary san detection
      cfi_cross_dso = true  # Cross-SO CFI Checks
      integer_overflow = false  # Enable integer overflow detection
      ubsan = false  # Enable some Ubsan options
      cfi_vcall_icall_only = true
      debug = false
    }
    if (drivers_peripheral_wlan_feature_enable_HDF_NL80211) {
      sources += [
        "src/sbuf/sbuf_cmd_adapter.c",
        "src/sbuf/sbuf_event_adapter.c",
      ]

      include_dirs = [
        "include",
        "$CLIENT_ROOT_DIR/interfaces/include",
      ]
      public_configs = [ ":wifi_driver_hdi_client_public_config" ]

      external_deps = [
        "c_utils:utils",
        "hdf_core:libhdf_utils",
        "hilog:libhilog",
      ]
      defines = [ "__OHOS__USER__" ]

      cflags = [
        "-Wall",
        "-Wextra",
        "-Werror",
        "-fsigned-char",
        "-fno-common",
        "-fno-strict-aliasing",
      ]
      cflags += [
        "-fdata-sections",
        "-ffunction-sections",
        "-Os",
        "-fno-merge-all-constants",
      ]
      ldflags = [
        "-Wl,--exclude-libs=ALL",
        "-Wl,--gc-sections",
      ]
      version_script = "wifi_driver_client.map"
      install_images = [ chipset_base_dir ]
      subsystem_name = "hdf"
      part_name = "drivers_peripheral_wlan"
    } else {
      sources += [
        "src/netlink/netlink_cmd_adapter.c",
        "src/netlink/netlink_event_adapter.c",
        "src/sbuf/sbuf_event_adapter.c",
      ]

      include_dirs = [
        "include",
        "$CLIENT_ROOT_DIR/interfaces/include",
        "$root_out_dir/include",
        "$root_out_dir/lib",
      ]

      public_configs = [ ":wifi_driver_hdi_client_public_config" ]
      external_deps = [
        "c_utils:utils",
        "hdf_core:libhdf_host",
        "hdf_core:libhdf_utils",
        "hilog:libhilog",
        "init:libbegetutil",
        "libnl:libnl_share",
      ]

      defines = [ "__OHOS__USER__" ]

      cflags = [
        "-Wall",
        "-Wextra",
        "-Werror",
        "-fsigned-char",
        "-fno-common",
        "-fno-strict-aliasing",
      ]
      cflags += [
        "-fdata-sections",
        "-ffunction-sections",
        "-Os",
        "-fno-merge-all-constants",
      ]
      ldflags = [
        "-Wl,--exclude-libs=ALL",
        "-Wl,--gc-sections",
      ]
      version_script = "wifi_driver_client.map"
      install_images = [ chipset_base_dir ]
      subsystem_name = "hdf"
      part_name = "drivers_peripheral_wlan"
    }
  }
}