File indexing completed on 2024-12-22 04:52:18

0001 #!/bin/sh
0002 # -*- mode: shell-script; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
0003 #
0004 # SPDX-FileCopyrightText: 2013 Freescale Semiconductor, Inc.
0005 # SPDX-FileCopyrightText: 2012, 2013 O.S. Systems Software LTDA.
0006 # SPDX-FileContributor: Otavio Salvador <otavio@ossystems.com.br>
0007 # SPDX-FileCopyrightText: 2017 Volker Krause <vkrause@kde.org>
0008 # SPDX-FileCopyrightText: 2022-2023 Andreas Cord-Landwehr <cordlandwehr@kde.org>
0009 #
0010 # SPDX-License-Identifier: GPL-2.0-only
0011 
0012 CWD=$(pwd)
0013 
0014 # identify directory with meta-layers, support both top layer location and nested sources/ structure
0015 SOURCESDIR=${CWD}
0016 if [ -e "${CWD}/sources" ]; then
0017     SOURCESDIR=${CWD}/sources
0018 fi
0019 
0020 THIS_SCRIPT="setup-environment"
0021 if [ "$(basename -- $0)" = "${THIS_SCRIPT}" ]; then
0022     echo "Error: This script needs to be sourced. Please run as '. $0'"
0023     return 1
0024 fi
0025 
0026 LIST_MACHINES=$(ls -1 ${SOURCESDIR}/*/conf/machine)
0027 
0028 usage()
0029 {
0030     echo -e "\nUsage: . ${THIS_SCRIPT} <build-dir>
0031     <build-dir>: specifies the build directory location (required)
0032 
0033 If undefined, this script will set \$MACHINE to 'raspberrypi'.
0034 
0035 Supported machines: $(echo; \
0036     echo ${LIST_MACHINES} \
0037     | sed s/\.conf//g | sed -r 's/^.+\///' | xargs -I% echo -e "\t%")
0038 
0039 To build for a machine listed above, run this script as:
0040 MACHINE=<machine> . ${THIS_SCRIPT} <build-dir>
0041 "
0042 }
0043 
0044 clean_up()
0045 {
0046     unset BUILDDIRECTORY CWD SOURCES TEMPLATES LIST_MACHINES VALID_MACHINE QT6_BUILD
0047     unset MACHINE SDKMACHINE DISTRO OEROOT
0048     unset generated_config updated
0049 }
0050 
0051 QT6_BUILD=false
0052 FORCE_RECONFIGURE=false
0053 
0054 # get command line options
0055 while test -n "${1}";
0056 do
0057     case $1 in
0058         -h|--help)
0059            usage
0060            clean_up
0061            return 0
0062            ;;
0063         -f)
0064             echo "Force generation of local.conf and bblayers.conf"
0065            FORCE_RECONFIGURE=true
0066            ;;
0067         --qt6)
0068            echo "Configure for Qt6 based build"
0069            QT6_BUILD=true
0070            ;;
0071         *)
0072            BUILDDIRECTORY=$1
0073            ;;
0074     esac
0075     shift
0076 done
0077 
0078 if [ "$(whoami)" = "root" ]; then
0079     echo "ERROR: do not use the BSP as root. Exiting..."
0080 fi
0081 
0082 if [ -z "$MACHINE" ]; then
0083     echo "WARNING: no MACHINE variable set, defaulting to MACHINE=raspberrypi4"
0084     MACHINE='raspberrypi4'
0085 fi
0086 
0087 BUILDDIRECTORY=${BUILDDIRECTORY:-build-${MACHINE}}
0088 
0089 # Check the machine type specified
0090 VALID_MACHINE=$(echo -e "${LIST_MACHINES}" | grep ${MACHINE}.conf$ | wc -l)
0091 if [ "x$MACHINE" = "x" ] || [ "$VALID_MACHINE" = "0" ]; then
0092     echo -e "\nThe \$MACHINE you have specified ($MACHINE) is not supported by this build setup"
0093     usage && clean_up
0094     return 1
0095 else
0096     if [ ! -e ${BUILDDIRECTORY}/conf/local.conf.sample ]; then
0097         echo "Configuring for ${MACHINE}"
0098     fi
0099 fi
0100 
0101 if [ -z "$SDKMACHINE" ]; then
0102     SDKMACHINE='x86_64'
0103 fi
0104 
0105 if [ -z "$DISTRO" ]; then
0106     DISTRO='kde-linux'
0107 fi
0108 
0109 # Clean up PATH, because if it includes tokens to current directories somehow,
0110 # wrong binaries can be used instead of the expected ones during task execution
0111 export PATH="`echo $PATH | sed 's/\(:.\|:\)*:/:/g;s/^.\?://;s/:.\?$//'`"
0112 
0113 generated_config=
0114 if [ ! -d "${CWD}/${BUILDDIRECTORY}/conf" ] || [ ${FORCE_RECONFIGURE} = true ]; then
0115     echo "Prepare initial build configuration directory: ${BUILDDIRECTORY}/conf"
0116     QT_SUFFIX=""
0117     if [ ${QT6_BUILD} = true ]; then
0118         QT_SUFFIX="-qt6"
0119     fi
0120 
0121     # generate bblayers for specific hardware variant
0122     case ${MACHINE} in
0123         raspberrypi*)
0124             LAYERSCONF="bblayers.conf.rpi${QT_SUFFIX}.sample"
0125             ;;
0126         visionfive2*)
0127             LAYERSCONF="bblayers.conf.visionfive2${QT_SUFFIX}.sample"
0128             ;;
0129         *)
0130             LAYERSCONF="bblayers.conf.sample"
0131             ;;
0132     esac
0133 
0134     # Generate the local.conf based on the Yocto defaults
0135     TEMPLATESDIR=${SOURCESDIR}/meta-kde-demo/templates
0136 
0137     LAYERSCONF=${TEMPLATESDIR}/${LAYERSCONF}
0138     if [ ! -e ${LAYERSCONF} ]; then
0139         echo "ERROR: Layer configuration file missing: '${LAYERSCONF}'"
0140         return 1
0141     fi
0142     mkdir -p ${CWD}/${BUILDDIRECTORY}/conf
0143     cp ${LAYERSCONF} ${CWD}/${BUILDDIRECTORY}/conf/bblayers.conf
0144 
0145     # Generate local.conf from poky example
0146     if [ -f ${SOURCESDIR}/poky/meta-poky/conf/local.conf.sample ]; then
0147         cp ${SOURCESDIR}/poky/meta-poky/conf/local.conf.sample ${CWD}/${BUILDDIRECTORY}/conf/local.conf.sample
0148     fi
0149     if [ -f ${SOURCESDIR}/poky/meta-poky/conf/templates/default/local.conf.sample ]; then
0150         cp ${SOURCESDIR}/poky/meta-poky/conf/templates/default/local.conf.sample ${CWD}/${BUILDDIRECTORY}/conf/local.conf.sample
0151     fi
0152     grep -v '^#\|^$' ${CWD}/${BUILDDIRECTORY}/conf/local.conf.sample > ${CWD}/${BUILDDIRECTORY}/conf/local.conf
0153     sed -e "s,MACHINE ??=.*,MACHINE ??= '$MACHINE',g" \
0154         -e "s,SDKMACHINE ??=.*,SDKMACHINE ??= '$SDKMACHINE',g" \
0155         -e "s,DISTRO ?=.*,DISTRO ?= '$DISTRO',g" \
0156         -i ${CWD}/${BUILDDIRECTORY}/conf/local.conf
0157 
0158     # allow building of ffmpeg
0159     echo "LICENSE_FLAGS_ACCEPTED=\"commercial\"" >> ${CWD}/${BUILDDIRECTORY}/conf/local.conf
0160 
0161     for s in $HOME/.oe $HOME/.yocto; do
0162         if [ -e $s/site.conf ]; then
0163             echo "Linking $s/site.conf to conf/site.conf"
0164             ln -s $s/site.conf conf
0165         fi
0166     done
0167 
0168     generated_config=1
0169 fi
0170 
0171 cat <<EOF
0172 
0173 Welcome to KDE Demo BSP
0174 
0175 The Yocto Project has extensive documentation about OE including a
0176 reference manual which can be found at:
0177     http://yoctoproject.org/documentation
0178 
0179 For more information about OpenEmbedded see their website:
0180     http://www.openembedded.org/
0181 
0182 You can now run 'bitbake <target>'
0183 
0184 Common targets are:
0185     kde-demo-image
0186 
0187 EOF
0188 
0189 if [ -n "$generated_config" ]; then
0190     cat <<EOF
0191 Your build environment has been configured at ${BUILDDIRECTORY} with:
0192 
0193     MACHINE=$MACHINE
0194     SDKMACHINE=$SDKMACHINE
0195     DISTRO=$DISTRO
0196 EOF
0197 else
0198     echo "Your configuration files at ${BUILDDIRECTORY} have not been touched."
0199 fi
0200 
0201 OEROOT=$(readlink -f ${SOURCESDIR}/poky)
0202 cd ${OEROOT}
0203 . ${OEROOT}/oe-init-build-env ${CWD}/${BUILDDIRECTORY} > /dev/null
0204 
0205 clean_up