summaryrefslogtreecommitdiff
path: root/meta/classes/relocatable.bbclass
blob: 7155503c9fa9828b609425f6b67f9a2d4c46a9bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
SYSROOT_PREPROCESS_FUNCS += "relocatable_binaries_preprocess"

CHRPATH_BIN ?= "chrpath"

def rpath_replace (path, d):
    import subprocess as sub

    cmd = bb.data.expand('${CHRPATH_BIN}', d)

    for root, dirs, files in os.walk(path):
        for file in files:
            fpath = root + '/' + file
            if '/bin/' in fpath:
                p = sub.Popen([cmd, '-l', fpath],stdout=sub.PIPE,stderr=sub.PIPE)
                err, out = p.communicate()
                # If returned succesfully, process stderr for results
                if p.returncode == 0:
                    # Throw away everything other than the rpath list
                    curr_rpath = err.partition("RPATH=")[2]
                    #bb.note("Current rpath for %s is %s" % (fpath, curr_rpath.strip()))
                    rpaths = curr_rpath.split(":")
                    new_rpaths = []
                    for rpath in rpaths:
                        depth = fpath.partition(path)[2].count('/')
                        if depth == 3:
                            # / is two levels up
                            root = "$ORIGIN/../.."
                        else:
                            root = "$ORIGIN/.."

                        # kill everything up to "/"
                        new_rpaths.append("%s%s" % (root, rpath.partition(path)[2].strip()))
                    args = ":".join(new_rpaths)
                    #bb.note("Setting rpath to " + args)
                    sub.call([cmd, '-r', args, fpath])

python relocatable_binaries_preprocess() {
    rpath_replace(bb.data.getVar('base_prefix', d, True), d)
}