SCsub 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env python
  2. from glob import glob
  3. from pathlib import Path
  4. import methods
  5. Import("env")
  6. env.platform_sources = []
  7. # Generate export icons
  8. def export_icon_builder(target, source, env):
  9. src_path = Path(str(source[0]))
  10. src_name = src_path.stem
  11. platform = src_path.parent.parent.stem
  12. with open(str(source[0]), "rb") as file:
  13. svg = "".join([f"\\{hex(x)[1:]}" for x in file.read()])
  14. with methods.generated_wrapper(target, prefix=platform) as file:
  15. file.write(
  16. f"""\
  17. static const char *_{platform}_{src_name}_svg = "{svg}";
  18. """
  19. )
  20. for platform in env.platform_exporters:
  21. for path in glob(f"{platform}/export/*.svg"):
  22. env.CommandNoCache(path.replace(".svg", "_svg.gen.h"), path, env.Run(export_icon_builder))
  23. # Register platform-exclusive APIs
  24. def register_platform_apis_builder(target, source, env):
  25. platforms = source[0].read()
  26. api_inc = "\n".join([f'#include "{p}/api/api.h"' for p in platforms])
  27. api_reg = "\n".join([f"\tregister_{p}_api();" for p in platforms])
  28. api_unreg = "\n".join([f"\tunregister_{p}_api();" for p in platforms])
  29. with methods.generated_wrapper(target) as file:
  30. file.write(
  31. f"""\
  32. #include "register_platform_apis.h"
  33. {api_inc}
  34. void register_platform_apis() {{
  35. {api_reg}
  36. }}
  37. void unregister_platform_apis() {{
  38. {api_unreg}
  39. }}
  40. """
  41. )
  42. register_platform_apis = env.CommandNoCache(
  43. "register_platform_apis.gen.cpp", env.Value(env.platform_apis), env.Run(register_platform_apis_builder)
  44. )
  45. env.add_source_files(env.platform_sources, register_platform_apis)
  46. for platform in env.platform_apis:
  47. env.add_source_files(env.platform_sources, f"{platform}/api/api.cpp")
  48. lib = env.add_library("platform", env.platform_sources)
  49. env.Prepend(LIBS=[lib])