mirror of
https://github.com/zeldaret/af.git
synced 2026-09-26 13:33:16 -04:00
fd05811213
* C file * trademark_init * trademark_cancel, trademark_move, trademark_main * trademark_draw * trademark_goto_demo_scene and func_80805360_jp * set_npc_4_title_demo * func_80804C40_jp * trademark_cleanup * func_808052B8_jp * func_80805104_jp * func_80804F78_jp * func_80804EE0_jp * fix warnings * small cleanup * fix build * some fixes * stuff * some cleanups * Fix rebase * Import data * Migrate bss * cleanup * Save substruct * format * TrademarkState and some other stuff * remove fake match * stuff I missed * whoops * Stupid `-Wtype-limits` * Update src/overlays/gamestates/ovl_trademark/m_trademark.c Co-authored-by: Prakxo <87568477+Prakxo@users.noreply.github.com> * Review * Update src/overlays/gamestates/ovl_trademark/m_trademark.c Co-authored-by: emilybrooks <emilybrooksemilybrooks@gmail.com> * Update src/overlays/gamestates/ovl_trademark/m_trademark.c Co-authored-by: Prakxo <87568477+Prakxo@users.noreply.github.com> * clang-tidy changes??? * review --------- Co-authored-by: Prakxo <87568477+Prakxo@users.noreply.github.com> Co-authored-by: emilybrooks <emilybrooksemilybrooks@gmail.com>
99 lines
2.4 KiB
Python
Executable File
99 lines
2.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import argparse
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
import tempfile
|
|
|
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
|
root_dir = os.path.abspath(os.path.join(script_dir, ".."))
|
|
|
|
# Project-specific
|
|
CPP_FLAGS = [
|
|
"-I.",
|
|
"-Iinclude",
|
|
"-Isrc",
|
|
"-Ibin",
|
|
"-Ibuild",
|
|
"-Ilib/ultralib/include",
|
|
"-Ilib/ultralib/include/PR",
|
|
"-Ilib/ultralib/include/ido",
|
|
|
|
"-D_LANGUAGE_C",
|
|
"-DF3DEX_GBI_2",
|
|
"-D__USE_ISOC99",
|
|
"-DNDEBUG",
|
|
"-D_FINALROM",
|
|
"-D_MIPS_SZLONG=32",
|
|
"-D__USE_ISOC99",
|
|
|
|
"-DM2CTX",
|
|
"-DCC_CHECK=1"
|
|
"-DNON_MATCHING",
|
|
|
|
"-ffreestanding",
|
|
"-std=gnu89",
|
|
]
|
|
|
|
def import_c_file(in_file) -> str:
|
|
in_file = os.path.relpath(in_file, root_dir)
|
|
|
|
cpp_command = ["gcc", "-E", "-P", "-dD", *CPP_FLAGS, in_file]
|
|
|
|
with tempfile.NamedTemporaryFile(suffix=".c") as tmp:
|
|
stock_macros = subprocess.check_output(["gcc", "-E", "-P", "-dM", tmp.name], cwd=root_dir, encoding="utf-8")
|
|
|
|
try:
|
|
out_text = subprocess.check_output(cpp_command, cwd=root_dir, encoding="utf-8")
|
|
except subprocess.CalledProcessError:
|
|
print(
|
|
"Failed to preprocess input file, when running command:\n"
|
|
+ " ".join(cpp_command),
|
|
file=sys.stderr,
|
|
)
|
|
sys.exit(1)
|
|
|
|
if not out_text:
|
|
print("Output is empty - aborting")
|
|
sys.exit(1)
|
|
|
|
defines = {}
|
|
source_lines = []
|
|
for line in out_text.splitlines(keepends=True):
|
|
if line.startswith("#define"):
|
|
sym = line.split()[1].split("(")[0]
|
|
defines[sym] = line
|
|
elif line.startswith("#undef"):
|
|
sym = line.split()[1]
|
|
if sym in defines:
|
|
del defines[sym]
|
|
else:
|
|
source_lines.append(line)
|
|
|
|
for line in stock_macros.strip().splitlines():
|
|
sym = line.split()[1].split("(")[0]
|
|
if sym in defines:
|
|
del defines[sym]
|
|
|
|
return "".join(defines.values()) + "".join(source_lines)
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(
|
|
description="""Create a context file which can be used for m2c / decomp.me"""
|
|
)
|
|
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()
|
|
|