Added libtool fixup to libtool-stage.
[oe-lite:cbss-core.git] / classes / libtool-stage.bbclass
1 STAGE_FIXUP_FUNCS += "libtool_stage_fixup"
2
3 python libtool_stage_fixup () {
4     import glob, sys, os
5     tempdir = bb.data.getVar('TEMP_STAGE_DIR', d, True)
6     os.chdir(tempdir)
7     recipe_type = d.getVar("RECIPE_TYPE", True)
8     stage_dir = os.path.realpath(d.getVar("STAGE_DIR", True))
9     stage_libdir = d.getVar("stage_libdir", True).lstrip("/")
10     stage_base_libdir = d.getVar("stage_base_libdir", True).lstrip("/")
11     target_libdir = d.getVar("target_libdir", True).lstrip("/")
12     target_base_libdir = d.getVar("target_base_libdir", True).lstrip("/")
13     libdir = d.getVar("libdir", True).lstrip("/")
14     base_libdir = d.getVar("base_libdir", True).lstrip("/")
15
16     def lafile_fixup(stage_subdir, libdir, base_libdir):
17         sysroot = "%s/%s"%(stage_dir, stage_subdir)
18         lafiles = set(glob.glob("%s/*.la"%(libdir))).union(
19                       glob.glob("%s/*.la"%(base_libdir)))
20         for filename in lafiles:
21             fixed = ""
22             with open(filename) as lafile:
23                 for line in lafile.readlines():
24                     line = line.replace("-L/%s"%(libdir),
25                                         "-L%s/%s"%(sysroot, libdir))
26                     line = line.replace("-L/%s"%(base_libdir),
27                                         "-L%s/%s"%(sysroot, base_libdir))
28                     line = line.replace("libdir='/%s'"%(libdir),
29                                         "libdir='%s/%s'"%(sysroot, libdir))
30                     line = line.replace("libdir='/%s'"%(base_libdir),
31                                         "libdir='%s/%s'"%(sysroot, base_libdir))
32                     line = line.replace("'/usr/lib",
33                                         "'%s/%s"%(sysroot, libdir))
34                     line = line.replace(" /usr/lib",
35                                         " %s/%s"%(sysroot, libdir))
36                     line = line.replace("'/lib",
37                                         "'%s/%s"%(sysroot, base_libdir))
38                     line = line.replace(" /lib",
39                                         " %s/%s"%(sysroot, base_libdir))
40                     fixed += line
41             with open(filename, "w") as lafile:
42                 lafile.write(fixed)
43         return
44
45     lafile_fixup("native", stage_libdir, stage_base_libdir)
46     if recipe_type == "canadian-cross":
47         lafile_fixup("host/sysroot", libdir, base_libdir)
48         lafile_fixup("target/sysroot", target_libdir, target_base_libdir)
49     elif recipe_type != "native":
50         lafile_fixup("sysroot", libdir, base_libdir)
51 }