blob: 120bcc64a64439cb929a01bf3d77b648436d214a [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001
2oe_soinstall() {
3 # Purpose: Install shared library file and
4 # create the necessary links
Patrick Williamsc0f7c042017-02-23 20:41:17 -06005 # Example: oe_soinstall libfoo.so.1.2.3 ${D}${libdir}
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006 libname=`basename $1`
Patrick Williamsc0f7c042017-02-23 20:41:17 -06007 case "$libname" in
8 *.so)
9 bbfatal "oe_soinstall: Shared library must haved versioned filename (e.g. libfoo.so.1.2.3)"
10 ;;
11 esac
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012 install -m 755 $1 $2/$libname
13 sonamelink=`${HOST_PREFIX}readelf -d $1 |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
Patrick Williamsc0f7c042017-02-23 20:41:17 -060014 if [ -z $sonamelink ]; then
15 bbfatal "oe_soinstall: $libname is missing ELF tag 'SONAME'."
16 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -050017 solink=`echo $libname | sed -e 's/\.so\..*/.so/'`
18 ln -sf $libname $2/$sonamelink
19 ln -sf $libname $2/$solink
20}
21
22oe_libinstall() {
23 # Purpose: Install a library, in all its forms
24 # Example
25 #
26 # oe_libinstall libltdl ${STAGING_LIBDIR}/
27 # oe_libinstall -C src/libblah libblah ${D}/${libdir}/
28 dir=""
29 libtool=""
30 silent=""
31 require_static=""
32 require_shared=""
33 staging_install=""
34 while [ "$#" -gt 0 ]; do
35 case "$1" in
36 -C)
37 shift
38 dir="$1"
39 ;;
40 -s)
41 silent=1
42 ;;
43 -a)
44 require_static=1
45 ;;
46 -so)
47 require_shared=1
48 ;;
49 -*)
50 bbfatal "oe_libinstall: unknown option: $1"
51 ;;
52 *)
53 break;
54 ;;
55 esac
56 shift
57 done
58
59 libname="$1"
60 shift
61 destpath="$1"
62 if [ -z "$destpath" ]; then
63 bbfatal "oe_libinstall: no destination path specified"
64 fi
65 if echo "$destpath/" | egrep '^${STAGING_LIBDIR}/' >/dev/null
66 then
67 staging_install=1
68 fi
69
70 __runcmd () {
71 if [ -z "$silent" ]; then
72 echo >&2 "oe_libinstall: $*"
73 fi
74 $*
75 }
76
77 if [ -z "$dir" ]; then
78 dir=`pwd`
79 fi
80
81 dotlai=$libname.lai
82
83 # Sanity check that the libname.lai is unique
84 number_of_files=`(cd $dir; find . -name "$dotlai") | wc -l`
85 if [ $number_of_files -gt 1 ]; then
86 bbfatal "oe_libinstall: $dotlai is not unique in $dir"
87 fi
88
89
90 dir=$dir`(cd $dir;find . -name "$dotlai") | sed "s/^\.//;s/\/$dotlai\$//;q"`
91 olddir=`pwd`
92 __runcmd cd $dir
93
94 lafile=$libname.la
95
96 # If such file doesn't exist, try to cut version suffix
97 if [ ! -f "$lafile" ]; then
98 libname1=`echo "$libname" | sed 's/-[0-9.]*$//'`
99 lafile1=$libname.la
100 if [ -f "$lafile1" ]; then
101 libname=$libname1
102 lafile=$lafile1
103 fi
104 fi
105
106 if [ -f "$lafile" ]; then
107 # libtool archive
108 eval `cat $lafile|grep "^library_names="`
109 libtool=1
110 else
111 library_names="$libname.so* $libname.dll.a $libname.*.dylib"
112 fi
113
114 __runcmd install -d $destpath/
115 dota=$libname.a
116 if [ -f "$dota" -o -n "$require_static" ]; then
117 rm -f $destpath/$dota
118 __runcmd install -m 0644 $dota $destpath/
119 fi
120 if [ -f "$dotlai" -a -n "$libtool" ]; then
121 rm -f $destpath/$libname.la
122 __runcmd install -m 0644 $dotlai $destpath/$libname.la
123 fi
124
125 for name in $library_names; do
126 files=`eval echo $name`
127 for f in $files; do
128 if [ ! -e "$f" ]; then
129 if [ -n "$libtool" ]; then
130 bbfatal "oe_libinstall: $dir/$f not found."
131 fi
132 elif [ -L "$f" ]; then
133 __runcmd cp -P "$f" $destpath/
134 elif [ ! -L "$f" ]; then
135 libfile="$f"
136 rm -f $destpath/$libfile
137 __runcmd install -m 0755 $libfile $destpath/
138 fi
139 done
140 done
141
142 if [ -z "$libfile" ]; then
143 if [ -n "$require_shared" ]; then
144 bbfatal "oe_libinstall: unable to locate shared library"
145 fi
146 elif [ -z "$libtool" ]; then
147 # special case hack for non-libtool .so.#.#.# links
148 baselibfile=`basename "$libfile"`
149 if (echo $baselibfile | grep -qE '^lib.*\.so\.[0-9.]*$'); then
150 sonamelink=`${HOST_PREFIX}readelf -d $libfile |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
151 solink=`echo $baselibfile | sed -e 's/\.so\..*/.so/'`
152 if [ -n "$sonamelink" -a x"$baselibfile" != x"$sonamelink" ]; then
153 __runcmd ln -sf $baselibfile $destpath/$sonamelink
154 fi
155 __runcmd ln -sf $baselibfile $destpath/$solink
156 fi
157 fi
158
159 __runcmd cd "$olddir"
160}
161
162oe_machinstall() {
163 # Purpose: Install machine dependent files, if available
164 # If not available, check if there is a default
165 # If no default, just touch the destination
166 # Example:
167 # $1 $2 $3 $4
168 # oe_machinstall -m 0644 fstab ${D}/etc/fstab
169 #
170 # TODO: Check argument number?
171 #
172 filename=`basename $3`
173 dirname=`dirname $3`
174
175 for o in `echo ${OVERRIDES} | tr ':' ' '`; do
176 if [ -e $dirname/$o/$filename ]; then
177 bbnote $dirname/$o/$filename present, installing to $4
178 install $1 $2 $dirname/$o/$filename $4
179 return
180 fi
181 done
182# bbnote overrides specific file NOT present, trying default=$3...
183 if [ -e $3 ]; then
184 bbnote $3 present, installing to $4
185 install $1 $2 $3 $4
186 else
187 bbnote $3 NOT present, touching empty $4
188 touch $4
189 fi
190}
191
192create_cmdline_wrapper () {
193 # Create a wrapper script where commandline options are needed
194 #
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600195 # These are useful to work around relocation issues, by passing extra options
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500196 # to a program
197 #
198 # Usage: create_cmdline_wrapper FILENAME <extra-options>
199
200 cmd=$1
201 shift
202
203 echo "Generating wrapper script for $cmd"
204
205 mv $cmd $cmd.real
206 cmdname=`basename $cmd`
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500207 dirname=`dirname $cmd`
208 cmdoptions=$@
209 if [ "${base_prefix}" != "" ]; then
210 relpath=`python3 -c "import os; print(os.path.relpath('${D}${base_prefix}', '$dirname'))"`
211 cmdoptions=`echo $@ | sed -e "s:${base_prefix}:\\$realdir/$relpath:g"`
212 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500213 cat <<END >$cmd
214#!/bin/bash
215realpath=\`readlink -fn \$0\`
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500216realdir=\`dirname \$realpath\`
217exec -a \`dirname \$realpath\`/$cmdname \`dirname \$realpath\`/$cmdname.real $cmdoptions "\$@"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500218END
219 chmod +x $cmd
220}
221
222create_wrapper () {
223 # Create a wrapper script where extra environment variables are needed
224 #
225 # These are useful to work around relocation issues, by setting environment
226 # variables which point to paths in the filesystem.
227 #
228 # Usage: create_wrapper FILENAME [[VAR=VALUE]..]
229
230 cmd=$1
231 shift
232
233 echo "Generating wrapper script for $cmd"
234
235 mv $cmd $cmd.real
236 cmdname=`basename $cmd`
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500237 dirname=`dirname $cmd`
238 exportstring=$@
239 if [ "${base_prefix}" != "" ]; then
240 relpath=`python3 -c "import os; print(os.path.relpath('${D}${base_prefix}', '$dirname'))"`
241 exportstring=`echo $@ | sed -e "s:${base_prefix}:\\$realdir/$relpath:g"`
242 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500243 cat <<END >$cmd
244#!/bin/bash
245realpath=\`readlink -fn \$0\`
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500246realdir=\`dirname \$realpath\`
247export $exportstring
Brad Bishop19323692019-04-05 15:28:33 -0400248exec -a "\$0" \$realdir/$cmdname.real "\$@"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500249END
250 chmod +x $cmd
251}
252
253# Copy files/directories from $1 to $2 but using hardlinks
254# (preserve symlinks)
255hardlinkdir () {
256 from=$1
257 to=$2
258 (cd $from; find . -print0 | cpio --null -pdlu $to)
259}
260
261
262def check_app_exists(app, d):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500263 app = d.expand(app).split()[0].strip()
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500264 path = d.getVar('PATH')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500265 return bool(bb.utils.which(path, app))
266
267def explode_deps(s):
268 return bb.utils.explode_deps(s)
269
270def base_set_filespath(path, d):
271 filespath = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500272 extrapaths = (d.getVar("FILESEXTRAPATHS") or "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500273 # Remove default flag which was used for checking
274 extrapaths = extrapaths.replace("__default:", "")
275 # Don't prepend empty strings to the path list
276 if extrapaths != "":
277 path = extrapaths.split(":") + path
278 # The ":" ensures we have an 'empty' override
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500279 overrides = (":" + (d.getVar("FILESOVERRIDES") or "")).split(":")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500280 overrides.reverse()
281 for o in overrides:
282 for p in path:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600283 if p != "":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500284 filespath.append(os.path.join(p, o))
285 return ":".join(filespath)
286
287def extend_variants(d, var, extend, delim=':'):
288 """Return a string of all bb class extend variants for the given extend"""
289 variants = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500290 whole = d.getVar(var) or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500291 for ext in whole.split():
292 eext = ext.split(delim)
293 if len(eext) > 1 and eext[0] == extend:
294 variants.append(eext[1])
295 return " ".join(variants)
296
297def multilib_pkg_extend(d, pkg):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500298 variants = (d.getVar("MULTILIB_VARIANTS") or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500299 if not variants:
300 return pkg
301 pkgs = pkg
302 for v in variants:
303 pkgs = pkgs + " " + v + "-" + pkg
304 return pkgs
305
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500306def get_multilib_datastore(variant, d):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400307 return oe.utils.get_multilib_datastore(variant, d)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500308
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500309def all_multilib_tune_values(d, var, unique = True, need_split = True, delim = ' '):
310 """Return a string of all ${var} in all multilib tune configuration"""
311 values = []
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800312 variants = (d.getVar("MULTILIB_VARIANTS") or "").split() + ['']
313 for item in variants:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500314 localdata = get_multilib_datastore(item, d)
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700315 # We need WORKDIR to be consistent with the original datastore
316 localdata.setVar("WORKDIR", d.getVar("WORKDIR"))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500317 value = localdata.getVar(var) or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500318 if value != "":
319 if need_split:
320 for item in value.split(delim):
321 values.append(item)
322 else:
323 values.append(value)
324 if unique:
325 #we do this to keep order as much as possible
326 ret = []
327 for value in values:
328 if not value in ret:
329 ret.append(value)
330 else:
331 ret = values
332 return " ".join(ret)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600333
334def all_multilib_tune_list(vars, d):
335 """
336 Return a list of ${VAR} for each variable VAR in vars from each
337 multilib tune configuration.
338 Is safe to be called from a multilib recipe/context as it can
339 figure out the original tune and remove the multilib overrides.
340 """
341 values = {}
342 for v in vars:
343 values[v] = []
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600344 values['ml'] = ['']
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800345
346 variants = (d.getVar("MULTILIB_VARIANTS") or "").split() + ['']
347 for item in variants:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500348 localdata = get_multilib_datastore(item, d)
349 values[v].append(localdata.getVar(v))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600350 values['ml'].append(item)
351 return values
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500352all_multilib_tune_list[vardepsexclude] = "OVERRIDES"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600353
354# If the user hasn't set up their name/email, set some defaults
355check_git_config() {
356 if ! git config user.email > /dev/null ; then
357 git config --local user.email "${PATCH_GIT_USER_EMAIL}"
358 fi
359 if ! git config user.name > /dev/null ; then
360 git config --local user.name "${PATCH_GIT_USER_NAME}"
361 fi
362}