MCPcopy Create free account
hub / github.com/doldecomp/mkdd / LinkStep

Class LinkStep

tools/project.py:876–957  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

874 return path.parent / (path.name + ".MAP")
875
876 class LinkStep:
877 def __init__(self, config: BuildConfigModule) -> None:
878 self.name = config["name"]
879 self.module_id = config["module_id"]
880 self.ldscript: Optional[Path] = Path(config["ldscript"])
881 self.entry = config["entry"]
882 self.inputs: List[str] = []
883
884 def add(self, obj: Path) -> None:
885 self.inputs.append(serialize_path(obj))
886
887 def output(self) -> Path:
888 if self.module_id == 0:
889 return build_path / f"{self.name}.dol"
890 else:
891 return build_path / self.name / f"{self.name}.rel"
892
893 def partial_output(self) -> Path:
894 if self.module_id == 0:
895 return build_path / f"{self.name}.elf"
896 else:
897 return build_path / self.name / f"{self.name}.plf"
898
899 def write(self, n: ninja_syntax.Writer) -> None:
900 n.comment(f"Link {self.name}")
901 if self.module_id == 0:
902 elf_path = build_path / f"{self.name}.elf"
903 elf_ldflags = f"$ldflags -lcf {serialize_path(self.ldscript)}"
904 if config.generate_map:
905 elf_map = map_path(elf_path)
906 elf_ldflags += f" -map {serialize_path(elf_map)}"
907 else:
908 elf_map = None
909 n.build(
910 outputs=elf_path,
911 rule="link",
912 inputs=self.inputs,
913 implicit=[
914 self.ldscript,
915 *mwld_implicit,
916 ],
917 implicit_outputs=elf_map,
918 variables={"ldflags": elf_ldflags},
919 order_only="post-compile",
920 )
921 else:
922 preplf_path = build_path / self.name / f"{self.name}.preplf"
923 plf_path = build_path / self.name / f"{self.name}.plf"
924 preplf_ldflags = "$ldflags -sdata 0 -sdata2 0 -r"
925 plf_ldflags = f"$ldflags -sdata 0 -sdata2 0 -r1 -lcf {serialize_path(self.ldscript)}"
926 if self.entry:
927 plf_ldflags += f" -m {self.entry}"
928 # -strip_partial is only valid with -m
929 if config.rel_strip_partial:
930 plf_ldflags += " -strip_partial"
931 if config.generate_map:
932 preplf_map = map_path(preplf_path)
933 preplf_ldflags += f" -map {serialize_path(preplf_map)}"

Callers 1

generate_build_ninjaFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected