This repository was archived by the owner on Jul 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure.py
More file actions
executable file
·468 lines (410 loc) · 12.3 KB
/
Copy pathconfigure.py
File metadata and controls
executable file
·468 lines (410 loc) · 12.3 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
#!/usr/bin/env python3
###
# Generates build files for the project.
# This file also includes the project configuration,
# such as compiler flags and the object matching status.
#
# Usage:
# python3 configure.py
# ninja
#
# Append --help to see available options.
###
import argparse
import sys
import os
import glob
import shutil
import subprocess
from pathlib import Path
from typing import Any, Dict, List, Tuple
from tools.custom.rsodec import rsodec
from tools.project import (
Object,
ProgressCategory,
ProjectConfig,
calculate_progress,
generate_build,
is_windows,
)
# Game versions
DEFAULT_VERSION = 0
VERSIONS = [
"SGVEAF_D", # USA Debug Proto
"SGVEAF", # USA Release
"SGVPAF", # Europe Release
"SGVJAF", # Japan Release
]
parser = argparse.ArgumentParser()
parser.add_argument(
"mode",
choices=["configure", "progress"],
default="configure",
help="script mode (default: configure)",
nargs="?",
)
parser.add_argument(
"-v",
"--version",
choices=VERSIONS,
type=str.upper,
default=VERSIONS[DEFAULT_VERSION],
help="version to build",
)
parser.add_argument(
"--build-dir",
metavar="DIR",
type=Path,
default=Path("build"),
help="base build directory (default: build)",
)
parser.add_argument(
"--binutils",
metavar="BINARY",
type=Path,
help="path to binutils (optional)",
)
parser.add_argument(
"--compilers",
metavar="DIR",
type=Path,
help="path to compilers (optional)",
)
parser.add_argument(
"--map",
action="store_true",
help="generate map file(s)",
)
parser.add_argument(
"--debug",
action="store_true",
help="build with debug info (non-matching)",
)
if not is_windows():
parser.add_argument(
"--wrapper",
metavar="BINARY",
type=Path,
help="path to wibo or wine (optional)",
)
parser.add_argument(
"--dtk",
metavar="BINARY | DIR",
type=Path,
help="path to decomp-toolkit binary or source (optional)",
)
parser.add_argument(
"--objdiff",
metavar="BINARY | DIR",
type=Path,
help="path to objdiff-cli binary or source (optional)",
)
parser.add_argument(
"--sjiswrap",
metavar="EXE",
type=Path,
help="path to sjiswrap.exe (optional)",
)
parser.add_argument(
"--verbose",
action="store_true",
help="print verbose output",
)
parser.add_argument(
"--non-matching",
dest="non_matching",
action="store_true",
help="builds equivalent (but non-matching) or modded objects",
)
parser.add_argument(
"--no-progress",
dest="progress",
action="store_false",
help="disable progress calculation",
)
parser.add_argument(
"--action",
dest="action",
action="store_false",
help="specifies CI action build, do not use manually.",
)
args = parser.parse_args()
config = ProjectConfig()
config.version = str(args.version)
version_num = VERSIONS.index(config.version)
# Apply arguments
config.build_dir = args.build_dir
config.dtk_path = args.dtk
config.objdiff_path = args.objdiff
config.binutils_path = args.binutils
config.compilers_path = args.compilers
config.generate_map = args.map
config.non_matching = args.non_matching
config.sjiswrap_path = args.sjiswrap
config.progress = args.progress
if not is_windows():
config.wrapper = args.wrapper
# Don't build asm unless we're --non-matching
if not config.non_matching:
config.asm_dir = None
# Tool versions
config.binutils_tag = "2.42-1"
config.compilers_tag = "latest"
config.dtk_tag = "v1.5.1"
config.objdiff_tag = "v3.0.0-beta.8"
config.sjiswrap_tag = "v1.2.1"
config.wibo_tag = "0.6.16"
# Project
## Helper (Guess who generated this)
def cflags_paths_expand(cflags):
seen = set()
converted = []
for flag in cflags:
if flag.startswith("-i "):
path = flag[3:]
if any(c in path for c in "*?[]"):
matches = glob.glob(path, recursive=True)
for p in matches:
norm_path = os.path.normpath(p)
flag_str = f"-i {norm_path}"
if os.path.isdir(p) and flag_str not in seen:
converted.append(flag_str)
seen.add(flag_str)
else:
if flag not in seen:
converted.append(flag)
seen.add(flag)
else:
if flag not in seen:
converted.append(flag)
seen.add(flag)
cflags[:] = converted
config.config_path = Path("config") / config.version / "config.yml"
config.check_sha_path = Path("config") / config.version / "build.sha1"
config.asflags = [
"-mgekko",
"--strip-local-absolute",
"-I include",
f"-I {config.build_dir}/{config.version}/include",
f"-I {config.build_dir}/{config.version}/bin",
f"--defsym version={version_num}",
]
config.ldflags = [
"-fp hardware",
"-nodefaults",
]
if args.debug:
config.ldflags.append("-g") # Or -gdwarf-2 for Wii linkers
if args.map:
config.ldflags.append("-mapunused")
# config.ldflags.append("-listclosure") # For Wii linkers
# Use for any additional files that should cause a re-configure when modified
config.reconfig_deps = []
# Optional numeric ID for decomp.me preset
# Can be overridden in libraries or objects
config.scratch_preset_id = None
# WIP Feature to specify separating by libraries
config.nolib = [
"*", # Leaving libraries unused for now, needs decomp to be finished
]
# Base flags, common to most GC/Wii games.
# Generally leave untouched, with overrides added below.
cflags_base = [
"-nodefaults",
"-proc gekko",
"-align powerpc",
"-enum int",
"-fp hardware",
"-W all",
"-O4,p",
'-pragma "cats off"',
'-pragma "warn_notinlined off"',
"-maxerrors 1",
"-nosyspath",
"-RTTI off",
"-fp_contract on",
"-str reuse",
"-i decomp/Prog/project",
"-i decomp/CodeWarrior/**/Include",
"-i decomp/CodeWarrior/**/INCLUDE",
f"-i {config.build_dir}/{config.version}/include",
f"-DVERSION_{config.version}",
]
# Debug flags
if args.debug:
# Or -sym dwarf-2 for Wii compilers
cflags_base.extend(["-sym on", "-DDEBUG=1"])
else:
cflags_base.append("-DNDEBUG=1")
# Github actions toggle
if args.action:
cflags_base.append("-DGH_ACTIONS")
#
cflags_gc = [
*cflags_base,
"-multibyte",
]
cflags_wii = [
*cflags_base,
"-enc SJIS",
]
# Metrowerks library flags
cflags_cw = [
"-Cpp_exceptions off",
"-use_lmw_stmw on",
"-str reuse,pool,readonly",
"-gccinc",
"-common off",
"-inline auto",
"-func_align 4",
]
cflags_cw_gc = [
*cflags_gc,
*cflags_cw
]
cflags_cw_wii = [
*cflags_wii,
*cflags_cw
]
# REL flags
cflags_rel = [
*cflags_wii,
"-sdata 0",
"-sdata2 0",
]
# fill in * , because MWCC not supporting that
cflags_paths_expand(cflags_base)
cflags_paths_expand(cflags_cw_gc)
cflags_paths_expand(cflags_cw_wii)
config.linker_version = "Wii/1.5"
# Helper function for SDK libraries
def SDKLib(lib_name: str, files: List[Tuple[bool, str]], lib_name_override: str="", conf: Dict[str,str]={"":""}) -> Dict[str, Any]:
objects = []
if lib_name_override == "":
lib_name_override = str
dirname = f"SDK/src/{lib_name}"
for matching, filename in files:
filepath = f"{dirname}/{filename}"
objects.append(Object(matching, filepath))
__cflags = cflags_sdk + [f"-i decomp/{dirname}"]
return {
"lib": lib_name_override,
"cflags": __cflags,
"progress_category": "sdk",
"src_dir": "decomp",
"objects": objects,
**conf
}
# Helper function for Dolphin libraries
def RevolutionLib(lib_name: str, files: List[Tuple[bool, str]], conf:Dict[str,str]={"":""}) -> Dict[str, Any]:
return SDKLib(f"dolphin/{lib_name}", files, f"{lib_name}")
# Helper function for CodeWarrior runtime libraries
def CWLib(lib_name: str, sub_path: str, files: List[Tuple[bool, str]], conf: Dict[str, str]={"":""}) -> Dict[str, Any]:
objects = []
dirpath = f"CodeWarrior/PowerPC_EABI_Support/{sub_path}"
for matching, filename in files:
filepath = f"{dirpath}/{filename}"
objects.append(Object(matching, filepath))
__cflags = cflags_cw_wii + [f"-i decomp/{dirpath}"]
return {
"lib": lib_name,
"mw_version": "GC/3.0a5",
"cflags": __cflags,
"progress_category": "cw",
"src_dir": f"decomp",
"objects": objects,
**conf
}
# Helper function for REL script objects
def Rel(lib_name: str, objects: List[Object]) -> Dict[str, Any]:
return {
"lib": lib_name,
"cflags": cflags_rel,
"progress_category": "game",
"src_dir": f"decomp",
"objects": objects,
}
Matching = True # Object matches and should be linked
NonMatching = False # Object does not match and should not be linked
Equivalent = config.non_matching # Object should be linked when configured with --non-matching
# Object is only matching for specific versions
def MatchingFor(*versions):
return config.version in versions
config.warn_missing_config = True
config.warn_missing_source = False
config.libs = [
# CodeWarrior
CWLib("Runtime.PPCEABI.H", "Runtime/Src", [
(NonMatching, "__init_cpp_exceptions.cpp"),
(Matching, "__mem.c"),
(Matching, "global_destructor_chain.c"),
]),
]
# Optional callback to adjust link order. This can be used to add, remove, or reorder objects.
# This is called once per module, with the module ID and the current link order.
#
# For example, this adds "dummy.c" to the end of the DOL link order if configured with --non-matching.
# "dummy.c" *must* be configured as a Matching (or Equivalent) object in order to be linked.
#def link_order_callback(module_id: int, objects: List[str]) -> List[str]:
# # Don't modify the link order for matching builds
# if not config.non_matching:
# return objects
# if module_id == 0: # DOL
# return objects + ["dummy.c"]
# return objects
# Uncomment to enable the link order callback.
# config.link_order_callback = link_order_callback
# RSO Directories
rso_basepath=f"build_rso"
rso_path=f"{rso_basepath}/{config.version}"
# RSO Preparation
def rso_conv():
try:
print("Preparing RSO files... (not yet supported by DTK though)")
dtk_path = os.path.abspath(os.path.join(rso_path, f"../../{config.build_dir}/tools/dtk"))
# Create RSO Directory
os.makedirs(rso_path, exist_ok=True)
# Call Extraction of RSO Archive
subprocess.run([dtk_path, "u8", "extract", f"../../orig/{config.version}/files/BIN000.DAT", "-q"], cwd=rso_path)
# Decrypt RSO Modules
for rso_file in Path(rso_path).iterdir():
# Call to RSO Decryptor
rsodec(rso_file, rso_file)
# Prepare and print info for RSO
rso_info = subprocess.check_output([dtk_path, "rso", "info", rso_file], text=True).removeprefix("Read RSO module ").rstrip('\n')
rso_basename = os.path.basename(rso_file)
print("- Got " + rso_basename + ", '" + rso_info + "'")
except Exception as e:
print(f"Error during RSO Preparation: {e}", file=sys.stderr)
shutil.rmtree(rso_basepath)
return 0
if args.mode == "configure":
if not os.path.isdir(rso_path):
rso_conv()
else:
print("Found 'rso_build/', expecting proper data inside (skip rso preparation).")
# Optional extra categories for progress tracking
# Adjust as desired for your project
config.progress_categories = [
ProgressCategory("game", "Main Game"),
ProgressCategory("havoc", "Havoc MiddleWare"),
ProgressCategory("nw4r", "NintendoWare"),
ProgressCategory("lib", "Misc Libraries"),
ProgressCategory("sdk", "Revolution SDK"),
ProgressCategory("cw", "CodeWarrior Runtime"),
]
config.progress_each_module = args.verbose
# Optional extra arguments to `objdiff-cli report generate`
config.progress_report_args = [
# Marks relocations as mismatching if the target value is different
# Default is "functionRelocDiffs=none", which is most lenient
# "--config functionRelocDiffs=data_value",
]
if args.mode == "configure":
# Write build.ninja and objdiff.json
generate_build(config)
elif args.mode == "progress":
# Print progress information
calculate_progress(config)
else:
sys.exit("Unknown mode: " + args.mode)