1
# $Id: detectsys.py 10885 2009-12-05 19:26:16Z mthuurne $
2
# Detect the native CPU and OS.
3
# Actually we rely on the Python "platform" module and map its output to names
4
# that the openMSX build understands.
6
from platform import machine, python_version, system
10
'''Detects the CPU family (not the CPU model) of the machine were are
12
Raises ValueError if no known CPU is detected.
14
cpu = machine().lower()
15
dashIndex = cpu.find('-')
17
# Hurd returns "cputype-cpusubtype" instead of just "cputype".
18
cpu = cpu[ : dashIndex]
19
if cpu in ('x86_64', 'amd64'):
21
elif cpu in ('x86', 'i386', 'i486', 'i586', 'i686'):
23
elif cpu.startswith('ppc') or cpu.startswith('power'):
24
return 'ppc64' if cpu.endswith('64') else 'ppc'
25
elif cpu.startswith('arm'):
27
elif cpu.startswith('mips'):
28
return 'mipsel' if cpu.endswith('el') else 'mips'
33
elif cpu.startswith('alpha'):
35
elif cpu.startswith('hppa') or cpu.startswith('parisc'):
37
elif cpu.startswith('s390'):
39
elif cpu.startswith('sparc') or cpu.startswith('sun4u'):
41
elif cpu.startswith('sh'):
42
return 'sheb' if cpu.endswith('eb') else 'sh'
46
# Python couldn't figure it out.
49
# Relatively safe bet.
51
raise ValueError('Unable to detect CPU')
53
raise ValueError('Unsupported or unrecognised CPU "%s"' % cpu)
56
'''Detects the operating system of the machine were are running on.
57
Raises ValueError if no known OS is detected.
60
if os in ('linux', 'darwin', 'freebsd', 'netbsd', 'openbsd', 'gnu'):
62
elif os.startswith('gnu/'):
63
# GNU userland on non-Hurd kernel, for example Debian GNU/kFreeBSD.
64
# For openMSX the kernel is not really relevant, so treat it like
65
# a generic GNU system.
67
elif os.startswith('mingw') or os == 'windows':
72
# Python couldn't figure it out.
73
raise ValueError('Unable to detect OS')
75
raise ValueError('Unsupported or unrecognised OS "%s"' % os)
77
if __name__ == '__main__':
79
print >> sys.stderr, ' Using Python %s native system detection...' % (
84
if hostOS == 'mingw32' and hostCPU == 'x86_64':
85
# It is possible to run MinGW on 64-bit Windows, but producing
86
# 64-bit code is not supported yet.
88
print >> sys.stderr, ' Detected system: %s-%s' % (hostCPU, hostOS)
89
print 'OPENMSX_TARGET_CPU=%s' % hostCPU
90
print 'OPENMSX_TARGET_OS=%s' % hostOS
91
except ValueError, ex:
92
print >> sys.stderr, ex