buildinfo2code.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. from cpu import getCPU, X86, X86_64
  2. from makeutils import extractMakeVariables, parseBool
  3. from outpututils import rewriteIfChanged
  4. from os.path import dirname, join as joinpath
  5. import sys
  6. def iterBuildInfoHeader(targetPlatform, cpuName, flavour, installShareDir):
  7. platformVars = extractMakeVariables(
  8. joinpath(dirname(__file__), 'platform-%s.mk' % targetPlatform),
  9. dict.fromkeys(
  10. ('COMPILE_FLAGS', 'LINK_FLAGS', 'LDFLAGS', 'TARGET_FLAGS',
  11. 'OPENMSX_TARGET_CPU'),
  12. ''
  13. )
  14. )
  15. setWindowIcon = parseBool(platformVars.get('SET_WINDOW_ICON', 'true'))
  16. targetCPU = getCPU(cpuName)
  17. # TODO: Add support for device-specific configuration.
  18. platformDingux = targetPlatform == 'dingux'
  19. platformPandora = targetPlatform == 'pandora'
  20. platformAndroid = targetPlatform == 'android'
  21. # Defaults.
  22. have16BPP = True
  23. have32BPP = True
  24. minScaleFactor = 1
  25. maxScaleFactor = 4
  26. # Platform overrides.
  27. if platformDingux:
  28. maxScaleFactor = 1
  29. elif platformAndroid:
  30. # At the moment, libsdl android crashes when trying to dynamically change the scale factor
  31. # TODO: debug why it crashes and then change the maxScaleFactor parameter here
  32. # so that people with a powerfull enough android device can use a higher scale factor
  33. have32BPP = False
  34. minScaleFactor = 2
  35. maxScaleFactor = 2
  36. elif platformPandora:
  37. have32BPP = False
  38. maxScaleFactor = 3
  39. yield '// Automatically generated by build process.'
  40. yield ''
  41. yield '#ifndef BUILD_INFO_HH'
  42. yield '#define BUILD_INFO_HH'
  43. yield ''
  44. # Use a macro i.s.o. a boolean to prevent compilation errors on inline asm.
  45. # Assembly doesn't appear to work with MINGW64... TODO: find out why
  46. yield '#ifdef __MINGW64__'
  47. yield '#define ASM_X86 0'
  48. yield '#define ASM_X86 0'
  49. yield '#define ASM_X86_32 0'
  50. yield '#define ASM_X86_64 0'
  51. yield '#else'
  52. # A compiler will typically only understand the instruction set that it
  53. # generates code for.
  54. yield '#define ASM_X86 %d' % (targetCPU is X86 or targetCPU is X86_64)
  55. yield '#define ASM_X86_32 %d' % (targetCPU is X86)
  56. yield '#define ASM_X86_64 %d' % (targetCPU is X86_64)
  57. yield '#endif'
  58. # Use a macro iso integer because we really need to exclude code sections
  59. # based on this.
  60. yield '#define PLATFORM_DINGUX %d' % platformDingux
  61. yield '#define PLATFORM_ANDROID %d' % platformAndroid
  62. yield '#define HAVE_16BPP %d' % have16BPP
  63. yield '#define HAVE_32BPP %d' % have32BPP
  64. yield '#define MIN_SCALE_FACTOR %d' % minScaleFactor
  65. yield '#define MAX_SCALE_FACTOR %d' % maxScaleFactor
  66. yield ''
  67. yield 'namespace openmsx {'
  68. yield ''
  69. # Note: Don't call it "BIG_ENDIAN", because some system header may #define
  70. # that.
  71. yield 'static const bool OPENMSX_BIGENDIAN = %s;' \
  72. % str(targetCPU.bigEndian).lower()
  73. yield 'static const bool OPENMSX_SET_WINDOW_ICON = %s;' \
  74. % str(setWindowIcon).lower()
  75. yield 'static const char* const DATADIR = "%s";' % installShareDir
  76. yield 'static const char* const BUILD_FLAVOUR = "%s";' % flavour
  77. yield 'static const char* const TARGET_PLATFORM = "%s";' % targetPlatform
  78. yield ''
  79. yield '} // namespace openmsx'
  80. yield ''
  81. yield '#endif // BUILD_INFO_HH'
  82. if __name__ == '__main__':
  83. if len(sys.argv) == 6:
  84. rewriteIfChanged(sys.argv[1], iterBuildInfoHeader(*sys.argv[2 : ]))
  85. else:
  86. print(
  87. 'Usage: python3 buildinfo2code.py CONFIG_HEADER '
  88. 'platform cpu flavour share-install-dir',
  89. file=sys.stderr
  90. )
  91. sys.exit(2)