blob: 917d7ee0ef875b97ddd41228f954f7a0a1dbdde6 [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001###########################################################
2## Standard rules for building binary object files from
Ying Wangd8d37212014-03-21 16:17:04 -07003## asm/c/cpp/yacc/lex/etc source files.
The Android Open Source Project88b60792009-03-03 19:28:42 -08004##
5## The list of object files is exported in $(all_objects).
6###########################################################
7
Ying Wangd8d37212014-03-21 16:17:04 -07008#######################################
9include $(BUILD_SYSTEM)/base_rules.mk
Chih-Hung Hsieh32427d62018-04-12 10:55:54 -070010include $(BUILD_SYSTEM)/use_lld_setup.mk
Ying Wangd8d37212014-03-21 16:17:04 -070011#######################################
12
Dan Albertd3d894d2014-11-14 15:28:49 -080013##################################################
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.
20ifdef 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
26else
27 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
Dimitry Ivanovcdf39272017-06-26 13:13:44 -070028 my_system_shared_libraries := libc libm libdl
Dan Albertd3d894d2014-11-14 15:28:49 -080029 else
30 my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES)
Dimitry Ivanovcdf39272017-06-26 13:13:44 -070031 my_system_shared_libraries := $(patsubst libc,libc libdl,$(my_system_shared_libraries))
Dan Albertd3d894d2014-11-14 15:28:49 -080032 endif
33endif
34
Dan Willemsenfc92fb22016-08-26 13:27:13 -070035my_soong_problems :=
36
Dan Albertd3d894d2014-11-14 15:28:49 -080037# 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.
40my_src_files := $(LOCAL_SRC_FILES)
Colin Crossa04abc82015-06-30 12:21:59 -070041my_src_files_exclude := $(LOCAL_SRC_FILES_EXCLUDE)
Dan Albertd3d894d2014-11-14 15:28:49 -080042my_static_libraries := $(LOCAL_STATIC_LIBRARIES)
43my_whole_static_libraries := $(LOCAL_WHOLE_STATIC_LIBRARIES)
Dimitry Ivanovcdf39272017-06-26 13:13:44 -070044my_shared_libraries := $(filter-out $(my_system_shared_libraries),$(LOCAL_SHARED_LIBRARIES))
Dan Willemsen8dae49c2017-02-15 15:48:11 -080045my_header_libraries := $(LOCAL_HEADER_LIBRARIES)
Dan Albertd3d894d2014-11-14 15:28:49 -080046my_cflags := $(LOCAL_CFLAGS)
Stephen Hines15680292014-11-26 00:53:46 -080047my_conlyflags := $(LOCAL_CONLYFLAGS)
Dan Albertd3d894d2014-11-14 15:28:49 -080048my_cppflags := $(LOCAL_CPPFLAGS)
Dan Willemsen7a5c5d72018-10-07 19:41:21 -070049my_cflags_no_override := $(GLOBAL_CLANG_CFLAGS_NO_OVERRIDE)
50my_cppflags_no_override := $(GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE)
Dan Albertd3d894d2014-11-14 15:28:49 -080051my_ldflags := $(LOCAL_LDFLAGS)
52my_ldlibs := $(LOCAL_LDLIBS)
53my_asflags := $(LOCAL_ASFLAGS)
54my_cc := $(LOCAL_CC)
Ying Wangc671a7c2015-07-20 18:40:18 -070055my_cc_wrapper := $(CC_WRAPPER)
Dan Albertd3d894d2014-11-14 15:28:49 -080056my_cxx := $(LOCAL_CXX)
Jiyong Park425d4892017-08-18 12:22:57 +090057my_cxx_ldlibs :=
Ying Wangc671a7c2015-07-20 18:40:18 -070058my_cxx_wrapper := $(CXX_WRAPPER)
Dan Albertd3d894d2014-11-14 15:28:49 -080059my_c_includes := $(LOCAL_C_INCLUDES)
60my_generated_sources := $(LOCAL_GENERATED_SOURCES)
Dan Willemsen1c6dc5b2016-01-06 14:28:36 -080061my_additional_dependencies := $(LOCAL_ADDITIONAL_DEPENDENCIES)
Ying Wangfaeb6932015-04-07 11:59:34 -070062my_export_c_include_dirs := $(LOCAL_EXPORT_C_INCLUDE_DIRS)
Dan Willemsenba6a1642016-09-29 12:08:29 -070063my_export_c_include_deps := $(LOCAL_EXPORT_C_INCLUDE_DEPS)
Evgenii Stepanove1b96f32017-01-23 16:57:38 -080064my_arflags :=
Dan Albertd3d894d2014-11-14 15:28:49 -080065
Ryan Campbella435aa52017-10-20 16:19:42 -070066ifneq (,$(strip $(foreach dir,$(COVERAGE_PATHS),$(filter $(dir)%,$(LOCAL_PATH)))))
67ifeq (,$(strip $(foreach dir,$(COVERAGE_EXCLUDE_PATHS),$(filter $(dir)%,$(LOCAL_PATH)))))
Ryan Campbell81c9d292016-09-12 13:56:50 -070068 my_native_coverage := true
69else
70 my_native_coverage := false
71endif
Ryan Campbellb55ff742017-02-27 09:09:16 -080072else
73 my_native_coverage := false
74endif
Ryan Campbell81c9d292016-09-12 13:56:50 -070075
Ivan Lozanofda9a6f2018-11-21 09:04:18 -080076ifeq ($(strip $(ENABLE_XOM)),true)
77 ifndef LOCAL_IS_HOST_MODULE
78 my_xom := true
79 # Disable XOM in excluded paths.
80 combined_xom_exclude_paths := $(XOM_EXCLUDE_PATHS) \
81 $(PRODUCT_XOM_EXCLUDE_PATHS)
82 ifneq ($(strip $(foreach dir,$(subst $(comma),$(space),$(combined_xom_exclude_paths)),\
83 $(filter $(dir)%,$(LOCAL_PATH)))),)
84 my_xom := false
85 endif
86
87 # Allow LOCAL_XOM to override the above
88 ifdef LOCAL_XOM
89 my_xom := $(LOCAL_XOM)
90 endif
91
92 ifeq ($(strip $(my_xom)),true)
93 ifeq (arm64,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
Ivan Lozanof9f03e02018-11-27 14:39:33 -080094 ifeq ($(my_use_clang_lld),true)
95 my_ldflags += -Wl,-execute-only
96 endif
Ivan Lozanofda9a6f2018-11-21 09:04:18 -080097 endif
98 endif
99 endif
100endif
101
Colin Crossa82fa122016-10-20 12:38:21 -0700102my_allow_undefined_symbols := $(strip $(LOCAL_ALLOW_UNDEFINED_SYMBOLS))
103ifdef SANITIZE_HOST
Dan Albertb58fb4a2014-11-14 17:15:00 -0800104ifdef LOCAL_IS_HOST_MODULE
105my_allow_undefined_symbols := true
Colin Crossa82fa122016-10-20 12:38:21 -0700106endif
Dan Albertb58fb4a2014-11-14 17:15:00 -0800107endif
108
Andrew Hsieh140761af02014-04-25 23:47:10 -0700109my_ndk_sysroot :=
110my_ndk_sysroot_include :=
111my_ndk_sysroot_lib :=
Dan Willemsenffa32582017-03-19 13:22:45 -0700112ifneq ($(LOCAL_SDK_VERSION),)
Ying Wang1a081002010-07-13 14:55:47 -0700113 ifdef LOCAL_IS_HOST_MODULE
Ian Rogers76a6dc32012-10-01 16:36:23 -0700114 $(error $(LOCAL_PATH): LOCAL_SDK_VERSION cannot be used in host module)
Ying Wang1a081002010-07-13 14:55:47 -0700115 endif
Nikola Veljkovicf7385622016-04-06 19:20:02 +0200116
Dan Albert02bf1382016-07-21 10:04:12 -0700117 # Make sure we've built the NDK.
Dan Albert248b8322017-12-14 13:52:04 -0800118 my_additional_dependencies += $(SOONG_OUT_DIR)/ndk_base.timestamp
Dan Albert02bf1382016-07-21 10:04:12 -0700119
Nikola Veljkovicf7385622016-04-06 19:20:02 +0200120 # mips32r6 is not supported by the NDK. No released NDK contains these
121 # libraries, but the r10 in prebuilts/ndk had a local hack to add them :(
122 #
123 # We need to find a real solution to this problem, but until we do just drop
124 # mips32r6 things back to r10 to get the tree building again.
125 ifeq (mips32r6,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH_VARIANT))
126 ifeq ($(LOCAL_NDK_VERSION), current)
127 LOCAL_NDK_VERSION := r10
128 endif
129 endif
130
Dan Albert02bf1382016-07-21 10:04:12 -0700131 my_arch := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
132 ifneq (,$(filter arm64 mips64 x86_64,$(my_arch)))
133 my_min_sdk_version := 21
134 else
Dan Albert105e4fe2017-08-17 16:24:46 -0700135 my_min_sdk_version := $(MIN_SUPPORTED_SDK_VERSION)
Dan Albert02bf1382016-07-21 10:04:12 -0700136 endif
137
138 # Historically we've just set up a bunch of symlinks in prebuilts/ndk to map
139 # missing API levels to existing ones where necessary, but we're not doing
140 # that for the generated libraries. Clip the API level to the minimum where
141 # appropriate.
Dan Willemsenffa32582017-03-19 13:22:45 -0700142 my_ndk_api := $(LOCAL_SDK_VERSION)
143 ifneq ($(my_ndk_api),current)
144 my_ndk_api := $(call math_max,$(my_ndk_api),$(my_min_sdk_version))
Dan Albert988107d2016-11-08 15:10:09 -0800145 endif
146
147 my_ndk_api_def := $(my_ndk_api)
148 my_ndk_hist_api := $(my_ndk_api)
149 ifeq ($(my_ndk_api),current)
150 my_ndk_api_def := __ANDROID_API_FUTURE__
151 # The last API level supported by the old prebuilt NDKs.
152 my_ndk_hist_api := 24
153 endif
154
Dan Albert02bf1382016-07-21 10:04:12 -0700155
Dan Albert754790d2016-08-05 16:34:40 -0700156 # Traditionally this has come from android/api-level.h, but with the libc
157 # headers unified it must be set by the build system since we don't have
158 # per-API level copies of that header now.
Dan Albert988107d2016-11-08 15:10:09 -0800159 my_cflags += -D__ANDROID_API__=$(my_ndk_api_def)
Dan Albert754790d2016-08-05 16:34:40 -0700160
Dan Albert02bf1382016-07-21 10:04:12 -0700161 my_ndk_source_root := \
162 $(HISTORICAL_NDK_VERSIONS_ROOT)/$(LOCAL_NDK_VERSION)/sources
163 my_ndk_sysroot := \
Dan Albert988107d2016-11-08 15:10:09 -0800164 $(HISTORICAL_NDK_VERSIONS_ROOT)/$(LOCAL_NDK_VERSION)/platforms/android-$(my_ndk_hist_api)/arch-$(my_arch)
Dan Albert02bf1382016-07-21 10:04:12 -0700165 my_built_ndk := $(SOONG_OUT_DIR)/ndk
166 my_ndk_triple := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_NDK_TRIPLE)
167 my_ndk_sysroot_include := \
168 $(my_built_ndk)/sysroot/usr/include \
169 $(my_built_ndk)/sysroot/usr/include/$(my_ndk_triple) \
170 $(my_ndk_sysroot)/usr/include \
Dan Albert445bc2f2015-12-11 12:49:18 -0800171
172 # x86_64 and and mips64 are both multilib toolchains, so their libraries are
173 # installed in /usr/lib64. Aarch64, on the other hand, is not a multilib
174 # compiler, so its libraries are in /usr/lib.
175 #
176 # Mips32r6 is yet another variation, with libraries installed in libr6.
177 #
178 # For the rest, the libraries are installed simply to /usr/lib.
Dan Albert02bf1382016-07-21 10:04:12 -0700179 ifneq (,$(filter x86_64 mips64,$(my_arch)))
180 my_ndk_libdir_name := lib64
Duane Sand1a074872014-11-08 15:25:18 -0800181 else ifeq (mips32r6,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH_VARIANT))
Dan Albert02bf1382016-07-21 10:04:12 -0700182 my_ndk_libdir_name := libr6
Andrew Hsieh140761af02014-04-25 23:47:10 -0700183 else
Dan Albert02bf1382016-07-21 10:04:12 -0700184 my_ndk_libdir_name := lib
Andrew Hsieh140761af02014-04-25 23:47:10 -0700185 endif
Ying Wangcce4c972011-03-03 18:53:53 -0800186
Dan Albert02bf1382016-07-21 10:04:12 -0700187 my_ndk_platform_dir := \
188 $(my_built_ndk)/platforms/android-$(my_ndk_api)/arch-$(my_arch)
189 my_built_ndk_libs := $(my_ndk_platform_dir)/usr/$(my_ndk_libdir_name)
190 my_ndk_sysroot_lib := $(my_ndk_sysroot)/usr/$(my_ndk_libdir_name)
191
Dan Willemsenffa32582017-03-19 13:22:45 -0700192 # The bionic linker now has support for packed relocations and gnu style
193 # hashes (which are much faster!), but shipping to older devices requires
194 # the old style hash. Fortunately, we can build with both and it'll work
195 # anywhere.
196 #
197 # This is not currently supported on MIPS architectures.
198 ifeq (,$(filter mips mips64,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)))
199 my_ldflags += -Wl,--hash-style=both
Dan Willemsenbab0fa62016-11-18 14:05:39 -0800200 endif
Dan Albertd3d894d2014-11-14 15:28:49 -0800201
Dan Willemsenffa32582017-03-19 13:22:45 -0700202 # We don't want to expose the relocation packer to the NDK just yet.
203 LOCAL_PACK_MODULE_RELOCATIONS := false
204
Ying Wangcce4c972011-03-03 18:53:53 -0800205 # Set up the NDK stl variant. Starting from NDK-r5 the c++ stl resides in a separate location.
206 # See ndk/docs/CPLUSPLUS-SUPPORT.html
207 my_ndk_stl_include_path :=
208 my_ndk_stl_shared_lib_fullpath :=
Ying Wangcce4c972011-03-03 18:53:53 -0800209 my_ndk_stl_static_lib :=
Duane Sand1a074872014-11-08 15:25:18 -0800210 my_cpu_variant := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)
Nikola Veljkovicf7385622016-04-06 19:20:02 +0200211 ifeq (mips32r6,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH_VARIANT))
212 my_cpu_variant := mips32r6
213 endif
Andrew Hsieh73d800e2014-03-04 17:11:52 +0800214 LOCAL_NDK_STL_VARIANT := $(strip $(LOCAL_NDK_STL_VARIANT))
Ying Wangcce4c972011-03-03 18:53:53 -0800215 ifeq (,$(LOCAL_NDK_STL_VARIANT))
Dan Albert37099682017-12-15 20:01:03 +0000216 LOCAL_NDK_STL_VARIANT := system
Ying Wangcce4c972011-03-03 18:53:53 -0800217 endif
Dan Albert19fbd1c2018-01-04 13:34:21 -0800218 ifneq (1,$(words $(filter none system c++_static c++_shared, $(LOCAL_NDK_STL_VARIANT))))
Ying Wang848020f2012-08-14 10:13:16 -0700219 $(error $(LOCAL_PATH): Unknown LOCAL_NDK_STL_VARIANT $(LOCAL_NDK_STL_VARIANT))
Ying Wangcce4c972011-03-03 18:53:53 -0800220 endif
Dan Albert19fbd1c2018-01-04 13:34:21 -0800221
Ying Wangcce4c972011-03-03 18:53:53 -0800222 ifeq (system,$(LOCAL_NDK_STL_VARIANT))
223 my_ndk_stl_include_path := $(my_ndk_source_root)/cxx-stl/system/include
Dan Albert0e2e71d2015-12-09 14:46:13 -0800224 my_system_shared_libraries += libstdc++
Dan Albert19fbd1c2018-01-04 13:34:21 -0800225 else ifneq (,$(filter c++_%, $(LOCAL_NDK_STL_VARIANT)))
Dan Albert3d1d1ea2017-12-15 15:25:06 -0800226 my_ndk_stl_include_path := \
227 $(my_ndk_source_root)/cxx-stl/llvm-libc++/include
228 my_ndk_stl_include_path += \
229 $(my_ndk_source_root)/cxx-stl/llvm-libc++abi/include
Dan Albert09607702016-08-08 17:14:59 -0700230 my_ndk_stl_include_path += $(my_ndk_source_root)/android/support/include
231
232 my_libcxx_libdir := \
233 $(my_ndk_source_root)/cxx-stl/llvm-libc++/libs/$(my_cpu_variant)
234
Dan Albert3d1d1ea2017-12-15 15:25:06 -0800235 ifeq (c++_static,$(LOCAL_NDK_STL_VARIANT))
236 my_ndk_stl_static_lib := \
237 $(my_libcxx_libdir)/libc++_static.a \
238 $(my_libcxx_libdir)/libc++abi.a
Dan Albert09607702016-08-08 17:14:59 -0700239 else
Dan Albert3d1d1ea2017-12-15 15:25:06 -0800240 my_ndk_stl_shared_lib_fullpath := $(my_libcxx_libdir)/libc++_shared.so
241 endif
Dan Albert09607702016-08-08 17:14:59 -0700242
Dan Albert3d1d1ea2017-12-15 15:25:06 -0800243 my_ndk_stl_static_lib += $(my_libcxx_libdir)/libandroid_support.a
244 ifneq (,$(filter armeabi armeabi-v7a,$(my_cpu_variant)))
245 my_ndk_stl_static_lib += $(my_libcxx_libdir)/libunwind.a
Dan Albert658d1e02016-03-22 17:17:40 -0700246 endif
247
Dan Albert2936a1e2016-09-14 16:08:04 -0700248 my_ldlibs += -ldl
Dan Albert0e2e71d2015-12-09 14:46:13 -0800249 else # LOCAL_NDK_STL_VARIANT must be none
250 # Do nothing.
251 endif
Dan Willemsenffa32582017-03-19 13:22:45 -0700252endif
253
254ifneq ($(LOCAL_USE_VNDK),)
Justin Yun65c680e2018-03-20 07:16:14 +0900255 # Required VNDK version for vendor modules is BOARD_VNDK_VERSION.
256 my_vndk_version := $(BOARD_VNDK_VERSION)
257 ifeq ($(my_vndk_version),current)
258 # Build with current PLATFORM_VNDK_VERSION.
259 # If PLATFORM_VNDK_VERSION has a CODENAME, it will return
260 # __ANDROID_API_FUTURE__.
261 my_vndk_version := $(call codename-or-sdk-to-sdk,$(PLATFORM_VNDK_VERSION))
262 endif
263 my_cflags += -D__ANDROID_API__=$(my_vndk_version) -D__ANDROID_VNDK__
Dan Albertc1ca1902016-08-04 14:14:50 -0700264endif
Dan Albert02bf1382016-07-21 10:04:12 -0700265
Dan Albertc1ca1902016-08-04 14:14:50 -0700266ifndef LOCAL_IS_HOST_MODULE
267# For device libraries, move LOCAL_LDLIBS references to my_shared_libraries. We
268# no longer need to use my_ldlibs to pick up NDK prebuilt libraries since we're
269# linking my_shared_libraries by full path now.
270my_allowed_ldlibs :=
271
272# Sort ldlibs and ldflags between -l and other linker flags
273# We'll do this again later, since there are still changes happening, but that's fine.
274my_ldlib_flags := $(my_ldflags) $(my_ldlibs)
275my_ldlibs := $(filter -l%,$(my_ldlib_flags))
276my_ldflags := $(filter-out -l%,$(my_ldlib_flags))
277my_ldlib_flags :=
278
279# Move other ldlibs back to shared libraries
280my_shared_libraries += $(patsubst -l%,lib%,$(filter-out $(my_allowed_ldlibs),$(my_ldlibs)))
281my_ldlibs := $(filter $(my_allowed_ldlibs),$(my_ldlibs))
Colin Cross0bd335f2017-09-08 14:41:22 -0700282else # LOCAL_IS_HOST_MODULE
Dan Willemsena3a06fe2017-09-26 20:26:11 -0700283 # Add -ldl, -lpthread, -lm and -lrt to host builds to match the default behavior of
Colin Cross0bd335f2017-09-08 14:41:22 -0700284 # device builds
285 ifneq ($($(my_prefix)OS),windows)
Dan Willemsena3a06fe2017-09-26 20:26:11 -0700286 my_ldlibs += -ldl -lpthread -lm
Colin Cross0bd335f2017-09-08 14:41:22 -0700287 ifneq ($(HOST_OS),darwin)
288 my_ldlibs += -lrt
289 endif
290 endif
Dan Albertc1ca1902016-08-04 14:14:50 -0700291endif
292
Dan Willemsenffa32582017-03-19 13:22:45 -0700293ifneq ($(LOCAL_SDK_VERSION),)
Dan Albertc1ca1902016-08-04 14:14:50 -0700294 my_all_ndk_libraries := \
295 $(NDK_MIGRATED_LIBS) $(addprefix lib,$(NDK_PREBUILT_SHARED_LIBRARIES))
296 my_ndk_shared_libraries := \
297 $(filter $(my_all_ndk_libraries),\
298 $(my_shared_libraries) $(my_system_shared_libraries))
299
300 my_shared_libraries := \
301 $(filter-out $(my_all_ndk_libraries),$(my_shared_libraries))
Dan Albert02bf1382016-07-21 10:04:12 -0700302 my_system_shared_libraries := \
Dan Albertc1ca1902016-08-04 14:14:50 -0700303 $(filter-out $(my_all_ndk_libraries),$(my_system_shared_libraries))
Ying Wang1a081002010-07-13 14:55:47 -0700304endif
305
Dan Albert95994de2014-08-07 18:29:11 -0700306# MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because
307# all code is position independent, and then those warnings get promoted to
308# errors.
Alexey Polyudovcbb038c2016-08-01 17:36:39 -0700309ifneq ($(LOCAL_NO_PIC),true)
Colin Crossfeb4a7e2018-09-19 14:45:52 -0700310 ifneq ($($(my_prefix)OS),windows)
311 ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),)
312 my_cflags += -fPIE
313 ifndef BUILD_HOST_static
314 ifneq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
315 my_ldflags += -pie
316 endif
317 endif
318 else
319 my_cflags += -fPIC
320 endif
321 endif
Alexey Polyudovcbb038c2016-08-01 17:36:39 -0700322endif
Dan Albert4803ce22014-08-06 12:36:46 -0700323
Dan Willemsen7a549852015-08-13 17:51:40 -0700324ifdef LOCAL_IS_HOST_MODULE
Dan Willemsen85ac8d22015-08-18 17:47:06 -0700325my_src_files += $(LOCAL_SRC_FILES_$($(my_prefix)OS)) $(LOCAL_SRC_FILES_$($(my_prefix)OS)_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
Dan Willemsen7a549852015-08-13 17:51:40 -0700326my_static_libraries += $(LOCAL_STATIC_LIBRARIES_$($(my_prefix)OS))
327my_shared_libraries += $(LOCAL_SHARED_LIBRARIES_$($(my_prefix)OS))
Dan Willemsen8dae49c2017-02-15 15:48:11 -0800328my_header_libraries += $(LOCAL_HEADER_LIBRARIES_$($(my_prefix)OS))
Dan Willemsen7a549852015-08-13 17:51:40 -0700329my_cflags += $(LOCAL_CFLAGS_$($(my_prefix)OS))
330my_cppflags += $(LOCAL_CPPFLAGS_$($(my_prefix)OS))
331my_ldflags += $(LOCAL_LDFLAGS_$($(my_prefix)OS))
332my_ldlibs += $(LOCAL_LDLIBS_$($(my_prefix)OS))
333my_asflags += $(LOCAL_ASFLAGS_$($(my_prefix)OS))
334my_c_includes += $(LOCAL_C_INCLUDES_$($(my_prefix)OS))
335my_generated_sources += $(LOCAL_GENERATED_SOURCES_$($(my_prefix)OS))
336endif
337
Ying Wang6feb6d52014-04-17 10:03:35 -0700338my_src_files += $(LOCAL_SRC_FILES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_SRC_FILES_$(my_32_64_bit_suffix))
Colin Crossa04abc82015-06-30 12:21:59 -0700339my_src_files_exclude += $(LOCAL_SRC_FILES_EXCLUDE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_SRC_FILES_EXCLUDE_$(my_32_64_bit_suffix))
Ying Wang6feb6d52014-04-17 10:03:35 -0700340my_shared_libraries += $(LOCAL_SHARED_LIBRARIES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_SHARED_LIBRARIES_$(my_32_64_bit_suffix))
341my_cflags += $(LOCAL_CFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CFLAGS_$(my_32_64_bit_suffix))
342my_cppflags += $(LOCAL_CPPFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CPPFLAGS_$(my_32_64_bit_suffix))
343my_ldflags += $(LOCAL_LDFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_LDFLAGS_$(my_32_64_bit_suffix))
344my_asflags += $(LOCAL_ASFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_ASFLAGS_$(my_32_64_bit_suffix))
345my_c_includes += $(LOCAL_C_INCLUDES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_C_INCLUDES_$(my_32_64_bit_suffix))
346my_generated_sources += $(LOCAL_GENERATED_SOURCES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_GENERATED_SOURCES_$(my_32_64_bit_suffix))
Colin Crossf4f2fbe2014-02-12 21:15:12 -0800347
Dan Willemsenc29172c2015-12-03 22:58:39 -0800348my_missing_exclude_files := $(filter-out $(my_src_files),$(my_src_files_exclude))
349ifneq ($(my_missing_exclude_files),)
350$(warning Files are listed in LOCAL_SRC_FILES_EXCLUDE but not LOCAL_SRC_FILES)
351$(error $(my_missing_exclude_files))
352endif
Colin Crossa04abc82015-06-30 12:21:59 -0700353my_src_files := $(filter-out $(my_src_files_exclude),$(my_src_files))
354
Dan Willemsenc57894c2016-10-28 16:30:48 -0700355# Strip '/' from the beginning of each src file. This helps the ../ detection in case
356# the source file is in the form of /../file
357my_src_files := $(patsubst /%,%,$(my_src_files))
358
Dan Albertdb905e72014-08-18 11:14:38 -0700359my_clang := $(strip $(LOCAL_CLANG))
Ying Wang824344a2014-05-27 13:03:36 -0700360ifdef LOCAL_CLANG_$(my_32_64_bit_suffix)
Dan Albertdb905e72014-08-18 11:14:38 -0700361my_clang := $(strip $(LOCAL_CLANG_$(my_32_64_bit_suffix)))
Ying Wang824344a2014-05-27 13:03:36 -0700362endif
363ifdef LOCAL_CLANG_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
Dan Albertdb905e72014-08-18 11:14:38 -0700364my_clang := $(strip $(LOCAL_CLANG_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)))
Ying Wang824344a2014-05-27 13:03:36 -0700365endif
Chih-Hung Hsiehd9cd1fa2016-08-02 14:22:06 -0700366ifeq ($(my_clang),false)
Dan Willemsenf0638392018-09-04 22:25:22 -0700367 $(call pretty-error,LOCAL_CLANG false is no longer supported)
Dan Willemsen77288172015-09-09 15:45:21 -0700368endif
369
Dan Albert76bfcd42017-02-03 16:16:11 -0800370ifeq ($(LOCAL_C_STD),)
371 my_c_std_version := $(DEFAULT_C_STD_VERSION)
372else ifeq ($(LOCAL_C_STD),experimental)
373 my_c_std_version := $(EXPERIMENTAL_C_STD_VERSION)
374else
375 my_c_std_version := $(LOCAL_C_STD)
376endif
377
378ifeq ($(LOCAL_CPP_STD),)
379 my_cpp_std_version := $(DEFAULT_CPP_STD_VERSION)
380else ifeq ($(LOCAL_CPP_STD),experimental)
381 my_cpp_std_version := $(EXPERIMENTAL_CPP_STD_VERSION)
382else
383 my_cpp_std_version := $(LOCAL_CPP_STD)
384endif
Dan Albertda637392015-10-26 11:09:24 -0700385
Colin Crosse56e3562016-10-17 15:34:29 -0700386my_c_std_conlyflags :=
387my_cpp_std_cppflags :=
388ifneq (,$(my_c_std_version))
389 my_c_std_conlyflags := -std=$(my_c_std_version)
390endif
Dan Albertc7d307d2015-07-29 15:13:57 -0700391
Colin Crosse56e3562016-10-17 15:34:29 -0700392ifneq (,$(my_cpp_std_version))
393 my_cpp_std_cppflags := -std=$(my_cpp_std_version)
394endif
Tim Murray06659bc2014-08-13 11:53:07 -0700395
Yi Kong42e18962018-06-06 16:42:22 -0700396# Extra cflags for projects under external/ directory
Yi Kong0047dbe2018-06-12 15:28:26 -0700397ifneq ($(filter external/%,$(LOCAL_PATH)),)
Yi Kong42e18962018-06-06 16:42:22 -0700398 my_cflags += $(CLANG_EXTERNAL_CFLAGS)
399endif
Yi Kong42e18962018-06-06 16:42:22 -0700400
Colin Crossf4f2fbe2014-02-12 21:15:12 -0800401# arch-specific static libraries go first so that generic ones can depend on them
Ying Wang6feb6d52014-04-17 10:03:35 -0700402my_static_libraries := $(LOCAL_STATIC_LIBRARIES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_STATIC_LIBRARIES_$(my_32_64_bit_suffix)) $(my_static_libraries)
403my_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)
Dan Willemsen8dae49c2017-02-15 15:48:11 -0800404my_header_libraries := $(LOCAL_HEADER_LIBRARIES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_HEADER_LIBRARIES_$(my_32_64_bit_suffix)) $(my_header_libraries)
Ying Wang6ef65192014-01-15 16:02:16 -0800405
Ying Wang75e8fcb2014-10-07 13:03:29 -0700406include $(BUILD_SYSTEM)/cxx_stl_setup.mk
Ying Wangd90de322014-05-23 16:42:37 -0700407
Ying Wang285045b2013-08-13 12:35:10 -0700408# Add static HAL libraries
409ifdef LOCAL_HAL_STATIC_LIBRARIES
410$(foreach lib, $(LOCAL_HAL_STATIC_LIBRARIES), \
411 $(eval b_lib := $(filter $(lib).%,$(BOARD_HAL_STATIC_LIBRARIES)))\
Ying Wang6ef65192014-01-15 16:02:16 -0800412 $(if $(b_lib), $(eval my_static_libraries += $(b_lib)),\
413 $(eval my_static_libraries += $(lib).default)))
Ying Wang285045b2013-08-13 12:35:10 -0700414b_lib :=
415endif
416
Nicolas Geoffrayb7c9f322015-09-25 13:54:09 +0100417ifneq ($(strip $(CUSTOM_$(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)LINKER)),)
418 my_linker := $(CUSTOM_$(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)LINKER)
419else
Alexey Polyudovccdc3112016-08-01 17:41:49 -0700420 my_linker := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)LINKER)
Nicolas Geoffrayb7c9f322015-09-25 13:54:09 +0100421endif
Evgenii Stepanov8f5e67a2015-07-10 18:06:51 -0700422
Dan Albert4ae5d4b2014-10-31 16:23:08 -0700423include $(BUILD_SYSTEM)/config_sanitizers.mk
Evgeniy Stepanov6cc9c062012-03-30 12:15:12 +0400424
Josh Gao4d9268e2017-02-23 13:17:46 -0800425# Statically link libwinpthread when cross compiling win32.
426ifeq ($($(my_prefix)OS),windows)
427 my_static_libraries += libwinpthread
428endif
429
Dan Willemsenfc92fb22016-08-26 13:27:13 -0700430ifneq ($(filter ../%,$(my_src_files)),)
431my_soong_problems += dotdot_srcs
432endif
433ifneq ($(foreach i,$(my_c_includes),$(filter %/..,$(i))$(findstring /../,$(i))),)
434my_soong_problems += dotdot_incs
435endif
436ifneq ($(filter %.arm,$(my_src_files)),)
437my_soong_problems += srcs_dotarm
438endif
439
Jing Yu2dcc8062009-09-21 16:31:50 -0700440####################################################
441## Add FDO flags if FDO is turned on and supported
Dehao Chen295a6d22014-09-19 10:18:12 -0700442## Please note that we will do option filtering during FDO build.
443## i.e. Os->O2, remove -fno-early-inline and -finline-limit.
444##################################################################
Ying Wang45d01432014-10-28 14:50:59 -0700445my_fdo_build :=
446ifneq ($(filter true always, $(LOCAL_FDO_SUPPORT)),)
447 ifeq ($(BUILD_FDO_INSTRUMENT),true)
448 my_cflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_INSTRUMENT_CFLAGS)
449 my_ldflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_INSTRUMENT_LDFLAGS)
450 my_fdo_build := true
451 else ifneq ($(filter true,$(BUILD_FDO_OPTIMIZE))$(filter always,$(LOCAL_FDO_SUPPORT)),)
452 my_cflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_OPTIMIZE_CFLAGS)
453 my_fdo_build := true
synergydev4a605762013-08-05 02:44:37 -0700454 endif
Shinichiro Hamaji09295a82015-09-24 17:51:20 +0900455 # Disable ccache (or other compiler wrapper) except gomacc, which
456 # can handle -fprofile-use properly.
457 my_cc_wrapper := $(filter $(GOMA_CC),$(my_cc_wrapper))
458 my_cxx_wrapper := $(filter $(GOMA_CC),$(my_cxx_wrapper))
Jing Yu2dcc8062009-09-21 16:31:50 -0700459endif
460
The Android Open Source Project88b60792009-03-03 19:28:42 -0800461###########################################################
Jim Huang20d1ba62010-10-14 16:15:56 +0800462## Explicitly declare assembly-only __ASSEMBLY__ macro for
463## assembly source
464###########################################################
Ying Wang6ef65192014-01-15 16:02:16 -0800465my_asflags += -D__ASSEMBLY__
Jim Huang20d1ba62010-10-14 16:15:56 +0800466
Dan Willemsenffa32582017-03-19 13:22:45 -0700467###########################################################
Ying Wang1a081002010-07-13 14:55:47 -0700468## Define PRIVATE_ variables from global vars
469###########################################################
Ying Wang7fff9a12014-01-09 14:39:41 -0800470ifndef LOCAL_IS_HOST_MODULE
Dan Willemsenbab0fa62016-11-18 14:05:39 -0800471ifdef LOCAL_USE_VNDK
472my_target_global_c_includes := \
473 $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)PROJECT_INCLUDES)
474my_target_global_c_system_includes := \
Jiyong Park7f8be9f2017-07-06 09:45:26 +0900475 $(TARGET_OUT_HEADERS) \
Dan Willemsenffa32582017-03-19 13:22:45 -0700476 $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)PROJECT_SYSTEM_INCLUDES)
Dan Willemsenbab0fa62016-11-18 14:05:39 -0800477else ifdef LOCAL_SDK_VERSION
Colin Cross23ba6122016-07-20 12:22:57 -0700478my_target_global_c_includes :=
479my_target_global_c_system_includes := $(my_ndk_stl_include_path) $(my_ndk_sysroot_include)
Dan Willemsenbab0fa62016-11-18 14:05:39 -0800480else ifdef BOARD_VNDK_VERSION
Colin Cross23ba6122016-07-20 12:22:57 -0700481my_target_global_c_includes := $(SRC_HEADERS) \
Alexey Polyudovccdc3112016-08-01 17:41:49 -0700482 $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)PROJECT_INCLUDES) \
483 $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)C_INCLUDES)
Colin Cross23ba6122016-07-20 12:22:57 -0700484my_target_global_c_system_includes := $(SRC_SYSTEM_HEADERS) \
Alexey Polyudovccdc3112016-08-01 17:41:49 -0700485 $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)PROJECT_SYSTEM_INCLUDES) \
486 $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)C_SYSTEM_INCLUDES)
Dan Willemsenbab0fa62016-11-18 14:05:39 -0800487else
488my_target_global_c_includes := $(SRC_HEADERS) \
489 $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)PROJECT_INCLUDES) \
490 $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)C_INCLUDES)
491my_target_global_c_system_includes := $(SRC_SYSTEM_HEADERS) $(TARGET_OUT_HEADERS) \
492 $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)PROJECT_SYSTEM_INCLUDES) \
493 $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)C_SYSTEM_INCLUDES)
494endif
Ying Wangf4723fa2013-08-15 11:01:10 -0700495
Alexey Polyudovccdc3112016-08-01 17:41:49 -0700496my_target_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CFLAGS)
Colin Crosse56e3562016-10-17 15:34:29 -0700497my_target_global_conlyflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CONLYFLAGS) $(my_c_std_conlyflags)
498my_target_global_cppflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CPPFLAGS) $(my_cpp_std_cppflags)
Chih-Hung Hsieh32427d62018-04-12 10:55:54 -0700499ifeq ($(my_use_clang_lld),true)
500 my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_LLDFLAGS)
Chih-Hung Hsieh289e8d62018-05-24 15:13:19 -0700501 include $(BUILD_SYSTEM)/pack_dyn_relocs_setup.mk
502 ifeq ($(my_pack_module_relocations),false)
503 my_target_global_ldflags += -Wl,--pack-dyn-relocs=none
504 endif
Chih-Hung Hsieh32427d62018-04-12 10:55:54 -0700505else
506 my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_LDFLAGS)
507endif # my_use_clang_lld
Ying Wangda4bf422012-08-16 16:45:01 -0700508
Colin Crosse25fd792016-07-19 13:19:21 -0700509$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_GLOBAL_C_INCLUDES := $(my_target_global_c_includes)
Colin Cross23ba6122016-07-20 12:22:57 -0700510$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_GLOBAL_C_SYSTEM_INCLUDES := $(my_target_global_c_system_includes)
Ying Wang1a081002010-07-13 14:55:47 -0700511$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CFLAGS := $(my_target_global_cflags)
Stephen Hines15680292014-11-26 00:53:46 -0800512$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CONLYFLAGS := $(my_target_global_conlyflags)
Logan Chiene6f65432013-12-10 19:07:41 +0800513$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CPPFLAGS := $(my_target_global_cppflags)
514$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_LDFLAGS := $(my_target_global_ldflags)
515
Ying Wang7fff9a12014-01-09 14:39:41 -0800516else # LOCAL_IS_HOST_MODULE
517
Colin Cross23ba6122016-07-20 12:22:57 -0700518my_host_global_c_includes := $(SRC_HEADERS) \
Colin Crosse25fd792016-07-19 13:19:21 -0700519 $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)C_INCLUDES)
Colin Cross23ba6122016-07-20 12:22:57 -0700520my_host_global_c_system_includes := $(SRC_SYSTEM_HEADERS) \
Colin Cross23ba6122016-07-20 12:22:57 -0700521 $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)C_SYSTEM_INCLUDES)
Colin Crosse25fd792016-07-19 13:19:21 -0700522
Dan Willemsen057aaea2015-08-14 12:59:50 -0700523my_host_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CFLAGS)
Colin Crosse56e3562016-10-17 15:34:29 -0700524my_host_global_conlyflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CONLYFLAGS) $(my_c_std_conlyflags)
525my_host_global_cppflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CPPFLAGS) $(my_cpp_std_cppflags)
Chih-Hung Hsieh4955b852018-04-17 14:15:14 -0700526ifeq ($(my_use_clang_lld),true)
527 my_host_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_LLDFLAGS)
528else
529 my_host_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_LDFLAGS)
530endif # my_use_clang_lld
Logan Chiene6f65432013-12-10 19:07:41 +0800531
Colin Crosse25fd792016-07-19 13:19:21 -0700532$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_GLOBAL_C_INCLUDES := $(my_host_global_c_includes)
Colin Cross23ba6122016-07-20 12:22:57 -0700533$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_GLOBAL_C_SYSTEM_INCLUDES := $(my_host_global_c_system_includes)
Logan Chiene6f65432013-12-10 19:07:41 +0800534$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CFLAGS := $(my_host_global_cflags)
Stephen Hines15680292014-11-26 00:53:46 -0800535$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CONLYFLAGS := $(my_host_global_conlyflags)
Logan Chiene6f65432013-12-10 19:07:41 +0800536$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_CPPFLAGS := $(my_host_global_cppflags)
537$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HOST_GLOBAL_LDFLAGS := $(my_host_global_ldflags)
538endif # LOCAL_IS_HOST_MODULE
Ying Wang1a081002010-07-13 14:55:47 -0700539
Dan Albert43e128a2015-01-23 16:12:57 -0800540# To enable coverage for a given module, set LOCAL_NATIVE_COVERAGE=true and
541# build with NATIVE_COVERAGE=true in your enviornment. Note that the build
542# system is not sensitive to changes to NATIVE_COVERAGE, so you should do a
543# clean build of your module after toggling it.
544ifeq ($(NATIVE_COVERAGE),true)
545 ifeq ($(my_native_coverage),true)
Dan Albert343ed672015-01-25 16:20:57 -0800546 # Note that clang coverage doesn't play nicely with acov out of the box.
547 # Clang apparently generates .gcno files that aren't compatible with
548 # gcov-4.8. This can be solved by installing gcc-4.6 and invoking lcov
549 # with `--gcov-tool /usr/bin/gcov-4.6`.
550 #
551 # http://stackoverflow.com/questions/17758126/clang-code-coverage-invalid-output
Dan Albert2c03e042015-01-24 15:14:35 -0800552 my_cflags += --coverage -O0
Dan Albert343ed672015-01-25 16:20:57 -0800553 my_ldflags += --coverage
Dan Albert43e128a2015-01-23 16:12:57 -0800554 endif
Dan Willemsen7db70a32016-08-23 06:53:47 +0000555
Dan Willemsenf0638392018-09-04 22:25:22 -0700556 my_coverage_lib := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)LIBPROFILE_RT)
Dan Willemsen7db70a32016-08-23 06:53:47 +0000557
558 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_COVERAGE_LIB := $(my_coverage_lib)
559 $(LOCAL_INTERMEDIATE_TARGETS): $(my_coverage_lib)
Dan Albert43e128a2015-01-23 16:12:57 -0800560else
561 my_native_coverage := false
562endif
563
Ying Wang1a081002010-07-13 14:55:47 -0700564###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800565## Define PRIVATE_ variables used by multiple module types
566###########################################################
567$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_NO_DEFAULT_COMPILER_FLAGS := \
Ying Wangdfbe79b2012-03-22 11:26:22 -0700568 $(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800569
Andrew Hsieh906cb782013-09-10 17:37:14 +0800570ifeq ($(strip $(WITH_STATIC_ANALYZER)),)
571 LOCAL_NO_STATIC_ANALYZER := true
572endif
573
Andrew Hsieh6cea59a2013-08-27 17:33:06 +0800574ifneq ($(strip $(LOCAL_IS_HOST_MODULE)),)
575 my_syntax_arch := host
576else
Alexey Polyudovccdc3112016-08-01 17:41:49 -0700577 my_syntax_arch := $($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
Andrew Hsieh6cea59a2013-08-27 17:33:06 +0800578endif
579
Ying Wang6ef65192014-01-15 16:02:16 -0800580ifeq ($(strip $(my_cc)),)
Dan Willemsenf0638392018-09-04 22:25:22 -0700581 my_cc := $(my_cc_wrapper) $(CLANG)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800582endif
Chih-Hung Hsieh765c1ea2016-02-02 11:30:39 -0800583
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800584SYNTAX_TOOLS_PREFIX := \
585 $(LLVM_PREBUILTS_BASE)/$(BUILD_OS)-x86/$(LLVM_PREBUILTS_VERSION)/libexec
586
Andrew Hsieh906cb782013-09-10 17:37:14 +0800587ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
Chih-Hung Hsieh765c1ea2016-02-02 11:30:39 -0800588 my_cc := CCC_CC=$(CLANG) CLANG=$(CLANG) \
589 $(SYNTAX_TOOLS_PREFIX)/ccc-analyzer
Andrew Hsieh906cb782013-09-10 17:37:14 +0800590endif
Chih-Hung Hsieh765c1ea2016-02-02 11:30:39 -0800591
Ying Wang6ef65192014-01-15 16:02:16 -0800592$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CC := $(my_cc)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800593
Ying Wang6ef65192014-01-15 16:02:16 -0800594ifeq ($(strip $(my_cxx)),)
Dan Willemsenf0638392018-09-04 22:25:22 -0700595 my_cxx := $(my_cxx_wrapper) $(CLANG_CXX)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800596endif
Chih-Hung Hsieh765c1ea2016-02-02 11:30:39 -0800597
Andrew Hsieh906cb782013-09-10 17:37:14 +0800598ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
Chih-Hung Hsieh765c1ea2016-02-02 11:30:39 -0800599 my_cxx := CCC_CXX=$(CLANG_CXX) CLANG_CXX=$(CLANG_CXX) \
600 $(SYNTAX_TOOLS_PREFIX)/c++-analyzer
Andrew Hsieh906cb782013-09-10 17:37:14 +0800601endif
Chih-Hung Hsieh765c1ea2016-02-02 11:30:39 -0800602
Evgenii Stepanov8f5e67a2015-07-10 18:06:51 -0700603$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LINKER := $(my_linker)
Ying Wang6ef65192014-01-15 16:02:16 -0800604$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CXX := $(my_cxx)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800605
606# TODO: support a mix of standard extensions so that this isn't necessary
607LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION))
608ifeq ($(LOCAL_CPP_EXTENSION),)
609 LOCAL_CPP_EXTENSION := .cpp
610endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800611
612# Certain modules like libdl have to have symbols resolved at runtime and blow
613# up if --no-undefined is passed to the linker.
614ifeq ($(strip $(LOCAL_NO_DEFAULT_COMPILER_FLAGS)),)
Colin Crossa82fa122016-10-20 12:38:21 -0700615 ifeq ($(my_allow_undefined_symbols),)
616 ifneq ($(HOST_OS),darwin)
617 my_ldflags += -Wl,--no-undefined
618 endif
619 else
620 ifdef LOCAL_IS_HOST_MODULE
621 ifeq ($(HOST_OS),darwin)
622 # darwin defaults to treating undefined symbols as errors
623 my_ldflags += -Wl,-undefined,dynamic_lookup
624 endif
625 endif
626 endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800627endif
628
Ying Wangfcdabd42011-04-25 14:22:41 -0700629ifeq (true,$(LOCAL_GROUP_STATIC_LIBRARIES))
630$(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES := true
631else
632$(LOCAL_BUILT_MODULE): PRIVATE_GROUP_STATIC_LIBRARIES :=
633endif
634
The Android Open Source Project88b60792009-03-03 19:28:42 -0800635###########################################################
636## Define arm-vs-thumb-mode flags.
637###########################################################
638LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE))
Ying Wangfaeb6932015-04-07 11:59:34 -0700639ifeq ($($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH),arm)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800640arm_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),arm)
641normal_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),thumb)
642
Dave Bort95282482009-04-23 18:44:55 -0700643# Read the values from something like TARGET_arm_CFLAGS or
644# TARGET_thumb_CFLAGS. HOST_(arm|thumb)_CFLAGS values aren't
645# actually used (although they are usually empty).
Ying Wang6ef65192014-01-15 16:02:16 -0800646arm_objects_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)$(arm_objects_mode)_CFLAGS)
647normal_objects_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)$(normal_objects_mode)_CFLAGS)
Evgeniy Stepanovf50f4c52012-04-05 11:44:37 +0400648
Chih-Wei Huang0d09e582010-07-09 10:07:52 +0800649else
650arm_objects_mode :=
651normal_objects_mode :=
652arm_objects_cflags :=
653normal_objects_cflags :=
654endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800655
656###########################################################
657## Define per-module debugging flags. Users can turn on
658## debugging for a particular module by setting DEBUG_MODULE_ModuleName
659## to a non-empty value in their environment or buildspec.mk,
660## and setting HOST_/TARGET_CUSTOM_DEBUG_CFLAGS to the
661## debug flags that they want to use.
662###########################################################
663ifdef DEBUG_MODULE_$(strip $(LOCAL_MODULE))
664 debug_cflags := $($(my_prefix)CUSTOM_DEBUG_CFLAGS)
665else
666 debug_cflags :=
667endif
668
Tim Murraya7aa8002012-10-29 16:06:00 -0700669####################################################
Dan Willemsen3bb168f2016-01-19 20:07:08 -0800670## Keep track of src -> obj mapping
671####################################################
672
673my_tracked_gen_files :=
674my_tracked_src_files :=
675
676###########################################################
677## Stuff source generated from one-off tools
678###########################################################
679$(my_generated_sources): PRIVATE_MODULE := $(my_register_name)
680
681my_gen_sources_copy := $(patsubst $(generated_sources_dir)/%,$(intermediates)/%,$(filter $(generated_sources_dir)/%,$(my_generated_sources)))
682
Dan Willemsen7f016152016-02-29 17:52:39 -0800683$(my_gen_sources_copy): $(intermediates)/% : $(generated_sources_dir)/%
Dan Willemsen3bb168f2016-01-19 20:07:08 -0800684 @echo "Copy: $@"
685 $(copy-file-to-target)
686
687my_generated_sources := $(patsubst $(generated_sources_dir)/%,$(intermediates)/%,$(my_generated_sources))
688
689# Generated sources that will actually produce object files.
690# Other files (like headers) are allowed in LOCAL_GENERATED_SOURCES,
691# since other compiled sources may depend on them, and we set up
692# the dependencies.
Dan Willemsen444c3232016-02-04 14:18:48 -0800693my_gen_src_files := $(filter %.c %$(LOCAL_CPP_EXTENSION) %.S %.s,$(my_generated_sources))
Dan Willemsen3bb168f2016-01-19 20:07:08 -0800694
695ALL_GENERATED_SOURCES += $(my_generated_sources)
696
697####################################################
Tim Murraya7aa8002012-10-29 16:06:00 -0700698## Compile RenderScript with reflected C++
699####################################################
700
Ying Wangb8e01852014-01-23 15:09:04 -0800701renderscript_sources := $(filter %.rs %.fs,$(my_src_files))
Tim Murraya7aa8002012-10-29 16:06:00 -0700702
703ifneq (,$(renderscript_sources))
Dan Willemsenfc92fb22016-08-26 13:27:13 -0700704my_soong_problems += rs
Tim Murraya7aa8002012-10-29 16:06:00 -0700705
706renderscript_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(renderscript_sources))
707RenderScript_file_stamp := $(intermediates)/RenderScriptCPP.stamp
708renderscript_intermediate := $(intermediates)/renderscript
709
Noah Presler4796a8c2015-08-13 17:04:10 -0700710renderscript_target_api :=
711
712ifneq (,$(LOCAL_RENDERSCRIPT_TARGET_API))
713renderscript_target_api := $(LOCAL_RENDERSCRIPT_TARGET_API)
714else
715ifneq (,$(LOCAL_SDK_VERSION))
716# Set target-api for LOCAL_SDK_VERSIONs other than current.
Michael Wright0fb087f2015-11-06 15:20:51 +0000717ifneq (,$(filter-out current system_current test_current, $(LOCAL_SDK_VERSION)))
Sundong Ahn5a44d1f2017-10-16 19:20:34 +0900718renderscript_target_api := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION))
Noah Presler4796a8c2015-08-13 17:04:10 -0700719endif
720endif # LOCAL_SDK_VERSION is set
721endif # LOCAL_RENDERSCRIPT_TARGET_API is set
722
723
Tim Murraya7aa8002012-10-29 16:06:00 -0700724ifeq ($(LOCAL_RENDERSCRIPT_CC),)
725LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC)
726endif
727
728# Turn on all warnings and warnings as errors for RS compiles.
729# This can be disabled with LOCAL_RENDERSCRIPT_FLAGS := -Wno-error
730renderscript_flags := -Wall -Werror
731renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS)
Ying Wangacaada12014-09-10 16:11:41 -0700732# -m32 or -m64
733renderscript_flags += -m$(my_32_64_bit_suffix)
Tim Murrayf0020c62014-09-10 15:11:01 -0700734
Ying Wang6ef65192014-01-15 16:02:16 -0800735renderscript_includes := \
Tim Murraya7aa8002012-10-29 16:06:00 -0700736 $(TOPDIR)external/clang/lib/Headers \
Jean-Luc Brouilleteba44932017-01-08 17:40:21 -0800737 $(TOPDIR)frameworks/rs/script_api/include \
Tim Murraya7aa8002012-10-29 16:06:00 -0700738 $(LOCAL_RENDERSCRIPT_INCLUDES)
739
740ifneq ($(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE),)
Ying Wang6ef65192014-01-15 16:02:16 -0800741renderscript_includes := $(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE)
Tim Murraya7aa8002012-10-29 16:06:00 -0700742endif
743
Ying Wangb9319562015-04-03 16:15:28 -0700744bc_dep_files := $(addprefix $(renderscript_intermediate)/, \
745 $(patsubst %.fs,%.d, $(patsubst %.rs,%.d, $(notdir $(renderscript_sources)))))
746
Ying Wang6ef65192014-01-15 16:02:16 -0800747$(RenderScript_file_stamp): PRIVATE_RS_INCLUDES := $(renderscript_includes)
Tim Murraya7aa8002012-10-29 16:06:00 -0700748$(RenderScript_file_stamp): PRIVATE_RS_CC := $(LOCAL_RENDERSCRIPT_CC)
749$(RenderScript_file_stamp): PRIVATE_RS_FLAGS := $(renderscript_flags)
750$(RenderScript_file_stamp): PRIVATE_RS_SOURCE_FILES := $(renderscript_sources_fullpath)
751$(RenderScript_file_stamp): PRIVATE_RS_OUTPUT_DIR := $(renderscript_intermediate)
Colin Crosse2f541b2018-05-16 09:53:40 -0700752$(RenderScript_file_stamp): PRIVATE_RS_TARGET_API := $(patsubst current,0,$(renderscript_target_api))
Ying Wangb9319562015-04-03 16:15:28 -0700753$(RenderScript_file_stamp): PRIVATE_DEP_FILES := $(bc_dep_files)
Tim Murraya7aa8002012-10-29 16:06:00 -0700754$(RenderScript_file_stamp): $(renderscript_sources_fullpath) $(LOCAL_RENDERSCRIPT_CC)
755 $(transform-renderscripts-to-cpp-and-bc)
756
Dan Willemsen461d8442016-11-10 18:19:36 -0800757# include the dependency files (.d) generated by llvm-rs-cc.
758$(call include-depfile,$(RenderScript_file_stamp).d,$(RenderScript_file_stamp))
Tim Murraya7aa8002012-10-29 16:06:00 -0700759
760LOCAL_INTERMEDIATE_TARGETS += $(RenderScript_file_stamp)
761
762rs_generated_cpps := $(addprefix \
763 $(renderscript_intermediate)/ScriptC_,$(patsubst %.fs,%.cpp, $(patsubst %.rs,%.cpp, \
764 $(notdir $(renderscript_sources)))))
765
Dan Willemsen3bb168f2016-01-19 20:07:08 -0800766$(call track-src-file-gen,$(renderscript_sources),$(rs_generated_cpps))
767
Stephen Hines8ff92522014-06-06 12:51:47 -0700768# This is just a dummy rule to make sure gmake doesn't skip updating the dependents.
Tim Murraya7aa8002012-10-29 16:06:00 -0700769$(rs_generated_cpps) : $(RenderScript_file_stamp)
Ying Wang81ab8332014-05-28 16:17:09 -0700770 @echo "Updated RS generated cpp file $@."
Ying Wange25b3982015-02-26 18:47:21 -0800771 $(hide) touch $@
Tim Murraya7aa8002012-10-29 16:06:00 -0700772
Ying Wang6ef65192014-01-15 16:02:16 -0800773my_c_includes += $(renderscript_intermediate)
774my_generated_sources += $(rs_generated_cpps)
Tim Murraya7aa8002012-10-29 16:06:00 -0700775
776endif
777
778
The Android Open Source Project88b60792009-03-03 19:28:42 -0800779###########################################################
Ying Wangfaeb6932015-04-07 11:59:34 -0700780## Compile the .proto files to .cc (or .c) and then to .o
Ying Wanga5fc87a2010-11-02 18:43:16 -0700781###########################################################
Joe Onoratobfc78112017-10-07 23:44:05 -0400782ifeq ($(strip $(LOCAL_PROTOC_OPTIMIZE_TYPE)),)
783 LOCAL_PROTOC_OPTIMIZE_TYPE := lite
784endif
Ying Wangb8e01852014-01-23 15:09:04 -0800785proto_sources := $(filter %.proto,$(my_src_files))
Ying Wanga5fc87a2010-11-02 18:43:16 -0700786ifneq ($(proto_sources),)
Ying Wang05f9f352016-05-05 20:02:08 -0700787proto_gen_dir := $(generated_sources_dir)/proto
Shinichiro Hamajia3184dc2016-04-05 17:34:51 +0900788proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources))
Ying Wangfaeb6932015-04-07 11:59:34 -0700789
Ying Wang05f9f352016-05-05 20:02:08 -0700790my_rename_cpp_ext :=
Ying Wangfaeb6932015-04-07 11:59:34 -0700791ifneq (,$(filter nanopb-c nanopb-c-enable_malloc, $(LOCAL_PROTOC_OPTIMIZE_TYPE)))
792my_proto_source_suffix := .c
793my_proto_c_includes := external/nanopb-c
Ying Wang05f9f352016-05-05 20:02:08 -0700794my_protoc_flags := --nanopb_out=$(proto_gen_dir) \
Yu Shan10be65d2018-08-03 23:48:10 +0000795 --plugin=$(HOST_OUT_EXECUTABLES)/protoc-gen-nanopb
Shinichiro Hamajia3184dc2016-04-05 17:34:51 +0900796my_protoc_deps := $(NANOPB_SRCS) $(proto_sources_fullpath:%.proto=%.options)
Ying Wangfaeb6932015-04-07 11:59:34 -0700797else
Ying Wang05f9f352016-05-05 20:02:08 -0700798my_proto_source_suffix := $(LOCAL_CPP_EXTENSION)
799ifneq ($(my_proto_source_suffix),.cc)
800# aprotoc is hardcoded to write out only .cc file.
801# We need to rename the extension to $(LOCAL_CPP_EXTENSION) if it's not .cc.
802my_rename_cpp_ext := true
803endif
Ying Wangfaeb6932015-04-07 11:59:34 -0700804my_proto_c_includes := external/protobuf/src
805my_cflags += -DGOOGLE_PROTOBUF_NO_RTTI
Joe Onoratobfc78112017-10-07 23:44:05 -0400806my_protoc_flags := --cpp_out=$(if $(filter lite lite-static,$(LOCAL_PROTOC_OPTIMIZE_TYPE)),lite:,)$(proto_gen_dir)
Shinichiro Hamajia3184dc2016-04-05 17:34:51 +0900807my_protoc_deps :=
Ying Wangfaeb6932015-04-07 11:59:34 -0700808endif
Ying Wang05f9f352016-05-05 20:02:08 -0700809my_proto_c_includes += $(proto_gen_dir)
Ying Wangfaeb6932015-04-07 11:59:34 -0700810
Ying Wang05f9f352016-05-05 20:02:08 -0700811proto_generated_cpps := $(addprefix $(proto_gen_dir)/, \
Ying Wangfaeb6932015-04-07 11:59:34 -0700812 $(patsubst %.proto,%.pb$(my_proto_source_suffix),$(proto_sources_fullpath)))
Ying Wanga5fc87a2010-11-02 18:43:16 -0700813
Ying Wangead89442014-02-25 11:18:40 -0800814# Ensure the transform-proto-to-cc rule is only defined once in multilib build.
Ying Wang05f9f352016-05-05 20:02:08 -0700815ifndef $(my_host)$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined
816$(proto_generated_cpps): PRIVATE_PROTO_INCLUDES := $(TOP)
817$(proto_generated_cpps): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS) $(my_protoc_flags)
818$(proto_generated_cpps): PRIVATE_RENAME_CPP_EXT := $(my_rename_cpp_ext)
819$(proto_generated_cpps): $(proto_gen_dir)/%.pb$(my_proto_source_suffix): %.proto $(my_protoc_deps) $(PROTOC)
Ying Wanga5fc87a2010-11-02 18:43:16 -0700820 $(transform-proto-to-cc)
821
Ying Wang05f9f352016-05-05 20:02:08 -0700822$(my_host)$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined := true
Ying Wangfaeb6932015-04-07 11:59:34 -0700823endif
Ying Wang05f9f352016-05-05 20:02:08 -0700824# Ideally we can generate the source directly into $(intermediates).
825# But many Android.mks assume the .pb.hs are in $(generated_sources_dir).
826# As a workaround, we make a copy in the $(intermediates).
827proto_intermediate_dir := $(intermediates)/proto
828proto_intermediate_cpps := $(patsubst $(proto_gen_dir)/%,$(proto_intermediate_dir)/%,\
829 $(proto_generated_cpps))
830$(proto_intermediate_cpps) : $(proto_intermediate_dir)/% : $(proto_gen_dir)/%
831 @echo "Copy: $@"
832 $(copy-file-to-target)
833 $(hide) cp $(basename $<).h $(basename $@).h
834$(call track-src-file-gen,$(proto_sources),$(proto_intermediate_cpps))
835
836my_generated_sources += $(proto_intermediate_cpps)
Ying Wanga5fc87a2010-11-02 18:43:16 -0700837
Ying Wangfaeb6932015-04-07 11:59:34 -0700838my_c_includes += $(my_proto_c_includes)
839# Auto-export the generated proto source dir.
840my_export_c_include_dirs += $(my_proto_c_includes)
841
842ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c-enable_malloc)
Ying Wang8a0d53e2015-04-08 09:54:34 -0700843 my_static_libraries += libprotobuf-c-nano-enable_malloc
Ying Wangfaeb6932015-04-07 11:59:34 -0700844else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c)
Ying Wang8a0d53e2015-04-08 09:54:34 -0700845 my_static_libraries += libprotobuf-c-nano
Ying Wangfaeb6932015-04-07 11:59:34 -0700846else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),full)
Dan Albertc3031c72014-11-11 10:42:17 -0800847 ifdef LOCAL_SDK_VERSION
Dan Alberta187fb52015-09-08 10:47:03 -0700848 my_static_libraries += libprotobuf-cpp-full-ndk
Dan Albertc3031c72014-11-11 10:42:17 -0800849 else
850 my_shared_libraries += libprotobuf-cpp-full
851 endif
Yabin Cui72a11562016-06-07 19:21:12 -0700852else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),lite-static)
853 my_static_libraries += libprotobuf-cpp-lite
Ying Wanga5fc87a2010-11-02 18:43:16 -0700854else
Dan Albertc3031c72014-11-11 10:42:17 -0800855 ifdef LOCAL_SDK_VERSION
Dan Alberta187fb52015-09-08 10:47:03 -0700856 my_static_libraries += libprotobuf-cpp-lite-ndk
Dan Albertc3031c72014-11-11 10:42:17 -0800857 else
858 my_shared_libraries += libprotobuf-cpp-lite
859 endif
Ying Wanga5fc87a2010-11-02 18:43:16 -0700860endif
Ying Wangead89442014-02-25 11:18:40 -0800861endif # $(proto_sources) non-empty
Ying Wanga5fc87a2010-11-02 18:43:16 -0700862
Ying Wanga5fc87a2010-11-02 18:43:16 -0700863###########################################################
Christopher Wiley2df75d12015-10-14 17:27:24 -0700864## AIDL: Compile .aidl files to .cpp and .h files
865###########################################################
866aidl_src := $(strip $(filter %.aidl,$(my_src_files)))
867aidl_gen_cpp :=
868ifneq ($(aidl_src),)
869
Christopher Wiley257796c2016-01-19 08:58:35 -0800870# Use the intermediates directory to avoid writing our own .cpp -> .o rules.
Christopher Wiley2df75d12015-10-14 17:27:24 -0700871aidl_gen_cpp_root := $(intermediates)/aidl-generated/src
872aidl_gen_include_root := $(intermediates)/aidl-generated/include
873
Christopher Wiley257796c2016-01-19 08:58:35 -0800874# Multi-architecture builds have distinct intermediates directories.
875# Thus we'll actually generate source for each architecture.
876$(foreach s,$(aidl_src),\
877 $(eval $(call define-aidl-cpp-rule,$(s),$(aidl_gen_cpp_root),aidl_gen_cpp)))
Christopher Wiley087f3272016-01-19 09:26:10 -0800878$(foreach cpp,$(aidl_gen_cpp), \
Dan Willemsenfb842812016-11-13 09:42:19 -0800879 $(call include-depfile,$(addsuffix .aidl.d,$(basename $(cpp))),$(cpp)))
Dan Willemsen3bb168f2016-01-19 20:07:08 -0800880$(call track-src-file-gen,$(aidl_src),$(aidl_gen_cpp))
Christopher Wiley2df75d12015-10-14 17:27:24 -0700881
Christopher Wiley2df75d12015-10-14 17:27:24 -0700882$(aidl_gen_cpp) : PRIVATE_MODULE := $(LOCAL_MODULE)
883$(aidl_gen_cpp) : PRIVATE_HEADER_OUTPUT_DIR := $(aidl_gen_include_root)
884$(aidl_gen_cpp) : PRIVATE_AIDL_FLAGS := $(addprefix -I,$(LOCAL_AIDL_INCLUDES))
885
Christopher Wileyc7e936f2015-11-19 07:06:01 -0800886# Add generated headers to include paths.
Christopher Wiley2df75d12015-10-14 17:27:24 -0700887my_c_includes += $(aidl_gen_include_root)
Christopher Wileyc7e936f2015-11-19 07:06:01 -0800888my_export_c_include_dirs += $(aidl_gen_include_root)
Christopher Wiley2df75d12015-10-14 17:27:24 -0700889# Pick up the generated C++ files later for transformation to .o files.
890my_generated_sources += $(aidl_gen_cpp)
891
892endif # $(aidl_src) non-empty
893
894###########################################################
Keun Soo Yim3d484752016-02-19 11:06:58 -0800895## Compile the .vts files to .cc (or .c) and then to .o
896###########################################################
897
898vts_src := $(strip $(filter %.vts,$(my_src_files)))
899vts_gen_cpp :=
900ifneq ($(vts_src),)
Dan Willemsenfc92fb22016-08-26 13:27:13 -0700901my_soong_problems += vts
Keun Soo Yim3d484752016-02-19 11:06:58 -0800902
903# Use the intermediates directory to avoid writing our own .cpp -> .o rules.
904vts_gen_cpp_root := $(intermediates)/vts-generated/src
905vts_gen_include_root := $(intermediates)/vts-generated/include
906
907# Multi-architecture builds have distinct intermediates directories.
908# Thus we'll actually generate source for each architecture.
909$(foreach s,$(vts_src),\
910 $(eval $(call define-vts-cpp-rule,$(s),$(vts_gen_cpp_root),vts_gen_cpp)))
911$(foreach cpp,$(vts_gen_cpp), \
912 $(call include-depfile,$(addsuffix .vts.P,$(basename $(cpp))),$(cpp)))
913$(call track-src-file-gen,$(vts_src),$(vts_gen_cpp))
914
915$(vts_gen_cpp) : PRIVATE_MODULE := $(LOCAL_MODULE)
916$(vts_gen_cpp) : PRIVATE_HEADER_OUTPUT_DIR := $(vts_gen_include_root)
Keun Soo Yim3c0ffa32016-09-08 18:30:28 -0700917$(vts_gen_cpp) : PRIVATE_VTS_FLAGS := $(addprefix -I,$(LOCAL_VTS_INCLUDES)) $(addprefix -m,$(LOCAL_VTS_MODE))
Keun Soo Yim3d484752016-02-19 11:06:58 -0800918
919# Add generated headers to include paths.
920my_c_includes += $(vts_gen_include_root)
921my_export_c_include_dirs += $(vts_gen_include_root)
922# Pick up the generated C++ files later for transformation to .o files.
923my_generated_sources += $(vts_gen_cpp)
924
925endif # $(vts_src) non-empty
926
927###########################################################
Ying Wangf0ebe162016-01-11 16:28:45 -0800928## YACC: Compile .y/.yy files to .c/.cpp and then to .o.
The Android Open Source Project88b60792009-03-03 19:28:42 -0800929###########################################################
930
Nicolas Geoffray9484e2e2014-03-03 15:57:06 +0000931y_yacc_sources := $(filter %.y,$(my_src_files))
Ying Wangf0ebe162016-01-11 16:28:45 -0800932y_yacc_cs := $(addprefix \
933 $(intermediates)/,$(y_yacc_sources:.y=.c))
934ifneq ($(y_yacc_cs),)
935$(y_yacc_cs): $(intermediates)/%.c: \
Shinichiro Hamajib708bc52016-04-05 20:12:48 +0900936 $(TOPDIR)$(LOCAL_PATH)/%.y $(BISON) $(BISON_DATA) \
Ying Wangf0ebe162016-01-11 16:28:45 -0800937 $(my_additional_dependencies)
938 $(call transform-y-to-c-or-cpp)
Dan Willemsen3bb168f2016-01-19 20:07:08 -0800939$(call track-src-file-gen,$(y_yacc_sources),$(y_yacc_cs))
Ying Wangf0ebe162016-01-11 16:28:45 -0800940
941my_generated_sources += $(y_yacc_cs)
942endif
Nicolas Geoffray9484e2e2014-03-03 15:57:06 +0000943
944yy_yacc_sources := $(filter %.yy,$(my_src_files))
945yy_yacc_cpps := $(addprefix \
946 $(intermediates)/,$(yy_yacc_sources:.yy=$(LOCAL_CPP_EXTENSION)))
Ying Wangf0ebe162016-01-11 16:28:45 -0800947ifneq ($(yy_yacc_cpps),)
Nicolas Geoffray9484e2e2014-03-03 15:57:06 +0000948$(yy_yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
Shinichiro Hamajib708bc52016-04-05 20:12:48 +0900949 $(TOPDIR)$(LOCAL_PATH)/%.yy $(BISON) $(BISON_DATA) \
Ying Wangf0ebe162016-01-11 16:28:45 -0800950 $(my_additional_dependencies)
951 $(call transform-y-to-c-or-cpp)
Dan Willemsen3bb168f2016-01-19 20:07:08 -0800952$(call track-src-file-gen,$(yy_yacc_sources),$(yy_yacc_cpps))
Nicolas Geoffray9484e2e2014-03-03 15:57:06 +0000953
Ying Wangf0ebe162016-01-11 16:28:45 -0800954my_generated_sources += $(yy_yacc_cpps)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800955endif
956
957###########################################################
Ying Wangf0ebe162016-01-11 16:28:45 -0800958## LEX: Compile .l/.ll files to .c/.cpp and then to .o.
The Android Open Source Project88b60792009-03-03 19:28:42 -0800959###########################################################
960
Nicolas Geoffray9484e2e2014-03-03 15:57:06 +0000961l_lex_sources := $(filter %.l,$(my_src_files))
Ying Wangf0ebe162016-01-11 16:28:45 -0800962l_lex_cs := $(addprefix \
963 $(intermediates)/,$(l_lex_sources:.l=.c))
964ifneq ($(l_lex_cs),)
965$(l_lex_cs): $(intermediates)/%.c: \
966 $(TOPDIR)$(LOCAL_PATH)/%.l
967 $(transform-l-to-c-or-cpp)
Dan Willemsen3bb168f2016-01-19 20:07:08 -0800968$(call track-src-file-gen,$(l_lex_sources),$(l_lex_cs))
Ying Wangf0ebe162016-01-11 16:28:45 -0800969
970my_generated_sources += $(l_lex_cs)
971endif
Nicolas Geoffray9484e2e2014-03-03 15:57:06 +0000972
973ll_lex_sources := $(filter %.ll,$(my_src_files))
974ll_lex_cpps := $(addprefix \
975 $(intermediates)/,$(ll_lex_sources:.ll=$(LOCAL_CPP_EXTENSION)))
Ying Wangf0ebe162016-01-11 16:28:45 -0800976ifneq ($(ll_lex_cpps),)
Nicolas Geoffray9484e2e2014-03-03 15:57:06 +0000977$(ll_lex_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
978 $(TOPDIR)$(LOCAL_PATH)/%.ll
Ying Wangf0ebe162016-01-11 16:28:45 -0800979 $(transform-l-to-c-or-cpp)
Dan Willemsen3bb168f2016-01-19 20:07:08 -0800980$(call track-src-file-gen,$(ll_lex_sources),$(ll_lex_cpps))
Nicolas Geoffray9484e2e2014-03-03 15:57:06 +0000981
Ying Wangf0ebe162016-01-11 16:28:45 -0800982my_generated_sources += $(ll_lex_cpps)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800983endif
984
985###########################################################
986## C++: Compile .cpp files to .o.
987###########################################################
988
Jeff Browne33ba4c2011-07-11 22:11:46 -0700989# we also do this on host modules, even though
The Android Open Source Project88b60792009-03-03 19:28:42 -0800990# it's not really arm, because there are files that are shared.
Ying Wangfb22a422015-03-10 18:03:11 -0700991cpp_arm_sources := $(patsubst %$(LOCAL_CPP_EXTENSION).arm,%$(LOCAL_CPP_EXTENSION),$(filter %$(LOCAL_CPP_EXTENSION).arm,$(my_src_files)))
992dotdot_arm_sources := $(filter ../%,$(cpp_arm_sources))
993cpp_arm_sources := $(filter-out ../%,$(cpp_arm_sources))
994cpp_arm_objects := $(addprefix $(intermediates)/,$(cpp_arm_sources:$(LOCAL_CPP_EXTENSION)=.o))
Dan Willemsen3bb168f2016-01-19 20:07:08 -0800995$(call track-src-file-obj,$(patsubst %,%.arm,$(cpp_arm_sources)),$(cpp_arm_objects))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800996
Ying Wangfb22a422015-03-10 18:03:11 -0700997# For source files starting with ../, we remove all the ../ in the object file path,
998# to avoid object file escaping the intermediate directory.
999dotdot_arm_objects :=
1000$(foreach s,$(dotdot_arm_sources),\
1001 $(eval $(call compile-dotdot-cpp-file,$(s),\
Ying Wang05f9f352016-05-05 20:02:08 -07001002 $(my_additional_dependencies),\
Ying Wangfb22a422015-03-10 18:03:11 -07001003 dotdot_arm_objects)))
Dan Willemsen3bb168f2016-01-19 20:07:08 -08001004$(call track-src-file-obj,$(patsubst %,%.arm,$(dotdot_arm_sources)),$(dotdot_arm_objects))
Ying Wangfb22a422015-03-10 18:03:11 -07001005
1006dotdot_sources := $(filter ../%$(LOCAL_CPP_EXTENSION),$(my_src_files))
1007dotdot_objects :=
1008$(foreach s,$(dotdot_sources),\
1009 $(eval $(call compile-dotdot-cpp-file,$(s),\
Ying Wang05f9f352016-05-05 20:02:08 -07001010 $(my_additional_dependencies),\
Ying Wangfb22a422015-03-10 18:03:11 -07001011 dotdot_objects)))
Dan Willemsen3bb168f2016-01-19 20:07:08 -08001012$(call track-src-file-obj,$(dotdot_sources),$(dotdot_objects))
Ying Wangfb22a422015-03-10 18:03:11 -07001013
1014cpp_normal_sources := $(filter-out ../%,$(filter %$(LOCAL_CPP_EXTENSION),$(my_src_files)))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001015cpp_normal_objects := $(addprefix $(intermediates)/,$(cpp_normal_sources:$(LOCAL_CPP_EXTENSION)=.o))
Dan Willemsen3bb168f2016-01-19 20:07:08 -08001016$(call track-src-file-obj,$(cpp_normal_sources),$(cpp_normal_objects))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001017
Ying Wangfb22a422015-03-10 18:03:11 -07001018$(dotdot_arm_objects) $(cpp_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode)
1019$(dotdot_arm_objects) $(cpp_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags)
1020$(dotdot_objects) $(cpp_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
1021$(dotdot_objects) $(cpp_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001022
1023cpp_objects := $(cpp_arm_objects) $(cpp_normal_objects)
1024
1025ifneq ($(strip $(cpp_objects)),)
1026$(cpp_objects): $(intermediates)/%.o: \
Ying Wangdfbe79b2012-03-22 11:26:22 -07001027 $(TOPDIR)$(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) \
Dan Albert954b5bd2014-11-08 22:20:03 -08001028 $(my_additional_dependencies)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001029 $(transform-$(PRIVATE_HOST)cpp-to-o)
Shinichiro Hamaji4037c422016-03-03 18:12:52 +09001030$(call include-depfiles-for-objs, $(cpp_objects))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001031endif
1032
Ying Wangfb22a422015-03-10 18:03:11 -07001033cpp_objects += $(dotdot_arm_objects) $(dotdot_objects)
1034
The Android Open Source Project88b60792009-03-03 19:28:42 -08001035###########################################################
1036## C++: Compile generated .cpp files to .o.
1037###########################################################
1038
Ying Wangec6d6262014-01-16 16:21:03 -08001039gen_cpp_sources := $(filter %$(LOCAL_CPP_EXTENSION),$(my_generated_sources))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001040gen_cpp_objects := $(gen_cpp_sources:%$(LOCAL_CPP_EXTENSION)=%.o)
Dan Willemsen3bb168f2016-01-19 20:07:08 -08001041$(call track-gen-file-obj,$(gen_cpp_sources),$(gen_cpp_objects))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001042
1043ifneq ($(strip $(gen_cpp_objects)),)
1044# Compile all generated files as thumb.
1045# TODO: support compiling certain generated files as arm.
1046$(gen_cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
1047$(gen_cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +04001048$(gen_cpp_objects): $(intermediates)/%.o: \
Ying Wang05f9f352016-05-05 20:02:08 -07001049 $(intermediates)/%$(LOCAL_CPP_EXTENSION) \
Dan Albert954b5bd2014-11-08 22:20:03 -08001050 $(my_additional_dependencies)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001051 $(transform-$(PRIVATE_HOST)cpp-to-o)
Shinichiro Hamaji4037c422016-03-03 18:12:52 +09001052$(call include-depfiles-for-objs, $(gen_cpp_objects))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001053endif
1054
1055###########################################################
1056## S: Compile generated .S and .s files to .o.
1057###########################################################
1058
Ying Wangec6d6262014-01-16 16:21:03 -08001059gen_S_sources := $(filter %.S,$(my_generated_sources))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001060gen_S_objects := $(gen_S_sources:%.S=%.o)
Dan Willemsen3bb168f2016-01-19 20:07:08 -08001061$(call track-gen-file-obj,$(gen_S_sources),$(gen_S_objects))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001062
1063ifneq ($(strip $(gen_S_sources)),)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +04001064$(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S \
Dan Albert954b5bd2014-11-08 22:20:03 -08001065 $(my_additional_dependencies)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001066 $(transform-$(PRIVATE_HOST)s-to-o)
Shinichiro Hamaji4037c422016-03-03 18:12:52 +09001067$(call include-depfiles-for-objs, $(gen_S_objects))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001068endif
1069
Ying Wangec6d6262014-01-16 16:21:03 -08001070gen_s_sources := $(filter %.s,$(my_generated_sources))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001071gen_s_objects := $(gen_s_sources:%.s=%.o)
Dan Willemsen3bb168f2016-01-19 20:07:08 -08001072$(call track-gen-file-obj,$(gen_s_sources),$(gen_s_objects))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001073
1074ifneq ($(strip $(gen_s_objects)),)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +04001075$(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s \
Dan Albert954b5bd2014-11-08 22:20:03 -08001076 $(my_additional_dependencies)
Dan Willemsen461d8442016-11-10 18:19:36 -08001077 $(transform-$(PRIVATE_HOST)s-to-o)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001078endif
1079
1080gen_asm_objects := $(gen_S_objects) $(gen_s_objects)
Dan Willemsen45d38c02016-01-15 16:38:46 -08001081$(gen_asm_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001082
1083###########################################################
Torne (Richard Coles)aace2022013-02-21 14:01:35 +00001084## o: Include generated .o files in output.
1085###########################################################
1086
Ying Wangec6d6262014-01-16 16:21:03 -08001087gen_o_objects := $(filter %.o,$(my_generated_sources))
Torne (Richard Coles)aace2022013-02-21 14:01:35 +00001088
1089###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001090## C: Compile .c files to .o.
1091###########################################################
1092
Ying Wangfb22a422015-03-10 18:03:11 -07001093c_arm_sources := $(patsubst %.c.arm,%.c,$(filter %.c.arm,$(my_src_files)))
1094dotdot_arm_sources := $(filter ../%,$(c_arm_sources))
1095c_arm_sources := $(filter-out ../%,$(c_arm_sources))
1096c_arm_objects := $(addprefix $(intermediates)/,$(c_arm_sources:.c=.o))
Dan Willemsen3bb168f2016-01-19 20:07:08 -08001097$(call track-src-file-obj,$(patsubst %,%.arm,$(c_arm_sources)),$(c_arm_objects))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001098
Ying Wangfb22a422015-03-10 18:03:11 -07001099# For source files starting with ../, we remove all the ../ in the object file path,
1100# to avoid object file escaping the intermediate directory.
1101dotdot_arm_objects :=
1102$(foreach s,$(dotdot_arm_sources),\
1103 $(eval $(call compile-dotdot-c-file,$(s),\
Ying Wang05f9f352016-05-05 20:02:08 -07001104 $(my_additional_dependencies),\
Ying Wangfb22a422015-03-10 18:03:11 -07001105 dotdot_arm_objects)))
Dan Willemsen3bb168f2016-01-19 20:07:08 -08001106$(call track-src-file-obj,$(patsubst %,%.arm,$(dotdot_arm_sources)),$(dotdot_arm_objects))
Ying Wangfb22a422015-03-10 18:03:11 -07001107
1108dotdot_sources := $(filter ../%.c, $(my_src_files))
1109dotdot_objects :=
1110$(foreach s, $(dotdot_sources),\
1111 $(eval $(call compile-dotdot-c-file,$(s),\
Ying Wang05f9f352016-05-05 20:02:08 -07001112 $(my_additional_dependencies),\
Ying Wangfb22a422015-03-10 18:03:11 -07001113 dotdot_objects)))
Dan Willemsen3bb168f2016-01-19 20:07:08 -08001114$(call track-src-file-obj,$(dotdot_sources),$(dotdot_objects))
Ying Wangfb22a422015-03-10 18:03:11 -07001115
1116c_normal_sources := $(filter-out ../%,$(filter %.c,$(my_src_files)))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001117c_normal_objects := $(addprefix $(intermediates)/,$(c_normal_sources:.c=.o))
Dan Willemsen3bb168f2016-01-19 20:07:08 -08001118$(call track-src-file-obj,$(c_normal_sources),$(c_normal_objects))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001119
Ying Wangfb22a422015-03-10 18:03:11 -07001120$(dotdot_arm_objects) $(c_arm_objects): PRIVATE_ARM_MODE := $(arm_objects_mode)
1121$(dotdot_arm_objects) $(c_arm_objects): PRIVATE_ARM_CFLAGS := $(arm_objects_cflags)
1122$(dotdot_objects) $(c_normal_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
1123$(dotdot_objects) $(c_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001124
1125c_objects := $(c_arm_objects) $(c_normal_objects)
1126
1127ifneq ($(strip $(c_objects)),)
Ying Wang05f9f352016-05-05 20:02:08 -07001128$(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c \
Dan Albert954b5bd2014-11-08 22:20:03 -08001129 $(my_additional_dependencies)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001130 $(transform-$(PRIVATE_HOST)c-to-o)
Shinichiro Hamaji4037c422016-03-03 18:12:52 +09001131$(call include-depfiles-for-objs, $(c_objects))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001132endif
1133
Ying Wangfb22a422015-03-10 18:03:11 -07001134c_objects += $(dotdot_arm_objects) $(dotdot_objects)
1135
The Android Open Source Project88b60792009-03-03 19:28:42 -08001136###########################################################
Jack Paleviche7b3e2c2009-05-04 14:32:44 -07001137## C: Compile generated .c files to .o.
1138###########################################################
1139
Ying Wangec6d6262014-01-16 16:21:03 -08001140gen_c_sources := $(filter %.c,$(my_generated_sources))
Jack Paleviche7b3e2c2009-05-04 14:32:44 -07001141gen_c_objects := $(gen_c_sources:%.c=%.o)
Dan Willemsen3bb168f2016-01-19 20:07:08 -08001142$(call track-gen-file-obj,$(gen_c_sources),$(gen_c_objects))
Jack Paleviche7b3e2c2009-05-04 14:32:44 -07001143
1144ifneq ($(strip $(gen_c_objects)),)
1145# Compile all generated files as thumb.
1146# TODO: support compiling certain generated files as arm.
1147$(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
1148$(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
Ying Wang05f9f352016-05-05 20:02:08 -07001149$(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c \
Dan Albert954b5bd2014-11-08 22:20:03 -08001150 $(my_additional_dependencies)
Jack Paleviche7b3e2c2009-05-04 14:32:44 -07001151 $(transform-$(PRIVATE_HOST)c-to-o)
Shinichiro Hamaji4037c422016-03-03 18:12:52 +09001152$(call include-depfiles-for-objs, $(gen_c_objects))
Jack Paleviche7b3e2c2009-05-04 14:32:44 -07001153endif
1154
1155###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001156## ObjC: Compile .m files to .o
1157###########################################################
1158
Ying Wangb8e01852014-01-23 15:09:04 -08001159objc_sources := $(filter %.m,$(my_src_files))
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001160objc_objects := $(addprefix $(intermediates)/,$(objc_sources:.m=.o))
Dan Willemsen62f2e562016-02-01 18:55:23 -08001161$(call track-src-file-obj,$(objc_sources),$(objc_objects))
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001162
1163ifneq ($(strip $(objc_objects)),)
Dan Willemsenfc92fb22016-08-26 13:27:13 -07001164my_soong_problems += objc
Ying Wang05f9f352016-05-05 20:02:08 -07001165$(objc_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.m \
Dan Albert954b5bd2014-11-08 22:20:03 -08001166 $(my_additional_dependencies)
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001167 $(transform-$(PRIVATE_HOST)m-to-o)
Shinichiro Hamaji4037c422016-03-03 18:12:52 +09001168$(call include-depfiles-for-objs, $(objc_objects))
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001169endif
1170
1171###########################################################
Scott James Remnantdd86e5a2015-09-17 15:40:49 -07001172## ObjC++: Compile .mm files to .o
1173###########################################################
1174
1175objcpp_sources := $(filter %.mm,$(my_src_files))
1176objcpp_objects := $(addprefix $(intermediates)/,$(objcpp_sources:.mm=.o))
Dan Willemsen62f2e562016-02-01 18:55:23 -08001177$(call track-src-file-obj,$(objcpp_sources),$(objcpp_objects))
Scott James Remnantdd86e5a2015-09-17 15:40:49 -07001178
1179ifneq ($(strip $(objcpp_objects)),)
Ying Wang05f9f352016-05-05 20:02:08 -07001180$(objcpp_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.mm \
Scott James Remnantdd86e5a2015-09-17 15:40:49 -07001181 $(my_additional_dependencies)
1182 $(transform-$(PRIVATE_HOST)mm-to-o)
Shinichiro Hamaji4037c422016-03-03 18:12:52 +09001183$(call include-depfiles-for-objs, $(objcpp_objects))
Scott James Remnantdd86e5a2015-09-17 15:40:49 -07001184endif
1185
1186###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001187## AS: Compile .S files to .o.
1188###########################################################
1189
Ying Wangb8e01852014-01-23 15:09:04 -08001190asm_sources_S := $(filter %.S,$(my_src_files))
Ying Wangfb22a422015-03-10 18:03:11 -07001191dotdot_sources := $(filter ../%,$(asm_sources_S))
1192asm_sources_S := $(filter-out ../%,$(asm_sources_S))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001193asm_objects_S := $(addprefix $(intermediates)/,$(asm_sources_S:.S=.o))
Dan Willemsen3bb168f2016-01-19 20:07:08 -08001194$(call track-src-file-obj,$(asm_sources_S),$(asm_objects_S))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001195
Ying Wangfb22a422015-03-10 18:03:11 -07001196dotdot_objects_S :=
1197$(foreach s,$(dotdot_sources),\
1198 $(eval $(call compile-dotdot-s-file,$(s),\
1199 $(my_additional_dependencies),\
1200 dotdot_objects_S)))
Dan Willemsen3bb168f2016-01-19 20:07:08 -08001201$(call track-src-file-obj,$(dotdot_sources),$(dotdot_objects_S))
Ying Wangfb22a422015-03-10 18:03:11 -07001202
The Android Open Source Project88b60792009-03-03 19:28:42 -08001203ifneq ($(strip $(asm_objects_S)),)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +04001204$(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S \
Dan Albert954b5bd2014-11-08 22:20:03 -08001205 $(my_additional_dependencies)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001206 $(transform-$(PRIVATE_HOST)s-to-o)
Shinichiro Hamaji72904772016-03-16 06:40:04 +09001207$(call include-depfiles-for-objs, $(asm_objects_S))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001208endif
1209
Ying Wangb8e01852014-01-23 15:09:04 -08001210asm_sources_s := $(filter %.s,$(my_src_files))
Ying Wangfb22a422015-03-10 18:03:11 -07001211dotdot_sources := $(filter ../%,$(asm_sources_s))
1212asm_sources_s := $(filter-out ../%,$(asm_sources_s))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001213asm_objects_s := $(addprefix $(intermediates)/,$(asm_sources_s:.s=.o))
Dan Willemsen3bb168f2016-01-19 20:07:08 -08001214$(call track-src-file-obj,$(asm_sources_s),$(asm_objects_s))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001215
Ying Wangfb22a422015-03-10 18:03:11 -07001216dotdot_objects_s :=
1217$(foreach s,$(dotdot_sources),\
1218 $(eval $(call compile-dotdot-s-file-no-deps,$(s),\
1219 $(my_additional_dependencies),\
1220 dotdot_objects_s)))
Dan Willemsen3bb168f2016-01-19 20:07:08 -08001221$(call track-src-file-obj,$(dotdot_sources),$(dotdot_objects_s))
Ying Wangfb22a422015-03-10 18:03:11 -07001222
The Android Open Source Project88b60792009-03-03 19:28:42 -08001223ifneq ($(strip $(asm_objects_s)),)
Evgeniy Stepanovb71e2df2012-03-20 18:00:16 +04001224$(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s \
Dan Albert954b5bd2014-11-08 22:20:03 -08001225 $(my_additional_dependencies)
Dan Willemsen461d8442016-11-10 18:19:36 -08001226 $(transform-$(PRIVATE_HOST)s-to-o)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001227endif
1228
Ying Wangfb22a422015-03-10 18:03:11 -07001229asm_objects := $(dotdot_objects_S) $(dotdot_objects_s) $(asm_objects_S) $(asm_objects_s)
Dan Willemsen45d38c02016-01-15 16:38:46 -08001230$(asm_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001231
1232
Ying Wangfe1e5c32015-03-09 18:57:40 -07001233# .asm for x86/x86_64 needs to be compiled with yasm.
Ying Wang7b913ce2014-06-05 19:05:47 -07001234asm_sources_asm := $(filter %.asm,$(my_src_files))
1235ifneq ($(strip $(asm_sources_asm)),)
1236asm_objects_asm := $(addprefix $(intermediates)/,$(asm_sources_asm:.asm=.o))
1237$(asm_objects_asm): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.asm \
Dan Albert954b5bd2014-11-08 22:20:03 -08001238 $(my_additional_dependencies)
Ying Wang7b913ce2014-06-05 19:05:47 -07001239 $(transform-asm-to-o)
Dan Willemsen3bb168f2016-01-19 20:07:08 -08001240$(call track-src-file-obj,$(asm_sources_asm),$(asm_objects_asm))
Ying Wang7b913ce2014-06-05 19:05:47 -07001241
1242asm_objects += $(asm_objects_asm)
1243endif
Ying Wang7b913ce2014-06-05 19:05:47 -07001244
Vishwath Mohan96a130b2017-11-17 11:19:36 -08001245###################################################################
1246## When compiling a CFI enabled target, use the .cfi variant of any
1247## static dependencies (where they exist).
1248##################################################################
1249define use_soong_cfi_static_libraries
1250 $(foreach l,$(1),$(if $(filter $(l),$(SOONG_CFI_STATIC_LIBRARIES)),\
1251 $(l).cfi,$(l)))
1252endef
1253
1254ifneq ($(filter cfi,$(my_sanitize)),)
1255 my_whole_static_libraries := $(call use_soong_cfi_static_libraries,\
1256 $(my_whole_static_libraries))
1257 my_static_libraries := $(call use_soong_cfi_static_libraries,\
1258 $(my_static_libraries))
1259endif
1260
Evgenii Stepanov8841a7f2018-07-27 11:54:32 -07001261ifneq ($(LOCAL_USE_VNDK),)
1262 my_soong_hwasan_static_libraries := $(SOONG_HWASAN_VENDOR_STATIC_LIBRARIES)
1263else
1264 my_soong_hwasan_static_libraries = $(SOONG_HWASAN_STATIC_LIBRARIES)
1265endif
1266
1267define use_soong_hwasan_static_libraries
1268 $(foreach l,$(1),$(if $(filter $(l),$(my_soong_hwasan_static_libraries)),\
1269 $(l).hwasan,$(l)))
1270endef
1271
1272ifneq ($(filter hwaddress,$(my_sanitize)),)
1273 my_whole_static_libraries := $(call use_soong_hwasan_static_libraries,\
1274 $(my_whole_static_libraries))
1275 my_static_libraries := $(call use_soong_hwasan_static_libraries,\
1276 $(my_static_libraries))
1277endif
1278
Jiyong Parkc8f57d92017-04-18 20:15:14 +09001279###########################################################
1280## When compiling against the VNDK, use LL-NDK libraries
1281###########################################################
1282ifneq ($(LOCAL_USE_VNDK),)
1283 ####################################################
1284 ## Soong modules may be built twice, once for /system
1285 ## and once for /vendor. If we're using the VNDK,
1286 ## switch all soong libraries over to the /vendor
1287 ## variant.
1288 ####################################################
Colin Cross8fb525d2018-09-06 16:25:22 -07001289 my_whole_static_libraries := $(foreach l,$(my_whole_static_libraries),\
1290 $(if $(SPLIT_VENDOR.STATIC_LIBRARIES.$(l)),$(l).vendor,$(l)))
1291 my_static_libraries := $(foreach l,$(my_static_libraries),\
1292 $(if $(SPLIT_VENDOR.STATIC_LIBRARIES.$(l)),$(l).vendor,$(l)))
1293 my_shared_libraries := $(foreach l,$(my_shared_libraries),\
1294 $(if $(SPLIT_VENDOR.SHARED_LIBRARIES.$(l)),$(l).vendor,$(l)))
1295 my_system_shared_libraries := $(foreach l,$(my_system_shared_libraries),\
1296 $(if $(SPLIT_VENDOR.SHARED_LIBRARIES.$(l)),$(l).vendor,$(l)))
1297 my_header_libraries := $(foreach l,$(my_header_libraries),\
1298 $(if $(SPLIT_VENDOR.HEADER_LIBRARIES.$(l)),$(l).vendor,$(l)))
Jiyong Parkc8f57d92017-04-18 20:15:14 +09001299endif
Jeff Davidson680f0712015-01-08 18:25:30 -08001300
Jiyong Parkc3f13562018-03-19 18:12:39 +09001301# Platform can use vendor public libraries. If a required shared lib is one of
1302# the vendor public libraries, the lib is switched to the stub version of the lib.
1303ifeq ($(LOCAL_USE_VNDK),)
Colin Cross8fb525d2018-09-06 16:25:22 -07001304 my_shared_libraries := $(foreach l,$(my_shared_libraries),\
1305 $(if $(filter $(l),$(VENDOR_PUBLIC_LIBRARIES)),$(l).vendorpublic,$(l)))
Jiyong Parkc3f13562018-03-19 18:12:39 +09001306endif
1307
Jeff Davidson680f0712015-01-08 18:25:30 -08001308##########################################################
1309## Set up installed module dependency
1310## We cannot compute the full path of the LOCAL_SHARED_LIBRARIES for
1311## they may cusomize their install path with LOCAL_MODULE_PATH
1312##########################################################
1313# Get the list of INSTALLED libraries as module names.
Dan Willemsenffa32582017-03-19 13:22:45 -07001314ifneq ($(LOCAL_SDK_VERSION),)
Jeff Davidson680f0712015-01-08 18:25:30 -08001315 installed_shared_library_module_names := \
1316 $(my_shared_libraries)
1317else
1318 installed_shared_library_module_names := \
1319 $(my_shared_libraries) $(my_system_shared_libraries)
1320endif
1321
1322# The real dependency will be added after all Android.mks are loaded and the install paths
1323# of the shared libraries are determined.
1324ifdef LOCAL_INSTALLED_MODULE
1325ifdef installed_shared_library_module_names
1326$(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \
Dimitry Ivanovcdf39272017-06-26 13:13:44 -07001327 $(my_register_name):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(installed_shared_library_module_names))
Jeff Davidson680f0712015-01-08 18:25:30 -08001328endif
1329endif
1330
1331
Ying Wang5f074802011-11-08 09:31:21 -08001332####################################################
1333## Import includes
1334####################################################
1335import_includes := $(intermediates)/import_includes
1336import_includes_deps := $(strip \
Jiyong Park0c59dab2017-07-03 13:14:52 +09001337 $(if $(LOCAL_USE_VNDK),\
Jiyong Parka9c4c712017-07-18 13:35:27 +09001338 $(call intermediates-dir-for,HEADER_LIBRARIES,device_kernel_headers,$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes) \
Ying Wang5f074802011-11-08 09:31:21 -08001339 $(foreach l, $(installed_shared_library_module_names), \
Alexey Polyudovccdc3112016-08-01 17:41:49 -07001340 $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes) \
Colin Cross90353fe2014-02-04 14:53:25 -08001341 $(foreach l, $(my_static_libraries) $(my_whole_static_libraries), \
Dan Willemsen8dae49c2017-02-15 15:48:11 -08001342 $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes) \
1343 $(foreach l, $(my_header_libraries), \
1344 $(call intermediates-dir-for,HEADER_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes))
Ying Wang14d02a32015-01-22 15:44:04 -08001345$(import_includes): PRIVATE_IMPORT_EXPORT_INCLUDES := $(import_includes_deps)
Dan Willemsen1c6dc5b2016-01-06 14:28:36 -08001346$(import_includes) : $(import_includes_deps)
Ying Wang5f074802011-11-08 09:31:21 -08001347 @echo Import includes file: $@
1348 $(hide) mkdir -p $(dir $@) && rm -f $@
1349ifdef import_includes_deps
Ying Wang14d02a32015-01-22 15:44:04 -08001350 $(hide) for f in $(PRIVATE_IMPORT_EXPORT_INCLUDES); do \
Ying Wang5f074802011-11-08 09:31:21 -08001351 cat $$f >> $@; \
1352 done
1353else
1354 $(hide) touch $@
1355endif
1356
Dan Willemsenb097fbe2016-06-07 14:25:14 -07001357####################################################
1358## Verify that NDK-built libraries only link against
1359## other NDK-built libraries
1360####################################################
1361
Dan Albert975e3032017-12-19 11:26:05 -08001362include $(BUILD_SYSTEM)/allowed_ndk_types.mk
1363
Dan Willemsenb097fbe2016-06-07 14:25:14 -07001364ifdef LOCAL_SDK_VERSION
Dan Albert4297c392017-12-19 11:27:39 -08001365my_link_type := native:ndk:$(my_ndk_stl_family):$(my_ndk_stl_link_type)
Dan Albert975e3032017-12-19 11:26:05 -08001366my_warn_types := $(my_warn_ndk_types)
1367my_allowed_types := $(my_allowed_ndk_types)
Dan Willemsen9d2b3282017-04-07 20:58:43 -07001368else ifdef LOCAL_USE_VNDK
Jiyong Parka3fb1582017-08-16 18:28:12 +09001369 _name := $(patsubst %.vendor,%,$(LOCAL_MODULE))
1370 ifneq ($(filter $(_name),$(VNDK_CORE_LIBRARIES) $(VNDK_SAMEPROCESS_LIBRARIES) $(LLNDK_LIBRARIES)),)
1371 ifeq ($(filter $(_name),$(VNDK_PRIVATE_LIBRARIES)),)
1372 my_link_type := native:vndk
1373 else
1374 my_link_type := native:vndk_private
1375 endif
1376 my_warn_types :=
1377 my_allowed_types := native:vndk native:vndk_private
1378 else
1379 # Modules installed to /vendor cannot directly depend on modules marked
1380 # with vendor_available: false
1381 my_link_type := native:vendor
1382 my_warn_types :=
1383 my_allowed_types := native:vendor native:vndk
1384 endif
Jiyong Parka52b6e92018-09-12 10:03:37 +09001385else ifneq ($(filter $(TARGET_RECOVERY_OUT)/%,$(call get_non_asan_path,$(LOCAL_MODULE_PATH))),)
Jiyong Park5dc34752018-08-28 12:32:45 +09001386my_link_type := native:recovery
1387my_warn_types :=
1388# TODO(b/113303515) remove native:platform and my_allowed_ndk_types
1389my_allowed_types := native:recovery native:platform $(my_allowed_ndk_types)
Dan Willemsenb097fbe2016-06-07 14:25:14 -07001390else
Dan Willemsenb47d4e92017-04-08 00:31:31 -07001391my_link_type := native:platform
Dan Albert975e3032017-12-19 11:26:05 -08001392my_warn_types := $(my_warn_ndk_types)
1393my_allowed_types := $(my_allowed_ndk_types) native:platform
Dan Willemsenb097fbe2016-06-07 14:25:14 -07001394endif
Dan Willemsenb097fbe2016-06-07 14:25:14 -07001395
Dan Willemsenb47d4e92017-04-08 00:31:31 -07001396my_link_deps := $(addprefix STATIC_LIBRARIES:,$(my_whole_static_libraries) $(my_static_libraries))
1397ifneq ($(filter-out STATIC_LIBRARIES HEADER_LIBRARIES,$(LOCAL_MODULE_CLASS)),)
1398my_link_deps += $(addprefix SHARED_LIBRARIES:,$(my_shared_libraries))
1399endif
1400
1401my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX)
1402my_common :=
1403include $(BUILD_SYSTEM)/link_type.mk
Dan Willemsenb097fbe2016-06-07 14:25:14 -07001404
The Android Open Source Project88b60792009-03-03 19:28:42 -08001405###########################################################
1406## Common object handling.
1407###########################################################
1408
Dan Willemsen3bb168f2016-01-19 20:07:08 -08001409my_unused_src_files := $(filter-out $(logtags_sources) $(my_tracked_src_files),$(my_src_files) $(my_gen_src_files))
1410ifneq ($(my_unused_src_files),)
Dan Willemsen9efeb1e2016-06-28 10:22:08 -07001411 $(error $(LOCAL_MODULE_MAKEFILE): $(LOCAL_MODULE): Unused source files: $(my_unused_src_files))
Dan Willemsen3bb168f2016-01-19 20:07:08 -08001412endif
1413
The Android Open Source Project88b60792009-03-03 19:28:42 -08001414# some rules depend on asm_objects being first. If your code depends on
1415# being first, it's reasonable to require it to be assembly
Torne (Richard Coles)a5afbe82013-08-29 15:36:34 +01001416normal_objects := \
Ying Wangdfbe79b2012-03-22 11:26:22 -07001417 $(asm_objects) \
1418 $(cpp_objects) \
1419 $(gen_cpp_objects) \
1420 $(gen_asm_objects) \
1421 $(c_objects) \
1422 $(gen_c_objects) \
1423 $(objc_objects) \
Ying Wang05f9f352016-05-05 20:02:08 -07001424 $(objcpp_objects)
Dan Willemsen3bb168f2016-01-19 20:07:08 -08001425
1426new_order_normal_objects := $(foreach f,$(my_src_files),$(my_src_file_obj_$(f)))
1427new_order_normal_objects += $(foreach f,$(my_gen_src_files),$(my_src_file_obj_$(f)))
1428
1429ifneq ($(sort $(normal_objects)),$(sort $(new_order_normal_objects)))
1430$(warning $(LOCAL_MODULE_MAKEFILE) Internal build system warning: New object list does not match old)
1431$(info Only in old: $(filter-out $(new_order_normal_objects),$(sort $(normal_objects))))
1432$(info Only in new: $(filter-out $(normal_objects),$(sort $(new_order_normal_objects))))
1433endif
1434
1435ifeq ($(BINARY_OBJECTS_ORDER),soong)
1436normal_objects := $(new_order_normal_objects)
1437endif
1438
1439normal_objects += $(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES))
Torne (Richard Coles)a5afbe82013-08-29 15:36:34 +01001440
1441all_objects := $(normal_objects) $(gen_o_objects)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001442
Dan Willemsen3bb168f2016-01-19 20:07:08 -08001443# Cleanup file tracking
1444$(foreach f,$(my_tracked_gen_files),$(eval my_src_file_gen_$(s):=))
1445my_tracked_gen_files :=
1446$(foreach f,$(my_tracked_src_files),$(eval my_src_file_obj_$(s):=))
1447my_tracked_src_files :=
1448
Colin Cross2d206702014-02-13 13:41:52 -08001449my_c_includes += $(TOPDIR)$(LOCAL_PATH) $(intermediates) $(generated_sources_dir)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001450
Jiyong Parkb43a52d2017-07-13 15:51:07 +09001451# The platform JNI header is for platform modules only.
1452ifeq ($(LOCAL_SDK_VERSION)$(LOCAL_USE_VNDK),)
Ying Wang6ef65192014-01-15 16:02:16 -08001453 my_c_includes += $(JNI_H_INCLUDE)
Ying Wangbce4b752010-07-22 15:51:56 -07001454endif
1455
Dan Willemsen062e30b2016-05-24 13:06:07 -07001456my_outside_includes := $(filter-out $(OUT_DIR)/%,$(filter /%,$(my_c_includes)))
1457ifneq ($(my_outside_includes),)
1458$(error $(LOCAL_MODULE_MAKEFILE): $(LOCAL_MODULE): C_INCLUDES must be under the source or output directories: $(my_outside_includes))
1459endif
1460
Torne (Richard Coles)a5afbe82013-08-29 15:36:34 +01001461# all_objects includes gen_o_objects which were part of LOCAL_GENERATED_SOURCES;
1462# use normal_objects here to avoid creating circular dependencies. This assumes
1463# that custom build rules which generate .o files don't consume other generated
1464# sources as input (or if they do they take care of that dependency themselves).
Ying Wangec6d6262014-01-16 16:21:03 -08001465$(normal_objects) : | $(my_generated_sources)
Colin Cross6b9bddd2015-11-30 17:33:26 -08001466$(all_objects) : $(import_includes)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001467ALL_C_CPP_ETC_OBJECTS += $(all_objects)
1468
The Android Open Source Project88b60792009-03-03 19:28:42 -08001469
1470###########################################################
1471# Standard library handling.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001472###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001473
1474###########################################################
1475# The list of libraries that this module will link against are in
1476# these variables. Each is a list of bare module names like "libc libm".
1477#
1478# LOCAL_SHARED_LIBRARIES
1479# LOCAL_STATIC_LIBRARIES
1480# LOCAL_WHOLE_STATIC_LIBRARIES
1481#
1482# We need to convert the bare names into the dependencies that
1483# we'll use for LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE.
1484# LOCAL_BUILT_MODULE should depend on the BUILT versions of the
1485# libraries, so that simply building this module doesn't force
1486# an install of a library. Similarly, LOCAL_INSTALLED_MODULE
1487# should depend on the INSTALLED versions of the libraries so
1488# that they get installed when this module does.
1489###########################################################
1490# NOTE:
1491# WHOLE_STATIC_LIBRARIES are libraries that are pulled into the
1492# module without leaving anything out, which is useful for turning
1493# a collection of .a files into a .so file. Linking against a
1494# normal STATIC_LIBRARY will only pull in code/symbols that are
1495# referenced by the module. (see gcc/ld's --whole-archive option)
1496###########################################################
1497
1498# Get the list of BUILT libraries, which are under
1499# various intermediates directories.
1500so_suffix := $($(my_prefix)SHLIB_SUFFIX)
1501a_suffix := $($(my_prefix)STATIC_LIB_SUFFIX)
1502
Dan Willemsenffa32582017-03-19 13:22:45 -07001503ifneq ($(LOCAL_SDK_VERSION),)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001504built_shared_libraries := \
Dan Willemsen8cf6b652018-09-05 11:01:12 -07001505 $(foreach lib,$(my_shared_libraries), \
1506 $(call intermediates-dir-for, \
1507 SHARED_LIBRARIES,$(lib),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/$(lib)$(so_suffix))
Ying Wangc01f2dc2015-12-15 10:00:19 -08001508built_shared_library_deps := $(addsuffix .toc, $(built_shared_libraries))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001509
Ying Wangd8d37212014-03-21 16:17:04 -07001510# Add the NDK libraries to the built module dependency
Ying Wangcce4c972011-03-03 18:53:53 -08001511my_system_shared_libraries_fullpath := \
1512 $(my_ndk_stl_shared_lib_fullpath) \
Andrew Hsieh140761af02014-04-25 23:47:10 -07001513 $(addprefix $(my_ndk_sysroot_lib)/, \
Ying Wangd8d37212014-03-21 16:17:04 -07001514 $(addsuffix $(so_suffix), $(my_system_shared_libraries)))
Ying Wang1a081002010-07-13 14:55:47 -07001515
Dan Albertc1ca1902016-08-04 14:14:50 -07001516# We need to preserve the ordering of LOCAL_SHARED_LIBRARIES regardless of
1517# whether the libs are generated or prebuilt, so we simply can't split into two
1518# lists and use addprefix.
1519my_ndk_shared_libraries_fullpath := \
1520 $(foreach _lib,$(my_ndk_shared_libraries),\
1521 $(if $(filter $(NDK_MIGRATED_LIBS),$(_lib)),\
1522 $(my_built_ndk_libs)/$(_lib)$(so_suffix),\
1523 $(my_ndk_sysroot_lib)/$(_lib)$(so_suffix)))
Dan Albert02bf1382016-07-21 10:04:12 -07001524
1525built_shared_libraries += \
Dan Albertc1ca1902016-08-04 14:14:50 -07001526 $(my_ndk_shared_libraries_fullpath) \
Dan Albert02bf1382016-07-21 10:04:12 -07001527 $(my_system_shared_libraries_fullpath) \
1528
Ying Wang1a081002010-07-13 14:55:47 -07001529else
Ying Wang1a081002010-07-13 14:55:47 -07001530built_shared_libraries := \
Dan Willemsen8cf6b652018-09-05 11:01:12 -07001531 $(foreach lib,$(installed_shared_library_module_names), \
1532 $(call intermediates-dir-for, \
1533 SHARED_LIBRARIES,$(lib),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/$(lib)$(so_suffix))
Ying Wangc01f2dc2015-12-15 10:00:19 -08001534built_shared_library_deps := $(addsuffix .toc, $(built_shared_libraries))
Shinichiro Hamaji0e7587a2015-10-09 14:36:04 +09001535my_system_shared_libraries_fullpath :=
Ying Wang1a081002010-07-13 14:55:47 -07001536endif
1537
The Android Open Source Project88b60792009-03-03 19:28:42 -08001538built_static_libraries := \
Ying Wang6ef65192014-01-15 16:02:16 -08001539 $(foreach lib,$(my_static_libraries), \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001540 $(call intermediates-dir-for, \
Alexey Polyudovccdc3112016-08-01 17:41:49 -07001541 STATIC_LIBRARIES,$(lib),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/$(lib)$(a_suffix))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001542
Ying Wang848020f2012-08-14 10:13:16 -07001543ifdef LOCAL_SDK_VERSION
Ying Wangcce4c972011-03-03 18:53:53 -08001544built_static_libraries += $(my_ndk_stl_static_lib)
1545endif
1546
The Android Open Source Project88b60792009-03-03 19:28:42 -08001547built_whole_libraries := \
Colin Cross90353fe2014-02-04 14:53:25 -08001548 $(foreach lib,$(my_whole_static_libraries), \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001549 $(call intermediates-dir-for, \
Alexey Polyudovccdc3112016-08-01 17:41:49 -07001550 STATIC_LIBRARIES,$(lib),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/$(lib)$(a_suffix))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001551
The Android Open Source Project88b60792009-03-03 19:28:42 -08001552# We don't care about installed static libraries, since the
1553# libraries have already been linked into the module at that point.
1554# We do, however, care about the NOTICE files for any static
Steve Blockd14d3b42012-03-01 11:34:41 +00001555# libraries that we use. (see notice_files.mk)
Dan Willemsen62db0f02018-06-16 09:37:13 -07001556#
1557# Don't do this in mm, since many of the targets won't exist.
1558ifeq ($(ONE_SHOT_MAKEFILE),)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001559installed_static_library_notice_file_targets := \
Colin Cross90353fe2014-02-04 14:53:25 -08001560 $(foreach lib,$(my_static_libraries) $(my_whole_static_libraries), \
Jaewoong Junge8cb1952018-11-08 16:53:02 -08001561 NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST$(if $(my_host_cross),_CROSS,),TARGET)-STATIC_LIBRARIES-$(lib))
Dan Willemsen62db0f02018-06-16 09:37:13 -07001562else
1563installed_static_library_notice_file_targets :=
1564endif
The Android Open Source Project88b60792009-03-03 19:28:42 -08001565
Colin Cross579668b2018-08-14 13:13:47 -07001566$(notice_target): | $(installed_static_library_notice_file_targets)
1567$(LOCAL_INSTALLED_MODULE): | $(notice_target)
1568
Doug Kwan9a8ecf92011-05-10 21:50:58 -07001569# Default is -fno-rtti.
Doug Kwane3c3c6d2011-06-07 10:55:48 -07001570ifeq ($(strip $(LOCAL_RTTI_FLAG)),)
1571LOCAL_RTTI_FLAG := -fno-rtti
1572endif
Doug Kwan9a8ecf92011-05-10 21:50:58 -07001573
The Android Open Source Project88b60792009-03-03 19:28:42 -08001574###########################################################
1575# Rule-specific variable definitions
1576###########################################################
Logan Chiene6f65432013-12-10 19:07:41 +08001577
Chih-Hung Hsieh9aa69a62014-09-04 17:15:47 -07001578my_cflags += $(LOCAL_CLANG_CFLAGS)
Stephen Hines15680292014-11-26 00:53:46 -08001579my_conlyflags += $(LOCAL_CLANG_CONLYFLAGS)
Dan Albertd2fa96d2014-11-28 14:00:12 -08001580my_cppflags += $(LOCAL_CLANG_CPPFLAGS)
Chih-Hung Hsieh9aa69a62014-09-04 17:15:47 -07001581my_asflags += $(LOCAL_CLANG_ASFLAGS)
1582my_ldflags += $(LOCAL_CLANG_LDFLAGS)
Chih-Hung Hsieh619fdb82014-09-26 17:13:48 -07001583my_cflags += $(LOCAL_CLANG_CFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_CFLAGS_$(my_32_64_bit_suffix))
Stephen Hines15680292014-11-26 00:53:46 -08001584my_conlyflags += $(LOCAL_CLANG_CONLYFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_CONLYFLAGS_$(my_32_64_bit_suffix))
Chih-Hung Hsieh619fdb82014-09-26 17:13:48 -07001585my_cppflags += $(LOCAL_CLANG_CPPFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_CPPFLAGS_$(my_32_64_bit_suffix))
1586my_ldflags += $(LOCAL_CLANG_LDFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_LDFLAGS_$(my_32_64_bit_suffix))
1587my_asflags += $(LOCAL_CLANG_ASFLAGS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) $(LOCAL_CLANG_ASFLAGS_$(my_32_64_bit_suffix))
Dan Willemsen02268f02016-05-19 14:39:25 -07001588my_cflags := $(call convert-to-clang-flags,$(my_cflags))
1589my_cppflags := $(call convert-to-clang-flags,$(my_cppflags))
1590my_asflags := $(call convert-to-clang-flags,$(my_asflags))
1591my_ldflags := $(call convert-to-clang-flags,$(my_ldflags))
Logan Chiene6f65432013-12-10 19:07:41 +08001592
Ying Wang45d01432014-10-28 14:50:59 -07001593ifeq ($(my_fdo_build), true)
1594 my_cflags := $(patsubst -Os,-O2,$(my_cflags))
1595 fdo_incompatible_flags := -fno-early-inlining -finline-limit=%
1596 my_cflags := $(filter-out $(fdo_incompatible_flags),$(my_cflags))
Dehao Chen295a6d22014-09-19 10:18:12 -07001597endif
1598
Dan Albertdf3fd1d2015-08-12 14:54:16 -07001599# No one should ever use this flag. On GCC it's mere presence will disable all
1600# warnings, even those that are specified after it (contrary to typical warning
1601# flag behavior). This circumvents CFLAGS_NO_OVERRIDE from forcibly enabling the
1602# warnings that are *always* bugs.
1603my_illegal_flags := -w
1604my_cflags := $(filter-out $(my_illegal_flags),$(my_cflags))
1605my_cppflags := $(filter-out $(my_illegal_flags),$(my_cppflags))
1606my_conlyflags := $(filter-out $(my_illegal_flags),$(my_conlyflags))
1607
Dan Albert5ae31dd2016-01-29 16:51:51 -08001608# We can enforce some rules more strictly in the code we own. my_strict
1609# indicates if this is code that we can be stricter with. If we have rules that
1610# we want to apply to *our* code (but maybe can't for vendor/device specific
1611# things), we could extend this to be a ternary value.
1612my_strict := true
1613ifneq ($(filter external/%,$(LOCAL_PATH)),)
1614 my_strict := false
1615endif
1616
1617# Can be used to make some annotations stricter for code we can fix (such as
1618# when we mark functions as deprecated).
1619ifeq ($(my_strict),true)
1620 my_cflags += -DANDROID_STRICT
1621endif
1622
Chih-Hung Hsieh1876acd2017-11-06 10:47:24 -08001623# Check if -Werror or -Wno-error is used in C compiler flags.
Colin Cross8fb525d2018-09-06 16:25:22 -07001624# Header libraries do not need cflags.
1625ifneq (HEADER_LIBRARIES,$(LOCAL_MODULE_CLASS))
1626 # Prebuilt modules do not need cflags.
1627 ifeq (,$(LOCAL_PREBUILT_MODULE_FILE))
1628 my_all_cflags := $(my_cflags) $(my_cppflags) $(my_cflags_no_override)
1629 # Issue warning if -Wno-error is used.
1630 ifneq (,$(filter -Wno-error,$(my_all_cflags)))
1631 $(eval MODULES_USING_WNO_ERROR := $(MODULES_USING_WNO_ERROR) $(LOCAL_MODULE_MAKEFILE):$(LOCAL_MODULE))
1632 else
1633 # Issue warning if -Werror is not used. Add it.
1634 ifeq (,$(filter -Werror,$(my_all_cflags)))
1635 # Add -Wall -Werror unless the project is in the WARNING_ALLOWED project list.
1636 ifeq (,$(strip $(call find_warning_allowed_projects,$(LOCAL_PATH))))
1637 my_cflags := -Wall -Werror $(my_cflags)
1638 else
1639 $(eval MODULES_ADDED_WALL := $(MODULES_ADDED_WALL) $(LOCAL_MODULE_MAKEFILE):$(LOCAL_MODULE))
1640 my_cflags := -Wall $(my_cflags)
Chih-Hung Hsieh1876acd2017-11-06 10:47:24 -08001641 endif
1642 endif
1643 endif
Chih-Hung Hsiehbab04882016-10-11 15:38:39 -07001644 endif
1645endif
1646
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001647# Disable clang-tidy if it is not found.
1648ifeq ($(PATH_TO_CLANG_TIDY),)
1649 my_tidy_enabled := false
1650else
1651 # If LOCAL_TIDY is not defined, use global WITH_TIDY
1652 my_tidy_enabled := $(LOCAL_TIDY)
1653 ifeq ($(my_tidy_enabled),)
1654 my_tidy_enabled := $(WITH_TIDY)
1655 endif
1656endif
1657
1658# my_tidy_checks is empty if clang-tidy is disabled.
1659my_tidy_checks :=
1660my_tidy_flags :=
1661ifneq (,$(filter 1 true,$(my_tidy_enabled)))
Dan Willemsenf0638392018-09-04 22:25:22 -07001662 tidy_only: $(cpp_objects) $(c_objects) $(gen_c_objects) $(gen_cpp_objects)
1663 # Set up global default checks
1664 my_tidy_checks := $(WITH_TIDY_CHECKS)
1665 ifeq ($(my_tidy_checks),)
1666 my_tidy_checks := $(call default_global_tidy_checks,$(LOCAL_PATH))
1667 endif
1668 # Append local clang-tidy checks.
1669 ifneq ($(LOCAL_TIDY_CHECKS),)
1670 my_tidy_checks := $(my_tidy_checks),$(LOCAL_TIDY_CHECKS)
1671 endif
Chih-Hung Hsieh1d9f04f2018-09-21 10:30:31 -07001672 my_tidy_flags := $(strip $(WITH_TIDY_FLAGS) $(LOCAL_TIDY_FLAGS))
Dan Willemsenf0638392018-09-04 22:25:22 -07001673 # If tidy flags are not specified, default to check all header files.
1674 ifeq ($(my_tidy_flags),)
1675 my_tidy_flags := $(call default_tidy_header_filter,$(LOCAL_PATH))
1676 endif
1677 # If clang-tidy is not enabled globally, add the -quiet flag.
1678 ifeq (,$(filter 1 true,$(WITH_TIDY)))
1679 my_tidy_flags += -quiet -extra-arg-before=-fno-caret-diagnostics
1680 endif
George Burgess IV5ab07d42017-05-03 18:10:47 -07001681
Dan Willemsenf0638392018-09-04 22:25:22 -07001682 ifneq ($(my_tidy_checks),)
1683 # We might be using the static analyzer through clang-tidy.
1684 # https://bugs.llvm.org/show_bug.cgi?id=32914
1685 my_tidy_flags += -extra-arg-before=-D__clang_analyzer__
George Burgess IV432899a2018-05-14 15:46:43 -07001686
Dan Willemsenf0638392018-09-04 22:25:22 -07001687 # A recent change in clang-tidy (r328258) enabled destructor inlining,
1688 # which appears to cause a number of false positives. Until that's
1689 # resolved, this turns off the effects of r328258.
1690 # https://bugs.llvm.org/show_bug.cgi?id=37459
1691 my_tidy_flags += -extra-arg-before=-Xclang
1692 my_tidy_flags += -extra-arg-before=-analyzer-config
1693 my_tidy_flags += -extra-arg-before=-Xclang
1694 my_tidy_flags += -extra-arg-before=c++-temp-dtor-inlining=false
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001695 endif
1696endif
1697
Chih-Hung Hsiehba646252016-08-16 16:27:30 -07001698my_tidy_checks := $(subst $(space),,$(my_tidy_checks))
1699
Chih-Hung Hsiehbe5dd202018-08-26 20:37:49 -07001700# Add dependency of clang-tidy and clang-tidy.sh
1701ifneq ($(my_tidy_checks),)
1702 my_clang_tidy_programs := $(PATH_TO_CLANG_TIDY) $(PATH_TO_CLANG_TIDY_SHELL)
1703 $(cpp_objects): $(intermediates)/%.o: $(my_clang_tidy_programs)
1704 $(c_objects): $(intermediates)/%.o: $(my_clang_tidy_programs)
1705 $(gen_cpp_objects): $(intermediates)/%.o: $(my_clang_tidy_programs)
1706 $(gen_c_objects): $(intermediates)/%.o: $(my_clang_tidy_programs)
1707endif
1708
Dan Willemsen6731b492016-06-07 16:55:57 -07001709# Move -l* entries from ldflags to ldlibs, and everything else to ldflags
1710my_ldlib_flags := $(my_ldflags) $(my_ldlibs)
1711my_ldlibs := $(filter -l%,$(my_ldlib_flags))
1712my_ldflags := $(filter-out -l%,$(my_ldlib_flags))
1713
1714# One last verification check for ldlibs
Dan Willemsen6731b492016-06-07 16:55:57 -07001715my_allowed_ldlibs :=
Dan Willemsen4dbb3542017-09-26 00:14:01 -07001716ifndef LOCAL_IS_HOST_MODULE
1717 ifneq ($(LOCAL_SDK_VERSION),)
1718 my_allowed_ldlibs := $(addprefix -l,$(NDK_PREBUILT_SHARED_LIBRARIES))
1719 endif
1720else
1721 my_allowed_ldlibs := $($(my_prefix)AVAILABLE_LIBRARIES)
Dan Willemsen6731b492016-06-07 16:55:57 -07001722endif
1723
1724my_bad_ldlibs := $(filter-out $(my_allowed_ldlibs),$(my_ldlibs))
1725ifneq ($(my_bad_ldlibs),)
1726 $(error $(LOCAL_MODULE_MAKEFILE): $(LOCAL_MODULE): Bad LOCAL_LDLIBS entries: $(my_bad_ldlibs))
1727endif
Dan Willemsen6731b492016-06-07 16:55:57 -07001728
Dan Willemsenc9aa6fc2016-09-13 10:44:44 -07001729# my_cxx_ldlibs may contain linker flags need to wrap certain libraries
1730# (start-group/end-group), so append after the check above.
1731my_ldlibs += $(my_cxx_ldlibs)
1732
The Android Open Source Project88b60792009-03-03 19:28:42 -08001733$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS)
Ying Wang6ef65192014-01-15 16:02:16 -08001734$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASFLAGS := $(my_asflags)
Stephen Hines15680292014-11-26 00:53:46 -08001735$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CONLYFLAGS := $(my_conlyflags)
Ying Wang6ef65192014-01-15 16:02:16 -08001736$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS := $(my_cflags)
1737$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS := $(my_cppflags)
Dan Albertd1600412015-06-10 16:33:43 -07001738$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS_NO_OVERRIDE := $(my_cflags_no_override)
1739$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS_NO_OVERRIDE := $(my_cppflags_no_override)
Doug Kwan9a8ecf92011-05-10 21:50:58 -07001740$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RTTI_FLAG := $(LOCAL_RTTI_FLAG)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001741$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEBUG_CFLAGS := $(debug_cflags)
Ying Wang6ef65192014-01-15 16:02:16 -08001742$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_C_INCLUDES := $(my_c_includes)
Ying Wang5f074802011-11-08 09:31:21 -08001743$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_IMPORT_INCLUDES := $(import_includes)
Ying Wang6ef65192014-01-15 16:02:16 -08001744$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDFLAGS := $(my_ldflags)
Dan Albertb05f2ca2014-09-12 14:46:57 -07001745$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDLIBS := $(my_ldlibs)
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001746$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TIDY_CHECKS := $(my_tidy_checks)
1747$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TIDY_FLAGS := $(my_tidy_flags)
Evgenii Stepanove1b96f32017-01-23 16:57:38 -08001748$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ARFLAGS := $(my_arflags)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001749
1750# this is really the way to get the files onto the command line instead
1751# of using $^, because then LOCAL_ADDITIONAL_DEPENDENCIES doesn't work
1752$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_SHARED_LIBRARIES := $(built_shared_libraries)
1753$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_STATIC_LIBRARIES := $(built_static_libraries)
1754$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(built_whole_libraries)
Ying Wang4aaa1a12016-03-22 18:23:13 -07001755$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_OBJECTS := $(strip $(all_objects))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001756
1757###########################################################
1758# Define library dependencies.
1759###########################################################
1760# all_libraries is used for the dependencies on LOCAL_BUILT_MODULE.
1761all_libraries := \
Ying Wangc01f2dc2015-12-15 10:00:19 -08001762 $(built_shared_library_deps) \
Shinichiro Hamaji0e7587a2015-10-09 14:36:04 +09001763 $(my_system_shared_libraries_fullpath) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001764 $(built_static_libraries) \
1765 $(built_whole_libraries)
1766
Ying Wang5f074802011-11-08 09:31:21 -08001767###########################################################
1768# Export includes
1769###########################################################
1770export_includes := $(intermediates)/export_includes
Dan Willemsen05909fa2017-03-19 13:22:45 -07001771export_cflags := $(foreach d,$(my_export_c_include_dirs),-I $(d))
Dan Willemsen05909fa2017-03-19 13:22:45 -07001772$(export_includes): PRIVATE_EXPORT_CFLAGS := $(export_cflags)
Christopher Wileyff1c3f22016-04-11 12:40:36 -07001773# Headers exported by whole static libraries are also exported by this library.
Dan Willemsena7808ac2016-03-04 12:40:25 -08001774export_include_deps := $(strip \
1775 $(foreach l,$(my_whole_static_libraries), \
Alexey Polyudovccdc3112016-08-01 17:41:49 -07001776 $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes))
Christopher Wileyff1c3f22016-04-11 12:40:36 -07001777# Re-export requested headers from shared libraries.
1778export_include_deps += $(strip \
1779 $(foreach l,$(LOCAL_EXPORT_SHARED_LIBRARY_HEADERS), \
Alexey Polyudovccdc3112016-08-01 17:41:49 -07001780 $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes))
Christopher Wileyff1c3f22016-04-11 12:40:36 -07001781# Re-export requested headers from static libraries.
1782export_include_deps += $(strip \
1783 $(foreach l,$(LOCAL_EXPORT_STATIC_LIBRARY_HEADERS), \
Alexey Polyudovccdc3112016-08-01 17:41:49 -07001784 $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes))
Dan Willemsen8dae49c2017-02-15 15:48:11 -08001785# Re-export requested headers from header libraries.
1786export_include_deps += $(strip \
1787 $(foreach l,$(LOCAL_EXPORT_HEADER_LIBRARY_HEADERS), \
1788 $(call intermediates-dir-for,HEADER_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes))
Dan Willemsena7808ac2016-03-04 12:40:25 -08001789$(export_includes): PRIVATE_REEXPORTED_INCLUDES := $(export_include_deps)
Ying Wang05f9f352016-05-05 20:02:08 -07001790# By adding $(my_generated_sources) it makes sure the headers get generated
1791# before any dependent source files get compiled.
Dan Willemsen8dae49c2017-02-15 15:48:11 -08001792$(export_includes) : $(my_export_c_include_deps) $(my_generated_sources) $(export_include_deps) $(LOCAL_EXPORT_C_INCLUDE_DEPS)
Ying Wang5f074802011-11-08 09:31:21 -08001793 @echo Export includes file: $< -- $@
Dan Willemsena7808ac2016-03-04 12:40:25 -08001794 $(hide) mkdir -p $(dir $@) && rm -f $@.tmp && touch $@.tmp
Dan Willemsen05909fa2017-03-19 13:22:45 -07001795ifdef export_cflags
1796 $(hide) echo "$(PRIVATE_EXPORT_CFLAGS)" >>$@.tmp
Dan Willemsena7808ac2016-03-04 12:40:25 -08001797endif
1798ifdef export_include_deps
1799 $(hide) for f in $(PRIVATE_REEXPORTED_INCLUDES); do \
1800 cat $$f >> $@.tmp; \
1801 done
Ying Wang5f074802011-11-08 09:31:21 -08001802endif
Colin Cross6b9bddd2015-11-30 17:33:26 -08001803 $(hide) if cmp -s $@.tmp $@ ; then \
1804 rm $@.tmp ; \
1805 else \
1806 mv $@.tmp $@ ; \
1807 fi
Dan Willemsen05909fa2017-03-19 13:22:45 -07001808export_cflags :=
Colin Cross6b9bddd2015-11-30 17:33:26 -08001809
1810# Kati adds restat=1 to ninja. GNU make does nothing for this.
1811.KATI_RESTAT: $(export_includes)
Ying Wang616e5962012-04-18 17:35:55 -07001812
1813# Make sure export_includes gets generated when you are running mm/mmm
Dan Willemsenb47d4e92017-04-08 00:31:31 -07001814$(LOCAL_BUILT_MODULE) : | $(export_includes)
Dan Willemsenfc92fb22016-08-26 13:27:13 -07001815
Dan Willemsen0be69072016-12-13 18:28:33 -08001816ifneq (,$(filter-out $(LOCAL_PATH)/%,$(my_export_c_include_dirs)))
1817my_soong_problems += non_local__export_c_include_dirs
1818endif
1819
Dan Willemsenfc92fb22016-08-26 13:27:13 -07001820SOONG_CONV.$(LOCAL_MODULE).PROBLEMS := \
1821 $(SOONG_CONV.$(LOCAL_MODULE).PROBLEMS) $(my_soong_problems)
1822SOONG_CONV.$(LOCAL_MODULE).DEPS := \
1823 $(SOONG_CONV.$(LOCAL_MODULE).DEPS) \
Dan Willemsen0bf506f2017-04-25 15:42:14 -07001824 $(filter-out $($(LOCAL_2ND_ARCH_VAR_PREFIX)UBSAN_RUNTIME_LIBRARY),\
1825 $(my_static_libraries) \
1826 $(my_whole_static_libraries) \
1827 $(my_shared_libraries) \
1828 $(my_system_shared_libraries))
Colin Cross3277ba32017-12-06 14:37:06 -08001829SOONG_CONV.$(LOCAL_MODULE).TYPE := native
Dan Willemsenfc92fb22016-08-26 13:27:13 -07001830SOONG_CONV := $(SOONG_CONV) $(LOCAL_MODULE)
Ryan Campbell81c9d292016-09-12 13:56:50 -07001831
1832###########################################################
1833# Coverage packaging.
1834###########################################################
1835ifeq ($(my_native_coverage),true)
Ryan Campbell5a6ea362017-02-28 16:20:23 -08001836my_gcno_objects := \
1837 $(cpp_objects) \
1838 $(gen_cpp_objects) \
1839 $(c_objects) \
1840 $(gen_c_objects) \
1841 $(objc_objects) \
1842 $(objcpp_objects)
1843
1844LOCAL_GCNO_FILES := $(patsubst %.o,%.gcno,$(my_gcno_objects))
1845$(foreach f,$(my_gcno_objects),$(eval $(call gcno-touch-rule,$(f),$(f:.o=.gcno))))
Ryan Campbell81c9d292016-09-12 13:56:50 -07001846endif