-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_sysroot.py
executable file
·69 lines (55 loc) · 1.7 KB
/
make_sysroot.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
#!/usr/bin/env python3
import os
import sys
import subprocess
def config_newlib(source_dir: str, install_dir: str):
config_cmd = [
os.path.join(source_dir, "configure"),
"--prefix=" + os.path.abspath(install_dir),
"--disable-shared",
"--target=i686-toy",
]
return subprocess.call(config_cmd)
def build_newlib(source_dir: str, install_dir: str):
if not os.path.isdir(source_dir):
print("newlib source dir is not exists : %s" % source_dir)
return 1
if os.path.exists("build_newlib"):
subprocess.call(["rm", "-rf", "build_newlib"])
pass
os.mkdir("build_newlib")
# cd into build_newlib/
os.chdir("build_newlib/")
# if Mkefile is not exisit, need to config newlib
if not os.path.exists("Makefile"):
if config_newlib(source_dir, install_dir) != 0:
return 1
# build newlib
if os.system("make") != 0:
return 1
# install newlib
if os.system("make install") != 0:
return 1
return 0
if __name__ == "__main__":
pwd = os.getcwd()
source_dir = os.path.join(pwd, "apps/newlib/")
install_dir = os.path.join(pwd, "sysroot/")
print(source_dir)
print(install_dir)
if not os.path.exists("build"):
os.mkdir("build")
# build
os.chdir("build/")
ret = build_newlib(source_dir, install_dir)
if ret == 1:
sys.exit(1)
# FIXME to solve gcc sysroot header and lib search path
os.chdir(pwd)
os.chdir("sysroot")
if not os.path.exists('usr'):
os.mkdir('usr')
os.chdir('usr')
subprocess.call(['ln', '-s', '../i686-toy/include', '.'])
subprocess.call(['ln', '-s', '../i686-toy/lib', '.'])
sys.exit(0)