-
Notifications
You must be signed in to change notification settings - Fork 12
/
crosscompile.py
63 lines (52 loc) · 1.96 KB
/
crosscompile.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
import platform
from os import path, getcwd
from build import prepare_build_directory, find_make_prog
from shutil import which
import subprocess
# platform.linux_distribution() and .dist() will be removed in 3.8, this will work for now
if "ubuntu" in platform.platform().lower():
try:
import apt
cache = apt.Cache()
cache.open()
SYSTEM = "Ubuntu"
except ImportError:
exit("Can't find python package apt in your ubuntu installation")
def execute_command(command):
subprocess_result = subprocess.Popen(command)
subprocess_result.communicate()
return
def compile_windows(src, dst, make_prog):
command = "cmake .. -DCMAKE_TOOLCHAIN_FILE=\"{0}/compile-tools/toolchains/Ubuntu-mingw32.cmake\"".format(src)
execute_command(command)
execute_command(make_prog)
command = "cmake -DCMAKE_TOOLCHAIN_FILE=\"{0}/compile-tools/toolchains/Ubuntu-mingw64.cmake\" ..".format(src)
execute_command(command)
execute_command(make_prog)
return
def compile_linux(src, dst, make_prog):
command = "cmake .. -DCMAKE_TOOLCHAIN_FILE={0}/compile-tools/toolchains/Ubuntu-gnueabihf.cmake".format(src)
execute_command(command)
execute_command(make_prog)
command = "cmake .."
execute_command(command)
execute_command(make_prog)
return
def cross_compile(src, dst, make_prog):
compile_linux(src, dst, make_prog)
try:
cache['mingw-w64'].is_installed
compile_windows(src, dst, make_prog)
except KeyError:
print("Missing package mingw-w64, can't crosscompile to windows")
def main(src, dst, folder_name):
if not path.isabs(dst):
dst = path.join(getcwd(), dst)
if not path.isdir(dst):
exit("Path specified doesn't exist")
make_prog = find_make_prog()[1]
if not make_prog or not which(make_prog):
exit("Couldn't find Make program")
print("Building")
prepare_build_directory(dst, folder_name)
cross_compile(src, dst, make_prog)