##################################################################
# Standard target filesystem paths.
##################################################################
#
# If changing these values, beware that native/cross/nativesdk bbclass 
# files may also need changes to keep in sync.
#

# Used by multilib code to change the library paths
baselib = "${BASELIB}"
baselib[vardepvalue] = "${baselib}"
BASELIB = "lib"
BASELIB_powerpc64 = "lib64"

# Path prefixes
export base_prefix = ""
export prefix = "/usr"
export exec_prefix = "/usr"

# Base paths
export base_bindir = "${base_prefix}/bin"
export base_sbindir = "${base_prefix}/sbin"
export base_libdir = "${base_prefix}/${baselib}"
export nonarch_base_libdir = "${base_prefix}/lib"

# Architecture independent paths
export datadir = "${prefix}/share"
export sysconfdir = "${base_prefix}/etc"
export servicedir = "${base_prefix}/srv"
export sharedstatedir = "${base_prefix}/com"
export localstatedir = "${base_prefix}/var"
export infodir = "${datadir}/info"
export mandir = "${datadir}/man"
export docdir = "${datadir}/doc"
export systemd_unitdir = "/lib/systemd"

# Architecture dependent paths
export bindir = "${exec_prefix}/bin"
export sbindir = "${exec_prefix}/sbin"
export libdir = "${exec_prefix}/${baselib}"
export libexecdir = "${libdir}/${BPN}"
export includedir = "${exec_prefix}/include"
export oldincludedir = "${exec_prefix}/include"
localedir = "${libdir}/locale"

# Linkage between native/cross/nativesdk layouts
base_bindir_native = "/bin"
base_sbindir_native = "/sbin"
sysconfdir_native = "/etc"
prefix_native = "/usr"
bindir_native = "${prefix_native}/bin"
sbindir_native = "${prefix_native}/sbin"
includedir_native = "${prefix_native}/include"
libdir_native = "${prefix_native}/lib"
libexecdir_native = "${libdir_native}/${BPN}"
base_libdir_native = "/lib"
datadir_native = "${prefix_native}/share"
bindir_cross = "/bin"
bindir_crossscripts = "${bindir}/crossscripts"
prefix_nativesdk = "/usr"
bindir_nativesdk = "${prefix_nativesdk}/bin"
includedir_nativesdk = "${prefix_nativesdk}/include"
libdir_nativesdk = "${prefix_nativesdk}/lib"
base_libdir_nativesdk = "/lib"
localstatedir_nativesdk = "/var"

#
# Cross recipes need to know about the target layout
# := is used carefully here
#
target_datadir := "${datadir}"
# Used to find env/perl/python
USRBINPATH = "${bindir}"
USRBINPATH_class-native = "/usr/bin"
USRBINPATH_class-nativesdk = "/usr/bin"

# Root home directory
ROOT_HOME ??= "/home/root"

##################################################################
# Architecture-dependent build variables.
##################################################################

BUILD_ARCH = "${@os.uname()[4]}"
BUILD_OS = "${@os.uname()[0].lower()}"
BUILD_VENDOR = ""
BUILD_SYS = "${BUILD_ARCH}${BUILD_VENDOR}-${BUILD_OS}"
BUILD_PREFIX = ""
BUILD_CC_ARCH = ""
BUILD_LD_ARCH = ""
BUILD_AS_ARCH = ""
BUILD_EXEEXT = ""

HOST_ARCH = "${TARGET_ARCH}"
HOST_OS = "${TARGET_OS}"
HOST_VENDOR = "${TARGET_VENDOR}"
HOST_SYS = "${HOST_ARCH}${HOST_VENDOR}-${HOST_OS}"
HOST_PREFIX = "${TARGET_PREFIX}"
HOST_CC_ARCH = "${TARGET_CC_ARCH}"
HOST_LD_ARCH = "${TARGET_LD_ARCH}"
HOST_AS_ARCH = "${TARGET_AS_ARCH}"
HOST_EXEEXT = ""

TUNE_ARCH ??= "INVALID"
TUNE_CCARGS ??= ""
TUNE_CCARGS[vardepvalue] = "${TUNE_CCARGS}"
TUNE_LDARGS ??= ""
TUNE_ASARGS ??= ""
TUNE_FEATURES ??= "${TUNE_FEATURES_tune-${DEFAULTTUNE}}"
LIBCEXTENSION ??= ""
ABIEXTENSION ??= ""
USE_NLS ??= "yes"
SDKUSE_NLS ??= "yes"

TARGET_ARCH = "${TUNE_ARCH}"
TARGET_OS = "linux${LIBCEXTENSION}${ABIEXTENSION}"
TARGET_VENDOR = "-oe"
TARGET_SYS = "${TARGET_ARCH}${TARGET_VENDOR}${@['-' + d.getVar('TARGET_OS', True), ''][d.getVar('TARGET_OS', True) == ('' or 'custom')]}"
TARGET_PREFIX = "${TARGET_SYS}-"
TARGET_CC_ARCH = "${TUNE_CCARGS}"
TARGET_LD_ARCH = "${TUNE_LDARGS}"
TARGET_AS_ARCH = "${TUNE_ASARGS}"

