components2code.py 1.1 KB

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