install.py 4.4 KB

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