File: detectsys.py

package info (click to toggle)
openmsx-catapult 19.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,952 kB
  • sloc: cpp: 6,592; python: 458; makefile: 43; sed: 37; sh: 25
file content (41 lines) | stat: -rw-r--r-- 1,257 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Detect the native OS.
# Actually we rely on the Python "platform" module and map its output to names
# that the Catapult build understands.

from platform import machine, python_version, system
import sys

def detectOS():
	'''Detects the operating system of the machine were are running on.
	Raises ValueError if no known OS is detected.
	'''
	os = system().lower()
	if os in ('linux', 'darwin', 'freebsd', 'netbsd', 'openbsd', 'gnu'):
		return os
	elif os.startswith('gnu/'):
		# GNU userland on non-Hurd kernel, for example Debian GNU/kFreeBSD.
		# For openMSX the kernel is not really relevant, so treat it like
		# a generic GNU system.
		return 'gnu'
	elif os.startswith('mingw') or os == 'windows':
		return 'mingw32'
	elif os == 'sunos':
		return 'solaris'
	elif os == '':
		# Python couldn't figure it out.
		raise ValueError('Unable to detect OS')
	else:
		raise ValueError('Unsupported or unrecognised OS "%s"' % os)

if __name__ == '__main__':
	try:
		print(
			'  Using Python %s native system detection...' % python_version(),
			file=sys.stderr
			)
		hostOS = detectOS()
		print('  Detected OS: %s' % (hostOS,), file=sys.stderr)
		print('CATAPULT_TARGET_OS=%s' % hostOS)
	except ValueError as ex:
		print(ex, file=sys.stderr)
		sys.exit(1)