Home | History | Annotate | Download | only in armhf_sysroot
      1 #!/usr/bin/env python
      2 #
      3 # Copyright 2016 Google Inc.
      4 #
      5 # Use of this source code is governed by a BSD-style license that can be
      6 # found in the LICENSE file.
      7 
      8 
      9 """Create the asset."""
     10 
     11 
     12 import argparse
     13 import fileinput
     14 import os
     15 import shutil
     16 import subprocess
     17 import sys
     18 
     19 from distutils import dir_util
     20 
     21 
     22 def create_asset(target_dir):
     23   """Create the asset."""
     24 
     25   print "Installing some cross-compiling packages. Hit enter to continue."
     26   raw_input()
     27   subprocess.check_call([
     28     "sudo","apt-get","install",
     29     "libstdc++-4.8-dev-armhf-cross",
     30     "libgcc-4.8-dev-armhf-cross",
     31     "binutils-arm-linux-gnueabihf"
     32   ])
     33 
     34 
     35   shutil.copytree('/usr/arm-linux-gnueabihf', target_dir)
     36   shutil.copytree('/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8.4',
     37     os.path.join(target_dir, 'gcc-cross'))
     38   # copy_tree allows copying into a dir that exists
     39   # We need to augment the toolchain with some lib*.so that help ld
     40   # do its magic as well as some includes that may be useful.
     41   dir_util.copy_tree('/usr/x86_64-linux-gnu/arm-linux-gnueabihf/lib',
     42                      os.path.join(target_dir, 'lib'))
     43   dir_util.copy_tree('/usr/x86_64-linux-gnu/arm-linux-gnueabihf/include',
     44                      os.path.join(target_dir, 'include'))
     45 
     46   # The file paths in libpthread.so and libc.so start off as absolute file
     47   # paths (e.g. /usr/arm-linux-gnueabihf/lib/libpthread.so.0), which won't
     48   # work on the bots. We use fileinput to replace just those lines (which
     49   # start with GROUP). fileinput redirects stdout, so printing here actually
     50   # writes to the file.
     51   bad_libpthread = os.path.join(target_dir, "lib", "libpthread.so")
     52   for line in fileinput.input(bad_libpthread, inplace=True):
     53     if line.startswith("GROUP"):
     54       print "GROUP ( libpthread.so.0 libpthread_nonshared.a )"
     55     else:
     56       print line
     57 
     58   bad_libc = os.path.join(target_dir, "lib", "libc.so")
     59   for line in fileinput.input(bad_libc, inplace=True):
     60     if line.startswith("GROUP"):
     61       print ("GROUP ( libc.so.6 libc_nonshared.a "
     62              "AS_NEEDED ( ld-linux-armhf.so.3 ) )")
     63     else:
     64       print line
     65 
     66 
     67 def main():
     68   if 'linux' not in sys.platform:
     69     print >> sys.stderr, 'This script only runs on Linux.'
     70     sys.exit(1)
     71   parser = argparse.ArgumentParser()
     72   parser.add_argument('--target_dir', '-t', required=True)
     73   args = parser.parse_args()
     74   create_asset(args.target_dir)
     75 
     76 
     77 if __name__ == '__main__':
     78   main()
     79