strip-binaries.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import argparse
  4. import os
  5. import sys
  6. from lib.config import LINUX_BINARIES
  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([strip, '--preserve-dates', binary_path])
  23. def main():
  24. args = parse_args()
  25. if args.file:
  26. strip_binary(args.file, args.target_cpu)
  27. else:
  28. strip_binaries(args.directory, args.target_cpu)
  29. def parse_args():
  30. parser = argparse.ArgumentParser(description='Strip linux binaries')
  31. parser.add_argument('-d', '--directory',
  32. help='Path to the dir that contains files to strip.',
  33. default=get_out_dir(),
  34. required=False)
  35. parser.add_argument('-f', '--file',
  36. help='Path to a specific file to strip.',
  37. required=False)
  38. parser.add_argument('-v', '--verbose',
  39. action='store_true',
  40. help='Prints the output of the subprocesses')
  41. parser.add_argument('--target-cpu',
  42. default='',
  43. required=False,
  44. help='Target cpu of binaries to strip')
  45. return parser.parse_args()
  46. if __name__ == '__main__':
  47. sys.exit(main())