1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // This file adds defines about the platform we're currently building on.
6 //  Operating System:
7 //    OS_WIN / OS_MACOSX / OS_LINUX / OS_POSIX (MACOSX or LINUX) /
8 //    OS_NACL (NACL_SFI or NACL_NONSFI) / OS_NACL_SFI / OS_NACL_NONSFI
9 //  Compiler:
10 //    COMPILER_MSVC / COMPILER_GCC
11 //  Processor:
12 //    ARCH_CPU_X86 / ARCH_CPU_X86_64 / ARCH_CPU_X86_FAMILY (X86 or X86_64)
13 //    ARCH_CPU_32_BITS / ARCH_CPU_64_BITS
14 
15 #ifndef BUILD_BUILD_CONFIG_H_
16 #define BUILD_BUILD_CONFIG_H_
17 
18 // A set of macros to use for platform detection.
19 #if defined(__native_client__)
20 // __native_client__ must be first, so that other OS_ defines are not set.
21 #define OS_NACL 1
22 // OS_NACL comes in two sandboxing technology flavors, SFI or Non-SFI.
23 // PNaCl toolchain defines __native_client_nonsfi__ macro in Non-SFI build
24 // mode, while it does not in SFI build mode.
25 #if defined(__native_client_nonsfi__)
26 #define OS_NACL_NONSFI
27 #else
28 #define OS_NACL_SFI
29 #endif
30 #elif defined(ANDROID)
31 #define OS_ANDROID 1
32 #elif defined(__APPLE__)
33 // only include TargetConditions after testing ANDROID as some android builds
34 // on mac don't have this header available and it's not needed unless the target
35 // is really mac/ios.
36 #include <TargetConditionals.h>
37 #define OS_MACOSX 1
38 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
39 #define OS_IOS 1
40 #endif  // defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
41 #elif defined(__linux__)
42 #define OS_LINUX 1
43 // include a system header to pull in features.h for glibc/uclibc macros.
44 #include <unistd.h>
45 #if defined(__GLIBC__) && !defined(__UCLIBC__)
46 // we really are using glibc, not uClibc pretending to be glibc
47 #define LIBC_GLIBC 1
48 #endif
49 #elif defined(_WIN32)
50 #define OS_WIN 1
51 #define TOOLKIT_VIEWS 1
52 #elif defined(__FreeBSD__) || defined(__DragonFly__)
53 #define OS_FREEBSD 1
54 #elif defined(__OpenBSD__)
55 #define OS_OPENBSD 1
56 #elif defined(__sun)
57 #define OS_SOLARIS 1
58 #elif defined(__QNXNTO__)
59 #define OS_QNX 1
60 #else
61 #error Please add support for your platform in build/build_config.h
62 #endif
63 
64 #if defined(USE_OPENSSL_CERTS) && defined(USE_NSS_CERTS)
65 #error Cannot use both OpenSSL and NSS for certificates
66 #endif
67 
68 // For access to standard BSD features, use OS_BSD instead of a
69 // more specific macro.
70 #if defined(OS_FREEBSD) || defined(OS_OPENBSD)
71 #define OS_BSD 1
72 #endif
73 
74 // For access to standard POSIXish features, use OS_POSIX instead of a
75 // more specific macro.
76 #if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_FREEBSD) ||     \
77     defined(OS_OPENBSD) || defined(OS_SOLARIS) || defined(OS_ANDROID) ||  \
78     defined(OS_NACL) || defined(OS_QNX)
79 #define OS_POSIX 1
80 #endif
81 
82 // Use tcmalloc
83 #if (defined(OS_WIN) || defined(OS_LINUX) || defined(OS_ANDROID)) && \
84     !defined(NO_TCMALLOC)
85 #define USE_TCMALLOC 1
86 #endif
87 
88 // Compiler detection.
89 #if defined(__GNUC__)
90 #define COMPILER_GCC 1
91 #elif defined(_MSC_VER)
92 #define COMPILER_MSVC 1
93 #else
94 #error Please add support for your compiler in build/build_config.h
95 #endif
96 
97 // Processor architecture detection.  For more info on what's defined, see:
98 //   http://msdn.microsoft.com/en-us/library/b0084kay.aspx
99 //   http://www.agner.org/optimize/calling_conventions.pdf
100 //   or with gcc, run: "echo | gcc -E -dM -"
101 #if defined(_M_ARM)
102 #define ARCH_CPU_ARM_FAMILY 1
103 #define ARCH_CPU_ARMEL 1
104 #define ARCH_CPU_32_BITS 1
105 #define ARCH_CPU_LITTLE_ENDIAN 1
106 #elif defined(_M_X64) || defined(__x86_64__)
107 #define ARCH_CPU_X86_FAMILY 1
108 #define ARCH_CPU_X86_64 1
109 #define ARCH_CPU_64_BITS 1
110 #define ARCH_CPU_LITTLE_ENDIAN 1
111 #elif defined(_M_IX86) || defined(__i386__)
112 #define ARCH_CPU_X86_FAMILY 1
113 #define ARCH_CPU_X86 1
114 #define ARCH_CPU_32_BITS 1
115 #define ARCH_CPU_LITTLE_ENDIAN 1
116 #elif defined(__ARMEL__)
117 #define ARCH_CPU_ARM_FAMILY 1
118 #define ARCH_CPU_ARMEL 1
119 #define ARCH_CPU_32_BITS 1
120 #define ARCH_CPU_LITTLE_ENDIAN 1
121 #elif defined(__aarch64__)
122 #define ARCH_CPU_ARM_FAMILY 1
123 #define ARCH_CPU_ARM64 1
124 #define ARCH_CPU_64_BITS 1
125 #define ARCH_CPU_LITTLE_ENDIAN 1
126 #elif defined(__pnacl__)
127 #define ARCH_CPU_32_BITS 1
128 #define ARCH_CPU_LITTLE_ENDIAN 1
129 #elif defined(__MIPSEL__)
130 #if defined(__LP64__)
131 #define ARCH_CPU_MIPS64_FAMILY 1
132 #define ARCH_CPU_MIPS64EL 1
133 #define ARCH_CPU_64_BITS 1
134 #define ARCH_CPU_LITTLE_ENDIAN 1
135 #else
136 #define ARCH_CPU_MIPS_FAMILY 1
137 #define ARCH_CPU_MIPSEL 1
138 #define ARCH_CPU_32_BITS 1
139 #define ARCH_CPU_LITTLE_ENDIAN 1
140 #endif
141 #elif (defined(__PPC64__) || defined(__PPC__)) && defined(__BIG_ENDIAN__)
142 #define ARCH_CPU_PPC64_FAMILY 1
143 #define ARCH_CPU_PPC64 1
144 #define ARCH_CPU_64_BITS 1
145 #define ARCH_CPU_BIG_ENDIAN 1
146 #elif defined(__PPC64__)
147 #define ARCH_CPU_PPC64_FAMILY 1
148 #define ARCH_CPU_PPC64 1
149 #define ARCH_CPU_64_BITS 1
150 #define ARCH_CPU_LITTLE_ENDIAN 1
151 #elif defined(__riscv) || defined(__riscv__)
152 #define ARCH_CPU_RISCV_FAMILY 1
153 #define ARCH_CPU_RISCV 1
154 #define ARCH_CPU_LITTLE_ENDIAN 1
155 #if defined(__riscv_xlen)
156 # if (__riscv_xlen == 64)
157 #  define ARCH_CPU_64_BITS 1
158 # else
159 #  define ARCH_CPU_32_BITS 1
160 # endif
161 #endif
162 # else
163 #error Please add support for your architecture in build/build_config.
164 #endif
165 
166 // Type detection for wchar_t.
167 #if defined(OS_WIN)
168 #define WCHAR_T_IS_UTF16
169 #elif defined(OS_POSIX) && defined(COMPILER_GCC) && \
170     defined(__WCHAR_MAX__) && \
171     (__WCHAR_MAX__ == 0x7fffffff || __WCHAR_MAX__ == 0xffffffff)
172 #define WCHAR_T_IS_UTF32
173 #elif defined(OS_POSIX) && defined(COMPILER_GCC) && \
174     defined(__WCHAR_MAX__) && \
175     (__WCHAR_MAX__ == 0x7fff || __WCHAR_MAX__ == 0xffff)
176 // On Posix, we'll detect short wchar_t, but projects aren't guaranteed to
177 // compile in this mode (in particular, Chrome doesn't). This is intended for
178 // other projects using base who manage their own dependencies and make sure
179 // short wchar works for them.
180 #define WCHAR_T_IS_UTF16
181 #else
182 #error Please add support for your compiler in build/build_config.h
183 #endif
184 
185 #if defined(OS_ANDROID)
186 // The compiler thinks std::string::const_iterator and "const char*" are
187 // equivalent types.
188 #define STD_STRING_ITERATOR_IS_CHAR_POINTER
189 // The compiler thinks base::string16::const_iterator and "char16*" are
190 // equivalent types.
191 #define BASE_STRING16_ITERATOR_IS_CHAR16_POINTER
192 #endif
193 
194 #endif  // BUILD_BUILD_CONFIG_H_
195