forked from ClangBuiltLinux/tc-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-binutils.py
executable file
·129 lines (116 loc) · 5.63 KB
/
build-binutils.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
128
129
#!/usr/bin/env python3
# pylint: disable=invalid-name
from argparse import ArgumentParser
from pathlib import Path
import time
import tc_build.binutils
import tc_build.utils
LATEST_BINUTILS_RELEASE = (2, 40, 0)
parser = ArgumentParser()
parser.add_argument('-B',
'--binutils-folder',
help='''
By default, the script will download a copy of the binutils source in the src folder within
the same folder as this script. If you have your own copy of the binutils source that you
would like to build from, pass it to this parameter. It can be either an absolute or
relative path.
''',
type=str)
parser.add_argument('-b',
'--build-folder',
help='''
By default, the script will create a "build/binutils" folder in the same folder as this
script then build each target in its own folder within that containing folder. If you
would like the containing build folder to be somewhere else, pass it to this parameter.
that done somewhere else, pass it to this parameter. It can be either an absolute or
relative path.
''',
type=str)
parser.add_argument('-i',
'--install-folder',
help='''
By default, the script will build binutils but stop before installing it. To install
them into a prefix, pass it to this parameter. This can be either an absolute or
relative path.
''',
type=str)
parser.add_argument('-m',
'--march',
metavar='ARCH',
help='''
Add -march=ARCH and -mtune=ARCH to CFLAGS to optimize the toolchain for the target
host processor.
''',
type=str)
parser.add_argument('--show-build-commands',
help='''
By default, the script only shows the output of the comands it is running. When this option
is enabled, the invocations of configure and make will be shown to help with reproducing
issues outside of the script.
''',
action='store_true')
parser.add_argument('-t',
'--targets',
help='''
The script can build binutils targeting arm-linux-gnueabi, aarch64-linux-gnu,
mips-linux-gnu, mipsel-linux-gnu, powerpc-linux-gnu, powerpc64-linux-gnu,
powerpc64le-linux-gnu, riscv64-linux-gnu, s390x-linux-gnu, and x86_64-linux-gnu.
By default, it builds all supported targets ("all"). If you would like to build
specific targets only, pass them to this script. It can be either the full target
or just the first part (arm, aarch64, x86_64, etc).
''',
nargs='+')
args = parser.parse_args()
script_start = time.time()
tc_build_folder = Path(__file__).resolve().parent
bsm = tc_build.binutils.BinutilsSourceManager()
if args.binutils_folder:
bsm.location = Path(args.binutils_folder).resolve()
if not bsm.location.exists():
raise RuntimeError(f"Provided binutils source ('{bsm.location}') does not exist?")
else:
# Turns (2, 40, 0) into 2.40 and (2, 40, 1) into 2.40.1 to follow tarball names
folder_name = 'binutils-' + '.'.join(str(x) for x in LATEST_BINUTILS_RELEASE if x)
bsm.location = Path(tc_build_folder, 'src', folder_name)
bsm.tarball.base_download_url = 'https://sourceware.org/pub/binutils/releases'
bsm.tarball.local_location = bsm.location.with_name(f"{folder_name}.tar.xz")
bsm.tarball_remote_checksum_name = 'sha512.sum'
bsm.prepare()
if args.build_folder:
build_folder = Path(args.build_folder).resolve()
else:
build_folder = Path(tc_build_folder, 'build/binutils')
default_targets = bsm.default_targets()
if args.targets:
targets = default_targets if 'all' in args.targets else set(args.targets)
else:
targets = default_targets
targets_to_builder = {
'arm': tc_build.binutils.ArmBinutilsBuilder,
'aarch64': tc_build.binutils.AArch64BinutilsBuilder,
'mips': tc_build.binutils.MipsBinutilsBuilder,
'mipsel': tc_build.binutils.MipselBinutilsBuilder,
'powerpc': tc_build.binutils.PowerPCBinutilsBuilder,
'powerpc64': tc_build.binutils.PowerPC64BinutilsBuilder,
'powerpc64le': tc_build.binutils.PowerPC64LEBinutilsBuilder,
'riscv64': tc_build.binutils.RISCV64BinutilsBuilder,
's390x': tc_build.binutils.S390XBinutilsBuilder,
'x86_64': tc_build.binutils.X8664BinutilsBuilder,
}
if 'loongarch64' in default_targets:
targets_to_builder['loongarch64'] = tc_build.binutils.LoongArchBinutilsBuilder
for item in targets:
target = item.split('-', maxsplit=1)[0]
if target in targets_to_builder:
builder = targets_to_builder[target]()
builder.folders.build = Path(build_folder, target)
if args.install_folder:
builder.folders.install = Path(args.install_folder).resolve()
builder.folders.source = bsm.location
if args.march:
builder.cflags += [f"-march={args.march}", f"-mtune={args.march}"]
builder.show_commands = args.show_build_commands
builder.build()
else:
tc_build.utils.print_warning(f"Unsupported target ('{target}'), ignoring...")
print(f"\nTotal script duration: {tc_build.utils.get_duration(script_start)}")