mirror of
https://github.com/zeldaret/st
synced 2026-06-02 18:18:44 -04:00
update configure script
This commit is contained in:
+79
-65
@@ -26,9 +26,9 @@ args = parser.parse_args()
|
||||
|
||||
# Config
|
||||
GAME = "st"
|
||||
DSD_VERSION = 'v0.9.1'
|
||||
DSD_VERSION = 'v0.10.1'
|
||||
WIBO_VERSION = '0.6.16'
|
||||
OBJDIFF_VERSION = 'v2.7.1'
|
||||
OBJDIFF_VERSION = 'v3.0.0-beta.6'
|
||||
MWCC_VERSION = "2.0/sp2p4"
|
||||
DECOMP_ME_COMPILER = "mwcc_30_139" # TODO: verify
|
||||
CC_FLAGS = " ".join([
|
||||
@@ -164,10 +164,11 @@ class Project:
|
||||
return self.game_build / "build" / "rom_config.yaml"
|
||||
|
||||
def source_object_files(self) -> list[str]:
|
||||
return [
|
||||
str(self.game_build / source_file.with_suffix(".o"))
|
||||
for source_file in get_c_cpp_files([src_path, libs_path])
|
||||
]
|
||||
files: list[str] = []
|
||||
for source_file in get_c_cpp_files([src_path, libs_path]):
|
||||
src_obj_path = self.game_build / source_file
|
||||
files.append(str(src_obj_path.with_suffix(".o")))
|
||||
return files
|
||||
|
||||
def arm9_o(self) -> Path:
|
||||
return self.game_build / "arm9.o"
|
||||
@@ -178,28 +179,27 @@ class Project:
|
||||
def objdiff_report(self) -> Path:
|
||||
return self.game_build / "report.json"
|
||||
|
||||
def modules(self) -> list[Any]:
|
||||
def files(self) -> list[dict[str, str]]:
|
||||
if self.delinks_json is None:
|
||||
return []
|
||||
return self.delinks_json['modules']
|
||||
return self.delinks_json['files']
|
||||
|
||||
def delink_files(self) -> list[str]:
|
||||
if self.delinks_json is None:
|
||||
return []
|
||||
return [file['delink_file'] for module in self.delinks_json['modules'] for file in module['files']]
|
||||
delink_files = [file['delink_file'] for file in self.files()]
|
||||
return list(set(delink_files))
|
||||
|
||||
def arm9_lcf_file(self) -> str:
|
||||
if self.delinks_json is None:
|
||||
return ""
|
||||
return self.delinks_json['arm9_lcf_file']
|
||||
|
||||
def module_lcf_files(self) -> list[str]:
|
||||
def arm9_objects_file(self) -> str:
|
||||
if self.delinks_json is None:
|
||||
return []
|
||||
return [module['lcf_file'] for module in self.delinks_json['modules']]
|
||||
return ""
|
||||
return self.delinks_json['arm9_objects_file']
|
||||
|
||||
|
||||
def can_run_dsd() -> bool:
|
||||
def check_can_run_dsd() -> bool:
|
||||
try:
|
||||
output = subprocess.run([DSD, "--version"], capture_output=True, text=True, check=True)
|
||||
version = output.stdout.strip().split(" ")[-1]
|
||||
@@ -215,17 +215,22 @@ def can_run_dsd() -> bool:
|
||||
|
||||
|
||||
def main():
|
||||
if platform is None: return
|
||||
if platform is None:
|
||||
return
|
||||
|
||||
delinks_json = None
|
||||
if can_run_dsd():
|
||||
can_run_dsd = check_can_run_dsd()
|
||||
if can_run_dsd:
|
||||
out = subprocess.run([
|
||||
DSD,
|
||||
"--force-color",
|
||||
"json",
|
||||
"delinks",
|
||||
"--config-path", config_path / args.version / "arm9" / "config.yaml"
|
||||
], capture_output=True, text=True, check=True)
|
||||
], capture_output=True, text=True)
|
||||
if out.returncode != 0:
|
||||
print(f"Error running dsd:\n{out.stderr.strip()}")
|
||||
return
|
||||
delinks_json = json.loads(out.stdout)
|
||||
|
||||
project = Project(args.version, platform=platform, delinks_json=delinks_json)
|
||||
@@ -271,6 +276,8 @@ def main():
|
||||
transform_dep = "tools/transform_dep.py"
|
||||
mwcc_cmd += f" && $python {transform_dep} $basefile.d $basefile.d"
|
||||
mwcc_implicit.append(transform_dep)
|
||||
if WINE == DEFAULT_WIBO_PATH:
|
||||
mwcc_implicit.append(WINE)
|
||||
n.rule(
|
||||
name="mwcc",
|
||||
command=mwcc_cmd,
|
||||
@@ -286,7 +293,7 @@ def main():
|
||||
|
||||
n.rule(
|
||||
name="mwld",
|
||||
command=f'{WINE} "{LD}" {LD_FLAGS} $extra_ld_flags $in -o $out'
|
||||
command=f'{WINE} "{LD}" {LD_FLAGS} $extra_ld_flags @$objects_file $lcf_file -o $out'
|
||||
)
|
||||
n.newline()
|
||||
|
||||
@@ -353,21 +360,28 @@ def main():
|
||||
n.newline()
|
||||
|
||||
add_download_tool_builds(n, project)
|
||||
add_extract_build(n, project)
|
||||
add_delink_and_lcf_builds(n, project)
|
||||
add_disassemble_builds(n, project)
|
||||
add_mwcc_builds(n, project, mwcc_implicit)
|
||||
add_mwld_and_rom_builds(n, project)
|
||||
add_check_builds(n, project)
|
||||
add_objdiff_builds(n, project)
|
||||
add_configure_build(n, project)
|
||||
add_apply_build(n, project)
|
||||
|
||||
n.default(["objdiff", "check", "sha1"])
|
||||
if can_run_dsd:
|
||||
add_extract_build(n, project)
|
||||
add_delink_and_lcf_builds(n, project)
|
||||
add_disassemble_builds(n, project)
|
||||
add_mwcc_builds(n, project, mwcc_implicit)
|
||||
add_mwld_and_rom_builds(n, project)
|
||||
add_check_builds(n, project)
|
||||
add_objdiff_builds(n, project)
|
||||
add_apply_build(n, project)
|
||||
|
||||
n.default(["objdiff", "check", "sha1"])
|
||||
else:
|
||||
n.default(["download_tools"])
|
||||
|
||||
|
||||
def add_download_tool_builds(n: ninja_syntax.Writer, project: Project):
|
||||
downloads: list[str] = []
|
||||
|
||||
if args.dsd is None:
|
||||
downloads.append(DSD)
|
||||
n.build(
|
||||
rule="download_tool",
|
||||
outputs=DSD,
|
||||
@@ -379,6 +393,7 @@ def add_download_tool_builds(n: ninja_syntax.Writer, project: Project):
|
||||
)
|
||||
n.newline()
|
||||
|
||||
downloads.append(OBJDIFF)
|
||||
n.build(
|
||||
rule="download_tool",
|
||||
outputs=OBJDIFF,
|
||||
@@ -391,6 +406,7 @@ def add_download_tool_builds(n: ninja_syntax.Writer, project: Project):
|
||||
n.newline()
|
||||
|
||||
if args.compiler is None:
|
||||
downloads.extend([CC, LD])
|
||||
n.build(
|
||||
rule="download_tool",
|
||||
outputs=[CC, LD],
|
||||
@@ -403,6 +419,7 @@ def add_download_tool_builds(n: ninja_syntax.Writer, project: Project):
|
||||
n.newline()
|
||||
|
||||
if project.platform.system != "windows" and WINE == DEFAULT_WIBO_PATH:
|
||||
downloads.append(WINE)
|
||||
n.build(
|
||||
rule="download_tool",
|
||||
outputs=WINE,
|
||||
@@ -414,6 +431,13 @@ def add_download_tool_builds(n: ninja_syntax.Writer, project: Project):
|
||||
)
|
||||
n.newline()
|
||||
|
||||
n.build(
|
||||
inputs=downloads,
|
||||
rule="phony",
|
||||
outputs="download_tools",
|
||||
)
|
||||
n.newline
|
||||
|
||||
|
||||
def add_extract_build(n: ninja_syntax.Writer, project: Project):
|
||||
if not args.no_extract:
|
||||
@@ -430,34 +454,21 @@ def add_extract_build(n: ninja_syntax.Writer, project: Project):
|
||||
|
||||
|
||||
def add_mwld_and_rom_builds(n: ninja_syntax.Writer, project: Project):
|
||||
n.comment("Link each module separately")
|
||||
for module in project.modules():
|
||||
lcf_file = module['lcf_file']
|
||||
objects_to_link = [file['object_to_link'] for file in module['files']]
|
||||
elf_file = module['elf_file']
|
||||
n.build(
|
||||
inputs=objects_to_link + [lcf_file],
|
||||
implicit=LD,
|
||||
rule="mwld",
|
||||
outputs=elf_file,
|
||||
variables={
|
||||
'extra_ld_flags': MODULE_LD_FLAGS,
|
||||
}
|
||||
)
|
||||
n.newline()
|
||||
|
||||
n.comment("Link all modules together")
|
||||
module_elf_files = [module['elf_file'] for module in project.modules()]
|
||||
n.comment("Run linker")
|
||||
objects_to_link = [file['object_to_link'] for file in project.files()]
|
||||
elf_file = str(project.arm9_o())
|
||||
lcf_file = project.arm9_lcf_file()
|
||||
if len(module_elf_files) > 0:
|
||||
objects_file = project.arm9_objects_file()
|
||||
if len(objects_to_link) > 0:
|
||||
n.build(
|
||||
inputs=module_elf_files + [lcf_file],
|
||||
inputs=[*objects_to_link, lcf_file, objects_file],
|
||||
implicit=LD,
|
||||
rule="mwld",
|
||||
outputs=elf_file,
|
||||
variables={
|
||||
'extra_ld_flags': ARM9_LD_FLAGS,
|
||||
'lcf_file': str(lcf_file),
|
||||
'objects_file': str(objects_file),
|
||||
}
|
||||
)
|
||||
n.newline()
|
||||
@@ -512,8 +523,10 @@ def add_mwcc_builds(n: ninja_syntax.Writer, project: Project, mwcc_implicit: lis
|
||||
for source_file in get_c_cpp_files([src_path, libs_path]):
|
||||
src_obj_path = project.game_build / source_file
|
||||
cc_flags: list[str] = []
|
||||
if is_cpp(source_file): cc_flags.append("-lang=c++")
|
||||
elif is_c(source_file): cc_flags.append("-lang=c")
|
||||
if is_cpp(source_file):
|
||||
cc_flags.append("-lang=c++")
|
||||
elif is_c(source_file):
|
||||
cc_flags.append("-lang=c")
|
||||
n.build(
|
||||
inputs=str(source_file),
|
||||
implicit=mwcc_implicit,
|
||||
@@ -529,7 +542,7 @@ def add_mwcc_builds(n: ninja_syntax.Writer, project: Project, mwcc_implicit: lis
|
||||
n.newline()
|
||||
|
||||
extension = source_file.suffix
|
||||
ctx_file = str(project.game_build / source_file.with_suffix(f".ctx{extension}"))
|
||||
ctx_file = str(src_obj_path.with_suffix(f".ctx{extension}"))
|
||||
n.build(
|
||||
inputs=str(source_file),
|
||||
rule="m2ctx",
|
||||
@@ -578,18 +591,18 @@ def add_delink_and_lcf_builds(n: ninja_syntax.Writer, project: Project):
|
||||
)
|
||||
n.newline()
|
||||
|
||||
lcf_files = project.module_lcf_files() + [project.arm9_lcf_file()]
|
||||
if len(lcf_files) > 1:
|
||||
n.build(
|
||||
inputs=project.delinks_files + [str(rom_config)],
|
||||
implicit=DSD,
|
||||
rule="lcf",
|
||||
outputs=lcf_files,
|
||||
variables={
|
||||
"config_path": str(project.arm9_config_yaml()),
|
||||
}
|
||||
)
|
||||
n.newline()
|
||||
lcf_file = project.arm9_lcf_file()
|
||||
objects_file = project.arm9_objects_file()
|
||||
n.build(
|
||||
inputs=project.delinks_files + [str(rom_config)],
|
||||
implicit=DSD,
|
||||
rule="lcf",
|
||||
outputs=[lcf_file, objects_file],
|
||||
variables={
|
||||
"config_path": str(project.arm9_config_yaml()),
|
||||
}
|
||||
)
|
||||
n.newline()
|
||||
|
||||
|
||||
def add_disassemble_builds(n: ninja_syntax.Writer, project: Project):
|
||||
@@ -655,7 +668,7 @@ def add_objdiff_builds(n: ninja_syntax.Writer, project: Project):
|
||||
)
|
||||
n.newline()
|
||||
|
||||
delink_files = [file['delink_file'] for module in project.modules() for file in module['files']]
|
||||
delink_files = project.delink_files()
|
||||
n.build(
|
||||
inputs=["objdiff.json"],
|
||||
implicit=[OBJDIFF] + delink_files + project.source_object_files(),
|
||||
@@ -709,4 +722,5 @@ def get_config_files(game_config: Path, name: str) -> list[str]:
|
||||
]
|
||||
|
||||
|
||||
if __name__ == "__main__": main()
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user