# Copyright (C) 2017  Siemens AG
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

# Variables from bitbake/conf/bitbake.conf
B = "${S}"
CVSDIR = "${DL_DIR}/cvs"
DEPENDS = ""
DEPLOY_DIR = "${TMPDIR}/deploy"
FILE_DIRNAME = "${@os.path.dirname(d.getVar('FILE', False))}"
FILESEXTRAPATHS ?= "__default:"
GITDIR = "${DL_DIR}/git"
DEBDIR = "${DL_DIR}/deb"
DEBSRCDIR = "${DL_DIR}/deb-src"
P = "${PN}-${PV}"
PF = "${PN}-${PV}-${PR}"
PN = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE', False),d)[0] or 'defaultpkgname'}"
PV = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE', False),d)[1] or '1.0'}"
PR = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE', False),d)[2] or 'r0'}"
PROVIDES = ""
S = "${WORKDIR}/${P}"
AUTOREV = "${@bb.fetch2.get_autorev(d)}"
SRC_URI = "file://${FILE}"
STAMPS_DIR ?= "${TMPDIR}/stamps"
STAMP = "${STAMPS_DIR}/${DISTRO}-${DISTRO_ARCH}/${PN}/${PV}-${PR}"
STAMPCLEAN = "${STAMPS_DIR}/${DISTRO}-${DISTRO_ARCH}/${PN}/*-*"
SVNDIR = "${DL_DIR}/svn"
T = "${WORKDIR}/temp"
TMPDIR = "${TOPDIR}/tmp"
PERSISTENT_DIR = "${TMPDIR}/cache"
GITPKGV = "${@bb.fetch2.get_srcrev(d, 'gitpkgv_revision')}"

# isar specific config
WORKDIR = "${TMPDIR}/work/${DISTRO}-${DISTRO_ARCH}/${PN}/${PV}-${PR}"
GIT_DL_LINK_DIR = "${TMPDIR}/work/${DISTRO}-${DISTRO_ARCH}"
DEPLOY_DIR_BOOTSTRAP = "${DEPLOY_DIR}/bootstrap"
DEPLOY_DIR_BUILDCHROOT = "${DEPLOY_DIR}/buildchroot"
DEPLOY_DIR_SDKCHROOT = "${DEPLOY_DIR}/sdkchroot"
DEPLOY_DIR_IMAGE = "${DEPLOY_DIR}/images/${MACHINE}"
DL_DIR ?= "${TOPDIR}/downloads"
SSTATE_DIR ?= "${TOPDIR}/sstate-cache"
SSTATE_MANIFESTS = "${TMPDIR}/sstate-control/${DISTRO}-${DISTRO_ARCH}"
BUILDCHROOT_HOST_DIR = "${DEPLOY_DIR_BUILDCHROOT}-host/${HOST_DISTRO}-${HOST_ARCH}_${DISTRO}-${DISTRO_ARCH}"
BUILDCHROOT_TARGET_DIR = "${DEPLOY_DIR_BUILDCHROOT}-target/${DISTRO}-${DISTRO_ARCH}"
SDKCHROOT_DIR = "${DEPLOY_DIR_SDKCHROOT}/${DISTRO}-${DISTRO_ARCH}"
CACHE = "${TMPDIR}/cache"
KERNEL_FILE ?= "vmlinuz"
KERNEL_FILE_mipsel ?= "vmlinux"
KERNEL_FILE_riscv64 ?= "vmlinux"
KERNEL_FILE_arm64 ?= "vmlinux"

OVERRIDES = "${DISTRO_ARCH}:${COMPAT_OVERRIDE}:${MACHINE}:${DISTRO}:forcevariable"
FILESOVERRIDES = "${DISTRO_ARCH}:${MACHINE}"
COMPAT_OVERRIDE = "${@'compat-arch' if d.getVar('ISAR_ENABLE_COMPAT_ARCH') == '1' else ''}"

# Setting default QEMU_ARCH variables for different DISTRO_ARCH:
QEMU_ARCH_amd64 = "x86_64"
QEMU_ARCH_i386 = "i386"
QEMU_ARCH_armhf = "arm"
QEMU_ARCH_arm64 = "aarch64"
QEMU_ARCH_mipsel = "mipsel"
QEMU_ARCH_riscv64 = "riscv64"

