
echo "$1 $2"

if [ "$1" == "" ] ; then
   echo "You must select a machine target [zcu102,vck190,z19,vpk120]"
   exit
fi

BNAME="$2"
if [ "$2" == "" ] ; then
   BNAME="build"
fi


METATEMP=""
if [ "$1" == "zcu102" ] || [ "$1" == "ZCU102" ] ; then
   echo "Generating build for zcu102-zynqmp machine"
   METATEMP="meta-zcu102"
elif [ "$1" == "zcu102-9082" ] || [ "$1" == "ZCU102-9082" ] ; then
   echo "Generating build for zcu102-zynqmp machine"
   METATEMP="meta-zcu102-9082"
elif [ "$1" == "zcu102-9081" ] || [ "$1" == "ZCU102-9081" ] ; then
   echo "Generating build for zcu102-zynqmp machine"
   METATEMP="meta-zcu102-9081"
elif [ "$1" == "vck190" ] || [ "$1" == "VCK190" ] ; then
   echo "Generating build for vck190-versal machine"
   METATEMP="meta-vck190"
elif [ "$1" == "z19-9081" ] || [ "$1" == "Z19-9081" ] ; then
   echo "Generating build for z19-zynqmp machine"
   METATEMP="meta-z19-9081"
elif [ "$1" == "z19-9082" ] || [ "$1" == "Z19-9082" ] ; then
   echo "Generating build for z19-zynqmp machine"
   METATEMP="meta-z19-9082"
elif [ "$1" == "vpk120-9082" ] || [ "$1" == "VPK120-9082" ] ; then
   echo "Generating build for z19-zynqmp machine"
   METATEMP="meta-vpk120-9082"   
else
   echo "The machine you requested ($1) is not supported"
#   return
fi
shift


if [ -n "$BASH_SOURCE" ]; then
	export ROOT=$(readlink -f $(dirname "$BASH_SOURCE"))
elif [ -n "$ZSH_NAME" ]; then
	export ROOT=$(readlink -f $(dirname "$0"))
else
	export ROOT=$(readlink -f ${PWD})
fi

ARMETA=$ROOT/sources/meta-atomicrules/meta-atomicrules-ardsoc/$METATEMP
echo "****** $ARMETA"
if [ ! -d $ARMETA ] ; then
   git submodule update --init --recursive
fi

TEMPLATECONF=$ARMETA/conf/templates/ardsoc
export TEMPLATECONF
echo "**** $TEMPLATECONF"
# Use the internal layer, if it's checked out
if [ -d $ROOT/sources/meta-xilinx-internal ]; then
    export TEMPLATECONF=$ROOT/sources/meta-xilinx-internal/conf/templates/default
fi
export PATH=$PATH:$ROOT/scripts
if [ -d $ROOT/sources/meta-xilinx/meta-xilinx-core/gen-machine-conf ]; then
        export PATH=$PATH:$ROOT/sources/meta-xilinx/meta-xilinx-core/gen-machine-conf
fi

# Translate environment variables old to new
if [ -n "${BB_ENV_WHITELIST}" ]; then
   export BB_ENV_PASSTHROUGH="${BB_ENV_WHITELIST}"
   unset BB_ENV_WHITELIST
fi
if [ -n "${BB_ENV_EXTRAWHITE}" ]; then
   export BB_ENV_PASSTHROUGH_ADDITIONS="${BB_ENV_EXTRAWHITE}"
   unset BB_ENV_EXTRAWHITE
fi
source $ROOT/sources/poky/oe-init-build-env "$BNAME"

