]> git.kernelconcepts.de Git - meta-kc-bsp.git/blob - setup-environment
dotsplash: pull themes package into image
[meta-kc-bsp.git] / setup-environment
1 #!/bin/sh
2 # -*- mode: shell-script; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 #
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
7 #
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.
11 #
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.
16 #
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.
20 #
21 # Add options for the script
22 # Copyright (C) 2013 Freescale Semiconductor, Inc.
23
24 CWD=`pwd`
25 PROGNAME="setup-environment"
26
27 usage()
28 {
29     echo -e "
30 Usage: MACHINE=<machine> DISTRO=<distro> source $PROGNAME <build-dir>
31 Usage:                                   source $PROGNAME <build-dir>
32     <machine>    machine name
33     <distro>     distro name
34     <build-dir>  build directory
35
36 The first usage is for creating a new build directory. In this case, the
37 script creates the build directory <build-dir>, configures it for the
38 specified <machine> and <distro>, and prepares the calling shell for running
39 bitbake on the build directory.
40
41 The second usage is for using an existing build directory. In this case,
42 the script prepares the calling shell for running bitbake on the build
43 directory <build-dir>. The build directory configuration is unchanged.
44 "
45
46     ls yocto/*/conf/machine/*.conf > /dev/null 2>&1
47 #    ls sources/meta-freescale-distro/conf/distro/fslc-*.conf > /dev/null 2>&1
48     if [ $? -eq 0 ]; then
49         echo -e "
50 Supported machines: `echo; ls conf/*/conf/machine/*.conf \
51 | sed s/\.conf//g | sed -r 's/^.+\///' | xargs -I% echo -e "\t%"`
52
53 Available Poky's distros: `echo; ls yocto/poky/meta-poky/conf/distro/*.conf \
54 | sed s/\.conf//g | sed -r 's/^.+\///' | xargs -I% echo -e "\t%"`
55
56 Examples:
57
58 - To create a new Yocto build directory:
59   $ MACHINE=tx6q-xxxx DISTRO=poky . $PROGNAME build
60
61 - To use an existing Yocto build directory:
62   $ . $PROGNAME build
63 "
64     fi
65 }
66
67 clean_up()
68 {
69    unset EULA LIST_MACHINES VALID_MACHINE
70    unset CWD TEMPLATES SHORTOPTS LONGOPTS ARGS PROGNAME
71    unset generated_config updated
72    unset MACHINE SDKMACHINE DISTRO OEROOT
73 }
74
75 # source default sdk configuration
76 if [ -e sdkdefaults.conf ]; then
77 . sdkdefaults.conf
78 fi
79
80
81 # get command line options
82 SHORTOPTS="h"
83 LONGOPTS="help"
84
85 ARGS=$(getopt --options $SHORTOPTS  \
86   --longoptions $LONGOPTS --name $PROGNAME -- "$@" )
87 # Print the usage menu if invalid options are specified
88 if [ $? != 0 -o $# -lt 1 ]; then
89    usage && clean_up
90    return 1
91 fi
92
93 eval set -- "$ARGS"
94 while true;
95 do
96     case $1 in
97         -h|--help)
98            usage
99            clean_up
100            return 0
101            ;;
102         --)
103            shift
104            break
105            ;;
106     esac
107 done
108
109 if [ "$(whoami)" = "root" ]; then
110     echo "ERROR: do not use the BSP as root. Exiting..."
111 fi
112
113 if [ ! -e $1/conf/local.conf.sample ]; then
114     build_dir_setup_enabled="true"
115 else
116     build_dir_setup_enabled="false"
117 fi
118
119 if [ "$build_dir_setup_enabled" = "true" ] && [ -z "$MACHINE" ]; then
120     usage
121     echo -e "ERROR: You must set MACHINE when creating a new build directory."
122     clean_up
123     return 1
124 fi
125
126 if [ -z "$SDKMACHINE" ]; then
127     SDKMACHINE='i686'
128 fi
129
130 if [ "$build_dir_setup_enabled" = "true" ] && [ -z "$DISTRO" ]; then
131     usage
132     echo -e "ERROR: You must set DISTRO when creating a new build directory."
133     clean_up
134     return 1
135 fi
136
137
138 OEROOT=$PWD/yocto/poky
139 if [ -e $PWD/yocto/oe-core ]; then
140     OEROOT=$PWD/yocto/oe-core
141 fi
142
143 . $OEROOT/oe-init-build-env $CWD/$1 > /dev/null
144
145 # if conf/local.conf not generated, no need to go further
146 if [ ! -e conf/local.conf ]; then
147     clean_up && return 1
148 fi
149
150 # Clean up PATH, because if it includes tokens to current directories somehow,
151 # wrong binaries can be used instead of the expected ones during task execution
152 export PATH="`echo $PATH | sed 's/\(:.\|:\)*:/:/g;s/^.\?://;s/:.\?$//'`"
153
154 generated_config=
155 if [ "$build_dir_setup_enabled" = "true" ]; then
156     mv conf/local.conf conf/local.conf.sample
157
158     # Generate the local.conf based on the Yocto defaults
159     TEMPLATES=$CWD/yocto/meta-kc-bsp/conf
160     grep -v '^#\|^$' conf/local.conf.sample > conf/local.conf
161     cat >> conf/local.conf <<EOF
162
163 DL_DIR ?= "\${BSPDIR}/downloads/"
164 EOF
165     # Change settings according environment
166     sed -e "s,^ *MACHINE ?=.*,MACHINE ?= '$MACHINE',g" \
167         -e "s,DISTRO ?=.*,DISTRO ?= '$DISTRO',g" \
168         -i conf/local.conf
169
170     cp $TEMPLATES/* conf/
171
172     for s in $HOME/.oe $HOME/.yocto; do
173         if [ -e $s/site.conf ]; then
174             echo "Linking $s/site.conf to conf/site.conf"
175             ln -s $s/site.conf conf
176         fi
177     done
178
179     generated_config=1
180 fi
181
182 # Handle EULA setting
183 EULA_ACCEPTED=
184
185 # EULA has been accepted already (ACCEPT_FSL_EULA is set in local.conf)
186 if grep -q '^\s*ACCEPT_FSL_EULA\s*=\s*["'\'']..*["'\'']' conf/local.conf; then
187     EULA_ACCEPTED=1
188 fi
189
190 if [ -z "$EULA_ACCEPTED" ] && [ -n "$EULA" ]; then
191     # The FSL EULA is not set as accepted in local.conf, but the EULA
192     # variable is set in the environment, so we just configure
193     # ACCEPT_FSL_EULA in local.conf according to $EULA.
194     echo "ACCEPT_FSL_EULA = \"$EULA\"" >> conf/local.conf
195 elif [ -n "$EULA_ACCEPTED" ]; then
196     # The FSL EULA has been accepted once, so ACCEPT_FSL_EULA is set
197     # in local.conf.  No need to do anything.
198     :
199 else
200     # THE FSL EULA is not set as accepted in local.conf, and EULA is
201     # not set in the environment, so we need to ask user if he/she
202     # accepts the FSL EULA:
203     cat <<EOF
204
205 Some BSPs depend on libraries and packages which are covered by Freescale's
206 End User License Agreement (EULA). To have the right to use these binaries in
207 your images, you need to read and accept the following...
208
209 EOF
210
211     sleep 4
212
213     more -d $CWD/yocto/meta-freescale/EULA
214     echo
215     REPLY=
216     while [ -z "$REPLY" ]; do
217         echo -n "Do you accept the EULA you just read? (y/n) "
218         read REPLY
219         case "$REPLY" in
220             y|Y)
221             echo "EULA has been accepted."
222             echo "ACCEPT_FSL_EULA = \"1\"" >> conf/local.conf
223             ;;
224             n|N)
225             echo "EULA has not been accepted."
226             ;;
227             *)
228             REPLY=
229             ;;
230         esac
231     done
232 fi
233
234 cat <<EOF
235
236 Welcome to kernel concepts custom BSP
237
238 The Yocto Project has extensive documentation about OE including a
239 reference manual which can be found at:
240     http://yoctoproject.org/documentation
241
242 For more information about OpenEmbedded see their website:
243     http://www.openembedded.org/
244
245 You can now run 'bitbake <target>'
246
247 Common targets are:
248     core-image-minimal
249     meta-toolchain
250     meta-toolchain-sdk
251     adt-installer
252     meta-ide-support
253
254 EOF
255
256 if [ -n "$generated_config" ]; then
257     cat <<EOF
258 Your build environment has been configured with:
259
260     MACHINE=$MACHINE
261     DISTRO=$DISTRO
262     EULA=$EULA
263 EOF
264 else
265     echo "Your configuration files at $1 have not been touched."
266 fi
267
268 clean_up