blob: d01cea67cca863468702425c7bc59133a41c0a14 [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 }
Marat Dukhan547fa362017-03-03 02:47:26 -050019
20 build.export_cpath("include", ["cpuinfo.h"])
21
Marat Dukhan3045d4f2017-03-04 01:51:42 -050022 with build.options(source_dir="src", macros=macros, extra_include_dirs="src"):
Marat Dukhancc70cfb2017-09-26 19:11:14 -070023 sources = ["init.c", "api.c", "log.c"]
Marat Dukhan547fa362017-03-03 02:47:26 -050024 if build.target.is_x86_64:
25 sources += [
Marat Dukhan7e4b1862017-08-21 02:53:35 -070026 "x86/init.c", "x86/info.c", "x86/vendor.c", "x86/uarch.c", "x86/name.c",
27 "x86/topology.c",
Marat Dukhan547fa362017-03-03 02:47:26 -050028 "x86/cache/init.c", "x86/cache/descriptor.c", "x86/cache/deterministic.c",
29 ]
30 if build.target.is_macos:
31 sources += ["x86/mach/init.c"]
Marat Dukhan3045d4f2017-03-04 01:51:42 -050032 elif build.target.is_linux:
Marat Dukhan4ba0d042017-10-13 17:16:30 -040033 sources += [
34 "x86/linux/init.c",
35 "x86/linux/cpuinfo.c",
36 ]
Marat Dukhan547fa362017-03-03 02:47:26 -050037 sources.append("x86/isa.c" if not build.target.is_nacl else "x86/nacl/isa.c")
Marat Dukhanab42e7e2017-05-09 13:19:39 +000038 if build.target.is_arm or build.target.is_arm64:
Marat Dukhan3c982762017-05-08 06:16:45 +000039 sources += ["arm/uarch.c", "arm/cache.c"]
40 if build.target.is_linux:
41 sources += [
42 "arm/linux/init.c",
Marat Dukhan271d7c32017-08-18 08:00:47 +000043 "arm/linux/cpuinfo.c",
Marat Dukhan7c775ab2017-10-15 21:50:11 +000044 "arm/linux/clusters.c",
45 "arm/linux/midr.c",
46 "arm/linux/chipset.c",
Marat Dukhan3c982762017-05-08 06:16:45 +000047 ]
Marat Dukhanab42e7e2017-05-09 13:19:39 +000048 if build.target.is_arm:
Marat Dukhan3c7c2482017-05-09 14:16:34 +000049 sources.append("arm/linux/arm32-isa.c")
Marat Dukhanab42e7e2017-05-09 13:19:39 +000050 elif build.target.is_arm64:
Marat Dukhan3c7c2482017-05-09 14:16:34 +000051 sources.append("arm/linux/arm64-isa.c")
Marat Dukhanab42e7e2017-05-09 13:19:39 +000052
Marat Dukhan547fa362017-03-03 02:47:26 -050053 if build.target.is_macos:
54 sources += ["mach/topology.c"]
Marat Dukhan3045d4f2017-03-04 01:51:42 -050055 if build.target.is_linux:
Marat Dukhan271d7c32017-08-18 08:00:47 +000056 sources += [
Marat Dukhand9f76e02017-09-24 22:46:08 -070057 "linux/current.c",
Marat Dukhan271d7c32017-08-18 08:00:47 +000058 "linux/cpulist.c",
Marat Dukhan4ba0d042017-10-13 17:16:30 -040059 "linux/smallfile.c",
60 "linux/multiline.c",
Marat Dukhan271d7c32017-08-18 08:00:47 +000061 "linux/processors.c",
62 ]
Marat Dukhan079ccbd2017-08-09 17:00:32 -070063 if options.mock:
64 sources += ["linux/mockfile.c"]
Marat Dukhan547fa362017-03-03 02:47:26 -050065 build.static_library("cpuinfo", map(build.cc, sources))
66
67 with build.options(source_dir="tools", deps=build):
68 build.executable("cpu-info", build.cc("cpu-info.c"))
69 build.executable("isa-info", build.cc("isa-info.c"))
70 build.executable("cache-info", build.cc("cache-info.c"))
71
Marat Dukhan0de277f2017-09-22 14:25:10 -070072 if build.target.is_x86_64:
73 with build.options(source_dir="tools", include_dirs=["src", "include"]):
74 build.executable("cpuid-dump", build.cc("cpuid-dump.c"))
75
Marat Dukhancc70cfb2017-09-26 19:11:14 -070076 with build.options(source_dir="test", deps=[build, build.deps.googletest]):
Marat Dukhanee705c72017-05-08 10:18:03 +000077 build.smoketest("init-test", build.cxx("init.cc"))
Marat Dukhancc70cfb2017-09-26 19:11:14 -070078 if build.target.is_linux:
79 build.smoketest("get-current-test", build.cxx("get-current.cc"))
Marat Dukhan7e4b1862017-08-21 02:53:35 -070080 if build.target.is_x86_64:
81 build.smoketest("brand-string-test", build.cxx("name/brand-string.cc"))
Marat Dukhancc70cfb2017-09-26 19:11:14 -070082 if options.mock:
83 with build.options(source_dir="test", include_dirs="test", macros="CPUINFO_MOCK", deps=[build, build.deps.googletest]):
84 if build.target.is_arm64 and build.target.is_linux:
85 build.unittest("scaleway-test", build.cxx("scaleway.cc"))
Marat Dukhan419a8192017-05-08 12:25:17 +000086
Marat Dukhan547fa362017-03-03 02:47:26 -050087 return build
88
89
90if __name__ == "__main__":
91 import sys
92 main(sys.argv[1:]).generate()