-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
executable file
·58 lines (42 loc) · 1014 Bytes
/
build.py
File metadata and controls
executable file
·58 lines (42 loc) · 1014 Bytes
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
#!/usr/bin/env python
import shutil
import subprocess
import sys
cflags = ["-Wall", "-Wextra", "-pedantic", "-std=c11"]
files = [
"./parser.c",
"./lexer.c",
"./main.c",
]
libs = ["m"]
sanitizers = [
"address",
"undefined",
"leak",
]
def find_compiler() -> str:
cc = shutil.which("cc")
if cc is None:
print("Failed to find C compiler")
sys.exit(1)
return cc
def get_flags() -> list[str]:
flags = [*cflags]
if "-mode:release" in sys.argv:
flags.append("-O2")
else:
flags.append("-g")
if "-sanitize" in sys.argv:
for sanitizer in sanitizers:
flags.append(f"-fsanitize={sanitizer}")
for lib in libs:
flags.append(f"-l{lib}")
return flags
def main():
cc = find_compiler()
flags = get_flags()
build_cmd = ' '.join([cc] + flags + files)
print(f"BUILDING WITH: {build_cmd}\n\n")
subprocess.run([cc, *flags, *files])
if __name__ == "__main__":
main()