4 This should only be run on a native Cell machine. E.g., ps3, qs21, etc.
6 It makes a few modifications to the file system and some pseudo shared libs
7 so that cross compiling from a build machine over NFS works. The changes
8 do not harm local compilation.
10 We create a symlink from /mnt/cell-root that points to /
11 This allows the local and build machine to access the root filesystem
12 using a common name, /mnt/cell-root. This is required because
13 configure hardcodes absolute paths into the generated Makefiles.
15 There are some .so files that aren't really shared libraries, but rather are
16 ascii linker scripts containing instructions to the linker. Most of them
17 contain a GROUP directive that includes hard-coded paths relative to /.
18 We modify those files such that the hard-coded paths are relative to /mnt/cell-root
19 instead of /. This allows them to work locally and while cross compiling over NFS.
21 E.g., /usr/lib/libc.so originally contains:
24 Use the shared library, but some functions are only in
25 the static library, so try that secondarily. */
26 OUTPUT_FORMAT(elf32-powerpc)
27 GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a AS_NEEDED ( /lib/ld.so.1 ) )
29 We modify it such that it reads:
32 Use the shared library, but some functions are only in
33 the static library, so try that secondarily. */
34 OUTPUT_FORMAT(elf32-powerpc)
35 GROUP ( /mnt/cell-root/lib/libc.so.6 /mnt/cell-root/usr/lib/libc_nonshared.a AS_NEEDED ( /mnt/cell-root/lib/ld.so.1 ) )
37 We backup <foo>.so to <foo>.so.original
47 cell_root_path = '/mnt/cell-root'
50 s = open('/proc/cpuinfo','r').read()
51 if s.find('Cell Broadband Engine') == -1:
52 sys.stderr.write('This program should only be run on Cell machines.\n')
56 create_symlink_if_reqd(cell_root_path, "..")
57 create_symlink_if_reqd("/opt/cell/toolchain", "../../usr")
58 create_symlink_if_reqd("/opt/cell/sysroot", "../..")
60 def symlink_exists_and_is_ok(path, contents):
61 return (os.path.islink(path) and os.readlink(path) == contents)
63 def create_symlink_if_reqd(path, contents):
64 if symlink_exists_and_is_ok(path, contents):
67 if os.path.islink(path):
68 # Is a symlink but points wrong place
70 os.symlink(contents, path)
73 if os.path.isdir(path):
74 # if it's empty we'll remove it and create the link
78 # directory wasn't empty
79 sys.stderr.write("There's already something at %s.\n" % (path,))
80 sys.stderr.write("Please remove it or move it out of the way and try again.\n")
82 os.symlink(contents, path)
85 if os.path.exists(path):
86 # There's something here, return an error
87 sys.stderr.write("There's already something at %s.\n" % (path,))
88 sys.stderr.write("Please remove it or move it out of the way and try again.\n")
91 # nothing there; go ahead and create the symlink
92 os.symlink(contents, path)
95 def find_ascii_shared_libs():
96 cmd = "find /lib /lib64 /usr/lib /usr/lib64 -name '*.so' -type f -print 2>/dev/null | xargs file | grep -v ELF | cut -d: -f 1"
97 pipe = os.popen(cmd, 'r')
98 filenames = pipe.read().splitlines()
102 def make_backup_copy(src):
103 dst = src + '.original'
104 if not os.path.exists(dst):
105 shutil.copy2(src, dst)
109 def replace_group_body(mo):
110 pat = ' /(?!' + cell_root_path[1:] + ')' # negative lookahead assertion
111 new = re.sub(pat, ' ' + cell_root_path + '/', mo.group(2))
112 return mo.group(1) + new + mo.group(3)
118 pat = re.compile(r'^( *GROUP *\()(.*)(\) *)$', re.M)
119 t = pat.sub(replace_group_body, s)
126 def edit_ascii_shared_libs():
127 print "Please be patient, this takes awhile..."
128 filenames = find_ascii_shared_libs()
137 edit_ascii_shared_libs()
140 if __name__ == '__main__':