OXYGENHUB
◆ main openmsx / build / install.py
4.4 KiB · Python · last changed chore(): initial commit 1 month ago source blame history raw
1
from fileutils import (
2
	installDirs, installFile, installSymlink, installTree, scanTree
3
	)
4
from makeutils import extractMakeVariables, parseBool
5
6
from os import listdir
7
from os.path import basename, expanduser, isdir, splitext
8
import os
9
import sys
10
11
def installAll(
12
	installPrefix, binaryDestDir, shareDestDir, docDestDir,
13
	binaryBuildPath, targetPlatform, cbios, symlinkForBinary
14
	):
15
	platformVars = extractMakeVariables(
16
		'build/platform-%s.mk' % targetPlatform,
17
		dict.fromkeys(
18
			('COMPILE_FLAGS', 'LINK_FLAGS', 'TARGET_FLAGS',
19
			 'OPENMSX_TARGET_CPU'),
20
			''
21
			)
22
		)
23
	binaryFileName = 'openmsx' + platformVars.get('EXEEXT', '')
24
25
	docNodeVars = extractMakeVariables('doc/node.mk')
26
	docsToInstall = [
27
		'doc/' + fileName for fileName in docNodeVars['INSTALL_DOCS'].split()
28
		]
29
30
	print('  Executable...')
31
	installDirs(installPrefix + binaryDestDir)
32
	installFile(
33
		binaryBuildPath,
34
		installPrefix + binaryDestDir + '/' + binaryFileName
35
		)
36
37
	print('  Data files...')
38
	installDirs(installPrefix + shareDestDir)
39
	installTree('share', installPrefix + shareDestDir, scanTree('share'))
40
41
	print('  Documentation...')
42
	installDirs(installPrefix + docDestDir)
43
	for path in docsToInstall:
44
		installFile(path, installPrefix + docDestDir + '/' + basename(path))
45
	installDirs(installPrefix + docDestDir + '/manual')
46
	for fileName in listdir('doc/manual'):
47
		if splitext(fileName)[1] in ('.html', '.css', '.png'):
48
			installFile(
49
				'doc/manual/' + fileName,
50
				installPrefix + docDestDir + '/manual/' + fileName
51
				)
52
53
	if cbios:
54
		print('  C-BIOS...')
55
		installFile(
56
			'Contrib/README.cbios', installPrefix + docDestDir + '/cbios.txt'
57
			)
58
		installTree(
59
			'Contrib/cbios', installPrefix + shareDestDir + '/machines',
60
			scanTree('Contrib/cbios')
61
			)
62
		installDirs(installPrefix + shareDestDir + '/systemroms/cbios-old')
63
		installTree(
64
			'Contrib/cbios-old',
65
			installPrefix + shareDestDir + '/systemroms/cbios-old',
66
			scanTree('Contrib/cbios-old')
67
			)
68
69
	if hasattr(os, 'symlink') and os.name != 'nt':
70
		print('  Creating symlinks...')
71
		for machine, alias in (
72
			('National_CF-3300', 'msx1'),
73
			('Toshiba_HX-10', 'msx1_eu'),
74
			('Sony_HB-F900', 'msx2'),
75
			('Philips_NMS_8250', 'msx2_eu'),
76
			('Panasonic_FS-A1WSX', 'msx2plus'),
77
			('Panasonic_FS-A1GT', 'turbor'),
78
			):
79
			installSymlink(
80
				machine + ".xml",
81
				installPrefix + shareDestDir + '/machines/' + alias + ".xml"
82
				)
83
		if symlinkForBinary and installPrefix == '':
84
			def createSymlinkToBinary(linkDir):
85
				if linkDir != binaryDestDir and isdir(linkDir):
86
					try:
87
						installSymlink(
88
							binaryDestDir + '/' + binaryFileName,
89
							linkDir + '/' + binaryFileName
90
							)
91
					except OSError:
92
						return False
93
					else:
94
						return True
95
				else:
96
					return False
97
			success = createSymlinkToBinary('/usr/local/bin')
98
			if not success:
99
				createSymlinkToBinary(expanduser('~/bin'))
100
101
def main(
102
	installPrefix, binaryDestDir, shareDestDir, docDestDir,
103
	binaryBuildPath, targetPlatform, verboseStr, cbiosStr
104
	):
105
	customVars = extractMakeVariables('build/custom.mk')
106
107
	try:
108
		verbose = parseBool(verboseStr)
109
		cbios = parseBool(cbiosStr)
110
		symlinkForBinary = parseBool(customVars['SYMLINK_FOR_BINARY'])
111
	except ValueError as ex:
112
		print('Invalid argument:', ex, file=sys.stderr)
113
		sys.exit(2)
114
115
	if installPrefix and not installPrefix.endswith('/'):
116
		# Just in case the destination directories are not absolute.
117
		installPrefix += '/'
118
119
	if verbose:
120
		print('Installing openMSX:')
121
122
	try:
123
		installAll(
124
			installPrefix, binaryDestDir, shareDestDir, docDestDir,
125
			binaryBuildPath, targetPlatform, cbios, symlinkForBinary
126
			)
127
	except OSError as ex:
128
		print('Installation failed:', ex, file=sys.stderr)
129
		sys.exit(1)
130
131
	if verbose:
132
		print('Installation complete... have fun!')
133
		print((
134
			'Notice: if you want to emulate real MSX systems and not only the '
135
			'free C-BIOS machines, put the system ROMs in one of the following '
136
			'directories: %s/systemroms or '
137
			'~/.openMSX/share/systemroms\n'
138
			'If you want openMSX to find MSX software referred to from replays '
139
			'or savestates you get from your friends, copy that MSX software to '
140
			'%s/software or '
141
			'~/.openMSX/share/software'
142
			) % (shareDestDir, shareDestDir))
143
144
if __name__ == '__main__':
145
	if len(sys.argv) == 9:
146
		main(*sys.argv[1 : ])
147
	else:
148
		print(
149
			'Usage: python3 install.py '
150
			'DESTDIR INSTALL_BINARY_DIR INSTALL_SHARE_DIR INSTALL_DOC_DIR '
151
			'BINARY_FULL OPENMSX_TARGET_OS INSTALL_VERBOSE INSTALL_CONTRIB',
152
			file=sys.stderr
153
			)
154
		sys.exit(2)