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="" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 33 | while [ "$#" -gt 0 ]; do |
| 34 | case "$1" in |
| 35 | -C) |
| 36 | shift |
| 37 | dir="$1" |
| 38 | ;; |
| 39 | -s) |
| 40 | silent=1 |
| 41 | ;; |
| 42 | -a) |
| 43 | require_static=1 |
| 44 | ;; |
| 45 | -so) |
| 46 | require_shared=1 |
| 47 | ;; |
| 48 | -*) |
| 49 | bbfatal "oe_libinstall: unknown option: $1" |
| 50 | ;; |
| 51 | *) |
| 52 | break; |
| 53 | ;; |
| 54 | esac |
| 55 | shift |
| 56 | done |
| 57 | |
| 58 | libname="$1" |
| 59 | shift |
| 60 | destpath="$1" |
| 61 | if [ -z "$destpath" ]; then |
| 62 | bbfatal "oe_libinstall: no destination path specified" |
| 63 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 64 | |
| 65 | __runcmd () { |
| 66 | if [ -z "$silent" ]; then |
| 67 | echo >&2 "oe_libinstall: $*" |
| 68 | fi |
| 69 | $* |
| 70 | } |
| 71 | |
| 72 | if [ -z "$dir" ]; then |
| 73 | dir=`pwd` |
| 74 | fi |
| 75 | |
| 76 | dotlai=$libname.lai |
| 77 | |
| 78 | # Sanity check that the libname.lai is unique |
| 79 | number_of_files=`(cd $dir; find . -name "$dotlai") | wc -l` |
| 80 | if [ $number_of_files -gt 1 ]; then |
| 81 | bbfatal "oe_libinstall: $dotlai is not unique in $dir" |
| 82 | fi |
| 83 | |
| 84 | |
| 85 | dir=$dir`(cd $dir;find . -name "$dotlai") | sed "s/^\.//;s/\/$dotlai\$//;q"` |
| 86 | olddir=`pwd` |
| 87 | __runcmd cd $dir |
| 88 | |
| 89 | lafile=$libname.la |
| 90 | |
| 91 | # If such file doesn't exist, try to cut version suffix |
| 92 | if [ ! -f "$lafile" ]; then |
| 93 | libname1=`echo "$libname" | sed 's/-[0-9.]*$//'` |
| 94 | lafile1=$libname.la |
| 95 | if [ -f "$lafile1" ]; then |
| 96 | libname=$libname1 |
| 97 | lafile=$lafile1 |
| 98 | fi |
| 99 | fi |
| 100 | |
| 101 | if [ -f "$lafile" ]; then |
| 102 | # libtool archive |
| 103 | eval `cat $lafile|grep "^library_names="` |
| 104 | libtool=1 |
| 105 | else |
| 106 | library_names="$libname.so* $libname.dll.a $libname.*.dylib" |
| 107 | fi |
| 108 | |
| 109 | __runcmd install -d $destpath/ |
| 110 | dota=$libname.a |
| 111 | if [ -f "$dota" -o -n "$require_static" ]; then |
| 112 | rm -f $destpath/$dota |
| 113 | __runcmd install -m 0644 $dota $destpath/ |
| 114 | fi |
| 115 | if [ -f "$dotlai" -a -n "$libtool" ]; then |
| 116 | rm -f $destpath/$libname.la |
| 117 | __runcmd install -m 0644 $dotlai $destpath/$libname.la |
| 118 | fi |
| 119 | |
| 120 | for name in $library_names; do |
| 121 | files=`eval echo $name` |
| 122 | for f in $files; do |
| 123 | if [ ! -e "$f" ]; then |
| 124 | if [ -n "$libtool" ]; then |
| 125 | bbfatal "oe_libinstall: $dir/$f not found." |
| 126 | fi |
| 127 | elif [ -L "$f" ]; then |
| 128 | __runcmd cp -P "$f" $destpath/ |
| 129 | elif [ ! -L "$f" ]; then |
| 130 | libfile="$f" |
| 131 | rm -f $destpath/$libfile |
| 132 | __runcmd install -m 0755 $libfile $destpath/ |
| 133 | fi |
| 134 | done |
| 135 | done |
| 136 | |
| 137 | if [ -z "$libfile" ]; then |
| 138 | if [ -n "$require_shared" ]; then |
| 139 | bbfatal "oe_libinstall: unable to locate shared library" |
| 140 | fi |
| 141 | elif [ -z "$libtool" ]; then |
| 142 | # special case hack for non-libtool .so.#.#.# links |
| 143 | baselibfile=`basename "$libfile"` |
| 144 | if (echo $baselibfile | grep -qE '^lib.*\.so\.[0-9.]*$'); then |
| 145 | sonamelink=`${HOST_PREFIX}readelf -d $libfile |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'` |
| 146 | solink=`echo $baselibfile | sed -e 's/\.so\..*/.so/'` |
| 147 | if [ -n "$sonamelink" -a x"$baselibfile" != x"$sonamelink" ]; then |
| 148 | __runcmd ln -sf $baselibfile $destpath/$sonamelink |
| 149 | fi |
| 150 | __runcmd ln -sf $baselibfile $destpath/$solink |
| 151 | fi |
| 152 | fi |
| 153 | |
| 154 | __runcmd cd "$olddir" |
| 155 | } |
| 156 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 157 | create_cmdline_wrapper () { |
| 158 | # Create a wrapper script where commandline options are needed |
| 159 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 160 | # These are useful to work around relocation issues, by passing extra options |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 161 | # to a program |
| 162 | # |
| 163 | # Usage: create_cmdline_wrapper FILENAME <extra-options> |
| 164 | |
| 165 | cmd=$1 |
| 166 | shift |
| 167 | |
| 168 | echo "Generating wrapper script for $cmd" |
| 169 | |
| 170 | mv $cmd $cmd.real |
| 171 | cmdname=`basename $cmd` |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 172 | dirname=`dirname $cmd` |
| 173 | cmdoptions=$@ |
| 174 | if [ "${base_prefix}" != "" ]; then |
| 175 | relpath=`python3 -c "import os; print(os.path.relpath('${D}${base_prefix}', '$dirname'))"` |
| 176 | cmdoptions=`echo $@ | sed -e "s:${base_prefix}:\\$realdir/$relpath:g"` |
| 177 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 178 | cat <<END >$cmd |
| 179 | #!/bin/bash |
| 180 | realpath=\`readlink -fn \$0\` |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 181 | realdir=\`dirname \$realpath\` |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 182 | exec -a \$realdir/$cmdname \$realdir/$cmdname.real $cmdoptions "\$@" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 183 | END |
| 184 | chmod +x $cmd |
| 185 | } |
| 186 | |
| 187 | create_wrapper () { |
| 188 | # Create a wrapper script where extra environment variables are needed |
| 189 | # |
| 190 | # These are useful to work around relocation issues, by setting environment |
| 191 | # variables which point to paths in the filesystem. |
| 192 | # |
| 193 | # Usage: create_wrapper FILENAME [[VAR=VALUE]..] |
| 194 | |
| 195 | cmd=$1 |
| 196 | shift |
| 197 | |
| 198 | echo "Generating wrapper script for $cmd" |
| 199 | |
| 200 | mv $cmd $cmd.real |
| 201 | cmdname=`basename $cmd` |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 202 | dirname=`dirname $cmd` |
| 203 | exportstring=$@ |
| 204 | if [ "${base_prefix}" != "" ]; then |
| 205 | relpath=`python3 -c "import os; print(os.path.relpath('${D}${base_prefix}', '$dirname'))"` |
| 206 | exportstring=`echo $@ | sed -e "s:${base_prefix}:\\$realdir/$relpath:g"` |
| 207 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 208 | cat <<END >$cmd |
| 209 | #!/bin/bash |
| 210 | realpath=\`readlink -fn \$0\` |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 211 | realdir=\`dirname \$realpath\` |
| 212 | export $exportstring |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 213 | exec -a "\$0" \$realdir/$cmdname.real "\$@" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 214 | END |
| 215 | chmod +x $cmd |
| 216 | } |
| 217 | |
| 218 | # Copy files/directories from $1 to $2 but using hardlinks |
| 219 | # (preserve symlinks) |
| 220 | hardlinkdir () { |
| 221 | from=$1 |
| 222 | to=$2 |
| 223 | (cd $from; find . -print0 | cpio --null -pdlu $to) |
| 224 | } |
| 225 | |
| 226 | |
| 227 | def check_app_exists(app, d): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 228 | app = d.expand(app).split()[0].strip() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 229 | path = d.getVar('PATH') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 230 | return bool(bb.utils.which(path, app)) |
| 231 | |
| 232 | def explode_deps(s): |
| 233 | return bb.utils.explode_deps(s) |
| 234 | |
| 235 | def base_set_filespath(path, d): |
| 236 | filespath = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 237 | extrapaths = (d.getVar("FILESEXTRAPATHS") or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 238 | # Remove default flag which was used for checking |
| 239 | extrapaths = extrapaths.replace("__default:", "") |
| 240 | # Don't prepend empty strings to the path list |
| 241 | if extrapaths != "": |
| 242 | path = extrapaths.split(":") + path |
| 243 | # The ":" ensures we have an 'empty' override |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 244 | overrides = (":" + (d.getVar("FILESOVERRIDES") or "")).split(":") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 245 | overrides.reverse() |
| 246 | for o in overrides: |
| 247 | for p in path: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 248 | if p != "": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 249 | filespath.append(os.path.join(p, o)) |
| 250 | return ":".join(filespath) |
| 251 | |
| 252 | def extend_variants(d, var, extend, delim=':'): |
| 253 | """Return a string of all bb class extend variants for the given extend""" |
| 254 | variants = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 255 | whole = d.getVar(var) or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 256 | for ext in whole.split(): |
| 257 | eext = ext.split(delim) |
| 258 | if len(eext) > 1 and eext[0] == extend: |
| 259 | variants.append(eext[1]) |
| 260 | return " ".join(variants) |
| 261 | |
| 262 | def multilib_pkg_extend(d, pkg): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 263 | variants = (d.getVar("MULTILIB_VARIANTS") or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 264 | if not variants: |
| 265 | return pkg |
| 266 | pkgs = pkg |
| 267 | for v in variants: |
| 268 | pkgs = pkgs + " " + v + "-" + pkg |
| 269 | return pkgs |
| 270 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 271 | def get_multilib_datastore(variant, d): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 272 | return oe.utils.get_multilib_datastore(variant, d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 273 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 274 | def all_multilib_tune_values(d, var, unique = True, need_split = True, delim = ' '): |
| 275 | """Return a string of all ${var} in all multilib tune configuration""" |
| 276 | values = [] |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 277 | variants = (d.getVar("MULTILIB_VARIANTS") or "").split() + [''] |
| 278 | for item in variants: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 279 | localdata = get_multilib_datastore(item, d) |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 280 | # We need WORKDIR to be consistent with the original datastore |
| 281 | localdata.setVar("WORKDIR", d.getVar("WORKDIR")) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 282 | value = localdata.getVar(var) or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 283 | if value != "": |
| 284 | if need_split: |
| 285 | for item in value.split(delim): |
| 286 | values.append(item) |
| 287 | else: |
| 288 | values.append(value) |
| 289 | if unique: |
| 290 | #we do this to keep order as much as possible |
| 291 | ret = [] |
| 292 | for value in values: |
| 293 | if not value in ret: |
| 294 | ret.append(value) |
| 295 | else: |
| 296 | ret = values |
| 297 | return " ".join(ret) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 298 | |
| 299 | def all_multilib_tune_list(vars, d): |
| 300 | """ |
| 301 | Return a list of ${VAR} for each variable VAR in vars from each |
| 302 | multilib tune configuration. |
| 303 | Is safe to be called from a multilib recipe/context as it can |
| 304 | figure out the original tune and remove the multilib overrides. |
| 305 | """ |
| 306 | values = {} |
| 307 | for v in vars: |
| 308 | values[v] = [] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 309 | values['ml'] = [''] |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 310 | |
| 311 | variants = (d.getVar("MULTILIB_VARIANTS") or "").split() + [''] |
| 312 | for item in variants: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 313 | localdata = get_multilib_datastore(item, d) |
| 314 | values[v].append(localdata.getVar(v)) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 315 | values['ml'].append(item) |
| 316 | return values |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 317 | all_multilib_tune_list[vardepsexclude] = "OVERRIDES" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 318 | |
| 319 | # If the user hasn't set up their name/email, set some defaults |
| 320 | check_git_config() { |
| 321 | if ! git config user.email > /dev/null ; then |
| 322 | git config --local user.email "${PATCH_GIT_USER_EMAIL}" |
| 323 | fi |
| 324 | if ! git config user.name > /dev/null ; then |
| 325 | git config --local user.name "${PATCH_GIT_USER_NAME}" |
| 326 | fi |
| 327 | } |