2017-11-16 08:33:48 +08:00
|
|
|
#!/usr/bin/env python
|
2024-06-12 04:19:07 +08:00
|
|
|
from misc.utility.scons_hints import *
|
2017-11-16 08:33:48 +08:00
|
|
|
|
2024-05-03 22:44:57 +08:00
|
|
|
from glob import glob
|
|
|
|
from pathlib import Path
|
2024-03-14 00:54:14 +08:00
|
|
|
|
2024-05-21 21:14:59 +08:00
|
|
|
import methods
|
|
|
|
|
2020-03-30 14:28:32 +08:00
|
|
|
Import("env")
|
2019-07-22 19:57:39 +08:00
|
|
|
|
|
|
|
env.platform_sources = []
|
2017-11-16 08:33:48 +08:00
|
|
|
|
2024-05-03 22:44:57 +08:00
|
|
|
|
|
|
|
# Generate export icons
|
|
|
|
def export_icon_builder(target, source, env):
|
|
|
|
src_path = Path(str(source[0]))
|
|
|
|
src_name = src_path.stem
|
|
|
|
platform = src_path.parent.parent.stem
|
2024-08-01 03:15:56 +08:00
|
|
|
with open(str(source[0]), "r") as file:
|
|
|
|
svg = file.read()
|
2024-05-03 22:44:57 +08:00
|
|
|
with methods.generated_wrapper(target, prefix=platform) as file:
|
|
|
|
file.write(
|
|
|
|
f"""\
|
2024-08-01 03:15:56 +08:00
|
|
|
static const char *_{platform}_{src_name}_svg = {methods.to_raw_cstring(svg)};
|
2024-05-03 22:44:57 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
for platform in env.platform_exporters:
|
|
|
|
for path in glob(f"{platform}/export/*.svg"):
|
|
|
|
env.CommandNoCache(path.replace(".svg", "_svg.gen.h"), path, env.Run(export_icon_builder))
|
|
|
|
|
|
|
|
|
2017-11-16 08:33:48 +08:00
|
|
|
# Register platform-exclusive APIs
|
2024-05-03 22:44:57 +08:00
|
|
|
def register_platform_apis_builder(target, source, env):
|
|
|
|
platforms = source[0].read()
|
|
|
|
api_inc = "\n".join([f'#include "{p}/api/api.h"' for p in platforms])
|
|
|
|
api_reg = "\n".join([f"\tregister_{p}_api();" for p in platforms])
|
|
|
|
api_unreg = "\n".join([f"\tunregister_{p}_api();" for p in platforms])
|
|
|
|
with methods.generated_wrapper(target) as file:
|
|
|
|
file.write(
|
|
|
|
f"""\
|
|
|
|
#include "register_platform_apis.h"
|
|
|
|
|
|
|
|
{api_inc}
|
|
|
|
|
|
|
|
void register_platform_apis() {{
|
|
|
|
{api_reg}
|
|
|
|
}}
|
|
|
|
|
|
|
|
void unregister_platform_apis() {{
|
|
|
|
{api_unreg}
|
|
|
|
}}
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
register_platform_apis = env.CommandNoCache(
|
|
|
|
"register_platform_apis.gen.cpp", env.Value(env.platform_apis), env.Run(register_platform_apis_builder)
|
|
|
|
)
|
|
|
|
env.add_source_files(env.platform_sources, register_platform_apis)
|
2017-11-16 08:33:48 +08:00
|
|
|
for platform in env.platform_apis:
|
2024-10-31 23:07:01 +08:00
|
|
|
env.add_source_files(env.platform_sources, f"{platform}/api/*.cpp")
|
2017-11-16 08:33:48 +08:00
|
|
|
|
2020-03-30 14:28:32 +08:00
|
|
|
lib = env.add_library("platform", env.platform_sources)
|
2019-08-13 04:30:57 +08:00
|
|
|
env.Prepend(LIBS=[lib])
|