-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure.py
More file actions
81 lines (66 loc) · 2.64 KB
/
Copy pathconfigure.py
File metadata and controls
81 lines (66 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""Generate build.ninja: compile every src/*.cpp with VC6 and link into one DLL
for reccmp to diff against orig/gamemd.exe.
Uses /Z7 (debug info embedded per-object) rather than /Zi (external per-TU PDB) --
135 cl.exe invocations running in parallel under ninja would otherwise be writing
to shared PDB state, a known VC6 stability problem. /Z7 avoids any cross-process
sharing during compilation; link.exe then assembles one final PDB from the
embedded info via /DEBUG.
Flags (/O2 /Ob1) are the ones validated in tools/smoketest/GetProgress.cpp to
reproduce the original compiler's output exactly -- see docs/compiler.md.
Usage: python configure.py
Then: <ninja path from config/paths.json> -f build.ninja
"""
import json
import pathlib
REPO_ROOT = pathlib.Path(__file__).resolve().parent
SRC_DIR = REPO_ROOT / "src"
BUILD_DIR = REPO_ROOT / "build"
PATHS = json.loads((REPO_ROOT / "config" / "paths.json").read_text())
VC6_BIN = PATHS["vc6_bin"]
VC6_LIB = PATHS["vc6_lib"]
VC6_INCLUDE = PATHS["vc6_include"]
CL_EXE = f"{VC6_BIN}\\CL.EXE"
LINK_EXE = f"{VC6_BIN}\\LINK.EXE"
MSPDB_BIN = str(pathlib.Path(PATHS["vc6_bin"]).parent.parent / "Common" / "MSDev98" / "Bin")
CL_FLAGS = f'/nologo /c /O2 /Ob1 /Z7 /I"{VC6_INCLUDE}"'
LINK_FLAGS = "/nologo /DLL /DEBUG"
def main() -> None:
cpp_files = sorted(SRC_DIR.glob("*.cpp"))
if not cpp_files:
print("no .cpp files in src/ -- run tools/gen_stubs.py first")
return
BUILD_DIR.mkdir(exist_ok=True)
(BUILD_DIR / "obj").mkdir(exist_ok=True)
lines = [
f"cl = {CL_EXE}",
f"link = {LINK_EXE}",
f"path_prefix = {VC6_BIN};{MSPDB_BIN}",
f"lib = {VC6_LIB}",
"",
"rule cl",
" command = cmd /c \"set PATH=$path_prefix;%PATH% && $cl " + CL_FLAGS + " /Fo$out $in\"",
" description = CL $in",
"",
"rule link",
" command = cmd /c \"set PATH=$path_prefix;%PATH% && $link "
+ LINK_FLAGS + " /LIBPATH:$lib /OUT:$out /PDB:$pdb $in\"",
" description = LINK $out",
"",
]
objs = []
for cpp in cpp_files:
obj = f"build/obj/{cpp.stem}.obj"
objs.append(obj)
lines.append(f"build {obj}: cl {cpp.relative_to(REPO_ROOT).as_posix()}")
lines.append("")
lines.append(
"build build/gamemd_recomp.dll: link " + " ".join(objs)
)
lines.append(" pdb = build/gamemd_recomp.pdb")
lines.append("")
lines.append("default build/gamemd_recomp.dll")
lines.append("")
(REPO_ROOT / "build.ninja").write_text("\n".join(lines), encoding="utf-8")
print(f"wrote build.ninja: {len(cpp_files)} TUs -> build/gamemd_recomp.dll")
if __name__ == "__main__":
main()