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 """NaCl SDK tool SCons.""" | 6 """NaCl SDK tool SCons.""" |
7 | 7 |
8 import __builtin__ | 8 import __builtin__ |
9 import re | 9 import re |
10 import os | 10 import os |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 133 |
134 bin_path = os.path.join(sdk_path, 'bin') | 134 bin_path = os.path.join(sdk_path, 'bin') |
135 # NOTE: attempts to eliminate this PATH setting and use | 135 # NOTE: attempts to eliminate this PATH setting and use |
136 # absolute path have been futile | 136 # absolute path have been futile |
137 env.PrependENVPath('PATH', bin_path) | 137 env.PrependENVPath('PATH', bin_path) |
138 | 138 |
139 tool_prefix = None | 139 tool_prefix = None |
140 tool_map = NACL_TOOL_MAP[env['TARGET_ARCHITECTURE']] | 140 tool_map = NACL_TOOL_MAP[env['TARGET_ARCHITECTURE']] |
141 subarch_spec = tool_map[env['TARGET_SUBARCH']] | 141 subarch_spec = tool_map[env['TARGET_SUBARCH']] |
142 tooldir = subarch_spec['tooldir'] | 142 tooldir = subarch_spec['tooldir'] |
| 143 # We need to pass it extra options for the subarch we are building. |
| 144 as_mode_flag = subarch_spec['as_flag'] |
| 145 cc_mode_flag = subarch_spec['cc_flag'] |
| 146 ld_mode_flag = subarch_spec['ld_flag'] |
143 if os.path.exists(os.path.join(sdk_path, tooldir)): | 147 if os.path.exists(os.path.join(sdk_path, tooldir)): |
144 # The tooldir for the build target exists. | 148 # The tooldir for the build target exists. |
145 # The tools there do the right thing without special options. | 149 # The tools there do the right thing without special options. |
146 tool_prefix = tooldir | 150 tool_prefix = tooldir |
147 libdir = os.path.join(tooldir, 'lib') | 151 libdir = os.path.join(tooldir, 'lib') |
148 as_mode_flag = '' | |
149 cc_mode_flag = '' | |
150 ld_mode_flag = '' | |
151 else: | 152 else: |
152 # We're building for a target for which there is no matching tooldir. | 153 # We're building for a target for which there is no matching tooldir. |
153 # For example, for x86-32 when only <sdk_path>/x86_64-nacl/ exists. | 154 # For example, for x86-32 when only <sdk_path>/x86_64-nacl/ exists. |
154 # Find a tooldir for a different subarch that does exist. | 155 # Find a tooldir for a different subarch that does exist. |
155 others_map = tool_map.copy() | 156 others_map = tool_map.copy() |
156 del others_map[env['TARGET_SUBARCH']] | 157 del others_map[env['TARGET_SUBARCH']] |
157 for subarch, tool_spec in others_map.iteritems(): | 158 for subarch, tool_spec in others_map.iteritems(): |
158 tooldir = tool_spec['tooldir'] | 159 tooldir = tool_spec['tooldir'] |
159 if os.path.exists(os.path.join(sdk_path, tooldir)): | 160 if os.path.exists(os.path.join(sdk_path, tooldir)): |
160 # OK, this is the other subarch to use as tooldir. | 161 # OK, this is the other subarch to use as tooldir. |
161 tool_prefix = tooldir | 162 tool_prefix = tooldir |
162 # We need to pass it extra options for the subarch we are building. | |
163 as_mode_flag = subarch_spec['as_flag'] | |
164 cc_mode_flag = subarch_spec['cc_flag'] | |
165 ld_mode_flag = subarch_spec['ld_flag'] | |
166 # The lib directory may have an alternate name, i.e. | 163 # The lib directory may have an alternate name, i.e. |
167 # 'lib32' in the x86_64-nacl tooldir. | 164 # 'lib32' in the x86_64-nacl tooldir. |
168 libdir = os.path.join(tooldir, subarch_spec.get('other_libdir', 'lib')) | 165 libdir = os.path.join(tooldir, subarch_spec.get('other_libdir', 'lib')) |
169 break | 166 break |
170 | 167 |
171 if tool_prefix is None: | 168 if tool_prefix is None: |
172 raise Exception("Cannot find a toolchain for %s in %s" % | 169 raise Exception("Cannot find a toolchain for %s in %s" % |
173 (env['TARGET_FULLARCH'], sdk_path)) | 170 (env['TARGET_FULLARCH'], sdk_path)) |
174 | 171 |
175 env.Replace(# Replace header and lib paths. | 172 env.Replace(# Replace header and lib paths. |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 | 318 |
322 if env.Bit('x86_64_zero_based_sandbox'): | 319 if env.Bit('x86_64_zero_based_sandbox'): |
323 pnacl_translate_flags += ' -sfi-zero-based-sandbox' | 320 pnacl_translate_flags += ' -sfi-zero-based-sandbox' |
324 | 321 |
325 if pnacl_extra_lib: | 322 if pnacl_extra_lib: |
326 env.Prepend(LIBPATH=pnacl_extra_lib) | 323 env.Prepend(LIBPATH=pnacl_extra_lib) |
327 | 324 |
328 env.Replace(# Replace header and lib paths. | 325 env.Replace(# Replace header and lib paths. |
329 NACL_SDK_INCLUDE=pnacl_include, | 326 NACL_SDK_INCLUDE=pnacl_include, |
330 NACL_SDK_LIB=pnacl_lib, | 327 NACL_SDK_LIB=pnacl_lib, |
| 328 # Remove arch-specific flags (if any) |
| 329 BASE_LINKFLAGS='', |
| 330 BASE_CFLAGS='', |
| 331 BASE_CXXFLAGS='', |
| 332 BASE_ASFLAGS='', |
| 333 BASE_ASPPFLAGS='', |
331 # Replace the normal unix tools with the PNaCl ones. | 334 # Replace the normal unix tools with the PNaCl ones. |
332 CC=pnacl_cc + pnacl_cc_flags, | 335 CC=pnacl_cc + pnacl_cc_flags, |
333 CXX=pnacl_cxx + pnacl_cxx_flags, | 336 CXX=pnacl_cxx + pnacl_cxx_flags, |
334 ASPP=pnacl_cc + pnacl_cc_flags, | 337 ASPP=pnacl_cc + pnacl_cc_flags, |
335 LIBPREFIX="lib", | 338 LIBPREFIX="lib", |
336 SHLIBPREFIX="lib", | 339 SHLIBPREFIX="lib", |
337 SHLIBSUFFIX=".so", | 340 SHLIBSUFFIX=".so", |
338 OBJSUFFIX=".bc", | 341 OBJSUFFIX=".bc", |
339 LINK=pnacl_cxx + ld_arch_flag + pnacl_ld_flags, | 342 LINK=pnacl_cxx + ld_arch_flag + pnacl_ld_flags, |
340 # Although we are currently forced to produce native output | 343 # Although we are currently forced to produce native output |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 # Dependency files it produces are to be found in ${LIBPATH}. | 791 # Dependency files it produces are to be found in ${LIBPATH}. |
789 # It is applied recursively to those dependencies in case | 792 # It is applied recursively to those dependencies in case |
790 # some of them are linker scripts too. | 793 # some of them are linker scripts too. |
791 ldscript_scanner = SCons.Scanner.Base( | 794 ldscript_scanner = SCons.Scanner.Base( |
792 function=ScanLinkerScript, | 795 function=ScanLinkerScript, |
793 skeys=['.a', '.so', '.pso'], | 796 skeys=['.a', '.so', '.pso'], |
794 path_function=SCons.Scanner.FindPathDirs('LIBPATH'), | 797 path_function=SCons.Scanner.FindPathDirs('LIBPATH'), |
795 recursive=True | 798 recursive=True |
796 ) | 799 ) |
797 env.Append(SCANNERS=ldscript_scanner) | 800 env.Append(SCANNERS=ldscript_scanner) |
OLD | NEW |