| OLD | NEW | 
|---|
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 | 
| 2 # Copyright 2009, Google Inc. | 2 # Copyright 2009, Google Inc. | 
| 3 # All rights reserved. | 3 # All rights reserved. | 
| 4 # | 4 # | 
| 5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without | 
| 6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are | 
| 7 # met: | 7 # met: | 
| 8 # | 8 # | 
| 9 #     * Redistributions of source code must retain the above copyright | 9 #     * Redistributions of source code must retain the above copyright | 
| 10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. | 
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 58         'x86': { | 58         'x86': { | 
| 59             '32': ['win_x86'], | 59             '32': ['win_x86'], | 
| 60             '64': ['win_x86'], | 60             '64': ['win_x86'], | 
| 61         }, | 61         }, | 
| 62     }, | 62     }, | 
| 63     'linux': { | 63     'linux': { | 
| 64         'x86': { | 64         'x86': { | 
| 65             '32': ['linux_x86'], | 65             '32': ['linux_x86'], | 
| 66             '64': ['linux_x86'], | 66             '64': ['linux_x86'], | 
| 67         }, | 67         }, | 
| 68         'arm': { |  | 
| 69             '32': ['linux_arm-untrusted', 'linux_arm-trusted'], |  | 
| 70         }, |  | 
| 71     }, | 68     }, | 
| 72     'mac': { | 69     'mac': { | 
| 73         'x86': { | 70         'x86': { | 
| 74             '32': ['mac_x86'], | 71             '32': ['mac_x86'], | 
| 75             '64': ['mac_x86'], | 72             '64': ['mac_x86'], | 
| 76         }, | 73         }, | 
| 77         'arm': { |  | 
| 78             # This entry is not actually correct, but it must be here |  | 
| 79             # for launching scons. |  | 
| 80             # TODO(pdox): Refactor this table so that pnacl is recognized |  | 
| 81             # as an x86 toolchain also, not just an ARM toolchain. |  | 
| 82             '32': ['linux_arm-untrusted'], |  | 
| 83         }, |  | 
| 84 |  | 
| 85     }, | 74     }, | 
| 86 } | 75 } | 
| 87 | 76 | 
| 88 |  | 
| 89 |  | 
| 90 def _PlatformSubdirs(env): | 77 def _PlatformSubdirs(env): | 
| 91   platform = NACL_CANONICAL_PLATFORM_MAP[env['PLATFORM']] | 78   if env.Bit('bitcode'): | 
| 92   arch = env['BUILD_ARCHITECTURE'] | 79     import platform | 
| 93   subarch = env['TARGET_SUBARCH'] | 80     name = 'pnacl_%s_%s' % (platform.system().lower(), platform.machine()) | 
| 94   name = NACL_PLATFORM_DIR_MAP[platform][arch][subarch] | 81   else: | 
|  | 82     platform = NACL_CANONICAL_PLATFORM_MAP[env['PLATFORM']] | 
|  | 83     arch = env['BUILD_ARCHITECTURE'] | 
|  | 84     subarch = env['TARGET_SUBARCH'] | 
|  | 85     name = NACL_PLATFORM_DIR_MAP[platform][arch][subarch] | 
| 95   return name | 86   return name | 
| 96 | 87 | 
| 97 | 88 | 
| 98 def _GetNaclSdkRoot(env, sdk_mode): | 89 def _GetNaclSdkRoot(env, sdk_mode): | 
| 99   """Return the path to the sdk. | 90   """Return the path to the sdk. | 
| 100 | 91 | 
| 101   Args: | 92   Args: | 
| 102     env: The SCons environment in question. | 93     env: The SCons environment in question. | 
| 103     sdk_mode: A string indicating which location to select the tools from. | 94     sdk_mode: A string indicating which location to select the tools from. | 
| 104   Returns: | 95   Returns: | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 116             stdout=subprocess.PIPE).communicate()[0].replace('\n', '') | 107             stdout=subprocess.PIPE).communicate()[0].replace('\n', '') | 
| 117       except WindowsError: | 108       except WindowsError: | 
| 118         raise NotImplementedError( | 109         raise NotImplementedError( | 
| 119             'Not able to decide where /usr/local/nacl-sdk is on this platform,' | 110             'Not able to decide where /usr/local/nacl-sdk is on this platform,' | 
| 120             'use naclsdk_mode=custom:...') | 111             'use naclsdk_mode=custom:...') | 
| 121       return path | 112       return path | 
| 122     else: | 113     else: | 
| 123       return '/usr/local/nacl-sdk' | 114       return '/usr/local/nacl-sdk' | 
| 124 | 115 | 
| 125   elif sdk_mode == 'download': | 116   elif sdk_mode == 'download': | 
| 126     platforms = _PlatformSubdirs(env) | 117     tcname = _PlatformSubdirs(env) | 
| 127     root = os.path.join(env['MAIN_DIR'], 'toolchain', platforms[-1]) | 118     return os.path.join(env['MAIN_DIR'], 'toolchain', tcname) | 
| 128     return root |  | 
| 129 |  | 
| 130   elif sdk_mode.startswith('custom:'): | 119   elif sdk_mode.startswith('custom:'): | 
| 131     return os.path.abspath(sdk_mode[len('custom:'):]) | 120     return os.path.abspath(sdk_mode[len('custom:'):]) | 
| 132 | 121 | 
| 133   elif sdk_mode == 'manual': | 122   elif sdk_mode == 'manual': | 
| 134     return None | 123     return None | 
| 135 | 124 | 
| 136   else: | 125   else: | 
| 137     raise Exception('Unknown sdk mode: %r' % sdk_mode) | 126     raise Exception('Unknown sdk mode: %r' % sdk_mode) | 
| 138 | 127 | 
| 139 | 128 | 
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 198                        '-g', | 187                        '-g', | 
| 199                        '-fno-builtin', | 188                        '-fno-builtin', | 
| 200                        '-fno-stack-protector', | 189                        '-fno-stack-protector', | 
| 201                        '-fdiagnostics-show-option', | 190                        '-fdiagnostics-show-option', | 
| 202                        '-pedantic', | 191                        '-pedantic', | 
| 203                        '-D__linux__', | 192                        '-D__linux__', | 
| 204                        ], | 193                        ], | 
| 205               ASFLAGS=[], | 194               ASFLAGS=[], | 
| 206               ) | 195               ) | 
| 207 | 196 | 
| 208 def _SetEnvForPnacl(env, arch): | 197 def _SetEnvForPnacl(env, root): | 
|  | 198   arch = env['TARGET_FULLARCH'] | 
| 209   assert arch in ['arm', 'x86-32', 'x86-64'] | 199   assert arch in ['arm', 'x86-32', 'x86-64'] | 
| 210   pnacl_sdk_root = '${MAIN_DIR}/toolchain/linux_arm-untrusted' | 200 | 
| 211   pnacl_sdk_lib = pnacl_sdk_root + '/libs-bitcode' | 201   env['PNACL_ROOT'] = root | 
|  | 202   pnacl_sdk_lib = '${PNACL_ROOT}/libs-bitcode' | 
| 212   #TODO(robertm): remove NACL_SDK_INCLUDE ASAP | 203   #TODO(robertm): remove NACL_SDK_INCLUDE ASAP | 
| 213   pnacl_sdk_include = (pnacl_sdk_root + | 204   pnacl_sdk_include = '${PNACL_ROOT}/arm-newlib/arm-none-linux-gnueabi/include' | 
| 214                        '/arm-newlib/arm-none-linux-gnueabi/include') | 205   pnacl_sdk_ar = '${PNACL_ROOT}/bin/pnacl-ar' | 
| 215   pnacl_sdk_ar = (pnacl_sdk_root + '/bin/pnacl-ar') | 206   pnacl_sdk_nm = '${PNACL_ROOT}/bin/pnacl-nm' | 
| 216   pnacl_sdk_nm = (pnacl_sdk_root + '/bin/pnacl-nm') | 207   pnacl_sdk_ranlib = '${PNACL_ROOT}/bin/pnacl-ranlib' | 
| 217   pnacl_sdk_ranlib = (pnacl_sdk_root + '/bin/pnacl-ranlib') |  | 
| 218 | 208 | 
| 219   pnacl_sdk_cc = (pnacl_sdk_root + '/bin/pnacl-gcc') | 209   pnacl_sdk_cc = '${PNACL_ROOT}/bin/pnacl-gcc' | 
| 220   pnacl_sdk_cxx = (pnacl_sdk_root + '/bin/pnacl-g++') | 210   pnacl_sdk_cxx = '${PNACL_ROOT}/bin/pnacl-g++' | 
| 221   pnacl_sdk_ld =  (pnacl_sdk_root + '/bin/pnacl-ld') | 211   pnacl_sdk_ld =  '${PNACL_ROOT}/bin/pnacl-ld' | 
| 222   pnacl_sdk_disass = (pnacl_sdk_root + '/arm-none-linux-gnueabi' + | 212   pnacl_sdk_disass = '${PNACL_ROOT}/bin/pnacl-dis' | 
| 223                   '/bin/llvm-dis') |  | 
| 224   # NOTE: XXX_flags start with space for easy concatenation | 213   # NOTE: XXX_flags start with space for easy concatenation | 
| 225   pnacl_sdk_cxx_flags = '' | 214   pnacl_sdk_cxx_flags = '' | 
| 226   pnacl_sdk_cc_flags = ' -std=gnu99' | 215   pnacl_sdk_cc_flags = ' -std=gnu99' | 
| 227   pnacl_sdk_cc_native_flags = ' -std=gnu99 -arch %s' % arch | 216   pnacl_sdk_cc_native_flags = ' -std=gnu99 -arch %s' % arch | 
| 228   pnacl_sdk_ld_flags = ' -arch %s' % arch | 217   pnacl_sdk_ld_flags = ' -arch %s' % arch | 
| 229   pnacl_sdk_ld_flags += ' ' + ' '.join(env['PNACL_BCLDFLAGS']) | 218   pnacl_sdk_ld_flags += ' ' + ' '.join(env['PNACL_BCLDFLAGS']) | 
| 230   if env.Bit('nacl_pic'): | 219   if env.Bit('nacl_pic'): | 
| 231     pnacl_sdk_cc_flags += ' -fPIC' | 220     pnacl_sdk_cc_flags += ' -fPIC' | 
| 232     pnacl_sdk_cxx_flags += ' -fPIC' | 221     pnacl_sdk_cxx_flags += ' -fPIC' | 
| 233     # NOTE: this is a special hack for the pnacl backend which | 222     # NOTE: this is a special hack for the pnacl backend which | 
| 234     #       does more than linking | 223     #       does more than linking | 
| 235     pnacl_sdk_ld_flags += ' -fPIC' | 224     pnacl_sdk_ld_flags += ' -fPIC' | 
| 236 | 225 | 
| 237   if env.Bit('use_sandboxed_translator'): | 226   if env.Bit('use_sandboxed_translator'): | 
| 238     pnacl_sdk_ld_flags += ' --pnacl-sb' | 227     pnacl_sdk_ld_flags += ' --pnacl-sb' | 
| 239 | 228 | 
| 240   # TODO(pdox): Remove the dependency on the gcc toolchain here. | 229   # TODO(pdox): Remove PNaCl's dependency on the gcc toolchain here. | 
| 241   nacl_gcc_root = os.path.join('${MAIN_DIR}', | 230   platform = NACL_CANONICAL_PLATFORM_MAP[env['PLATFORM']] | 
| 242                                'toolchain', | 231   nnacl_root = os.path.join(env['MAIN_DIR'], 'toolchain', '%s_x86' % platform) | 
| 243                                _PlatformSubdirs(env)[0]) | 232 | 
| 244   cc_other_map = { | 233   cc_other_map = { | 
| 245       'arm':    pnacl_sdk_cc + pnacl_sdk_cc_native_flags, | 234       'arm':    pnacl_sdk_cc + pnacl_sdk_cc_native_flags, | 
| 246       'x86-32': os.path.join(nacl_gcc_root, 'bin', 'nacl-gcc'), | 235       'x86-32': os.path.join(nnacl_root, 'bin', 'nacl-gcc'), | 
| 247       'x86-64': os.path.join(nacl_gcc_root, 'bin', 'nacl64-gcc'), | 236       'x86-64': os.path.join(nnacl_root, 'bin', 'nacl64-gcc'), | 
| 248       } | 237       } | 
| 249 | 238 | 
| 250   env.Replace(# Replace header and lib paths. | 239   env.Replace(# Replace header and lib paths. | 
| 251               NACL_SDK_INCLUDE=pnacl_sdk_include, | 240               NACL_SDK_INCLUDE=pnacl_sdk_include, | 
| 252               NACL_SDK_LIB=pnacl_sdk_lib, | 241               NACL_SDK_LIB=pnacl_sdk_lib, | 
| 253               # Replace the normal unix tools with the PNaCl ones. | 242               # Replace the normal unix tools with the PNaCl ones. | 
| 254               CC=pnacl_sdk_cc + pnacl_sdk_cc_flags, | 243               CC=pnacl_sdk_cc + pnacl_sdk_cc_flags, | 
| 255               CXX=pnacl_sdk_cxx + pnacl_sdk_cxx_flags, | 244               CXX=pnacl_sdk_cxx + pnacl_sdk_cxx_flags, | 
| 256               # NOTE: only in bitcode compilation scenarios where | 245               # NOTE: only in bitcode compilation scenarios where | 
| 257               #       CC compiles to bitcode and | 246               #       CC compiles to bitcode and | 
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 390 | 379 | 
| 391   # Get root of the SDK. | 380   # Get root of the SDK. | 
| 392   root = _GetNaclSdkRoot(env, sdk_mode) | 381   root = _GetNaclSdkRoot(env, sdk_mode) | 
| 393 | 382 | 
| 394   # Determine where to get the SDK from. | 383   # Determine where to get the SDK from. | 
| 395   if sdk_mode == 'manual': | 384   if sdk_mode == 'manual': | 
| 396     _SetEnvForSdkManually(env) | 385     _SetEnvForSdkManually(env) | 
| 397   else: | 386   else: | 
| 398     # if bitcode=1 use pnacl toolchain | 387     # if bitcode=1 use pnacl toolchain | 
| 399     if env.Bit('bitcode'): | 388     if env.Bit('bitcode'): | 
| 400       _SetEnvForPnacl(env, env['TARGET_FULLARCH']) | 389       _SetEnvForPnacl(env, root) | 
| 401     elif env.Bit('target_x86'): | 390     elif env.Bit('target_x86'): | 
| 402       _SetEnvForX86Sdk(env, root) | 391       _SetEnvForX86Sdk(env, root) | 
| 403     else: | 392     else: | 
| 404       print "ERROR: unknown TARGET_ARCHITECTURE: ", env['TARGET_ARCHITECTURE'] | 393       print "ERROR: unknown TARGET_ARCHITECTURE: ", env['TARGET_ARCHITECTURE'] | 
| 405       assert 0 | 394       assert 0 | 
| 406 | 395 | 
| 407   env.Prepend(LIBPATH='${NACL_SDK_LIB}') | 396   env.Prepend(LIBPATH='${NACL_SDK_LIB}') | 
| OLD | NEW | 
|---|