1 2oe_soinstall() { 3 # Purpose: Install shared library file and 4 # create the necessary links 5 # Example: oe_soinstall libfoo.so.1.2.3 ${D}${libdir} 6 libname=`basename $1` 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 12 install -m 755 $1 $2/$libname 13 sonamelink=`${HOST_PREFIX}readelf -d $1 |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'` 14 if [ -z $sonamelink ]; then 15 bbfatal "oe_soinstall: $libname is missing ELF tag 'SONAME'." 16 fi 17 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 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 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 157create_cmdline_wrapper () { 158 # Create a wrapper script where commandline options are needed 159 # 160 # These are useful to work around relocation issues, by passing extra options 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` 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 178 cat <<END >$cmd 179#!/bin/bash 180realpath=\`readlink -fn \$0\` 181realdir=\`dirname \$realpath\` 182exec -a \$realdir/$cmdname \$realdir/$cmdname.real $cmdoptions "\$@" 183END 184 chmod +x $cmd 185} 186 187create_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` 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 208 cat <<END >$cmd 209#!/bin/bash 210realpath=\`readlink -fn \$0\` 211realdir=\`dirname \$realpath\` 212export $exportstring 213exec -a "\$0" \$realdir/$cmdname.real "\$@" 214END 215 chmod +x $cmd 216} 217 218# Copy files/directories from $1 to $2 but using hardlinks 219# (preserve symlinks) 220hardlinkdir () { 221 from=$1 222 to=$2 223 (cd $from; find . -print0 | cpio --null -pdlu $to) 224} 225 226 227def check_app_exists(app, d): 228 app = d.expand(app).split()[0].strip() 229 path = d.getVar('PATH') 230 return bool(bb.utils.which(path, app)) 231 232def explode_deps(s): 233 return bb.utils.explode_deps(s) 234 235def base_set_filespath(path, d): 236 filespath = [] 237 extrapaths = (d.getVar("FILESEXTRAPATHS") or "") 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 244 overrides = (":" + (d.getVar("FILESOVERRIDES") or "")).split(":") 245 overrides.reverse() 246 for o in overrides: 247 for p in path: 248 if p != "": 249 filespath.append(os.path.join(p, o)) 250 return ":".join(filespath) 251 252def extend_variants(d, var, extend, delim=':'): 253 """Return a string of all bb class extend variants for the given extend""" 254 variants = [] 255 whole = d.getVar(var) or "" 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 262def multilib_pkg_extend(d, pkg): 263 variants = (d.getVar("MULTILIB_VARIANTS") or "").split() 264 if not variants: 265 return pkg 266 pkgs = pkg 267 for v in variants: 268 pkgs = pkgs + " " + v + "-" + pkg 269 return pkgs 270 271def get_multilib_datastore(variant, d): 272 return oe.utils.get_multilib_datastore(variant, d) 273 274def 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 = [] 277 variants = (d.getVar("MULTILIB_VARIANTS") or "").split() + [''] 278 for item in variants: 279 localdata = get_multilib_datastore(item, d) 280 # We need WORKDIR to be consistent with the original datastore 281 localdata.setVar("WORKDIR", d.getVar("WORKDIR")) 282 value = localdata.getVar(var) or "" 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) 298 299def 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] = [] 309 values['ml'] = [''] 310 311 variants = (d.getVar("MULTILIB_VARIANTS") or "").split() + [''] 312 for item in variants: 313 localdata = get_multilib_datastore(item, d) 314 values[v].append(localdata.getVar(v)) 315 values['ml'].append(item) 316 return values 317all_multilib_tune_list[vardepsexclude] = "OVERRIDES" 318 319# If the user hasn't set up their name/email, set some defaults 320check_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} 328