# 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")

HAL_ROOT_DIR = "./.."

if (defined(ohos_lite)) {
  ohos_shared_library("wifi_hal") {
    sources = [
      "src/wifi_hal.c",
      "src/wifi_hal_ap_feature.c",
      "src/wifi_hal_base_feature.c",
      "src/wifi_hal_cmd.c",
      "src/wifi_hal_sta_feature.c",
      "src/wifi_hal_util.c",
    ]

    include_dirs = [
      "include",
      "$HAL_ROOT_DIR/interfaces/include",
      "$HAL_ROOT_DIR/client/include",
    ]

    external_deps = [
      "hdf_core:hdf_posix_osal",
      "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"
  }
} else {
  ohos_shared_library("wifi_hal") {
    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
    }
    sources = [
      "src/wifi_hal.c",
      "src/wifi_hal_ap_feature.c",
      "src/wifi_hal_base_feature.c",
      "src/wifi_hal_cmd.c",
      "src/wifi_hal_p2p_feature.c",
      "src/wifi_hal_sta_feature.c",
      "src/wifi_hal_util.c",
    ]
    include_dirs = [
      "include",
      "$HAL_ROOT_DIR/interfaces/include",
      "$HAL_ROOT_DIR/client/include",
    ]
    deps = [ "$HAL_ROOT_DIR/client:wifi_driver_client" ]
    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",
    ]
    install_images = [ chipset_base_dir ]
    subsystem_name = "hdf"
    part_name = "drivers_peripheral_wlan"
    if (is_standard_system) {
      external_deps = [
        "c_utils:utils",
        "hdf_core:libhdf_utils",
        "hilog:libhilog",
      ]
    } else {
      external_deps = [ "hilog:libhilog" ]
    }
  }
}