File: components2code.py

package info (click to toggle)
openmsx 0.8.2-2.1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 15,796 kB
  • sloc: cpp: 124,615; xml: 22,614; tcl: 7,336; python: 3,789; asm: 1,154; sh: 69; makefile: 25
file content (45 lines) | stat: -rw-r--r-- 1,233 bytes parent folder | download | duplicates (2)
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
44
45
# $Id: components2code.py 10418 2009-08-27 12:28:00Z mthuurne $
# 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 ''
	yield '#include <string>'
	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 std::string 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 >> sys.stderr, (
			'Usage: python components2code.py COMPONENTS_HEADER PROBE_MAKE'
			)
		sys.exit(2)