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 // OS_CHROMEOS is set by the build system 10 // Compiler: 11 // COMPILER_MSVC / COMPILER_GCC 12 // Processor: 13 // ARCH_CPU_X86 / ARCH_CPU_X86_64 / ARCH_CPU_X86_FAMILY (X86 or X86_64) 14 // ARCH_CPU_32_BITS / ARCH_CPU_64_BITS 15 16 #ifndef BUILD_BUILD_CONFIG_H_ 17 #define BUILD_BUILD_CONFIG_H_ 18 19 // A brief primer on #defines: 20 // 21 // - __ANDROID__ is automatically defined by the Android toolchain (see 22 // https://goo.gl/v61lXa). It's not defined when building host code. 23 // - __ANDROID_HOST__ is defined via -D by Android.mk when building host code 24 // within an Android checkout. 25 // - ANDROID is defined via -D when building code for either Android targets or 26 // hosts. Use __ANDROID__ and __ANDROID_HOST__ instead. 27 // - OS_ANDROID is a Chrome-specific define used to build Chrome for Android 28 // within the NDK. 29 30 // Android targets and hosts don't use tcmalloc. 31 #if defined(__ANDROID__) || defined(__ANDROID_HOST__) 32 #define NO_TCMALLOC 33 #endif // defined(__ANDROID__) || defined(__ANDROID_HOST__) 34 35 // Use the Chrome OS version of the code for both Android targets and Chrome OS builds. 36 #if !defined(__ANDROID_HOST__) 37 #define OS_CHROMEOS 1 38 #endif // !defined(__ANDROID_HOST__) 39 40 #if defined(__ANDROID__) // Android targets 41 42 #define __linux__ 1 43 44 #elif !defined(__ANDROID_HOST__) // Chrome OS 45 46 // TODO: Remove these once the GLib MessageLoopForUI isn't being used: 47 // https://crbug.com/361635 48 #define USE_GLIB 1 49 #define USE_OZONE 1 50 51 #endif // defined(__ANDROID__) 52 53 // A set of macros to use for platform detection. 54 #if defined(__native_client__) 55 // __native_client__ must be first, so that other OS_ defines are not set. 56 #define OS_NACL 1 57 // OS_NACL comes in two sandboxing technology flavors, SFI or Non-SFI. 58 // PNaCl toolchain defines __native_client_nonsfi__ macro in Non-SFI build 59 // mode, while it does not in SFI build mode. 60 #if defined(__native_client_nonsfi__) 61 #define OS_NACL_NONSFI 62 #else 63 #define OS_NACL_SFI 64 #endif 65 // Don't set OS_ANDROID; it's only used when building Chrome for Android. 66 #elif defined(__APPLE__) 67 // only include TargetConditions after testing ANDROID as some android builds 68 // on mac don't have this header available and it's not needed unless the target 69 // is really mac/ios. 70 #include <TargetConditionals.h> 71 #define OS_MACOSX 1 72 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE 73 #define OS_IOS 1 74 #endif // defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE 75 #elif defined(__linux__) 76 #define OS_LINUX 1 77 // include a system header to pull in features.h for glibc/uclibc macros. 78 #include <unistd.h> 79 #if defined(__GLIBC__) && !defined(__UCLIBC__) 80 // we really are using glibc, not uClibc pretending to be glibc 81 #define LIBC_GLIBC 1 82 #endif 83 #elif defined(_WIN32) 84 #define OS_WIN 1 85 #elif defined(__Fuchsia__) 86 #define OS_FUCHSIA 1 87 #elif defined(__FreeBSD__) 88 #define OS_FREEBSD 1 89 #elif defined(__NetBSD__) 90 #define OS_NETBSD 1 91 #elif defined(__OpenBSD__) 92 #define OS_OPENBSD 1 93 #elif defined(__sun) 94 #define OS_SOLARIS 1 95 #elif defined(__QNXNTO__) 96 #define OS_QNX 1 97 #elif defined(_AIX) 98 #define OS_AIX 1 99 #elif defined(__asmjs__) 100 #define OS_ASMJS 101 #else 102 #error Please add support for your platform in build/build_config.h 103 #endif 104 // NOTE: Adding a new port? Please follow 105 // https://chromium.googlesource.com/chromium/src/+/master/docs/new_port_policy.md 106 107 // For access to standard BSD features, use OS_BSD instead of a 108 // more specific macro. 109 #if defined(OS_FREEBSD) || defined(OS_NETBSD) || defined(OS_OPENBSD) 110 #define OS_BSD 1 111 #endif 112 113 // For access to standard POSIXish features, use OS_POSIX instead of a 114 // more specific macro. 115 #if defined(OS_AIX) || defined(OS_ANDROID) || defined(OS_ASMJS) || \ 116 defined(OS_FREEBSD) || defined(OS_LINUX) || defined(OS_MACOSX) || \ 117 defined(OS_NACL) || defined(OS_NETBSD) || defined(OS_OPENBSD) || \ 118 defined(OS_QNX) || defined(OS_SOLARIS) 119 #define OS_POSIX 1 120 #endif 121 122 // Use tcmalloc 123 #if (defined(OS_WIN) || defined(OS_LINUX) || defined(OS_ANDROID)) && \ 124 !defined(NO_TCMALLOC) 125 #define USE_TCMALLOC 1 126 #endif 127 128 // Compiler detection. 129 #if defined(__GNUC__) 130 #define COMPILER_GCC 1 131 #elif defined(_MSC_VER) 132 #define COMPILER_MSVC 1 133 #else 134 #error Please add support for your compiler in build/build_config.h 135 #endif 136 137 // Processor architecture detection. For more info on what's defined, see: 138 // http://msdn.microsoft.com/en-us/library/b0084kay.aspx 139 // http://www.agner.org/optimize/calling_conventions.pdf 140 // or with gcc, run: "echo | gcc -E -dM -" 141 #if defined(_M_X64) || defined(__x86_64__) 142 #define ARCH_CPU_X86_FAMILY 1 143 #define ARCH_CPU_X86_64 1 144 #define ARCH_CPU_64_BITS 1 145 #define ARCH_CPU_LITTLE_ENDIAN 1 146 #elif defined(_M_IX86) || defined(__i386__) 147 #define ARCH_CPU_X86_FAMILY 1 148 #define ARCH_CPU_X86 1 149 #define ARCH_CPU_32_BITS 1 150 #define ARCH_CPU_LITTLE_ENDIAN 1 151 #elif defined(__s390x__) 152 #define ARCH_CPU_S390_FAMILY 1 153 #define ARCH_CPU_S390X 1 154 #define ARCH_CPU_64_BITS 1 155 #define ARCH_CPU_BIG_ENDIAN 1 156 #elif defined(__s390__) 157 #define ARCH_CPU_S390_FAMILY 1 158 #define ARCH_CPU_S390 1 159 #define ARCH_CPU_31_BITS 1 160 #define ARCH_CPU_BIG_ENDIAN 1 161 #elif (defined(__PPC64__) || defined(__PPC__)) && defined(__BIG_ENDIAN__) 162 #define ARCH_CPU_PPC64_FAMILY 1 163 #define ARCH_CPU_PPC64 1 164 #define ARCH_CPU_64_BITS 1 165 #define ARCH_CPU_BIG_ENDIAN 1 166 #elif defined(__PPC64__) 167 #define ARCH_CPU_PPC64_FAMILY 1 168 #define ARCH_CPU_PPC64 1 169 #define ARCH_CPU_64_BITS 1 170 #define ARCH_CPU_LITTLE_ENDIAN 1 171 #elif defined(__ARMEL__) 172 #define ARCH_CPU_ARM_FAMILY 1 173 #define ARCH_CPU_ARMEL 1 174 #define ARCH_CPU_32_BITS 1 175 #define ARCH_CPU_LITTLE_ENDIAN 1 176 #elif defined(__aarch64__) 177 #define ARCH_CPU_ARM_FAMILY 1 178 #define ARCH_CPU_ARM64 1 179 #define ARCH_CPU_64_BITS 1 180 #define ARCH_CPU_LITTLE_ENDIAN 1 181 #elif defined(__pnacl__) || defined(__asmjs__) 182 #define ARCH_CPU_32_BITS 1 183 #define ARCH_CPU_LITTLE_ENDIAN 1 184 #elif defined(__MIPSEL__) 185 #if defined(__LP64__) 186 #define ARCH_CPU_MIPS_FAMILY 1 187 #define ARCH_CPU_MIPS64EL 1 188 #define ARCH_CPU_64_BITS 1 189 #define ARCH_CPU_LITTLE_ENDIAN 1 190 #else 191 #define ARCH_CPU_MIPS_FAMILY 1 192 #define ARCH_CPU_MIPSEL 1 193 #define ARCH_CPU_32_BITS 1 194 #define ARCH_CPU_LITTLE_ENDIAN 1 195 #endif 196 #elif defined(__MIPSEB__) 197 #if defined(__LP64__) 198 #define ARCH_CPU_MIPS_FAMILY 1 199 #define ARCH_CPU_MIPS64 1 200 #define ARCH_CPU_64_BITS 1 201 #define ARCH_CPU_BIG_ENDIAN 1 202 #else 203 #define ARCH_CPU_MIPS_FAMILY 1 204 #define ARCH_CPU_MIPS 1 205 #define ARCH_CPU_32_BITS 1 206 #define ARCH_CPU_BIG_ENDIAN 1 207 #endif 208 #else 209 #error Please add support for your architecture in build/build_config.h 210 #endif 211 212 // Type detection for wchar_t. 213 #if defined(OS_WIN) 214 #define WCHAR_T_IS_UTF16 215 #elif defined(OS_FUCHSIA) 216 #define WCHAR_T_IS_UTF32 217 #elif defined(OS_POSIX) && defined(COMPILER_GCC) && defined(__WCHAR_MAX__) && \ 218 (__WCHAR_MAX__ == 0x7fffffff || __WCHAR_MAX__ == 0xffffffff) 219 #define WCHAR_T_IS_UTF32 220 #elif defined(OS_POSIX) && defined(COMPILER_GCC) && defined(__WCHAR_MAX__) && \ 221 (__WCHAR_MAX__ == 0x7fff || __WCHAR_MAX__ == 0xffff) 222 // On Posix, we'll detect short wchar_t, but projects aren't guaranteed to 223 // compile in this mode (in particular, Chrome doesn't). This is intended for 224 // other projects using base who manage their own dependencies and make sure 225 // short wchar works for them. 226 #define WCHAR_T_IS_UTF16 227 #else 228 #error Please add support for your compiler in build/build_config.h 229 #endif 230 231 #if defined(OS_ANDROID) 232 // The compiler thinks std::string::const_iterator and "const char*" are 233 // equivalent types. 234 #define STD_STRING_ITERATOR_IS_CHAR_POINTER 235 // The compiler thinks base::string16::const_iterator and "char16*" are 236 // equivalent types. 237 #define BASE_STRING16_ITERATOR_IS_CHAR16_POINTER 238 #endif 239 240 #endif // BUILD_BUILD_CONFIG_H_ 241