OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium 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 """Bootstraps gn. | 6 """Bootstraps gn. |
7 | 7 |
8 It is done by first building it manually in a temporary directory, then building | 8 It is done by first building it manually in a temporary directory, then building |
9 it with its own BUILD.gn to the final destination. | 9 it with its own BUILD.gn to the final destination. |
10 """ | 10 """ |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 if options.verbose: | 100 if options.verbose: |
101 cmd.append('-v') | 101 cmd.append('-v') |
102 cmd.append('gn') | 102 cmd.append('gn') |
103 check_call(cmd) | 103 check_call(cmd) |
104 | 104 |
105 def write_ninja(path, options): | 105 def write_ninja(path, options): |
106 cc = os.environ.get('CC', '') | 106 cc = os.environ.get('CC', '') |
107 cxx = os.environ.get('CXX', '') | 107 cxx = os.environ.get('CXX', '') |
108 cflags = os.environ.get('CFLAGS', '').split() | 108 cflags = os.environ.get('CFLAGS', '').split() |
109 cflags_cc = os.environ.get('CXXFLAGS', '').split() | 109 cflags_cc = os.environ.get('CXXFLAGS', '').split() |
| 110 ld = os.environ.get('LD', cxx) |
110 ldflags = os.environ.get('LDFLAGS', '').split() | 111 ldflags = os.environ.get('LDFLAGS', '').split() |
111 include_dirs = [SRC_ROOT] | 112 include_dirs = [SRC_ROOT] |
112 libs = [] | 113 libs = [] |
113 | 114 |
114 if is_posix: | 115 if is_posix: |
115 if options.debug: | 116 if options.debug: |
116 cflags.extend(['-O0', '-g']) | 117 cflags.extend(['-O0', '-g']) |
117 else: | 118 else: |
118 cflags.extend(['-O2', '-g0']) | 119 cflags.extend(['-O2', '-g0']) |
119 | 120 |
120 cflags.extend(['-D_FILE_OFFSET_BITS=64 -pthread', '-pipe']) | 121 cflags.extend(['-D_FILE_OFFSET_BITS=64', '-pthread', '-pipe']) |
121 cflags_cc.extend(['-std=gnu++11', '-Wno-c++11-narrowing']) | 122 cflags_cc.extend(['-std=gnu++11', '-Wno-c++11-narrowing']) |
122 | 123 |
123 static_libraries = { | 124 static_libraries = { |
124 'base': {'sources': [], 'tool': 'cxx'}, | 125 'base': {'sources': [], 'tool': 'cxx'}, |
125 'dynamic_annotations': {'sources': [], 'tool': 'cc'}, | 126 'dynamic_annotations': {'sources': [], 'tool': 'cc'}, |
126 'gn': {'sources': [], 'tool': 'cxx'}, | 127 'gn': {'sources': [], 'tool': 'cxx'}, |
127 } | 128 } |
128 | 129 |
129 for name in os.listdir(GN_ROOT): | 130 for name in os.listdir(GN_ROOT): |
130 if not name.endswith('.cc'): | 131 if not name.endswith('.cc'): |
131 continue | 132 continue |
132 if name.endswith('_unittest.cc'): | 133 if name.endswith('_unittest.cc'): |
133 continue | 134 continue |
134 if name in ['generate_test_gn_data.cc']: | 135 if name in ['generate_test_gn_data.cc', 'run_all_unittests.cc']: |
135 continue | 136 continue |
136 full_path = os.path.join(GN_ROOT, name) | 137 full_path = os.path.join(GN_ROOT, name) |
137 static_libraries['gn']['sources'].append( | 138 static_libraries['gn']['sources'].append( |
138 os.path.relpath(full_path, SRC_ROOT)) | 139 os.path.relpath(full_path, SRC_ROOT)) |
139 | 140 |
140 static_libraries['dynamic_annotations']['sources'].extend([ | 141 static_libraries['dynamic_annotations']['sources'].extend([ |
141 'base/third_party/dynamic_annotations/dynamic_annotations.c', | 142 'base/third_party/dynamic_annotations/dynamic_annotations.c', |
142 ]) | 143 ]) |
143 static_libraries['base']['sources'].extend([ | 144 static_libraries['base']['sources'].extend([ |
144 'base/at_exit.cc', | 145 'base/at_exit.cc', |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 libs.extend([ | 371 libs.extend([ |
371 '-framework', 'AppKit', | 372 '-framework', 'AppKit', |
372 '-framework', 'CoreFoundation', | 373 '-framework', 'CoreFoundation', |
373 '-framework', 'Foundation', | 374 '-framework', 'Foundation', |
374 '-framework', 'Security', | 375 '-framework', 'Security', |
375 ]); | 376 ]); |
376 | 377 |
377 ninja_lines.extend([ | 378 ninja_lines.extend([ |
378 'build gn: link %s' % ( | 379 'build gn: link %s' % ( |
379 ' '.join(['%s.a' % library for library in static_libraries])), | 380 ' '.join(['%s.a' % library for library in static_libraries])), |
380 ' ld = $ldxx', | |
381 ' ldflags = %s' % ' '.join(ldflags), | 381 ' ldflags = %s' % ' '.join(ldflags), |
382 ' libs = %s' % ' '.join(libs), | 382 ' libs = %s' % ' '.join(libs), |
383 '', # Make sure the file ends with a newline. | |
384 ]) | 383 ]) |
| 384 if ld: |
| 385 ninja_lines.append(' ld = %s' % ld) |
| 386 else: |
| 387 ninja_lines.append(' ld = $ldxx') |
| 388 |
| 389 ninja_lines.append('') # Make sure the file ends with a newline. |
385 | 390 |
386 with open(path, 'w') as f: | 391 with open(path, 'w') as f: |
387 f.write(ninja_template + '\n'.join(ninja_lines)) | 392 f.write(ninja_template + '\n'.join(ninja_lines)) |
388 | 393 |
389 | 394 |
390 def build_gn_with_gn(temp_gn, build_dir, options): | 395 def build_gn_with_gn(temp_gn, build_dir, options): |
391 cmd = [temp_gn, 'gen', build_dir] | 396 cmd = [temp_gn, 'gen', build_dir] |
392 if not options.debug: | 397 if not options.debug: |
393 cmd.append('--args=is_debug=false') | 398 cmd.append('--args=is_debug=false') |
394 check_call(cmd) | 399 check_call(cmd) |
395 | 400 |
396 cmd = ['ninja', '-C', build_dir] | 401 cmd = ['ninja', '-C', build_dir] |
397 if options.verbose: | 402 if options.verbose: |
398 cmd.append('-v') | 403 cmd.append('-v') |
399 cmd.append('gn') | 404 cmd.append('gn') |
400 check_call(cmd) | 405 check_call(cmd) |
401 | 406 |
402 if not debug: | 407 if not debug: |
403 check_call(['strip', os.path.join(build_dir, 'gn')]) | 408 check_call(['strip', os.path.join(build_dir, 'gn')]) |
404 | 409 |
405 | 410 |
406 if __name__ == '__main__': | 411 if __name__ == '__main__': |
407 sys.exit(main(sys.argv[1:])) | 412 sys.exit(main(sys.argv[1:])) |
OLD | NEW |