-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.py
executable file
·175 lines (141 loc) · 4.41 KB
/
configure.py
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
#! /usr/bin/env python3
import argparse
import os
import shutil
import sys
from pathlib import Path
from typing import Dict, List, Set, Union
import ninja_syntax
import config
ROOT = Path(__file__).parent.resolve()
TOOLS_DIR = ROOT / "tools"
BASENAME = "lv0ldr"
LD_PATH = f"{BASENAME}.ld"
BIN_PATH = f"build/{BASENAME}.bin"
MAP_PATH = f"build/{BASENAME}.map"
ELF_PATH = f"build/{BASENAME}.elf"
COMMON_INCLUDES = f"{ROOT}/include"
GAME_CC_DIR = f"{TOOLS_DIR}/cc/spu"
COMMON_COMPILE_FLAGS = "-Os"
GAME_GCC_CMD = f"{GAME_CC_DIR}/bin/gcc.exe -fno-unit-at-a-time -c -B {GAME_CC_DIR}/bin -I {COMMON_INCLUDES} {COMMON_COMPILE_FLAGS} $in"
GAME_COMPILE_CMD = f"{GAME_GCC_CMD} -o"
GAME_GPP_CMD = f"{GAME_CC_DIR}/bin/g++.exe -fno-if-conversion2 -fno-unit-at-a-time -fno-inline -ffunction-sections -fdata-sections -c -B {GAME_CC_DIR}/bin -I {COMMON_INCLUDES} -Os $in"
GAME_COMPILE_CPP_CMD = f"{GAME_GPP_CMD} -o"
def clean():
shutil.rmtree("asm", ignore_errors=True)
shutil.rmtree("assets", ignore_errors=True)
shutil.rmtree("build", ignore_errors=True)
def build_stuff():
built_objects: Set[Path] = set()
def build(
object_path: Path,
src_path: Path,
task: str,
variables: Dict[str, str] = {},
implicit_outputs: List[str] = [],
):
if object_path.suffix == ".o":
built_objects.add(object_path)
ninja.build(
outputs=str(object_path),
rule=task,
inputs=str(src_path),
variables=variables,
implicit_outputs=implicit_outputs,
)
ninja = ninja_syntax.Writer(open(str(ROOT / "build.ninja"), "w"), width=9999)
# Rules
cross = f"{GAME_CC_DIR}/bin/"
ld_args = f"-Map $mapfile -T $in -T undefined_syms.ld -o $out"
ninja.rule(
"as",
description="as $in",
command=f"cpp $in -o - | {cross}as.exe -Iinclude - -o $out",
)
ninja.rule(
"cc",
description="cc $in",
command=f"{GAME_COMPILE_CMD} $out",
)
ninja.rule(
"cxx",
description="cxx $in",
command=f"{GAME_COMPILE_CPP_CMD} $out",
)
ninja.rule(
"databin",
description="convert $in to o file",
command=f"printf \".section .data\\n .incbin \\\"$in\\\"\\n\" | {cross}as.exe - -o $out"
)
ninja.rule(
"ld",
description="link $out",
command=f"{cross}ld.exe {ld_args}",
)
ninja.rule(
"sha1sum",
description="sha1sum $in",
command="sha1sum -c $in && touch $out",
)
ninja.rule(
"bin",
description="bin $out",
command=f"{cross}objcopy.exe $in $out -O binary",
)
# for entry in linker_entries:
# seg = entry.segment
#
# if seg.type[0] == ".":
# continue
#
# if entry.object_path is None:
# continue
#
# if isinstance(seg, splat.segtypes.common.asm.CommonSegAsm) or isinstance(
# seg, splat.segtypes.common.data.CommonSegData
# ):
# build(entry.object_path, entry.src_paths, "as")
# elif isinstance(seg, splat.segtypes.common.c.CommonSegC):
# build(entry.object_path, entry.src_paths, "cc")
# elif isinstance(seg, splat.segtypes.common.databin.CommonSegDatabin):
# build(entry.object_path, entry.src_paths, "as")
# else:
# print(f"ERROR: Unsupported build segment type {seg.type}")
# sys.exit(1)
for entry in config.BuildFiles:
build(entry.object_path, entry.src_path, entry.build_rule)
config.generate_linker(LD_PATH)
ninja.build(
ELF_PATH,
"ld",
LD_PATH,
implicit=[str(obj) for obj in built_objects],
variables={"mapfile": MAP_PATH},
)
ninja.build(
BIN_PATH + ".bin",
"bin",
ELF_PATH,
)
ninja.build(
BIN_PATH + ".ok",
"sha1sum",
f"{BASENAME}.sha1",
implicit=[BIN_PATH + ".bin"],
)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Configure the project")
parser.add_argument(
"-c",
"--clean",
help="Clean extraction and build artifacts",
action="store_true",
)
args = parser.parse_args()
LD_PATH = f"{BASENAME}.ld"
BIN_PATH = f"build/{BASENAME}"
MAP_PATH = f"build/{BASENAME}.map"
ELF_PATH = f"build/{BASENAME}.elf"
if args.clean:
clean()
build_stuff()