| 1 | from rpython.translator.platform.linux import Linux |
| 2 | from rpython.translator.platform.posix import _run_subprocess, GnuMakefile |
| 3 | from rpython.translator.platform import ExecutionResult, log |
| 4 | from os import getenv |
| 5 | |
| 6 | SB2 = getenv('SB2') |
| 7 | if SB2 is None: |
| 8 | log.error('SB2: Provide a path to the sb2 rootfs for the target in env variable SB2') |
| 9 | assert 0 |
| 10 | |
| 11 | sb2_params = getenv('SB2OPT') |
| 12 | if sb2_params is None: |
| 13 | log.info('Pass additional options to sb2 in SB2OPT') |
| 14 | SB2ARGS = [] |
| 15 | else: |
| 16 | SB2ARGS = sb2_params.split(' ') |
| 17 | |
| 18 | class ARM(Linux): |
| 19 | name = "arm" |
| 20 | shared_only = ('-fPIC',) |
| 21 | |
| 22 | available_librarydirs = [SB2 + '/lib/arm-linux-gnueabi/', |
| 23 | SB2 + '/lib/arm-linux-gnueabihf/', |
| 24 | SB2 + '/lib/aarch64-linux-gnu/', |
| 25 | SB2 + '/usr/lib/arm-linux-gnueabi/', |
| 26 | SB2 + '/usr/lib/arm-linux-gnueabihf/', |
| 27 | SB2 + '/usr/lib/aarch64-linux-gnu/'] |
| 28 | |
| 29 | available_includedirs = [SB2 + '/usr/include/arm-linux-gnueabi/', |
| 30 | SB2 + '/usr/include/arm-linux-gnueabihf/', |
| 31 | SB2 + '/usr/include/aarch64-linux-gnu/'] |
| 32 | copied_cache = {} |
| 33 | |
| 34 | |
| 35 | def _invent_new_name(self, basepath, base): |
| 36 | pth = basepath.join(base) |
| 37 | num = 0 |
| 38 | while pth.check(): |
| 39 | pth = basepath.join('%s_%d' % (base,num)) |
| 40 | num += 1 |
| 41 | return pth.ensure(dir=1) |
| 42 | |
| 43 | def _execute_c_compiler(self, cc, args, outname, cwd=None): |
| 44 | log.execute('sb2 ' + ' '.join(SB2ARGS) + ' ' + cc + ' ' + ' '.join(args)) |
| 45 | args = SB2ARGS + [cc] + args |
| 46 | returncode, stdout, stderr = _run_subprocess('sb2', args) |
| 47 | self._handle_error(returncode, stderr, stdout, outname) |
| 48 | |
| 49 | def execute(self, executable, args=[], env=None): |
| 50 | if isinstance(args, str): |
| 51 | args = ' '.join(SB2ARGS) + ' ' + str(executable) + ' ' + args |
| 52 | log.message('executing sb2 ' + args) |
| 53 | else: |
| 54 | args = SB2ARGS + [str(executable)] + args |
| 55 | log.message('executing sb2 ' + ' '.join(args)) |
| 56 | returncode, stdout, stderr = _run_subprocess('sb2', args, |
| 57 | env) |
| 58 | return ExecutionResult(returncode, stdout, stderr) |
| 59 | |
| 60 | def include_dirs_for_libffi(self): |
| 61 | return self.available_includedirs |
| 62 | |
| 63 | def library_dirs_for_libffi(self): |
| 64 | return self.available_librarydirs |
| 65 | |
| 66 | def _preprocess_library_dirs(self, library_dirs): |
| 67 | return list(library_dirs) + self.available_librarydirs |
| 68 | |
| 69 | def execute_makefile(self, path_to_makefile, extra_opts=[]): |
| 70 | if isinstance(path_to_makefile, GnuMakefile): |
| 71 | path = path_to_makefile.makefile_dir |
| 72 | else: |
| 73 | path = path_to_makefile |
| 74 | log.execute('sb2 %s make %s in %s' % (' '.join(SB2ARGS), " ".join(extra_opts), path)) |
| 75 | returncode, stdout, stderr = _run_subprocess( |
| 76 | 'sb2', SB2ARGS + ['make', '-C', str(path)] + extra_opts) |
| 77 | self._handle_error(returncode, stdout, stderr, path.join('make')) |