]> git.karo-electronics.de Git - meta-tx09.git/blob - setup-environment
topas910: add support for old topas910 eval board
[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: 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 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 cat <<EOF
183
184 Welcome to kernel concepts custom BSP
185
186 The Yocto Project has extensive documentation about OE including a
187 reference manual which can be found at:
188     http://yoctoproject.org/documentation
189
190 For more information about OpenEmbedded see their website:
191     http://www.openembedded.org/
192
193 You can now run 'bitbake <target>'
194
195 Common targets are:
196
197 EOF
198
199 if [ -z "$COMMON_TARGETS" ]; then
200
201 echo    core-image-minimal
202 echo    meta-toolchain
203
204 else
205
206 echo "$COMMON_TARGETS"
207
208 fi
209
210
211 if [ -n "$generated_config" ]; then
212     cat <<EOF
213 Your build environment has been configured with:
214
215     MACHINE=$MACHINE
216     DISTRO=$DISTRO
217
218 EOF
219 else
220     echo "Your configuration files at $1 have not been touched."
221     echo
222 fi
223
224 clean_up