1 # 2 # Copyright (C) 2011 The Android Open Source Project 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 # 16 17 ifndef ART_ANDROID_COMMON_BUILD_MK 18 ART_ANDROID_COMMON_BUILD_MK = true 19 20 include art/build/Android.common.mk 21 include art/build/Android.common_utils.mk 22 23 # These can be overridden via the environment or by editing to 24 # enable/disable certain build configuration. 25 # 26 # For example, to disable everything but the host debug build you use: 27 # 28 # (export ART_BUILD_TARGET_NDEBUG=false && export ART_BUILD_TARGET_DEBUG=false && export ART_BUILD_HOST_NDEBUG=false && ...) 29 # 30 # Beware that tests may use the non-debug build for performance, notable 055-enum-performance 31 # 32 ART_BUILD_TARGET_NDEBUG ?= true 33 ART_BUILD_TARGET_DEBUG ?= true 34 ART_BUILD_HOST_NDEBUG ?= true 35 ART_BUILD_HOST_DEBUG ?= true 36 37 # Set this to change what opt level Art is built at. 38 ART_DEBUG_OPT_FLAG ?= -O2 39 ART_NDEBUG_OPT_FLAG ?= -O3 40 41 # Enable the static builds only for checkbuilds. 42 ifneq (,$(filter checkbuild,$(MAKECMDGOALS))) 43 ART_BUILD_HOST_STATIC ?= true 44 else 45 ART_BUILD_HOST_STATIC ?= false 46 endif 47 48 # Asan does not support static linkage 49 ifdef SANITIZE_HOST 50 ART_BUILD_HOST_STATIC := false 51 endif 52 53 ifneq ($(HOST_OS),linux) 54 ART_BUILD_HOST_STATIC := false 55 endif 56 57 ifeq ($(ART_BUILD_TARGET_NDEBUG),false) 58 $(info Disabling ART_BUILD_TARGET_NDEBUG) 59 endif 60 ifeq ($(ART_BUILD_TARGET_DEBUG),false) 61 $(info Disabling ART_BUILD_TARGET_DEBUG) 62 endif 63 ifeq ($(ART_BUILD_HOST_NDEBUG),false) 64 $(info Disabling ART_BUILD_HOST_NDEBUG) 65 endif 66 ifeq ($(ART_BUILD_HOST_DEBUG),false) 67 $(info Disabling ART_BUILD_HOST_DEBUG) 68 endif 69 ifeq ($(ART_BUILD_HOST_STATIC),true) 70 $(info Enabling ART_BUILD_HOST_STATIC) 71 endif 72 73 ifeq ($(ART_TEST_DEBUG_GC),true) 74 ART_DEFAULT_GC_TYPE := SS 75 ART_USE_TLAB := true 76 endif 77 78 # 79 # Used to enable JIT 80 # 81 ART_JIT := false 82 ifneq ($(wildcard art/JIT_ART),) 83 $(info Enabling ART_JIT because of existence of art/JIT_ART) 84 ART_JIT := true 85 endif 86 ifeq ($(WITH_ART_JIT), true) 87 ART_JIT := true 88 endif 89 90 # 91 # Used to change the default GC. Valid values are CMS, SS, GSS. The default is CMS. 92 # 93 ART_DEFAULT_GC_TYPE ?= CMS 94 art_default_gc_type_cflags := -DART_DEFAULT_GC_TYPE_IS_$(ART_DEFAULT_GC_TYPE) 95 96 ART_HOST_CFLAGS := 97 ART_TARGET_CFLAGS := 98 99 ART_HOST_ASFLAGS := 100 ART_TARGET_ASFLAGS := 101 102 # Clang build support. 103 104 # Host. 105 ART_HOST_CLANG := false 106 ifneq ($(WITHOUT_HOST_CLANG),true) 107 # By default, host builds use clang for better warnings. 108 ART_HOST_CLANG := true 109 endif 110 111 # Clang on the target. Target builds use GCC by default. 112 ifneq ($(USE_CLANG_PLATFORM_BUILD),) 113 ART_TARGET_CLANG := $(USE_CLANG_PLATFORM_BUILD) 114 else 115 ART_TARGET_CLANG := false 116 endif 117 ART_TARGET_CLANG_arm := 118 ART_TARGET_CLANG_arm64 := 119 ART_TARGET_CLANG_mips := 120 ART_TARGET_CLANG_mips64 := 121 ART_TARGET_CLANG_x86 := 122 ART_TARGET_CLANG_x86_64 := 123 124 define set-target-local-clang-vars 125 LOCAL_CLANG := $(ART_TARGET_CLANG) 126 $(foreach arch,$(ART_TARGET_SUPPORTED_ARCH), 127 ifneq ($$(ART_TARGET_CLANG_$(arch)),) 128 LOCAL_CLANG_$(arch) := $$(ART_TARGET_CLANG_$(arch)) 129 endif) 130 endef 131 132 ART_TARGET_CLANG_CFLAGS := 133 ART_TARGET_CLANG_CFLAGS_arm := 134 ART_TARGET_CLANG_CFLAGS_arm64 := 135 ART_TARGET_CLANG_CFLAGS_mips := 136 ART_TARGET_CLANG_CFLAGS_mips64 := 137 ART_TARGET_CLANG_CFLAGS_x86 := 138 ART_TARGET_CLANG_CFLAGS_x86_64 := 139 140 # Warn about thread safety violations with clang. 141 art_clang_cflags := -Wthread-safety -Wthread-safety-negative 142 143 # Warn if switch fallthroughs aren't annotated. 144 art_clang_cflags += -Wimplicit-fallthrough 145 146 # Enable float equality warnings. 147 art_clang_cflags += -Wfloat-equal 148 149 # Enable warning of converting ints to void*. 150 art_clang_cflags += -Wint-to-void-pointer-cast 151 152 # Enable warning of wrong unused annotations. 153 art_clang_cflags += -Wused-but-marked-unused 154 155 # Enable warning for deprecated language features. 156 art_clang_cflags += -Wdeprecated 157 158 # Enable warning for unreachable break & return. 159 art_clang_cflags += -Wunreachable-code-break -Wunreachable-code-return 160 161 # Enable missing-noreturn only on non-Mac. As lots of things are not implemented for Apple, it's 162 # a pain. 163 ifneq ($(HOST_OS),darwin) 164 art_clang_cflags += -Wmissing-noreturn 165 endif 166 167 168 # GCC-only warnings. 169 art_gcc_cflags := -Wunused-but-set-parameter 170 # Suggest const: too many false positives, but good for a trial run. 171 # -Wsuggest-attribute=const 172 # Useless casts: too many, as we need to be 32/64 agnostic, but the compiler knows. 173 # -Wuseless-cast 174 # Zero-as-null: Have to convert all NULL and "diagnostic ignore" all includes like libnativehelper 175 # that are still stuck pre-C++11. 176 # -Wzero-as-null-pointer-constant \ 177 # Suggest final: Have to move to a more recent GCC. 178 # -Wsuggest-final-types 179 180 ART_TARGET_CLANG_CFLAGS := $(art_clang_cflags) 181 ifeq ($(ART_HOST_CLANG),true) 182 # Bug: 15446488. We don't omit the frame pointer to work around 183 # clang/libunwind bugs that cause SEGVs in run-test-004-ThreadStress. 184 ART_HOST_CFLAGS += $(art_clang_cflags) -fno-omit-frame-pointer 185 else 186 ART_HOST_CFLAGS += $(art_gcc_cflags) 187 endif 188 ifneq ($(ART_TARGET_CLANG),true) 189 ART_TARGET_CFLAGS += $(art_gcc_cflags) 190 else 191 # TODO: if we ever want to support GCC/Clang mix for multi-target products, this needs to be 192 # split up. 193 ifeq ($(ART_TARGET_CLANG_$(TARGET_ARCH)),false) 194 ART_TARGET_CFLAGS += $(art_gcc_cflags) 195 endif 196 endif 197 198 # Clear local variables now their use has ended. 199 art_clang_cflags := 200 art_gcc_cflags := 201 202 ART_CPP_EXTENSION := .cc 203 204 ART_C_INCLUDES := \ 205 external/gtest/include \ 206 external/icu/icu4c/source/common \ 207 external/lz4/lib \ 208 external/valgrind/include \ 209 external/valgrind \ 210 external/vixl/src \ 211 external/zlib \ 212 213 # We optimize Thread::Current() with a direct TLS access. This requires access to a private 214 # Bionic header. 215 # Note: technically we only need this on device, but this avoids the duplication of the includes. 216 ART_C_INCLUDES += bionic/libc/private 217 218 # Base set of cflags used by all things ART. 219 art_cflags := \ 220 -fno-rtti \ 221 -std=gnu++11 \ 222 -ggdb3 \ 223 -Wall \ 224 -Werror \ 225 -Wextra \ 226 -Wstrict-aliasing \ 227 -fstrict-aliasing \ 228 -Wunreachable-code \ 229 -Wredundant-decls \ 230 -Wshadow \ 231 -Wunused \ 232 -fvisibility=protected \ 233 $(art_default_gc_type_cflags) 234 235 # The architectures the compiled tools are able to run on. Setting this to 'all' will cause all 236 # architectures to be included. 237 ART_TARGET_CODEGEN_ARCHS ?= all 238 ART_HOST_CODEGEN_ARCHS ?= all 239 240 ifeq ($(ART_TARGET_CODEGEN_ARCHS),all) 241 ART_TARGET_CODEGEN_ARCHS := $(sort $(ART_TARGET_SUPPORTED_ARCH) $(ART_HOST_SUPPORTED_ARCH)) 242 # We need to handle the fact that some compiler tests mix code from different architectures. 243 ART_TARGET_COMPILER_TESTS ?= true 244 else 245 ART_TARGET_COMPILER_TESTS := false 246 ifeq ($(ART_TARGET_CODEGEN_ARCHS),svelte) 247 ART_TARGET_CODEGEN_ARCHS := $(sort $(ART_TARGET_ARCH_64) $(ART_TARGET_ARCH_32)) 248 endif 249 endif 250 ifeq ($(ART_HOST_CODEGEN_ARCHS),all) 251 ART_HOST_CODEGEN_ARCHS := $(sort $(ART_TARGET_SUPPORTED_ARCH) $(ART_HOST_SUPPORTED_ARCH)) 252 ART_HOST_COMPILER_TESTS ?= true 253 else 254 ART_HOST_COMPILER_TESTS := false 255 ifeq ($(ART_HOST_CODEGEN_ARCHS),svelte) 256 ART_HOST_CODEGEN_ARCHS := $(sort $(ART_TARGET_CODEGEN_ARCHS) $(ART_HOST_ARCH_64) $(ART_HOST_ARCH_32)) 257 endif 258 endif 259 260 ifneq (,$(filter arm64,$(ART_TARGET_CODEGEN_ARCHS))) 261 ART_TARGET_CODEGEN_ARCHS += arm 262 endif 263 ifneq (,$(filter mips64,$(ART_TARGET_CODEGEN_ARCHS))) 264 ART_TARGET_CODEGEN_ARCHS += mips 265 endif 266 ifneq (,$(filter x86_64,$(ART_TARGET_CODEGEN_ARCHS))) 267 ART_TARGET_CODEGEN_ARCHS += x86 268 endif 269 ART_TARGET_CODEGEN_ARCHS := $(sort $(ART_TARGET_CODEGEN_ARCHS)) 270 ifneq (,$(filter arm64,$(ART_HOST_CODEGEN_ARCHS))) 271 ART_HOST_CODEGEN_ARCHS += arm 272 endif 273 ifneq (,$(filter mips64,$(ART_HOST_CODEGEN_ARCHS))) 274 ART_HOST_CODEGEN_ARCHS += mips 275 endif 276 ifneq (,$(filter x86_64,$(ART_HOST_CODEGEN_ARCHS))) 277 ART_HOST_CODEGEN_ARCHS += x86 278 endif 279 ART_HOST_CODEGEN_ARCHS := $(sort $(ART_HOST_CODEGEN_ARCHS)) 280 281 # Base set of cflags used by target build only 282 art_target_cflags := \ 283 $(foreach target_arch,$(strip $(ART_TARGET_CODEGEN_ARCHS)), -DART_ENABLE_CODEGEN_$(target_arch)) 284 # Base set of cflags used by host build only 285 art_host_cflags := \ 286 $(foreach host_arch,$(strip $(ART_HOST_CODEGEN_ARCHS)), -DART_ENABLE_CODEGEN_$(host_arch)) 287 288 # Base set of asflags used by all things ART. 289 art_asflags := 290 291 # Missing declarations: too many at the moment, as we use "extern" quite a bit. 292 # -Wmissing-declarations \ 293 294 295 296 ifdef ART_IMT_SIZE 297 art_cflags += -DIMT_SIZE=$(ART_IMT_SIZE) 298 else 299 # Default is 64 300 art_cflags += -DIMT_SIZE=64 301 endif 302 303 ifeq ($(ART_HEAP_POISONING),true) 304 art_cflags += -DART_HEAP_POISONING=1 305 art_asflags += -DART_HEAP_POISONING=1 306 endif 307 308 # 309 # Used to change the read barrier type. Valid values are BAKER, BROOKS, TABLELOOKUP. 310 # The default is BAKER. 311 # 312 ART_READ_BARRIER_TYPE ?= BAKER 313 314 ifeq ($(ART_USE_READ_BARRIER),true) 315 art_cflags += -DART_USE_READ_BARRIER=1 316 art_cflags += -DART_READ_BARRIER_TYPE_IS_$(ART_READ_BARRIER_TYPE)=1 317 art_asflags += -DART_USE_READ_BARRIER=1 318 art_asflags += -DART_READ_BARRIER_TYPE_IS_$(ART_READ_BARRIER_TYPE)=1 319 320 # Temporarily override -fstack-protector-strong with -fstack-protector to avoid a major 321 # slowdown with the read barrier config. b/26744236. 322 art_cflags += -fstack-protector 323 endif 324 325 ifeq ($(ART_USE_TLAB),true) 326 art_cflags += -DART_USE_TLAB=1 327 endif 328 329 # Cflags for non-debug ART and ART tools. 330 art_non_debug_cflags := \ 331 $(ART_NDEBUG_OPT_FLAG) 332 333 # Cflags for debug ART and ART tools. 334 art_debug_cflags := \ 335 $(ART_DEBUG_OPT_FLAG) \ 336 -DDYNAMIC_ANNOTATIONS_ENABLED=1 \ 337 -UNDEBUG 338 339 art_host_non_debug_cflags := $(art_non_debug_cflags) 340 art_target_non_debug_cflags := $(art_non_debug_cflags) 341 342 ifeq ($(HOST_OS),linux) 343 # Larger frame-size for host clang builds today 344 ifneq ($(ART_COVERAGE),true) 345 ifneq ($(NATIVE_COVERAGE),true) 346 art_host_non_debug_cflags += -Wframe-larger-than=2700 347 ifdef SANITIZE_TARGET 348 art_target_non_debug_cflags += -Wframe-larger-than=6400 349 else 350 art_target_non_debug_cflags += -Wframe-larger-than=1728 351 endif 352 endif 353 endif 354 endif 355 356 ifndef LIBART_IMG_HOST_BASE_ADDRESS 357 $(error LIBART_IMG_HOST_BASE_ADDRESS unset) 358 endif 359 ART_HOST_CFLAGS += $(art_cflags) -DART_BASE_ADDRESS=$(LIBART_IMG_HOST_BASE_ADDRESS) 360 ART_HOST_CFLAGS += -DART_DEFAULT_INSTRUCTION_SET_FEATURES=default $(art_host_cflags) 361 ART_HOST_ASFLAGS += $(art_asflags) 362 363 ifndef LIBART_IMG_TARGET_BASE_ADDRESS 364 $(error LIBART_IMG_TARGET_BASE_ADDRESS unset) 365 endif 366 ART_TARGET_CFLAGS += $(art_cflags) -DART_TARGET -DART_BASE_ADDRESS=$(LIBART_IMG_TARGET_BASE_ADDRESS) 367 ART_TARGET_CFLAGS += $(art_target_cflags) 368 ART_TARGET_ASFLAGS += $(art_asflags) 369 370 ART_HOST_NON_DEBUG_CFLAGS := $(art_host_non_debug_cflags) 371 ART_TARGET_NON_DEBUG_CFLAGS := $(art_target_non_debug_cflags) 372 ART_HOST_DEBUG_CFLAGS := $(art_debug_cflags) 373 ART_TARGET_DEBUG_CFLAGS := $(art_debug_cflags) 374 375 ifndef LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA 376 LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA=-0x1000000 377 endif 378 ifndef LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA 379 LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA=0x1000000 380 endif 381 ART_HOST_CFLAGS += -DART_BASE_ADDRESS_MIN_DELTA=$(LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA) 382 ART_HOST_CFLAGS += -DART_BASE_ADDRESS_MAX_DELTA=$(LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA) 383 384 ifndef LIBART_IMG_TARGET_MIN_BASE_ADDRESS_DELTA 385 LIBART_IMG_TARGET_MIN_BASE_ADDRESS_DELTA=-0x1000000 386 endif 387 ifndef LIBART_IMG_TARGET_MAX_BASE_ADDRESS_DELTA 388 LIBART_IMG_TARGET_MAX_BASE_ADDRESS_DELTA=0x1000000 389 endif 390 ART_TARGET_CFLAGS += -DART_BASE_ADDRESS_MIN_DELTA=$(LIBART_IMG_TARGET_MIN_BASE_ADDRESS_DELTA) 391 ART_TARGET_CFLAGS += -DART_BASE_ADDRESS_MAX_DELTA=$(LIBART_IMG_TARGET_MAX_BASE_ADDRESS_DELTA) 392 393 # To use oprofile_android --callgraph, uncomment this and recompile with "mmm art -B -j16" 394 # ART_TARGET_CFLAGS += -fno-omit-frame-pointer -marm -mapcs 395 396 # Clear locals now they've served their purpose. 397 art_cflags := 398 art_asflags := 399 art_host_cflags := 400 art_target_cflags := 401 art_debug_cflags := 402 art_non_debug_cflags := 403 art_host_non_debug_cflags := 404 art_target_non_debug_cflags := 405 art_default_gc_type_cflags := 406 407 ART_HOST_LDLIBS := 408 ifneq ($(ART_HOST_CLANG),true) 409 # GCC lacks libc++ assumed atomic operations, grab via libatomic. 410 ART_HOST_LDLIBS += -latomic 411 endif 412 413 ART_TARGET_LDFLAGS := 414 415 # $(1): ndebug_or_debug 416 define set-target-local-cflags-vars 417 LOCAL_CFLAGS += $(ART_TARGET_CFLAGS) 418 LOCAL_CFLAGS_x86 += $(ART_TARGET_CFLAGS_x86) 419 LOCAL_ASFLAGS += $(ART_TARGET_ASFLAGS) 420 LOCAL_LDFLAGS += $(ART_TARGET_LDFLAGS) 421 art_target_cflags_ndebug_or_debug := $(1) 422 ifeq ($$(art_target_cflags_ndebug_or_debug),debug) 423 LOCAL_CFLAGS += $(ART_TARGET_DEBUG_CFLAGS) 424 else 425 LOCAL_CFLAGS += $(ART_TARGET_NON_DEBUG_CFLAGS) 426 endif 427 428 LOCAL_CLANG_CFLAGS := $(ART_TARGET_CLANG_CFLAGS) 429 $(foreach arch,$(ART_TARGET_SUPPORTED_ARCH), 430 LOCAL_CLANG_CFLAGS_$(arch) += $$(ART_TARGET_CLANG_CFLAGS_$(arch))) 431 432 # Clear locally used variables. 433 art_target_cflags_ndebug_or_debug := 434 endef 435 436 # Support for disabling certain builds. 437 ART_BUILD_TARGET := false 438 ART_BUILD_HOST := false 439 ART_BUILD_NDEBUG := false 440 ART_BUILD_DEBUG := false 441 ifeq ($(ART_BUILD_TARGET_NDEBUG),true) 442 ART_BUILD_TARGET := true 443 ART_BUILD_NDEBUG := true 444 endif 445 ifeq ($(ART_BUILD_TARGET_DEBUG),true) 446 ART_BUILD_TARGET := true 447 ART_BUILD_DEBUG := true 448 endif 449 ifeq ($(ART_BUILD_HOST_NDEBUG),true) 450 ART_BUILD_HOST := true 451 ART_BUILD_NDEBUG := true 452 endif 453 ifeq ($(ART_BUILD_HOST_DEBUG),true) 454 ART_BUILD_HOST := true 455 ART_BUILD_DEBUG := true 456 endif 457 458 endif # ART_ANDROID_COMMON_BUILD_MK 459