# Codename of the repository created by the caching class
DEBDISTRONAME ?= "isar"

# Strings used in sstate signature files
TARGET_VENDOR = ""
TARGET_OS = "isar"
PACKAGE_ARCH ?= "${DISTRO_ARCH}"

# Isar apt repository paths
REPO_ISAR_DIR = "${DEPLOY_DIR}/isar-apt/${DISTRO}-${DISTRO_ARCH}/apt"
REPO_ISAR_DB_DIR = "${DEPLOY_DIR}/isar-apt/${DISTRO}-${DISTRO_ARCH}/db"
THIRD_PARTY_APT_KEYRING = "/etc/apt/trusted.gpg.d/third_party.gpg"

# Base apt repository paths
REPO_BASE_DIR = "${DEPLOY_DIR}/base-apt/${DISTRO}/apt"
REPO_BASE_DB_DIR = "${DEPLOY_DIR}/base-apt/${DISTRO}/db"

BB_HASHBASE_WHITELIST ?= "TMPDIR FILE PATH PWD BB_TASKHASH BBPATH BBSERVER DL_DIR \
    SSTATE_DIR THISDIR FILESEXTRAPATHS FILE_DIRNAME HOME LOGNAME SHELL TERM \
    USER FILESPATH STAGING_DIR_HOST STAGING_DIR_TARGET COREBASE PRSERV_HOST \
    PRSERV_DUMPDIR PRSERV_DUMPFILE PRSERV_LOCKDOWN PARALLEL_MAKE \
    CCACHE_DIR EXTERNAL_TOOLCHAIN CCACHE CCACHE_NOHASHDIR LICENSE_PATH SDKPKGSUFFIX \
    WORKDIR STAMPCLEAN PKGDATA_DIR BUILD_ARCH SSTATE_PKGARCH \
    BB_WORKERCONTEXT BB_LIMITEDDEPS DEPLOY_DIR"
BB_HASHCONFIG_WHITELIST ?= "${BB_HASHBASE_WHITELIST} DATE TIME SSH_AGENT_PID \
    SSH_AUTH_SOCK PSEUDO_BUILD BB_ENV_EXTRAWHITE DISABLE_SANITY_CHECKS \
    BB_NUMBER_THREADS BB_ORIGENV BB_INVALIDCONF BBINCLUDED \
    GIT_PROXY_COMMAND ALL_PROXY all_proxy NO_PROXY no_proxy FTP_PROXY ftp_proxy \
    HTTP_PROXY http_proxy HTTPS_PROXY https_proxy SOCKS5_USER SOCKS5_PASSWD \
    BB_SETSCENE_ENFORCE BB_CMDLINE BB_SERVER_TIMEOUT"
BB_SIGNATURE_HANDLER ?= "basichash"
BB_STAMP_POLICY ?= "full"

# Default to setting automatically based on cpu count
BB_NUMBER_THREADS ?= "${@bb.utils.cpu_count()}"

# Default to setting automatically based on cpu count
PARALLEL_MAKE ?= "-j ${@bb.utils.cpu_count()}"

BBINCLUDELOGS ??= "yes"

# Add event handlers for bitbake
INHERIT += "isar-events sstate"

# Buildstats requires IMAGE_ROOTFS to be always defined
IMAGE_ROOTFS ??= "${WORKDIR}/rootfs"
INHERIT += "${@'buildstats' if d.getVar('USE_BUILDSTATS') == '1' else ''}"

# Default values for ccache
USE_CCACHE ??= "0"
CCACHE_TOP_DIR ?= "${TMPDIR}/ccache"
CCACHE_DIR ?= "${CCACHE_TOP_DIR}/${DISTRO}-${DISTRO_ARCH}"

include conf/local.conf
include conf/multiconfig/${BB_CURRENT_MC}.conf
include conf/machine/${MACHINE}.conf
include conf/distro/${DISTRO}.conf

PATCHRESOLVE ?= "noop"
