2 # -*- mode: shell-script; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
4 # Copyright (C) 2012, 2013, 2016 O.S. Systems Software LTDA.
5 # Authored-by: Otavio Salvador <otavio@ossystems.com.br>
6 # Copyright (C) 2018 kernel concepts GmbH
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License version 2 as
10 # published by the Free Software Foundation.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 # Add options for the script
22 # Copyright (C) 2013 Freescale Semiconductor, Inc.
25 PROGNAME="setup-environment"
30 Usage: . $PROGNAME <build-dir>
31 Usage: MACHINE=<machine> DISTRO=<distro> source $PROGNAME <build-dir>
32 Usage: source $PROGNAME <build-dir>
33 <machine> machine name
34 <distro> distribution name
35 <build-dir> build directory
37 The first usage is for creating a new build directory. In this case, the
38 script creates the build directory <build-dir> and confgures it according
39 to the supplied sdkdefaults.conf. Optionally it configures it for the
40 specified <machine> and <distro>, and prepares the calling shell for running
41 bitbake on the build directory.
43 The second usage is for using an existing build directory. In this case,
44 the script prepares the calling shell for running bitbake on the build
45 directory <build-dir>. The build directory configuration is unchanged.
48 ls yocto/*/conf/machine/*.conf > /dev/null 2>&1
51 Supported machines: `echo; ls conf/*/conf/machine/*.conf \
52 | sed s/\.conf//g | sed -r 's/^.+\///' | xargs -I% echo -e "\t%"`
54 Available Poky's distros: `echo; ls yocto/poky/meta-poky/conf/distro/*.conf \
55 | sed s/\.conf//g | sed -r 's/^.+\///' | xargs -I% echo -e "\t%"`
59 - To use an existing Yocto build directory or create a new build dir using
60 the supplied defaults.
63 - To create a new Yocto build directory with custom defaults:
64 $ MACHINE=tx6q-xxxx DISTRO=poky . $PROGNAME build
72 unset LIST_MACHINES VALID_MACHINE
73 unset CWD TEMPLATES SHORTOPTS LONGOPTS ARGS PROGNAME
74 unset generated_config updated
75 unset MACHINE SDKMACHINE DISTRO OEROOT
78 # source default sdk configuration
79 if [ -e sdkdefaults.conf ]; then
84 # get command line options
88 ARGS=$(getopt --options $SHORTOPTS \
89 --longoptions $LONGOPTS --name $PROGNAME -- "$@" )
90 # Print the usage menu if invalid options are specified
91 if [ $? != 0 -o $# -lt 1 ]; then
112 if [ "$(whoami)" = "root" ]; then
113 echo "ERROR: do not use the BSP as root. Exiting..."
116 if [ ! -e $1/conf/local.conf.sample ]; then
117 build_dir_setup_enabled="true"
119 build_dir_setup_enabled="false"
122 if [ "$build_dir_setup_enabled" = "true" ] && [ -z "$MACHINE" ]; then
124 echo -e "ERROR: You must set MACHINE when creating a new build directory."
129 if [ -z "$SDKMACHINE" ]; then
133 if [ "$build_dir_setup_enabled" = "true" ] && [ -z "$DISTRO" ]; then
135 echo -e "ERROR: You must set DISTRO when creating a new build directory."
141 OEROOT=$PWD/yocto/poky
142 if [ -e $PWD/yocto/oe-core ]; then
143 OEROOT=$PWD/yocto/oe-core
146 . $OEROOT/oe-init-build-env $CWD/$1 > /dev/null
148 # if conf/local.conf not generated, no need to go further
149 if [ ! -e conf/local.conf ]; then
153 # Clean up PATH, because if it includes tokens to current directories somehow,
154 # wrong binaries can be used instead of the expected ones during task execution
155 export PATH="`echo $PATH | sed 's/\(:.\|:\)*:/:/g;s/^.\?://;s/:.\?$//'`"
158 if [ "$build_dir_setup_enabled" = "true" ]; then
159 mv conf/local.conf conf/local.conf.sample
161 # Generate the local.conf based on the Yocto defaults
162 TEMPLATES=$CWD/yocto/meta-kc-bsp/conf
163 cat conf/local.conf.sample > conf/local.conf
164 cat >> conf/local.conf <<EOF
166 DL_DIR ?= "\${BSPDIR}/downloads/"
168 # Change settings according environment
169 sed -e "s,MACHINE ?=.*,MACHINE ?= '$MACHINE',g" \
170 -e "s,DISTRO ?=.*,DISTRO ?= '$DISTRO',g" \
173 cp $TEMPLATES/* conf/
175 for s in $HOME/.oe $HOME/.yocto; do
176 if [ -e $s/site.conf ]; then
177 echo "Linking $s/site.conf to conf/site.conf"
178 ln -s $s/site.conf conf
187 Welcome to kernel concepts custom BSP
189 The Yocto Project has extensive documentation about OE including a
190 reference manual which can be found at:
191 http://yoctoproject.org/documentation
193 For more information about OpenEmbedded see their website:
194 http://www.openembedded.org/
196 You can now run 'bitbake <target>'
202 if [ -z "$COMMON_TARGETS" ]; then
204 echo core-image-minimal
209 echo "$COMMON_TARGETS"
214 if [ -n "$generated_config" ]; then
216 Your build environment has been configured with:
223 echo "Your configuration files at $1 have not been touched."
227 # indicate Yocto environment on shell prompt
228 export PS1="[yocto] $PS1"