File: components2code.py

package info (click to toggle)
openmsx 20.0%2Bdfsg-1.2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 27,544 kB
  • sloc: cpp: 236,922; xml: 49,948; tcl: 15,056; python: 5,385; perl: 281; sh: 77; makefile: 53
file content (43 lines) | stat: -rw-r--r-- 1,137 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Creates the components header file.

from components import iterComponents
from makeutils import extractMakeVariables
from outpututils import rewriteIfChanged

import sys

def iterComponentsHeader(probeMakePath):
	probeVars = extractMakeVariables(probeMakePath)
	buildComponents = set(
		component.makeName
		for component in iterComponents()
		if component.canBuild(probeVars)
		)

	yield '// Automatically generated by build process.'
	yield ''
	yield '#ifndef COMPONENTS_HH'
	yield '#define COMPONENTS_HH'
	yield ''
	for component in iterComponents():
		varName = component.makeName
		yield '#define COMPONENT_%s %d' % (varName, varName in buildComponents)
	yield ''
	yield 'namespace openmsx {'
	yield ''
	yield 'static const char* const BUILD_COMPONENTS = "%s";' \
		% ' '.join(sorted(buildComponents))
	yield ''
	yield '} // namespace openmsx'
	yield ''
	yield '#endif // COMPONENTS_HH'

if __name__ == '__main__':
	if len(sys.argv) == 3:
		rewriteIfChanged(sys.argv[1], iterComponentsHeader(sys.argv[2]))
	else:
		print(
			'Usage: python3 components2code.py COMPONENTS_HEADER PROBE_MAKE',
			file=sys.stderr
			)
		sys.exit(2)