Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright 2014 the V8 project authors. All rights reserved. |
| 3 | # Redistribution and use in source and binary forms, with or without |
| 4 | # modification, are permitted provided that the following conditions are |
| 5 | # met: |
| 6 | # |
| 7 | # * Redistributions of source code must retain the above copyright |
| 8 | # notice, this list of conditions and the following disclaimer. |
| 9 | # * Redistributions in binary form must reproduce the above |
| 10 | # copyright notice, this list of conditions and the following |
| 11 | # disclaimer in the documentation and/or other materials provided |
| 12 | # with the distribution. |
| 13 | # * Neither the name of Google Inc. nor the names of its |
| 14 | # contributors may be used to endorse or promote products derived |
| 15 | # from this software without specific prior written permission. |
| 16 | # |
| 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | |
| 29 | """Outputs host CPU architecture in format recognized by gyp.""" |
| 30 | |
| 31 | import platform |
| 32 | import re |
| 33 | import sys |
| 34 | |
| 35 | |
| 36 | def main(): |
| 37 | print DoMain([]) |
| 38 | return 0 |
| 39 | |
| 40 | def DoMain(_): |
| 41 | """Hook to be called from gyp without starting a separate python |
| 42 | interpreter.""" |
| 43 | host_arch = platform.machine() |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 44 | host_system = platform.system(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 45 | |
| 46 | # Convert machine type to format recognized by gyp. |
| 47 | if re.match(r'i.86', host_arch) or host_arch == 'i86pc': |
| 48 | host_arch = 'ia32' |
| 49 | elif host_arch in ['x86_64', 'amd64']: |
| 50 | host_arch = 'x64' |
| 51 | elif host_arch.startswith('arm'): |
| 52 | host_arch = 'arm' |
| 53 | elif host_arch == 'aarch64': |
| 54 | host_arch = 'arm64' |
| 55 | elif host_arch == 'mips64': |
| 56 | host_arch = 'mips64el' |
| 57 | elif host_arch.startswith('mips'): |
| 58 | host_arch = 'mipsel' |
| 59 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 60 | # Under AIX the value returned by platform.machine is not |
| 61 | # the best indicator of the host architecture |
| 62 | # AIX 6.1 which is the lowest level supported only provides |
| 63 | # a 64 bit kernel |
| 64 | if host_system == 'AIX': |
| 65 | host_arch = 'ppc64' |
| 66 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 67 | # platform.machine is based on running kernel. It's possible to use 64-bit |
| 68 | # kernel with 32-bit userland, e.g. to give linker slightly more memory. |
| 69 | # Distinguish between different userland bitness by querying |
| 70 | # the python binary. |
| 71 | if host_arch == 'x64' and platform.architecture()[0] == '32bit': |
| 72 | host_arch = 'ia32' |
| 73 | |
| 74 | return host_arch |
| 75 | |
| 76 | if __name__ == '__main__': |
| 77 | sys.exit(main()) |