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], |
| 17 | "CPUINFO_MOCK": int(options.mock) |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 18 | } |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 19 | |
| 20 | build.export_cpath("include", ["cpuinfo.h"]) |
| 21 | |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 22 | with build.options(source_dir="src", macros=macros, extra_include_dirs="src"): |
Marat Dukhan | cc70cfb | 2017-09-26 19:11:14 -0700 | [diff] [blame] | 23 | sources = ["init.c", "api.c", "log.c"] |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 24 | if build.target.is_x86_64: |
| 25 | sources += [ |
Marat Dukhan | 7e4b186 | 2017-08-21 02:53:35 -0700 | [diff] [blame] | 26 | "x86/init.c", "x86/info.c", "x86/vendor.c", "x86/uarch.c", "x86/name.c", |
| 27 | "x86/topology.c", |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 28 | "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 Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 32 | elif build.target.is_linux: |
Marat Dukhan | 4ba0d04 | 2017-10-13 17:16:30 -0400 | [diff] [blame] | 33 | sources += [ |
| 34 | "x86/linux/init.c", |
| 35 | "x86/linux/cpuinfo.c", |
| 36 | ] |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 37 | 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] | 38 | if build.target.is_arm or build.target.is_arm64: |
Marat Dukhan | 3c98276 | 2017-05-08 06:16:45 +0000 | [diff] [blame] | 39 | sources += ["arm/uarch.c", "arm/cache.c"] |
| 40 | if build.target.is_linux: |
| 41 | sources += [ |
| 42 | "arm/linux/init.c", |
Marat Dukhan | 271d7c3 | 2017-08-18 08:00:47 +0000 | [diff] [blame] | 43 | "arm/linux/cpuinfo.c", |
Marat Dukhan | 7c775ab | 2017-10-15 21:50:11 +0000 | [diff] [blame] | 44 | "arm/linux/clusters.c", |
| 45 | "arm/linux/midr.c", |
| 46 | "arm/linux/chipset.c", |
Marat Dukhan | 3c98276 | 2017-05-08 06:16:45 +0000 | [diff] [blame] | 47 | ] |
Marat Dukhan | ab42e7e | 2017-05-09 13:19:39 +0000 | [diff] [blame] | 48 | if build.target.is_arm: |
Marat Dukhan | 3c7c248 | 2017-05-09 14:16:34 +0000 | [diff] [blame] | 49 | sources.append("arm/linux/arm32-isa.c") |
Marat Dukhan | ab42e7e | 2017-05-09 13:19:39 +0000 | [diff] [blame] | 50 | elif build.target.is_arm64: |
Marat Dukhan | 3c7c248 | 2017-05-09 14:16:34 +0000 | [diff] [blame] | 51 | sources.append("arm/linux/arm64-isa.c") |
Marat Dukhan | ab42e7e | 2017-05-09 13:19:39 +0000 | [diff] [blame] | 52 | |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 53 | if build.target.is_macos: |
| 54 | sources += ["mach/topology.c"] |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 55 | if build.target.is_linux: |
Marat Dukhan | 271d7c3 | 2017-08-18 08:00:47 +0000 | [diff] [blame] | 56 | sources += [ |
Marat Dukhan | d9f76e0 | 2017-09-24 22:46:08 -0700 | [diff] [blame] | 57 | "linux/current.c", |
Marat Dukhan | 271d7c3 | 2017-08-18 08:00:47 +0000 | [diff] [blame] | 58 | "linux/cpulist.c", |
Marat Dukhan | 4ba0d04 | 2017-10-13 17:16:30 -0400 | [diff] [blame] | 59 | "linux/smallfile.c", |
| 60 | "linux/multiline.c", |
Marat Dukhan | 271d7c3 | 2017-08-18 08:00:47 +0000 | [diff] [blame] | 61 | "linux/processors.c", |
| 62 | ] |
Marat Dukhan | 079ccbd | 2017-08-09 17:00:32 -0700 | [diff] [blame] | 63 | if options.mock: |
| 64 | sources += ["linux/mockfile.c"] |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 65 | 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 Dukhan | 0de277f | 2017-09-22 14:25:10 -0700 | [diff] [blame] | 72 | 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 Dukhan | cc70cfb | 2017-09-26 19:11:14 -0700 | [diff] [blame] | 76 | with build.options(source_dir="test", deps=[build, build.deps.googletest]): |
Marat Dukhan | ee705c7 | 2017-05-08 10:18:03 +0000 | [diff] [blame] | 77 | build.smoketest("init-test", build.cxx("init.cc")) |
Marat Dukhan | cc70cfb | 2017-09-26 19:11:14 -0700 | [diff] [blame] | 78 | if build.target.is_linux: |
| 79 | build.smoketest("get-current-test", build.cxx("get-current.cc")) |
Marat Dukhan | 7e4b186 | 2017-08-21 02:53:35 -0700 | [diff] [blame] | 80 | if build.target.is_x86_64: |
| 81 | build.smoketest("brand-string-test", build.cxx("name/brand-string.cc")) |
Marat Dukhan | cc70cfb | 2017-09-26 19:11:14 -0700 | [diff] [blame] | 82 | 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 Dukhan | 419a819 | 2017-05-08 12:25:17 +0000 | [diff] [blame] | 86 | |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 87 | return build |
| 88 | |
| 89 | |
| 90 | if __name__ == "__main__": |
| 91 | import sys |
| 92 | main(sys.argv[1:]).generate() |