strip-binaries.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python
  2. import argparse
  3. import os
  4. import sys
  5. from lib.config import LINUX_BINARIES
  6. from lib.util import execute, get_out_dir
  7. def strip_binaries(directory, target_cpu):
  8. for binary in LINUX_BINARIES:
  9. binary_path = os.path.join(directory, binary)
  10. if os.path.isfile(binary_path):
  11. strip_binary(binary_path, target_cpu)
  12. def strip_binary(binary_path, target_cpu):
  13. if target_cpu == 'arm':
  14. strip = 'arm-linux-gnueabihf-strip'
  15. elif target_cpu == 'arm64':
  16. strip = 'aarch64-linux-gnu-strip'
  17. elif target_cpu == 'mips64el':
  18. strip = 'mips64el-redhat-linux-strip'
  19. else:
  20. strip = 'strip'
  21. execute([strip, '--preserve-dates', binary_path])
  22. def main():
  23. args = parse_args()
  24. if args.file:
  25. strip_binary(args.file, args.target_cpu)
  26. else:
  27. strip_binaries(args.directory, args.target_cpu)
  28. def parse_args():
  29. parser = argparse.ArgumentParser(description='Strip linux binaries')
  30. parser.add_argument('-d', '--directory',
  31. help='Path to the dir that contains files to strip.',
  32. default=get_out_dir(),
  33. required=False)
  34. parser.add_argument('-f', '--file',
  35. help='Path to a specific file to strip.',
  36. required=False)
  37. parser.add_argument('-v', '--verbose',
  38. action='store_true',
  39. help='Prints the output of the subprocesses')
  40. parser.add_argument('--target-cpu',
  41. default='',
  42. required=False,
  43. help='Target cpu of binaries to strip')
  44. return parser.parse_args()
  45. if __name__ == '__main__':
  46. sys.exit(main())