Exclude duplicate macros in m2ctx

This commit is contained in:
Aetias
2024-02-18 11:34:42 +01:00
parent 7412a00674
commit f23e8d5e11
+8 -1
View File
@@ -66,7 +66,7 @@ while i < len(sys.argv):
try:
ctx = subprocess.check_output(['gcc', '-E', '-P', '-undef', '-dD', *CXX_FLAGS, in_file], cwd=root_dir, encoding=encoding)
ctx: str = subprocess.check_output(['gcc', '-E', '-P', '-undef', '-dD', *CXX_FLAGS, in_file], cwd=root_dir, encoding=encoding)
except subprocess.CalledProcessError as e:
eprint(f"Failed to preprocess '{in_file}'")
if verbose: eprint(e)
@@ -74,6 +74,13 @@ except subprocess.CalledProcessError as e:
exit(1)
lines = ctx.splitlines(True)
for i in reversed(range(len(lines))):
if lines[i].startswith('#define __cplusplus'): lines.pop(i)
elif lines[i].startswith('#define __STDC_HOSTED__'): lines.pop(i)
ctx = ''.join(lines)
if out_file:
try:
with open(out_file, "w") as file: