########################################################### ## Standard rules for building binary object files from ## asm/c/cpp/yacc/lex/etc source files. ## ## The list of object files is exported in $(all_objects). ###########################################################
####################################### include $(BUILD_SYSTEM)/base_rules.mk #######################################
################################################## # Compute the dependency of the shared libraries ################################################## # On the target, we compile with -nostdlib, so we must add in the # default system shared libraries, unless they have requested not # to by supplying a LOCAL_SYSTEM_SHARED_LIBRARIES value. One would # supply that, for example, when building libc itself.
ifdef LOCAL_IS_HOST_MODULE ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
ifdef USE_HOST_MUSL
my_system_shared_libraries := libc_musl else
my_system_shared_libraries := endif else
my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES) endif else ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
my_system_shared_libraries := libc libm libdl else
my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES)
my_system_shared_libraries := $(patsubst libc,libc libdl,$(my_system_shared_libraries)) endif endif
# Third party code has additional no-override flags.
is_third_party := ifneq ($(filter external/% hardware/% vendor/%,$(LOCAL_PATH)),)
is_third_party := true endif
my_soong_problems :=
# The following LOCAL_ variables will be modified in this file. # Because the same LOCAL_ variables may be used to define modules for both 1st arch and 2nd arch, # we can't modify them in place.
my_src_files := $(LOCAL_SRC_FILES)
my_src_files_exclude := $(LOCAL_SRC_FILES_EXCLUDE)
my_static_libraries := $(LOCAL_STATIC_LIBRARIES)
my_whole_static_libraries := $(LOCAL_WHOLE_STATIC_LIBRARIES)
my_shared_libraries := $(filter-out $(my_system_shared_libraries),$(LOCAL_SHARED_LIBRARIES))
my_header_libraries := $(LOCAL_HEADER_LIBRARIES)
my_cflags := $(LOCAL_CFLAGS)
my_conlyflags := $(LOCAL_CONLYFLAGS)
my_cppflags := $(LOCAL_CPPFLAGS)
my_cflags_no_override := $(GLOBAL_CLANG_CFLAGS_NO_OVERRIDE)
my_cppflags_no_override := $(GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE) ifeq ($(my_32_64_bit_suffix), 64)
my_cflags_no_override += $(GLOBAL_CLANG_CFLAGS_64_NO_OVERRIDE) endif
ifdef is_third_party
my_cflags_no_override += $(GLOBAL_CLANG_EXTERNAL_CFLAGS_NO_OVERRIDE)
my_cppflags_no_override += $(GLOBAL_CLANG_EXTERNAL_CFLAGS_NO_OVERRIDE) endif
my_ldflags := $(LOCAL_LDFLAGS)
my_ldlibs := $(LOCAL_LDLIBS)
my_asflags := $(LOCAL_ASFLAGS)
my_cc := $(LOCAL_CC)
my_cc_wrapper := $(CC_WRAPPER)
my_cxx := $(LOCAL_CXX)
my_cxx_link := $(LOCAL_CXX)
my_cxx_ldlibs :=
my_cxx_wrapper := $(CXX_WRAPPER)
my_c_includes := $(LOCAL_C_INCLUDES)
my_generated_sources := $(LOCAL_GENERATED_SOURCES)
my_additional_dependencies := $(LOCAL_ADDITIONAL_DEPENDENCIES)
my_export_c_include_dirs := $(LOCAL_EXPORT_C_INCLUDE_DIRS)
my_export_c_include_deps := $(LOCAL_EXPORT_C_INCLUDE_DEPS)
my_arflags :=
# Disable clang-tidy if it is not found. ifeq ($(PATH_TO_CLANG_TIDY),)
my_tidy_enabled := false else
my_tidy_enabled := $(LOCAL_TIDY) endif
# my_tidy_checks is empty if clang-tidy is disabled.
my_tidy_checks :=
my_tidy_flags := ifneq (,$(filter 1 true,$(my_tidy_enabled))) # Set up global default checks
my_tidy_checks := $(WITH_TIDY_CHECKS) ifeq ($(my_tidy_checks),)
my_tidy_checks := $(call default_global_tidy_checks,$(LOCAL_PATH)) endif # Append local clang-tidy checks. ifneq ($(LOCAL_TIDY_CHECKS),)
my_tidy_checks := $(my_tidy_checks),$(LOCAL_TIDY_CHECKS) endif
my_tidy_flags := $(strip $(WITH_TIDY_FLAGS) $(LOCAL_TIDY_FLAGS)) # If tidy flags are not specified, default to check all header files. ifeq ($(my_tidy_flags),)
my_tidy_flags := $(call default_tidy_header_filter,$(LOCAL_PATH)) endif # If clang-tidy is not enabled globally, add the -quiet flag. ifeq (,$(filter 1 true,$(WITH_TIDY)))
my_tidy_flags += -quiet -extra-arg-before=-fno-caret-diagnostics endif
ifneq ($(my_tidy_checks),) # We might be using the static analyzer through clang-tidy. # https://bugs.llvm.org/show_bug.cgi?id=32914
my_tidy_flags += -extra-arg-before=-D__clang_analyzer__
# A recent change in clang-tidy (r328258) enabled destructor inlining, # which appears to cause a number of false positives. Until that's # resolved, this turns off the effects of r328258. # https://bugs.llvm.org/show_bug.cgi?id=37459
my_tidy_flags += -extra-arg-before=-Xclang
my_tidy_flags += -extra-arg-before=-analyzer-config
my_tidy_flags += -extra-arg-before=-Xclang
my_tidy_flags += -extra-arg-before=c++-temp-dtor-inlining=false endif endif
# Configure the pool to use for clang rules. # If LOCAL_CC or LOCAL_CXX is set don't RBE. # If clang-tidy is being used, don't use the RBE pool (as clang-tidy runs in # the same action, and is not remoted)
my_pool := ifeq (,$(strip $(my_cc))$(strip $(my_cxx))$(strip $(my_tidy_checks)))
my_pool := $(RBE_POOL) endif
# Historically we've just set up a bunch of symlinks in prebuilts/ndk to map # missing API levels to existing ones where necessary, but we're not doing # that for the generated libraries. Clip the API level to the minimum where # appropriate.
my_ndk_api := $(LOCAL_SDK_VERSION) ifneq ($(my_ndk_api),current)
my_ndk_api := $(call math_max,$(my_ndk_api),$(my_min_sdk_version)) endif
# The bionic linker now has support for packed relocations and gnu style # hashes (which are much faster!), but shipping to older devices requires # the old style hash. Fortunately, we can build with both and it'll work # anywhere.
my_ldflags += -Wl,--hash-style=both
# We don't want to expose the relocation packer to the NDK just yet.
LOCAL_PACK_MODULE_RELOCATIONS := false
# Set up the NDK stl variant. Starting from NDK-r5 the c++ stl resides in a separate location. # See ndk/docs/CPLUSPLUS-SUPPORT.html
my_ndk_stl_include_path :=
my_ndk_stl_shared_lib_fullpath :=
my_ndk_stl_static_lib :=
my_cpu_variant := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)
LOCAL_NDK_STL_VARIANT := $(strip $(LOCAL_NDK_STL_VARIANT)) ifeq (,$(LOCAL_NDK_STL_VARIANT))
LOCAL_NDK_STL_VARIANT := system endif ifneq (1,$(words $(filter none system c++_static c++_shared, $(LOCAL_NDK_STL_VARIANT))))
$(error $(LOCAL_PATH): Unknown LOCAL_NDK_STL_VARIANT $(LOCAL_NDK_STL_VARIANT)) endif
# Include the target-specific __config_site file followed by the generic libc++ headers.
my_ndk_stl_include_path := $(my_libcxx_arch_dir)/include/c++/v1
my_ndk_stl_include_path += $(my_llvm_dir)/include/c++/v1
my_libcxx_libdir := $(my_libcxx_arch_dir)/lib
my_ndk_stl_static_lib += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_LIBUNWIND)
my_ldlibs += -ldl else# LOCAL_NDK_STL_VARIANT must be none # Do nothing. endif
# Clang's coverage/profile runtime needs symbols like 'stderr' that were not # exported from libc prior to API level 23 ifneq ($(my_ndk_api),current) ifeq ($(call math_lt, $(my_ndk_api),23),true)
my_native_coverage := false
my_clang_coverage := false endif endif endif
ifneq ($(LOCAL_MIN_SDK_VERSION),)
ifdef LOCAL_IS_HOST_MODULE
$(error $(LOCAL_PATH): LOCAL_MIN_SDK_VERSION cannot be used in host module) endif
my_api_level := $(LOCAL_MIN_SDK_VERSION) endif
# Define __ANDROID_VENDOR_API__ for both product and vendor variants because # they both use the same LLNDK libraries. ifeq ($(BOARD_API_LEVEL),) # TODO(b/314036847): This is a fallback for UDC targets. # This must be a build failure when UDC is no longer built from this source tree.
my_cflags += -D__ANDROID_VENDOR_API__=$(PLATFORM_SDK_VERSION) else
my_cflags += -D__ANDROID_VENDOR_API__=$(BOARD_API_LEVEL) endif endif
ifndef LOCAL_IS_HOST_MODULE # For device libraries, move LOCAL_LDLIBS references to my_shared_libraries. We # no longer need to use my_ldlibs to pick up NDK prebuilt libraries since we're # linking my_shared_libraries by full path now.
my_allowed_ldlibs :=
# Sort ldlibs and ldflags between -l and other linker flags # We'll do this again later, since there are still changes happening, but that's fine.
my_ldlib_flags := $(my_ldflags) $(my_ldlibs)
my_ldlibs := $(filter -l%,$(my_ldlib_flags))
my_ldflags := $(filter-out -l%,$(my_ldlib_flags))
my_ldlib_flags :=
# Move other ldlibs back to shared libraries
my_shared_libraries += $(patsubst -l%,lib%,$(filter-out $(my_allowed_ldlibs),$(my_ldlibs)))
my_ldlibs := $(filter $(my_allowed_ldlibs),$(my_ldlibs)) else# LOCAL_IS_HOST_MODULE # Add -ldl, -lpthread, -lm and -lrt to host builds to match the default behavior of # device builds
ifndef USE_HOST_MUSL
my_ldlibs += -ldl -lpthread -lm ifneq ($(HOST_OS),darwin)
my_ldlibs += -lrt endif endif endif
# MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because # all code is position independent, and then those warnings get promoted to # errors. ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),)
my_cflags += -fPIE
ifndef BUILD_HOST_static ifneq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
my_ldflags += -pie endif endif else
my_cflags += -fPIC endif
my_missing_exclude_files := $(filter-out $(my_src_files),$(my_src_files_exclude)) ifneq ($(my_missing_exclude_files),)
$(warning Files are listed in LOCAL_SRC_FILES_EXCLUDE but not LOCAL_SRC_FILES)
$(error $(my_missing_exclude_files)) endif
my_src_files := $(filter-out $(my_src_files_exclude),$(my_src_files))
# Strip '/' from the beginning of each src file. This helps the ../ detection in case # the source file is in the form of /../file
my_src_files := $(patsubst /%,%,$(my_src_files))
# Extra cflags for projects under external/ directory ifneq ($(filter external/%,$(LOCAL_PATH)),)
my_cflags += $(CLANG_EXTERNAL_CFLAGS) endif
# Extra cflags for projects under hardware/ directory. # This should match the definition of `thirdPartyDirPrefixExceptions` # in build/soong/android/paths.go. # Get the second element of LOCAL_PATH ifneq ($(filter hardware/%,$(LOCAL_PATH)),)
my_subdir := $(word 2,$(subst /,$(space),$(LOCAL_PATH)))
must_compile_hardware_subdirs := \
hardware/google/% \
hardware/interfaces/% \
hardware/libhardware/% \
hardware/libhardware_legacy/% \
hardware/ril/% ifeq ($(filter $(must_compile_hardware_subdirs),$(my_subdir)),)
my_cflags += $(CLANG_EXTERNAL_CFLAGS) endif endif
# Extra cflags for projects under vendor/ directory. # This should match the definition of `thirdPartyDirPrefixExceptions` # in build/soong/android/paths.go. ifneq ($(filter vendor/%,$(LOCAL_PATH)),)
my_subdir := $(word 2,$(subst /,$(space),$(LOCAL_PATH))) # Do not add the flags for any subdir that contains the string "google". ifneq ($(findstring google,$(my_subdir)),)
my_cflags += $(CLANG_EXTERNAL_CFLAGS) endif endif
# arch-specific static libraries go first so that generic ones can depend on them
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)
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)
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)
########################################################### # TODO: support a mix of standard extensions so that this isn't necessary
LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION)) ifeq ($(LOCAL_CPP_EXTENSION),)
LOCAL_CPP_EXTENSION := .cpp endif
# Certain modules like libdl have to have symbols resolved at runtime and blow # up if --no-undefined is passed to the linker. ifeq ($(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS)),) ifeq ($(my_allow_undefined_symbols),) ifneq ($(HOST_OS),darwin)
my_ldflags += -Wl,--no-undefined endif else
ifdef LOCAL_IS_HOST_MODULE ifeq ($(HOST_OS),darwin) # darwin defaults to treating undefined symbols as errors
my_ldflags += -Wl,-undefined,dynamic_lookup endif endif endif endif
# Read the values from something like TARGET_arm_CFLAGS or # TARGET_thumb_CFLAGS. HOST_(arm|thumb)_CFLAGS values aren't # actually used (although they are usually empty).
normal_objects_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)$(normal_objects_mode)_CFLAGS)
########################################################### ## Define per-module debugging flags. Users can turn on ## debugging for a particular module by setting DEBUG_MODULE_ModuleName ## to a non-empty value in their environment or buildspec.mk, ## and setting HOST_/TARGET_CUSTOM_DEBUG_CFLAGS to the ## debug flags that they want to use. ###########################################################
ifdef DEBUG_MODULE_$(strip $(LOCAL_MODULE))
debug_cflags := $($(my_prefix)CUSTOM_DEBUG_CFLAGS) else
debug_cflags := endif
#################################################### ## Keep track of src -> obj mapping ####################################################
# Generated sources that will actually produce object files. # Other files (like headers) are allowed in LOCAL_GENERATED_SOURCES, # since other compiled sources may depend on them, and we set up # the dependencies.
my_gen_src_files := $(filter %.c %$(LOCAL_CPP_EXTENSION) %.S %.s,$(my_generated_sources))
#################################################### ## Compile RenderScript with reflected C++ ####################################################
ifneq (,$(LOCAL_RENDERSCRIPT_TARGET_API))
renderscript_target_api := $(LOCAL_RENDERSCRIPT_TARGET_API) else ifneq (,$(LOCAL_SDK_VERSION)) # Set target-api for LOCAL_SDK_VERSIONs other than current. ifneq (,$(filter-out current system_current test_current, $(LOCAL_SDK_VERSION)))
renderscript_target_api := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION)) endif endif# LOCAL_SDK_VERSION is set endif# LOCAL_RENDERSCRIPT_TARGET_API is set
# Turn on all warnings and warnings as errors for RS compiles. # This can be disabled with LOCAL_RENDERSCRIPT_FLAGS := -Wno-error
renderscript_flags := -Wall -Werror
renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS) # -m32 or -m64
renderscript_flags += -m$(my_32_64_bit_suffix)
# This is just a no-op rule to make sure gmake doesn't skip updating the dependents.
$(rs_generated_cpps) : $(RenderScript_file_stamp)
@echo"Updated RS generated cpp file $@."
$(hide) touch $@
# Ensure the transform-proto-to-cc rule is only defined once in multilib build.
ifndef $(my_host)$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined
$(proto_generated_cpps): PRIVATE_PROTO_INCLUDES := $(TOP)
$(proto_generated_cpps): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS) $(my_protoc_flags)
$(proto_generated_cpps): PRIVATE_RENAME_CPP_EXT := $(my_rename_cpp_ext)
$(proto_generated_cpps): $(proto_gen_dir)/%.pb$(my_proto_source_suffix): %.proto $(my_protoc_deps) $(PROTOC)
$(transform-proto-to-cc)
$(my_host)$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined := true endif # Ideally we can generate the source directly into $(intermediates). # But many Android.mks assume the .pb.hs are in $(generated_sources_dir). # As a workaround, we make a copy in the $(intermediates).
proto_intermediate_dir := $(intermediates)/proto
proto_intermediate_cpps := $(patsubst $(proto_gen_dir)/%,$(proto_intermediate_dir)/%,\
$(proto_generated_cpps))
$(proto_intermediate_cpps) : $(proto_intermediate_dir)/% : $(proto_gen_dir)/%
@echo"Copy: $@"
$(copy-file-to-target)
$(hide) cp $(basename $<).h $(basename $@).h
$(call track-src-file-gen,$(proto_sources),$(proto_intermediate_cpps))
# Use the intermediates directory to avoid writing our own .cpp -> .o rules.
aidl_gen_cpp_root := $(intermediates)/aidl-generated/src
aidl_gen_include_root := $(intermediates)/aidl-generated/include
# Multi-architecture builds have distinct intermediates directories. # Thus we'll actually generate source for each architecture.
$(foreach s,$(aidl_src),\
$(eval $(calldefine-aidl-cpp-rule,$(s),$(aidl_gen_cpp_root),aidl_gen_cpp)))
$(foreach cpp,$(aidl_gen_cpp), \
$(callinclude-depfile,$(addsuffix .aidl.d,$(basename $(cpp))),$(cpp)))
$(call track-src-file-gen,$(aidl_src),$(aidl_gen_cpp))
# Add generated headers to include paths.
my_c_includes += $(aidl_gen_include_root)
my_export_c_include_dirs += $(aidl_gen_include_root) # Pick up the generated C++ files later for transformation to .o files.
my_generated_sources += $(aidl_gen_cpp)
endif# $(aidl_src) non-empty
########################################################### ## Compile the .vts files to .cc (or .c) and then to .o ###########################################################
# Use the intermediates directory to avoid writing our own .cpp -> .o rules.
vts_gen_cpp_root := $(intermediates)/vts-generated/src
vts_gen_include_root := $(intermediates)/vts-generated/include
# Multi-architecture builds have distinct intermediates directories. # Thus we'll actually generate source for each architecture.
$(foreach s,$(vts_src),\
$(eval $(calldefine-vts-cpp-rule,$(s),$(vts_gen_cpp_root),vts_gen_cpp)))
$(call track-src-file-gen,$(vts_src),$(vts_gen_cpp))
# Add generated headers to include paths.
my_c_includes += $(vts_gen_include_root)
my_export_c_include_dirs += $(vts_gen_include_root) # Pick up the generated C++ files later for transformation to .o files.
my_generated_sources += $(vts_gen_cpp)
endif# $(vts_src) non-empty
########################################################### ## YACC: Compile .y/.yy files to .c/.cpp and then to .o. ###########################################################
########################################################### ## LEX: Compile .l/.ll files to .c/.cpp and then to .o. ###########################################################
########################################################### ## C++: Compile .cpp files to .o. ###########################################################
ifneq ($(filter %$(LOCAL_CPP_EXTENSION).arm,$(my_src_files)),)
$(call pretty-error,Files ending in $(LOCAL_CPP_EXTENSION).arm are deprecated. See $(CHANGES_URL)#file_arm) endif
########################################################### ## o: Include generated .o files in output. ###########################################################
# .asm for x86/x86_64 needs to be compiled with yasm.
asm_sources_asm := $(filter %.asm,$(my_src_files)) ifneq ($(strip $(asm_sources_asm)),)
asm_objects_asm := $(addprefix $(intermediates)/,$(asm_sources_asm:.asm=.o))
$(asm_objects_asm): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.asm \
$(my_additional_dependencies) $(YASM)
$(transform-asm-to-o)
$(call track-src-file-obj,$(asm_sources_asm),$(asm_objects_asm))
asm_objects += $(asm_objects_asm) endif
################################################################### ## Convert to sanitized names where they exist. ## These lists come from sanitizerStaticLibsMap; see ## build/soong/cc/sanitize.go ## ## $(1): list of static dependencies ## $(2): name of sanitizer (e.g. cfi, hwasan) ################################################################## define use_soong_sanitized_static_libraries
$(foreach lib,$(1),$(if $(filter $(lib),\
$(SOONG_$(2)_$(my_image_variant)_$(my_arch)_STATIC_LIBRARIES)),\
$(lib).$(2),$(lib))) endef
################################################################### ## When compiling a CFI enabled target, use the .cfi variant of any ## static dependencies (where they exist). ################################################################## ifneq ($(filter cfi,$(my_sanitize)),)
my_whole_static_libraries := $(call use_soong_sanitized_static_libraries,\
$(my_whole_static_libraries),cfi)
my_static_libraries := $(call use_soong_sanitized_static_libraries,\
$(my_static_libraries),cfi) endif
################################################################### ## When compiling a hwasan enabled target, use the .hwasan variant ## of any static dependencies (where they exist). ################################################################## ifneq ($(filter hwaddress,$(my_sanitize)),)
my_whole_static_libraries := $(call use_soong_sanitized_static_libraries,\
$(my_whole_static_libraries),hwasan)
my_static_libraries := $(call use_soong_sanitized_static_libraries,\
$(my_static_libraries),hwasan) endif
################################################################### ## When compiling a memtag_stack enabled target, use the .memtag_stack variant ## of any static dependencies (where they exist). ################################################################## ifneq ($(filter memtag_stack,$(my_sanitize)),)
my_whole_static_libraries := $(call use_soong_sanitized_static_libraries,\
$(my_whole_static_libraries),memtag_stack)
my_static_libraries := $(call use_soong_sanitized_static_libraries,\
$(my_static_libraries),memtag_stack) endif
################################################################### ## When compiling against API imported module, use API import stub ## libraries. ##################################################################
########################################################### ## When compiling against the VNDK, use LL-NDK libraries ########################################################### ifneq ($(call module-in-vendor-or-product),) ##################################################### ## Soong modules may be built three times, once for ## /system, once for /vendor and once for /product. ## If we're using the VNDK, switch all soong ## libraries over to the /vendor or /product variant. ##################################################### ifeq ($(LOCAL_IN_PRODUCT),true)
my_whole_static_libraries := $(foreach l,$(my_whole_static_libraries),\
$(if $(SPLIT_PRODUCT.STATIC_LIBRARIES.$(l)),$(l).product,$(l)))
my_static_libraries := $(foreach l,$(my_static_libraries),\
$(if $(SPLIT_PRODUCT.STATIC_LIBRARIES.$(l)),$(l).product,$(l)))
my_shared_libraries := $(foreach l,$(my_shared_libraries),\
$(if $(SPLIT_PRODUCT.SHARED_LIBRARIES.$(l)),$(l).product,$(l)))
my_system_shared_libraries := $(foreach l,$(my_system_shared_libraries),\
$(if $(SPLIT_PRODUCT.SHARED_LIBRARIES.$(l)),$(l).product,$(l)))
my_header_libraries := $(foreach l,$(my_header_libraries),\
$(if $(SPLIT_PRODUCT.HEADER_LIBRARIES.$(l)),$(l).product,$(l))) else
my_whole_static_libraries := $(foreach l,$(my_whole_static_libraries),\
$(if $(SPLIT_VENDOR.STATIC_LIBRARIES.$(l)),$(l).vendor,$(l)))
my_static_libraries := $(foreach l,$(my_static_libraries),\
$(if $(SPLIT_VENDOR.STATIC_LIBRARIES.$(l)),$(l).vendor,$(l)))
my_shared_libraries := $(foreach l,$(my_shared_libraries),\
$(if $(SPLIT_VENDOR.SHARED_LIBRARIES.$(l)),$(l).vendor,$(l)))
my_system_shared_libraries := $(foreach l,$(my_system_shared_libraries),\
$(if $(SPLIT_VENDOR.SHARED_LIBRARIES.$(l)),$(l).vendor,$(l)))
my_header_libraries := $(foreach l,$(my_header_libraries),\
$(if $(SPLIT_VENDOR.HEADER_LIBRARIES.$(l)),$(l).vendor,$(l))) endif endif
# Platform can use vendor public libraries. If a required shared lib is one of # the vendor public libraries, the lib is switched to the stub version of the lib. ifeq ($(call module-in-vendor-or-product),)
my_shared_libraries := $(foreach l,$(my_shared_libraries),\
$(if $(filter $(l),$(VENDOR_PUBLIC_LIBRARIES)),$(l).vendorpublic,$(l))) endif
########################################################### ## When compiling against the NDK, use SDK variants of Soong libraries ###########################################################
########################################################## ## Set up installed module dependency ## We cannot compute the full path of the LOCAL_SHARED_LIBRARIES for ## they may cusomize their install path with LOCAL_MODULE_PATH ########################################################## # Get the list of INSTALLED libraries as module names. ifneq ($(LOCAL_SDK_VERSION),)
installed_shared_library_module_names := \
$(my_shared_libraries) else
installed_shared_library_module_names := \
$(my_shared_libraries) $(my_system_shared_libraries) endif
# The real dependency will be added after all Android.mks are loaded and the install paths # of the shared libraries are determined.
ifdef LOCAL_INSTALLED_MODULE
ifdef installed_shared_library_module_names
$(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \
$(my_register_name):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(installed_shared_library_module_names)) endif endif
#################################################### ## Verify that NDK-built libraries only link against ## other NDK-built libraries ####################################################
# some rules depend on asm_objects being first. If your code depends on # being first, it's reasonable to require it to be assembly
normal_objects := \
$(asm_objects) \
$(cpp_objects) \
$(gen_cpp_objects) \
$(gen_asm_objects) \
$(c_objects) \
$(gen_c_objects) \
$(objc_objects) \
$(objcpp_objects)
ifneq ($(sort $(normal_objects)),$(sort $(new_order_normal_objects)))
$(warning $(LOCAL_MODULE_MAKEFILE) Internal build system warning: New object list does not match old)
$(info Only in old: $(filter-out $(new_order_normal_objects),$(sort $(normal_objects))))
$(info Only in new: $(filter-out $(normal_objects),$(sort $(new_order_normal_objects)))) endif
my_outside_includes := $(filter-out $(OUT_DIR)/%,$(filter /%,$(my_c_includes)) $(filter ../%,$(my_c_includes))) ifneq ($(my_outside_includes),) ifeq ($(BUILD_BROKEN_OUTSIDE_INCLUDE_DIRS),true)
$(call pretty-warning,C_INCLUDES must be under the source or output directories: $(my_outside_includes)) else
$(call pretty-error,C_INCLUDES must be under the source or output directories: $(my_outside_includes)) endif endif
# all_objects includes gen_o_objects which were part of LOCAL_GENERATED_SOURCES; # use normal_objects here to avoid creating circular dependencies. This assumes # that custom build rules which generate .o files don't consume other generated # sources as input (or if they do they take care of that dependency themselves).
$(normal_objects) : | $(my_generated_sources)
ALL_C_CPP_ETC_OBJECTS += $(all_objects)
########################################################### # Standard library handling. ###########################################################
########################################################### # The list of libraries that this module will link against are in # these variables. Each is a list of bare module names like "libc libm". # # LOCAL_SHARED_LIBRARIES # LOCAL_STATIC_LIBRARIES # LOCAL_WHOLE_STATIC_LIBRARIES # # We need to convert the bare names into the dependencies that # we'll use for LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE. # LOCAL_BUILT_MODULE should depend on the BUILT versions of the # libraries, so that simply building this module doesn't force # an install of a library. Similarly, LOCAL_INSTALLED_MODULE # should depend on the INSTALLED versions of the libraries so # that they get installed when this module does. ########################################################### # NOTE: # WHOLE_STATIC_LIBRARIES are libraries that are pulled into the # module without leaving anything out, which is useful for turning # a collection of .a files into a .so file. Linking against a # normal STATIC_LIBRARY will only pull in code/symbols that are # referenced by the module. (see gcc/ld's --whole-archive option) ###########################################################
# Get the list of BUILT libraries, which are under # various intermediates directories.
so_suffix := $($(my_prefix)SHLIB_SUFFIX)
a_suffix := $($(my_prefix)STATIC_LIB_SUFFIX)
# Add the NDK libraries to the built module dependency
my_system_shared_libraries_fullpath := \
$(my_ndk_stl_shared_lib_fullpath) \
$(addprefix $(my_ndk_sysroot_lib)/, \
$(addsuffix $(so_suffix), $(my_system_shared_libraries)))
# We need to preserve the ordering of LOCAL_SHARED_LIBRARIES regardless of # whether the libs are generated or prebuilt, so we simply can't split into two # lists and use addprefix.
my_ndk_shared_libraries_fullpath := \
$(foreach _lib,$(my_ndk_shared_libraries),\
$(if $(filter $(NDK_KNOWN_LIBS),$(_lib)),\
$(my_ndk_sysroot_lib)/$(_lib)$(so_suffix)))
# No one should ever use this flag. On GCC it's mere presence will disable all # warnings, even those that are specified after it (contrary to typical warning # flag behavior). This circumvents CFLAGS_NO_OVERRIDE from forcibly enabling the # warnings that are *always* bugs.
my_illegal_flags := -w
my_cflags := $(filter-out $(my_illegal_flags),$(my_cflags))
my_cppflags := $(filter-out $(my_illegal_flags),$(my_cppflags))
my_conlyflags := $(filter-out $(my_illegal_flags),$(my_conlyflags))
# We can enforce some rules more strictly in the code we own. my_strict # indicates if this is code that we can be stricter with. If we have rules that # we want to apply to *our* code (but maybe can't for vendor/device specific # things), we could extend this to be a ternary value.
my_strict := true ifneq ($(filter external/%,$(LOCAL_PATH)),)
my_strict := false endif
# Can be used to make some annotations stricter for code we can fix (such as # when we mark functions as deprecated). ifeq ($(my_strict),true)
my_cflags += -DANDROID_STRICT endif
# Check if -Werror or -Wno-error is used in C compiler flags. # Header libraries do not need cflags.
my_all_cflags := $(my_cflags) $(my_cppflags) $(my_cflags_no_override) ifneq (HEADER_LIBRARIES,$(LOCAL_MODULE_CLASS)) # Prebuilt modules do not need cflags. ifeq (,$(LOCAL_PREBUILT_MODULE_FILE)) # Issue warning if -Wno-error is used. ifneq (,$(filter -Wno-error,$(my_all_cflags)))
$(eval MODULES_USING_WNO_ERROR := $(MODULES_USING_WNO_ERROR) $(LOCAL_MODULE_MAKEFILE):$(LOCAL_MODULE)) else # Issue warning if -Werror is not used. Add it. ifeq (,$(filter -Werror,$(my_all_cflags))) # Add -Wall -Werror unless the project is in the WARNING_ALLOWED project list. ifeq (,$(strip $(call find_warning_allowed_projects,$(LOCAL_PATH))))
my_cflags := -Wall -Werror $(my_cflags) else
$(eval MODULES_WARNINGS_ALLOWED := $(MODULES_USING_WNO_ERROR) $(LOCAL_MODULE_MAKEFILE):$(LOCAL_MODULE))
my_cflags := -Wall $(my_cflags) endif endif endif endif endif
ifneq (,$(filter -Weverything,$(my_all_cflags))) ifeq (,$(ANDROID_TEMPORARILY_ALLOW_WEVERYTHING))
$(call pretty-error, -Weverything is not allowed in Android.mk files.\
Build with `m ANDROID_TEMPORARILY_ALLOW_WEVERYTHING=true` to experiment locally with -Weverything.) endif endif
# my_cxx_ldlibs may contain linker flags need to wrap certain libraries # (start-group/end-group), so append after the check above.
my_ldlibs += $(my_cxx_ldlibs)
########################################################### ## Define PRIVATE_ variables from global vars ###########################################################
ifndef LOCAL_IS_HOST_MODULE
# To enable coverage for a given module, set LOCAL_NATIVE_COVERAGE=true and # build with NATIVE_COVERAGE=true in your enviornment. ifeq ($(NATIVE_COVERAGE),true) ifeq ($(my_native_coverage),true) # Note that clang coverage doesn't play nicely with acov out of the box. # Clang apparently generates .gcno files that aren't compatible with # gcov-4.8. This can be solved by installing gcc-4.6 and invoking lcov # with `--gcov-tool /usr/bin/gcov-4.6`. # # http://stackoverflow.com/questions/17758126/clang-code-coverage-invalid-output
my_cflags += --coverage -O0
my_ldflags += --coverage endif
# this is really the way to get the files onto the command line instead # of using $^, because then LOCAL_ADDITIONAL_DEPENDENCIES doesn't work
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_SHARED_LIBRARIES := $(built_shared_libraries)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_STATIC_LIBRARIES := $(built_static_libraries)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(built_whole_libraries)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_OBJECTS := $(strip $(all_objects))
########################################################### # Define library dependencies. ########################################################### # all_libraries is used for the dependencies on LOCAL_BUILT_MODULE.
all_libraries := \
$(built_shared_library_deps) \
$(my_system_shared_libraries_fullpath) \
$(built_static_libraries) \
$(built_whole_libraries)
########################################################### # Export includes ###########################################################
# Headers exported by whole static libraries are also exported by this library.
export_include_deps := $(strip \
$(foreach l,$(my_whole_static_libraries), \
$(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross)))) # Re-export requested headers from shared libraries.
export_include_deps += $(strip \
$(foreach l,$(LOCAL_EXPORT_SHARED_LIBRARY_HEADERS), \
$(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross)))) # Re-export requested headers from static libraries.
export_include_deps += $(strip \
$(foreach l,$(LOCAL_EXPORT_STATIC_LIBRARY_HEADERS), \
$(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross)))) # Re-export requested headers from header libraries.
export_include_deps += $(strip \
$(foreach l,$(LOCAL_EXPORT_HEADER_LIBRARY_HEADERS), \
$(call intermediates-dir-for,HEADER_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))))
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.