buildinfo2code.py 3.3 KB

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