summaryrefslogtreecommitdiffstats
path: root/meta/classes/utils.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/utils.bbclass')
-rw-r--r--meta/classes/utils.bbclass368
1 files changed, 368 insertions, 0 deletions
diff --git a/meta/classes/utils.bbclass b/meta/classes/utils.bbclass
new file mode 100644
index 0000000000..0a533afb1f
--- /dev/null
+++ b/meta/classes/utils.bbclass
@@ -0,0 +1,368 @@
1# For compatibility
2def base_path_join(a, *p):
3 return oe.path.join(a, *p)
4
5def base_path_relative(src, dest):
6 return oe.path.relative(src, dest)
7
8def base_path_out(path, d):
9 return oe.path.format_display(path, d)
10
11def base_read_file(filename):
12 return oe.utils.read_file(filename)
13
14def base_ifelse(condition, iftrue = True, iffalse = False):
15 return oe.utils.ifelse(condition, iftrue, iffalse)
16
17def base_conditional(variable, checkvalue, truevalue, falsevalue, d):
18 return oe.utils.conditional(variable, checkvalue, truevalue, falsevalue, d)
19
20def base_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
21 return oe.utils.less_or_equal(variable, checkvalue, truevalue, falsevalue, d)
22
23def base_version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
24 return oe.utils.version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d)
25
26def base_contains(variable, checkvalues, truevalue, falsevalue, d):
27 return oe.utils.contains(variable, checkvalues, truevalue, falsevalue, d)
28
29def base_both_contain(variable1, variable2, checkvalue, d):
30 return oe.utils.both_contain(variable1, variable2, checkvalue, d)
31
32def base_prune_suffix(var, suffixes, d):
33 return oe.utils.prune_suffix(var, suffixes, d)
34
35def oe_filter(f, str, d):
36 return oe.utils.str_filter(f, str, d)
37
38def oe_filter_out(f, str, d):
39 return oe.utils.str_filter_out(f, str, d)
40
41def machine_paths(d):
42 """List any existing machine specific filespath directories"""
43 machine = d.getVar("MACHINE", True)
44 filespathpkg = d.getVar("FILESPATHPKG", True).split(":")
45 for basepath in d.getVar("FILESPATHBASE", True).split(":"):
46 for pkgpath in filespathpkg:
47 machinepath = os.path.join(basepath, pkgpath, machine)
48 if os.path.isdir(machinepath):
49 yield machinepath
50
51def is_machine_specific(d):
52 """Determine whether the current recipe is machine specific"""
53 machinepaths = set(machine_paths(d))
54 srcuri = d.getVar("SRC_URI", True).split()
55 for url in srcuri:
56 fetcher = bb.fetch2.Fetch([srcuri], d)
57 if url.startswith("file://"):
58 if any(fetcher.localpath(url).startswith(mp + "/") for mp in machinepaths):
59 return True
60
61oe_soinstall() {
62 # Purpose: Install shared library file and
63 # create the necessary links
64 # Example:
65 #
66 # oe_
67 #
68 #bbnote installing shared library $1 to $2
69 #
70 libname=`basename $1`
71 install -m 755 $1 $2/$libname
72 sonamelink=`${HOST_PREFIX}readelf -d $1 |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
73 solink=`echo $libname | sed -e 's/\.so\..*/.so/'`
74 ln -sf $libname $2/$sonamelink
75 ln -sf $libname $2/$solink
76}
77
78oe_libinstall() {
79 # Purpose: Install a library, in all its forms
80 # Example
81 #
82 # oe_libinstall libltdl ${STAGING_LIBDIR}/
83 # oe_libinstall -C src/libblah libblah ${D}/${libdir}/
84 dir=""
85 libtool=""
86 silent=""
87 require_static=""
88 require_shared=""
89 staging_install=""
90 while [ "$#" -gt 0 ]; do
91 case "$1" in
92 -C)
93 shift
94 dir="$1"
95 ;;
96 -s)
97 silent=1
98 ;;
99 -a)
100 require_static=1
101 ;;
102 -so)
103 require_shared=1
104 ;;
105 -*)
106 bbfatal "oe_libinstall: unknown option: $1"
107 ;;
108 *)
109 break;
110 ;;
111 esac
112 shift
113 done
114
115 libname="$1"
116 shift
117 destpath="$1"
118 if [ -z "$destpath" ]; then
119 bbfatal "oe_libinstall: no destination path specified"
120 fi
121 if echo "$destpath/" | egrep '^${STAGING_LIBDIR}/' >/dev/null
122 then
123 staging_install=1
124 fi
125
126 __runcmd () {
127 if [ -z "$silent" ]; then
128 echo >&2 "oe_libinstall: $*"
129 fi
130 $*
131 }
132
133 if [ -z "$dir" ]; then
134 dir=`pwd`
135 fi
136
137 dotlai=$libname.lai
138
139 # Sanity check that the libname.lai is unique
140 number_of_files=`(cd $dir; find . -name "$dotlai") | wc -l`
141 if [ $number_of_files -gt 1 ]; then
142 bbfatal "oe_libinstall: $dotlai is not unique in $dir"
143 fi
144
145
146 dir=$dir`(cd $dir;find . -name "$dotlai") | sed "s/^\.//;s/\/$dotlai\$//;q"`
147 olddir=`pwd`
148 __runcmd cd $dir
149
150 lafile=$libname.la
151
152 # If such file doesn't exist, try to cut version suffix
153 if [ ! -f "$lafile" ]; then
154 libname1=`echo "$libname" | sed 's/-[0-9.]*$//'`
155 lafile1=$libname.la
156 if [ -f "$lafile1" ]; then
157 libname=$libname1
158 lafile=$lafile1
159 fi
160 fi
161
162 if [ -f "$lafile" ]; then
163 # libtool archive
164 eval `cat $lafile|grep "^library_names="`
165 libtool=1
166 else
167 library_names="$libname.so* $libname.dll.a $libname.*.dylib"
168 fi
169
170 __runcmd install -d $destpath/
171 dota=$libname.a
172 if [ -f "$dota" -o -n "$require_static" ]; then
173 rm -f $destpath/$dota
174 __runcmd install -m 0644 $dota $destpath/
175 fi
176 if [ -f "$dotlai" -a -n "$libtool" ]; then
177 rm -f $destpath/$libname.la
178 __runcmd install -m 0644 $dotlai $destpath/$libname.la
179 fi
180
181 for name in $library_names; do
182 files=`eval echo $name`
183 for f in $files; do
184 if [ ! -e "$f" ]; then
185 if [ -n "$libtool" ]; then
186 bbfatal "oe_libinstall: $dir/$f not found."
187 fi
188 elif [ -L "$f" ]; then
189 __runcmd cp -P "$f" $destpath/
190 elif [ ! -L "$f" ]; then
191 libfile="$f"
192 rm -f $destpath/$libfile
193 __runcmd install -m 0755 $libfile $destpath/
194 fi
195 done
196 done
197
198 if [ -z "$libfile" ]; then
199 if [ -n "$require_shared" ]; then
200 bbfatal "oe_libinstall: unable to locate shared library"
201 fi
202 elif [ -z "$libtool" ]; then
203 # special case hack for non-libtool .so.#.#.# links
204 baselibfile=`basename "$libfile"`
205 if (echo $baselibfile | grep -qE '^lib.*\.so\.[0-9.]*$'); then
206 sonamelink=`${HOST_PREFIX}readelf -d $libfile |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
207 solink=`echo $baselibfile | sed -e 's/\.so\..*/.so/'`
208 if [ -n "$sonamelink" -a x"$baselibfile" != x"$sonamelink" ]; then
209 __runcmd ln -sf $baselibfile $destpath/$sonamelink
210 fi
211 __runcmd ln -sf $baselibfile $destpath/$solink
212 fi
213 fi
214
215 __runcmd cd "$olddir"
216}
217
218oe_machinstall() {
219 # Purpose: Install machine dependent files, if available
220 # If not available, check if there is a default
221 # If no default, just touch the destination
222 # Example:
223 # $1 $2 $3 $4
224 # oe_machinstall -m 0644 fstab ${D}/etc/fstab
225 #
226 # TODO: Check argument number?
227 #
228 filename=`basename $3`
229 dirname=`dirname $3`
230
231 for o in `echo ${OVERRIDES} | tr ':' ' '`; do
232 if [ -e $dirname/$o/$filename ]; then
233 bbnote $dirname/$o/$filename present, installing to $4
234 install $1 $2 $dirname/$o/$filename $4
235 return
236 fi
237 done
238# bbnote overrides specific file NOT present, trying default=$3...
239 if [ -e $3 ]; then
240 bbnote $3 present, installing to $4
241 install $1 $2 $3 $4
242 else
243 bbnote $3 NOT present, touching empty $4
244 touch $4
245 fi
246}
247
248create_cmdline_wrapper () {
249 # Create a wrapper script where commandline options are needed
250 #
251 # These are useful to work around relocation issues, by passing extra options
252 # to a program
253 #
254 # Usage: create_cmdline_wrapper FILENAME <extra-options>
255
256 cmd=$1
257 shift
258
259 echo "Generating wrapper script for $cmd"
260
261 mv $cmd $cmd.real
262 cmdname=`basename $cmd`.real
263 cat <<END >$cmd
264#!/bin/bash
265realpath=\`readlink -fn \$0\`
266exec -a $cmd \`dirname \$realpath\`/$cmdname $@ "\$@"
267END
268 chmod +x $cmd
269}
270
271create_wrapper () {
272 # Create a wrapper script where extra environment variables are needed
273 #
274 # These are useful to work around relocation issues, by setting environment
275 # variables which point to paths in the filesystem.
276 #
277 # Usage: create_wrapper FILENAME [[VAR=VALUE]..]
278
279 cmd=$1
280 shift
281
282 echo "Generating wrapper script for $cmd"
283
284 mv $cmd $cmd.real
285 cmdname=`basename $cmd`
286 cat <<END >$cmd
287#!/bin/bash
288realpath=\`readlink -fn \$0\`
289export $@
290exec -a \`dirname \$realpath\`/$cmdname \`dirname \$realpath\`/$cmdname.real "\$@"
291END
292 chmod +x $cmd
293}
294
295def check_app_exists(app, d):
296 app = d.expand(app)
297 path = d.getVar('PATH', d, True)
298 return bool(bb.utils.which(path, app))
299
300def explode_deps(s):
301 return bb.utils.explode_deps(s)
302
303def base_set_filespath(path, d):
304 filespath = []
305 extrapaths = (d.getVar("FILESEXTRAPATHS", True) or "")
306 # Don't prepend empty strings to the path list
307 if extrapaths != "":
308 path = extrapaths.split(":") + path
309 # The ":" ensures we have an 'empty' override
310 overrides = (":" + (d.getVar("FILESOVERRIDES", True) or "")).split(":")
311 overrides.reverse()
312 for o in overrides:
313 for p in path:
314 if p != "":
315 filespath.append(os.path.join(p, o))
316 return ":".join(filespath)
317
318def extend_variants(d, var, extend, delim=':'):
319 """Return a string of all bb class extend variants for the given extend"""
320 variants = []
321 whole = d.getVar(var, True) or ""
322 for ext in whole.split():
323 eext = ext.split(delim)
324 if len(eext) > 1 and eext[0] == extend:
325 variants.append(eext[1])
326 return " ".join(variants)
327
328def multilib_pkg_extend(d, pkg):
329 variants = (d.getVar("MULTILIB_VARIANTS", True) or "").split()
330 if not variants:
331 return pkg
332 pkgs = pkg
333 for v in variants:
334 pkgs = pkgs + " " + v + "-" + pkg
335 return pkgs
336
337def all_multilib_tune_values(d, var, unique = True, need_split = True, delim = ' '):
338 """Return a string of all ${var} in all multilib tune configuration"""
339 values = []
340 value = d.getVar(var, True) or ""
341 if value != "":
342 if need_split:
343 for item in value.split(delim):
344 values.append(item)
345 else:
346 values.append(value)
347 variants = d.getVar("MULTILIB_VARIANTS", True) or ""
348 for item in variants.split():
349 localdata = bb.data.createCopy(d)
350 overrides = localdata.getVar("OVERRIDES", False) + ":virtclass-multilib-" + item
351 localdata.setVar("OVERRIDES", overrides)
352 bb.data.update_data(localdata)
353 value = localdata.getVar(var, True) or ""
354 if value != "":
355 if need_split:
356 for item in value.split(delim):
357 values.append(item)
358 else:
359 values.append(value)
360 if unique:
361 #we do this to keep order as much as possible
362 ret = []
363 for value in values:
364 if not value in ret:
365 ret.append(value)
366 else:
367 ret = values
368 return " ".join(ret)