mirror of
https://github.com/encounter/dtk-template.git
synced 2025-07-06 05:06:06 +00:00
Merge 89f689d68dcf9d972681720f912d9d36226e8ba6 into 04c8b45f9305cd2fa03d6eb7c63625b30cad1c11
This commit is contained in:
commit
09d8fba54f
2
.gitignore
vendored
2
.gitignore
vendored
@ -9,4 +9,4 @@ objdiff.json
|
|||||||
orig/*/*
|
orig/*/*
|
||||||
!orig/*/.gitkeep
|
!orig/*/.gitkeep
|
||||||
/*.txt
|
/*.txt
|
||||||
ctx.c
|
*.ctx
|
||||||
|
@ -13,8 +13,13 @@
|
|||||||
"files.insertFinalNewline": true,
|
"files.insertFinalNewline": true,
|
||||||
"files.trimFinalNewlines": true,
|
"files.trimFinalNewlines": true,
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
|
"*.c.ctx": "c",
|
||||||
|
"*.ctx": "cpp",
|
||||||
"*.inc": "cpp"
|
"*.inc": "cpp"
|
||||||
},
|
},
|
||||||
|
"files.exclude": {
|
||||||
|
"*.ctx": true
|
||||||
|
},
|
||||||
"search.useIgnoreFiles": false,
|
"search.useIgnoreFiles": false,
|
||||||
"search.exclude": {
|
"search.exclude": {
|
||||||
"build/*/config.json": true,
|
"build/*/config.json": true,
|
||||||
@ -23,4 +28,4 @@
|
|||||||
".ninja_*": true,
|
".ninja_*": true,
|
||||||
"objdiff.json": true
|
"objdiff.json": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
configure.py
13
configure.py
@ -27,7 +27,7 @@ from tools.project import (
|
|||||||
# Game versions
|
# Game versions
|
||||||
DEFAULT_VERSION = 0
|
DEFAULT_VERSION = 0
|
||||||
VERSIONS = [
|
VERSIONS = [
|
||||||
"GAMEID", # 0
|
"GAMEID", # 0
|
||||||
]
|
]
|
||||||
|
|
||||||
if len(VERSIONS) > 1:
|
if len(VERSIONS) > 1:
|
||||||
@ -67,6 +67,12 @@ parser.add_argument(
|
|||||||
action="store_true",
|
action="store_true",
|
||||||
help="generate map file(s)",
|
help="generate map file(s)",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--context",
|
||||||
|
dest="context",
|
||||||
|
action="store_true",
|
||||||
|
help="generate context file(s) for decomp.me",
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--debug",
|
"--debug",
|
||||||
dest="debug",
|
dest="debug",
|
||||||
@ -111,6 +117,7 @@ config.build_dir = args.build_dir
|
|||||||
config.build_dtk_path = args.build_dtk
|
config.build_dtk_path = args.build_dtk
|
||||||
config.compilers_path = args.compilers
|
config.compilers_path = args.compilers
|
||||||
config.debug = args.debug
|
config.debug = args.debug
|
||||||
|
config.generate_context = args.context
|
||||||
config.generate_map = args.map
|
config.generate_map = args.map
|
||||||
config.sjiswrap_path = args.sjiswrap
|
config.sjiswrap_path = args.sjiswrap
|
||||||
if not is_windows():
|
if not is_windows():
|
||||||
@ -150,7 +157,7 @@ cflags_base = [
|
|||||||
"-RTTI off",
|
"-RTTI off",
|
||||||
"-fp_contract on",
|
"-fp_contract on",
|
||||||
"-str reuse",
|
"-str reuse",
|
||||||
"-multibyte", # For Wii compilers, replace with `-enc SJIS`
|
"-multibyte", # For Wii compilers, replace with `-enc SJIS`
|
||||||
"-i include",
|
"-i include",
|
||||||
f"-i build/{config.version}/include",
|
f"-i build/{config.version}/include",
|
||||||
f"-DVERSION={version_num}",
|
f"-DVERSION={version_num}",
|
||||||
@ -169,7 +176,7 @@ cflags_runtime = [
|
|||||||
"-str reuse,pool,readonly",
|
"-str reuse,pool,readonly",
|
||||||
"-gccinc",
|
"-gccinc",
|
||||||
"-common off",
|
"-common off",
|
||||||
"-inline auto",
|
"-inline auto",
|
||||||
]
|
]
|
||||||
|
|
||||||
# REL flags
|
# REL flags
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
###
|
###
|
||||||
# Generates a ctx.c file, usable for "Context" on https://decomp.me.
|
# Generates a *.ctx file, usable for "Context" on https://decomp.me.
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# python3 tools/decompctx.py src/file.cpp
|
# python3 tools/decompctx.py src/file.cpp
|
||||||
@ -20,54 +20,61 @@ src_dir = os.path.join(root_dir, "src")
|
|||||||
include_dir = os.path.join(root_dir, "include")
|
include_dir = os.path.join(root_dir, "include")
|
||||||
|
|
||||||
include_pattern = re.compile(r'^#include\s*[<"](.+?)[>"]$')
|
include_pattern = re.compile(r'^#include\s*[<"](.+?)[>"]$')
|
||||||
guard_pattern = re.compile(r'^#ifndef\s+(.*)$')
|
guard_pattern = re.compile(r"^#ifndef\s+(.*)$")
|
||||||
|
|
||||||
|
defines = set[str]()
|
||||||
|
quiet = False
|
||||||
|
|
||||||
defines = set()
|
|
||||||
|
|
||||||
def import_h_file(in_file: str, r_path: str) -> str:
|
def import_h_file(in_file: str, r_path: str) -> str:
|
||||||
rel_path = os.path.join(root_dir, r_path, in_file)
|
rel_path = os.path.join(root_dir, r_path, in_file)
|
||||||
inc_path = os.path.join(include_dir, in_file)
|
inc_path = os.path.join(include_dir, in_file)
|
||||||
if os.path.exists(rel_path):
|
if os.path.exists(rel_path):
|
||||||
return import_c_file(rel_path)
|
return import_c_file(rel_path)
|
||||||
elif os.path.exists(inc_path):
|
elif os.path.exists(inc_path):
|
||||||
return import_c_file(inc_path)
|
return import_c_file(inc_path)
|
||||||
else:
|
else:
|
||||||
print("Failed to locate", in_file)
|
if not quiet:
|
||||||
exit(1)
|
print("Failed to locate", in_file)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
def import_c_file(in_file) -> str:
|
|
||||||
|
def import_c_file(in_file: str) -> str:
|
||||||
in_file = os.path.relpath(in_file, root_dir)
|
in_file = os.path.relpath(in_file, root_dir)
|
||||||
out_text = ''
|
out_text = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(in_file, encoding="utf-8") as file:
|
with open(in_file, encoding="utf-8") as file:
|
||||||
out_text += process_file(in_file, list(file))
|
out_text += process_file(in_file, list(file))
|
||||||
except Exception:
|
except Exception:
|
||||||
with open(in_file) as file:
|
with open(in_file) as file:
|
||||||
out_text += process_file(in_file, list(file))
|
out_text += process_file(in_file, list(file))
|
||||||
return out_text
|
return out_text
|
||||||
|
|
||||||
def process_file(in_file: str, lines) -> str:
|
|
||||||
out_text = ''
|
def process_file(in_file: str, lines: list[str]) -> str:
|
||||||
|
out_text = ""
|
||||||
for idx, line in enumerate(lines):
|
for idx, line in enumerate(lines):
|
||||||
guard_match = guard_pattern.match(line.strip())
|
guard_match = guard_pattern.match(line.strip())
|
||||||
if idx == 0:
|
if idx == 0:
|
||||||
if guard_match:
|
if guard_match:
|
||||||
if guard_match[1] in defines:
|
if guard_match[1] in defines:
|
||||||
break
|
break
|
||||||
defines.add(guard_match[1])
|
defines.add(guard_match[1])
|
||||||
print("Processing file", in_file)
|
if not quiet:
|
||||||
include_match = include_pattern.match(line.strip())
|
print("Processing file", in_file)
|
||||||
if include_match and not include_match[1].endswith(".s"):
|
include_match = include_pattern.match(line.strip())
|
||||||
out_text += f"/* \"{in_file}\" line {idx} \"{include_match[1]}\" */\n"
|
if include_match and not include_match[1].endswith(".s"):
|
||||||
out_text += import_h_file(include_match[1], os.path.dirname(in_file))
|
out_text += f'/* "{in_file}" line {idx} "{include_match[1]}" */\n'
|
||||||
out_text += f"/* end \"{include_match[1]}\" */\n"
|
out_text += import_h_file(include_match[1], os.path.dirname(in_file))
|
||||||
else:
|
out_text += f'/* end "{include_match[1]}" */\n'
|
||||||
out_text += line
|
else:
|
||||||
|
out_text += line
|
||||||
|
|
||||||
return out_text
|
return out_text
|
||||||
|
|
||||||
def main():
|
|
||||||
|
def main() -> None:
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="""Create a context file which can be used for decomp.me"""
|
description="""Create a context file which can be used for decomp.me"""
|
||||||
)
|
)
|
||||||
@ -75,12 +82,27 @@ def main():
|
|||||||
"c_file",
|
"c_file",
|
||||||
help="""File from which to create context""",
|
help="""File from which to create context""",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--relative",
|
||||||
|
dest="relative",
|
||||||
|
help="Extract context relative to the source file",
|
||||||
|
action="store_true",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--quiet", dest="quiet", help="Don't print anything", action="store_true"
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
output = import_c_file(args.c_file)
|
global quiet
|
||||||
|
quiet = args.quiet
|
||||||
|
c_file = args.c_file
|
||||||
|
content = import_c_file(c_file)
|
||||||
|
filename = (
|
||||||
|
f"{c_file}.ctx" if args.relative else os.path.join(root_dir, "context.ctx")
|
||||||
|
)
|
||||||
|
|
||||||
with open(os.path.join(root_dir, "ctx.c"), "w", encoding="utf-8") as f:
|
with open(filename, "w", encoding="utf-8") as f:
|
||||||
f.write(output)
|
f.write(content)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -50,6 +50,7 @@ class ProjectConfig:
|
|||||||
self.check_sha_path = None # Path to version.sha1
|
self.check_sha_path = None # Path to version.sha1
|
||||||
self.config_path = None # Path to config.yml
|
self.config_path = None # Path to config.yml
|
||||||
self.debug = False # Build with debug info
|
self.debug = False # Build with debug info
|
||||||
|
self.generate_context = False # Generate .ctx file(s)
|
||||||
self.generate_map = False # Generate map file(s)
|
self.generate_map = False # Generate map file(s)
|
||||||
self.ldflags = None # Linker flags
|
self.ldflags = None # Linker flags
|
||||||
self.libs = None # List of libraries
|
self.libs = None # List of libraries
|
||||||
@ -340,6 +341,10 @@ def generate_build_ninja(config, build_config):
|
|||||||
mwcc_implicit.append(transform_dep)
|
mwcc_implicit.append(transform_dep)
|
||||||
mwcc_sjis_implicit.append(transform_dep)
|
mwcc_sjis_implicit.append(transform_dep)
|
||||||
|
|
||||||
|
if config.generate_context:
|
||||||
|
mwcc_cmd += f" && $python tools/decompctx.py $in --relative --quiet"
|
||||||
|
mwcc_sjis_cmd += f" && $python tools/decompctx.py $in --relative --quiet"
|
||||||
|
|
||||||
n.comment("Link ELF file")
|
n.comment("Link ELF file")
|
||||||
n.rule(
|
n.rule(
|
||||||
name="link",
|
name="link",
|
||||||
@ -567,6 +572,9 @@ def generate_build_ninja(config, build_config):
|
|||||||
implicit=path(
|
implicit=path(
|
||||||
mwcc_sjis_implicit if options["shiftjis"] else mwcc_implicit
|
mwcc_sjis_implicit if options["shiftjis"] else mwcc_implicit
|
||||||
),
|
),
|
||||||
|
implicit_outputs=None
|
||||||
|
if not config.generate_context
|
||||||
|
else str(unit_src_path) + ".ctx",
|
||||||
)
|
)
|
||||||
|
|
||||||
if lib["host"]:
|
if lib["host"]:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user