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 | } |
| 19 | if build.target.is_linux: |
| 20 | macros["_GNU_SOURCE"] = 1 |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 21 | |
| 22 | build.export_cpath("include", ["cpuinfo.h"]) |
| 23 | |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 24 | with build.options(source_dir="src", macros=macros, extra_include_dirs="src"): |
| 25 | sources = ["init.c", "cache.c", "log.c"] |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 26 | 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 Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 33 | elif build.target.is_linux: |
| 34 | sources += ["x86/linux/init.c"] |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 35 | sources.append("x86/isa.c" if not build.target.is_nacl else "x86/nacl/isa.c") |
Marat Dukhan | 3c98276 | 2017-05-08 06:16:45 +0000 | [diff] [blame] | 36 | 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 Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 44 | if build.target.is_macos: |
| 45 | sources += ["mach/topology.c"] |
Marat Dukhan | 3045d4f | 2017-03-04 01:51:42 -0500 | [diff] [blame] | 46 | if build.target.is_linux: |
| 47 | sources += ["linux/cpuset.c"] |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 48 | 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 Dukhan | 4f63992 | 2017-05-08 07:24:37 +0000 | [diff] [blame] | 55 | with build.options(source_dir="test", deps=[build, build.deps.googletest]): |
Marat Dukhan | ee705c7 | 2017-05-08 10:18:03 +0000 | [diff] [blame^] | 56 | build.smoketest("init-test", build.cxx("init.cc")) |
Marat Dukhan | 51a3427 | 2017-05-08 05:13:19 -0400 | [diff] [blame] | 57 | 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 Dukhan | ee705c7 | 2017-05-08 10:18:03 +0000 | [diff] [blame^] | 61 | build.unittest("raspberry-pi3-test", build.cxx("raspberry-pi3.cc")) |
Marat Dukhan | 4f63992 | 2017-05-08 07:24:37 +0000 | [diff] [blame] | 62 | |
Marat Dukhan | 547fa36 | 2017-03-03 02:47:26 -0500 | [diff] [blame] | 63 | return build |
| 64 | |
| 65 | |
| 66 | if __name__ == "__main__": |
| 67 | import sys |
| 68 | main(sys.argv[1:]).generate() |