| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from platform import machine, python_version, system |
| 6 |
import sys |
| 7 |
|
| 8 |
def detectCPU(): |
| 9 |
'''Detects the CPU family (not the CPU model) of the machine were are |
| 10 |
running on. |
| 11 |
Raises ValueError if no known CPU is detected. |
| 12 |
''' |
| 13 |
cpu = machine().lower() |
| 14 |
dashIndex = cpu.find('-') |
| 15 |
if dashIndex != -1: |
| 16 |
|
| 17 |
cpu = cpu[ : dashIndex] |
| 18 |
if cpu in ('x86_64', 'amd64'): |
| 19 |
return 'x86_64' |
| 20 |
elif cpu in ('x86', 'i386', 'i486', 'i586', 'i686'): |
| 21 |
return 'x86' |
| 22 |
elif cpu.startswith('ppc') or cpu.endswith('ppc') or cpu.startswith('power'): |
| 23 |
return 'ppc64' if cpu.endswith('64') else 'ppc' |
| 24 |
elif cpu.startswith('arm'): |
| 25 |
return 'arm' |
| 26 |
elif cpu.startswith('mips') or cpu == 'sgi': |
| 27 |
return 'mipsel' if cpu.endswith('el') else 'mips' |
| 28 |
elif cpu.startswith('alpha'): |
| 29 |
return 'alpha' |
| 30 |
elif cpu.startswith('hppa') or cpu.startswith('parisc'): |
| 31 |
return 'hppa' |
| 32 |
elif cpu.startswith('s390'): |
| 33 |
return 's390' |
| 34 |
elif cpu.startswith('sparc') or cpu.startswith('sun4u'): |
| 35 |
return 'sparc' |
| 36 |
elif cpu.startswith('sh'): |
| 37 |
return 'sheb' if cpu.endswith('eb') else 'sh' |
| 38 |
elif cpu == '': |
| 39 |
|
| 40 |
os = system().lower() |
| 41 |
if os == 'windows': |
| 42 |
|
| 43 |
return 'x86' |
| 44 |
return 'unknown' |
| 45 |
else: |
| 46 |
return cpu |
| 47 |
|
| 48 |
def detectOS(): |
| 49 |
'''Detects the operating system of the machine were are running on. |
| 50 |
Raises ValueError if no known OS is detected. |
| 51 |
''' |
| 52 |
os = system().lower() |
| 53 |
if os in ('linux', 'darwin', 'freebsd', 'netbsd', 'openbsd', 'gnu'): |
| 54 |
return os |
| 55 |
elif os.startswith('gnu/'): |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
return 'gnu' |
| 60 |
elif os.startswith('mingw') or os == 'windows': |
| 61 |
return 'mingw32' |
| 62 |
elif os == 'sunos': |
| 63 |
return 'solaris' |
| 64 |
elif os == '': |
| 65 |
|
| 66 |
return 'unknown' |
| 67 |
else: |
| 68 |
return os |
| 69 |
|
| 70 |
if __name__ == '__main__': |
| 71 |
try: |
| 72 |
print(' Using Python %s native system detection...' % ( |
| 73 |
python_version() |
| 74 |
), file = sys.stderr) |
| 75 |
hostCPU = detectCPU() |
| 76 |
hostOS = detectOS() |
| 77 |
print(' Detected system: %s-%s' % (hostCPU, hostOS), file = sys.stderr) |
| 78 |
print('OPENMSX_TARGET_CPU=%s' % hostCPU) |
| 79 |
print('OPENMSX_TARGET_OS=%s' % hostOS) |
| 80 |
except ValueError as ex: |
| 81 |
print(ex, file = sys.stderr) |
| 82 |
sys.exit(1) |