Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | |
| 4 | import confu |
| 5 | parser = confu.standard_parser("cpuinfo configuration script") |
| 6 | parser.add_argument("--log", dest="log_level", |
| 7 | choices=("none", "error", "warning", "info", "debug"), default="error") |
Marat Dukhan | 51a3427 | 2017-05-08 05:13:19 -0400 | [diff] [blame] | 8 | parser.add_argument("--mock", dest="mock", action="store_true") |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 9 | |
| 10 | |
| 11 | def main(args): |
| 12 | options = parser.parse_args(args) |
| 13 | build = confu.Build.from_options(options) |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 14 | |
| 15 | macros = { |
Marat Dukhan | 51a3427 | 2017-05-08 05:13:19 -0400 | [diff] [blame] | 16 | "CPUINFO_LOG_LEVEL": {"none": 0, "error": 1, "warning": 2, "info": 3, "debug": 4}[options.log_level], |
Marat Dukhan | cf70aee | 2018-03-24 23:21:02 -0700 | [diff] [blame] | 17 | "CPUINFO_LOG_TO_STDIO": int(not options.mock), |
| 18 | "CPUINFO_MOCK": int(options.mock), |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 19 | } |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 20 | |
| 21 | build.export_cpath("include", ["cpuinfo.h"]) |
| 22 | |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 23 | with build.options(source_dir="src", macros=macros, extra_include_dirs="src"): |
Marat Dukhan | cc70cfb | 2017-09-26 19:11:14 -0700 | [diff] [blame] | 24 | sources = ["init.c", "api.c", "log.c"] |
Marat Dukhan | c0a2f56 | 2017-12-23 19:55:25 -0800 | [diff] [blame] | 25 | if build.target.is_x86 or build.target.is_x86_64: |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 26 | sources += [ |
Marat Dukhan | 7e4b186 | 2017-08-21 02:53:35 -0700 | [diff] [blame] | 27 | "x86/init.c", "x86/info.c", "x86/vendor.c", "x86/uarch.c", "x86/name.c", |
| 28 | "x86/topology.c", |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 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 Dukhan | c0a2f56 | 2017-12-23 19:55:25 -0800 | [diff] [blame] | 33 | elif build.target.is_linux or build.target.is_android: |
Marat Dukhan | 4ba0d04 | 2017-10-13 17:16:30 -0400 | [diff] [blame] | 34 | sources += [ |
| 35 | "x86/linux/init.c", |
| 36 | "x86/linux/cpuinfo.c", |
| 37 | ] |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 38 | sources.append("x86/isa.c" if not build.target.is_nacl else "x86/nacl/isa.c") |
Marat Dukhan | ab42e7e | 2017-05-09 13:19:39 +0000 | [diff] [blame] | 39 | if build.target.is_arm or build.target.is_arm64: |
Marat Dukhan | 3c98276 | 2017-05-08 06:16:45 +0000 | [diff] [blame] | 40 | sources += ["arm/uarch.c", "arm/cache.c"] |
Marat Dukhan | c0a2f56 | 2017-12-23 19:55:25 -0800 | [diff] [blame] | 41 | if build.target.is_linux or build.target.is_android: |
Marat Dukhan | 3c98276 | 2017-05-08 06:16:45 +0000 | [diff] [blame] | 42 | sources += [ |
| 43 | "arm/linux/init.c", |
Marat Dukhan | 271d7c3 | 2017-08-18 08:00:47 +0000 | [diff] [blame] | 44 | "arm/linux/cpuinfo.c", |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 45 | "arm/linux/clusters.c", |
| 46 | "arm/linux/midr.c", |
| 47 | "arm/linux/chipset.c", |
Marat Dukhan | 63a7a6b | 2017-11-29 15:11:56 -0800 | [diff] [blame] | 48 | "arm/linux/hwcap.c", |
Marat Dukhan | 3c98276 | 2017-05-08 06:16:45 +0000 | [diff] [blame] | 49 | ] |
Marat Dukhan | ab42e7e | 2017-05-09 13:19:39 +0000 | [diff] [blame] | 50 | if build.target.is_arm: |
Marat Dukhan | deaa898 | 2017-11-28 11:07:11 -0800 | [diff] [blame] | 51 | sources.append("arm/linux/aarch32-isa.c") |
Marat Dukhan | ab42e7e | 2017-05-09 13:19:39 +0000 | [diff] [blame] | 52 | elif build.target.is_arm64: |
Marat Dukhan | deaa898 | 2017-11-28 11:07:11 -0800 | [diff] [blame] | 53 | sources.append("arm/linux/aarch64-isa.c") |
Marat Dukhan | c0a2f56 | 2017-12-23 19:55:25 -0800 | [diff] [blame] | 54 | if build.target.is_android: |
| 55 | sources += [ |
| 56 | "arm/android/gpu.c", |
| 57 | "arm/android/properties.c", |
| 58 | ] |
Marat Dukhan | ab42e7e | 2017-05-09 13:19:39 +0000 | [diff] [blame] | 59 | |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 60 | if build.target.is_macos: |
| 61 | sources += ["mach/topology.c"] |
Marat Dukhan | c0a2f56 | 2017-12-23 19:55:25 -0800 | [diff] [blame] | 62 | if build.target.is_linux or build.target.is_android: |
Marat Dukhan | 271d7c3 | 2017-08-18 08:00:47 +0000 | [diff] [blame] | 63 | sources += [ |
Marat Dukhan | d9f76e0 | 2017-09-24 22:46:08 -0700 | [diff] [blame] | 64 | "linux/current.c", |
Marat Dukhan | 271d7c3 | 2017-08-18 08:00:47 +0000 | [diff] [blame] | 65 | "linux/cpulist.c", |
Marat Dukhan | 4ba0d04 | 2017-10-13 17:16:30 -0400 | [diff] [blame] | 66 | "linux/smallfile.c", |
| 67 | "linux/multiline.c", |
Marat Dukhan | 271d7c3 | 2017-08-18 08:00:47 +0000 | [diff] [blame] | 68 | "linux/processors.c", |
| 69 | ] |
Marat Dukhan | 079ccbd | 2017-08-09 17:00:32 -0700 | [diff] [blame] | 70 | if options.mock: |
| 71 | sources += ["linux/mockfile.c"] |
Marat Dukhan | c0a2f56 | 2017-12-23 19:55:25 -0800 | [diff] [blame] | 72 | if build.target.is_android: |
| 73 | sources.append("linux/gpu.c") |
| 74 | if options.mock: |
| 75 | sources.append("gpu/gles2-mock.c") |
| 76 | else: |
| 77 | sources.append("gpu/gles2.c") |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 78 | build.static_library("cpuinfo", map(build.cc, sources)) |
| 79 | |
| 80 | with build.options(source_dir="tools", deps=build): |
| 81 | build.executable("cpu-info", build.cc("cpu-info.c")) |
| 82 | build.executable("isa-info", build.cc("isa-info.c")) |
| 83 | build.executable("cache-info", build.cc("cache-info.c")) |
| 84 | |
Marat Dukhan | 0de277f | 2017-09-22 14:25:10 -0700 | [diff] [blame] | 85 | if build.target.is_x86_64: |
| 86 | with build.options(source_dir="tools", include_dirs=["src", "include"]): |
| 87 | build.executable("cpuid-dump", build.cc("cpuid-dump.c")) |
| 88 | |
Marat Dukhan | cc70cfb | 2017-09-26 19:11:14 -0700 | [diff] [blame] | 89 | with build.options(source_dir="test", deps=[build, build.deps.googletest]): |
Marat Dukhan | ee705c7 | 2017-05-08 10:18:03 +0000 | [diff] [blame] | 90 | build.smoketest("init-test", build.cxx("init.cc")) |
Marat Dukhan | cc70cfb | 2017-09-26 19:11:14 -0700 | [diff] [blame] | 91 | if build.target.is_linux: |
| 92 | build.smoketest("get-current-test", build.cxx("get-current.cc")) |
Marat Dukhan | 7e4b186 | 2017-08-21 02:53:35 -0700 | [diff] [blame] | 93 | if build.target.is_x86_64: |
| 94 | build.smoketest("brand-string-test", build.cxx("name/brand-string.cc")) |
Marat Dukhan | cc70cfb | 2017-09-26 19:11:14 -0700 | [diff] [blame] | 95 | if options.mock: |
| 96 | with build.options(source_dir="test", include_dirs="test", macros="CPUINFO_MOCK", deps=[build, build.deps.googletest]): |
| 97 | if build.target.is_arm64 and build.target.is_linux: |
| 98 | build.unittest("scaleway-test", build.cxx("scaleway.cc")) |
Marat Dukhan | 419a819 | 2017-05-08 12:25:17 +0000 | [diff] [blame] | 99 | |
Marat Dukhan | 8127f77 | 2017-11-10 21:02:28 +0000 | [diff] [blame] | 100 | if not options.mock: |
| 101 | with build.options(source_dir="bench", deps=[build, build.deps.googlebenchmark]): |
Marat Dukhan | 9f3404b | 2017-12-07 00:24:39 -0800 | [diff] [blame] | 102 | build.benchmark("init-bench", build.cxx("init.cc")) |
Marat Dukhan | 8127f77 | 2017-11-10 21:02:28 +0000 | [diff] [blame] | 103 | if not build.target.is_macos: |
| 104 | build.benchmark("get-current-bench", build.cxx("get-current.cc")) |
| 105 | |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 106 | return build |
| 107 | |
| 108 | |
| 109 | if __name__ == "__main__": |
| 110 | import sys |
| 111 | main(sys.argv[1:]).generate() |