summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAetias <144526980+AetiasHax@users.noreply.github.com>2024-05-03 15:44:52 +0200
committerGitHub <noreply@github.com>2024-05-03 15:44:52 +0200
commitb3edffce212962aeec3d313fb8ba46c203fa0b20 (patch)
treedb39ef633dd5e597b96f3b1726dd647a570e5a44 /tools
parent5c08baf1c24e50891ea12e8dcd0038c935875631 (diff)
parent0538f141fda58bf09f2da841f2dadadb8696cdf4 (diff)
Merge pull request #42 from AetiasHax/fix-build
Update compiler flags and decompiling docs
Diffstat (limited to 'tools')
-rw-r--r--tools/lcf.py6
-rwxr-xr-xtools/m2ctx.py81
2 files changed, 26 insertions, 61 deletions
diff --git a/tools/lcf.py b/tools/lcf.py
index 7122d656..f0fc74d8 100644
--- a/tools/lcf.py
+++ b/tools/lcf.py
@@ -13,8 +13,8 @@ def name(path: str): return path.split("/")[-1]
ARM9_OBJECTS = [
'asm/main/main_02000000.s',
- 'asm/main/Actor/ActorType.s',
'src/Main/Actor/ActorType.cpp',
+ 'asm/main/Actor/ActorType.s',
'asm/main/main_0203e8a0.s',
@@ -86,13 +86,13 @@ ov00 = Overlay(name='ov00', after='ARM9', objects=[
'asm/ov00/ov00_020b1498.s',
- 'asm/ov00/Actor/Actor.s',
'src/00_Core/Actor/Actor.cpp',
+ 'asm/ov00/Actor/Actor.s',
'asm/ov00/ov00_020c3348.s',
- 'asm/ov00/Actor/ActorManager.s',
'src/00_Core/Actor/ActorManager.cpp',
+ 'asm/ov00/Actor/ActorManager.s',
'asm/ov00/ov00_020c3e54.s',
])
diff --git a/tools/m2ctx.py b/tools/m2ctx.py
index 71562c0a..7bb5885a 100755
--- a/tools/m2ctx.py
+++ b/tools/m2ctx.py
@@ -5,6 +5,15 @@ import pyperclip
import subprocess
import os
from pathlib import Path
+import argparse
+
+parser = argparse.ArgumentParser(description="Generates a context for decomp.me")
+parser.add_argument('file', help="Input file to preprocess")
+parser.add_argument('-f', type=str, dest='out_file', required=False, help='Output context file')
+parser.add_argument('-c', action=argparse.BooleanOptionalAction, dest='clipboard', required=False, help='Copy output to clipboard')
+parser.add_argument('-e', type=str, dest='encoding', required=False, default="Shift-JIS", help='Input file encoding')
+parser.add_argument('-v', action=argparse.BooleanOptionalAction, dest='verbose', required=False, help='Verbose error output')
+args = parser.parse_args()
CXX_FLAGS = [
'-nostdinc',
@@ -15,63 +24,19 @@ CXX_FLAGS = [
script_dir = Path(os.path.dirname(os.path.realpath(__file__)))
root_dir = script_dir / ".."
-program = os.path.basename(sys.argv[0])
-
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
-def print_usage():
- eprint(f"Usage: {program} INFILE [-f OUTFILE] [-c] [-e ENCODING] [-v]")
- eprint(" INFILE \tInput file to preprocess")
- eprint(" -f OUTFILE \tOutput context file")
- eprint(" -c \tCopy output to clipboard")
- eprint(" -e ENCODING\tInput file encoding (Default: Shift-JIS)")
- eprint(" -v \tVerbose error output")
-
-if len(sys.argv) == 1:
- print_usage()
- exit(1)
-
-
-in_file = None
-out_file = None
-clipboard = False
-encoding = "Shift-JIS"
-verbose = False
-i = 1
-while i < len(sys.argv):
- arg = sys.argv[i]
- if arg == "-f":
- i += 1
- if i >= len(sys.argv):
- eprint("Expected output file after -f")
- exit(1)
- out_file = sys.argv[i]
- elif arg == "-c":
- clipboard = True
- elif arg == "-e":
- i += 1
- if i >= len(sys.argv):
- eprint("Expected input file encoding after -e")
- exit(1)
- encoding = sys.argv[i]
- elif arg == "-v":
- verbose = True
- elif arg.startswith("-"):
- eprint(f"Unknown option '{arg}'")
- elif in_file is None:
- in_file = arg
- else:
- eprint(f"Duplicate input file '{arg}'")
- exit(1)
- i += 1
-
-
try:
- ctx: str = 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', '-fworking-directory', '-undef', '-dD',
+ *CXX_FLAGS,
+ args.file
+ ], cwd=root_dir, encoding=args.encoding)
except subprocess.CalledProcessError as e:
- eprint(f"Failed to preprocess '{in_file}'")
- if verbose: eprint(e)
+ eprint(f"Failed to preprocess '{args.file}'")
+ if args.verbose: eprint(e)
else: eprint("Use -v for more verbose error output")
exit(1)
@@ -85,17 +50,17 @@ for i in reversed(range(len(lines))):
ctx = ''.join(lines)
-if out_file:
+if args.out_file:
try:
- with open(out_file, "w") as file:
+ with open(args.out_file, "w") as file:
file.write(ctx)
except OSError as e:
- eprint(f"Failed to write file '{out_file}'")
- if verbose: eprint(e)
+ eprint(f"Failed to write file '{args.out_file}'")
+ if args.verbose: eprint(e)
else: eprint("Use -v for more verbose error output")
exit(1)
-if clipboard:
+if args.clipboard:
pyperclip.copy(ctx)
eprint("Copied context to clipboard")
-if out_file is None and not clipboard:
+if args.out_file is None and not args.clipboard:
print(ctx)