# Check for LD_LIBRARY_PATH being set, which can break SDK and generally is a bad practice
# http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html#AEN80
# http://xahlee.info/UnixResource_dir/_/ldpath.html
# Only disable this check if you are absolutely know what you are doing!
if [ ! -z "${LD_LIBRARY_PATH:-}" ]; then
    echo "Your environment is misconfigured, you probably need to 'unset LD_LIBRARY_PATH'"
    echo "but please check why this was set in the first place and that it's safe to unset."
    echo "The SDK will not operate correctly in most cases when LD_LIBRARY_PATH is set."
    echo "For more references see:"
    echo "  http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html#AEN80"
    echo "  http://xahlee.info/UnixResource_dir/_/ldpath.html"
    return 1
fi

export SDKTARGETSYSROOT=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/cortexa57-poky-linux
export PATH=/usr/local/oe-sdk-hardcoded-buildpath/sysroots/aarch64-pokysdk-linux/usr/bin:/usr/local/oe-sdk-hardcoded-buildpath/sysroots/aarch64-pokysdk-linux/usr/sbin:/usr/local/oe-sdk-hardcoded-buildpath/sysroots/aarch64-pokysdk-linux/bin:/usr/local/oe-sdk-hardcoded-buildpath/sysroots/aarch64-pokysdk-linux/sbin:/usr/local/oe-sdk-hardcoded-buildpath/sysroots/aarch64-pokysdk-linux/usr/bin/../aarch64-pokysdk-linux/bin:/usr/local/oe-sdk-hardcoded-buildpath/sysroots/aarch64-pokysdk-linux/usr/bin/aarch64-poky-linux:/usr/local/oe-sdk-hardcoded-buildpath/sysroots/aarch64-pokysdk-linux/usr/bin/aarch64-poky-linux-musl:"$PATH"
export PKG_CONFIG_SYSROOT_DIR=$SDKTARGETSYSROOT
export PKG_CONFIG_PATH=$SDKTARGETSYSROOT/usr/lib/pkgconfig:$SDKTARGETSYSROOT/usr/share/pkgconfig
export CONFIG_SITE=/usr/local/oe-sdk-hardcoded-buildpath/site-config-cortexa57-poky-linux
export OECORE_NATIVE_SYSROOT="/usr/local/oe-sdk-hardcoded-buildpath/sysroots/aarch64-pokysdk-linux"
export OECORE_TARGET_SYSROOT="$SDKTARGETSYSROOT"
export OECORE_ACLOCAL_OPTS="-I /usr/local/oe-sdk-hardcoded-buildpath/sysroots/aarch64-pokysdk-linux/usr/share/aclocal"
export OECORE_BASELIB="lib"
export OECORE_TARGET_ARCH="aarch64"
export OECORE_TARGET_OS="linux"
export OECORE_TARGET_BITS="64"
export OECORE_TARGET_ENDIAN="little"
export OECORE_MESON_HOST_SYSTEM="linux"
export OECORE_MESON_HOST_CPU_FAMILY="aarch64"
export OECORE_MESON_HOST_CPU="aarch64"
export OECORE_MESON_HOST_ENDIAN="little"
unset command_not_found_handle
export CC="aarch64-poky-linux-gcc  -mcpu=cortex-a57+crc -mbranch-protection=standard -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=$SDKTARGETSYSROOT"
export CXX="aarch64-poky-linux-g++  -mcpu=cortex-a57+crc -mbranch-protection=standard -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=$SDKTARGETSYSROOT"
export CPP="aarch64-poky-linux-gcc -E  -mcpu=cortex-a57+crc -mbranch-protection=standard -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=$SDKTARGETSYSROOT"
export AS="aarch64-poky-linux-as "
export LD="aarch64-poky-linux-ld  --sysroot=$SDKTARGETSYSROOT"
export GDB=aarch64-poky-linux-gdb
export STRIP=aarch64-poky-linux-strip
export RANLIB=aarch64-poky-linux-ranlib
export OBJCOPY=aarch64-poky-linux-objcopy
export OBJDUMP=aarch64-poky-linux-objdump
export READELF=aarch64-poky-linux-readelf
export AR=aarch64-poky-linux-ar
export NM=aarch64-poky-linux-nm
export M4=m4
export TARGET_PREFIX=aarch64-poky-linux-
export CONFIGURE_FLAGS="--target=aarch64-poky-linux --host=aarch64-poky-linux --build=aarch64-linux --with-libtool-sysroot=$SDKTARGETSYSROOT"
export CFLAGS=" -O2 -g  -pipe"
export CXXFLAGS=" -O2 -g  -pipe"
export LDFLAGS="-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-z,relro,-z,now"
export CPPFLAGS=""
export KCFLAGS="--sysroot=$SDKTARGETSYSROOT"
export OECORE_DISTRO_VERSION="5.3.99+snapshot-dc5276913327b54ae70b9fdb88f00ba74f586208"
export OECORE_SDK_VERSION="5.3.99+snapshot"
export ARCH=arm64
export CROSS_COMPILE=aarch64-poky-linux-
export OECORE_TUNE_CCARGS=" -mcpu=cortex-a57+crc -mbranch-protection=standard"

# Append environment subscripts
if [ -d "$OECORE_TARGET_SYSROOT/environment-setup.d" ]; then
    for envfile in $OECORE_TARGET_SYSROOT/environment-setup.d/*.sh; do
	    . $envfile
    done
fi
if [ -d "$OECORE_NATIVE_SYSROOT/environment-setup.d" ]; then
    for envfile in $OECORE_NATIVE_SYSROOT/environment-setup.d/*.sh; do
	    . $envfile
    done
fi
