# Copyright (c) 2020 Project CHIP Authors
#
# 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.

declare_args() {
  # Debug build. Set this to false to remove development features.
  is_debug = true
}

if (target_os == "") {
  target_os = host_os
}

if (target_cpu == "") {
  target_cpu = host_cpu
}

if (current_cpu == "") {
  current_cpu = target_cpu
}
if (current_os == "") {
  current_os = target_os
}

_chip_overrides = {
  import("//build_overrides/chip.gni")
}

_pigweed_overrides = {
  import("//build_overrides/pigweed.gni")
}

_chip_defaults = {
  import("//build/config/defaults.gni")
}

declare_args() {
  # Toolchain to use for host. This is usually set by default.
  host_toolchain = ""
}

if (host_toolchain == "") {
  if (_chip_defaults.is_clang) {
    host_toolchain = "//build/toolchain/host:${host_os}_${host_cpu}_clang"
  } else {
    host_toolchain = "//build/toolchain/host:${host_os}_${host_cpu}_gcc"
  }
}

if (_chip_defaults.custom_toolchain != "") {
  _default_toolchain = _chip_defaults.custom_toolchain
} else if (target_os == host_os) {
  _default_toolchain = host_toolchain
} else if (target_os == "all") {
  _default_toolchain = "${_pigweed_overrides.dir_pw_toolchain}/dummy"
} else if (target_os == "freertos") {
  if (target_cpu == "arm") {
    _default_toolchain = "//build/toolchain/arm_gcc"
  } else {
    assert(false, "Unsupported target_cpu: ${target_cpu}")
  }
} else if (target_os == "android") {
  if (current_cpu == "arm") {
    _default_toolchain = "//build/toolchain/android:android_arm"
  } else if (current_cpu == "arm64") {
    _default_toolchain = "//build/toolchain/android:android_arm64"
  } else if (current_cpu == "x64") {
    _default_toolchain = "//build/toolchain/android:android_x64"
  } else if (current_cpu == "x86") {
    _default_toolchain = "//build/toolchain/android:android_x86"
  } else {
    assert(false, "Unsupported target_cpu: ${current_cpu}")
  }
} else if (target_os == "ios") {
  _default_toolchain = "//build/toolchain/ios:ios_${target_cpu}"
} else {
  assert(false, "No toolchain specified, please specify custom_toolchain")
}

set_default_toolchain(_default_toolchain)

set_defaults("static_library") {
  configs = _chip_defaults.default_configs
}
set_defaults("source_set") {
  configs = _chip_defaults.default_configs
}
set_defaults("executable") {
  configs =
      _chip_defaults.default_configs + _chip_defaults.executable_default_configs
}
set_defaults("shared_library") {
  configs = _chip_defaults.default_configs
}
set_defaults("loadable_module") {
  configs = _chip_defaults.default_configs
}
