Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 1 | UNINATIVE_LOADER ?= "${STAGING_DIR}-uninative/${BUILD_ARCH}-linux/lib/${@bb.utils.contains('BUILD_ARCH', 'x86_64', 'ld-linux-x86-64.so.2', 'ld-linux.so.2', d)}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 3 | UNINATIVE_URL ?= "unset" |
| 4 | UNINATIVE_TARBALL ?= "${BUILD_ARCH}-nativesdk-libc.tar.bz2" |
| 5 | # Example checksums |
| 6 | #UNINATIVE_CHECKSUM[i586] = "dead" |
| 7 | #UNINATIVE_CHECKSUM[x86_64] = "dead" |
| 8 | UNINATIVE_DLDIR ?= "${DL_DIR}/uninative/" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 10 | # https://wiki.debian.org/GCC5 |
| 11 | # We may see binaries built with gcc5 run or linked into gcc4 environment |
| 12 | # so use the older libstdc++ standard for now until we don't support gcc4 |
| 13 | # on the host system. |
| 14 | BUILD_CXXFLAGS_append = " -D_GLIBCXX_USE_CXX11_ABI=0" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 15 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 16 | # |
| 17 | # icu configure defaults to CXX11 if no -std= option is passed in CXXFLAGS |
| 18 | # therefore pass one |
| 19 | BUILD_CXXFLAGS_append_pn-icu-native = " -std=c++98" |
| 20 | |
| 21 | addhandler uninative_event_fetchloader |
| 22 | uninative_event_fetchloader[eventmask] = "bb.event.BuildStarted" |
| 23 | |
| 24 | addhandler uninative_event_enable |
| 25 | uninative_event_enable[eventmask] = "bb.event.ConfigParsed" |
| 26 | |
| 27 | python uninative_event_fetchloader() { |
| 28 | """ |
| 29 | This event fires on the parent and will try to fetch the tarball if the |
| 30 | loader isn't already present. |
| 31 | """ |
| 32 | |
| 33 | chksum = d.getVarFlag("UNINATIVE_CHECKSUM", d.getVar("BUILD_ARCH", True), True) |
| 34 | if not chksum: |
| 35 | bb.fatal("Uninative selected but not configured correctly, please set UNINATIVE_CHECKSUM[%s]" % d.getVar("BUILD_ARCH", True)) |
| 36 | |
| 37 | loader = d.getVar("UNINATIVE_LOADER", True) |
| 38 | loaderchksum = loader + ".chksum" |
| 39 | if os.path.exists(loader) and os.path.exists(loaderchksum): |
| 40 | with open(loaderchksum, "r") as f: |
| 41 | readchksum = f.read().strip() |
| 42 | if readchksum == chksum: |
| 43 | return |
| 44 | |
| 45 | import subprocess |
| 46 | try: |
| 47 | # Save and restore cwd as Fetch.download() does a chdir() |
| 48 | olddir = os.getcwd() |
| 49 | |
| 50 | tarball = d.getVar("UNINATIVE_TARBALL", True) |
| 51 | tarballdir = os.path.join(d.getVar("UNINATIVE_DLDIR", True), chksum) |
| 52 | tarballpath = os.path.join(tarballdir, tarball) |
| 53 | |
| 54 | if not os.path.exists(tarballpath): |
| 55 | bb.utils.mkdirhier(tarballdir) |
| 56 | if d.getVar("UNINATIVE_URL", True) == "unset": |
| 57 | bb.fatal("Uninative selected but not configured, please set UNINATIVE_URL") |
| 58 | |
| 59 | localdata = bb.data.createCopy(d) |
| 60 | localdata.setVar('FILESPATH', "") |
| 61 | localdata.setVar('DL_DIR', tarballdir) |
| 62 | |
| 63 | srcuri = d.expand("${UNINATIVE_URL}${UNINATIVE_TARBALL};sha256sum=%s" % chksum) |
| 64 | bb.note("Fetching uninative binary shim from %s" % srcuri) |
| 65 | |
| 66 | fetcher = bb.fetch2.Fetch([srcuri], localdata, cache=False) |
| 67 | fetcher.download() |
| 68 | localpath = fetcher.localpath(srcuri) |
| 69 | if localpath != tarballpath and os.path.exists(localpath) and not os.path.exists(tarballpath): |
| 70 | os.symlink(localpath, tarballpath) |
| 71 | |
| 72 | cmd = d.expand("mkdir -p ${STAGING_DIR}-uninative; cd ${STAGING_DIR}-uninative; tar -xjf ${UNINATIVE_DLDIR}/%s/${UNINATIVE_TARBALL}; ${STAGING_DIR}-uninative/relocate_sdk.py ${STAGING_DIR}-uninative/${BUILD_ARCH}-linux ${UNINATIVE_LOADER} ${UNINATIVE_LOADER} ${STAGING_DIR}-uninative/${BUILD_ARCH}-linux/${bindir_native}/patchelf-uninative ${STAGING_DIR}-uninative/${BUILD_ARCH}-linux${base_libdir_native}/libc*.so" % chksum) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 73 | subprocess.check_call(cmd, shell=True) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 74 | |
| 75 | with open(loaderchksum, "w") as f: |
| 76 | f.write(chksum) |
| 77 | |
| 78 | enable_uninative(d) |
| 79 | |
| 80 | except bb.fetch2.BBFetchException as exc: |
| 81 | bb.warn("Disabling uninative as unable to fetch uninative tarball: %s" % str(exc)) |
| 82 | bb.warn("To build your own uninative loader, please bitbake uninative-tarball and set UNINATIVE_TARBALL appropriately.") |
| 83 | except subprocess.CalledProcessError as exc: |
| 84 | bb.warn("Disabling uninative as unable to install uninative tarball: %s" % str(exc)) |
| 85 | bb.warn("To build your own uninative loader, please bitbake uninative-tarball and set UNINATIVE_TARBALL appropriately.") |
| 86 | finally: |
| 87 | os.chdir(olddir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 88 | } |
| 89 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 90 | python uninative_event_enable() { |
| 91 | """ |
| 92 | This event handler is called in the workers and is responsible for setting |
| 93 | up uninative if a loader is found. |
| 94 | """ |
| 95 | enable_uninative(d) |
| 96 | } |
| 97 | |
| 98 | def enable_uninative(d): |
| 99 | loader = d.getVar("UNINATIVE_LOADER", True) |
| 100 | if os.path.exists(loader): |
| 101 | bb.debug(2, "Enabling uninative") |
| 102 | d.setVar("NATIVELSBSTRING", "universal") |
| 103 | d.appendVar("SSTATEPOSTUNPACKFUNCS", " uninative_changeinterp") |
| 104 | d.prependVar("PATH", "${STAGING_DIR}-uninative/${BUILD_ARCH}-linux${bindir_native}:") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 105 | |
| 106 | python uninative_changeinterp () { |
| 107 | import subprocess |
| 108 | import stat |
| 109 | import oe.qa |
| 110 | |
| 111 | if not (bb.data.inherits_class('native', d) or bb.data.inherits_class('crosssdk', d) or bb.data.inherits_class('cross', d)): |
| 112 | return |
| 113 | |
| 114 | sstateinst = d.getVar('SSTATE_INSTDIR', True) |
| 115 | for walkroot, dirs, files in os.walk(sstateinst): |
| 116 | for file in files: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 117 | if file.endswith(".so") or ".so." in file: |
| 118 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 119 | f = os.path.join(walkroot, file) |
| 120 | if os.path.islink(f): |
| 121 | continue |
| 122 | s = os.stat(f) |
| 123 | if not ((s[stat.ST_MODE] & stat.S_IXUSR) or (s[stat.ST_MODE] & stat.S_IXGRP) or (s[stat.ST_MODE] & stat.S_IXOTH)): |
| 124 | continue |
| 125 | elf = oe.qa.ELFFile(f) |
| 126 | try: |
| 127 | elf.open() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 128 | except oe.qa.NotELFFileError: |
| 129 | continue |
| 130 | if not elf.isDynamic(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 131 | continue |
| 132 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 133 | try: |
| 134 | subprocess.check_output(("patchelf-uninative", "--set-interpreter", |
| 135 | d.getVar("UNINATIVE_LOADER", True), f), |
| 136 | stderr=subprocess.STDOUT) |
| 137 | except subprocess.CalledProcessError as e: |
| 138 | bb.fatal("'%s' failed with exit code %d and the following output:\n%s" % |
| 139 | (e.cmd, e.returncode, e.output)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 140 | } |