~ubuntu-branches/ubuntu/utopic/openmsx-debugger/utopic

« back to all changes in this revision

Viewing changes to build/detectsys.py

  • Committer: Bazaar Package Importer
  • Author(s): Joost Yervante Damad
  • Date: 2009-12-06 07:40:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20091206074002-kssfkg1d6xbp6w9e
Tags: 0.0.0.svn20091206-1
New svn snapshot (Closes: #559612)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
5
 
 
6
from platform import machine, python_version, system
 
7
import sys
 
8
 
 
9
def detectCPU():
 
10
        '''Detects the CPU family (not the CPU model) of the machine were are
 
11
        running on.
 
12
        Raises ValueError if no known CPU is detected.
 
13
        '''
 
14
        cpu = machine().lower()
 
15
        dashIndex = cpu.find('-')
 
16
        if dashIndex != -1:
 
17
                # Hurd returns "cputype-cpusubtype" instead of just "cputype".
 
18
                cpu = cpu[ : dashIndex]
 
19
        if cpu in ('x86_64', 'amd64'):
 
20
                return 'x86_64'
 
21
        elif cpu in ('x86', 'i386', 'i486', 'i586', 'i686'):
 
22
                return 'x86'
 
23
        elif cpu.startswith('ppc') or cpu.startswith('power'):
 
24
                return 'ppc64' if cpu.endswith('64') else 'ppc'
 
25
        elif cpu.startswith('arm'):
 
26
                return 'arm'
 
27
        elif cpu.startswith('mips'):
 
28
                return 'mipsel' if cpu.endswith('el') else 'mips'
 
29
        elif cpu == 'm68k':
 
30
                return 'm68k'
 
31
        elif cpu == 'ia64':
 
32
                return 'ia64'
 
33
        elif cpu.startswith('alpha'):
 
34
                return 'alpha'
 
35
        elif cpu.startswith('hppa') or cpu.startswith('parisc'):
 
36
                return 'hppa'
 
37
        elif cpu.startswith('s390'):
 
38
                return 's390'
 
39
        elif cpu.startswith('sparc') or cpu.startswith('sun4u'):
 
40
                return 'sparc'
 
41
        elif cpu.startswith('sh'):
 
42
                return 'sheb' if cpu.endswith('eb') else 'sh'
 
43
        elif cpu == 'avr32':
 
44
                return 'avr32'
 
45
        elif cpu == '':
 
46
                # Python couldn't figure it out.
 
47
                os = system().lower()
 
48
                if os == 'windows':
 
49
                        # Relatively safe bet.
 
50
                        return 'x86'
 
51
                raise ValueError('Unable to detect CPU')
 
52
        else:
 
53
                raise ValueError('Unsupported or unrecognised CPU "%s"' % cpu)
 
54
 
 
55
def detectOS():
 
56
        '''Detects the operating system of the machine were are running on.
 
57
        Raises ValueError if no known OS is detected.
 
58
        '''
 
59
        os = system().lower()
 
60
        if os in ('linux', 'darwin', 'freebsd', 'netbsd', 'openbsd', 'gnu'):
 
61
                return os
 
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.
 
66
                return 'gnu'
 
67
        elif os.startswith('mingw') or os == 'windows':
 
68
                return 'mingw32'
 
69
        elif os == 'sunos':
 
70
                return 'solaris'
 
71
        elif os == '':
 
72
                # Python couldn't figure it out.
 
73
                raise ValueError('Unable to detect OS')
 
74
        else:
 
75
                raise ValueError('Unsupported or unrecognised OS "%s"' % os)
 
76
 
 
77
if __name__ == '__main__':
 
78
        try:
 
79
                print >> sys.stderr, '  Using Python %s native system detection...' % (
 
80
                        python_version()
 
81
                        )
 
82
                hostCPU = detectCPU()
 
83
                hostOS = detectOS()
 
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.
 
87
                        hostCPU = 'x86'
 
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
 
93
                sys.exit(1)