forked from godotengine/godot-mono-builds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
llvm.py
executable file
·127 lines (89 loc) · 3.77 KB
/
llvm.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
#!/usr/bin/python
import os
import sys
from os.path import join as path_join
from options import *
from os_utils import *
target_values = ['llvm32', 'llvm64', 'llvmwin32', 'llvmwin64']
mxe_targets = {
'llvmwin32': {'arch': 'i686', 'mxe': 'mxe-Win32'},
'llvmwin64': {'arch': 'x86_64', 'mxe': 'mxe-Win64'}
}
def make(opts: BaseOpts, target: str):
stamp_file = path_join(opts.configure_dir, '.stamp-%s-make' % target)
if os.path.isfile(stamp_file):
return
build_dir = path_join(opts.configure_dir, 'llvm-%s' % target)
install_dir = path_join(opts.install_dir, 'llvm-%s' % target)
mkdir_p(build_dir)
mkdir_p(install_dir)
CMAKE_ARGS = []
if target in mxe_targets:
mxe = mxe_targets[target]['mxe']
arch = mxe_targets[target]['arch']
CMAKE_ARGS += [
'-DCMAKE_EXE_LINKER_FLAGS="-static"',
'-DCROSS_TOOLCHAIN_FLAGS_NATIVE=-DCMAKE_TOOLCHAIN_FILE=%s/external/llvm/cmake/modules/NATIVE.cmake' % opts.mono_source_root,
'-DCMAKE_TOOLCHAIN_FILE=%s/external/llvm/cmake/modules/%s.cmake' % (opts.mono_source_root, mxe),
'-DLLVM_ENABLE_THREADS=Off',
'-DLLVM_BUILD_EXECUTION_ENGINE=Off'
]
if sys.platform == 'darwin':
mingw_zlib_prefix = '%s/opt/mingw-zlib/usr' % opts.mxe_prefix
if not os.path.isfile(mingw_zlib_prefix):
mingw_zlib_prefix = opts.mxe_prefix
CMAKE_ARGS += [
'-DZLIB_ROOT=%s/%s-w64-mingw32' % (mingw_zlib_prefix, arch),
'-DZLIB_LIBRARY=%s/%s-w64-mingw32/lib/libz.a' % (mingw_zlib_prefix, arch),
'-DZLIB_INCLUDE_DIR=%s/%s-w64-mingw32/include' % (mingw_zlib_prefix, arch)
]
replace_in_new_file(
src_file='%s/sdks/builds/%s.cmake.in' % (opts.mono_source_root, mxe),
search='@MXE_PATH@', replace=opts.mxe_prefix,
dst_file='%s/external/llvm/cmake/modules/%s.cmake' % (opts.mono_source_root, mxe)
)
if target in ['llvm32', 'llvmwin32']:
CMAKE_ARGS += ['-DLLVM_BUILD_32_BITS=On']
CMAKE_ARGS += [os.environ.get('llvm-%s_CMAKE_ARGS' % target, '')]
make_args = [
'-C', '%s/llvm' % opts.mono_source_root,
'-f', 'build.mk', 'install-llvm',
'LLVM_BUILD=%s' % build_dir,
'LLVM_PREFIX=%s' % install_dir,
'LLVM_CMAKE_ARGS=%s' % ' '.join([a for a in CMAKE_ARGS if a])
]
make_args += ['V=1'] if opts.verbose_make else []
run_command('make', args=make_args, name='make')
touch(stamp_file)
def clean(opts: BaseOpts, target: str):
build_dir = path_join(opts.configure_dir, 'llvm-%s' % target)
install_dir = path_join(opts.install_dir, 'llvm-%s' % target)
stamp_file = path_join(opts.configure_dir, '.stamp-%s-make' % target)
rm_rf(stamp_file)
make_args = [
'-C', '%s/llvm' % opts.mono_source_root,
'-f', 'build.mk', 'clean-llvm',
'LLVM_BUILD=%s' % build_dir,
'LLVM_PREFIX=%s' % install_dir
]
make_args += ['V=1'] if opts.verbose_make else []
run_command('make', args=make_args, name='make clean')
def main(raw_args):
import cmd_utils
parser = cmd_utils.build_arg_parser(description='Builds LLVM for Mono')
default_help = 'default: %(default)s'
parser.add_argument('action', choices=['make', 'clean'])
parser.add_argument('--target', choices=target_values, action='append', required=True)
cmd_utils.add_base_arguments(parser, default_help)
args = parser.parse_args(raw_args)
opts = base_opts_from_args(args)
targets = args.target
try:
for target in targets:
action = { 'make': make, 'clean': clean }[args.action]
action(opts, target)
except BuildError as e:
sys.exit(e.message)
if __name__ == '__main__':
from sys import argv
main(argv[1:])