| 1 |
from cpu import getCPU, X86, X86_64 |
| 2 |
from makeutils import extractMakeVariables, parseBool |
| 3 |
from outpututils import rewriteIfChanged |
| 4 |
|
| 5 |
from os.path import dirname, join as joinpath |
| 6 |
import sys |
| 7 |
|
| 8 |
def iterBuildInfoHeader(targetPlatform, cpuName, flavour, installShareDir, installDocDir): |
| 9 |
platformVars = extractMakeVariables( |
| 10 |
joinpath(dirname(__file__), 'platform-%s.mk' % targetPlatform), |
| 11 |
dict.fromkeys( |
| 12 |
('COMPILE_FLAGS', 'LINK_FLAGS', 'LDFLAGS', 'TARGET_FLAGS', |
| 13 |
'OPENMSX_TARGET_CPU'), |
| 14 |
'' |
| 15 |
) |
| 16 |
) |
| 17 |
setWindowIcon = parseBool(platformVars.get('SET_WINDOW_ICON', 'true')) |
| 18 |
|
| 19 |
targetCPU = getCPU(cpuName) |
| 20 |
|
| 21 |
|
| 22 |
platformPandora = targetPlatform == 'pandora' |
| 23 |
platformAndroid = targetPlatform == 'android' |
| 24 |
|
| 25 |
|
| 26 |
minScaleFactor = 2 |
| 27 |
maxScaleFactor = 4 |
| 28 |
|
| 29 |
|
| 30 |
if platformAndroid: |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
minScaleFactor = 2 |
| 35 |
maxScaleFactor = 2 |
| 36 |
elif platformPandora: |
| 37 |
maxScaleFactor = 3 |
| 38 |
|
| 39 |
yield '// Automatically generated by build process.' |
| 40 |
yield '' |
| 41 |
yield '#ifndef BUILD_INFO_HH' |
| 42 |
yield '#define BUILD_INFO_HH' |
| 43 |
yield '' |
| 44 |
|
| 45 |
|
| 46 |
yield '#define PLATFORM_ANDROID %d' % platformAndroid |
| 47 |
yield '#define MIN_SCALE_FACTOR %d' % minScaleFactor |
| 48 |
yield '#define MAX_SCALE_FACTOR %d' % maxScaleFactor |
| 49 |
yield '' |
| 50 |
yield 'namespace openmsx {' |
| 51 |
yield '' |
| 52 |
yield 'static const bool OPENMSX_SET_WINDOW_ICON = %s;' \ |
| 53 |
% str(setWindowIcon).lower() |
| 54 |
yield 'static const char* const DATADIR = "%s";' % installShareDir |
| 55 |
yield 'static const char* const DOCDIR = "%s";' % installDocDir |
| 56 |
yield 'static const char* const BUILD_FLAVOUR = "%s";' % flavour |
| 57 |
yield 'static const char* const TARGET_PLATFORM = "%s";' % targetPlatform |
| 58 |
yield 'static const char* const TARGET_CPU = "%s";' % targetCPU.name |
| 59 |
yield '' |
| 60 |
yield '} // namespace openmsx' |
| 61 |
yield '' |
| 62 |
yield '#endif // BUILD_INFO_HH' |
| 63 |
|
| 64 |
if __name__ == '__main__': |
| 65 |
if len(sys.argv) == 7: |
| 66 |
rewriteIfChanged(sys.argv[1], iterBuildInfoHeader(*sys.argv[2 : ])) |
| 67 |
else: |
| 68 |
print( |
| 69 |
'Usage: python3 buildinfo2code.py CONFIG_HEADER ' |
| 70 |
'platform cpu flavour share-install-dir doc-install-dir', |
| 71 |
file=sys.stderr |
| 72 |
) |
| 73 |
sys.exit(2) |