Merge pull request #241 from Jcw87/makefile_header_deps

Add header dependencies to Makefiles
This commit is contained in:
TakaRikka
2023-01-13 22:53:05 -08:00
committed by GitHub
810 changed files with 7346 additions and 1634 deletions
+1
View File
@@ -12,6 +12,7 @@ from pathlib import Path
try:
import click
import libdol2asm
import libdol2asm.util
except ImportError as e:
MISSING_PREREQUISITES = (
f"Missing prerequisite python module {e}.\n"
+1
View File
@@ -1613,6 +1613,7 @@ LIBRARY_LUT = [
("db", "dolphin/"),
("dsp", "dolphin/"),
("dvd", "dolphin/"),
("exi", "dolphin/"),
("gd", "dolphin/"),
("gf", "dolphin/"),
("gx", "dolphin/"),
+1 -2
View File
@@ -1,8 +1,7 @@
from dataclasses import dataclass, field
from capstone import *
from capstone.ppc import *
from capstone.ppc import PPC_REG_R3
from ...builder import AsyncBuilder
from ...types import *
+34 -18
View File
@@ -1,4 +1,4 @@
from pathlib import Path
from pathlib import Path, PurePosixPath
from .. import util
from ..globals import *
@@ -8,7 +8,7 @@ from ..builder import AsyncBuilder
async def create_library(library: Library):
assert library.name
lib_path = library.makefile_path
cpp_path = library.source_path
cpp_path = PurePosixPath(library.source_path)
o_path = f"$(BUILD_DIR)/{cpp_path}"
makefile_path = lib_path.joinpath("Makefile")
@@ -30,7 +30,7 @@ async def create_library(library: Library):
if tu.is_empty:
continue
await builder.write(f"\t{tu.source_path(library)} \\")
await builder.write(f"\t{PurePosixPath(tu.source_path(library))} \\")
await builder.write("")
await builder.write(f"{prefix}_O_FILES := \\")
@@ -38,7 +38,7 @@ async def create_library(library: Library):
if tu.is_empty:
continue
await builder.write(f"\t$(BUILD_DIR)/{tu.object_path(library)} \\")
await builder.write(f"\t$(BUILD_DIR)/{PurePosixPath(tu.object_path(library))} \\")
await builder.write("")
await builder.write(f"{prefix}_CFLAGS := \\")
@@ -58,11 +58,19 @@ async def create_library(library: Library):
#await builder.write(f"\t@$(STRIP) -d -R .dead -R .comment {target_path}")
await builder.write("")
await builder.write(f"{o_path}/%.o: {cpp_path}/%.cpp")
await builder.write(f"{o_path}/%.o: {cpp_path}/%.cpp {o_path}/%.d")
await builder.write(f"\t@mkdir -p $(@D)")
await builder.write(f"\t@echo building... $<")
await builder.write(f"\t@iconv -f UTF-8 -t CP932 < $< > $@.iconv.cpp")
await builder.write(f"\t@$(CC) $(CFLAGS) $({prefix}_CFLAGS) -c -o $@ $@.iconv.cpp")
await builder.write(f"\t@$(ICONV) -f UTF-8 -t CP932 < $< > $(basename $@).cpp")
await builder.write(f"\t@$(CC) $(CFLAGS) $({prefix}_CFLAGS) $(DEPFLAGS) -c -o $(dir $@) $(basename $@).cpp")
await builder.write("\t@if [ -z '$(DISABLE_DEPS)' ]; then tools/transform-dep.py '$(basename $@).d' '$(basename $@).d'; touch -c $@; fi")
await builder.write("")
await builder.write("ifndef DISABLE_DEPS")
await builder.write(f"{prefix}_D_FILES := $({prefix}_O_FILES:.o=.d)")
await builder.write(f"$({prefix}_D_FILES):")
await builder.write(f"include $(wildcard $({prefix}_D_FILES))")
await builder.write("endif")
await builder.write("")
debug(f"generated Makefile: '{makefile_path}'")
@@ -73,7 +81,7 @@ async def create_rel(module: Module, rel_path: Path):
prefix = f"m{module.index}".upper()
lib_path = base.makefile_path
cpp_path = base.source_path
cpp_path = PurePosixPath(base.source_path)
o_path = f"$(BUILD_DIR)/{cpp_path}"
makefile_path = lib_path.joinpath("Makefile")
@@ -101,9 +109,9 @@ async def create_rel(module: Module, rel_path: Path):
if tu.is_empty:
continue
if tu.special == "rel":
await builder.write(f"\t{rel_path.joinpath(tu.name)}.cpp \\")
await builder.write(f"\t{PurePosixPath(rel_path.joinpath(tu.name))}.cpp \\")
else:
await builder.write(f"\t{tu.source_path(base)} \\")
await builder.write(f"\t{PurePosixPath(tu.source_path(base))} \\")
await builder.write("")
await builder.write(f"{prefix}_O_FILES := \\")
@@ -111,9 +119,9 @@ async def create_rel(module: Module, rel_path: Path):
if tu.is_empty:
continue
if tu.special == "rel":
await builder.write(f"\t$(BUILD_DIR)/{rel_path.joinpath(tu.name)}.o \\")
await builder.write(f"\t$(BUILD_DIR)/{PurePosixPath(rel_path.joinpath(tu.name))}.o \\")
else:
await builder.write(f"\t$(BUILD_DIR)/{tu.object_path(base)} \\")
await builder.write(f"\t$(BUILD_DIR)/{PurePosixPath(tu.object_path(base))} \\")
await builder.write("")
await builder.write(f"{prefix}_LIBS := \\")
@@ -146,11 +154,19 @@ async def create_rel(module: Module, rel_path: Path):
await builder.write(f"\t@$(LD) -opt_partial -strip_partial $({prefix}_LDFLAGS) -o $({prefix}_TARGET) @{input_file}")
await builder.write("")
await builder.write(f"{o_path}/%.o: {cpp_path}/%.cpp")
await builder.write(f"{o_path}/%.o: {cpp_path}/%.cpp {o_path}/%.d")
await builder.write(f"\t@echo [{module.index:>3}] building $@")
await builder.write(f"\t@mkdir -p $(@D)")
await builder.write(f"\t@iconv -f UTF-8 -t CP932 < $< > $@.iconv.cpp")
await builder.write(f"\t@$(CC) $(CFLAGS) $({prefix}_CFLAGS) -c -o $@ $@.iconv.cpp")
await builder.write(f"\t@$(ICONV) -f UTF-8 -t CP932 < $< > $(basename $@).cpp")
await builder.write(f"\t@$(CC) $(CFLAGS) $({prefix}_CFLAGS) $(DEPFLAGS) -c -o $(dir $@) $(basename $@).cpp")
await builder.write("\t@if [ -z '$(DISABLE_DEPS)' ]; then tools/transform-dep.py '$(basename $@).d' '$(basename $@).d'; touch -c $@; fi")
await builder.write("")
await builder.write("ifndef DISABLE_DEPS")
await builder.write(f"{prefix}_D_FILES := $({prefix}_O_FILES:.o=.d)")
await builder.write(f"$({prefix}_D_FILES):")
await builder.write(f"include $(wildcard $({prefix}_D_FILES))")
await builder.write("endif")
await builder.write("")
for library in libraries[1:]:
@@ -250,7 +266,7 @@ async def create_obj_files(modules: Module):
if tu.is_empty:
continue
await builder.write(f"\t$(BUILD_DIR)/{tu.object_path(base)} \\")
await builder.write(f"\t$(BUILD_DIR)/{PurePosixPath(tu.object_path(base))} \\")
await builder.write("")
await builder.write(f"LIBS := \\")
@@ -288,7 +304,7 @@ async def create_include_link(modules: Module):
if name == None:
continue
target = lib.makefile_path.joinpath('Makefile')
target = PurePosixPath(lib.makefile_path.joinpath('Makefile'))
await builder.write(f"-include {target}")
await builder.write("")
@@ -297,7 +313,7 @@ async def create_include_link(modules: Module):
if module.index == 0:
continue
target = module.base_library.makefile_path.joinpath('Makefile')
target = PurePosixPath(module.base_library.makefile_path.joinpath('Makefile'))
await builder.write(f"-include {target}")
await builder.write("")
+1
View File
@@ -1613,6 +1613,7 @@ LIBRARY_LUT = [
("db", "dolphin/"),
("dsp", "dolphin/"),
("dvd", "dolphin/"),
("exi", "dolphin/"),
("gd", "dolphin/"),
("gf", "dolphin/"),
("gx", "dolphin/"),
+7 -5
View File
@@ -61,6 +61,8 @@ class Dol2AsmSplitter:
select_tu, select_asm):
self.debug_logging = debug_logging
self.game_path = game_path
self.files_path = game_path / "files"
self.sys_path = game_path / "sys"
self.lib_path = lib_path
self.src_path = src_path
self.asm_path = asm_path
@@ -88,15 +90,15 @@ class Dol2AsmSplitter:
fatal_exit()
# check if the 'main.dol' and 'frameworkF.map' exists
self.baserom_path = util.check_file(self.game_path, "main.dol")
self.baserom_path = util.check_file(self.sys_path, "main.dol")
self.framework_path = util.check_file(
self.game_path, "map/Final/Release/frameworkF.map")
self.files_path , "map/Final/Release/frameworkF.map")
info(f"found 'main.dol' at '{self.baserom_path}'")
info(f"found 'frameworkF.map' at '{self.framework_path}'")
# search for '.map' files
self.map_path = util.check_dir(self.game_path, "map/Final/Release")
self.map_path = util.check_dir(self.files_path, "map/Final/Release")
self.maps_path = [
x
for x in util.get_files_with_ext(self.map_path, ".map")
@@ -105,9 +107,9 @@ class Dol2AsmSplitter:
info(f"found {len(self.maps_path)} map files in '{self.map_path}'")
# search for '.rel' files
self._rel_path = util.check_dir(self.game_path, "rel/Final/Release")
self._rel_path = util.check_dir(self.files_path, "rel/Final/Release")
self.rels_path = util.get_files_with_ext(self._rel_path, ".rel")
self.rels_archive_path = util.check_file(self.game_path, "RELS.arc")
self.rels_archive_path = util.check_file(self.files_path, "RELS.arc")
info(f"found {len(self.rels_path)} RELs in '{self._rel_path}'")
def read_dol(self):
+69
View File
@@ -0,0 +1,69 @@
#!/usr/bin/env python3
# borrowed from prime-decomp
import argparse
import os
from platform import uname
if os.name != 'nt':
wineprefix = os.environ.get('WINEPREFIX', os.path.join(os.environ['HOME'], '.wine'))
winedevices = os.path.join(wineprefix, 'dosdevices')
def in_wsl() -> bool:
return 'microsoft-standard' in uname().release
def import_d_file(in_file) -> str:
out_lines = []
with open(in_file) as file:
for idx, line in enumerate(file):
if idx == 0:
if line.endswith(' \\\n'):
out_lines.append(line[:-3].replace('\\', '/') + " \\\n")
else:
out_lines.append(line.replace('\\', '/'))
else:
suffix = ''
if line.endswith(' \\\n'):
suffix = ' \\'
path = line.lstrip()[:-3]
else:
path = line.strip()
# lowercase drive letter
path = path[0].lower() + path[1:]
if os.name == 'nt':
path = path.replace('\\', '/')
elif path[0] == 'z':
# shortcut for z:
path = path[2:].replace('\\', '/')
elif in_wsl():
path = path[0:1] + path[2:]
path = os.path.join('/mnt', path.replace('\\', '/'))
else:
# use $WINEPREFIX/dosdevices to resolve path
path = os.path.realpath(os.path.join(winedevices, path.replace('\\', '/')))
out_lines.append(f"\t{path}{suffix}\n")
return ''.join(out_lines)
def main():
parser = argparse.ArgumentParser(
description="""Transform a .d file from Wine paths to normal paths"""
)
parser.add_argument(
"d_file",
help="""Dependency file in""",
)
parser.add_argument(
"d_file_out",
help="""Dependency file out""",
)
args = parser.parse_args()
output = import_d_file(args.d_file)
with open(args.d_file_out, "w", encoding="UTF-8") as f:
f.write(output)
if __name__ == "__main__":
main()