| 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 """NEXE building script | 6 """NEXE building script |
| 7 | 7 |
| 8 This module will take a set of source files, include paths, library paths, and | 8 This module will take a set of source files, include paths, library paths, and |
| 9 additional arguments, and use them to build. | 9 additional arguments, and use them to build. |
| 10 """ | 10 """ |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 self.name = options.name | 261 self.name = options.name |
| 262 self.BuildCompileOptions(options.compile_flags, self.define_list) | 262 self.BuildCompileOptions(options.compile_flags, self.define_list) |
| 263 self.BuildLinkOptions(options.link_flags) | 263 self.BuildLinkOptions(options.link_flags) |
| 264 self.BuildArchiveOptions() | 264 self.BuildArchiveOptions() |
| 265 self.verbose = options.verbose | 265 self.verbose = options.verbose |
| 266 self.suffix = options.suffix | 266 self.suffix = options.suffix |
| 267 self.strip = options.strip | 267 self.strip = options.strip |
| 268 self.empty = options.empty | 268 self.empty = options.empty |
| 269 self.strip_all = options.strip_all | 269 self.strip_all = options.strip_all |
| 270 self.strip_debug = options.strip_debug | 270 self.strip_debug = options.strip_debug |
| 271 self.tls_edit = options.tls_edit |
| 271 self.finalize_pexe = options.finalize_pexe and arch == 'pnacl' | 272 self.finalize_pexe = options.finalize_pexe and arch == 'pnacl' |
| 272 goma_config = GetGomaConfig(options.gomadir, self.osname, arch, toolname, | 273 goma_config = GetGomaConfig(options.gomadir, self.osname, arch, toolname, |
| 273 self.is_pnacl_toolchain) | 274 self.is_pnacl_toolchain) |
| 274 self.gomacc = goma_config.get('gomacc', '') | 275 self.gomacc = goma_config.get('gomacc', '') |
| 275 self.goma_burst = goma_config.get('burst', False) | 276 self.goma_burst = goma_config.get('burst', False) |
| 276 | 277 |
| 277 # Use unoptimized native objects for debug IRT builds for faster compiles. | 278 # Use unoptimized native objects for debug IRT builds for faster compiles. |
| 278 if (self.is_pnacl_toolchain | 279 if (self.is_pnacl_toolchain |
| 279 and (self.outtype == 'nlib' | 280 and (self.outtype == 'nlib' |
| 280 or self.outtype == 'nexe') | 281 or self.outtype == 'nexe') |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 raise Error('Failed to compile %s to %s with deps %s and cmdline:\t%s' | 568 raise Error('Failed to compile %s to %s with deps %s and cmdline:\t%s' |
| 568 '\nNeedsRebuild returned error: %s' % ( | 569 '\nNeedsRebuild returned error: %s' % ( |
| 569 src, out, outd, ' '.join(cmd_line), e)) | 570 src, out, outd, ' '.join(cmd_line), e)) |
| 570 return out | 571 return out |
| 571 | 572 |
| 572 def Link(self, srcs): | 573 def Link(self, srcs): |
| 573 """Link these objects with predetermined options and output name.""" | 574 """Link these objects with predetermined options and output name.""" |
| 574 out = self.LinkOutputName() | 575 out = self.LinkOutputName() |
| 575 self.Log('\nLink %s' % out) | 576 self.Log('\nLink %s' % out) |
| 576 bin_name = self.GetCXXCompiler() | 577 bin_name = self.GetCXXCompiler() |
| 577 MakeDir(os.path.dirname(out)) | |
| 578 self.CleanOutput(out) | |
| 579 | 578 |
| 580 cmd_line = [bin_name, '-o', out, '-Wl,--as-needed'] | 579 link_out = out |
| 580 if self.tls_edit is not None: |
| 581 link_out = out + '.raw' |
| 582 |
| 583 MakeDir(os.path.dirname(link_out)) |
| 584 self.CleanOutput(link_out) |
| 585 |
| 586 cmd_line = [bin_name, '-o', link_out, '-Wl,--as-needed'] |
| 581 if not self.empty: | 587 if not self.empty: |
| 582 cmd_line += srcs | 588 cmd_line += srcs |
| 583 cmd_line += self.link_options | 589 cmd_line += self.link_options |
| 584 | 590 |
| 585 err = self.Run(cmd_line, out) | 591 err = self.Run(cmd_line, link_out) |
| 586 if err: | 592 if err: |
| 587 raise Error('FAILED with %d: %s' % (err, ' '.join(cmd_line))) | 593 raise Error('FAILED with %d: %s' % (err, ' '.join(cmd_line))) |
| 594 |
| 595 if self.tls_edit is not None: |
| 596 tls_edit_cmd = [self.tls_edit, link_out, out] |
| 597 tls_edit_err = self.Run(tls_edit_cmd, out) |
| 598 if tls_edit_err: |
| 599 raise Error('FAILED with %d: %s' % (err, ' '.join(tls_edit_cmd))) |
| 600 |
| 588 return out | 601 return out |
| 589 | 602 |
| 590 # For now, only support translating a pexe, and not .o file(s) | 603 # For now, only support translating a pexe, and not .o file(s) |
| 591 def Translate(self, src): | 604 def Translate(self, src): |
| 592 """Translate a pexe to a nexe.""" | 605 """Translate a pexe to a nexe.""" |
| 593 out = self.TranslateOutputName() | 606 out = self.TranslateOutputName() |
| 594 self.Log('\nTranslate %s' % out) | 607 self.Log('\nTranslate %s' % out) |
| 595 bin_name = self.GetBinName('translate') | 608 bin_name = self.GetBinName('translate') |
| 596 cmd_line = [bin_name, '-arch', self.arch, src, '-o', out] | 609 cmd_line = [bin_name, '-arch', self.arch, src, '-o', out] |
| 597 cmd_line += self.link_options | 610 cmd_line += self.link_options |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 help='Strip the NEXE for debugging', action='store_true') | 722 help='Strip the NEXE for debugging', action='store_true') |
| 710 parser.add_option('--strip-all', dest='strip_all', default=False, | 723 parser.add_option('--strip-all', dest='strip_all', default=False, |
| 711 help='Strip the NEXE for production', action='store_true') | 724 help='Strip the NEXE for production', action='store_true') |
| 712 parser.add_option('--strip', dest='strip', default='', | 725 parser.add_option('--strip', dest='strip', default='', |
| 713 help='Strip the filename') | 726 help='Strip the filename') |
| 714 parser.add_option('--nonstable-pnacl', dest='finalize_pexe', default=True, | 727 parser.add_option('--nonstable-pnacl', dest='finalize_pexe', default=True, |
| 715 help='Do not finalize pnacl bitcode for ABI stability', | 728 help='Do not finalize pnacl bitcode for ABI stability', |
| 716 action='store_false') | 729 action='store_false') |
| 717 parser.add_option('--source-list', dest='source_list', | 730 parser.add_option('--source-list', dest='source_list', |
| 718 help='Filename to load a source list from') | 731 help='Filename to load a source list from') |
| 732 parser.add_option('--tls-edit', dest='tls_edit', default=None, |
| 733 help='tls_edit location if TLS should be modified for IRT') |
| 719 parser.add_option('-a', '--arch', dest='arch', | 734 parser.add_option('-a', '--arch', dest='arch', |
| 720 help='Set target architecture') | 735 help='Set target architecture') |
| 721 parser.add_option('-c', '--compile', dest='compile_only', default=False, | 736 parser.add_option('-c', '--compile', dest='compile_only', default=False, |
| 722 help='Compile only.', action='store_true') | 737 help='Compile only.', action='store_true') |
| 723 parser.add_option('-i', '--include-dirs', dest='incdirs', | 738 parser.add_option('-i', '--include-dirs', dest='incdirs', |
| 724 help='Set include directories.') | 739 help='Set include directories.') |
| 725 parser.add_option('-l', '--lib-dirs', dest='libdirs', | 740 parser.add_option('-l', '--lib-dirs', dest='libdirs', |
| 726 help='Set library directories.') | 741 help='Set library directories.') |
| 727 parser.add_option('-n', '--name', dest='name', | 742 parser.add_option('-n', '--name', dest='name', |
| 728 help='Base path and name of the nexe.') | 743 help='Base path and name of the nexe.') |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 shutil.copy(objs[0], options.name) | 835 shutil.copy(objs[0], options.name) |
| 821 else: | 836 else: |
| 822 build.Generate(objs) | 837 build.Generate(objs) |
| 823 return 0 | 838 return 0 |
| 824 except Error as e: | 839 except Error as e: |
| 825 sys.stderr.write('%s\n' % e) | 840 sys.stderr.write('%s\n' % e) |
| 826 return 1 | 841 return 1 |
| 827 | 842 |
| 828 if __name__ == '__main__': | 843 if __name__ == '__main__': |
| 829 sys.exit(Main(sys.argv)) | 844 sys.exit(Main(sys.argv)) |
| OLD | NEW |