blob: 4f016e3d002e1e9933e4d0efeea68ca4c7292e52 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001def machine_paths(d):
2 """List any existing machine specific filespath directories"""
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003 machine = d.getVar("MACHINE")
4 filespathpkg = d.getVar("FILESPATHPKG").split(":")
5 for basepath in d.getVar("FILESPATHBASE").split(":"):
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006 for pkgpath in filespathpkg:
7 machinepath = os.path.join(basepath, pkgpath, machine)
8 if os.path.isdir(machinepath):
9 yield machinepath
10
11def is_machine_specific(d):
12 """Determine whether the current recipe is machine specific"""
13 machinepaths = set(machine_paths(d))
Brad Bishop6e60e8b2018-02-01 10:27:11 -050014 srcuri = d.getVar("SRC_URI").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015 for url in srcuri:
16 fetcher = bb.fetch2.Fetch([srcuri], d)
17 if url.startswith("file://"):
18 if any(fetcher.localpath(url).startswith(mp + "/") for mp in machinepaths):
19 return True
20
21oe_soinstall() {
22 # Purpose: Install shared library file and
23 # create the necessary links
Patrick Williamsc0f7c042017-02-23 20:41:17 -060024 # Example: oe_soinstall libfoo.so.1.2.3 ${D}${libdir}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025 libname=`basename $1`
Patrick Williamsc0f7c042017-02-23 20:41:17 -060026 case "$libname" in
27 *.so)
28 bbfatal "oe_soinstall: Shared library must haved versioned filename (e.g. libfoo.so.1.2.3)"
29 ;;
30 esac
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031 install -m 755 $1 $2/$libname
32 sonamelink=`${HOST_PREFIX}readelf -d $1 |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
Patrick Williamsc0f7c042017-02-23 20:41:17 -060033 if [ -z $sonamelink ]; then
34 bbfatal "oe_soinstall: $libname is missing ELF tag 'SONAME'."
35 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -050036 solink=`echo $libname | sed -e 's/\.so\..*/.so/'`
37 ln -sf $libname $2/$sonamelink
38 ln -sf $libname $2/$solink
39}
40
41oe_libinstall() {
42 # Purpose: Install a library, in all its forms
43 # Example
44 #
45 # oe_libinstall libltdl ${STAGING_LIBDIR}/
46 # oe_libinstall -C src/libblah libblah ${D}/${libdir}/
47 dir=""
48 libtool=""
49 silent=""
50 require_static=""
51 require_shared=""
52 staging_install=""
53 while [ "$#" -gt 0 ]; do
54 case "$1" in
55 -C)
56 shift
57 dir="$1"
58 ;;
59 -s)
60 silent=1
61 ;;
62 -a)
63 require_static=1
64 ;;
65 -so)
66 require_shared=1
67 ;;
68 -*)
69 bbfatal "oe_libinstall: unknown option: $1"
70 ;;
71 *)
72 break;
73 ;;
74 esac
75 shift
76 done
77
78 libname="$1"
79 shift
80 destpath="$1"
81 if [ -z "$destpath" ]; then
82 bbfatal "oe_libinstall: no destination path specified"
83 fi
84 if echo "$destpath/" | egrep '^${STAGING_LIBDIR}/' >/dev/null
85 then
86 staging_install=1
87 fi
88
89 __runcmd () {
90 if [ -z "$silent" ]; then
91 echo >&2 "oe_libinstall: $*"
92 fi
93 $*
94 }
95
96 if [ -z "$dir" ]; then
97 dir=`pwd`
98 fi
99
100 dotlai=$libname.lai
101
102 # Sanity check that the libname.lai is unique
103 number_of_files=`(cd $dir; find . -name "$dotlai") | wc -l`
104 if [ $number_of_files -gt 1 ]; then
105 bbfatal "oe_libinstall: $dotlai is not unique in $dir"
106 fi
107
108
109 dir=$dir`(cd $dir;find . -name "$dotlai") | sed "s/^\.//;s/\/$dotlai\$//;q"`
110 olddir=`pwd`
111 __runcmd cd $dir
112
113 lafile=$libname.la
114
115 # If such file doesn't exist, try to cut version suffix
116 if [ ! -f "$lafile" ]; then
117 libname1=`echo "$libname" | sed 's/-[0-9.]*$//'`
118 lafile1=$libname.la
119 if [ -f "$lafile1" ]; then
120 libname=$libname1
121 lafile=$lafile1
122 fi
123 fi
124
125 if [ -f "$lafile" ]; then
126 # libtool archive
127 eval `cat $lafile|grep "^library_names="`
128 libtool=1
129 else
130 library_names="$libname.so* $libname.dll.a $libname.*.dylib"
131 fi
132
133 __runcmd install -d $destpath/
134 dota=$libname.a
135 if [ -f "$dota" -o -n "$require_static" ]; then
136 rm -f $destpath/$dota
137 __runcmd install -m 0644 $dota $destpath/
138 fi
139 if [ -f "$dotlai" -a -n "$libtool" ]; then
140 rm -f $destpath/$libname.la
141 __runcmd install -m 0644 $dotlai $destpath/$libname.la
142 fi
143
144 for name in $library_names; do
145 files=`eval echo $name`
146 for f in $files; do
147 if [ ! -e "$f" ]; then
148 if [ -n "$libtool" ]; then
149 bbfatal "oe_libinstall: $dir/$f not found."
150 fi
151 elif [ -L "$f" ]; then
152 __runcmd cp -P "$f" $destpath/
153 elif [ ! -L "$f" ]; then
154 libfile="$f"
155 rm -f $destpath/$libfile
156 __runcmd install -m 0755 $libfile $destpath/
157 fi
158 done
159 done
160
161 if [ -z "$libfile" ]; then
162 if [ -n "$require_shared" ]; then
163 bbfatal "oe_libinstall: unable to locate shared library"
164 fi
165 elif [ -z "$libtool" ]; then
166 # special case hack for non-libtool .so.#.#.# links
167 baselibfile=`basename "$libfile"`
168 if (echo $baselibfile | grep -qE '^lib.*\.so\.[0-9.]*$'); then
169 sonamelink=`${HOST_PREFIX}readelf -d $libfile |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
170 solink=`echo $baselibfile | sed -e 's/\.so\..*/.so/'`
171 if [ -n "$sonamelink" -a x"$baselibfile" != x"$sonamelink" ]; then
172 __runcmd ln -sf $baselibfile $destpath/$sonamelink
173 fi
174 __runcmd ln -sf $baselibfile $destpath/$solink
175 fi
176 fi
177
178 __runcmd cd "$olddir"
179}
180
181oe_machinstall() {
182 # Purpose: Install machine dependent files, if available
183 # If not available, check if there is a default
184 # If no default, just touch the destination
185 # Example:
186 # $1 $2 $3 $4
187 # oe_machinstall -m 0644 fstab ${D}/etc/fstab
188 #
189 # TODO: Check argument number?
190 #
191 filename=`basename $3`
192 dirname=`dirname $3`
193
194 for o in `echo ${OVERRIDES} | tr ':' ' '`; do
195 if [ -e $dirname/$o/$filename ]; then
196 bbnote $dirname/$o/$filename present, installing to $4
197 install $1 $2 $dirname/$o/$filename $4
198 return
199 fi
200 done
201# bbnote overrides specific file NOT present, trying default=$3...
202 if [ -e $3 ]; then
203 bbnote $3 present, installing to $4
204 install $1 $2 $3 $4
205 else
206 bbnote $3 NOT present, touching empty $4
207 touch $4
208 fi
209}
210
211create_cmdline_wrapper () {
212 # Create a wrapper script where commandline options are needed
213 #
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600214 # These are useful to work around relocation issues, by passing extra options
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500215 # to a program
216 #
217 # Usage: create_cmdline_wrapper FILENAME <extra-options>
218
219 cmd=$1
220 shift
221
222 echo "Generating wrapper script for $cmd"
223
224 mv $cmd $cmd.real
225 cmdname=`basename $cmd`
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500226 dirname=`dirname $cmd`
227 cmdoptions=$@
228 if [ "${base_prefix}" != "" ]; then
229 relpath=`python3 -c "import os; print(os.path.relpath('${D}${base_prefix}', '$dirname'))"`
230 cmdoptions=`echo $@ | sed -e "s:${base_prefix}:\\$realdir/$relpath:g"`
231 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500232 cat <<END >$cmd
233#!/bin/bash
234realpath=\`readlink -fn \$0\`
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500235realdir=\`dirname \$realpath\`
236exec -a \`dirname \$realpath\`/$cmdname \`dirname \$realpath\`/$cmdname.real $cmdoptions "\$@"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500237END
238 chmod +x $cmd
239}
240
241create_wrapper () {
242 # Create a wrapper script where extra environment variables are needed
243 #
244 # These are useful to work around relocation issues, by setting environment
245 # variables which point to paths in the filesystem.
246 #
247 # Usage: create_wrapper FILENAME [[VAR=VALUE]..]
248
249 cmd=$1
250 shift
251
252 echo "Generating wrapper script for $cmd"
253
254 mv $cmd $cmd.real
255 cmdname=`basename $cmd`
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500256 dirname=`dirname $cmd`
257 exportstring=$@
258 if [ "${base_prefix}" != "" ]; then
259 relpath=`python3 -c "import os; print(os.path.relpath('${D}${base_prefix}', '$dirname'))"`
260 exportstring=`echo $@ | sed -e "s:${base_prefix}:\\$realdir/$relpath:g"`
261 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500262 cat <<END >$cmd
263#!/bin/bash
264realpath=\`readlink -fn \$0\`
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500265realdir=\`dirname \$realpath\`
266export $exportstring
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500267exec -a \`dirname \$realpath\`/$cmdname \`dirname \$realpath\`/$cmdname.real "\$@"
268END
269 chmod +x $cmd
270}
271
272# Copy files/directories from $1 to $2 but using hardlinks
273# (preserve symlinks)
274hardlinkdir () {
275 from=$1
276 to=$2
277 (cd $from; find . -print0 | cpio --null -pdlu $to)
278}
279
280
281def check_app_exists(app, d):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500282 app = d.expand(app).split()[0].strip()
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500283 path = d.getVar('PATH')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500284 return bool(bb.utils.which(path, app))
285
286def explode_deps(s):
287 return bb.utils.explode_deps(s)
288
289def base_set_filespath(path, d):
290 filespath = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500291 extrapaths = (d.getVar("FILESEXTRAPATHS") or "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500292 # Remove default flag which was used for checking
293 extrapaths = extrapaths.replace("__default:", "")
294 # Don't prepend empty strings to the path list
295 if extrapaths != "":
296 path = extrapaths.split(":") + path
297 # The ":" ensures we have an 'empty' override
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500298 overrides = (":" + (d.getVar("FILESOVERRIDES") or "")).split(":")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500299 overrides.reverse()
300 for o in overrides:
301 for p in path:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600302 if p != "":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500303 filespath.append(os.path.join(p, o))
304 return ":".join(filespath)
305
306def extend_variants(d, var, extend, delim=':'):
307 """Return a string of all bb class extend variants for the given extend"""
308 variants = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500309 whole = d.getVar(var) or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500310 for ext in whole.split():
311 eext = ext.split(delim)
312 if len(eext) > 1 and eext[0] == extend:
313 variants.append(eext[1])
314 return " ".join(variants)
315
316def multilib_pkg_extend(d, pkg):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500317 variants = (d.getVar("MULTILIB_VARIANTS") or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500318 if not variants:
319 return pkg
320 pkgs = pkg
321 for v in variants:
322 pkgs = pkgs + " " + v + "-" + pkg
323 return pkgs
324
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500325def get_multilib_datastore(variant, d):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400326 return oe.utils.get_multilib_datastore(variant, d)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500327
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500328def all_multilib_tune_values(d, var, unique = True, need_split = True, delim = ' '):
329 """Return a string of all ${var} in all multilib tune configuration"""
330 values = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500331 value = d.getVar(var) or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500332 if value != "":
333 if need_split:
334 for item in value.split(delim):
335 values.append(item)
336 else:
337 values.append(value)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500338 variants = d.getVar("MULTILIB_VARIANTS") or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500339 for item in variants.split():
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500340 localdata = get_multilib_datastore(item, d)
341 value = localdata.getVar(var) or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500342 if value != "":
343 if need_split:
344 for item in value.split(delim):
345 values.append(item)
346 else:
347 values.append(value)
348 if unique:
349 #we do this to keep order as much as possible
350 ret = []
351 for value in values:
352 if not value in ret:
353 ret.append(value)
354 else:
355 ret = values
356 return " ".join(ret)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600357
358def all_multilib_tune_list(vars, d):
359 """
360 Return a list of ${VAR} for each variable VAR in vars from each
361 multilib tune configuration.
362 Is safe to be called from a multilib recipe/context as it can
363 figure out the original tune and remove the multilib overrides.
364 """
365 values = {}
366 for v in vars:
367 values[v] = []
368
369 localdata = bb.data.createCopy(d)
370 overrides = localdata.getVar("OVERRIDES", False).split(":")
371 newoverrides = []
372 for o in overrides:
373 if not o.startswith("virtclass-multilib-"):
374 newoverrides.append(o)
375 localdata.setVar("OVERRIDES", ":".join(newoverrides))
376 localdata.setVar("MLPREFIX", "")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500377 origdefault = localdata.getVar("DEFAULTTUNE_MULTILIB_ORIGINAL")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600378 if origdefault:
379 localdata.setVar("DEFAULTTUNE", origdefault)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600380 values['ml'] = ['']
381 for v in vars:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500382 values[v].append(localdata.getVar(v))
383 variants = d.getVar("MULTILIB_VARIANTS") or ""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600384 for item in variants.split():
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500385 localdata = get_multilib_datastore(item, d)
386 values[v].append(localdata.getVar(v))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600387 values['ml'].append(item)
388 return values
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500389all_multilib_tune_list[vardepsexclude] = "OVERRIDES"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600390
391# If the user hasn't set up their name/email, set some defaults
392check_git_config() {
393 if ! git config user.email > /dev/null ; then
394 git config --local user.email "${PATCH_GIT_USER_EMAIL}"
395 fi
396 if ! git config user.name > /dev/null ; then
397 git config --local user.name "${PATCH_GIT_USER_NAME}"
398 fi
399}