| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 tool_prefix = tooldir | 92 tool_prefix = tooldir |
| 93 # The lib directory may have an alternate name, i.e. | 93 # The lib directory may have an alternate name, i.e. |
| 94 # 'lib32' in the x86_64-nacl tooldir. | 94 # 'lib32' in the x86_64-nacl tooldir. |
| 95 libdir = os.path.join(tooldir, subarch_spec.get('other_libdir', 'lib')) | 95 libdir = os.path.join(tooldir, subarch_spec.get('other_libdir', 'lib')) |
| 96 break | 96 break |
| 97 | 97 |
| 98 if tool_prefix is None: | 98 if tool_prefix is None: |
| 99 raise Exception("Cannot find a toolchain for %s in %s" % | 99 raise Exception("Cannot find a toolchain for %s in %s" % |
| 100 (env['TARGET_FULLARCH'], sdk_path)) | 100 (env['TARGET_FULLARCH'], sdk_path)) |
| 101 | 101 |
| 102 cc = 'clang' if env.Bit('nacl_clang') else 'gcc' |
| 103 cxx = 'clang++' if env.Bit('nacl_clang') else 'g++' |
| 104 # Eventually nacl-clang will default to -no-integrated-as but for now we have |
| 105 # to use the integrated as for compilation because of |
| 106 # https://code.google.com/p/nativeclient/issues/detail?id=3966 |
| 107 # However clang's as' support of some of the nacl syntax is incomplete, so for |
| 108 # now use binutils as for our asm files. |
| 109 as_flags = '-no-integrated-as' if env.Bit('nacl_clang') else [] |
| 110 |
| 102 env.Replace(# Replace header and lib paths. | 111 env.Replace(# Replace header and lib paths. |
| 103 # where to put nacl extra sdk headers | 112 # where to put nacl extra sdk headers |
| 104 # TODO(robertm): switch to using the mechanism that | 113 # TODO(robertm): switch to using the mechanism that |
| 105 # passes arguments to scons | 114 # passes arguments to scons |
| 106 NACL_SDK_INCLUDE='%s/%s/include' % (sdk_path, tool_prefix), | 115 NACL_SDK_INCLUDE='%s/%s/include' % (sdk_path, tool_prefix), |
| 107 # where to find/put nacl generic extra sdk libraries | 116 # where to find/put nacl generic extra sdk libraries |
| 108 NACL_SDK_LIB='%s/%s' % (sdk_path, libdir), | 117 NACL_SDK_LIB='%s/%s' % (sdk_path, libdir), |
| 109 # Replace the normal unix tools with the NaCl ones. | 118 # Replace the normal unix tools with the NaCl ones. |
| 110 CC=os.path.join(bin_path, '%s-gcc' % tool_prefix), | 119 CC=os.path.join(bin_path, '%s-%s' % (tool_prefix, cc)), |
| 111 CXX=os.path.join(bin_path, '%s-g++' % tool_prefix), | 120 CXX=os.path.join(bin_path, '%s-%s' % (tool_prefix, cxx)), |
| 112 AR=os.path.join(bin_path, '%s-ar' % tool_prefix), | 121 AR=os.path.join(bin_path, '%s-ar' % tool_prefix), |
| 113 AS=os.path.join(bin_path, '%s-as' % tool_prefix), | 122 AS=os.path.join(bin_path, '%s-as' % tool_prefix), |
| 114 ASPP=os.path.join(bin_path, '%s-gcc' % tool_prefix), | 123 ASPP=os.path.join(bin_path, '%s-%s' % (tool_prefix, cc)), |
| 115 GDB=os.path.join(bin_path, '%s-gdb' % tool_prefix), | 124 GDB=os.path.join(bin_path, '%s-gdb' % tool_prefix), |
| 116 # NOTE: use g++ for linking so we can handle C AND C++. | 125 # NOTE: use g++ for linking so we can handle C AND C++. |
| 117 LINK=os.path.join(bin_path, '%s-g++' % tool_prefix), | 126 LINK=os.path.join(bin_path, '%s-%s' % (tool_prefix, cxx)), |
| 118 # Grrr... and sometimes we really need ld. | 127 # Grrr... and sometimes we really need ld. |
| 119 LD=os.path.join(bin_path, '%s-ld' % tool_prefix) + ld_mode_flag, | 128 LD=os.path.join(bin_path, '%s-ld' % tool_prefix) + ld_mode_flag, |
| 120 RANLIB=os.path.join(bin_path, '%s-ranlib' % tool_prefix), | 129 RANLIB=os.path.join(bin_path, '%s-ranlib' % tool_prefix), |
| 121 NM=os.path.join(bin_path, '%s-nm' % tool_prefix), | 130 NM=os.path.join(bin_path, '%s-nm' % tool_prefix), |
| 122 OBJDUMP=os.path.join(bin_path, '%s-objdump' % tool_prefix), | 131 OBJDUMP=os.path.join(bin_path, '%s-objdump' % tool_prefix), |
| 123 STRIP=os.path.join(bin_path, '%s-strip' % tool_prefix), | 132 STRIP=os.path.join(bin_path, '%s-strip' % tool_prefix), |
| 124 ADDR2LINE=os.path.join(bin_path, '%s-addr2line' % tool_prefix), | 133 ADDR2LINE=os.path.join(bin_path, '%s-addr2line' % tool_prefix), |
| 125 BASE_LINKFLAGS=[cc_mode_flag], | 134 BASE_LINKFLAGS=[cc_mode_flag], |
| 126 BASE_CFLAGS=[cc_mode_flag], | 135 BASE_CFLAGS=[cc_mode_flag], |
| 127 BASE_CXXFLAGS=[cc_mode_flag], | 136 BASE_CXXFLAGS=[cc_mode_flag], |
| 128 BASE_ASFLAGS=[as_mode_flag], | 137 BASE_ASFLAGS=[as_mode_flag], |
| 129 BASE_ASPPFLAGS=[cc_mode_flag], | 138 BASE_ASPPFLAGS=[cc_mode_flag], |
| 130 CFLAGS=['-std=gnu99'], | 139 CFLAGS=['-std=gnu99'], |
| 131 CCFLAGS=['-O3', | 140 CCFLAGS=['-O3', |
| 132 '-Werror', | 141 '-Werror', |
| 133 '-Wall', | 142 '-Wall', |
| 134 '-Wno-variadic-macros', | 143 '-Wno-variadic-macros', |
| 135 '-Wswitch-enum', | 144 '-Wswitch-enum', |
| 136 '-g', | 145 '-g', |
| 137 '-fno-stack-protector', | 146 '-fno-stack-protector', |
| 138 '-fdiagnostics-show-option', | 147 '-fdiagnostics-show-option', |
| 139 '-pedantic', | 148 '-pedantic', |
| 140 '-D__linux__', | 149 '-D__linux__', |
| 141 ], | 150 ], |
| 142 ASFLAGS=[], | 151 ASFLAGS=as_flags, |
| 143 ) | 152 ) |
| 144 | 153 |
| 145 # NaClSdk environment seems to be inherited from the host environment. | 154 # NaClSdk environment seems to be inherited from the host environment. |
| 146 # On Linux host, this probably makes sense. On Windows and Mac, this | 155 # On Linux host, this probably makes sense. On Windows and Mac, this |
| 147 # introduces nothing except problems. | 156 # introduces nothing except problems. |
| 148 # For now, simply override the environment settings as in | 157 # For now, simply override the environment settings as in |
| 149 # <scons>/engine/SCons/Platform/posix.py | 158 # <scons>/engine/SCons/Platform/posix.py |
| 150 env.Replace(LIBPREFIX='lib', | 159 env.Replace(LIBPREFIX='lib', |
| 151 LIBSUFFIX='.a', | 160 LIBSUFFIX='.a', |
| 152 SHLIBPREFIX='$LIBPREFIX', | 161 SHLIBPREFIX='$LIBPREFIX', |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 env['TEMPFILE'] = NaClTempFileMunge | 667 env['TEMPFILE'] = NaClTempFileMunge |
| 659 for com in ['LINKCOM', 'SHLINKCOM', 'ARCOM']: | 668 for com in ['LINKCOM', 'SHLINKCOM', 'ARCOM']: |
| 660 env[com] = "${TEMPFILE('%s')}" % env[com] | 669 env[com] = "${TEMPFILE('%s')}" % env[com] |
| 661 | 670 |
| 662 # Get root of the SDK. | 671 # Get root of the SDK. |
| 663 root = env.GetToolchainDir() | 672 root = env.GetToolchainDir() |
| 664 | 673 |
| 665 # if bitcode=1 use pnacl toolchain | 674 # if bitcode=1 use pnacl toolchain |
| 666 if env.Bit('bitcode'): | 675 if env.Bit('bitcode'): |
| 667 _SetEnvForPnacl(env, root) | 676 _SetEnvForPnacl(env, root) |
| 677 elif env.Bit('built_elsewhere'): |
| 678 _StubOutEnvToolsForBuiltElsewhere(env) |
| 679 else: |
| 680 _SetEnvForNativeSdk(env, root) |
| 668 | 681 |
| 682 if (env.Bit('bitcode') or env.Bit('nacl_clang')) and env.Bit('target_x86'): |
| 669 # Get GDB from the nacl-gcc toolchain even when using PNaCl. | 683 # Get GDB from the nacl-gcc toolchain even when using PNaCl. |
| 670 # TODO(mseaborn): We really want the nacl-gdb binary to be in a | 684 # TODO(mseaborn): We really want the nacl-gdb binary to be in a |
| 671 # separate tarball from the nacl-gcc toolchain, then this step | 685 # separate tarball from the nacl-gcc toolchain, then this step |
| 672 # will not be necessary. | 686 # will not be necessary. |
| 673 # See http://code.google.com/p/nativeclient/issues/detail?id=2773 | 687 # See http://code.google.com/p/nativeclient/issues/detail?id=2773 |
| 674 if env.Bit('target_x86'): | 688 temp_env = env.Clone() |
| 675 temp_env = env.Clone() | 689 temp_env.ClearBits('bitcode', 'nacl_clang') |
| 676 temp_env.ClearBits('bitcode') | 690 temp_root = temp_env.GetToolchainDir() |
| 677 temp_root = temp_env.GetToolchainDir() | 691 _SetEnvForNativeSdk(temp_env, temp_root) |
| 678 _SetEnvForNativeSdk(temp_env, temp_root) | 692 env.Replace(GDB=temp_env['GDB']) |
| 679 env.Replace(GDB=temp_env['GDB']) | |
| 680 elif env.Bit('built_elsewhere'): | |
| 681 _StubOutEnvToolsForBuiltElsewhere(env) | |
| 682 else: | |
| 683 _SetEnvForNativeSdk(env, root) | |
| 684 | 693 |
| 685 env.Prepend(LIBPATH='${NACL_SDK_LIB}') | 694 env.Prepend(LIBPATH='${NACL_SDK_LIB}') |
| 686 | 695 |
| 687 # Install our scanner for (potential) linker scripts. | 696 # Install our scanner for (potential) linker scripts. |
| 688 # It applies to "source" files ending in .a or .so. | 697 # It applies to "source" files ending in .a or .so. |
| 689 # Dependency files it produces are to be found in ${LIBPATH}. | 698 # Dependency files it produces are to be found in ${LIBPATH}. |
| 690 # It is applied recursively to those dependencies in case | 699 # It is applied recursively to those dependencies in case |
| 691 # some of them are linker scripts too. | 700 # some of them are linker scripts too. |
| 692 ldscript_scanner = SCons.Scanner.Base( | 701 ldscript_scanner = SCons.Scanner.Base( |
| 693 function=ScanLinkerScript, | 702 function=ScanLinkerScript, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 709 # translation. | 718 # translation. |
| 710 if not os.path.exists(version_file) or env.Bit('use_sandboxed_translator'): | 719 if not os.path.exists(version_file) or env.Bit('use_sandboxed_translator'): |
| 711 version_file = os.path.join(os.path.dirname(root), 'pnacl_translator', | 720 version_file = os.path.join(os.path.dirname(root), 'pnacl_translator', |
| 712 'FEATURE_VERSION') | 721 'FEATURE_VERSION') |
| 713 if os.path.exists(version_file): | 722 if os.path.exists(version_file): |
| 714 with open(version_file, 'r') as fh: | 723 with open(version_file, 'r') as fh: |
| 715 version = int(fh.read()) | 724 version = int(fh.read()) |
| 716 else: | 725 else: |
| 717 version = 0 | 726 version = 0 |
| 718 env.Replace(TOOLCHAIN_FEATURE_VERSION=version) | 727 env.Replace(TOOLCHAIN_FEATURE_VERSION=version) |
| OLD | NEW |