| 1 |
|
| 2 |
|
| 3 |
from components import iterComponents |
| 4 |
from makeutils import extractMakeVariables |
| 5 |
from outpututils import rewriteIfChanged |
| 6 |
|
| 7 |
import sys |
| 8 |
|
| 9 |
def iterComponentsHeader(probeMakePath): |
| 10 |
probeVars = extractMakeVariables(probeMakePath) |
| 11 |
buildComponents = set( |
| 12 |
component.makeName |
| 13 |
for component in iterComponents() |
| 14 |
if component.canBuild(probeVars) |
| 15 |
) |
| 16 |
|
| 17 |
yield '// Automatically generated by build process.' |
| 18 |
yield '' |
| 19 |
yield '#ifndef COMPONENTS_HH' |
| 20 |
yield '#define COMPONENTS_HH' |
| 21 |
yield '' |
| 22 |
for component in iterComponents(): |
| 23 |
varName = component.makeName |
| 24 |
yield '#define COMPONENT_%s %d' % (varName, varName in buildComponents) |
| 25 |
yield '' |
| 26 |
yield 'namespace openmsx {' |
| 27 |
yield '' |
| 28 |
yield 'static const char* const BUILD_COMPONENTS = "%s";' \ |
| 29 |
% ' '.join(sorted(buildComponents)) |
| 30 |
yield '' |
| 31 |
yield '} // namespace openmsx' |
| 32 |
yield '' |
| 33 |
yield '#endif // COMPONENTS_HH' |
| 34 |
|
| 35 |
if __name__ == '__main__': |
| 36 |
if len(sys.argv) == 3: |
| 37 |
rewriteIfChanged(sys.argv[1], iterComponentsHeader(sys.argv[2])) |
| 38 |
else: |
| 39 |
print( |
| 40 |
'Usage: python3 components2code.py COMPONENTS_HEADER PROBE_MAKE', |
| 41 |
file=sys.stderr |
| 42 |
) |
| 43 |
sys.exit(2) |