strip-binaries.py 1.8 KB

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