Home | History | Annotate | Download | only in core
      1 ###########################################################
      2 ## Standard rules for building binary object files from
      3 ## asm/c/cpp/yacc/lex/etc source files.
      4 ##
      5 ## The list of object files is exported in $(all_objects).
      6 ###########################################################
      7 
      8 #######################################
      9 include $(BUILD_SYSTEM)/base_rules.mk
     10 include $(BUILD_SYSTEM)/use_lld_setup.mk
     11 #######################################
     12 
     13 ##################################################
     14 # Compute the dependency of the shared libraries
     15 ##################################################
     16 # On the target, we compile with -nostdlib, so we must add in the
     17 # default system shared libraries, unless they have requested not
     18 # to by supplying a LOCAL_SYSTEM_SHARED_LIBRARIES value.  One would
     19 # supply that, for example, when building libc itself.
     20 ifdef LOCAL_IS_HOST_MODULE
     21   ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
     22       my_system_shared_libraries :=
     23   else
     24       my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES)
     25   endif
     26 else
     27   ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
     28       my_system_shared_libraries := libc libm libdl
     29   else
     30       my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES)
     31       my_system_shared_libraries := $(patsubst libc,libc libdl,$(my_system_shared_libraries))
     32   endif
     33 endif
     34 
     35 my_soong_problems :=
     36 
     37 # The following LOCAL_ variables will be modified in this file.
     38 # Because the same LOCAL_ variables may be used to define modules for both 1st arch and 2nd arch,
     39 # we can't modify them in place.
     40 my_src_files := $(LOCAL_SRC_FILES)
     41 my_src_files_exclude := $(LOCAL_SRC_FILES_EXCLUDE)
     42 my_static_libraries := $(LOCAL_STATIC_LIBRARIES)
     43 my_whole_static_libraries := $(LOCAL_WHOLE_STATIC_LIBRARIES)
     44 my_shared_libraries := $(filter-out $(my_system_shared_libraries),$(LOCAL_SHARED_LIBRARIES))
     45 my_header_libraries := $(LOCAL_HEADER_LIBRARIES)
     46 my_cflags := $(LOCAL_CFLAGS)
     47 my_conlyflags := $(LOCAL_CONLYFLAGS)
     48 my_cppflags := $(LOCAL_CPPFLAGS)
     49 my_cflags_no_override := $(GLOBAL_CLANG_CFLAGS_NO_OVERRIDE)
     50 my_cppflags_no_override := $(GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE)
     51 my_ldflags := $(LOCAL_LDFLAGS)
     52 my_ldlibs := $(LOCAL_LDLIBS)
     53 my_asflags := $(LOCAL_ASFLAGS)
     54 my_cc := $(LOCAL_CC)
     55 my_cc_wrapper := $(CC_WRAPPER)
     56 my_cxx := $(LOCAL_CXX)
     57 my_cxx_ldlibs :=
     58 my_cxx_wrapper := $(CXX_WRAPPER)
     59 my_c_includes := $(LOCAL_C_INCLUDES)
     60 my_generated_sources := $(LOCAL_GENERATED_SOURCES)
     61 my_additional_dependencies := $(LOCAL_ADDITIONAL_DEPENDENCIES)
     62 my_export_c_include_dirs := $(LOCAL_EXPORT_C_INCLUDE_DIRS)
     63 my_export_c_include_deps := $(LOCAL_EXPORT_C_INCLUDE_DEPS)
     64 my_arflags :=
     65 
     66 ifneq (,$(strip $(foreach dir,$(COVERAGE_PATHS),$(filter $(dir)%,$(LOCAL_PATH)))))
     67 ifeq (,$(strip $(foreach dir,$(COVERAGE_EXCLUDE_PATHS),$(filter $(dir)%,$(LOCAL_PATH)))))
     68   my_native_coverage := true
     69 else
     70   my_native_coverage := false
     71 endif
     72 else
     73   my_native_coverage := false
     74 endif
     75 ifneq ($(NATIVE_COVERAGE),true)
     76   my_native_coverage := false
     77 endif
     78 
     79 ifneq ($(strip $(ENABLE_XOM)),false)
     80   ifndef LOCAL_IS_HOST_MODULE
     81     my_xom := true
     82     # Disable XOM in excluded paths.
     83     combined_xom_exclude_paths := $(XOM_EXCLUDE_PATHS) \
     84                                   $(PRODUCT_XOM_EXCLUDE_PATHS)
     85     ifneq ($(strip $(foreach dir,$(subst $(comma),$(space),$(combined_xom_exclude_paths)),\
     86            $(filter $(dir)%,$(LOCAL_PATH)))),)
     87       my_xom := false
     88     endif
     89 
     90     # Allow LOCAL_XOM to override the above
     91     ifdef LOCAL_XOM
     92       my_xom := $(LOCAL_XOM)
     93     endif
     94 
     95     ifeq ($(strip $(my_xom)),true)
     96       ifeq (arm64,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
     97         ifeq ($(my_use_clang_lld),true)
     98           my_ldflags += -Wl,-execute-only
     99         endif
    100       endif
    101     endif
    102   endif
    103 endif
    104 
    105 my_allow_undefined_symbols := $(strip $(LOCAL_ALLOW_UNDEFINED_SYMBOLS))
    106 ifdef SANITIZE_HOST
    107 ifdef LOCAL_IS_HOST_MODULE
    108 my_allow_undefined_symbols := true
    109 endif
    110 endif
    111 
    112 my_ndk_sysroot :=
    113 my_ndk_sysroot_include :=
    114 my_ndk_sysroot_lib :=
    115 ifneq ($(LOCAL_SDK_VERSION),)
    116   ifdef LOCAL_IS_HOST_MODULE
    117     $(error $(LOCAL_PATH): LOCAL_SDK_VERSION cannot be used in host module)
    118   endif
    119 
    120   # Make sure we've built the NDK.
    121   my_additional_dependencies += $(SOONG_OUT_DIR)/ndk_base.timestamp
    122 
    123   # mips32r6 is not supported by the NDK. No released NDK contains these
    124   # libraries, but the r10 in prebuilts/ndk had a local hack to add them :(
    125   #
    126   # We need to find a real solution to this problem, but until we do just drop
    127   # mips32r6 things back to r10 to get the tree building again.
    128   ifeq (mips32r6,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH_VARIANT))
    129     ifeq ($(LOCAL_NDK_VERSION), current)
    130       LOCAL_NDK_VERSION := r10
    131     endif
    132   endif
    133 
    134   my_arch := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
    135   ifneq (,$(filter arm64 mips64 x86_64,$(my_arch)))
    136     my_min_sdk_version := 21
    137   else
    138     my_min_sdk_version := $(MIN_SUPPORTED_SDK_VERSION)
    139   endif
    140 
    141   # Historically we've just set up a bunch of symlinks in prebuilts/ndk to map
    142   # missing API levels to existing ones where necessary, but we're not doing
    143   # that for the generated libraries. Clip the API level to the minimum where
    144   # appropriate.
    145   my_ndk_api := $(LOCAL_SDK_VERSION)
    146   ifneq ($(my_ndk_api),current)
    147     my_ndk_api := $(call math_max,$(my_ndk_api),$(my_min_sdk_version))
    148   endif
    149 
    150   my_ndk_api_def := $(my_ndk_api)
    151   my_ndk_hist_api := $(my_ndk_api)
    152   ifeq ($(my_ndk_api),current)
    153     my_ndk_api_def := __ANDROID_API_FUTURE__
    154     # The last API level supported by the old prebuilt NDKs.
    155     my_ndk_hist_api := 24
    156   endif
    157 
    158 
    159   # Traditionally this has come from android/api-level.h, but with the libc
    160   # headers unified it must be set by the build system since we don't have
    161   # per-API level copies of that header now.
    162   my_cflags += -D__ANDROID_API__=$(my_ndk_api_def)
    163 
    164   my_ndk_source_root := \
    165       $(HISTORICAL_NDK_VERSIONS_ROOT)/$(LOCAL_NDK_VERSION)/sources
    166   my_ndk_sysroot := \
    167     $(HISTORICAL_NDK_VERSIONS_ROOT)/$(LOCAL_NDK_VERSION)/platforms/android-$(my_ndk_hist_api)/arch-$(my_arch)
    168   my_built_ndk := $(SOONG_OUT_DIR)/ndk
    169   my_ndk_triple := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_NDK_TRIPLE)
    170   my_ndk_sysroot_include := \
    171       $(my_built_ndk)/sysroot/usr/include \
    172       $(my_built_ndk)/sysroot/usr/include/$(my_ndk_triple) \
    173       $(my_ndk_sysroot)/usr/include \
    174 
    175   # x86_64 and and mips64 are both multilib toolchains, so their libraries are
    176   # installed in /usr/lib64. Aarch64, on the other hand, is not a multilib
    177   # compiler, so its libraries are in /usr/lib.
    178   #
    179   # Mips32r6 is yet another variation, with libraries installed in libr6.
    180   #
    181   # For the rest, the libraries are installed simply to /usr/lib.
    182   ifneq (,$(filter x86_64 mips64,$(my_arch)))
    183     my_ndk_libdir_name := lib64
    184   else ifeq (mips32r6,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH_VARIANT))
    185     my_ndk_libdir_name := libr6
    186   else
    187     my_ndk_libdir_name := lib
    188   endif
    189 
    190   my_ndk_platform_dir := \
    191       $(my_built_ndk)/platforms/android-$(my_ndk_api)/arch-$(my_arch)
    192   my_built_ndk_libs := $(my_ndk_platform_dir)/usr/$(my_ndk_libdir_name)
    193   my_ndk_sysroot_lib := $(my_ndk_sysroot)/usr/$(my_ndk_libdir_name)
    194 
    195   # The bionic linker now has support for packed relocations and gnu style
    196   # hashes (which are much faster!), but shipping to older devices requires
    197   # the old style hash. Fortunately, we can build with both and it'll work
    198   # anywhere.
    199   #
    200   # This is not currently supported on MIPS architectures.
    201   ifeq (,$(filter mips mips64,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)))
    202     my_ldflags += -Wl,--hash-style=both
    203   endif
    204 
    205   # We don't want to expose the relocation packer to the NDK just yet.
    206   LOCAL_PACK_MODULE_RELOCATIONS := false
    207 
    208   # Set up the NDK stl variant. Starting from NDK-r5 the c++ stl resides in a separate location.
    209   # See ndk/docs/CPLUSPLUS-SUPPORT.html
    210   my_ndk_stl_include_path :=
    211   my_ndk_stl_shared_lib_fullpath :=
    212   my_ndk_stl_static_lib :=
    213   my_cpu_variant := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)
    214   ifeq (mips32r6,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH_VARIANT))
    215     my_cpu_variant := mips32r6
    216   endif
    217   LOCAL_NDK_STL_VARIANT := $(strip $(LOCAL_NDK_STL_VARIANT))
    218   ifeq (,$(LOCAL_NDK_STL_VARIANT))
    219     LOCAL_NDK_STL_VARIANT := system
    220   endif
    221   ifneq (1,$(words $(filter none system c++_static c++_shared, $(LOCAL_NDK_STL_VARIANT))))
    222     $(error $(LOCAL_PATH): Unknown LOCAL_NDK_STL_VARIANT $(LOCAL_NDK_STL_VARIANT))
    223   endif
    224 
    225   ifeq (system,$(LOCAL_NDK_STL_VARIANT))
    226     my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/system/include
    227     my_system_shared_libraries += libstdc++
    228   else ifneq (,$(filter c++_%, $(LOCAL_NDK_STL_VARIANT)))
    229     my_ndk_stl_include_path := \
    230       $(my_ndk_source_root)/cxx-stl/llvm-libc++/include
    231     my_ndk_stl_include_path += \
    232       $(my_ndk_source_root)/cxx-stl/llvm-libc++abi/include
    233 
    234     my_libcxx_libdir := \
    235       $(my_ndk_source_root)/cxx-stl/llvm-libc++/libs/$(my_cpu_variant)
    236 
    237     ifeq (c++_static,$(LOCAL_NDK_STL_VARIANT))
    238       my_ndk_stl_static_lib := \
    239         $(my_libcxx_libdir)/libc++_static.a \
    240         $(my_libcxx_libdir)/libc++abi.a
    241     else
    242       my_ndk_stl_shared_lib_fullpath := $(my_libcxx_libdir)/libc++_shared.so
    243     endif
    244 
    245     ifneq ($(my_ndk_api),current)
    246       ifeq ($(call math_lt,$(my_ndk_api),21),true)
    247         my_ndk_stl_include_path += $(my_ndk_source_root)/android/support/include
    248         my_ndk_stl_static_lib += $(my_libcxx_libdir)/libandroid_support.a
    249       endif
    250     endif
    251 
    252     ifneq (,$(filter armeabi armeabi-v7a,$(my_cpu_variant)))
    253       my_ndk_stl_static_lib += $(my_libcxx_libdir)/libunwind.a
    254     endif
    255 
    256     my_ldlibs += -ldl
    257   else # LOCAL_NDK_STL_VARIANT must be none
    258     # Do nothing.
    259   endif
    260 
    261   # Clang's coverage/profile runtime needs symbols like 'stderr' that were not
    262   # exported from libc prior to API level 23
    263   ifneq ($(my_ndk_api),current)
    264     ifeq ($(call math_lt, $(my_ndk_api),23),true)
    265       my_native_coverage := false
    266     endif
    267   endif
    268 endif
    269 
    270 ifneq ($(LOCAL_USE_VNDK),)
    271   # Required VNDK version for vendor modules is BOARD_VNDK_VERSION.
    272   my_vndk_version := $(BOARD_VNDK_VERSION)
    273   ifeq ($(my_vndk_version),current)
    274     # Build with current PLATFORM_VNDK_VERSION.
    275     # If PLATFORM_VNDK_VERSION has a CODENAME, it will return
    276     # __ANDROID_API_FUTURE__.
    277     my_vndk_version := $(call codename-or-sdk-to-sdk,$(PLATFORM_VNDK_VERSION))
    278   endif
    279   my_cflags += -D__ANDROID_API__=$(my_vndk_version) -D__ANDROID_VNDK__
    280 endif
    281 
    282 ifndef LOCAL_IS_HOST_MODULE
    283 # For device libraries, move LOCAL_LDLIBS references to my_shared_libraries. We
    284 # no longer need to use my_ldlibs to pick up NDK prebuilt libraries since we're
    285 # linking my_shared_libraries by full path now.
    286 my_allowed_ldlibs :=
    287 
    288 # Sort ldlibs and ldflags between -l and other linker flags
    289 # We'll do this again later, since there are still changes happening, but that's fine.
    290 my_ldlib_flags := $(my_ldflags) $(my_ldlibs)
    291 my_ldlibs := $(filter -l%,$(my_ldlib_flags))
    292 my_ldflags := $(filter-out -l%,$(my_ldlib_flags))
    293 my_ldlib_flags :=
    294 
    295 # Move other ldlibs back to shared libraries
    296 my_shared_libraries += $(patsubst -l%,lib%,$(filter-out $(my_allowed_ldlibs),$(my_ldlibs)))
    297 my_ldlibs := $(filter $(my_allowed_ldlibs),$(my_ldlibs))
    298 else # LOCAL_IS_HOST_MODULE
    299   # Add -ldl, -lpthread, -lm and -lrt to host builds to match the default behavior of
    300   # device builds
    301   my_ldlibs += -ldl -lpthread -lm
    302   ifneq ($(HOST_OS),darwin)
    303     my_ldlibs += -lrt
    304   endif
    305 endif
    306 
    307 ifneq ($(LOCAL_SDK_VERSION),)
    308   my_all_ndk_libraries := \
    309       $(NDK_MIGRATED_LIBS) $(addprefix lib,$(NDK_PREBUILT_SHARED_LIBRARIES))
    310   my_ndk_shared_libraries := \
    311       $(filter $(my_all_ndk_libraries),\
    312         $(my_shared_libraries) $(my_system_shared_libraries))
    313 
    314   my_shared_libraries := \
    315       $(filter-out $(my_all_ndk_libraries),$(my_shared_libraries))
    316   my_system_shared_libraries := \
    317       $(filter-out $(my_all_ndk_libraries),$(my_system_shared_libraries))
    318 endif
    319 
    320 # MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because
    321 # all code is position independent, and then those warnings get promoted to
    322 # errors.
    323 ifneq ($(LOCAL_NO_PIC),true)
    324   ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),)
    325     my_cflags += -fPIE
    326     ifndef BUILD_HOST_static
    327       ifneq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
    328         my_ldflags += -pie
    329       endif
    330     endif
    331   else
    332     my_cflags += -fPIC
    333   endif
    334 endif
    335 
    336 ifdef LOCAL_IS_HOST_MODULE
    337 my_src_files += $(LOCAL_SRC_FILES_$($(my_prefix)OS)) $(LOCAL_SRC_FILES_$($(my_prefix)OS)_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
    338 my_static_libraries += $(LOCAL_STATIC_LIBRARIES_$($(my_prefix)OS))
    339 my_shared_libraries += $(LOCAL_SHARED_LIBRARIES_$($(my_prefix)OS))
    340 my_header_libraries += $(LOCAL_HEADER_LIBRARIES_$($(my_prefix)OS))
    341 my_cflags += $(LOCAL_CFLAGS_$($(my_prefix)OS))
    342 my_cppflags += $(LOCAL_CPPFLAGS_$($(my_prefix)OS))
    343 my_ldflags += $(LOCAL_LDFLAGS_$($(my_prefix)OS))
    344 my_ldlibs += $(LOCAL_LDLIBS_$($(my_prefix)OS))
    345 my_asflags += $(LOCAL_ASFLAGS_$($(my_prefix)OS))
    346 my_c_includes += $(LOCAL_C_INCLUDES_$($(my_prefix)OS))
    347 my_generated_sources += $(LOCAL_GENERATED_SOURCES_$($(my_prefix)OS))
    348 endif
    349 
    350 my_src_files += $(LOCAL_SRC_FILES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_SRC_FILES_$(my_32_64_bit_suffix))
    351 my_src_files_exclude += $(LOCAL_SRC_FILES_EXCLUDE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_SRC_FILES_EXCLUDE_$(my_32_64_bit_suffix))
    352 my_shared_libraries += $(LOCAL_SHARED_LIBRARIES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_SHARED_LIBRARIES_$(my_32_64_bit_suffix))
    353 my_cflags += $(LOCAL_CFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CFLAGS_$(my_32_64_bit_suffix))
    354 my_cppflags += $(LOCAL_CPPFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CPPFLAGS_$(my_32_64_bit_suffix))
    355 my_ldflags += $(LOCAL_LDFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_LDFLAGS_$(my_32_64_bit_suffix))
    356 my_asflags += $(LOCAL_ASFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_ASFLAGS_$(my_32_64_bit_suffix))
    357 my_c_includes += $(LOCAL_C_INCLUDES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_C_INCLUDES_$(my_32_64_bit_suffix))
    358 my_generated_sources += $(LOCAL_GENERATED_SOURCES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_GENERATED_SOURCES_$(my_32_64_bit_suffix))
    359 
    360 my_missing_exclude_files := $(filter-out $(my_src_files),$(my_src_files_exclude))
    361 ifneq ($(my_missing_exclude_files),)
    362 $(warning Files are listed in LOCAL_SRC_FILES_EXCLUDE but not LOCAL_SRC_FILES)
    363 $(error $(my_missing_exclude_files))
    364 endif
    365 my_src_files := $(filter-out $(my_src_files_exclude),$(my_src_files))
    366 
    367 # Strip '/' from the beginning of each src file. This helps the ../ detection in case
    368 # the source file is in the form of /../file
    369 my_src_files := $(patsubst /%,%,$(my_src_files))
    370 
    371 my_clang := $(strip $(LOCAL_CLANG))
    372 ifdef LOCAL_CLANG_$(my_32_64_bit_suffix)
    373 my_clang := $(strip $(LOCAL_CLANG_$(my_32_64_bit_suffix)))
    374 endif
    375 ifdef LOCAL_CLANG_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
    376 my_clang := $(strip $(LOCAL_CLANG_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)))
    377 endif
    378 ifeq ($(my_clang),false)
    379     $(call pretty-error,LOCAL_CLANG false is no longer supported)
    380 endif
    381 
    382 ifeq ($(LOCAL_C_STD),)
    383     my_c_std_version := $(DEFAULT_C_STD_VERSION)
    384 else ifeq ($(LOCAL_C_STD),experimental)
    385     my_c_std_version := $(EXPERIMENTAL_C_STD_VERSION)
    386 else
    387     my_c_std_version := $(LOCAL_C_STD)
    388 endif
    389 
    390 ifeq ($(LOCAL_CPP_STD),)
    391     my_cpp_std_version := $(DEFAULT_CPP_STD_VERSION)
    392 else ifeq ($(LOCAL_CPP_STD),experimental)
    393     my_cpp_std_version := $(EXPERIMENTAL_CPP_STD_VERSION)
    394 else
    395     my_cpp_std_version := $(LOCAL_CPP_STD)
    396 endif
    397 
    398 my_c_std_conlyflags :=
    399 my_cpp_std_cppflags :=
    400 ifneq (,$(my_c_std_version))
    401     my_c_std_conlyflags := -std=$(my_c_std_version)
    402 endif
    403 
    404 ifneq (,$(my_cpp_std_version))
    405    my_cpp_std_cppflags := -std=$(my_cpp_std_version)
    406 endif
    407 
    408 # Extra cflags for projects under external/ directory
    409 ifneq ($(filter external/%,$(LOCAL_PATH)),)
    410     my_cflags += $(CLANG_EXTERNAL_CFLAGS)
    411 endif
    412 
    413 # arch-specific static libraries go first so that generic ones can depend on them
    414 my_static_libraries := $(LOCAL_STATIC_LIBRARIES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_STATIC_LIBRARIES_$(my_32_64_bit_suffix)) $(my_static_libraries)
    415 my_whole_static_libraries := $(LOCAL_WHOLE_STATIC_LIBRARIES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_WHOLE_STATIC_LIBRARIES_$(my_32_64_bit_suffix)) $(my_whole_static_libraries)
    416 my_header_libraries := $(LOCAL_HEADER_LIBRARIES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_HEADER_LIBRARIES_$(my_32_64_bit_suffix)) $(my_header_libraries)
    417 
    418 include $(BUILD_SYSTEM)/cxx_stl_setup.mk
    419 
    420 # Add static HAL libraries
    421 ifdef LOCAL_HAL_STATIC_LIBRARIES
    422 $(foreach lib, $(LOCAL_HAL_STATIC_LIBRARIES), \
    423     $(eval b_lib := $(filter $(lib).%,$(BOARD_HAL_STATIC_LIBRARIES)))\
    424     $(if $(b_lib), $(eval my_static_libraries += $(b_lib)),\
    425                    $(eval my_static_libraries += $(lib).default)))
    426 b_lib :=
    427 endif
    428 
    429 ifneq ($(strip $(CUSTOM_$(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)LINKER)),)
    430   my_linker := $(CUSTOM_$(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)LINKER)
    431 else
    432   my_linker := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)LINKER)
    433 endif
    434 
    435 include $(BUILD_SYSTEM)/config_sanitizers.mk
    436 
    437 ifneq ($(filter ../%,$(my_src_files)),)
    438 my_soong_problems += dotdot_srcs
    439 endif
    440 ifneq ($(foreach i,$(my_c_includes),$(filter %/..,$(i))$(findstring /../,$(i))),)
    441 my_soong_problems += dotdot_incs
    442 endif
    443 
    444 ####################################################
    445 ## Add FDO flags if FDO is turned on and supported
    446 ## Please note that we will do option filtering during FDO build.
    447 ## i.e. Os->O2, remove -fno-early-inline and -finline-limit.
    448 ##################################################################
    449 my_fdo_build :=
    450 ifneq ($(filter true always, $(LOCAL_FDO_SUPPORT)),)
    451   ifeq ($(BUILD_FDO_INSTRUMENT),true)
    452     my_cflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_INSTRUMENT_CFLAGS)
    453     my_ldflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_INSTRUMENT_LDFLAGS)
    454     my_fdo_build := true
    455   else ifneq ($(filter true,$(BUILD_FDO_OPTIMIZE))$(filter always,$(LOCAL_FDO_SUPPORT)),)
    456     my_cflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_OPTIMIZE_CFLAGS)
    457     my_fdo_build := true
    458   endif
    459   # Disable ccache (or other compiler wrapper) except gomacc, which
    460   # can handle -fprofile-use properly.
    461   my_cc_wrapper := $(filter $(GOMA_CC),$(my_cc_wrapper))
    462   my_cxx_wrapper := $(filter $(GOMA_CC),$(my_cxx_wrapper))
    463 endif
    464 
    465 ###########################################################
    466 ## Explicitly declare assembly-only __ASSEMBLY__ macro for
    467 ## assembly source
    468 ###########################################################
    469 my_asflags += -D__ASSEMBLY__
    470 
    471 ###########################################################
    472 # TODO: support a mix of standard extensions so that this isn't necessary
    473 LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION))
    474 ifeq ($(LOCAL_CPP_EXTENSION),)
    475   LOCAL_CPP_EXTENSION := .cpp
    476 endif
    477 
    478 # Certain modules like libdl have to have symbols resolved at runtime and blow
    479 # up if --no-undefined is passed to the linker.
    480 ifeq ($(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS)),)
    481   ifeq ($(my_allow_undefined_symbols),)
    482     ifneq ($(HOST_OS),darwin)
    483       my_ldflags += -Wl,--no-undefined
    484     endif
    485   else
    486     ifdef LOCAL_IS_HOST_MODULE
    487       ifeq ($(HOST_OS),darwin)
    488         # darwin defaults to treating undefined symbols as errors
    489         my_ldflags += -Wl,-undefined,dynamic_lookup
    490       endif
    491     endif
    492   endif
    493 endif
    494 
    495 ifeq (true,$(LOCAL_GROUP_STATIC_LIBRARIES))
    496 $(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES := true
    497 else
    498 $(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES :=
    499 endif
    500 
    501 ###########################################################
    502 ## Define arm-vs-thumb-mode flags.
    503 ###########################################################
    504 LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE))
    505 ifeq ($($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH),arm)
    506 normal_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),thumb)
    507 
    508 # Read the values from something like TARGET_arm_CFLAGS or
    509 # TARGET_thumb_CFLAGS.  HOST_(arm|thumb)_CFLAGS values aren't
    510 # actually used (although they are usually empty).
    511 normal_objects_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)$(normal_objects_mode)_CFLAGS)
    512 
    513 else
    514 normal_objects_mode :=
    515 normal_objects_cflags :=
    516 endif
    517 
    518 ###########################################################
    519 ## Define per-module debugging flags.  Users can turn on
    520 ## debugging for a particular module by setting DEBUG_MODULE_ModuleName
    521 ## to a non-empty value in their environment or buildspec.mk,
    522 ## and setting HOST_/TARGET_CUSTOM_DEBUG_CFLAGS to the
    523 ## debug flags that they want to use.
    524 ###########################################################
    525 ifdef DEBUG_MODULE_$(strip $(LOCAL_MODULE))
    526   debug_cflags := $($(my_prefix)CUSTOM_DEBUG_CFLAGS)
    527 else
    528   debug_cflags :=
    529 endif
    530 
    531 ####################################################
    532 ## Keep track of src -> obj mapping
    533 ####################################################
    534 
    535 my_tracked_gen_files :=
    536 my_tracked_src_files :=
    537 
    538 ###########################################################
    539 ## Stuff source generated from one-off tools
    540 ###########################################################
    541 $(my_generated_sources): PRIVATE_MODULE := $(my_register_name)
    542 
    543 my_gen_sources_copy := $(patsubst $(generated_sources_dir)/%,$(intermediates)/%,$(filter $(generated_sources_dir)/%,$(my_generated_sources)))
    544 
    545 $(my_gen_sources_copy): $(intermediates)/% : $(generated_sources_dir)/%
    546 	@echo "Copy: $@"
    547 	$(copy-file-to-target)
    548 
    549 my_generated_sources := $(patsubst $(generated_sources_dir)/%,$(intermediates)/%,$(my_generated_sources))
    550 
    551 # Generated sources that will actually produce object files.
    552 # Other files (like headers) are allowed in LOCAL_GENERATED_SOURCES,
    553 # since other compiled sources may depend on them, and we set up
    554 # the dependencies.
    555 my_gen_src_files := $(filter %.c %$(LOCAL_CPP_EXTENSION) %.S %.s,$(my_generated_sources))
    556 
    557 ALL_GENERATED_SOURCES += $(my_generated_sources)
    558 
    559 ####################################################
    560 ## Compile RenderScript with reflected C++
    561 ####################################################
    562 
    563 renderscript_sources := $(filter %.rs %.fs,$(my_src_files))
    564 
    565 ifneq (,$(renderscript_sources))
    566 my_soong_problems += rs
    567 
    568 renderscript_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(renderscript_sources))
    569 RenderScript_file_stamp := $(intermediates)/RenderScriptCPP.stamp
    570 renderscript_intermediate := $(intermediates)/renderscript
    571 
    572 renderscript_target_api :=
    573 
    574 ifneq (,$(LOCAL_RENDERSCRIPT_TARGET_API))
    575 renderscript_target_api := $(LOCAL_RENDERSCRIPT_TARGET_API)
    576 else
    577 ifneq (,$(LOCAL_SDK_VERSION))
    578 # Set target-api for LOCAL_SDK_VERSIONs other than current.
    579 ifneq (,$(filter-out current system_current test_current, $(LOCAL_SDK_VERSION)))
    580 renderscript_target_api := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION))
    581 endif
    582 endif  # LOCAL_SDK_VERSION is set
    583 endif  # LOCAL_RENDERSCRIPT_TARGET_API is set
    584 
    585 
    586 ifeq ($(LOCAL_RENDERSCRIPT_CC),)
    587 LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC)
    588 endif
    589 
    590 # Turn on all warnings and warnings as errors for RS compiles.
    591 # This can be disabled with LOCAL_RENDERSCRIPT_FLAGS := -Wno-error
    592 renderscript_flags := -Wall -Werror
    593 renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS)
    594 # -m32 or -m64
    595 renderscript_flags += -m$(my_32_64_bit_suffix)
    596 
    597 renderscript_includes := \
    598     $(TOPDIR)external/clang/lib/Headers \
    599     $(TOPDIR)frameworks/rs/script_api/include \
    600     $(LOCAL_RENDERSCRIPT_INCLUDES)
    601 
    602 ifneq ($(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE),)
    603 renderscript_includes := $(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE)
    604 endif
    605 
    606 bc_dep_files := $(addprefix $(renderscript_intermediate)/, \
    607     $(patsubst %.fs,%.d, $(patsubst %.rs,%.d, $(notdir $(renderscript_sources)))))
    608 
    609 $(RenderScript_file_stamp): PRIVATE_RS_INCLUDES := $(renderscript_includes)
    610 $(RenderScript_file_stamp): PRIVATE_RS_CC := $(LOCAL_RENDERSCRIPT_CC)
    611 $(RenderScript_file_stamp): PRIVATE_RS_FLAGS := $(renderscript_flags)
    612 $(RenderScript_file_stamp): PRIVATE_RS_SOURCE_FILES := $(renderscript_sources_fullpath)
    613 $(RenderScript_file_stamp): PRIVATE_RS_OUTPUT_DIR := $(renderscript_intermediate)
    614 $(RenderScript_file_stamp): PRIVATE_RS_TARGET_API := $(patsubst current,0,$(renderscript_target_api))
    615 $(RenderScript_file_stamp): PRIVATE_DEP_FILES := $(bc_dep_files)
    616 $(RenderScript_file_stamp): $(renderscript_sources_fullpath) $(LOCAL_RENDERSCRIPT_CC)
    617 	$(transform-renderscripts-to-cpp-and-bc)
    618 
    619 # include the dependency files (.d) generated by llvm-rs-cc.
    620 $(call include-depfile,$(RenderScript_file_stamp).d,$(RenderScript_file_stamp))
    621 
    622 LOCAL_INTERMEDIATE_TARGETS += $(RenderScript_file_stamp)
    623 
    624 rs_generated_cpps := $(addprefix \
    625     $(renderscript_intermediate)/ScriptC_,$(patsubst %.fs,%.cpp, $(patsubst %.rs,%.cpp, \
    626     $(notdir $(renderscript_sources)))))
    627 
    628 $(call track-src-file-gen,$(renderscript_sources),$(rs_generated_cpps))
    629 
    630 # This is just a dummy rule to make sure gmake doesn't skip updating the dependents.
    631 $(rs_generated_cpps) : $(RenderScript_file_stamp)
    632 	@echo "Updated RS generated cpp file $@."
    633 	$(hide) touch $@
    634 
    635 my_c_includes += $(renderscript_intermediate)
    636 my_generated_sources += $(rs_generated_cpps)
    637 
    638 endif
    639 
    640 
    641 ###########################################################
    642 ## Compile the .proto files to .cc (or .c) and then to .o
    643 ###########################################################
    644 ifeq ($(strip $(LOCAL_PROTOC_OPTIMIZE_TYPE)),)
    645   LOCAL_PROTOC_OPTIMIZE_TYPE := lite
    646 endif
    647 proto_sources := $(filter %.proto,$(my_src_files))
    648 ifneq ($(proto_sources),)
    649 proto_gen_dir := $(generated_sources_dir)/proto
    650 proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources))
    651 
    652 my_rename_cpp_ext :=
    653 ifneq (,$(filter nanopb-c nanopb-c-enable_malloc nanopb-c-16bit nanopb-c-enable_malloc-16bit nanopb-c-32bit nanopb-c-enable_malloc-32bit, $(LOCAL_PROTOC_OPTIMIZE_TYPE)))
    654 my_proto_source_suffix := .c
    655 my_proto_c_includes := external/nanopb-c
    656 my_protoc_flags := --nanopb_out=$(proto_gen_dir) \
    657     --plugin=$(HOST_OUT_EXECUTABLES)/protoc-gen-nanopb
    658 my_protoc_deps := $(NANOPB_SRCS) $(proto_sources_fullpath:%.proto=%.options)
    659 else
    660 my_proto_source_suffix := $(LOCAL_CPP_EXTENSION)
    661 ifneq ($(my_proto_source_suffix),.cc)
    662 # aprotoc is hardcoded to write out only .cc file.
    663 # We need to rename the extension to $(LOCAL_CPP_EXTENSION) if it's not .cc.
    664 my_rename_cpp_ext := true
    665 endif
    666 my_proto_c_includes := external/protobuf/src
    667 my_cflags += -DGOOGLE_PROTOBUF_NO_RTTI
    668 my_protoc_flags := --cpp_out=$(if $(filter lite lite-static,$(LOCAL_PROTOC_OPTIMIZE_TYPE)),lite:,)$(proto_gen_dir)
    669 my_protoc_deps :=
    670 endif
    671 my_proto_c_includes += $(proto_gen_dir)
    672 
    673 proto_generated_cpps := $(addprefix $(proto_gen_dir)/, \
    674     $(patsubst %.proto,%.pb$(my_proto_source_suffix),$(proto_sources_fullpath)))
    675 
    676 # Ensure the transform-proto-to-cc rule is only defined once in multilib build.
    677 ifndef $(my_host)$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined
    678 $(proto_generated_cpps): PRIVATE_PROTO_INCLUDES := $(TOP)
    679 $(proto_generated_cpps): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS) $(my_protoc_flags)
    680 $(proto_generated_cpps): PRIVATE_RENAME_CPP_EXT := $(my_rename_cpp_ext)
    681 $(proto_generated_cpps): $(proto_gen_dir)/%.pb$(my_proto_source_suffix): %.proto $(my_protoc_deps) $(PROTOC)
    682 	$(transform-proto-to-cc)
    683 
    684 $(my_host)$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined := true
    685 endif
    686 # Ideally we can generate the source directly into $(intermediates).
    687 # But many Android.mks assume the .pb.hs are in $(generated_sources_dir).
    688 # As a workaround, we make a copy in the $(intermediates).
    689 proto_intermediate_dir := $(intermediates)/proto
    690 proto_intermediate_cpps := $(patsubst $(proto_gen_dir)/%,$(proto_intermediate_dir)/%,\
    691     $(proto_generated_cpps))
    692 $(proto_intermediate_cpps) : $(proto_intermediate_dir)/% : $(proto_gen_dir)/%
    693 	@echo "Copy: $@"
    694 	$(copy-file-to-target)
    695 	$(hide) cp $(basename $<).h $(basename $@).h
    696 $(call track-src-file-gen,$(proto_sources),$(proto_intermediate_cpps))
    697 
    698 my_generated_sources += $(proto_intermediate_cpps)
    699 
    700 my_c_includes += $(my_proto_c_includes)
    701 # Auto-export the generated proto source dir.
    702 my_export_c_include_dirs += $(my_proto_c_includes)
    703 
    704 ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c-enable_malloc)
    705     my_static_libraries += libprotobuf-c-nano-enable_malloc
    706 else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c)
    707     my_static_libraries += libprotobuf-c-nano
    708 else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c-enable_malloc-16bit)
    709     my_static_libraries += libprotobuf-c-nano-enable_malloc-16bit
    710 else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c-16bit)
    711     my_static_libraries += libprotobuf-c-nano-16bit
    712 else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c-enable_malloc-32bit)
    713     my_static_libraries += libprotobuf-c-nano-enable_malloc-32bit
    714 else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c-32bit)
    715     my_static_libraries += libprotobuf-c-nano-32bit
    716 else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),full)
    717     ifdef LOCAL_SDK_VERSION
    718         my_static_libraries += libprotobuf-cpp-full-ndk
    719     else
    720         my_shared_libraries += libprotobuf-cpp-full
    721     endif
    722 else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),lite-static)
    723     my_static_libraries += libprotobuf-cpp-lite
    724 else
    725     ifdef LOCAL_SDK_VERSION
    726         my_static_libraries += libprotobuf-cpp-lite-ndk
    727     else
    728         my_shared_libraries += libprotobuf-cpp-lite
    729     endif
    730 endif
    731 endif  # $(proto_sources) non-empty
    732 
    733 ###########################################################
    734 ## AIDL: Compile .aidl files to .cpp and .h files
    735 ###########################################################
    736 aidl_src := $(strip $(filter %.aidl,$(my_src_files)))
    737 aidl_gen_cpp :=
    738 ifneq ($(aidl_src),)
    739 
    740 # Use the intermediates directory to avoid writing our own .cpp -> .o rules.
    741 aidl_gen_cpp_root := $(intermediates)/aidl-generated/src
    742 aidl_gen_include_root := $(intermediates)/aidl-generated/include
    743 
    744 # Multi-architecture builds have distinct intermediates directories.
    745 # Thus we'll actually generate source for each architecture.
    746 $(foreach s,$(aidl_src),\
    747     $(eval $(call define-aidl-cpp-rule,$(s),$(aidl_gen_cpp_root),aidl_gen_cpp)))
    748 $(foreach cpp,$(aidl_gen_cpp), \
    749     $(call include-depfile,$(addsuffix .aidl.d,$(basename $(cpp))),$(cpp)))
    750 $(call track-src-file-gen,$(aidl_src),$(aidl_gen_cpp))
    751 
    752 $(aidl_gen_cpp) : PRIVATE_MODULE := $(LOCAL_MODULE)
    753 $(aidl_gen_cpp) : PRIVATE_HEADER_OUTPUT_DIR := $(aidl_gen_include_root)
    754 $(aidl_gen_cpp) : PRIVATE_AIDL_FLAGS := $(addprefix -I,$(LOCAL_AIDL_INCLUDES))
    755 
    756 # Add generated headers to include paths.
    757 my_c_includes += $(aidl_gen_include_root)
    758 my_export_c_include_dirs += $(aidl_gen_include_root)
    759 # Pick up the generated C++ files later for transformation to .o files.
    760 my_generated_sources += $(aidl_gen_cpp)
    761 
    762 endif  # $(aidl_src) non-empty
    763 
    764 ###########################################################
    765 ## Compile the .vts files to .cc (or .c) and then to .o
    766 ###########################################################
    767 
    768 vts_src := $(strip $(filter %.vts,$(my_src_files)))
    769 vts_gen_cpp :=
    770 ifneq ($(vts_src),)
    771 my_soong_problems += vts
    772 
    773 # Use the intermediates directory to avoid writing our own .cpp -> .o rules.
    774 vts_gen_cpp_root := $(intermediates)/vts-generated/src
    775 vts_gen_include_root := $(intermediates)/vts-generated/include
    776 
    777 # Multi-architecture builds have distinct intermediates directories.
    778 # Thus we'll actually generate source for each architecture.
    779 $(foreach s,$(vts_src),\
    780     $(eval $(call define-vts-cpp-rule,$(s),$(vts_gen_cpp_root),vts_gen_cpp)))
    781 $(call track-src-file-gen,$(vts_src),$(vts_gen_cpp))
    782 
    783 $(vts_gen_cpp) : PRIVATE_MODULE := $(LOCAL_MODULE)
    784 $(vts_gen_cpp) : PRIVATE_HEADER_OUTPUT_DIR := $(vts_gen_include_root)
    785 $(vts_gen_cpp) : PRIVATE_VTS_FLAGS := $(addprefix -I,$(LOCAL_VTS_INCLUDES)) $(addprefix -m,$(LOCAL_VTS_MODE))
    786 
    787 # Add generated headers to include paths.
    788 my_c_includes += $(vts_gen_include_root)
    789 my_export_c_include_dirs += $(vts_gen_include_root)
    790 # Pick up the generated C++ files later for transformation to .o files.
    791 my_generated_sources += $(vts_gen_cpp)
    792 
    793 endif  # $(vts_src) non-empty
    794 
    795 ###########################################################
    796 ## YACC: Compile .y/.yy files to .c/.cpp and then to .o.
    797 ###########################################################
    798 
    799 y_yacc_sources := $(filter %.y,$(my_src_files))
    800 y_yacc_cs := $(addprefix \
    801     $(intermediates)/,$(y_yacc_sources:.y=.c))
    802 ifneq ($(y_yacc_cs),)
    803 $(y_yacc_cs): $(intermediates)/%.c: \
    804     $(TOPDIR)$(LOCAL_PATH)/%.y $(BISON) $(BISON_DATA) \
    805     $(my_additional_dependencies)
    806 	$(call transform-y-to-c-or-cpp)
    807 $(call track-src-file-gen,$(y_yacc_sources),$(y_yacc_cs))
    808 
    809 my_generated_sources += $(y_yacc_cs)
    810 endif
    811 
    812 yy_yacc_sources := $(filter %.yy,$(my_src_files))
    813 yy_yacc_cpps := $(addprefix \
    814     $(intermediates)/,$(yy_yacc_sources:.yy=$(LOCAL_CPP_EXTENSION)))
    815 ifneq ($(yy_yacc_cpps),)
    816 $(yy_yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
    817     $(TOPDIR)$(LOCAL_PATH)/%.yy $(BISON) $(BISON_DATA) \
    818     $(my_additional_dependencies)
    819 	$(call transform-y-to-c-or-cpp)
    820 $(call track-src-file-gen,$(yy_yacc_sources),$(yy_yacc_cpps))
    821 
    822 my_generated_sources += $(yy_yacc_cpps)
    823 endif
    824 
    825 ###########################################################
    826 ## LEX: Compile .l/.ll files to .c/.cpp and then to .o.
    827 ###########################################################
    828 
    829 l_lex_sources := $(filter %.l,$(my_src_files))
    830 l_lex_cs := $(addprefix \
    831     $(intermediates)/,$(l_lex_sources:.l=.c))
    832 ifneq ($(l_lex_cs),)
    833 $(l_lex_cs): $(intermediates)/%.c: \
    834     $(TOPDIR)$(LOCAL_PATH)/%.l
    835 	$(transform-l-to-c-or-cpp)
    836 $(call track-src-file-gen,$(l_lex_sources),$(l_lex_cs))
    837 
    838 my_generated_sources += $(l_lex_cs)
    839 endif
    840 
    841 ll_lex_sources := $(filter %.ll,$(my_src_files))
    842 ll_lex_cpps := $(addprefix \
    843     $(intermediates)/,$(ll_lex_sources:.ll=$(LOCAL_CPP_EXTENSION)))
    844 ifneq ($(ll_lex_cpps),)
    845 $(ll_lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
    846     $(TOPDIR)$(LOCAL_PATH)/%.ll
    847 	$(transform-l-to-c-or-cpp)
    848 $(call track-src-file-gen,$(ll_lex_sources),$(ll_lex_cpps))
    849 
    850 my_generated_sources += $(ll_lex_cpps)
    851 endif
    852 
    853 ###########################################################
    854 ## C++: Compile .cpp files to .o.
    855 ###########################################################
    856 
    857 ifneq ($(filter %$(LOCAL_CPP_EXTENSION).arm,$(my_src_files)),)
    858 $(call pretty-error,Files ending in $(LOCAL_CPP_EXTENSION).arm are deprecated. See $(CHANGES_URL)#file_arm)
    859 endif
    860 
    861 dotdot_sources := $(filter ../%$(LOCAL_CPP_EXTENSION),$(my_src_files))
    862 dotdot_objects :=
    863 $(foreach s,$(dotdot_sources),\
    864   $(eval $(call compile-dotdot-cpp-file,$(s),\
    865     $(my_additional_dependencies),\
    866     dotdot_objects)))
    867 $(call track-src-file-obj,$(dotdot_sources),$(dotdot_objects))
    868 
    869 cpp_normal_sources := $(filter-out ../%,$(filter %$(LOCAL_CPP_EXTENSION),$(my_src_files)))
    870 cpp_objects := $(addprefix $(intermediates)/,$(cpp_normal_sources:$(LOCAL_CPP_EXTENSION)=.o))
    871 $(call track-src-file-obj,$(cpp_normal_sources),$(cpp_objects))
    872 
    873 $(dotdot_objects) $(cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
    874 $(dotdot_objects) $(cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
    875 
    876 ifneq ($(strip $(cpp_objects)),)
    877 $(cpp_objects): $(intermediates)/%.o: \
    878     $(TOPDIR)$(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) \
    879     $(my_additional_dependencies)
    880 	$(transform-$(PRIVATE_HOST)cpp-to-o)
    881 $(call include-depfiles-for-objs, $(cpp_objects))
    882 endif
    883 
    884 cpp_objects += $(dotdot_objects)
    885 
    886 ###########################################################
    887 ## C++: Compile generated .cpp files to .o.
    888 ###########################################################
    889 
    890 gen_cpp_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(my_generated_sources))
    891 gen_cpp_objects := $(gen_cpp_sources:%$(LOCAL_CPP_EXTENSION)=%.o)
    892 $(call track-gen-file-obj,$(gen_cpp_sources),$(gen_cpp_objects))
    893 
    894 ifneq ($(strip $(gen_cpp_objects)),)
    895 # Compile all generated files as thumb.
    896 $(gen_cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
    897 $(gen_cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
    898 $(gen_cpp_objects): $(intermediates)/%.o: \
    899     $(intermediates)/%$(LOCAL_CPP_EXTENSION) \
    900     $(my_additional_dependencies)
    901 	$(transform-$(PRIVATE_HOST)cpp-to-o)
    902 $(call include-depfiles-for-objs, $(gen_cpp_objects))
    903 endif
    904 
    905 ###########################################################
    906 ## S: Compile generated .S and .s files to .o.
    907 ###########################################################
    908 
    909 gen_S_sources := $(filter %.S,$(my_generated_sources))
    910 gen_S_objects := $(gen_S_sources:%.S=%.o)
    911 $(call track-gen-file-obj,$(gen_S_sources),$(gen_S_objects))
    912 
    913 ifneq ($(strip $(gen_S_sources)),)
    914 $(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S \
    915     $(my_additional_dependencies)
    916 	$(transform-$(PRIVATE_HOST)s-to-o)
    917 $(call include-depfiles-for-objs, $(gen_S_objects))
    918 endif
    919 
    920 gen_s_sources := $(filter %.s,$(my_generated_sources))
    921 gen_s_objects := $(gen_s_sources:%.s=%.o)
    922 $(call track-gen-file-obj,$(gen_s_sources),$(gen_s_objects))
    923 
    924 ifneq ($(strip $(gen_s_objects)),)
    925 $(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s \
    926     $(my_additional_dependencies)
    927 	$(transform-$(PRIVATE_HOST)s-to-o)
    928 endif
    929 
    930 gen_asm_objects := $(gen_S_objects) $(gen_s_objects)
    931 $(gen_asm_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
    932 
    933 ###########################################################
    934 ## o: Include generated .o files in output.
    935 ###########################################################
    936 
    937 gen_o_objects := $(filter %.o,$(my_generated_sources))
    938 
    939 ###########################################################
    940 ## C: Compile .c files to .o.
    941 ###########################################################
    942 
    943 ifneq ($(filter %.c.arm,$(my_src_files)),)
    944 $(call pretty-error,Files ending in .c.arm are deprecated. See $(CHANGES_URL)#file_arm)
    945 endif
    946 
    947 dotdot_sources := $(filter ../%.c, $(my_src_files))
    948 dotdot_objects :=
    949 $(foreach s, $(dotdot_sources),\
    950   $(eval $(call compile-dotdot-c-file,$(s),\
    951     $(my_additional_dependencies),\
    952     dotdot_objects)))
    953 $(call track-src-file-obj,$(dotdot_sources),$(dotdot_objects))
    954 
    955 c_normal_sources := $(filter-out ../%,$(filter %.c,$(my_src_files)))
    956 c_objects := $(addprefix $(intermediates)/,$(c_normal_sources:.c=.o))
    957 $(call track-src-file-obj,$(c_normal_sources),$(c_objects))
    958 
    959 $(dotdot_objects) $(c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
    960 $(dotdot_objects) $(c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
    961 
    962 ifneq ($(strip $(c_objects)),)
    963 $(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c \
    964     $(my_additional_dependencies)
    965 	$(transform-$(PRIVATE_HOST)c-to-o)
    966 $(call include-depfiles-for-objs, $(c_objects))
    967 endif
    968 
    969 c_objects += $(dotdot_objects)
    970 
    971 ###########################################################
    972 ## C: Compile generated .c files to .o.
    973 ###########################################################
    974 
    975 gen_c_sources := $(filter %.c,$(my_generated_sources))
    976 gen_c_objects := $(gen_c_sources:%.c=%.o)
    977 $(call track-gen-file-obj,$(gen_c_sources),$(gen_c_objects))
    978 
    979 ifneq ($(strip $(gen_c_objects)),)
    980 # Compile all generated files as thumb.
    981 $(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
    982 $(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
    983 $(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c \
    984     $(my_additional_dependencies)
    985 	$(transform-$(PRIVATE_HOST)c-to-o)
    986 $(call include-depfiles-for-objs, $(gen_c_objects))
    987 endif
    988 
    989 ###########################################################
    990 ## ObjC: Compile .m files to .o
    991 ###########################################################
    992 
    993 objc_sources := $(filter %.m,$(my_src_files))
    994 objc_objects := $(addprefix $(intermediates)/,$(objc_sources:.m=.o))
    995 $(call track-src-file-obj,$(objc_sources),$(objc_objects))
    996 
    997 ifneq ($(strip $(objc_objects)),)
    998 my_soong_problems += objc
    999 $(objc_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.m \
   1000     $(my_additional_dependencies)
   1001 	$(transform-$(PRIVATE_HOST)m-to-o)
   1002 $(call include-depfiles-for-objs, $(objc_objects))
   1003 endif
   1004 
   1005 ###########################################################
   1006 ## ObjC++: Compile .mm files to .o
   1007 ###########################################################
   1008 
   1009 objcpp_sources := $(filter %.mm,$(my_src_files))
   1010 objcpp_objects := $(addprefix $(intermediates)/,$(objcpp_sources:.mm=.o))
   1011 $(call track-src-file-obj,$(objcpp_sources),$(objcpp_objects))
   1012 
   1013 ifneq ($(strip $(objcpp_objects)),)
   1014 $(objcpp_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.mm \
   1015     $(my_additional_dependencies)
   1016 	$(transform-$(PRIVATE_HOST)mm-to-o)
   1017 $(call include-depfiles-for-objs, $(objcpp_objects))
   1018 endif
   1019 
   1020 ###########################################################
   1021 ## AS: Compile .S files to .o.
   1022 ###########################################################
   1023 
   1024 asm_sources_S := $(filter %.S,$(my_src_files))
   1025 dotdot_sources := $(filter ../%,$(asm_sources_S))
   1026 asm_sources_S := $(filter-out ../%,$(asm_sources_S))
   1027 asm_objects_S := $(addprefix $(intermediates)/,$(asm_sources_S:.S=.o))
   1028 $(call track-src-file-obj,$(asm_sources_S),$(asm_objects_S))
   1029 
   1030 dotdot_objects_S :=
   1031 $(foreach s,$(dotdot_sources),\
   1032   $(eval $(call compile-dotdot-s-file,$(s),\
   1033     $(my_additional_dependencies),\
   1034     dotdot_objects_S)))
   1035 $(call track-src-file-obj,$(dotdot_sources),$(dotdot_objects_S))
   1036 
   1037 ifneq ($(strip $(asm_objects_S)),)
   1038 $(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S \
   1039     $(my_additional_dependencies)
   1040 	$(transform-$(PRIVATE_HOST)s-to-o)
   1041 $(call include-depfiles-for-objs, $(asm_objects_S))
   1042 endif
   1043 
   1044 asm_sources_s := $(filter %.s,$(my_src_files))
   1045 dotdot_sources := $(filter ../%,$(asm_sources_s))
   1046 asm_sources_s := $(filter-out ../%,$(asm_sources_s))
   1047 asm_objects_s := $(addprefix $(intermediates)/,$(asm_sources_s:.s=.o))
   1048 $(call track-src-file-obj,$(asm_sources_s),$(asm_objects_s))
   1049 
   1050 dotdot_objects_s :=
   1051 $(foreach s,$(dotdot_sources),\
   1052   $(eval $(call compile-dotdot-s-file-no-deps,$(s),\
   1053     $(my_additional_dependencies),\
   1054     dotdot_objects_s)))
   1055 $(call track-src-file-obj,$(dotdot_sources),$(dotdot_objects_s))
   1056 
   1057 ifneq ($(strip $(asm_objects_s)),)
   1058 $(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s \
   1059     $(my_additional_dependencies)
   1060 	$(transform-$(PRIVATE_HOST)s-to-o)
   1061 endif
   1062 
   1063 asm_objects := $(dotdot_objects_S) $(dotdot_objects_s) $(asm_objects_S) $(asm_objects_s)
   1064 $(asm_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
   1065 
   1066 
   1067 # .asm for x86/x86_64 needs to be compiled with yasm.
   1068 asm_sources_asm := $(filter %.asm,$(my_src_files))
   1069 ifneq ($(strip $(asm_sources_asm)),)
   1070 asm_objects_asm := $(addprefix $(intermediates)/,$(asm_sources_asm:.asm=.o))
   1071 $(asm_objects_asm): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.asm \
   1072     $(my_additional_dependencies)
   1073 	$(transform-asm-to-o)
   1074 $(call track-src-file-obj,$(asm_sources_asm),$(asm_objects_asm))
   1075 
   1076 asm_objects += $(asm_objects_asm)
   1077 endif
   1078 
   1079 ###################################################################
   1080 ## When compiling a CFI enabled target, use the .cfi variant of any
   1081 ## static dependencies (where they exist).
   1082 ##################################################################
   1083 define use_soong_cfi_static_libraries
   1084   $(foreach l,$(1),$(if $(filter $(l),$(SOONG_CFI_STATIC_LIBRARIES)),\
   1085       $(l).cfi,$(l)))
   1086 endef
   1087 
   1088 ifneq ($(filter cfi,$(my_sanitize)),)
   1089   my_whole_static_libraries := $(call use_soong_cfi_static_libraries,\
   1090     $(my_whole_static_libraries))
   1091   my_static_libraries := $(call use_soong_cfi_static_libraries,\
   1092     $(my_static_libraries))
   1093 endif
   1094 
   1095 ifneq ($(LOCAL_USE_VNDK),)
   1096   my_soong_hwasan_static_libraries := $(SOONG_HWASAN_VENDOR_STATIC_LIBRARIES)
   1097 else
   1098   my_soong_hwasan_static_libraries = $(SOONG_HWASAN_STATIC_LIBRARIES)
   1099 endif
   1100 
   1101 define use_soong_hwasan_static_libraries
   1102   $(foreach l,$(1),$(if $(filter $(l),$(my_soong_hwasan_static_libraries)),\
   1103       $(l).hwasan,$(l)))
   1104 endef
   1105 
   1106 ifneq ($(filter hwaddress,$(my_sanitize)),)
   1107   my_whole_static_libraries := $(call use_soong_hwasan_static_libraries,\
   1108     $(my_whole_static_libraries))
   1109   my_static_libraries := $(call use_soong_hwasan_static_libraries,\
   1110     $(my_static_libraries))
   1111 endif
   1112 
   1113 ###########################################################
   1114 ## When compiling against the VNDK, use LL-NDK libraries
   1115 ###########################################################
   1116 ifneq ($(LOCAL_USE_VNDK),)
   1117   ####################################################
   1118   ## Soong modules may be built twice, once for /system
   1119   ## and once for /vendor. If we're using the VNDK,
   1120   ## switch all soong libraries over to the /vendor
   1121   ## variant.
   1122   ####################################################
   1123   my_whole_static_libraries := $(foreach l,$(my_whole_static_libraries),\
   1124     $(if $(SPLIT_VENDOR.STATIC_LIBRARIES.$(l)),$(l).vendor,$(l)))
   1125   my_static_libraries := $(foreach l,$(my_static_libraries),\
   1126     $(if $(SPLIT_VENDOR.STATIC_LIBRARIES.$(l)),$(l).vendor,$(l)))
   1127   my_shared_libraries := $(foreach l,$(my_shared_libraries),\
   1128     $(if $(SPLIT_VENDOR.SHARED_LIBRARIES.$(l)),$(l).vendor,$(l)))
   1129   my_system_shared_libraries := $(foreach l,$(my_system_shared_libraries),\
   1130     $(if $(SPLIT_VENDOR.SHARED_LIBRARIES.$(l)),$(l).vendor,$(l)))
   1131   my_header_libraries := $(foreach l,$(my_header_libraries),\
   1132     $(if $(SPLIT_VENDOR.HEADER_LIBRARIES.$(l)),$(l).vendor,$(l)))
   1133 endif
   1134 
   1135 # Platform can use vendor public libraries. If a required shared lib is one of
   1136 # the vendor public libraries, the lib is switched to the stub version of the lib.
   1137 ifeq ($(LOCAL_USE_VNDK),)
   1138   my_shared_libraries := $(foreach l,$(my_shared_libraries),\
   1139     $(if $(filter $(l),$(VENDOR_PUBLIC_LIBRARIES)),$(l).vendorpublic,$(l)))
   1140 endif
   1141 
   1142 ##########################################################
   1143 ## Set up installed module dependency
   1144 ## We cannot compute the full path of the LOCAL_SHARED_LIBRARIES for
   1145 ## they may cusomize their install path with LOCAL_MODULE_PATH
   1146 ##########################################################
   1147 # Get the list of INSTALLED libraries as module names.
   1148 ifneq ($(LOCAL_SDK_VERSION),)
   1149   installed_shared_library_module_names := \
   1150       $(my_shared_libraries)
   1151 else
   1152   installed_shared_library_module_names := \
   1153       $(my_shared_libraries) $(my_system_shared_libraries)
   1154 endif
   1155 
   1156 # The real dependency will be added after all Android.mks are loaded and the install paths
   1157 # of the shared libraries are determined.
   1158 ifdef LOCAL_INSTALLED_MODULE
   1159 ifdef installed_shared_library_module_names
   1160 $(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \
   1161     $(my_register_name):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(installed_shared_library_module_names))
   1162 endif
   1163 endif
   1164 
   1165 
   1166 ####################################################
   1167 ## Import includes
   1168 ####################################################
   1169 import_includes := $(intermediates)/import_includes
   1170 import_includes_deps := $(strip \
   1171     $(if $(LOCAL_USE_VNDK),\
   1172       $(call intermediates-dir-for,HEADER_LIBRARIES,device_kernel_headers,$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes) \
   1173     $(foreach l, $(installed_shared_library_module_names), \
   1174       $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes) \
   1175     $(foreach l, $(my_static_libraries) $(my_whole_static_libraries), \
   1176       $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes) \
   1177     $(foreach l, $(my_header_libraries), \
   1178       $(call intermediates-dir-for,HEADER_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes))
   1179 $(import_includes): PRIVATE_IMPORT_EXPORT_INCLUDES := $(import_includes_deps)
   1180 $(import_includes) : $(import_includes_deps)
   1181 	@echo Import includes file: $@
   1182 	$(hide) mkdir -p $(dir $@) && rm -f $@
   1183 ifdef import_includes_deps
   1184 	$(hide) for f in $(PRIVATE_IMPORT_EXPORT_INCLUDES); do \
   1185 	  cat $$f >> $@; \
   1186 	done
   1187 else
   1188 	$(hide) touch $@
   1189 endif
   1190 
   1191 ####################################################
   1192 ## Verify that NDK-built libraries only link against
   1193 ## other NDK-built libraries
   1194 ####################################################
   1195 
   1196 include $(BUILD_SYSTEM)/allowed_ndk_types.mk
   1197 
   1198 ifdef LOCAL_SDK_VERSION
   1199 my_link_type := native:ndk:$(my_ndk_stl_family):$(my_ndk_stl_link_type)
   1200 my_warn_types := $(my_warn_ndk_types)
   1201 my_allowed_types := $(my_allowed_ndk_types)
   1202 else ifdef LOCAL_USE_VNDK
   1203     _name := $(patsubst %.vendor,%,$(LOCAL_MODULE))
   1204     ifneq ($(filter $(_name),$(VNDK_CORE_LIBRARIES) $(VNDK_SAMEPROCESS_LIBRARIES) $(LLNDK_LIBRARIES)),)
   1205         ifeq ($(filter $(_name),$(VNDK_PRIVATE_LIBRARIES)),)
   1206             my_link_type := native:vndk
   1207         else
   1208             my_link_type := native:vndk_private
   1209         endif
   1210         my_warn_types :=
   1211         my_allowed_types := native:vndk native:vndk_private
   1212     else
   1213         # Modules installed to /vendor cannot directly depend on modules marked
   1214         # with vendor_available: false
   1215         my_link_type := native:vendor
   1216         my_warn_types :=
   1217         my_allowed_types := native:vendor native:vndk native:platform_vndk
   1218     endif
   1219 else ifneq ($(filter $(TARGET_RECOVERY_OUT)/%,$(call get_non_asan_path,$(LOCAL_MODULE_PATH))),)
   1220 my_link_type := native:recovery
   1221 my_warn_types :=
   1222 # TODO(b/113303515) remove native:platform and my_allowed_ndk_types
   1223 my_allowed_types := native:recovery native:platform native:platform_vndk $(my_allowed_ndk_types)
   1224 else
   1225 my_link_type := native:platform
   1226 my_warn_types := $(my_warn_ndk_types)
   1227 my_allowed_types := $(my_allowed_ndk_types) native:platform native:platform_vndk
   1228 endif
   1229 
   1230 my_link_deps := $(addprefix STATIC_LIBRARIES:,$(my_whole_static_libraries) $(my_static_libraries))
   1231 ifneq ($(filter-out STATIC_LIBRARIES HEADER_LIBRARIES,$(LOCAL_MODULE_CLASS)),)
   1232 my_link_deps += $(addprefix SHARED_LIBRARIES:,$(my_shared_libraries))
   1233 endif
   1234 
   1235 my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX)
   1236 my_common :=
   1237 include $(BUILD_SYSTEM)/link_type.mk
   1238 
   1239 ###########################################################
   1240 ## Common object handling.
   1241 ###########################################################
   1242 
   1243 my_unused_src_files := $(filter-out $(logtags_sources) $(my_tracked_src_files),$(my_src_files) $(my_gen_src_files))
   1244 ifneq ($(my_unused_src_files),)
   1245   $(error $(LOCAL_MODULE_MAKEFILE): $(LOCAL_MODULE): Unused source files: $(my_unused_src_files))
   1246 endif
   1247 
   1248 # some rules depend on asm_objects being first.  If your code depends on
   1249 # being first, it's reasonable to require it to be assembly
   1250 normal_objects := \
   1251     $(asm_objects) \
   1252     $(cpp_objects) \
   1253     $(gen_cpp_objects) \
   1254     $(gen_asm_objects) \
   1255     $(c_objects) \
   1256     $(gen_c_objects) \
   1257     $(objc_objects) \
   1258     $(objcpp_objects)
   1259 
   1260 new_order_normal_objects := $(foreach f,$(my_src_files),$(my_src_file_obj_$(f)))
   1261 new_order_normal_objects += $(foreach f,$(my_gen_src_files),$(my_src_file_obj_$(f)))
   1262 
   1263 ifneq ($(sort $(normal_objects)),$(sort $(new_order_normal_objects)))
   1264 $(warning $(LOCAL_MODULE_MAKEFILE) Internal build system warning: New object list does not match old)
   1265 $(info Only in old: $(filter-out $(new_order_normal_objects),$(sort $(normal_objects))))
   1266 $(info Only in new: $(filter-out $(normal_objects),$(sort $(new_order_normal_objects))))
   1267 endif
   1268 
   1269 ifeq ($(BINARY_OBJECTS_ORDER),soong)
   1270 normal_objects := $(new_order_normal_objects)
   1271 endif
   1272 
   1273 normal_objects += $(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES))
   1274 
   1275 all_objects := $(normal_objects) $(gen_o_objects)
   1276 
   1277 LOCAL_INTERMEDIATE_TARGETS += $(all_objects)
   1278 
   1279 # Cleanup file tracking
   1280 $(foreach f,$(my_tracked_gen_files),$(eval my_src_file_gen_$(s):=))
   1281 my_tracked_gen_files :=
   1282 $(foreach f,$(my_tracked_src_files),$(eval my_src_file_obj_$(s):=))
   1283 my_tracked_src_files :=
   1284 
   1285 my_c_includes += $(TOPDIR)$(LOCAL_PATH) $(intermediates) $(generated_sources_dir)
   1286 
   1287 # The platform JNI header is for platform modules only.
   1288 ifeq ($(LOCAL_SDK_VERSION)$(LOCAL_USE_VNDK),)
   1289   my_c_includes += $(JNI_H_INCLUDE)
   1290 endif
   1291 
   1292 my_outside_includes := $(filter-out $(OUT_DIR)/%,$(filter /%,$(my_c_includes)))
   1293 ifneq ($(my_outside_includes),)
   1294 $(error $(LOCAL_MODULE_MAKEFILE): $(LOCAL_MODULE): C_INCLUDES must be under the source or output directories: $(my_outside_includes))
   1295 endif
   1296 
   1297 # all_objects includes gen_o_objects which were part of LOCAL_GENERATED_SOURCES;
   1298 # use normal_objects here to avoid creating circular dependencies. This assumes
   1299 # that custom build rules which generate .o files don't consume other generated
   1300 # sources as input (or if they do they take care of that dependency themselves).
   1301 $(normal_objects) : | $(my_generated_sources)
   1302 $(all_objects) : $(import_includes)
   1303 ALL_C_CPP_ETC_OBJECTS += $(all_objects)
   1304 
   1305 
   1306 ###########################################################
   1307 # Standard library handling.
   1308 ###########################################################
   1309 
   1310 ###########################################################
   1311 # The list of libraries that this module will link against are in
   1312 # these variables.  Each is a list of bare module names like "libc libm".
   1313 #
   1314 # LOCAL_SHARED_LIBRARIES
   1315 # LOCAL_STATIC_LIBRARIES
   1316 # LOCAL_WHOLE_STATIC_LIBRARIES
   1317 #
   1318 # We need to convert the bare names into the dependencies that
   1319 # we'll use for LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE.
   1320 # LOCAL_BUILT_MODULE should depend on the BUILT versions of the
   1321 # libraries, so that simply building this module doesn't force
   1322 # an install of a library.  Similarly, LOCAL_INSTALLED_MODULE
   1323 # should depend on the INSTALLED versions of the libraries so
   1324 # that they get installed when this module does.
   1325 ###########################################################
   1326 # NOTE:
   1327 # WHOLE_STATIC_LIBRARIES are libraries that are pulled into the
   1328 # module without leaving anything out, which is useful for turning
   1329 # a collection of .a files into a .so file.  Linking against a
   1330 # normal STATIC_LIBRARY will only pull in code/symbols that are
   1331 # referenced by the module. (see gcc/ld's --whole-archive option)
   1332 ###########################################################
   1333 
   1334 # Get the list of BUILT libraries, which are under
   1335 # various intermediates directories.
   1336 so_suffix := $($(my_prefix)SHLIB_SUFFIX)
   1337 a_suffix := $($(my_prefix)STATIC_LIB_SUFFIX)
   1338 
   1339 ifneq ($(LOCAL_SDK_VERSION),)
   1340 built_shared_libraries := \
   1341     $(foreach lib,$(my_shared_libraries), \
   1342       $(call intermediates-dir-for, \
   1343         SHARED_LIBRARIES,$(lib),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/$(lib)$(so_suffix))
   1344 built_shared_library_deps := $(addsuffix .toc, $(built_shared_libraries))
   1345 
   1346 # Add the NDK libraries to the built module dependency
   1347 my_system_shared_libraries_fullpath := \
   1348     $(my_ndk_stl_shared_lib_fullpath) \
   1349     $(addprefix $(my_ndk_sysroot_lib)/, \
   1350         $(addsuffix $(so_suffix), $(my_system_shared_libraries)))
   1351 
   1352 # We need to preserve the ordering of LOCAL_SHARED_LIBRARIES regardless of
   1353 # whether the libs are generated or prebuilt, so we simply can't split into two
   1354 # lists and use addprefix.
   1355 my_ndk_shared_libraries_fullpath := \
   1356     $(foreach _lib,$(my_ndk_shared_libraries),\
   1357         $(if $(filter $(NDK_MIGRATED_LIBS),$(_lib)),\
   1358             $(my_built_ndk_libs)/$(_lib)$(so_suffix),\
   1359             $(my_ndk_sysroot_lib)/$(_lib)$(so_suffix)))
   1360 
   1361 built_shared_libraries += \
   1362     $(my_ndk_shared_libraries_fullpath) \
   1363     $(my_system_shared_libraries_fullpath) \
   1364 
   1365 else
   1366 built_shared_libraries := \
   1367     $(foreach lib,$(installed_shared_library_module_names), \
   1368       $(call intermediates-dir-for, \
   1369         SHARED_LIBRARIES,$(lib),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/$(lib)$(so_suffix))
   1370 built_shared_library_deps := $(addsuffix .toc, $(built_shared_libraries))
   1371 my_system_shared_libraries_fullpath :=
   1372 endif
   1373 
   1374 built_static_libraries := \
   1375     $(foreach lib,$(my_static_libraries), \
   1376       $(call intermediates-dir-for, \
   1377         STATIC_LIBRARIES,$(lib),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/$(lib)$(a_suffix))
   1378 
   1379 ifdef LOCAL_SDK_VERSION
   1380 built_static_libraries += $(my_ndk_stl_static_lib)
   1381 endif
   1382 
   1383 built_whole_libraries := \
   1384     $(foreach lib,$(my_whole_static_libraries), \
   1385       $(call intermediates-dir-for, \
   1386         STATIC_LIBRARIES,$(lib),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/$(lib)$(a_suffix))
   1387 
   1388 # We don't care about installed static libraries, since the
   1389 # libraries have already been linked into the module at that point.
   1390 # We do, however, care about the NOTICE files for any static
   1391 # libraries that we use. (see notice_files.mk)
   1392 #
   1393 # Don't do this in mm, since many of the targets won't exist.
   1394 ifeq ($(ONE_SHOT_MAKEFILE),)
   1395 installed_static_library_notice_file_targets := \
   1396     $(foreach lib,$(my_static_libraries) $(my_whole_static_libraries), \
   1397       NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST$(if $(my_host_cross),_CROSS,),TARGET)-STATIC_LIBRARIES-$(lib))
   1398 else
   1399 installed_static_library_notice_file_targets :=
   1400 endif
   1401 
   1402 $(notice_target): | $(installed_static_library_notice_file_targets)
   1403 $(LOCAL_INSTALLED_MODULE): | $(notice_target)
   1404 
   1405 # Default is -fno-rtti.
   1406 ifeq ($(strip $(LOCAL_RTTI_FLAG)),)
   1407 LOCAL_RTTI_FLAG := -fno-rtti
   1408 endif
   1409 
   1410 ###########################################################
   1411 # Rule-specific variable definitions
   1412 ###########################################################
   1413 
   1414 my_cflags += $(LOCAL_CLANG_CFLAGS)
   1415 my_conlyflags += $(LOCAL_CLANG_CONLYFLAGS)
   1416 my_cppflags += $(LOCAL_CLANG_CPPFLAGS)
   1417 my_asflags += $(LOCAL_CLANG_ASFLAGS)
   1418 my_ldflags += $(LOCAL_CLANG_LDFLAGS)
   1419 my_cflags += $(LOCAL_CLANG_CFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_CFLAGS_$(my_32_64_bit_suffix))
   1420 my_conlyflags += $(LOCAL_CLANG_CONLYFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_CONLYFLAGS_$(my_32_64_bit_suffix))
   1421 my_cppflags += $(LOCAL_CLANG_CPPFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_CPPFLAGS_$(my_32_64_bit_suffix))
   1422 my_ldflags += $(LOCAL_CLANG_LDFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_LDFLAGS_$(my_32_64_bit_suffix))
   1423 my_asflags += $(LOCAL_CLANG_ASFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_ASFLAGS_$(my_32_64_bit_suffix))
   1424 my_cflags := $(call convert-to-clang-flags,$(my_cflags))
   1425 my_cppflags := $(call convert-to-clang-flags,$(my_cppflags))
   1426 my_asflags := $(call convert-to-clang-flags,$(my_asflags))
   1427 my_ldflags := $(call convert-to-clang-flags,$(my_ldflags))
   1428 
   1429 ifeq ($(my_fdo_build), true)
   1430   my_cflags := $(patsubst -Os,-O2,$(my_cflags))
   1431   fdo_incompatible_flags := -fno-early-inlining -finline-limit=%
   1432   my_cflags := $(filter-out $(fdo_incompatible_flags),$(my_cflags))
   1433 endif
   1434 
   1435 # No one should ever use this flag. On GCC it's mere presence will disable all
   1436 # warnings, even those that are specified after it (contrary to typical warning
   1437 # flag behavior). This circumvents CFLAGS_NO_OVERRIDE from forcibly enabling the
   1438 # warnings that are *always* bugs.
   1439 my_illegal_flags := -w
   1440 my_cflags := $(filter-out $(my_illegal_flags),$(my_cflags))
   1441 my_cppflags := $(filter-out $(my_illegal_flags),$(my_cppflags))
   1442 my_conlyflags := $(filter-out $(my_illegal_flags),$(my_conlyflags))
   1443 
   1444 # We can enforce some rules more strictly in the code we own. my_strict
   1445 # indicates if this is code that we can be stricter with. If we have rules that
   1446 # we want to apply to *our* code (but maybe can't for vendor/device specific
   1447 # things), we could extend this to be a ternary value.
   1448 my_strict := true
   1449 ifneq ($(filter external/%,$(LOCAL_PATH)),)
   1450     my_strict := false
   1451 endif
   1452 
   1453 # Can be used to make some annotations stricter for code we can fix (such as
   1454 # when we mark functions as deprecated).
   1455 ifeq ($(my_strict),true)
   1456     my_cflags += -DANDROID_STRICT
   1457 endif
   1458 
   1459 # Check if -Werror or -Wno-error is used in C compiler flags.
   1460 # Header libraries do not need cflags.
   1461 ifneq (HEADER_LIBRARIES,$(LOCAL_MODULE_CLASS))
   1462   # Prebuilt modules do not need cflags.
   1463   ifeq (,$(LOCAL_PREBUILT_MODULE_FILE))
   1464     my_all_cflags := $(my_cflags) $(my_cppflags) $(my_cflags_no_override)
   1465     # Issue warning if -Wno-error is used.
   1466     ifneq (,$(filter -Wno-error,$(my_all_cflags)))
   1467       $(eval MODULES_USING_WNO_ERROR := $(MODULES_USING_WNO_ERROR) $(LOCAL_MODULE_MAKEFILE):$(LOCAL_MODULE))
   1468     else
   1469       # Issue warning if -Werror is not used. Add it.
   1470       ifeq (,$(filter -Werror,$(my_all_cflags)))
   1471         # Add -Wall -Werror unless the project is in the WARNING_ALLOWED project list.
   1472         ifeq (,$(strip $(call find_warning_allowed_projects,$(LOCAL_PATH))))
   1473           my_cflags := -Wall -Werror $(my_cflags)
   1474         else
   1475           $(eval MODULES_ADDED_WALL := $(MODULES_ADDED_WALL) $(LOCAL_MODULE_MAKEFILE):$(LOCAL_MODULE))
   1476           my_cflags := -Wall $(my_cflags)
   1477         endif
   1478       endif
   1479     endif
   1480   endif
   1481 endif
   1482 
   1483 # Disable clang-tidy if it is not found.
   1484 ifeq ($(PATH_TO_CLANG_TIDY),)
   1485   my_tidy_enabled := false
   1486 else
   1487   # If LOCAL_TIDY is not defined, use global WITH_TIDY
   1488   my_tidy_enabled := $(LOCAL_TIDY)
   1489   ifeq ($(my_tidy_enabled),)
   1490     my_tidy_enabled := $(WITH_TIDY)
   1491   endif
   1492 endif
   1493 
   1494 # my_tidy_checks is empty if clang-tidy is disabled.
   1495 my_tidy_checks :=
   1496 my_tidy_flags :=
   1497 ifneq (,$(filter 1 true,$(my_tidy_enabled)))
   1498   tidy_only: $(cpp_objects) $(c_objects) $(gen_c_objects) $(gen_cpp_objects)
   1499   # Set up global default checks
   1500   my_tidy_checks := $(WITH_TIDY_CHECKS)
   1501   ifeq ($(my_tidy_checks),)
   1502     my_tidy_checks := $(call default_global_tidy_checks,$(LOCAL_PATH))
   1503   endif
   1504   # Append local clang-tidy checks.
   1505   ifneq ($(LOCAL_TIDY_CHECKS),)
   1506     my_tidy_checks := $(my_tidy_checks),$(LOCAL_TIDY_CHECKS)
   1507   endif
   1508   my_tidy_flags := $(strip $(WITH_TIDY_FLAGS) $(LOCAL_TIDY_FLAGS))
   1509   # If tidy flags are not specified, default to check all header files.
   1510   ifeq ($(my_tidy_flags),)
   1511     my_tidy_flags := $(call default_tidy_header_filter,$(LOCAL_PATH))
   1512   endif
   1513   # If clang-tidy is not enabled globally, add the -quiet flag.
   1514   ifeq (,$(filter 1 true,$(WITH_TIDY)))
   1515     my_tidy_flags += -quiet -extra-arg-before=-fno-caret-diagnostics
   1516   endif
   1517 
   1518   ifneq ($(my_tidy_checks),)
   1519     # We might be using the static analyzer through clang-tidy.
   1520     # https://bugs.llvm.org/show_bug.cgi?id=32914
   1521     my_tidy_flags += -extra-arg-before=-D__clang_analyzer__
   1522 
   1523     # A recent change in clang-tidy (r328258) enabled destructor inlining,
   1524     # which appears to cause a number of false positives. Until that's
   1525     # resolved, this turns off the effects of r328258.
   1526     # https://bugs.llvm.org/show_bug.cgi?id=37459
   1527     my_tidy_flags += -extra-arg-before=-Xclang
   1528     my_tidy_flags += -extra-arg-before=-analyzer-config
   1529     my_tidy_flags += -extra-arg-before=-Xclang
   1530     my_tidy_flags += -extra-arg-before=c++-temp-dtor-inlining=false
   1531   endif
   1532 endif
   1533 
   1534 my_tidy_checks := $(subst $(space),,$(my_tidy_checks))
   1535 
   1536 # Add dependency of clang-tidy and clang-tidy.sh
   1537 ifneq ($(my_tidy_checks),)
   1538   my_clang_tidy_programs := $(PATH_TO_CLANG_TIDY) $(PATH_TO_CLANG_TIDY_SHELL)
   1539   $(cpp_objects): $(intermediates)/%.o: $(my_clang_tidy_programs)
   1540   $(c_objects): $(intermediates)/%.o: $(my_clang_tidy_programs)
   1541   $(gen_cpp_objects): $(intermediates)/%.o: $(my_clang_tidy_programs)
   1542   $(gen_c_objects): $(intermediates)/%.o: $(my_clang_tidy_programs)
   1543 endif
   1544 
   1545 # Move -l* entries from ldflags to ldlibs, and everything else to ldflags
   1546 my_ldlib_flags := $(my_ldflags) $(my_ldlibs)
   1547 my_ldlibs := $(filter -l%,$(my_ldlib_flags))
   1548 my_ldflags := $(filter-out -l%,$(my_ldlib_flags))
   1549 
   1550 # One last verification check for ldlibs
   1551 my_allowed_ldlibs :=
   1552 ifndef LOCAL_IS_HOST_MODULE
   1553   ifneq ($(LOCAL_SDK_VERSION),)
   1554     my_allowed_ldlibs := $(addprefix -l,$(NDK_PREBUILT_SHARED_LIBRARIES))
   1555   endif
   1556 else
   1557   my_allowed_ldlibs := $($(my_prefix)AVAILABLE_LIBRARIES)
   1558 endif
   1559 
   1560 my_bad_ldlibs := $(filter-out $(my_allowed_ldlibs),$(my_ldlibs))
   1561 ifneq ($(my_bad_ldlibs),)
   1562   $(error $(LOCAL_MODULE_MAKEFILE): $(LOCAL_MODULE): Bad LOCAL_LDLIBS entries: $(my_bad_ldlibs))
   1563 endif
   1564 
   1565 # my_cxx_ldlibs may contain linker flags need to wrap certain libraries
   1566 # (start-group/end-group), so append after the check above.
   1567 my_ldlibs += $(my_cxx_ldlibs)
   1568 
   1569 ###########################################################
   1570 ## Define PRIVATE_ variables from global vars
   1571 ###########################################################
   1572 ifndef LOCAL_IS_HOST_MODULE
   1573 ifdef LOCAL_USE_VNDK
   1574 my_target_global_c_includes := \
   1575     $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)PROJECT_INCLUDES)
   1576 my_target_global_c_system_includes := \
   1577     $(TARGET_OUT_HEADERS) \
   1578     $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)PROJECT_SYSTEM_INCLUDES)
   1579 else ifdef LOCAL_SDK_VERSION
   1580 my_target_global_c_includes :=
   1581 my_target_global_c_system_includes := $(my_ndk_stl_include_path) $(my_ndk_sysroot_include)
   1582 else ifdef BOARD_VNDK_VERSION
   1583 my_target_global_c_includes := $(SRC_HEADERS) \
   1584     $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)PROJECT_INCLUDES) \
   1585     $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)C_INCLUDES)
   1586 my_target_global_c_system_includes := $(SRC_SYSTEM_HEADERS) \
   1587     $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)PROJECT_SYSTEM_INCLUDES) \
   1588     $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)C_SYSTEM_INCLUDES)
   1589 else
   1590 my_target_global_c_includes := $(SRC_HEADERS) \
   1591     $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)PROJECT_INCLUDES) \
   1592     $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)C_INCLUDES)
   1593 my_target_global_c_system_includes := $(SRC_SYSTEM_HEADERS) $(TARGET_OUT_HEADERS) \
   1594     $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)PROJECT_SYSTEM_INCLUDES) \
   1595     $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)C_SYSTEM_INCLUDES)
   1596 endif
   1597 
   1598 my_target_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CFLAGS)
   1599 my_target_global_conlyflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CONLYFLAGS) $(my_c_std_conlyflags)
   1600 my_target_global_cppflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CPPFLAGS) $(my_cpp_std_cppflags)
   1601 ifeq ($(my_use_clang_lld),true)
   1602   my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_LLDFLAGS)
   1603   include $(BUILD_SYSTEM)/pack_dyn_relocs_setup.mk
   1604   ifeq ($(my_pack_module_relocations),false)
   1605     my_target_global_ldflags += -Wl,--pack-dyn-relocs=none
   1606   endif
   1607 else
   1608   my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_LDFLAGS)
   1609 endif # my_use_clang_lld
   1610 
   1611 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_GLOBAL_C_INCLUDES := $(my_target_global_c_includes)
   1612 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_GLOBAL_C_SYSTEM_INCLUDES := $(my_target_global_c_system_includes)
   1613 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CFLAGS := $(my_target_global_cflags)
   1614 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CONLYFLAGS := $(my_target_global_conlyflags)
   1615 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CPPFLAGS := $(my_target_global_cppflags)
   1616 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_LDFLAGS := $(my_target_global_ldflags)
   1617 
   1618 else # LOCAL_IS_HOST_MODULE
   1619 
   1620 my_host_global_c_includes := $(SRC_HEADERS) \
   1621     $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)C_INCLUDES)
   1622 my_host_global_c_system_includes := $(SRC_SYSTEM_HEADERS) \
   1623     $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)C_SYSTEM_INCLUDES)
   1624 
   1625 my_host_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CFLAGS)
   1626 my_host_global_conlyflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CONLYFLAGS) $(my_c_std_conlyflags)
   1627 my_host_global_cppflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CPPFLAGS) $(my_cpp_std_cppflags)
   1628 ifeq ($(my_use_clang_lld),true)
   1629   my_host_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_LLDFLAGS)
   1630 else
   1631   my_host_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_LDFLAGS)
   1632 endif # my_use_clang_lld
   1633 
   1634 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_GLOBAL_C_INCLUDES := $(my_host_global_c_includes)
   1635 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_GLOBAL_C_SYSTEM_INCLUDES := $(my_host_global_c_system_includes)
   1636 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CFLAGS := $(my_host_global_cflags)
   1637 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CONLYFLAGS := $(my_host_global_conlyflags)
   1638 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CPPFLAGS := $(my_host_global_cppflags)
   1639 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_LDFLAGS := $(my_host_global_ldflags)
   1640 endif # LOCAL_IS_HOST_MODULE
   1641 
   1642 # To enable coverage for a given module, set LOCAL_NATIVE_COVERAGE=true and
   1643 # build with NATIVE_COVERAGE=true in your enviornment.
   1644 ifeq ($(NATIVE_COVERAGE),true)
   1645     ifeq ($(my_native_coverage),true)
   1646         # Note that clang coverage doesn't play nicely with acov out of the box.
   1647         # Clang apparently generates .gcno files that aren't compatible with
   1648         # gcov-4.8.  This can be solved by installing gcc-4.6 and invoking lcov
   1649         # with `--gcov-tool /usr/bin/gcov-4.6`.
   1650         #
   1651         # http://stackoverflow.com/questions/17758126/clang-code-coverage-invalid-output
   1652         my_cflags += --coverage -O0
   1653         my_ldflags += --coverage
   1654     endif
   1655 
   1656     my_coverage_lib := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)LIBPROFILE_RT)
   1657 
   1658     $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_COVERAGE_LIB := $(my_coverage_lib)
   1659     $(LOCAL_INTERMEDIATE_TARGETS): $(my_coverage_lib)
   1660 endif
   1661 
   1662 ###########################################################
   1663 ## Define PRIVATE_ variables used by multiple module types
   1664 ###########################################################
   1665 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_DEFAULT_COMPILER_FLAGS := \
   1666     $(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS))
   1667 
   1668 ifeq ($(strip $(WITH_STATIC_ANALYZER)),)
   1669   LOCAL_NO_STATIC_ANALYZER := true
   1670 endif
   1671 
   1672 ifneq ($(strip $(LOCAL_IS_HOST_MODULE)),)
   1673   my_syntax_arch := host
   1674 else
   1675   my_syntax_arch := $($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
   1676 endif
   1677 
   1678 ifeq ($(strip $(my_cc)),)
   1679   my_cc := $(my_cc_wrapper) $(CLANG)
   1680 endif
   1681 
   1682 SYNTAX_TOOLS_PREFIX := \
   1683     $(LLVM_PREBUILTS_BASE)/$(BUILD_OS)-x86/$(LLVM_PREBUILTS_VERSION)/libexec
   1684 
   1685 ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
   1686   my_cc := CCC_CC=$(CLANG) CLANG=$(CLANG) \
   1687            $(SYNTAX_TOOLS_PREFIX)/ccc-analyzer
   1688 endif
   1689 
   1690 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CC := $(my_cc)
   1691 
   1692 ifeq ($(strip $(my_cxx)),)
   1693   my_cxx := $(my_cxx_wrapper) $(CLANG_CXX)
   1694 endif
   1695 
   1696 ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
   1697   my_cxx := CCC_CXX=$(CLANG_CXX) CLANG_CXX=$(CLANG_CXX) \
   1698             $(SYNTAX_TOOLS_PREFIX)/c++-analyzer
   1699 endif
   1700 
   1701 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LINKER := $(my_linker)
   1702 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CXX := $(my_cxx)
   1703 
   1704 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS)
   1705 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASFLAGS := $(my_asflags)
   1706 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CONLYFLAGS := $(my_conlyflags)
   1707 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS := $(my_cflags)
   1708 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS := $(my_cppflags)
   1709 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS_NO_OVERRIDE := $(my_cflags_no_override)
   1710 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS_NO_OVERRIDE := $(my_cppflags_no_override)
   1711 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RTTI_FLAG := $(LOCAL_RTTI_FLAG)
   1712 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEBUG_CFLAGS := $(debug_cflags)
   1713 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_C_INCLUDES := $(my_c_includes)
   1714 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_IMPORT_INCLUDES := $(import_includes)
   1715 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDFLAGS := $(my_ldflags)
   1716 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDLIBS := $(my_ldlibs)
   1717 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TIDY_CHECKS := $(my_tidy_checks)
   1718 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TIDY_FLAGS := $(my_tidy_flags)
   1719 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ARFLAGS := $(my_arflags)
   1720 
   1721 # this is really the way to get the files onto the command line instead
   1722 # of using $^, because then LOCAL_ADDITIONAL_DEPENDENCIES doesn't work
   1723 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_SHARED_LIBRARIES := $(built_shared_libraries)
   1724 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_STATIC_LIBRARIES := $(built_static_libraries)
   1725 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(built_whole_libraries)
   1726 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_OBJECTS := $(strip $(all_objects))
   1727 
   1728 ###########################################################
   1729 # Define library dependencies.
   1730 ###########################################################
   1731 # all_libraries is used for the dependencies on LOCAL_BUILT_MODULE.
   1732 all_libraries := \
   1733     $(built_shared_library_deps) \
   1734     $(my_system_shared_libraries_fullpath) \
   1735     $(built_static_libraries) \
   1736     $(built_whole_libraries)
   1737 
   1738 ###########################################################
   1739 # Export includes
   1740 ###########################################################
   1741 export_includes := $(intermediates)/export_includes
   1742 export_cflags := $(foreach d,$(my_export_c_include_dirs),-I $(d))
   1743 $(export_includes): PRIVATE_EXPORT_CFLAGS := $(export_cflags)
   1744 # Headers exported by whole static libraries are also exported by this library.
   1745 export_include_deps := $(strip \
   1746    $(foreach l,$(my_whole_static_libraries), \
   1747      $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes))
   1748 # Re-export requested headers from shared libraries.
   1749 export_include_deps += $(strip \
   1750    $(foreach l,$(LOCAL_EXPORT_SHARED_LIBRARY_HEADERS), \
   1751      $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes))
   1752 # Re-export requested headers from static libraries.
   1753 export_include_deps += $(strip \
   1754    $(foreach l,$(LOCAL_EXPORT_STATIC_LIBRARY_HEADERS), \
   1755      $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes))
   1756 # Re-export requested headers from header libraries.
   1757 export_include_deps += $(strip \
   1758    $(foreach l,$(LOCAL_EXPORT_HEADER_LIBRARY_HEADERS), \
   1759      $(call intermediates-dir-for,HEADER_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes))
   1760 $(export_includes): PRIVATE_REEXPORTED_INCLUDES := $(export_include_deps)
   1761 # By adding $(my_generated_sources) it makes sure the headers get generated
   1762 # before any dependent source files get compiled.
   1763 $(export_includes) : $(my_export_c_include_deps) $(my_generated_sources) $(export_include_deps) $(LOCAL_EXPORT_C_INCLUDE_DEPS)
   1764 	@echo Export includes file: $< -- $@
   1765 	$(hide) mkdir -p $(dir $@) && rm -f $@.tmp && touch $@.tmp
   1766 ifdef export_cflags
   1767 	$(hide) echo "$(PRIVATE_EXPORT_CFLAGS)" >>$@.tmp
   1768 endif
   1769 ifdef export_include_deps
   1770 	$(hide) for f in $(PRIVATE_REEXPORTED_INCLUDES); do \
   1771 		cat $$f >> $@.tmp; \
   1772 		done
   1773 endif
   1774 	$(hide) if cmp -s $@.tmp $@ ; then \
   1775 	  rm $@.tmp ; \
   1776 	else \
   1777 	  mv $@.tmp $@ ; \
   1778 	fi
   1779 export_cflags :=
   1780 
   1781 # Kati adds restat=1 to ninja. GNU make does nothing for this.
   1782 .KATI_RESTAT: $(export_includes)
   1783 
   1784 # Make sure export_includes gets generated when you are running mm/mmm
   1785 $(LOCAL_BUILT_MODULE) : | $(export_includes)
   1786 
   1787 ifneq (,$(filter-out $(LOCAL_PATH)/%,$(my_export_c_include_dirs)))
   1788 my_soong_problems += non_local__export_c_include_dirs
   1789 endif
   1790 
   1791 SOONG_CONV.$(LOCAL_MODULE).PROBLEMS := \
   1792     $(SOONG_CONV.$(LOCAL_MODULE).PROBLEMS) $(my_soong_problems)
   1793 SOONG_CONV.$(LOCAL_MODULE).DEPS := \
   1794     $(SOONG_CONV.$(LOCAL_MODULE).DEPS) \
   1795     $(filter-out $($(LOCAL_2ND_ARCH_VAR_PREFIX)UBSAN_RUNTIME_LIBRARY),\
   1796         $(my_static_libraries) \
   1797         $(my_whole_static_libraries) \
   1798         $(my_shared_libraries) \
   1799         $(my_system_shared_libraries))
   1800 SOONG_CONV.$(LOCAL_MODULE).TYPE := native
   1801 SOONG_CONV := $(SOONG_CONV) $(LOCAL_MODULE)
   1802 
   1803 ###########################################################
   1804 # Coverage packaging.
   1805 ###########################################################
   1806 ifeq ($(my_native_coverage),true)
   1807 my_gcno_objects := \
   1808     $(cpp_objects) \
   1809     $(gen_cpp_objects) \
   1810     $(c_objects) \
   1811     $(gen_c_objects) \
   1812     $(objc_objects) \
   1813     $(objcpp_objects)
   1814 
   1815 LOCAL_GCNO_FILES := $(patsubst %.o,%.gcno,$(my_gcno_objects))
   1816 $(foreach f,$(my_gcno_objects),$(eval $(call gcno-touch-rule,$(f),$(f:.o=.gcno))))
   1817 endif
   1818