Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | |
| 2 | oe_soinstall() { |
| 3 | # Purpose: Install shared library file and |
| 4 | # create the necessary links |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 5 | # Example: oe_soinstall libfoo.so.1.2.3 ${D}${libdir} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | libname=`basename $1` |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 12 | install -m 755 $1 $2/$libname |
| 13 | sonamelink=`${HOST_PREFIX}readelf -d $1 |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'` |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 14 | if [ -z $sonamelink ]; then |
| 15 | bbfatal "oe_soinstall: $libname is missing ELF tag 'SONAME'." |
| 16 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 17 | solink=`echo $libname | sed -e 's/\.so\..*/.so/'` |
| 18 | ln -sf $libname $2/$sonamelink |
| 19 | ln -sf $libname $2/$solink |
| 20 | } |
| 21 | |
| 22 | oe_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 | |
| 162 | oe_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 | |
| 192 | create_cmdline_wrapper () { |
| 193 | # Create a wrapper script where commandline options are needed |
| 194 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 195 | # These are useful to work around relocation issues, by passing extra options |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 196 | # 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 207 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 213 | cat <<END >$cmd |
| 214 | #!/bin/bash |
| 215 | realpath=\`readlink -fn \$0\` |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 216 | realdir=\`dirname \$realpath\` |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 217 | exec -a \$realdir/$cmdname \$realdir/$cmdname.real $cmdoptions "\$@" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 218 | END |
| 219 | chmod +x $cmd |
| 220 | } |
| 221 | |
| 222 | create_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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 237 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 243 | cat <<END >$cmd |
| 244 | #!/bin/bash |
| 245 | realpath=\`readlink -fn \$0\` |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 246 | realdir=\`dirname \$realpath\` |
| 247 | export $exportstring |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 248 | exec -a "\$0" \$realdir/$cmdname.real "\$@" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 249 | END |
| 250 | chmod +x $cmd |
| 251 | } |
| 252 | |
| 253 | # Copy files/directories from $1 to $2 but using hardlinks |
| 254 | # (preserve symlinks) |
| 255 | hardlinkdir () { |
| 256 | from=$1 |
| 257 | to=$2 |
| 258 | (cd $from; find . -print0 | cpio --null -pdlu $to) |
| 259 | } |
| 260 | |
| 261 | |
| 262 | def check_app_exists(app, d): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 263 | app = d.expand(app).split()[0].strip() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 264 | path = d.getVar('PATH') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 265 | return bool(bb.utils.which(path, app)) |
| 266 | |
| 267 | def explode_deps(s): |
| 268 | return bb.utils.explode_deps(s) |
| 269 | |
| 270 | def base_set_filespath(path, d): |
| 271 | filespath = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 272 | extrapaths = (d.getVar("FILESEXTRAPATHS") or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 273 | # 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 279 | overrides = (":" + (d.getVar("FILESOVERRIDES") or "")).split(":") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 280 | overrides.reverse() |
| 281 | for o in overrides: |
| 282 | for p in path: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 283 | if p != "": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 284 | filespath.append(os.path.join(p, o)) |
| 285 | return ":".join(filespath) |
| 286 | |
| 287 | def extend_variants(d, var, extend, delim=':'): |
| 288 | """Return a string of all bb class extend variants for the given extend""" |
| 289 | variants = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 290 | whole = d.getVar(var) or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 291 | 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 | |
| 297 | def multilib_pkg_extend(d, pkg): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 298 | variants = (d.getVar("MULTILIB_VARIANTS") or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 299 | if not variants: |
| 300 | return pkg |
| 301 | pkgs = pkg |
| 302 | for v in variants: |
| 303 | pkgs = pkgs + " " + v + "-" + pkg |
| 304 | return pkgs |
| 305 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 306 | def get_multilib_datastore(variant, d): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 307 | return oe.utils.get_multilib_datastore(variant, d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 308 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 309 | def 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 Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 312 | variants = (d.getVar("MULTILIB_VARIANTS") or "").split() + [''] |
| 313 | for item in variants: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 314 | localdata = get_multilib_datastore(item, d) |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 315 | # We need WORKDIR to be consistent with the original datastore |
| 316 | localdata.setVar("WORKDIR", d.getVar("WORKDIR")) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 317 | value = localdata.getVar(var) or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 318 | 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 333 | |
| 334 | def 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 344 | values['ml'] = [''] |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 345 | |
| 346 | variants = (d.getVar("MULTILIB_VARIANTS") or "").split() + [''] |
| 347 | for item in variants: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 348 | localdata = get_multilib_datastore(item, d) |
| 349 | values[v].append(localdata.getVar(v)) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 350 | values['ml'].append(item) |
| 351 | return values |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 352 | all_multilib_tune_list[vardepsexclude] = "OVERRIDES" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 353 | |
| 354 | # If the user hasn't set up their name/email, set some defaults |
| 355 | check_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 | } |