papermario/tools/m2ctx.py
Ethan Roseman 33c9dda3a5
KMC GCC, effects, cleanup, map funcs (#476)
* warnings, cleanup, 2 npc ai funcs

* kmcgcc stuff

* effect_75

* effect_9.c done

* cleanup, work on kmc gcc

* start on fx_73

* guOrtho/guOrthoF

* more libultra/cleanup

* more libultra

* add wine for darwin

* effect_73 done

* UnkQuizFunc

* effect func naming

* name appendGfx funcs

* fix fx_66

* Add KMC wrapper to Jenkinsfile

* mac fixes

* fix macro usage

* oopz

* 3 fixes

* blah

* KMC_ASM

* config changes
2021-10-22 23:01:27 +09:00

67 lines
1.7 KiB
Python
Executable File

#!/usr/bin/env python3
import argparse
import os
import sys
import subprocess
from pathlib import Path
script_dir = os.path.dirname(os.path.realpath(__file__))
root_dir = os.path.abspath(os.path.join(script_dir, ".."))
src_dir = root_dir + "src/"
# Project-specific
CPP_FLAGS = [
"-Iinclude",
"-Isrc",
"-Iver/current/build/include",
"-D_LANGUAGE_C",
"-DF3DEX_GBI_2",
"-D_MIPS_SZLONG=32",
"-DSCRIPT(...)={}"
"-D__attribute__(...)=",
"-D__asm__(...)=",
"-ffreestanding",
]
def import_c_file(in_file) -> str:
in_file = os.path.relpath(in_file, root_dir)
cpp_command = ["gcc", "-E", "-P", "-dM", *CPP_FLAGS, in_file]
cpp_command2 = ["gcc", "-E", "-P", *CPP_FLAGS, in_file]
out_text = ""
try:
out_text += subprocess.check_output(cpp_command, cwd=root_dir, encoding="utf-8")
out_text += subprocess.check_output(cpp_command2, cwd=root_dir, encoding="utf-8")
except subprocess.CalledProcessError:
print(
"Failed to preprocess input file, when running command:\n"
+ cpp_command,
file=sys.stderr,
)
sys.exit(1)
if not out_text:
print("Output is empty - aborting")
sys.exit(1)
return out_text
def main():
parser = argparse.ArgumentParser(
description="""Create a context file which can be used for mips_to_c"""
)
parser.add_argument(
"c_file",
help="""File from which to create context""",
)
args = parser.parse_args()
output = import_c_file(args.c_file)
with open(os.path.join(root_dir, "ctx.c"), "w", encoding="UTF-8") as f:
f.write(output)
if __name__ == "__main__":
main()