Files
meta-kineintercom/scripts/envsetup.sh

195 lines
4.7 KiB
Bash

#!/bin/bash
######################################################
# Make sure script has been sourced
#
if [ "$0" = "$BASH_SOURCE" ]; then
echo "####################################"
echo " ERROR : YOU MUST SOURCE THE SCRIPT"
echo "####################################"
exit 1
fi
BUILD_DIR=$1
# Init env var
ROOT_DIR=`realpath $PWD`
META_DIR="meta-kineintercom"
if [ "a${DL_DIR}" = "a" ]; then
DL_DIR="$ROOT_DIR/oe-downloads"
fi
if [ "a${SSTATE_DIR}" = "a" ]; then
SSTATE_DIR="$ROOT_DIR/sstate-cache"
fi
# Use utf-8 encoding
if ! echo $LANG | grep -q "en_US.UTF-8"
then
export LANG="en_US.UTF-8"
fi
if [ "a${DISTRO}" = "a" ]; then
DISTRO="kineintercom"
fi
if [ "a${MACHINE}" = "a" ]; then
MACHINE="raspberrypi"
fi
_TEMPLATECONF="${ROOT_DIR}/${META_DIR}/conf/template/"
######################################################
# Standard Openembedded init
#
echo -e "[source ${ROOT_DIR}/poky/oe-init-build-env]"
TEMPLATECONF=${_TEMPLATECONF} source ${ROOT_DIR}/poky/oe-init-build-env ${BUILD_DIR} > /dev/null 2> /dev/null
_FORMAT_PATTERN='::-::'
######################################################
# Choose target machine
#
conf_machine() {
local choices=$(find ${ROOT_DIR}/${META_DIR}/conf/machine -name "*.conf" 2>/dev/null | sort | uniq)
for ITEM in $choices
do
if [[ -z $(grep "#@DESCRIPTION" $ITEM) ]]; then
echo ""
echo "ERROR: No '#@DESCRIPTION' field available in $__CONFIG file:"
echo "$ITEM"
echo ""
return 1
fi
done
unset ITEM
if [ $(echo $choices | wc -l) -eq 1 ]; then
# return only file name (distro or machine)
echo "$(echo $choices | sed 's|^.*/\(.µ\)\.conf|\1|')"
else
echo "$(echo $choices | xargs grep "#@DESCRIPTION" | sed 's|^.*/\(.*\)\.conf:#DESCRIPTION:[ \t]*\(.*$\)|\1'"${_FORMAT_PATTERN}"'\2|')"
fi
}
######################################################
# Apply configuration to site.conf file
#
conf_siteconf() {
_NCPU=$(grep '^processor' /proc/cpuinfo 2>/dev/null | wc -l)
# Sanity check that we have a valid number, if not then fallback to a safe default
[ "$_NCPU" -ge 1 ] 2>/dev/null || _NCPU=2
cat > conf/site.conf <<EOF
#
# local.conf covers user settings, site.conf covers site specific information
# such as proxy server addresses and optionally any shared download location
#
# SITE_CONF_VERSION is increased each time build/conf/site.conf
# changes incompatibly
SCONF_VERSION = "1"
BB_NUMBER_THREADS = "${_NCPU}"
PARALLEL_MAKE = "-j ${_NCPU}"
# Where to place downloads
DL_DIR = "${DL_DIR}"
# Where to place shared-state files
SSTATE_DIR = "${SSTATE_DIR}"
# Machine Selection
MACHINE = "${MACHINE}"
# Default policy config
DISTRO = "${DISTRO}"
# Package Management configuration
PACKAGE_CLASSES = "package_deb"
# Additional image features
USER_CLASSES = "buildstats"
# Interactive shell configuration
PATCHRESOLVE = "noop"
EOF
}
######################################################
# Update bblayer.conf file
#
update_layerconf() {
cp $1/conf/template/bblayers.conf.sample conf/bblayers.conf
}
######################################################
# Extract description for images provided
#
list_images_descr() {
list_images=$1
if [ "z$ZSH_NAME" != "z" ]; then
# zsh don't split strnig as expected
eval "list_images=($list_images)"
fi
for l in $list_images;
do
local image=`echo $1 | sed -e 's#^./\([^/]*\).bb$#\1#'`
if [ ! -z "$(grep "^SUMMARY[ \t]*=" $1)" ]; then
local descr=`grep "^SUMMARY[ \t]*=" $1 | sed -e 's/^.*"\(.*\)["\]$/\1/'`
else
local descr=`grep "^DESCRIPTION[ \t]*=" $1 | sed -e 's/^.*"\(.*\)["\]$/\1/'`
fi
if [ -z "$descr" ] && [ "$2" == "ERR" ]; then
echo ""
echo "ERROR: No description available for image: $image"
echo "$1"
echo ""
return 1
else
printf " %-33s - $descr\n" $image
fi
done
}
######################################################
# alias function: list all images available
#
list_images() {
local metalayer=$1
if [[ -z $metalayer ]] || ! [[ -e "$ROOT_DIR/$metalayer" ]]; then
echo ""
echo "ERROR: Cannot find layer '$metalayer' at $ROOT_DIR/ root."
echo "Please use full meta layer path from baseline root:"
echo "eg: 'stoe_list_images openembedded-core'"
echo ""
return 1
fi
local LIST=`find $ROOT_DIR/$metalayer/* -wholename "*/images/*.bb" | grep -v meta-skeleton | sort`
echo ""
echo "=========================================================="
echo "Available images for '$metalayer' layer are:"
echo ""
list_images_descr "$LIST" "ERR"
echo ""
}
echo "** DL_DIR: ${DL_DIR}"
echo "** SSTATE_DIR: ${SSTATE_DIR}"
echo "** DISTRO: ${DISTRO}"
echo "** MACHINE: ${MACHINE}"
touch conf/local.conf
if [ -f conf/site.conf ]; then
echo "====> !!!! [WARNING] site.conf already exists. Nothing done ... !!!!"
else
conf_siteconf
fi
update_layerconf ${ROOT_DIR}/${META_DIR}
list_images ${META_DIR}