| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 # Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 from optparse import OptionParser | 6 from optparse import OptionParser |
| 7 import os | 7 import os |
| 8 import subprocess | 8 import subprocess |
| 9 import sys | 9 import sys |
| 10 | 10 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 if toolname not in ['newlib', 'glibc', 'pnacl']: | 103 if toolname not in ['newlib', 'glibc', 'pnacl']: |
| 104 ErrOut('Toolchain of type %s not supported.' % toolname) | 104 ErrOut('Toolchain of type %s not supported.' % toolname) |
| 105 | 105 |
| 106 self.root_path = options.root | 106 self.root_path = options.root |
| 107 self.nacl_path = os.path.join(self.root_path, 'native_client') | 107 self.nacl_path = os.path.join(self.root_path, 'native_client') |
| 108 | 108 |
| 109 project_path, project_name = os.path.split(options.name) | 109 project_path, project_name = os.path.split(options.name) |
| 110 self.outdir = options.objdir | 110 self.outdir = options.objdir |
| 111 | 111 |
| 112 # Set the toolchain directories | 112 # Set the toolchain directories |
| 113 print 'toolpath=' + options.toolpath |
| 114 print 'toolname=' + self.toolname |
| 113 self.toolchain = os.path.join(options.toolpath, self.toolname) | 115 self.toolchain = os.path.join(options.toolpath, self.toolname) |
| 114 self.toolbin = os.path.join(self.toolchain, tool_subdir, 'bin') | 116 self.toolbin = os.path.join(self.toolchain, tool_subdir, 'bin') |
| 115 | 117 |
| 116 if self.pnacl: | 118 if self.pnacl: |
| 117 self.toollib = os.path.join(self.toolchain, tool_subdir,'lib') | 119 self.toollib = os.path.join(self.toolchain, tool_subdir,'lib') |
| 118 self.toolinc = os.path.join(self.toolchain, tool_subdir, 'sysroot', | 120 self.toolinc = os.path.join(self.toolchain, tool_subdir, 'sysroot', |
| 119 'include') | 121 'include') |
| 120 else: | 122 else: |
| 121 self.toollib = os.path.join(self.toolchain, | 123 self.toollib = os.path.join(self.toolchain, |
| 122 tool_subdir, | 124 tool_subdir, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 'WINDOWS' in define or | 201 'WINDOWS' in define or |
| 200 'WINVER' in define)] | 202 'WINVER' in define)] |
| 201 options += ['-D' + define for define in define_list] | 203 options += ['-D' + define for define in define_list] |
| 202 self.compile_options = options + ['-I' + name for name in self.inc_paths] | 204 self.compile_options = options + ['-I' + name for name in self.inc_paths] |
| 203 | 205 |
| 204 def BuildLinkOptions(self, options): | 206 def BuildLinkOptions(self, options): |
| 205 """Generates link options, called once by __init__.""" | 207 """Generates link options, called once by __init__.""" |
| 206 options = ArgToList(options) | 208 options = ArgToList(options) |
| 207 if self.toolname in ['glibc', 'newlib'] and self.mainarch == 'x86': | 209 if self.toolname in ['glibc', 'newlib'] and self.mainarch == 'x86': |
| 208 options += ['-B' + self.toollib] | 210 options += ['-B' + self.toollib] |
| 211 if self.outtype == 'nso': |
| 212 options += ['-Wl,-rpath-link,' + name for name in self.lib_paths] |
| 213 options += ['-shared'] |
| 214 options += ['-Wl,-soname,' + os.path.basename(self.name)] |
| 209 self.link_options = options + ['-L' + name for name in self.lib_paths] | 215 self.link_options = options + ['-L' + name for name in self.lib_paths] |
| 210 | 216 |
| 211 def BuildArchiveOptions(self): | 217 def BuildArchiveOptions(self): |
| 212 """Generates link options, called once by __init__.""" | 218 """Generates link options, called once by __init__.""" |
| 213 self.archive_options = [] | 219 self.archive_options = [] |
| 214 | 220 |
| 215 def Run(self, cmd_line, out): | 221 def Run(self, cmd_line, out): |
| 216 """Helper which runs a command line.""" | 222 """Helper which runs a command line.""" |
| 217 | 223 |
| 218 # For POSIX style path on windows for POSIX based toolchain | 224 # For POSIX style path on windows for POSIX based toolchain |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 err = self.Run(cmd_line, out) | 351 err = self.Run(cmd_line, out) |
| 346 if err: | 352 if err: |
| 347 ErrOut('\nFAILED with %d: %s\n\n' % (err, ' '.join(cmd_line))) | 353 ErrOut('\nFAILED with %d: %s\n\n' % (err, ' '.join(cmd_line))) |
| 348 return out | 354 return out |
| 349 | 355 |
| 350 def Generate(self, srcs): | 356 def Generate(self, srcs): |
| 351 """Generate final output file. | 357 """Generate final output file. |
| 352 | 358 |
| 353 Link or Archive the final output file, from the compiled sources. | 359 Link or Archive the final output file, from the compiled sources. |
| 354 """ | 360 """ |
| 355 if self.outtype == 'nexe': | 361 if self.outtype in ['nexe', 'nso']: |
| 356 out = self.Link(srcs) | 362 out = self.Link(srcs) |
| 357 if self.strip_debug: | 363 if self.strip_debug: |
| 358 self.Strip(out) | 364 self.Strip(out) |
| 359 elif self.outtype == 'nlib': | 365 elif self.outtype == 'nlib': |
| 360 self.Archive(srcs) | 366 self.Archive(srcs) |
| 361 | 367 |
| 362 | 368 |
| 363 def Main(argv): | 369 def Main(argv): |
| 364 parser = OptionParser() | 370 parser = OptionParser() |
| 365 parser.add_option('--empty', dest='empty', default=False, | 371 parser.add_option('--empty', dest='empty', default=False, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 help='Enable verbosity', action='store_true') | 406 help='Enable verbosity', action='store_true') |
| 401 parser.add_option('-t', '--toolpath', dest='toolpath', | 407 parser.add_option('-t', '--toolpath', dest='toolpath', |
| 402 help='Set the path for of the toolchains.') | 408 help='Set the path for of the toolchains.') |
| 403 (options, files) = parser.parse_args(argv[1:]) | 409 (options, files) = parser.parse_args(argv[1:]) |
| 404 | 410 |
| 405 if not argv: | 411 if not argv: |
| 406 parser.print_help() | 412 parser.print_help() |
| 407 return 1 | 413 return 1 |
| 408 | 414 |
| 409 options.verbose = True | 415 options.verbose = True |
| 416 print ' '.join(argv) |
| 410 if options.source_list: | 417 if options.source_list: |
| 411 source_list_handle = open(options.source_list, 'r') | 418 source_list_handle = open(options.source_list, 'r') |
| 412 source_list = source_list_handle.read().splitlines() | 419 source_list = source_list_handle.read().splitlines() |
| 413 source_list_handle.close() | 420 source_list_handle.close() |
| 414 files = files + source_list | 421 files = files + source_list |
| 415 | 422 |
| 416 build = Builder(options) | 423 build = Builder(options) |
| 417 objs = [] | 424 objs = [] |
| 418 for filename in files: | 425 for filename in files: |
| 419 out = build.Compile(filename) | 426 out = build.Compile(filename) |
| 420 if out: | 427 if out: |
| 421 objs.append(out) | 428 objs.append(out) |
| 422 # Do not link if building an object | 429 # Do not link if building an object |
| 423 if not options.compile_only: | 430 if not options.compile_only: |
| 424 build.Generate(objs) | 431 build.Generate(objs) |
| 425 return 0 | 432 return 0 |
| 426 | 433 |
| 427 if __name__ == '__main__': | 434 if __name__ == '__main__': |
| 428 sys.exit(Main(sys.argv)) | 435 sys.exit(Main(sys.argv)) |
| OLD | NEW |