add mk-standalone

This commit is contained in:
Josh Holtrop 2016-12-06 13:22:32 -05:00
parent 0b29b4e328
commit 9d140d2509

24
mk-standalone Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env python3
import re
import sys
import os
from subprocess import *
def main(args):
if len(args) < 3:
sys.stderr.write("Usage: %s binary dest\n" % args[0])
return 1
binary = args[1]
dest = args[2]
os.mkdir(dest)
for line in Popen(["ldd", binary], stdout = PIPE).communicate()[0].decode().split("\n"):
m = re.search(r'=>\s*(/\S*)', line)
if m is not None:
lib = m.group(1)
os.spawnlp(os.P_WAIT, "cp", "cp", "-L", lib, dest)
os.spawnlp(os.P_WAIT, "cp", "cp", "-L", binary, dest)
os.spawnlp(os.P_WAIT, "patchelf", "patchelf", "--set-rpath", "$ORIGIN", os.path.join(dest, os.path.basename(binary)))
if __name__ == "__main__":
sys.exit(main(sys.argv))