#!/bin/bash SETUP_SCRIPT="$1" shift PROGNAME=$(basename "$SETUP_SCRIPT") SETUP_SCRIPTDIR=$(dirname "$SETUP_SCRIPT") TD_TOP="${TD_TOP:-$(readlink -f $SETUP_SCRIPTDIR)}" DISTRO_DEFAULT="tegrademo" BUILDDIR_DEFAULT="build" distro_list() { local paths paths=$(find -L $TD_TOP/layers/ -path '*meta-*/conf/distro/*' -name '*.conf') find $paths -maxdepth 1 -name '*.conf' | xargs basename -s .conf | sort -u | awk '{print "\t" $0}' } distro_path() { local dconf=$(find -L "$TD_TOP"/layers -path "*/conf/distro/*" -name "${1}.conf" | head -n 1) [ -n "$dconf" ] || exit 1 echo "$dconf" | sed -E -e's,.*/layers/([^/]+)/conf/.*,\1,' } machine_list() { find -L "$TD_TOP"/layers/meta*/conf/machine -maxdepth 1 -name '*.conf' | xargs basename -s .conf | sort -u | awk '{print "\t" $0}' } usage() { cat >&2 < [] [] Usage: . $PROGNAME [] Options: -h, --help Print this usage message -m, --machine Set the MACHINE name in the build configuratino -d, --distro Set the DISTRO name in the build configuration (default '${DISTRO_DEFAULT}') -c, --color Colorize the output; can be 'never', 'always', or 'auto' (default 'auto') Arguments: BUILDDIR Location of BUILDDIR (default '${BUILDDIR_DEFAULT}') The first usage is for creating a new build directory. In this case, the script creates the build directory , configures it for the specified and , and prepares the calling shell for running bitbake on the build directory. The second usage is for using an existing build directory. In this case, the script prepares the calling shell for running bitbake on the build directory . The build directory configuration is unchanged. Available distros: $(distro_list) Available machines: $(machine_list) Examples: - To create a new Yocto build directory: $ . $PROGNAME --machine jetson-xavier-nx-devkit --distro testdistro build-testdistro - To use an existing Yocto build directory: $ . $PROGNAME build-testdistro EOF } COLOR=auto DISTRO="${DISTRO:-$DISTRO_DEFAULT}" # get command line options SHORTOPTS="hm:d:b:c:" LONGOPTS="help,machine:,distro:,color:" ARGS=$(getopt --options $SHORTOPTS --longoptions $LONGOPTS --name $PROGNAME -- "$@" ) # Print the usage menu if invalid options are specified if [ $? != 0 ]; then usage echo "TD_RC=1" exit 1 fi eval set -- "$ARGS" while true; do case $1 in -h | --help) usage; echo "TD_RC=1"; exit 0 ;; -m | --machine) MACHINE="$2"; shift 2;; -d | --distro) DISTRO="$2"; shift 2;; -c | --color) COLOR="$2"; shift 2;; -- ) shift; break ;; * ) break ;; esac done BUILDDIR="${1:-$BUILDDIR_DEFAULT}" if [ ! -e $BUILDDIR/conf/local.conf ]; then if [ -z "$MACHINE" ]; then usage echo "ERROR: You must set MACHINE when creating a new build directory." >&2 echo "TD_RC=1" exit 1 fi if ! machine_list | grep -qx "[[:space:]]*$MACHINE"; then echo "ERROR: machine \"$MACHINE\" not found" >&2 echo "Available MACHINEs:" >&2 machine_list >&2 echo "TD_RC=1" exit 1 fi if [ -z "$DISTRO" ]; then DISTRO=$DISTRO_DEFAULT fi if ! distro_list | grep -Eqx "[[:space:]]*$DISTRO"; then echo "ERROR: distro \"$DISTRO\" not found" >&2 echo "Available DISTROs:" >&2 distro_list >&2 echo "TD_RC=1" exit 1 fi LAYERPATH=$(distro_path $DISTRO) NEEDSETUP=yes fi if [ $COLOR = "auto" ]; then if [ -t 1 ]; then COLOR=always else COLOR=never fi else COLOR=never fi cat <