1 # This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2 # See https://llvm.org/LICENSE.txt for license information.
3 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 """Defines variables that use selects to configure LLVM based on platform."""
15 def native_arch_defines(arch, triple):
17 r'LLVM_NATIVE_ARCH=\"{}\"'.format(arch),
18 "LLVM_NATIVE_ASMPARSER=LLVMInitialize{}AsmParser".format(arch),
19 "LLVM_NATIVE_ASMPRINTER=LLVMInitialize{}AsmPrinter".format(arch),
20 "LLVM_NATIVE_DISASSEMBLER=LLVMInitialize{}Disassembler".format(arch),
21 "LLVM_NATIVE_TARGET=LLVMInitialize{}Target".format(arch),
22 "LLVM_NATIVE_TARGETINFO=LLVMInitialize{}TargetInfo".format(arch),
23 "LLVM_NATIVE_TARGETMC=LLVMInitialize{}TargetMC".format(arch),
24 "LLVM_NATIVE_TARGETMCA=LLVMInitialize{}TargetMCA".format(arch),
25 r'LLVM_HOST_TRIPLE=\"{}\"'.format(triple),
26 r'LLVM_DEFAULT_TARGET_TRIPLE=\"{}\"'.format(triple),
32 "BACKTRACE_HEADER=<execinfo.h>",
33 r'LTDL_SHLIB_EXT=\".so\"',
34 r'LLVM_PLUGIN_EXT=\".so\"',
35 "LLVM_ENABLE_THREADS=1",
36 "HAVE_DEREGISTER_FRAME=1",
38 "HAVE_PTHREAD_GETNAME_NP=1",
40 "HAVE_PTHREAD_SETNAME_NP=1",
41 "HAVE_REGISTER_FRAME=1",
48 linux_defines = posix_defines + [
52 "HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC=1",
55 macos_defines = posix_defines + [
57 "HAVE_MALLOC_MALLOC_H=1",
58 "HAVE_MALLOC_ZONE_STATISTICS=1",
59 "HAVE_PROC_PID_RUSAGE=1",
60 "HAVE_UNW_ADD_DYNAMIC_FDE=1",
64 # Windows system library specific defines.
65 "_CRT_SECURE_NO_DEPRECATE",
66 "_CRT_SECURE_NO_WARNINGS",
67 "_CRT_NONSTDC_NO_DEPRECATE",
68 "_CRT_NONSTDC_NO_WARNINGS",
69 "_SCL_SECURE_NO_DEPRECATE",
70 "_SCL_SECURE_NO_WARNINGS",
75 r'LTDL_SHLIB_EXT=\".dll\"',
76 r'LLVM_PLUGIN_EXT=\".dll\"',
79 # TODO: We should switch to platforms-based config settings to make this easier
82 "@bazel_tools//src/conditions:windows": win32_defines,
83 "@bazel_tools//src/conditions:darwin": macos_defines,
84 "@bazel_tools//src/conditions:freebsd": posix_defines,
85 "//conditions:default": linux_defines,
88 # HAVE_BUILTIN_THREAD_POINTER is true for on Linux (outside of ppc64) for
89 # all recent toolchains. Add it here by default on Linux as we can't perform a
90 # configure time check.
91 builtin_thread_pointer = select({
92 "@bazel_tools//src/conditions:linux_ppc64le": [],
93 "@bazel_tools//src/conditions:linux": ["HAVE_BUILTIN_THREAD_POINTER"],
94 "//conditions:default": [],
97 # TODO: We should split out host vs. target here.
98 llvm_config_defines = os_defines + builtin_thread_pointer + select({
99 "@bazel_tools//src/conditions:windows": native_arch_defines("X86", "x86_64-pc-win32"),
100 "@bazel_tools//src/conditions:darwin_arm64": native_arch_defines("AArch64", "arm64-apple-darwin"),
101 "@bazel_tools//src/conditions:darwin_x86_64": native_arch_defines("X86", "x86_64-unknown-darwin"),
102 "@bazel_tools//src/conditions:linux_aarch64": native_arch_defines("AArch64", "aarch64-unknown-linux-gnu"),
103 "@bazel_tools//src/conditions:linux_ppc64le": native_arch_defines("PowerPC", "powerpc64le-unknown-linux-gnu"),
104 "@bazel_tools//src/conditions:linux_s390x": native_arch_defines("SystemZ", "systemz-unknown-linux_gnu"),
105 "//conditions:default": native_arch_defines("X86", "x86_64-unknown-linux-gnu"),
107 "LLVM_VERSION_MAJOR={}".format(LLVM_VERSION_MAJOR),
108 "LLVM_VERSION_MINOR={}".format(LLVM_VERSION_MINOR),
109 "LLVM_VERSION_PATCH={}".format(LLVM_VERSION_PATCH),
110 r'LLVM_VERSION_STRING=\"{}\"'.format(PACKAGE_VERSION),
111 # These shouldn't be needed by the C++11 standard, but are for some
112 # platforms (e.g. glibc < 2.18. See
113 # https://sourceware.org/bugzilla/show_bug.cgi?id=15366). These are also
114 # included unconditionally in the CMake build:
115 # https://github.com/llvm/llvm-project/blob/cd0dd8ece8e/llvm/cmake/modules/HandleLLVMOptions.cmake#L907-L909
116 "__STDC_LIMIT_MACROS",
117 "__STDC_CONSTANT_MACROS",
118 "__STDC_FORMAT_MACROS",