-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.py
More file actions
executable file
·105 lines (84 loc) · 3.37 KB
/
build.py
File metadata and controls
executable file
·105 lines (84 loc) · 3.37 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
#!/usr/bin/env python3
import subprocess
import sys
import os
import shutil
def main():
parse_args()
def parse_args():
args = sys.argv[1:]
if len(args) < 1:
print("You need to specify a target: all, mingw, linux, mac")
return
xmake_get_config()
target = args[0]
verbose = False
if len(args) > 1:
i = 1
while i < len(args):
if args[i] == "-v":
verbose = True
i += 1
if target == "all":
build_mingw(verbose)
build_linux(verbose)
build_mac(verbose)
elif target == "mingw":
build_mingw(verbose)
elif target == "linux":
build_linux(verbose)
elif target == "mac":
build_mac(verbose)
else:
print("Unknown target: " + target)
return
xmake_set_config()
def build_mingw(verbose):
if build("Mingw", "mingw", "i386", verbose):
copy_files("build/mingw/i386/release", "build/all/mingw-32", ["libHateEngine.dll", "libHateEngine.dll.a", "libHateEngine-static.a"])
# Copy recompiled stdlib
copy_files("extern_resources", "build/all/mingw-32", ["libgcc_s_dw2-1.dll", "libstdc++-6.dll", "libwinpthread-1.dll"])
if build("Mingw", "mingw", "x86_64", verbose):
copy_files("build/mingw/x86_64/release", "build/all/mingw-64", ["libHateEngine.dll", "libHateEngine.dll.a", "libHateEngine-static.a"])
def build_linux(verbose):
if build("Linux", "linux", "x86_64", verbose):
copy_files("build/linux/x86_64/release", "build/all/linux-64", ["libHateEngine.so", "libHateEngine-static.a"])
def build_mac(verbose):
# Check OS is MacOS
if not sys.platform == "darwin":
return
if build("Mac", "macosx", "arm64", verbose, ["--target_minver=11.0"]):
copy_files("build/macosx/arm64/release", "build/all/mac-arm64", ["libHateEngine.dylib", "libHateEngine-static.a"])
if build("Mac", "macosx", "x86_64", verbose, ["--target_minver=10.7"]):
copy_files("build/macosx/x86_64/release", "build/all/mac-64", ["libHateEngine.dylib", "libHateEngine-static.a"])
def build(target_name: str, platform: str, arch: str, verbose: bool, additional_flags: list[str] = []) -> bool:
print(f"Building {target_name} [{arch}]")
args = ["xmake", "f", "-m", "release", "-p", platform, "-a", arch, "-y"]
if verbose:
args.append("-v")
args += additional_flags
out = subprocess.DEVNULL if not verbose else None
result = subprocess.call(args, stdout=out, stderr=out)
if result != 0:
print(f"{target_name} [{arch}] configure failed")
return False
args = ["xmake"]
if verbose:
args.append("-v")
result = subprocess.call(args, stdout=out, stderr=out)
if result != 0:
print(f"{target_name} [{arch}] build failed")
return False
return True
def copy_files(src: str, dst: str, files: list[str]):
if not os.path.exists(dst):
os.makedirs(dst)
for file in files:
shutil.copyfile(src + "/" + file, dst + "/" + file)
###### Saving and after restoring a xmake user-defined config
def xmake_get_config():
subprocess.call(["xmake", "f", "--export=build/config.back"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def xmake_set_config():
subprocess.call(["xmake", "f", "--import=build/config.back"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if __name__ == "__main__":
main()