-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsetup-environment
executable file
·223 lines (187 loc) · 6.25 KB
/
setup-environment
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/bin/sh
# -*- mode: shell-script; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
#
# Copyright (C) 2012, 2013, 2016 O.S. Systems Software LTDA.
# Authored-by: Otavio Salvador <otavio@ossystems.com.br>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Add options for the script
# Copyright (C) 2013 Freescale Semiconductor, Inc.
# Copyright (C) 2017 Rockchip, Inc.
CWD=`pwd`
PROGNAME="setup-environment"
PACKAGE_CLASSES="package_deb"
BUILD_DIR=""
usage()
{
echo -e "\nUsage: source $PROGNAME -b <build-dir>
<build-dir>: specifies the build directory location (required)
If undefined, this script will set \$MACHINE to 'evb-rk3288'\$DISTRO to 'rk-x11'.
"
ls sources/*/conf/machine/*.conf sources/*/*/conf/machine/*.conf > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo -e "
Supported machines: `echo; ls sources/*/conf/machine/*.conf sources/*/*/conf/machine/*.conf \
| sed s/\.conf//g | sed -r 's/^.+\///' | xargs -I% echo -e "\t%"`
Supported distros: `echo; ls sources/*/conf/distro/*.conf sources/*/*/conf/distro/*.conf \
| sed s/\.conf//g | sed -r 's/^.+\///' | xargs -I% echo -e "\t%"`
You can run this script as:
MACHINE=<machine> DISTRO=<DISTRO> source $PROGNAME -b <build-dir>
"
fi
}
clean_up()
{
unset LIST_MACHINES VALID_MACHINE
unset CWD TEMPLATES SHORTOPTS LONGOPTS ARGS PROGNAME
unset generated_config updated
unset MACHINE SDKMACHINE DISTRO OEROOT
unset rockchip_flag
}
# get command line options
OLD_OPTIND=$OPTIND
while getopts "e:h:b:gh" rockchip_flag
do
case $rockchip_flag in
h)
usage
clean_up
return 0
;;
b)
BUILD_DIR="$OPTARG"
;;
?)
usage
clean_up
return 0
;;
esac
done
OPTIND=$OLD_OPTIND
# Print the usage menu if invalid options are specified
if [ "${BUILD_DIR}" = "" ]; then
echo "WARNING: <build-dir> undefined, use build as default dir"
BUILD_DIR="build"
fi
if [ "$(whoami)" = "root" ]; then
echo "ERROR: do not use the BSP as root. Exiting..."
fi
if [ -z "$MACHINE" ]; then
MACHINE='evb-rk3288'
echo "WARNING: <machine> undefined, use evb-rk3288 as default machine"
fi
# Check the machine type specified
LIST_MACHINES=`ls -1 $CWD/sources/*/conf/machine $CWD/sources/*/*/conf/machine/`
VALID_MACHINE=`echo -e "$LIST_MACHINES" | grep ${MACHINE}.conf$ | wc -l`
if [ "x$MACHINE" = "x" ] || [ "$VALID_MACHINE" = "0" ]; then
echo -e "\nThe \$MACHINE you have specified ($MACHINE) is not supported by this build setup"
usage && clean_up
return 1
else
if [ ! -e $BUILD_DIR/conf/local.conf.sample ]; then
echo "Configuring for ${MACHINE}"
fi
fi
if [ -z "$DISTRO" ]; then
DISTRO='rk-x11'
fi
LIST_DISTRO=`ls -1 $CWD/sources/*/conf/distro $CWD/sources/*/*/conf/distro/`
VALID_DISTRO=`echo -e "$LIST_DISTRO" | grep ${DISTRO}.conf$ | wc -l`
if [ "x$DISTRO" = "x" ] || [ "$VALID_DISTRO" = "0" ]; then
echo -e "\nThe \$DISTRO you have specified ($DISTRO) is not supported by this build setup"
usage && clean_up
return 1
fi
if [ -z "$SDKMACHINE" ]; then
SDKMACHINE='i686'
fi
OEROOT=$PWD/sources/poky
if [ -e $PWD/sources/oe-core ]; then
OEROOT=$PWD/sources/oe-core
fi
# Ensure all files in sources/base are kept in sync with project root
updated=
for f in $CWD/sources/base/*; do
file="$(basename $f)"
if [ "$file" = "conf" ] || echo $file | grep -q '~$'; then
continue
fi
if ! cmp -s "$file" "$f"; then
updated="true"
[ -e $file ] && chmod u+w $file
cp $f $file
fi
done
if [ "$updated" = "true" ]; then
echo "The project root content has been updated. Please run '$PROGNAME' again."
return
fi
. $OEROOT/oe-init-build-env $CWD/$BUILD_DIR > /dev/null
# if conf/local.conf not generated, no need to go further
if [ ! -e conf/local.conf ]; then
clean_up && return 1
fi
# Clean up PATH, because if it includes tokens to current directories somehow,
# wrong binaries can be used instead of the expected ones during task execution
export PATH="`echo $PATH | sed 's/\(:.\|:\)*:/:/g;s/^.\?://;s/:.\?$//'`"
generated_config=
if [ ! -e conf/local.conf.sample ]; then
mv conf/local.conf conf/local.conf.sample
# Generate the local.conf based on the Yocto defaults
TEMPLATES=$CWD/sources/base/conf
grep -v '^#\|^$' conf/local.conf.sample > conf/local.conf
cat >> conf/local.conf <<EOF
DL_DIR ?= "\${BSPDIR}/downloads/"
EOF
# Change settings according environment
sed -e "s,MACHINE ??=.*,MACHINE ??= '$MACHINE',g" \
-e "s,SDKMACHINE ??=.*,SDKMACHINE ??= '$SDKMACHINE',g" \
-e "s,DISTRO ?=.*,DISTRO ?= '$DISTRO',g" \
-e "s,PACKAGE_CLASSES ?=.*,PACKAGE_CLASSES ?= '$PACKAGE_CLASSES',g" \
-i conf/local.conf
if [[ ${DISTRO:0:2} == "rv" ]];then
cp $TEMPLATES/bblayers_rv.conf conf/bblayers.conf
else
cp $TEMPLATES/bblayers.conf conf/bblayers.conf
fi
for s in $HOME/.oe $HOME/.yocto; do
if [ -e $s/site.conf ]; then
echo "Linking $s/site.conf to conf/site.conf"
ln -s $s/site.conf conf
fi
done
generated_config=1
fi
cat <<EOF
Welcome to Rockchip Yocto BSP
The Yocto Project has extensive documentation about OE including a
reference manual which can be found at:
http://yoctoproject.org/documentation
For more information about OpenEmbedded see their website:
http://www.openembedded.org/
You can now run 'bitbake <target>'
EOF
if [ -n "$generated_config" ]; then
cat <<EOF
Your build environment has been configured with:
MACHINE=$MACHINE
SDKMACHINE=$SDKMACHINE
DISTRO=$DISTRO
EOF
else
echo "Your configuration files at $BUILD_DIR have not been touched."
fi
clean_up