]> git.kernelconcepts.de Git - meta-tx09.git/blob - setup-environment
setup-environment: update descriptions
[meta-tx09.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: . $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
36
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.
42
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.
46 "
47
48     ls yocto/*/conf/machine/*.conf > /dev/null 2>&1
49     if [ $? -eq 0 ]; then
50         echo -e "
51 Supported machines: `echo; ls conf/*/conf/machine/*.conf \
52 | sed s/\.conf//g | sed -r 's/^.+\///' | xargs -I% echo -e "\t%"`
53
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%"`
56
57 Examples:
58
59 - To use an existing Yocto build directory or create a new build dir using 
60   the supplied defaults.
61   $ . $PROGNAME build
62   
63 - To create a new Yocto build directory with custom defaults:
64   $ MACHINE=tx6q-xxxx DISTRO=poky . $PROGNAME build
65
66 "
67     fi
68 }
69
70 clean_up()
71 {
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
76 }
77
78 # source default sdk configuration
79 if [ -e sdkdefaults.conf ]; then
80 . sdkdefaults.conf
81 fi
82
83
84 # get command line options
85 SHORTOPTS="h"
86 LONGOPTS="help"
87
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
92    usage && clean_up
93    return 1
94 fi
95
96 eval set -- "$ARGS"
97 while true;
98 do
99     case $1 in
100         -h|--help)
101            usage
102            clean_up
103            return 0
104            ;;
105         --)
106            shift
107            break
108            ;;
109     esac
110 done
111
112 if [ "$(whoami)" = "root" ]; then
113     echo "ERROR: do not use the BSP as root. Exiting..."
114 fi
115
116 if [ ! -e $1/conf/local.conf.sample ]; then
117     build_dir_setup_enabled="true"
118 else
119     build_dir_setup_enabled="false"
120 fi
121
122 if [ "$build_dir_setup_enabled" = "true" ] && [ -z "$MACHINE" ]; then
123     usage
124     echo -e "ERROR: You must set MACHINE when creating a new build directory."
125     clean_up
126     return 1
127 fi
128
129 if [ -z "$SDKMACHINE" ]; then
130     SDKMACHINE='i686'
131 fi
132
133 if [ "$build_dir_setup_enabled" = "true" ] && [ -z "$DISTRO" ]; then
134     usage
135     echo -e "ERROR: You must set DISTRO when creating a new build directory."
136     clean_up
137     return 1
138 fi
139
140
141 OEROOT=$PWD/yocto/poky
142 if [ -e $PWD/yocto/oe-core ]; then
143     OEROOT=$PWD/yocto/oe-core
144 fi
145
146 . $OEROOT/oe-init-build-env $CWD/$1 > /dev/null
147
148 # if conf/local.conf not generated, no need to go further
149 if [ ! -e conf/local.conf ]; then
150     clean_up && return 1
151 fi
152
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/:.\?$//'`"
156
157 generated_config=
158 if [ "$build_dir_setup_enabled" = "true" ]; then
159     mv conf/local.conf conf/local.conf.sample
160
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
165
166 DL_DIR ?= "\${BSPDIR}/downloads/"
167 EOF
168     # Change settings according environment
169     sed -e "s,MACHINE ?=.*,MACHINE ?= '$MACHINE',g" \
170         -e "s,DISTRO ?=.*,DISTRO ?= '$DISTRO',g" \
171         -i conf/local.conf
172
173     cp $TEMPLATES/* conf/
174
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
179         fi
180     done
181
182     generated_config=1
183 fi
184
185 cat <<EOF
186
187 Welcome to kernel concepts custom BSP
188
189 The Yocto Project has extensive documentation about OE including a
190 reference manual which can be found at:
191     http://yoctoproject.org/documentation
192
193 For more information about OpenEmbedded see their website:
194     http://www.openembedded.org/
195
196 You can now run 'bitbake <target>'
197
198 Common targets are:
199
200 EOF
201
202 if [ -z "$COMMON_TARGETS" ]; then
203
204 echo    core-image-minimal
205 echo    meta-toolchain
206
207 else
208
209 echo "$COMMON_TARGETS"
210
211 fi
212
213
214 if [ -n "$generated_config" ]; then
215     cat <<EOF
216 Your build environment has been configured with:
217
218     MACHINE=$MACHINE
219     DISTRO=$DISTRO
220
221 EOF
222 else
223     echo "Your configuration files at $1 have not been touched."
224     echo
225 fi
226
227 # indicate Yocto environment on shell prompt
228 export PS1="[yocto] $PS1"
229
230 clean_up