SDK_ARCH = "${BUILD_ARCH}"
SDK_OS = "${BUILD_OS}"
SDK_VENDOR = "-oesdk"
SDK_SYS = "${SDK_ARCH}${SDK_VENDOR}${@['-' + d.getVar('SDK_OS', True), ''][d.getVar('SDK_OS', True) == ('' or 'custom')]}"
SDK_PREFIX = "${SDK_SYS}-"
SDK_CC_ARCH = "${BUILD_CC_ARCH}"
SDKPKGSUFFIX = "nativesdk"
SDK_PACKAGE_ARCHS = "all any noarch ${SDK_ARCH}-${SDKPKGSUFFIX}"
SDK_LD_ARCH = "${BUILD_LD_ARCH}"
SDK_AS_ARCH = "${BUILD_AS_ARCH}"

PACKAGE_ARCH = "${TUNE_PKGARCH}"
MACHINE_ARCH = "${@[d.getVar('TUNE_PKGARCH', True), d.getVar('MACHINE', True)][bool(d.getVar('MACHINE', True))].replace('-', '_')}"
PACKAGE_EXTRA_ARCHS ??= "${PACKAGE_EXTRA_ARCHS_tune-${DEFAULTTUNE}}"
PACKAGE_ARCHS = "all any noarch ${PACKAGE_EXTRA_ARCHS} ${MACHINE_ARCH}"
# MACHINE_ARCH shouldn't be included here as a variable dependency
# since machine specific packages are handled using multimachine
PACKAGE_ARCHS[vardepsexclude] = "MACHINE_ARCH"

MULTIMACH_TARGET_SYS = "${PACKAGE_ARCH}${TARGET_VENDOR}-${TARGET_OS}"
MULTIMACH_HOST_SYS = "${PACKAGE_ARCH}${HOST_VENDOR}-${HOST_OS}"

# select proper CPU to get binary locales generated
QEMU_OPTIONS = ""
QEMU_OPTIONS_iwmmxt  = "-cpu pxa270-c5"
QEMU_OPTIONS_armv6   = "-cpu arm1136"
QEMU_OPTIONS_armv7a   = "-cpu cortex-a8"
QEMU_OPTIONS_e500v2    = "-cpu e500v2"
QEMU_OPTIONS_e500mc    = "-cpu e500mc"
QEMU_OPTIONS_e5500     = "-cpu e5500"
QEMU_OPTIONS_e5500-64b = "-cpu e5500"

##################################################################
# Date/time variables.
##################################################################

DATE := "${@time.strftime('%Y%m%d',time.gmtime())}"
TIME := "${@time.strftime('%H%M%S',time.gmtime())}"
DATETIME = "${DATE}${TIME}"

##################################################################
# Openembedded Software Prerequisites.
##################################################################

# python-native should be here but python relies on building 
# its own in staging
ASSUME_PROVIDED = "\
    bzip2-native \
    chrpath-native \
    git-native \
    grep-native \
    diffstat-native \
    patch-native \
    perl-native-runtime \
    python-native-runtime \
    tar-native \
    virtual/libintl-native \
    "
# gzip-native should be listed above?

##################################################################
# Package default variables.
##################################################################

PN = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE'),d)[0] or 'defaultpkgname'}"
PV = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE'),d)[1] or '1.0'}"
PR = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE'),d)[2] or 'r0'}"
PRINC ?= "0"
PF = "${PN}-${EXTENDPE}${PV}-${PR}"
EXTENDPE = "${@['','${PE\x7d_'][int(d.getVar('PE',1) or 0) > 0]}"
P = "${PN}-${PV}"

EXTENDPRAUTO = "${@['.${PRAUTO\x7d',''][d.getVar('PRAUTO',1) is None]}"
PRAUTOINX = "${PF}"

PKGV ?= "${PV}"
PKGR ?= "${PR}${EXTENDPRAUTO}"
PKGE ?= "${@['','${PE\x7d'][int(d.getVar('PE',1) or 0) > 0]}"
EXTENDPKGEVER = "${@['','${PKGE\x7d:'][d.getVar('PKGE',1).strip() != '']}"
EXTENDPKGV ?= "${EXTENDPKGEVER}${PKGV}-${PKGR}"

# Base package name
# Automatically derives "foo" from "foo-native", "foo-cross" or "foo-initial"
# otherwise it is the same as PN and P
SPECIAL_PKGSUFFIX = "-native -cross -initial -intermediate -crosssdk -cross-canadian"
BPN = "${@base_prune_suffix(d.getVar('PN', True), d.getVar('SPECIAL_PKGSUFFIX', True).split(), d)}"
BP = "${BPN}-${PV}"

# Package info.

SECTION = "base"
PRIORITY = "optional"
SUMMARY ?= "${PN} version ${PV}-${PR}"
DESCRIPTION ?= "${SUMMARY}"

# The following two are commented out because they result in a recursive
# definition of the variable in some corner cases.  These are left in
# to illustrate the intended behavior.
#SUMMARY_${PN} ?= "${SUMMARY}"
#DESCRIPTION_${PN} ?= "${DESCRIPTION}"

SUMMARY_${PN}-dbg ?= "${SUMMARY} - Debugging files"
DESCRIPTION_${PN}-dbg ?= "${DESCRIPTION}  \
This package contains ELF symbols and related sources for debugging purposes."

SUMMARY_${PN}-dev ?= "${SUMMARY} - Development files"
DESCRIPTION_${PN}-dev ?= "${DESCRIPTION}  \
This package contains symbolic links, header files, and \
related items necessary for software development."

