diff --git a/tools/m2ctx.py b/tools/m2ctx.py index 17811919..4cf897ec 100755 --- a/tools/m2ctx.py +++ b/tools/m2ctx.py @@ -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: