• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/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", "fatal", "error", "warning", "info", "debug"), default="error")
8parser.add_argument("--mock", dest="mock", action="store_true")
9
10
11def main(args):
12    options = parser.parse_args(args)
13    build = confu.Build.from_options(options)
14
15    macros = {
16        "CPUINFO_LOG_LEVEL": {"none": 0, "fatal": 1, "error": 2, "warning": 3, "info": 4, "debug": 5}[options.log_level],
17        "CLOG_LOG_TO_STDIO": int(not options.mock),
18        "CPUINFO_MOCK": int(options.mock),
19    }
20    if build.target.is_linux or build.target.is_android:
21        macros["_GNU_SOURCE"] = 1
22
23    build.export_cpath("include", ["cpuinfo.h"])
24
25    with build.options(source_dir="src", macros=macros, extra_include_dirs="src", deps=build.deps.clog):
26        sources = ["api.c", "init.c", "cache.c"]
27        if build.target.is_x86 or build.target.is_x86_64:
28            sources += [
29                "x86/init.c", "x86/info.c", "x86/isa.c", "x86/vendor.c",
30                "x86/uarch.c", "x86/name.c", "x86/topology.c",
31                "x86/cache/init.c", "x86/cache/descriptor.c", "x86/cache/deterministic.c",
32            ]
33            if build.target.is_macos:
34                sources += ["x86/mach/init.c"]
35            elif build.target.is_linux or build.target.is_android:
36                sources += [
37                    "x86/linux/init.c",
38                    "x86/linux/cpuinfo.c",
39                ]
40        if build.target.is_arm or build.target.is_arm64:
41            sources += ["arm/uarch.c", "arm/cache.c"]
42            if build.target.is_linux or build.target.is_android:
43                sources += [
44                    "arm/linux/init.c",
45                    "arm/linux/cpuinfo.c",
46                    "arm/linux/clusters.c",
47                    "arm/linux/midr.c",
48                    "arm/linux/chipset.c",
49                    "arm/linux/hwcap.c",
50                ]
51                if build.target.is_arm:
52                    sources.append("arm/linux/aarch32-isa.c")
53                elif build.target.is_arm64:
54                    sources.append("arm/linux/aarch64-isa.c")
55                if build.target.is_android:
56                    sources += [
57                        "arm/android/properties.c",
58                    ]
59
60        if build.target.is_macos:
61            sources += ["mach/topology.c"]
62        if build.target.is_linux or build.target.is_android:
63            sources += [
64                "linux/cpulist.c",
65                "linux/smallfile.c",
66                "linux/multiline.c",
67                "linux/processors.c",
68            ]
69            if options.mock:
70                sources += ["linux/mockfile.c"]
71        build.static_library("cpuinfo", map(build.cc, sources))
72
73    with build.options(source_dir="tools", deps=[build, build.deps.clog]):
74        build.executable("cpu-info", build.cc("cpu-info.c"))
75        build.executable("isa-info", build.cc("isa-info.c"))
76        build.executable("cache-info", build.cc("cache-info.c"))
77
78    if build.target.is_x86_64:
79        with build.options(source_dir="tools", include_dirs=["src", "include"]):
80            build.executable("cpuid-dump", build.cc("cpuid-dump.c"))
81
82    with build.options(source_dir="test", deps=[build, build.deps.clog, build.deps.googletest]):
83        build.smoketest("init-test", build.cxx("init.cc"))
84        if build.target.is_linux:
85            build.smoketest("get-current-test", build.cxx("get-current.cc"))
86        if build.target.is_x86_64:
87            build.smoketest("brand-string-test", build.cxx("name/brand-string.cc"))
88    if options.mock:
89        with build.options(source_dir="test", include_dirs="test", macros="CPUINFO_MOCK", deps=[build, build.deps.googletest]):
90            if build.target.is_arm64 and build.target.is_linux:
91                build.unittest("scaleway-test", build.cxx("scaleway.cc"))
92
93    if not options.mock:
94        with build.options(source_dir="bench", deps=[build, build.deps.clog, build.deps.googlebenchmark]):
95            build.benchmark("init-bench", build.cxx("init.cc"))
96            if not build.target.is_macos:
97                build.benchmark("get-current-bench", build.cxx("get-current.cc"))
98
99    return build
100
101
102if __name__ == "__main__":
103    import sys
104    main(sys.argv[1:]).generate()
105