blob: f8fd3ddeb8f87ee141225aa40822b6a26a9190d2 [file] [log] [blame]
Marat Dukhan547fa362017-03-03 02:47:26 -05001#!/usr/bin/env python
2
3
4import confu
5parser = confu.standard_parser("cpuinfo configuration script")
6parser.add_argument("--log", dest="log_level",
7 choices=("none", "error", "warning", "info", "debug"), default="error")
Marat Dukhan51a34272017-05-08 05:13:19 -04008parser.add_argument("--mock", dest="mock", action="store_true")
Marat Dukhan547fa362017-03-03 02:47:26 -05009
10
11def main(args):
12 options = parser.parse_args(args)
13 build = confu.Build.from_options(options)
Marat Dukhan3045d4f2017-03-04 01:51:42 -050014
15 macros = {
Marat Dukhan51a34272017-05-08 05:13:19 -040016 "CPUINFO_LOG_LEVEL": {"none": 0, "error": 1, "warning": 2, "info": 3, "debug": 4}[options.log_level],
17 "CPUINFO_MOCK": int(options.mock)
Marat Dukhan3045d4f2017-03-04 01:51:42 -050018 }
19 if build.target.is_linux:
20 macros["_GNU_SOURCE"] = 1
Marat Dukhan547fa362017-03-03 02:47:26 -050021
22 build.export_cpath("include", ["cpuinfo.h"])
23
Marat Dukhan3045d4f2017-03-04 01:51:42 -050024 with build.options(source_dir="src", macros=macros, extra_include_dirs="src"):
25 sources = ["init.c", "cache.c", "log.c"]
Marat Dukhan547fa362017-03-03 02:47:26 -050026 if build.target.is_x86_64:
27 sources += [
28 "x86/init.c", "x86/info.c", "x86/vendor.c", "x86/uarch.c", "x86/topology.c",
29 "x86/cache/init.c", "x86/cache/descriptor.c", "x86/cache/deterministic.c",
30 ]
31 if build.target.is_macos:
32 sources += ["x86/mach/init.c"]
Marat Dukhan3045d4f2017-03-04 01:51:42 -050033 elif build.target.is_linux:
34 sources += ["x86/linux/init.c"]
Marat Dukhan547fa362017-03-03 02:47:26 -050035 sources.append("x86/isa.c" if not build.target.is_nacl else "x86/nacl/isa.c")
Marat Dukhan3c982762017-05-08 06:16:45 +000036 if build.target.is_arm:
37 sources += ["arm/uarch.c", "arm/cache.c"]
38 if build.target.is_linux:
39 sources += [
40 "arm/linux/init.c",
41 "arm/linux/isa.c",
42 "arm/linux/cpuinfo.c"
43 ]
Marat Dukhan547fa362017-03-03 02:47:26 -050044 if build.target.is_macos:
45 sources += ["mach/topology.c"]
Marat Dukhan3045d4f2017-03-04 01:51:42 -050046 if build.target.is_linux:
47 sources += ["linux/cpuset.c"]
Marat Dukhan547fa362017-03-03 02:47:26 -050048 build.static_library("cpuinfo", map(build.cc, sources))
49
50 with build.options(source_dir="tools", deps=build):
51 build.executable("cpu-info", build.cc("cpu-info.c"))
52 build.executable("isa-info", build.cc("isa-info.c"))
53 build.executable("cache-info", build.cc("cache-info.c"))
54
Marat Dukhan4f639922017-05-08 07:24:37 +000055 with build.options(source_dir="test", deps=[build, build.deps.googletest]):
Marat Dukhanee705c72017-05-08 10:18:03 +000056 build.smoketest("init-test", build.cxx("init.cc"))
Marat Dukhan51a34272017-05-08 05:13:19 -040057 if options.mock:
58 with build.options(macros={"CPUINFO_MOCK": int(options.mock)}):
59 if build.target.is_arm and build.target.is_linux:
60 build.unittest("raspberry-pi2-test", build.cxx("raspberry-pi2.cc"))
Marat Dukhanee705c72017-05-08 10:18:03 +000061 build.unittest("raspberry-pi3-test", build.cxx("raspberry-pi3.cc"))
Marat Dukhan4f639922017-05-08 07:24:37 +000062
Marat Dukhan547fa362017-03-03 02:47:26 -050063 return build
64
65
66if __name__ == "__main__":
67 import sys
68 main(sys.argv[1:]).generate()