summaryrefslogtreecommitdiff
path: root/scripts/amalgamation/gen_amalgamation.py
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-07-21 16:17:26 +1000
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-07-21 16:17:26 +1000
commit1f9b47d925a0a21111e458a573a991ef26a35528 (patch)
tree7d7fc43b24d096b4c7998e6f09684619c670ffd3 /scripts/amalgamation/gen_amalgamation.py
parent47465948f2a5a85d0882ff116fce095f401d69c1 (diff)
start adding rust bindgen
Diffstat (limited to 'scripts/amalgamation/gen_amalgamation.py')
-rw-r--r--scripts/amalgamation/gen_amalgamation.py55
1 files changed, 45 insertions, 10 deletions
diff --git a/scripts/amalgamation/gen_amalgamation.py b/scripts/amalgamation/gen_amalgamation.py
index 45a1c21..4a4d946 100644
--- a/scripts/amalgamation/gen_amalgamation.py
+++ b/scripts/amalgamation/gen_amalgamation.py
@@ -2,23 +2,58 @@
#
# This makes including and linking Celeritas very easy.
import re
-import sys
+import os
+from pathlib import Path
-def find_pub_functions(filepath):
+categories = {
+ "RAL": "src/ral",
+ "Render": "src/new_render",
+ "Maths": "src/maths"
+}
+
+def find_pub_functions_in_folder(folder_path):
+ functions = []
+ for filename in os.listdir(folder_path):
+ filepath = os.path.join(folder_path, filename)
+ if os.path.isfile(filepath):
+ file_funcs = find_pub_functions_in_file(filepath)
+ functions.extend(file_funcs)
+
+ return functions
+
+def find_pub_functions_in_file(file_path):
pattern = r'PUB\s+(\w+\s+)*(\w+)\s+(\w+)\s*\((.*?)\)'
- with open(filepath, 'r') as file:
+ with open(file_path, 'r') as file:
content = file.read()
matches = re.finditer(pattern, content, re.MULTILINE)
+ # Collect all the functions into an array
+ functions = []
for match in matches:
- print(match.group(0))
+ signature = match.group(0)
+ if signature.startswith("PUB "):
+ signature = signature[4:]
-if __name__ == "__main__":
- if len(sys.argv) != 2:
- print("Usage: python script.py <path_to_c_file>")
- sys.exit(1)
+ print(signature)
+ functions.append(signature)
+
+ return functions
- file_path = sys.argv[1]
- find_pub_functions(file_path)
+def generate_header():
+ header_path = "celeritas.h"
+
+ script_dir = Path(__file__).resolve().parent
+ grandparent_dir = script_dir.parents[1]
+
+ with open(header_path, 'w') as export_file:
+ for category in categories.keys():
+ folder = os.path.join(grandparent_dir, categories[category])
+ category_funcs = find_pub_functions_in_folder(folder)
+ for func in category_funcs:
+ export_file.write(func)
+ export_file.write(';\n')
+
+if __name__ == "__main__":
+ generate_header()