]> git.kernelconcepts.de Git - meta-tx09.git/blob - setup-environment
topasa900: fix UBI header offset and leb size, add initial definitions for u-boot...
[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 #    ls sources/meta-freescale-distro/conf/distro/fslc-*.conf > /dev/null 2>&1
50     if [ $? -eq 0 ]; then
51         echo -e "
52 Supported machines: `echo; ls conf/*/conf/machine/*.conf \
53 | sed s/\.conf//g | sed -r 's/^.+\///' | xargs -I% echo -e "\t%"`
54
55 Available Poky's distros: `echo; ls yocto/poky/meta-poky/conf/distro/*.conf \
56 | sed s/\.conf//g | sed -r 's/^.+\///' | xargs -I% echo -e "\t%"`
57
58 Examples:
59
60 - To use an existing Yocto build directory or create a new buil dir using 
61   the supplied defaults.
62   $ . $PROGNAME build
63   
64 - To create a new Yocto build directory:
65   $ MACHINE=tx6q-xxxx DISTRO=poky . $PROGNAME build
66
67 "
68     fi
69 }
70
71 clean_up()
72 {
73    unset LIST_MACHINES VALID_MACHINE
74    unset CWD TEMPLATES SHORTOPTS LONGOPTS ARGS PROGNAME
75    unset generated_config updated
76    unset MACHINE SDKMACHINE DISTRO OEROOT
77 }
78
79 # source default sdk configuration
80 if [ -e sdkdefaults.conf ]; then
81 . sdkdefaults.conf
82 fi
83
84
85 # get command line options
86 SHORTOPTS="h"
87 LONGOPTS="help"
88
89 ARGS=$(getopt --options $SHORTOPTS  \
90   --longoptions $LONGOPTS --name $PROGNAME -- "$@" )
91 # Print the usage menu if invalid options are specified
92 if [ $? != 0 -o $# -lt 1 ]; then
93    usage && clean_up
94    return 1
95 fi
96
97 eval set -- "$ARGS"
98 while true;
99 do
100     case $1 in
101         -h|--help)
102            usage
103            clean_up
104            return 0
105            ;;
106         --)
107            shift
108            break
109            ;;
110     esac
111 done
112
113 if [ "$(whoami)" = "root" ]; then
114     echo "ERROR: do not use the BSP as root. Exiting..."
115 fi
116
117 if [ ! -e $1/conf/local.conf.sample ]; then
118     build_dir_setup_enabled="true"
119 else
120     build_dir_setup_enabled="false"
121 fi
122
123 if [ "$build_dir_setup_enabled" = "true" ] && [ -z "$MACHINE" ]; then
124     usage
125     echo -e "ERROR: You must set MACHINE when creating a new build directory."
126     clean_up
127     return 1
128 fi
129
130 if [ -z "$SDKMACHINE" ]; then
131     SDKMACHINE='i686'
132 fi
133
134 if [ "$build_dir_setup_enabled" = "true" ] && [ -z "$DISTRO" ]; then
135     usage
136     echo -e "ERROR: You must set DISTRO when creating a new build directory."
137     clean_up
138     return 1
139 fi
140
141
142 OEROOT=$PWD/yocto/poky
143 if [ -e $PWD/yocto/oe-core ]; then
144     OEROOT=$PWD/yocto/oe-core
145 fi
146
147 . $OEROOT/oe-init-build-env $CWD/$1 > /dev/null
148
149 # if conf/local.conf not generated, no need to go further
150 if [ ! -e conf/local.conf ]; then
151     clean_up && return 1
152 fi
153
154 # Clean up PATH, because if it includes tokens to current directories somehow,
155 # wrong binaries can be used instead of the expected ones during task execution
156 export PATH="`echo $PATH | sed 's/\(:.\|:\)*:/:/g;s/^.\?://;s/:.\?$//'`"
157
158 generated_config=
159 if [ "$build_dir_setup_enabled" = "true" ]; then
160     mv conf/local.conf conf/local.conf.sample
161
162     # Generate the local.conf based on the Yocto defaults
163     TEMPLATES=$CWD/yocto/meta-kc-bsp/conf
164     cat conf/local.conf.sample > conf/local.conf
165     cat >> conf/local.conf <<EOF
166
167 DL_DIR ?= "\${BSPDIR}/downloads/"
168 EOF
169     # Change settings according environment
170     sed -e "s,MACHINE ?=.*,MACHINE ?= '$MACHINE',g" \
171         -e "s,DISTRO ?=.*,DISTRO ?= '$DISTRO',g" \
172         -i conf/local.conf
173
174     cp $TEMPLATES/* conf/
175
176     for s in $HOME/.oe $HOME/.yocto; do
177         if [ -e $s/site.conf ]; then
178             echo "Linking $s/site.conf to conf/site.conf"
179             ln -s $s/site.conf conf
180         fi
181     done
182
183     generated_config=1
184 fi
185
186 cat <<EOF
187
188 Welcome to kernel concepts custom BSP
189
190 The Yocto Project has extensive documentation about OE including a
191 reference manual which can be found at:
192     http://yoctoproject.org/documentation
193
194 For more information about OpenEmbedded see their website:
195     http://www.openembedded.org/
196
197 You can now run 'bitbake <target>'
198
199 Common targets are:
200
201 EOF
202
203 if [ -z "$COMMON_TARGETS" ]; then
204
205 echo    core-image-minimal
206 echo    meta-toolchain
207
208 else
209
210 echo "$COMMON_TARGETS"
211
212 fi
213
214
215 if [ -n "$generated_config" ]; then
216     cat <<EOF
217 Your build environment has been configured with:
218
219     MACHINE=$MACHINE
220     DISTRO=$DISTRO
221
222 EOF
223 else
224     echo "Your configuration files at $1 have not been touched."
225     echo
226 fi
227
228 clean_up