diff --git a/tools/merger/join.py b/tools/merger/join.py new file mode 100644 index 0000000..7bfd4a8 --- /dev/null +++ b/tools/merger/join.py @@ -0,0 +1,101 @@ +#!/usr/bin/python +# +# Copyright (c) 2023-present Péter Magyar +# Copyright (c) 2020 Krzysztof Gabis +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +import sys +import argparse +import re +import os + +template_args = {} +input_path = "" + +print_includes_dict = dict() + +def print_includes(f): + s = f.split("\n") + + for l in s: + if l.startswith("#include <"): + l = l.strip() + + if not l in print_includes_dict: + print(l) + print_includes_dict[l] = 1 + + +def process_file(f): + #print_includes(f) + + return f.replace('#include ', '//#include ') + +def process_command(name, value): + if name == "ARG": + print("Appending arg: " + value) + return template_args[value] + elif name == "FILE": + file_path = os.path.join(input_path, value) + print("Appending file: " + value) + with open(file_path, "r") as file: + res = "#line 1 \"" + value + "\"\n" + res += process_file(file.read()) + res += "#line 0" + return res + +def process_template(template): + regex = r"{{([A-Z]*):([\w./]*)}}" + matches = re.finditer(regex, template, re.MULTILINE) + for _, match in enumerate(matches, start=1): + res = process_command(match.group(1), match.group(2)) + template = template.replace(match.group(0), res) + + return template + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--template", required=True) + parser.add_argument("--path", required=True) + parser.add_argument("--output", required=True) + + args, unknown = parser.parse_known_args() + + global input_path + input_path = args.path + + if len(unknown) % 2 != 0: + print("Uneven number or template args") + return 1 + for i in range(0, len(unknown), 2): + arg = unknown[i] + if arg.startswith("--"): + template_args[arg[2:]] = unknown[i + 1] + + with open(args.template, "r") as f: + output = process_template(f.read()) + + with open(args.output, "w") as f: + f.write(output) + + print("OK") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/tools/merger/join.sh b/tools/merger/join.sh new file mode 100755 index 0000000..363d00a --- /dev/null +++ b/tools/merger/join.sh @@ -0,0 +1,9 @@ + +mkdir -p out + +cd .. +cd .. + +python misc/merger/join.py --template misc/merger/sfw.h.inl --path . --output misc/merger/out/sfw.h +python misc/merger/join.py --template misc/merger/sfw.cpp.inl --path . --output misc/merger/out/sfw.cpp + diff --git a/tools/merger/sfw.cpp.inl b/tools/merger/sfw.cpp.inl new file mode 100644 index 0000000..465edf3 --- /dev/null +++ b/tools/merger/sfw.cpp.inl @@ -0,0 +1,8 @@ + +#include "sfw.h" + + +{{FILE:core/crypto/mbedtls/library/md5.c}} + + + diff --git a/tools/merger/sfw.h.inl b/tools/merger/sfw.h.inl new file mode 100644 index 0000000..2dc9fbf --- /dev/null +++ b/tools/merger/sfw.h.inl @@ -0,0 +1,36 @@ +#ifndef SFW_H +#define SFW_H + +// https://github.com/Relintai/sfw + +/* +Copyright (c) 2023-present Péter Magyar. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +// TODO gather all licenses to here + + + + +{{FILE:core/typedefs.h}} + + +#endif