-
Notifications
You must be signed in to change notification settings - Fork 323
/
configure.py
executable file
·110 lines (95 loc) · 4.47 KB
/
configure.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
#!/usr/bin/env python
import confu
parser = confu.standard_parser("cpuinfo configuration script")
parser.add_argument("--log", dest="log_level",
choices=("none", "fatal", "error", "warning", "info", "debug"), default="error")
parser.add_argument("--mock", dest="mock", action="store_true")
def main(args):
options = parser.parse_args(args)
build = confu.Build.from_options(options)
macros = {
"CPUINFO_LOG_LEVEL": {"none": 0, "fatal": 1, "error": 2, "warning": 3, "info": 4, "debug": 5}[options.log_level],
"CLOG_LOG_TO_STDIO": int(not options.mock),
"CPUINFO_MOCK": int(options.mock),
}
if build.target.is_linux or build.target.is_android:
macros["_GNU_SOURCE"] = 1
build.export_cpath("include", ["cpuinfo.h"])
with build.options(source_dir="src", macros=macros, extra_include_dirs="src", deps=build.deps.clog):
sources = ["api.c", "init.c", "cache.c"]
if build.target.is_x86 or build.target.is_x86_64:
sources += [
"x86/init.c", "x86/info.c", "x86/isa.c", "x86/vendor.c",
"x86/uarch.c", "x86/name.c", "x86/topology.c",
"x86/cache/init.c", "x86/cache/descriptor.c", "x86/cache/deterministic.c",
]
if build.target.is_macos:
sources += ["x86/mach/init.c"]
elif build.target.is_linux or build.target.is_android:
sources += [
"x86/linux/init.c",
"x86/linux/cpuinfo.c",
]
if build.target.is_arm or build.target.is_arm64:
sources += ["arm/uarch.c", "arm/cache.c"]
if build.target.is_linux or build.target.is_android:
sources += [
"arm/linux/init.c",
"arm/linux/cpuinfo.c",
"arm/linux/clusters.c",
"arm/linux/midr.c",
"arm/linux/chipset.c",
"arm/linux/hwcap.c",
]
if build.target.is_arm:
sources.append("arm/linux/aarch32-isa.c")
elif build.target.is_arm64:
sources.append("arm/linux/aarch64-isa.c")
if build.target.is_android:
sources += [
"arm/android/properties.c",
]
if build.target.is_riscv:
if build.target.is_linux:
sources += [
"riscv/linux/init.c",
"riscv/linux/riscv-isa.c",
]
if build.target.is_macos:
sources += ["mach/topology.c"]
if build.target.is_linux or build.target.is_android:
sources += [
"linux/cpulist.c",
"linux/smallfile.c",
"linux/multiline.c",
"linux/processors.c",
]
if options.mock:
sources += ["linux/mockfile.c"]
build.static_library("cpuinfo", map(build.cc, sources))
with build.options(source_dir="tools", deps=[build, build.deps.clog]):
build.executable("cpu-info", build.cc("cpu-info.c"))
build.executable("isa-info", build.cc("isa-info.c"))
build.executable("cache-info", build.cc("cache-info.c"))
if build.target.is_x86_64:
with build.options(source_dir="tools", include_dirs=["src", "include"]):
build.executable("cpuid-dump", build.cc("cpuid-dump.c"))
with build.options(source_dir="test", deps=[build, build.deps.clog, build.deps.googletest]):
build.smoketest("init-test", build.cxx("init.cc"))
if build.target.is_linux:
build.smoketest("get-current-test", build.cxx("get-current.cc"))
if build.target.is_x86_64:
build.smoketest("brand-string-test", build.cxx("name/brand-string.cc"))
if options.mock:
with build.options(source_dir="test", include_dirs="test", macros="CPUINFO_MOCK", deps=[build, build.deps.googletest]):
if build.target.is_arm64 and build.target.is_linux:
build.unittest("scaleway-test", build.cxx("scaleway.cc"))
if not options.mock:
with build.options(source_dir="bench", deps=[build, build.deps.clog, build.deps.googlebenchmark]):
build.benchmark("init-bench", build.cxx("init.cc"))
if not build.target.is_macos:
build.benchmark("get-current-bench", build.cxx("get-current.cc"))
return build
if __name__ == "__main__":
import sys
main(sys.argv[1:]).generate()