1#!/usr/bin/env python3 2 3from __future__ import print_function 4import os 5 6 7CPUINFO_SOURCES = { 8 None: [ 9 "init.c", 10 "api.c", 11 "cache.c", 12 "log.c", 13 ], 14 "defined(__linux__)": [ 15 "linux/multiline.c", 16 "linux/cpulist.c", 17 "linux/mockfile.c", 18 "linux/smallfile.c", 19 "linux/processors.c", 20 ], 21 "defined(__MACH__) && defined(__APPLE__)": [ 22 "mach/topology.c", 23 ], 24 "defined(__i386__) || defined(__i686__) || defined(__x86_64__) || defined(_WIN32)": [ 25 "x86/cache/init.c", 26 "x86/cache/deterministic.c", 27 "x86/cache/descriptor.c", 28 "x86/info.c", 29 "x86/mockcpuid.c", 30 "x86/isa.c", 31 "x86/topology.c", 32 "x86/name.c", 33 "x86/init.c", 34 "x86/uarch.c", 35 "x86/vendor.c", 36 ], 37 "(defined(__i386__) || defined(__i686__) || defined(__x86_64__)) && defined(__linux__)": [ 38 "x86/linux/init.c", 39 "x86/linux/cpuinfo.c", 40 ], 41 "(defined(__i386__) || defined(__i686__) || defined(__x86_64__)) && defined(__MACH__) && defined(__APPLE__)": [ 42 "x86/mach/init.c", 43 ], 44 "defined(_WIN32)": [ 45 "x86/windows/init.c", 46 ], 47 "(defined(__arm__) || defined(__aarch64__)) && defined(__linux__)": [ 48 "arm/linux/cpuinfo.c", 49 "arm/linux/hwcap.c", 50 "arm/linux/init.c", 51 "arm/linux/clusters.c", 52 "arm/linux/midr.c", 53 "arm/linux/chipset.c", 54 "arm/tlb.c", 55 "arm/uarch.c", 56 "arm/cache.c", 57 ], 58 "defined(__arm__) && defined(__linux__)": [ 59 "arm/linux/aarch32-isa.c", 60 ], 61 "defined(__aarch64__) && defined(__linux__)": [ 62 "arm/linux/aarch64-isa.c", 63 ], 64 "(defined(__arm__) || defined(__aarch64__)) && defined(__ANDROID__)": [ 65 "arm/android/properties.c", 66 ], 67 "(defined(__arm__) || defined(__aarch64__)) && defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE": [ 68 "arm/mach/init.c", 69 ], 70} 71 72 73if __name__ == "__main__": 74 for condition, filenames in CPUINFO_SOURCES.items(): 75 for filename in filenames: 76 filepath = os.path.join("cpuinfo/wrappers", filename) 77 if not os.path.exists(os.path.dirname(filepath)): 78 print(filepath) 79 os.makedirs(os.path.dirname(filepath)) 80 with open(filepath, "w") as wrapper: 81 print("/* Auto-generated by generate-wrappers.py script. Do not modify */", file=wrapper) 82 print(file=wrapper) 83 print("#ifdef __APPLE__", file=wrapper) 84 print("\t#include <TargetConditionals.h>", file=wrapper) 85 print("#endif /* __APPLE__ */", file=wrapper) 86 print(file=wrapper) 87 88 if not condition: 89 print("#include <%s>" % filename, file=wrapper) 90 else: 91 # Include source file only if condition is satisfied 92 print("#if %s" % condition, file=wrapper) 93 print("#include <%s>" % filename, file=wrapper) 94 print("#endif /* %s */" % condition, file=wrapper) 95