|
|
|
@@ -3,7 +3,6 @@ from shutil import rmtree
|
|
|
|
from sys import argv
|
|
|
|
from sys import argv
|
|
|
|
from argparse import ArgumentParser, Namespace
|
|
|
|
from argparse import ArgumentParser, Namespace
|
|
|
|
import tomllib as toml
|
|
|
|
import tomllib as toml
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MX_DISCARD_PATHS = [
|
|
|
|
MX_DISCARD_PATHS = [
|
|
|
|
"cmake",
|
|
|
|
"cmake",
|
|
|
|
@@ -74,7 +73,7 @@ def recurse_cmakelists(path: Path):
|
|
|
|
if has_headers:
|
|
|
|
if has_headers:
|
|
|
|
lines.append("target_include_directories(%s PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})"%(CMAKE_TARGET))
|
|
|
|
lines.append("target_include_directories(%s PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})"%(CMAKE_TARGET))
|
|
|
|
if len(sources) != 0:
|
|
|
|
if len(sources) != 0:
|
|
|
|
lines.append("target_sources(%s PUBLIC"%(CMAKE_TARGET))
|
|
|
|
lines.append("target_sources(%s PRIVATE"%(CMAKE_TARGET))
|
|
|
|
lines += ["\t%s"%(src.name) for src in sources]
|
|
|
|
lines += ["\t%s"%(src.name) for src in sources]
|
|
|
|
lines.append(")")
|
|
|
|
lines.append(")")
|
|
|
|
lines += ["add_subdirectory(%s)"%(directory.name) for directory in dirs]
|
|
|
|
lines += ["add_subdirectory(%s)"%(directory.name) for directory in dirs]
|
|
|
|
@@ -92,10 +91,9 @@ def root_cmakelists(path: Path):
|
|
|
|
lists_path = path / "CMakeLists.txt"
|
|
|
|
lists_path = path / "CMakeLists.txt"
|
|
|
|
|
|
|
|
|
|
|
|
# Define custom libraries
|
|
|
|
# Define custom libraries
|
|
|
|
lines.append("add_library(%s STATIC)"%(CMAKE_TARGET))
|
|
|
|
lines.append("add_library(%s OBJECT)"%(CMAKE_TARGET))
|
|
|
|
lines.append("target_compile_definitions(%s PRIVATE ${COMPILER_DEFINES})"%(CMAKE_TARGET))
|
|
|
|
lines.append("target_compile_definitions(%s PRIVATE ${COMPILER_DEFINES})"%(CMAKE_TARGET))
|
|
|
|
lines.append("target_compile_options(%s PRIVATE -Os -ffunction-sections -fdata-sections -g -flto)"%(CMAKE_TARGET))
|
|
|
|
lines.append("target_compile_options(%s PRIVATE -Os -ffunction-sections -fdata-sections -g -flto)"%(CMAKE_TARGET))
|
|
|
|
lines.append("target_link_options(%s PRIVATE -T ${LINKER_SCRIPT} -Wl,--gc-sections -flto)"%(CMAKE_TARGET))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Read previously generated contents
|
|
|
|
# Read previously generated contents
|
|
|
|
with open(lists_path, "r") as _if:
|
|
|
|
with open(lists_path, "r") as _if:
|
|
|
|
@@ -131,7 +129,7 @@ def call_my_main(path: Path):
|
|
|
|
with open(main_c, "r") as _if:
|
|
|
|
with open(main_c, "r") as _if:
|
|
|
|
content = _if.read()
|
|
|
|
content = _if.read()
|
|
|
|
|
|
|
|
|
|
|
|
patched = content.replace("/* USER CODE BEGIN PFP */", "/* USER CODE BEGIN PFP */\nvoid my_main();").replace("/* USER CODE BEGIN WHILE */", "/* USER CODE BEGIN WHILE */\nmy_main();")
|
|
|
|
patched = content.replace("/* USER CODE BEGIN PFP */", "/* USER CODE BEGIN PFP */\nvoid my_main();").replace("/* USER CODE BEGIN WHILE */\n while (1)", "/* USER CODE BEGIN WHILE */\nmy_main();\n while (1)")
|
|
|
|
|
|
|
|
|
|
|
|
with open(main_c, "w") as of:
|
|
|
|
with open(main_c, "w") as of:
|
|
|
|
of.write(patched)
|
|
|
|
of.write(patched)
|
|
|
|
|