SUMMARY_${PN}-staticdev ?= "${SUMMARY} - Development files (Static Libraries)"
DESCRIPTION_${PN}-staticdev?= "${DESCRIPTION}  \
This package contains static libraries for software development."

SUMMARY_${PN}-doc ?= "${SUMMARY} - Documentation files"
DESCRIPTION_${PN}-doc ?= "${DESCRIPTION}  \
This package contains documentation."

LICENSE = "INVALID"
MAINTAINER = "OE-Core Developers <openembedded-core@lists.openembedded.org>"
HOMEPAGE = "unknown"

# Package dependencies and provides.

# Ensure that -dev packages recommend the corresponding -dev packages of their
# deps, and the same for -dbg.
DEPCHAIN_PRE  = ""
DEPCHAIN_POST = "-dev -dbg"

DEPENDS = ""
RDEPENDS = ""
PROVIDES = ""
PROVIDES_prepend = "${PN} "
RPROVIDES = ""

MULTI_PROVIDER_WHITELIST = "virtual/libintl virtual/libintl-native virtual/nativesdk-libintl virtual/xserver virtual/update-alternatives-native virtual/update-alternatives"

SOLIBS = ".so.*"
SOLIBS_darwin = ".dylib"

SOLIBSDEV = ".so"
# Due to the ordering of PACKAGES and the naming of the dev symlinks on darwin,
# we can't make the symlinks end up in the -dev packages easily at this point. This hack
# at least means builds aren't completely broken and symlinks don't take up much space.
SOLIBSDEV_darwin = ".dylibbroken"

PACKAGE_BEFORE_PN ?= ""
PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
PACKAGES_DYNAMIC = "^${PN}-locale-.*"
FILES = ""

FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
            ${sysconfdir} ${sharedstatedir} ${localstatedir} \
            ${base_bindir}/* ${base_sbindir}/* \
            ${base_libdir}/*${SOLIBS} \
            ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \
            ${datadir}/${BPN} ${libdir}/${BPN}/* \
            ${datadir}/pixmaps ${datadir}/applications \
            ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
            ${libdir}/bonobo/servers"

FILES_${PN}-bin = "${bindir}/* ${sbindir}/*"

FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
            ${datadir}/gnome/help"
SECTION_${PN}-doc = "doc"

FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
                ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
                ${datadir}/aclocal ${base_libdir}/*.o \
                ${libdir}/${BPN}/*.la ${base_libdir}/*.la"
SECTION_${PN}-dev = "devel"
ALLOW_EMPTY_${PN}-dev = "1"
RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})"

FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
SECTION_${PN}-staticdev = "devel"
RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"

DOTDEBUG-dbg = "${bindir}/.debug ${sbindir}/.debug ${libexecdir}/.debug ${libdir}/.debug \
            ${base_bindir}/.debug ${base_sbindir}/.debug ${base_libdir}/.debug ${libdir}/${BPN}/.debug \
            ${libdir}/matchbox-panel/.debug /usr/src/debug"

DEBUGFILEDIRECTORY-dbg = "/usr/lib/debug /usr/src/debug"

FILES_${PN}-dbg = "${@d.getVar(['DOTDEBUG-dbg', 'DEBUGFILEDIRECTORY-dbg'][d.getVar('PACKAGE_DEBUG_SPLIT_STYLE', True) == 'debug-file-directory'], True)}"

SECTION_${PN}-dbg = "devel"
ALLOW_EMPTY_${PN}-dbg = "1"

FILES_${PN}-locale = "${datadir}/locale"

# File manifest

FILE_DIRNAME = "${@os.path.dirname(d.getVar('FILE'))}"
# FILESPATH is set in base.bbclass
#FILESPATH = "${FILE_DIRNAME}/${PF}:${FILE_DIRNAME}/${P}:${FILE_DIRNAME}/${PN}:${FILE_DIRNAME}/${BP}:${FILE_DIRNAME}/${BPN}:${FILE_DIRNAME}/files:${FILE_DIRNAME}"

##################################################################
# General work and output directories for the build system.
##################################################################

TMPDIR ?= "${TOPDIR}/tmp"
CACHE = "${TMPDIR}/cache${@['', '/' + str(d.getVar('MACHINE', True))][bool(d.getVar('MACHINE', True))]}${@['', '/' + str(d.getVar('SDKMACHINE', True))][bool(d.getVar('SDKMACHINE', True))]}"
# The persistent cache should be shared by all builds
PERSISTENT_DIR = "${TOPDIR}/cache"
LOG_DIR = "${TMPDIR}/log"
CO_DIR = "${DL_DIR}"
CVSDIR = "${CO_DIR}/cvs"
SVNDIR = "${CO_DIR}/svn"
GITDIR = "${CO_DIR}/git2"
BZRDIR = "${CO_DIR}/bzr"
HGDIR = "${CO_DIR}/hg"

STAMPS_DIR ?= "${TMPDIR}/stamps"
STAMP = "${STAMPS_DIR}/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}"
STAMPCLEAN = "${STAMPS_DIR}/${MULTIMACH_TARGET_SYS}/${PN}/*-*"
BASE_WORKDIR ?= "${TMPDIR}/work"
WORKDIR = "${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}"
T = "${WORKDIR}/temp"
D = "${WORKDIR}/image"
S = "${WORKDIR}/${BP}"
B = "${S}"

STAGING_DIR = "${TMPDIR}/sysroots"

STAGING_DIR_NATIVE = "${STAGING_DIR}/${BUILD_SYS}"
STAGING_BINDIR_NATIVE = "${STAGING_DIR_NATIVE}${bindir_native}"
STAGING_BINDIR_CROSS = "${STAGING_BINDIR}/crossscripts"
STAGING_BINDIR_TOOLCHAIN = "${STAGING_DIR_NATIVE}${bindir_native}/${TUNE_PKGARCH}${TARGET_VENDOR}-${TARGET_OS}"
STAGING_LIBDIR_NATIVE = "${STAGING_DIR_NATIVE}${libdir_native}"
STAGING_LIBEXECDIR_NATIVE = "${STAGING_DIR_NATIVE}${libexecdir_native}"
STAGING_BASE_LIBDIR_NATIVE = "${STAGING_DIR_NATIVE}${base_libdir_native}"
STAGING_INCDIR_NATIVE = "${STAGING_DIR_NATIVE}${includedir_native}"
STAGING_ETCDIR_NATIVE = "${STAGING_DIR_NATIVE}${sysconfdir_native}"
STAGING_DATADIR_NATIVE = "${STAGING_DIR_NATIVE}${datadir_native}"

STAGING_DIR_HOST = "${STAGING_DIR}/${MACHINE}"
STAGING_BINDIR = "${STAGING_DIR_HOST}${bindir}"
STAGING_LIBDIR = "${STAGING_DIR_HOST}${libdir}"
STAGING_LIBEXECDIR = "${STAGING_DIR_HOST}${libexecdir}"
STAGING_BASELIBDIR = "${STAGING_DIR_HOST}${base_libdir}"
STAGING_INCDIR = "${STAGING_DIR_HOST}${includedir}"
STAGING_DATADIR = "${STAGING_DIR_HOST}${datadir}"
STAGING_EXECPREFIXDIR = "${STAGING_DIR_HOST}${exec_prefix}"
STAGING_LOADER_DIR = "${STAGING_DIR_HOST}/loader"
STAGING_FIRMWARE_DIR = "${STAGING_DIR_HOST}/firmware"

STAGING_DIR_TARGET = "${STAGING_DIR}/${MACHINE}"
STAGING_DIR_TCBOOTSTRAP = "${STAGING_DIR_TARGET}-tcbootstrap"

# Setting DEPLOY_DIR outside of TMPDIR is helpful, when you are using
# packaged staging and/or multimachine.
DEPLOY_DIR ?= "${TMPDIR}/deploy"
DEPLOY_DIR_TAR = "${DEPLOY_DIR}/tar"
DEPLOY_DIR_IPK = "${DEPLOY_DIR}/ipk"
DEPLOY_DIR_RPM = "${DEPLOY_DIR}/rpm"
DEPLOY_DIR_DEB = "${DEPLOY_DIR}/deb"
DEPLOY_DIR_IMAGE ?= "${DEPLOY_DIR}/images/${MACHINE}"
DEPLOY_DIR_TOOLS = "${DEPLOY_DIR}/tools"

PKGDATA_DIR = "${STAGING_DIR_HOST}/pkgdata"

##################################################################
# SDK variables.
##################################################################

SDK_NAME_PREFIX ?= "oecore"
SDK_NAME = "${SDK_NAME_PREFIX}-${SDK_ARCH}-${TUNE_PKGARCH}"
SDKPATH = "/usr/local/${SDK_NAME_PREFIX}-${SDK_ARCH}"
SDKPATHNATIVE = "${SDKPATH}/sysroots/${SDK_SYS}"

##################################################################
# Kernel info.
##################################################################

OLDEST_KERNEL = "2.6.16"
STAGING_KERNEL_DIR = "${STAGING_DIR_HOST}/usr/src/kernel"

##################################################################
# Specific image creation and rootfs population info.
##################################################################

IMAGE_ROOTFS = "${WORKDIR}/rootfs"
IMAGE_BASENAME = "${PN}"
IMAGE_NAME = "${IMAGE_BASENAME}-${MACHINE}-${DATETIME}"
IMAGE_NAME[vardepsexclude] += "DATETIME"
IMAGE_LINK_NAME = "${IMAGE_BASENAME}-${MACHINE}"

# This option allows for a percentage overage of the actual image size rather than a
# fixed extra space, this is space needed for initial startup and basic operations.
IMAGE_OVERHEAD_FACTOR ?= "1.3"
# This option allows for adding additional space in K above and beyond what the 
# IMAGE_OVERHEAD_FACTOR might add. This space is for additional packages, user data, ...
# To set a fixed size then overriding IMAGE_ROOTFS_SIZE with the max size one wants
# should do the trick
IMAGE_ROOTFS_EXTRA_SPACE ?= "0"

EXTRA_IMAGEDEPENDS = ""

##################################################################
# Toolchain info.
##################################################################

PATH_prepend = "${COREBASE}/scripts:${STAGING_BINDIR_TOOLCHAIN}:${STAGING_BINDIR_CROSS}:${STAGING_DIR_NATIVE}${sbindir_native}:${STAGING_BINDIR_NATIVE}:${STAGING_DIR_NATIVE}${base_sbindir_native}:${STAGING_DIR_NATIVE}/${base_bindir_native}:"
export PATH

##################################################################
# Build utility info.
##################################################################

CCACHE ??= ""
# Disable ccache explicitly if CCACHE is null since gcc may be a symlink
# of ccache some distributions (e.g., Fedora 17).
export CCACHE_DISABLE ??= "${@[0,1][d.getVar('CCACHE', True) == '']}"
# Assign CCACHE_DIR a default value to fix a bug of ccache 3.1.7,
# since it would always create CCACHE_DIR/.ccache even if
# CCACHE_DISABLE = 1.
export CCACHE_DIR ??= "${@os.getenv('HOME')}"

TOOLCHAIN_OPTIONS = " --sysroot=${STAGING_DIR_TARGET}"

export CC = "${CCACHE}${HOST_PREFIX}gcc ${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
export CXX = "${CCACHE}${HOST_PREFIX}g++ ${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
export F77 = "${CCACHE}${HOST_PREFIX}g77 ${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
export CPP = "${HOST_PREFIX}gcc -E${TOOLCHAIN_OPTIONS} ${HOST_CC_ARCH}"
export LD = "${HOST_PREFIX}ld${TOOLCHAIN_OPTIONS} ${HOST_LD_ARCH}"
export CCLD = "${CC}"
export AR = "${HOST_PREFIX}ar"
export AS = "${HOST_PREFIX}as ${HOST_AS_ARCH}"
export RANLIB = "${HOST_PREFIX}ranlib"
export STRIP = "${HOST_PREFIX}strip"
export OBJCOPY = "${HOST_PREFIX}objcopy"
export OBJDUMP = "${HOST_PREFIX}objdump"
export STRINGS = "${HOST_PREFIX}strings"
export NM = "${HOST_PREFIX}nm"
PYTHON = "${@sys.executable}"

export BUILD_CC = "${CCACHE}${BUILD_PREFIX}gcc ${BUILD_CC_ARCH}"
export BUILD_CXX = "${CCACHE}${BUILD_PREFIX}g++ ${BUILD_CC_ARCH}"
export BUILD_F77 = "${CCACHE}${BUILD_PREFIX}g77 ${BUILD_CC_ARCH}"
export BUILD_CPP = "${BUILD_PREFIX}cpp ${BUILD_CC_ARCH}"
export BUILD_LD = "${BUILD_PREFIX}ld ${BUILD_LD_ARCH}"
export BUILD_CCLD = "${BUILD_PREFIX}gcc ${BUILD_CC_ARCH}"
export BUILD_AR = "${BUILD_PREFIX}ar"
export BUILD_AS = "${BUILD_PREFIX}as ${BUILD_AS_ARCH}"
export BUILD_RANLIB = "${BUILD_PREFIX}ranlib"
export BUILD_STRIP = "${BUILD_PREFIX}strip"
export BUILD_NM = "${BUILD_PREFIX}nm"

export MAKE = "make"
EXTRA_OEMAKE = "-e MAKEFLAGS="
EXTRA_OECONF = ""
export LC_ALL = "C"

##################################################################
# Patch handling.
##################################################################
PATCHTOOL = 'quilt'
PATCHRESOLVE = 'user'

##################################################################
# Build flags and options.
##################################################################

export BUILD_CPPFLAGS = "-isystem${STAGING_INCDIR_NATIVE}"
BUILDSDK_CPPFLAGS = "-isystem${STAGING_INCDIR}"
export CPPFLAGS = "${TARGET_CPPFLAGS}"
export TARGET_CPPFLAGS = ""
#export TARGET_CPPFLAGS = "-isystem${STAGING_DIR_TARGET}${includedir}"

export BUILD_CFLAGS = "${BUILD_CPPFLAGS} ${BUILD_OPTIMIZATION}"
BUILDSDK_CFLAGS = "${BUILDSDK_CPPFLAGS} ${BUILD_OPTIMIZATION}"
export CFLAGS = "${TARGET_CFLAGS}"
export TARGET_CFLAGS = "${TARGET_CPPFLAGS} ${SELECTED_OPTIMIZATION}"

export BUILD_CXXFLAGS = "${BUILD_CFLAGS} -fpermissive"
export CXXFLAGS = "${TARGET_CXXFLAGS}"
export TARGET_CXXFLAGS = "${TARGET_CFLAGS} -fpermissive"

export BUILD_LDFLAGS = "-L${STAGING_LIBDIR_NATIVE} \
                        -L${STAGING_BASE_LIBDIR_NATIVE} \
                        -Wl,-rpath-link,${STAGING_LIBDIR_NATIVE} \
                        -Wl,-rpath-link,${STAGING_BASE_LIBDIR_NATIVE} \
                        -Wl,-rpath,${STAGING_LIBDIR_NATIVE} \
                        -Wl,-rpath,${STAGING_BASE_LIBDIR_NATIVE} \
                        -Wl,-O1"

BUILDSDK_LDFLAGS = "-L${STAGING_LIBDIR} \
                    -Wl,-rpath-link,${STAGING_LIBDIR} \
                    -Wl,-rpath,${libdir} -Wl,-O1 \
                    -L${STAGING_DIR_HOST}${base_libdir} \
                    -Wl,-rpath-link,${STAGING_DIR_HOST}${base_libdir} \
                    -Wl,-rpath,${base_libdir} -Wl,-O1"

LINKER_HASH_STYLE ??= "gnu"
# mips does not support GNU hash style therefore we override
LINKER_HASH_STYLE_mips = "sysv"
LINKER_HASH_STYLE_mipsel = "sysv"
LINKER_HASH_STYLE_mips64 = "sysv"
LINKER_HASH_STYLE_mips64el = "sysv"
TARGET_LINK_HASH_STYLE ?= "${@['-Wl,--hash-style=gnu',''][d.getVar('LINKER_HASH_STYLE', True) != 'gnu']}"

export LDFLAGS = "${TARGET_LDFLAGS}"
export TARGET_LDFLAGS = "-Wl,-O1 ${TARGET_LINK_HASH_STYLE}"
#export TARGET_LDFLAGS = "-L${STAGING_DIR_TARGET}${libdir} \
#                         -Wl,-rpath-link,${STAGING_DIR_TARGET}${libdir} \
#                         -Wl,-O1"

# Which flags to leave by strip-flags() in bin/build/oebuild.sh ?
ALLOWED_FLAGS = "-O -mcpu -march -pipe"

# Pass parallel make options to the compile task
EXTRA_OEMAKE_prepend_task-compile = "${PARALLEL_MAKE} "
PARALLEL_MAKEINST ??= "${PARALLEL_MAKE}"
# Pass parallel make options to the install task
EXTRA_OEMAKE_prepend_task-install = "${PARALLEL_MAKEINST} "

##################################################################
# Optimization flags.
##################################################################
DEBUG_FLAGS ?= "-g -feliminate-unused-debug-types"
# Disabled until the option works properly -feliminate-dwarf2-dups
FULL_OPTIMIZATION = "-O2 -pipe ${DEBUG_FLAGS}"
DEBUG_OPTIMIZATION = "-O -fno-omit-frame-pointer ${DEBUG_FLAGS} -pipe"
SELECTED_OPTIMIZATION = "${@d.getVar(['FULL_OPTIMIZATION', 'DEBUG_OPTIMIZATION'][d.getVar('DEBUG_BUILD', True) == '1'], True)}"
SELECTED_OPTIMIZATION[vardeps] += "FULL_OPTIMIZATION DEBUG_OPTIMIZATION"
BUILD_OPTIMIZATION = "-O2 -pipe"

##################################################################
# Bootstrap stuff.
##################################################################

BOOTSTRAP_EXTRA_RDEPENDS = ""
BOOTSTRAP_EXTRA_RRECOMMENDS = ""

##################################################################
# Download locations and utilities.
##################################################################

ADOBE_MIRROR = "http://fpdownload.macromedia.com/get/flashplayer/current/"
APACHE_MIRROR = "http://www.apache.org/dist"
DEBIAN_MIRROR = "ftp://ftp.debian.org/debian/pool"
E_MIRROR = "http://download.enlightenment.org/releases"
E_SVN = "svn://svn.enlightenment.org/svn/e"
FREEBSD_MIRROR = "ftp://ftp.freebsd.org/pub/FreeBSD/"
FREEDESKTOP_CVS = "cvs://anoncvs:anoncvs@anoncvs.freedesktop.org/cvs"
FREESMARTPHONE_GIT = "git://git.freesmartphone.org"
GENTOO_MIRROR = "http://distfiles.gentoo.org/distfiles"
GNOME_GIT = "git://git.gnome.org"
GNOME_MIRROR = "http://ftp.gnome.org/pub/GNOME/sources"
GNU_MIRROR = "ftp://ftp.gnu.org/gnu"
GPE_MIRROR = "http://gpe.linuxtogo.org/download/source"
GPE_EXTRA_SVN = "svn://projects.linuxtogo.org/svn/gpe/trunk/extra;module=${PN}"
GPE_SVN = "svn://projects.linuxtogo.org/svn/gpe/trunk/base;module=${PN}"
GPEPHONE_MIRROR = "http://gpephone.linuxtogo.org/download/gpephone"
GPEPHONE_SVN = "svn://projects.linuxtogo.org/svn/gpephone/trunk/source;module=${PN}"
HANDHELDS_CVS = "cvs://anoncvs:anoncvs@anoncvs.handhelds.org/cvs"
KERNELORG_MIRROR = "http://kernel.org/pub"
SOURCEFORGE_MIRROR = "http://downloads.sourceforge.net"
XLIBS_MIRROR = "http://xlibs.freedesktop.org/release"
XORG_MIRROR = "http://xorg.freedesktop.org/releases"

# You can use the mirror of your country to get faster downloads by putting
#  export DEBIAN_MIRROR = "ftp://ftp.de.debian.org/debian/pool"
#     into your local.conf

FETCHCMD_svn = "/usr/bin/env svn --non-interactive --trust-server-cert"
FETCHCMD_cvs = "/usr/bin/env cvs"
FETCHCMD_wget = "/usr/bin/env wget -t 2 -T 30 -nv --passive-ftp --no-check-certificate"
FETCHCMD_bzr = "/usr/bin/env bzr"
FETCHCMD_hg = "/usr/bin/env hg"

SRCDATE = "${DATE}"
SRCREV ??= "INVALID"
AUTOREV = "${@bb.fetch2.get_autorev(d)}"
SRCPV = "${@bb.fetch2.get_srcrev(d)}"
SRCPV[vardepvalue] = "${SRCPV}"

SRC_URI = ""

# Use pseudo as the fakeroot implementation
PSEUDO_LOCALSTATEDIR ?= "${WORKDIR}/pseudo/"
PSEUDO_PASSWD ?= "${STAGING_DIR_TARGET}"
export PSEUDO_DISABLED = "1"
#export PSEUDO_PREFIX = "${STAGING_DIR_NATIVE}${prefix_native}"
#export PSEUDO_BINDIR = "${STAGING_DIR_NATIVE}${bindir_native}"
#export PSEUDO_LIBDIR = "${STAGING_DIR_NATIVE}$PSEUDOBINDIR/../lib/pseudo/lib
FAKEROOTBASEENV = "PSEUDO_BINDIR=${STAGING_BINDIR_NATIVE} PSEUDO_LIBDIR=${STAGING_BINDIR_NATIVE}/../lib/pseudo/lib PSEUDO_PREFIX=${STAGING_BINDIR_NATIVE}/../../ PSEUDO_DISABLED=1"
FAKEROOTCMD = "${STAGING_BINDIR_NATIVE}/pseudo"
FAKEROOTENV = "PSEUDO_PREFIX=${STAGING_DIR_NATIVE}${prefix_native} PSEUDO_LOCALSTATEDIR=${PSEUDO_LOCALSTATEDIR} PSEUDO_PASSWD=${PSEUDO_PASSWD} PSEUDO_NOSYMLINKEXP=1 PSEUDO_DISABLED=0"
FAKEROOTNOENV = "PSEUDO_UNLOAD=1"
FAKEROOTDIRS = "${PSEUDO_LOCALSTATEDIR}"
PREFERRED_PROVIDER_virtual/fakeroot-native ?= "pseudo-native"

##################################################################
# Miscellaneous utilities.
##################################################################

MKTEMPDIRCMD = "mktemp -d -q ${TMPBASE}"
MKTEMPCMD = "mktemp -q ${TMPBASE}"

# GNU patch tries to be intellgent about checking out read-only files from
# a RCS, which freaks out those special folks with active Perforce clients
# the following makes patch ignore RCS:

export PATCH_GET="0"

##################################################################
# Not sure about the rest of this yet.
##################################################################

# Pre-build configuration output
BUILDCFG_HEADER = "Build Configuration:"
BUILDCFG_VARS = "BB_VERSION BUILD_SYS NATIVELSBSTRING TARGET_SYS MACHINE DISTRO DISTRO_VERSION TUNE_FEATURES TARGET_FPU"
BUILDCFG_VARS[type] = "list"
BUILDCFG_NEEDEDVARS = "TARGET_ARCH TARGET_OS"
BUILDCFG_NEEDEDVARS[type] = "list"

# Other

export PKG_CONFIG_DIR = "${STAGING_DIR_HOST}/${libdir}/pkgconfig"
export PKG_CONFIG_PATH = "${PKG_CONFIG_DIR}:${STAGING_DATADIR}/pkgconfig"
export PKG_CONFIG_LIBDIR = "${PKG_CONFIG_DIR}"
export PKG_CONFIG_SYSROOT_DIR = "${STAGING_DIR_HOST}"
export PKG_CONFIG_DISABLE_UNINSTALLED = "yes"

# library package naming
AUTO_LIBNAME_PKGS = "${PACKAGES}"

###
### Config file processing
###

# Overrides are processed left to right, so the ones that are named later take precedence.
# You generally want them to go from least to most specific.
# 
# This means that an envionment variable named '<foo>_arm' overrides an
# environment variable '<foo>' (when ${TARGET_ARCH} is arm).
# An environment variable '<foo>_qemuarm' overrides '<foo>' and overrides
# '<foo>_arm' when ${MACHINE} is 'qemuarm'. 
# If you use combination ie '<foo>_qemuarm_arm', then '<foo>_qemuarm_arm' will override 
# '<foo>_qemuarm' and then '<foo>' will be overriden with that value from '<foo>_qemuarm'.
# And finally '<foo>_forcevariable' overrides any standard variable, with the highest priority.
#
# This works for  functions as well, they are really just environment variables.
# Default OVERRIDES to make compilation fail fast in case of build system misconfiguration.
OVERRIDES = "${TARGET_OS}:${TRANSLATED_TARGET_ARCH}:build-${BUILD_OS}:pn-${PN}:${MACHINEOVERRIDES}:${DISTROOVERRIDES}:${CLASSOVERRIDE}:forcevariable"
OVERRIDES[vardepsexclude] = "MACHINEOVERRIDES"
CLASSOVERRIDE ?= "class-target"
DISTROOVERRIDES ?= "${@d.getVar('DISTRO', True) or ''}"
MACHINEOVERRIDES ?= "${MACHINE}"
MACHINEOVERRIDES[vardepsexclude] = "MACHINE"

FILESOVERRIDES = "${TRANSLATED_TARGET_ARCH}:${MACHINEOVERRIDES}:${DISTROOVERRIDES}"

CPU_FEATURES ?= ""
CPU_FEATURES_arm ?= "vfp"

##################################################################
# Include the rest of the config files.
##################################################################

require conf/abi_version.conf
include conf/site.conf
include conf/auto.conf
include conf/local.conf
include conf/build/${BUILD_SYS}.conf
include conf/target/${TARGET_SYS}.conf
include conf/machine/${MACHINE}.conf
include conf/machine-sdk/${SDKMACHINE}.conf
include conf/distro/${DISTRO}.conf
include conf/distro/defaultsetup.conf
include conf/documentation.conf
include conf/licenses.conf
require conf/sanity.conf

##################################################################
# Weak variables (usually to retain backwards compatibility)
##################################################################

DL_DIR ?= "${TOPDIR}/downloads"
SSTATE_DIR ?= "${TOPDIR}/sstate-cache"
IMAGE_FSTYPES ?= "tar.gz"
INITRAMFS_FSTYPES ?= "cpio.gz"
DEFAULT_TASK_PROVIDER ?= "packagegroup-base"
MACHINE_TASK_PROVIDER ?= "${DEFAULT_TASK_PROVIDER}"
IMAGE_ROOTFS_SIZE ?= "65536"

# Forcefully set CACHE now so future changes to things like 
# MACHINE don't change the path to the cache
CACHE := "${CACHE}"

##################################################################
# Magic Cookie for SANITY CHECK
##################################################################
OES_BITBAKE_CONF = "1"

##################################################################
# Machine properties and packagegroup-base stuff
##################################################################

DISTRO_FEATURES ?= ""

DISTRO_EXTRA_RDEPENDS ?= ""
DISTRO_EXTRA_RRECOMMENDS ?= ""
MACHINE_EXTRA_RDEPENDS ?= ""
MACHINE_EXTRA_RRECOMMENDS ?= ""
MACHINE_ESSENTIAL_EXTRA_RDEPENDS ?= ""
MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS ?= ""

EXTRA_IMAGE_FEATURES ??= ""
IMAGE_FEATURES += "${EXTRA_IMAGE_FEATURES}"

DISTRO_FEATURES_BACKFILL = "pulseaudio sysvinit"
MACHINE_FEATURES_BACKFILL = "rtc"

COMBINED_FEATURES = "\
    ${@base_both_contain("DISTRO_FEATURES", "MACHINE_FEATURES", "alsa", d)} \
    ${@base_both_contain("DISTRO_FEATURES", "MACHINE_FEATURES", "bluetooth", d)} \
    ${@base_both_contain("DISTRO_FEATURES", "MACHINE_FEATURES", "ext2", d)} \
    ${@base_both_contain("DISTRO_FEATURES", "MACHINE_FEATURES", "vfat", d)} \
    ${@base_both_contain("DISTRO_FEATURES", "MACHINE_FEATURES", "irda", d)} \
    ${@base_both_contain("DISTRO_FEATURES", "MACHINE_FEATURES", "pcmcia", d)} \
    ${@base_both_contain("DISTRO_FEATURES", "MACHINE_FEATURES", "pci", d)} \
    ${@base_both_contain("DISTRO_FEATURES", "MACHINE_FEATURES", "usbgadget", d)} \
    ${@base_both_contain("DISTRO_FEATURES", "MACHINE_FEATURES", "usbhost", d)} \
    ${@base_both_contain("DISTRO_FEATURES", "MACHINE_FEATURES", "wifi", d)}"
COMBINED_FEATURES[vardeps] += "DISTRO_FEATURES MACHINE_FEATURES"

SERIAL_CONSOLE ??= ""
SERIAL_CONSOLES ??= "${@d.getVar('SERIAL_CONSOLE', True).replace(' ', ';')}"

NO_RECOMMENDATIONS ?= ""
BAD_RECOMMENDATIONS ?= ""

# Make sure MACHINE isn't exported
# (breaks binutils at least)
MACHINE[unexport] = "1"

# Make sure TARGET_ARCH isn't exported
# (breaks Makefiles using implicit rules, e.g. quilt, as GNU make has this 
# in them, undocumented)
TARGET_ARCH[unexport] = "1"

# Make sure DISTRO isn't exported
# (breaks sysvinit at least)
DISTRO[unexport] = "1"

# Used by canadian-cross to handle string conversions on TARGET_ARCH where needed
TRANSLATED_TARGET_ARCH ??= "${@d.getVar('TARGET_ARCH', True).replace("_", "-")}"

# Complete output from bitbake
BB_CONSOLELOG ?= "${LOG_DIR}/cooker/${MACHINE}/${DATETIME}.log"

# Setup our default hash policy
BB_SIGNATURE_HANDLER ?= "OEBasicHash"
BB_HASHBASE_WHITELIST ?= "TMPDIR FILE PATH PWD BB_TASKHASH BBPATH 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_DISABLE LICENSE_PATH SDKPKGSUFFIX"
BB_HASHCONFIG_WHITELIST ?= "${BB_HASHBASE_WHITELIST} DATE TIME SSH_AGENT_PID \
    SSH_AUTH_SOCK PSEUDO_BUILD BB_ENV_EXTRAWHITE DISABLE_SANITY_CHECKS \
    PARALLEL_MAKE BB_NUMBER_THREADS BB_ORIGENV"
BB_SIGNATURE_EXCLUDE_FLAGS ?= "doc defaultval _append _prepend deps depends \
    lockfiles type vardepsexclude vardeps vardepvalue file-checksums python \
    func task export unexport noexec nostamp dirs cleandirs \
    sstate-lockfile-shared prefuncs postfuncs export_func deptask rdeptask \
    recrdeptask nodeprrecs stamp-base stamp-extra-info"

MLPREFIX ??= ""
MULTILIB_VARIANTS ??= ""