forked from qualcomm-linux/meta-qcom-distro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_bb_env.sh
306 lines (255 loc) · 9.72 KB
/
set_bb_env.sh
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#!/bin/sh
#
# Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause-Clear
# set_bb_env.sh
# Define macros for build targets.
# Some convenience macros are defined to save some typing.
# Set the build environment.
if ! $(return >/dev/null 2>&1) ; then
echo 'error: this script must be sourced'
echo ''
exit 2
fi
WS=`pwd`
SCRIPT_NAME="setup-environment"
umask 022
usage () {
cat <<EOF
Usage: [DISTRO=<DISTRO>] [MACHINE=<MACHINE>] source ${SCRIPT_NAME} [BUILDDIR]
If no MACHINE is set, list all possible machines, and ask user to choose.
If no DISTRO is set, list all possible distros, and ask user to choose.
If no BUILDDIR is set, it will be set to build-DISTRO.
If BUILDDIR is set and is already configured it is used as-is
EOF
}
if [ $# -gt 1 ]; then
usage
return 1
fi
OEROOT="$WS/layers/poky"
if [ -e "$WS/layers/openembedded-core" ]; then
OEROOT="$WS/layers/openembedded-core"
fi
apply_poky_patches () {
cd ${WS}/layers/poky
patchfile='0001-fetch2-git-Add-verbose-logging-support.patch'
wget -nv https://artifacts.codelinaro.org/artifactory/codelinaro-le/$patchfile
git apply --check $patchfile
if [ $? != 0 ] ; then
echo " $patchfile ... patch Failed to apply, ignoring"
else
git apply $patchfile
fi
rm $patchfile
cd -
}
# Eventually we need to call oe-init-build-env to finalize the configuration
# of the newly created build folder
init_build_env () {
# Let bitbake use the following env-vars as if they were pre-set bitbake ones.
BB_ENV_PASSTHROUGH_ADDITIONS="DEBUG_BUILD PERFORMANCE_BUILD FWZIP_PATH CUST_ID BB_GIT_VERBOSE_FETCH QCOM_SELECTED_BSP"
apply_poky_patches &> /dev/null
# Yocto/OE-core works a bit differently than OE-classic. We're going
# to source the OE build environment setup script that Yocto provided.
. ${OEROOT}/oe-init-build-env ${BUILDDIR}
# Clean up environment.
unset MACHINE SDKMACHINE DISTRO WS OEROOT usage SCRIPT_NAME QCOM_SELECTED_BSP
unset EXTRALAYERS DEBUG_BUILD PERFORMANCE_BUILD BUILDTYPE FWZIP_PATH CUST_ID BB_GIT_VERBOSE_FETCH
unset DISTROTABLE DISTROLAYERS MACHINETABLE MACHLAYERS ITEM
}
# If BUILDDIR is provided and is already a valid build folder, let's use it
if [ $# -eq 1 ]; then
BUILDDIR="${WS}/$1"
if [ -f "${BUILDDIR}/conf/local.conf" ] &&
[ -f "${BUILDDIR}/conf/auto.conf" ] &&
[ -f "${BUILDDIR}/conf/bblayers.conf" ]; then
init_build_env
return
fi
fi
# Choose one among whiptail & dialog to show dialog boxes
read uitool <<< "$(which whiptail dialog 2> /dev/null)"
# create a common list of "<machine>(<layer>)", sorted by <machine>
# Restrict to meta-qcom-hwe machines
MACHLAYERS=$(find layers -print | grep "meta-qcom-hwe/conf/machine/.*\.conf" | sed -e 's/\.conf//g' -e 's/layers\///' | awk -F'/conf/machine/' '{print $NF "(" $1 ")"}' | LANG=C sort)
if [ -n "${MACHLAYERS}" ] && [ -z "${MACHINE}" ]; then
for ITEM in $MACHLAYERS; do
if [[ $PREFMACH == *$(echo "$ITEM" |cut -d'(' -f1)* ]]; then
MACHINETABLE="${MACHINETABLE} $(echo "$ITEM" | cut -d'(' -f1) $(echo "$ITEM" | cut -d'(' -f2 | cut -d')' -f1)"
fi
done
if [ -n "${MACHINETABLE}" ]; then
MACHINE=$($uitool --title "Preferred Machines" --menu \
"Please choose a machine" 0 0 20 \
${MACHINETABLE} 3>&1 1>&2 2>&3)
fi
if [ -z "${MACHINE}" ]; then
for ITEM in $MACHLAYERS; do
MACHINETABLE="${MACHINETABLE} $(echo "$ITEM" | cut -d'(' -f1) $(echo "$ITEM" | cut -d'(' -f2 | cut -d')' -f1)"
done
MACHINE=$($uitool --title "Available Machines" --menu \
"Please choose a machine" 0 0 20 \
${MACHINETABLE} 3>&1 1>&2 2>&3)
fi
fi
# guard against Ctrl-D or cancel
if [ -z "$MACHINE" ]; then
echo "To choose a machine interactively please install whiptail or dialog."
echo "To choose a machine non-interactively please use the following syntax:"
echo " MACHINE=<your-machine> source ./setup-environment"
echo ""
echo "Press <ENTER> to see a list of your choices"
read -r
echo "$MACHLAYERS" | sed -e 's/(/ (/g' | sed -e 's/)/)\n/g' | sed -e 's/^ */\t/g'
return
fi
# create a common list of "<distro>(<layer>)", sorted by <distro>
# Restrict to meta-qti-distro distros
DISTROLAYERS=$(find layers -print | grep "meta-qcom-distro/conf/distro/.*\.conf" | sed -e 's/\.conf//g' -e 's/layers\///' | awk -F'/conf/distro/' '{print $NF "(" $1 ")"}' | LANG=C sort)
if [ -n "${DISTROLAYERS}" ] && [ -z "${DISTRO}" ]; then
for ITEM in $DISTROLAYERS; do
if [[ $PREFDIST == *$(echo "$ITEM" |cut -d'(' -f1)* ]]; then
DISTROTABLE="${DISTROTABLE} $(echo "$ITEM" | cut -d'(' -f1) $(echo "$ITEM" | cut -d'(' -f2 | cut -d')' -f1)"
fi
done
if [ -n "${DISTROTABLE}" ]; then
DISTRO=$($uitool --title "Preferred Distributions" --menu \
"Please choose a distribution" 0 0 20 \
${DISTROTABLE} 3>&1 1>&2 2>&3)
fi
if [ -z "${DISTRO}" ]; then
for ITEM in $DISTROLAYERS; do
DISTROTABLE="${DISTROTABLE} $(echo "$ITEM" | cut -d'(' -f1) $(echo "$ITEM" | cut -d'(' -f2 | cut -d')' -f1)"
done
DISTRO=$($uitool --title "Available Distributions" --menu \
"Please choose a distribution" 0 0 20 \
${DISTROTABLE} 3>&1 1>&2 2>&3)
fi
fi
# If nothing has been set, go for 'nodistro'
if [ -z "$DISTRO" ]; then
DISTRO="nodistro"
fi
# If debug_build is set to non zero, force no performance build
if [ -n "${DEBUG_BUILD}" ] && [ $DEBUG_BUILD -ne 0 ]; then
DEBUG_BUILD=1
PERFORMANCE_BUILD=0
BUILDTYPE="debug"
# If performance_build is set to non zero, go for performance build
elif [ -n "${PERFORMANCE_BUILD}" ] && [ $PERFORMANCE_BUILD -ne 0 ]; then
DEBUG_BUILD=0
PERFORMANCE_BUILD=1
BUILDTYPE="performance"
fi
# If nothing has been set, go for 'default'
if [ -z "$BUILDTYPE" ]; then
DEBUG_BUILD=0
PERFORMANCE_BUILD=0
BUILDTYPE="default"
fi
if [ -z "${SDKMACHINE}" ]; then
SDKMACHINE='x86_64'
fi
BUILDDIR="${WS}/build-$DISTRO"
DISTRO_VERSION='1.0'
if [ $# -eq 1 ]; then
BUILDDIR="${WS}/$1"
fi
mkdir -p "${BUILDDIR}"/conf
##### bblayers.conf #####
cat >| ${BUILDDIR}/conf/bblayers.conf <<EOF
# This configuration file is dynamically generated every time
# set_bb_env.sh is sourced to set up a workspace. DO NOT EDIT.
#--------------------------------------------------------------
EOF
if [ -e ${WS}/layers/meta-qcom-distro/conf/bblayers.conf ]; then
cat ${WS}/layers/meta-qcom-distro/conf/bblayers.conf >> ${BUILDDIR}/conf/bblayers.conf
fi
# If EXTRALAYERS are avilable update them
if [ -n "${EXTRALAYERS}" ]; then
earr=($EXTRALAYERS)
for s in "${earr[@]}"; do
str=\${WORKSPACE}/layers/$(echo "${s}")
sed -i "/EXTRALAYERS ?= /a\\ ${str} \\ \\" ${BUILDDIR}/conf/bblayers.conf
done
fi
##### local.conf #####
cat >| ${BUILDDIR}/conf/local.conf <<EOF
# This configuration file is dynamically generated every time
# set_bb_env.sh is sourced to set up a workspace. DO NOT EDIT.
#--------------------------------------------------------------
EOF
if [ -e $WS/layers/meta-qcom-distro/conf/local.conf ]; then
cat $WS/layers/meta-qcom-distro/conf/local.conf >> ${BUILDDIR}/conf/local.conf
fi
# If CUST_ID is avilable update
if [ -n "$CUST_ID" ]; then
echo -e "\n# Cust ID" >> ${BUILDDIR}/conf/local.conf
echo "CUST_ID = \"$CUST_ID\"" >> ${BUILDDIR}/conf/local.conf
fi
# If FWZIP_PATH is avilable update
if [ -n "$FWZIP_PATH" ]; then
echo -e "\n# FW zip path" >> ${BUILDDIR}/conf/local.conf
echo "FWZIP_PATH = \"$FWZIP_PATH\"" >> ${BUILDDIR}/conf/local.conf
fi
# If BB_GIT_VERBOSE_FETCH is avilable update
if [ -n "$BB_GIT_VERBOSE_FETCH" ]; then
sed -i "s/^BB_GIT_VERBOSE_FETCH = .*$/BB_GIT_VERBOSE_FETCH = \"$BB_GIT_VERBOSE_FETCH\"/g" ${BUILDDIR}/conf/local.conf
fi
##### auto.conf #####
cat >| ${BUILDDIR}/conf/auto.conf <<EOF
# This configuration file is dynamically generated every time
# set_bb_env.sh is sourced to set up a workspace. DO NOT EDIT.
#--------------------------------------------------------------
DISTRO = "${DISTRO}"
MACHINE = "${MACHINE}"
SDKMACHINE = "${SDKMACHINE}"
DISTRO_VERSION = "${DISTRO_VERSION}"
DEBUG_BUILD = "${DEBUG_BUILD}"
PERFORMANCE_BUILD = "${PERFORMANCE_BUILD}"
# Force error for dangling bbappends
BB_DANGLINGAPPENDS_WARNONLY_forcevariable = "false"
# Extra options that can be changed by the user
INHERIT += "rm_work"
EOF
# If QCOM_SELECTED_BSP is not defined, set it to 'custom'
if [ -z "$QCOM_SELECTED_BSP" ]; then
QCOM_SELECTED_BSP='custom'
fi
# Update QCOM_SELECTED_BSP in auto.conf
cat >> ${BUILDDIR}/conf/auto.conf <<EOF
# Selected QCOM BSP
QCOM_SELECTED_BSP = "${QCOM_SELECTED_BSP}"
EOF
##### site.conf #####
cat >| ${BUILDDIR}/conf/site.conf <<EOF
# This configuration file is dynamically generated every time
# set_bb_env.sh is sourced to set up a workspace. DO NOT EDIT.
#--------------------------------------------------------------
SCONF_VERSION = "1"
# Where to store sources
DL_DIR = "${WS}/downloads"
# Where to save shared state
SSTATE_DIR = "${WS}/sstate-cache"
# Add codelinaro sites to MIRRORS
MIRRORS += "\
git://github.com git://git.codelinaro.org/clo/yocto-mirrors/github/ \
git://.*/.*/ git://git.codelinaro.org/clo/yocto-mirrors/ \
https://.*/.*/ https://codelinaro.jfrog.io/artifactory/codelinaro-le/ \
"
EOF
if [ -e $WS/layers/meta-qcom-distro/conf/site.conf ]; then
cat $WS/layers/meta-qcom-distro/conf/site.conf >> ${BUILDDIR}/conf/site.conf
fi
cat <<EOF
Your build environment has been configured with:
MACHINE = ${MACHINE}
SDKMACHINE = ${SDKMACHINE}
DISTRO = ${DISTRO}
BUILDTYPE = ${BUILDTYPE}
BSP-TYPE = qcom-${QCOM_SELECTED_BSP}-bsp
You can now run 'bitbake <target>'
EOF
# Finalize
init_build_env