| # SPDX-License-Identifier: GPL-2.0-only |
| # Take a sysroot directory and turn all the abolute symlinks and turn them into |
| # relative ones such that the sysroot is usable within another system. |
| print("Usage is " + sys.argv[0] + "<directory>") |
| topdir = os.path.abspath(topdir) |
| def handlelink(filep, subdir): |
| link = os.readlink(filep) |
| if link.startswith(topdir): |
| #print("Replacing %s with %s for %s" % (link, topdir+link, filep)) |
| print("Replacing %s with %s for %s" % (link, os.path.relpath(topdir+link, subdir), filep)) |
| os.symlink(os.path.relpath(topdir+link, subdir), filep) |
| for subdir, dirs, files in os.walk(topdir): |
| filep = os.path.join(subdir, f) |
| if os.path.islink(filep): |
| #print("Considering %s" % filep) |
| handlelink(filep, subdir) |