-
Notifications
You must be signed in to change notification settings - Fork 55
/
setup-mel-builddir
executable file
·240 lines (210 loc) · 7.42 KB
/
setup-mel-builddir
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
#!/bin/sh
#
# Copyright 2007-2013 Mentor Graphics Corporation
#
# This file is licensed under the terms of the GNU General Public License
# version 2. This program is licensed "as is" without any warranty of any
# kind, whether express or implied.
OPTIONALLAYERS="${OPTIONALLAYERS:-mentor-private}"
EXTRAMELLAYERS="${EXTRAMELLAYERS:-openembedded-layer filesystems-layer networking sourcery}"
usage () {
cat >&2 <<END
Usage: $0 [OPTIONS...] [MACHINE]
When operating from a MEL install, this script will use the template config
files from the installed BSP. If multiple BSPs are installed, you must specify
MACHINE, and the script will use the templates from that BSP.
When no installed BSP is available, MACHINE is required, and this script will
set up the build directory with a base set of layers + all layers which
include the machine .conf file for this machine, sorted by layer recipe
priority.
If the build directory already exists and is configured, you can leave MACHINE
unspecified, and the script will set you up for that build directory without
changing its configuration.
Options:
-b BUILDDIR Specify the build directory to create (default: 'build')
-o MELDIR Specify the root of the MEL install, where you can find bitbake and the layers
-f Force overwrite of existing configuration files in the build
directory. This includes local.conf and bblayers.conf, but not
site.conf
-h Show this usage information
END
}
prompt_choice () {
prompt_message="$1"
prompt_default="$2"
prompt_options="$(mktemp prompt-choice.XXXXXX)"
cat >>"$prompt_options"
prompt_count="$(wc -l <"$prompt_options")"
case $prompt_count in
0)
# No choices provided
rm -f "$prompt_options"
return 1
;;
1)
# Only one choice
cat "$prompt_options"
rm -f "$prompt_options"
return 0
;;
esac
if [ ! -t 0 ] || [ ! -t 2 ]; then
# We only prompt when running on a tty
return 2
fi
while [ -z "$prompt_value" ]; do
prompt_num=0
while read choice; do
prompt_num=$(expr $prompt_num + 1)
eval prompt_value_${prompt_num}="$choice"
printf >&2 "%s) %s\n" "$prompt_num" "$choice"
done <"$prompt_options"
printf >&2 "%s: " "$prompt_message"
read selection </dev/tty
prompt_value="$(eval echo \${prompt_value_$selection})"
done
printf "%s\n" "$prompt_value"
rm -f "$prompt_options"
}
abspath () {
readlink -f "$1"
}
configure_for_machine () {
sed -i -e"s/^#*MACHINE *?*=.*/MACHINE ??= \"$MACHINE\"/" $1/local.conf
sed -n -i -e "s|##COREBASE##|$OEROOT|g" -e '/^BBLAYERS /{ :start; /\\$/{n; b start}; d; }; p' $1/bblayers.conf
echo 'BBLAYERS = "\' >> $1/bblayers.conf
layersfile=$(mktemp setup-mel-builddir.XXXXXX)
$layerdir/scripts/bb-determine-layers -g "*:*/*:$MELDIR/*:$MELDIR/*/*" -o "$EXTRAMELLAYERS $OPTIONALLAYERS" -x "$EXCLUDEDLAYERS" $MACHINE >$layersfile
if [ $? -ne 0 ]; then
rm -f $layersfile
echo >&2 "Error in execution of bb-determine-layers, aborting"
exit 1
fi
sed 's,^, ,; s,$, \\,' <$layersfile >>$1/bblayers.conf
rm -f $layersfile
echo '"' >> $1/bblayers.conf
unset layersfile
}
process_arguments () {
BUILDDIR=
MELDIR=
OEROOT=
force_overwrite=
while getopts b:o:fh opt; do
case "$opt" in
b)
BUILDDIR="$(abspath $OPTARG)"
;;
o)
MELDIR="$(abspath $OPTARG)"
;;
f)
force_overwrite="-f"
;;
\?|h)
usage
return 1
;;
esac
done
if [ -z $BUILDDIR ]; then
if [ -f conf/local.conf -o -f conf/bblayers.conf ]; then
# Assuming we're already in the build dir
BUILDDIR=$PWD
else
BUILDDIR=$PWD/build
fi
fi
if [ -z "$MELDIR" ]; then
MELDIR=$(dirname $layerdir)
fi
}
setup_builddir () {
process_arguments "$@" || return $?
shift $(expr $OPTIND - 1)
if [ -e "$MELDIR/poky" ]; then
OEROOT="$MELDIR/poky"
elif [ -e "$MELDIR/oe-core" ]; then
OEROOT="$MELDIR/oe-core"
else
echo >&2 "Unable to locate poky or oe-core in $MELDIR, aborting"
return 3
fi
if [ "$force_overwrite" = "-f" ]; then
rm -f $BUILDDIR/conf/local.conf $BUILDDIR/conf/bblayers.conf
fi
TEMPLATECONF=
MACHINE=$1
if [ -n "$MACHINE" ]; then
if [ -e $MELDIR/$MACHINE/binary ]; then
# User specified machine and we have the binary content for this BSP
TEMPLATECONF=$MELDIR/$MACHINE/conf
fi
else
if [ ! -e $BUILDDIR/conf/local.conf -o ! -e $BUILDDIR/conf/bblayers.conf ]; then
MACHINE="$(ls -1d $MELDIR/*/binary 2>/dev/null | sed "s,^$MELDIR/,,; s,/binary$,," | prompt_choice "Select BSP to use")"
if [ $? -ne 0 ]; then
echo >&2 "Error: no installed MEL BSP, please specify MACHINE"
return 1
else
TEMPLATECONF=$MELDIR/$MACHINE/conf
fi
fi
fi
: ${TEMPLATECONF:=$layerdir/conf}
mkdir -p $BUILDDIR/conf
if [ ! -e $BUILDDIR/conf/local.conf ]; then
cp $TEMPLATECONF/local.conf.sample $BUILDDIR/conf/local.conf
echo "You had no local.conf file. This configuration file has therefore been"
echo "created for you with some default values."
(
JOBS_FACTOR="2"
THREADS_FACTOR="3 / 2"
NCPU=`grep -c processor /proc/cpuinfo`
JOBS=`expr $NCPU \* $JOBS_FACTOR`
THREADS=`expr $NCPU \* $THREADS_FACTOR`
sed -i -e"s/^#*PARALLEL_MAKE *?*=.*/PARALLEL_MAKE ?= \"-j$JOBS\"/" $BUILDDIR/conf/local.conf
sed -i -e"s/^#*BB_NUMBER_THREADS *?*=.*/BB_NUMBER_THREADS ?= \"$THREADS\"/" $BUILDDIR/conf/local.conf
)
else
if [ -n "$MACHINE" ]; then
echo "Configuring existing local.conf for $MACHINE"
fi
fi
if [ ! -e $BUILDDIR/conf/bblayers.conf ]; then
echo "MELDIR = \"$MELDIR\"" >$BUILDDIR/conf/bblayers.conf
echo >>$BUILDDIR/conf/bblayers.conf
cat $TEMPLATECONF/bblayers.conf.sample >>$BUILDDIR/conf/bblayers.conf
echo "You had no bblayers.conf file. This configuration file has therefore been"
echo "created for you with some default values."
else
if [ -n "$MACHINE" ]; then
echo "Configuring existing bblayers.conf for $MACHINE"
fi
fi
if [ -z "$MACHINE" ]; then
MACHINE=$(sed -n 's/^MACHINE ?*= "\([^"]*\)"/\1/p' $BUILDDIR/conf/local.conf)
fi
if [ -n "$MACHINE" ]; then
PATH="$OEROOT/scripts:$OEROOT/bitbake/bin:$PATH" configure_for_machine "$BUILDDIR/conf"
fi
cat >$BUILDDIR/setup-environment <<END
if [ -n "\$BASH_SOURCE" ]; then
BUILDDIR="\$(dirname "\$BASH_SOURCE")"
elif [ -n "\$ZSH_NAME" ]; then
BUILDDIR="\$(dirname "\$0")"
else
BUILDDIR="\$(pwd)"
fi
export TEMPLATECONF="$TEMPLATECONF"
. $OEROOT/oe-init-build-env $BUILDDIR
unset TEMPLATECONF
END
}
scriptsdir="$(cd $(dirname $0) && pwd)"
scriptsdir="$(abspath $scriptsdir)"
layerdir="${scriptsdir%/*}"
setup_builddir "$@" || exit $?
if [ -e $BUILDDIR/conf/local.conf ]; then
sed -i -e "s/^DISTRO.*/DISTRO = 'mel'/" $BUILDDIR/conf/local.conf
fi