base_rules.mk revision 25e01177dee8bd061b2b8d3a0636482b74e94cbb
1# 2# Copyright (C) 2008 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16 17# Users can define base-rules-hook in their buildspec.mk to perform 18# arbitrary operations as each module is included. 19ifdef base-rules-hook 20$(if $(base-rules-hook),) 21endif 22 23########################################################### 24## Common instructions for a generic module. 25########################################################### 26 27LOCAL_MODULE := $(strip $(LOCAL_MODULE)) 28ifeq ($(LOCAL_MODULE),) 29 $(error $(LOCAL_PATH): LOCAL_MODULE is not defined) 30endif 31 32LOCAL_IS_HOST_MODULE := $(strip $(LOCAL_IS_HOST_MODULE)) 33ifdef LOCAL_IS_HOST_MODULE 34 ifneq ($(LOCAL_IS_HOST_MODULE),true) 35 $(error $(LOCAL_PATH): LOCAL_IS_HOST_MODULE must be "true" or empty, not "$(LOCAL_IS_HOST_MODULE)") 36 endif 37 ifeq ($(LOCAL_HOST_PREFIX),) 38 my_prefix := HOST_ 39 else 40 my_prefix := $(LOCAL_HOST_PREFIX) 41 endif 42 my_host := host- 43else 44 my_prefix := TARGET_ 45 my_host := 46endif 47 48ifeq ($(my_prefix),HOST_CROSS_) 49 my_host_cross := true 50else 51 my_host_cross := 52endif 53 54my_module_tags := $(LOCAL_MODULE_TAGS) 55ifeq ($(my_host_cross),true) 56 my_module_tags := 57endif 58 59########################################################### 60## Validate and define fallbacks for input LOCAL_* variables. 61########################################################### 62 63## Dump a .csv file of all modules and their tags 64#ifneq ($(tag-list-first-time),false) 65#$(shell rm -f tag-list.csv) 66#tag-list-first-time := false 67#endif 68#$(shell echo $(lastword $(filter-out config/% out/%,$(MAKEFILE_LIST))),$(LOCAL_MODULE),$(strip $(LOCAL_MODULE_CLASS)),$(subst $(space),$(comma),$(sort $(my_module_tags))) >> tag-list.csv) 69 70LOCAL_UNINSTALLABLE_MODULE := $(strip $(LOCAL_UNINSTALLABLE_MODULE)) 71my_module_tags := $(sort $(my_module_tags)) 72ifeq (,$(my_module_tags)) 73 my_module_tags := optional 74endif 75 76# User tags are not allowed anymore. Fail early because it will not be installed 77# like it used to be. 78ifneq ($(filter $(my_module_tags),user),) 79 $(warning *** Module name: $(LOCAL_MODULE)) 80 $(warning *** Makefile location: $(LOCAL_MODULE_MAKEFILE)) 81 $(warning * ) 82 $(warning * Module is attempting to use the 'user' tag. This) 83 $(warning * used to cause the module to be installed automatically.) 84 $(warning * Now, the module must be listed in the PRODUCT_PACKAGES) 85 $(warning * section of a product makefile to have it installed.) 86 $(warning * ) 87 $(error user tag detected on module.) 88endif 89 90# Only the tags mentioned in this test are expected to be set by module 91# makefiles. Anything else is either a typo or a source of unexpected 92# behaviors. 93ifneq ($(filter-out debug eng tests optional samples,$(my_module_tags)),) 94$(warning unusual tags $(my_module_tags) on $(LOCAL_MODULE) at $(LOCAL_PATH)) 95endif 96 97# Add implicit tags. 98# 99# If the local directory or one of its parents contains a MODULE_LICENSE_GPL 100# file, tag the module as "gnu". Search for "*_GPL*", "*_LGPL*" and "*_MPL*" 101# so that we can also find files like MODULE_LICENSE_GPL_AND_AFL 102# 103license_files := $(call find-parent-file,$(LOCAL_PATH),MODULE_LICENSE*) 104gpl_license_file := $(call find-parent-file,$(LOCAL_PATH),MODULE_LICENSE*_GPL* MODULE_LICENSE*_MPL* MODULE_LICENSE*_LGPL*) 105ifneq ($(gpl_license_file),) 106 my_module_tags += gnu 107 ALL_GPL_MODULE_LICENSE_FILES := $(sort $(ALL_GPL_MODULE_LICENSE_FILES) $(gpl_license_file)) 108endif 109 110LOCAL_MODULE_CLASS := $(strip $(LOCAL_MODULE_CLASS)) 111ifneq ($(words $(LOCAL_MODULE_CLASS)),1) 112 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS must contain exactly one word, not "$(LOCAL_MODULE_CLASS)") 113endif 114 115my_32_64_bit_suffix := $(if $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)IS_64_BIT),64,32) 116 117ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE)) 118my_multilib_module_path := $(strip $(LOCAL_MODULE_PATH_$(my_32_64_bit_suffix))) 119ifdef my_multilib_module_path 120my_module_path := $(my_multilib_module_path) 121else 122my_module_path := $(strip $(LOCAL_MODULE_PATH)) 123endif 124my_module_relative_path := $(strip $(LOCAL_MODULE_RELATIVE_PATH)) 125ifeq ($(my_module_path),) 126 ifdef LOCAL_IS_HOST_MODULE 127 partition_tag := 128 else 129 ifeq (true,$(LOCAL_PROPRIETARY_MODULE)) 130 partition_tag := _VENDOR 131 else ifeq (true,$(LOCAL_OEM_MODULE)) 132 partition_tag := _OEM 133 else ifeq (true,$(LOCAL_ODM_MODULE)) 134 partition_tag := _ODM 135 else 136 # The definition of should-install-to-system will be different depending 137 # on which goal (e.g., sdk or just droid) is being built. 138 partition_tag := $(if $(call should-install-to-system,$(my_module_tags)),,_DATA) 139 endif 140 endif 141 install_path_var := $(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT$(partition_tag)_$(LOCAL_MODULE_CLASS) 142 ifeq (true,$(LOCAL_PRIVILEGED_MODULE)) 143 install_path_var := $(install_path_var)_PRIVILEGED 144 endif 145 146 my_module_path := $($(install_path_var)) 147 ifeq ($(strip $(my_module_path)),) 148 $(error $(LOCAL_PATH): unhandled install path "$(install_path_var) for $(LOCAL_MODULE)") 149 endif 150endif 151ifneq ($(my_module_relative_path),) 152 my_module_path := $(my_module_path)/$(my_module_relative_path) 153endif 154endif # not LOCAL_UNINSTALLABLE_MODULE 155 156ifneq ($(strip $(LOCAL_BUILT_MODULE)$(LOCAL_INSTALLED_MODULE)),) 157 $(error $(LOCAL_PATH): LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE must not be defined by component makefiles) 158endif 159 160my_register_name := $(LOCAL_MODULE) 161ifdef LOCAL_2ND_ARCH_VAR_PREFIX 162ifndef LOCAL_NO_2ND_ARCH_MODULE_SUFFIX 163my_register_name := $(LOCAL_MODULE)$($(my_prefix)2ND_ARCH_MODULE_SUFFIX) 164endif 165endif 166ifeq ($(my_host_cross),true) 167 my_register_name := host_cross_$(LOCAL_MODULE) 168endif 169# Make sure that this IS_HOST/CLASS/MODULE combination is unique. 170module_id := MODULE.$(if \ 171 $(LOCAL_IS_HOST_MODULE),$($(my_prefix)OS),TARGET).$(LOCAL_MODULE_CLASS).$(my_register_name) 172ifdef $(module_id) 173$(error $(LOCAL_PATH): $(module_id) already defined by $($(module_id))) 174endif 175$(module_id) := $(LOCAL_PATH) 176 177intermediates := $(call local-intermediates-dir,,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross)) 178intermediates.COMMON := $(call local-intermediates-dir,COMMON) 179generated_sources_dir := $(call local-generated-sources-dir) 180 181########################################################### 182# Pick a name for the intermediate and final targets 183########################################################### 184include $(BUILD_SYSTEM)/configure_module_stem.mk 185 186# OVERRIDE_BUILT_MODULE_PATH is only allowed to be used by the 187# internal SHARED_LIBRARIES build files. 188OVERRIDE_BUILT_MODULE_PATH := $(strip $(OVERRIDE_BUILT_MODULE_PATH)) 189ifdef OVERRIDE_BUILT_MODULE_PATH 190 ifneq ($(LOCAL_MODULE_CLASS),SHARED_LIBRARIES) 191 $(error $(LOCAL_PATH): Illegal use of OVERRIDE_BUILT_MODULE_PATH) 192 endif 193 built_module_path := $(OVERRIDE_BUILT_MODULE_PATH) 194else 195 built_module_path := $(intermediates) 196endif 197LOCAL_BUILT_MODULE := $(built_module_path)/$(my_built_module_stem) 198 199ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE)) 200 # Apk and its attachments reside in its own subdir. 201 ifeq ($(LOCAL_MODULE_CLASS),APPS) 202 # framework-res.apk doesn't like the additional layer. 203 ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true) 204 my_module_path := $(my_module_path)/$(LOCAL_MODULE) 205 endif 206 endif 207 LOCAL_INSTALLED_MODULE := $(my_module_path)/$(my_installed_module_stem) 208endif 209 210# Assemble the list of targets to create PRIVATE_ variables for. 211LOCAL_INTERMEDIATE_TARGETS += $(LOCAL_BUILT_MODULE) 212 213########################################################### 214## logtags: Add .logtags files to global list 215########################################################### 216 217logtags_sources := $(filter %.logtags,$(LOCAL_SRC_FILES)) 218 219ifneq ($(strip $(logtags_sources)),) 220event_log_tags := $(addprefix $(LOCAL_PATH)/,$(logtags_sources)) 221else 222event_log_tags := 223endif 224 225########################################################### 226## make clean- targets 227########################################################### 228cleantarget := clean-$(my_register_name) 229$(cleantarget) : PRIVATE_MODULE := $(my_register_name) 230$(cleantarget) : PRIVATE_CLEAN_FILES := \ 231 $(LOCAL_BUILT_MODULE) \ 232 $(LOCAL_INSTALLED_MODULE) \ 233 $(intermediates) 234$(cleantarget):: 235 @echo "Clean: $(PRIVATE_MODULE)" 236 $(hide) rm -rf $(PRIVATE_CLEAN_FILES) 237 238########################################################### 239## Common definitions for module. 240########################################################### 241$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_PATH:=$(LOCAL_PATH) 242$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_IS_HOST_MODULE := $(LOCAL_IS_HOST_MODULE) 243$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_HOST:= $(my_host) 244$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_PREFIX := $(my_prefix) 245 246$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_INTERMEDIATES_DIR:= $(intermediates) 247$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_2ND_ARCH_VAR_PREFIX := $(LOCAL_2ND_ARCH_VAR_PREFIX) 248 249# Tell the module and all of its sub-modules who it is. 250$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_MODULE:= $(my_register_name) 251 252# Provide a short-hand for building this module. 253# We name both BUILT and INSTALLED in case 254# LOCAL_UNINSTALLABLE_MODULE is set. 255.PHONY: $(my_register_name) 256$(my_register_name): $(LOCAL_BUILT_MODULE) $(LOCAL_INSTALLED_MODULE) 257 258########################################################### 259## Module installation rule 260########################################################### 261 262# Some hosts do not have ACP; override the LOCAL version if that's the case. 263ifneq ($(strip $(HOST_ACP_UNAVAILABLE)),) 264 LOCAL_ACP_UNAVAILABLE := $(strip $(HOST_ACP_UNAVAILABLE)) 265endif 266 267ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE)) 268 # Define a copy rule to install the module. 269 # acp and libraries that it uses can't use acp for 270 # installation; hence, LOCAL_ACP_UNAVAILABLE. 271$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := $(LOCAL_POST_INSTALL_CMD) 272ifneq ($(LOCAL_ACP_UNAVAILABLE),true) 273$(LOCAL_INSTALLED_MODULE): $(LOCAL_BUILT_MODULE) | $(ACP) 274 @echo "Install: $@" 275 $(copy-file-to-new-target) 276 $(PRIVATE_POST_INSTALL_CMD) 277else 278$(LOCAL_INSTALLED_MODULE): $(LOCAL_BUILT_MODULE) 279 @echo "Install: $@" 280 $(copy-file-to-target-with-cp) 281endif 282 283# Rule to install the module's companion init.rc. 284my_init_rc := $(LOCAL_INIT_RC_$(my_32_64_bit_suffix)) 285my_init_rc_src := 286my_init_rc_installed := 287ifndef my_init_rc 288my_init_rc := $(LOCAL_INIT_RC) 289# Make sure we don't define the rule twice in multilib module. 290LOCAL_INIT_RC := 291endif 292ifdef my_init_rc 293my_init_rc_src := $(LOCAL_PATH)/$(my_init_rc) 294my_init_rc_installed := $(TARGET_OUT$(partition_tag)_ETC)/init/$(notdir $(my_init_rc_src)) 295$(my_init_rc_installed) : $(my_init_rc_src) | $(ACP) 296 @echo "Install: $@" 297 $(copy-file-to-new-target) 298 299$(my_register_name) : $(my_init_rc_installed) 300endif # my_init_rc 301endif # !LOCAL_UNINSTALLABLE_MODULE 302 303########################################################### 304## CHECK_BUILD goals 305########################################################### 306my_checked_module := 307# If nobody has defined a more specific module for the 308# checked modules, use LOCAL_BUILT_MODULE. 309ifdef LOCAL_CHECKED_MODULE 310 my_checked_module := $(LOCAL_CHECKED_MODULE) 311else 312 my_checked_module := $(LOCAL_BUILT_MODULE) 313endif 314 315# If they request that this module not be checked, then don't. 316# PLEASE DON'T SET THIS. ANY PLACES THAT SET THIS WITHOUT 317# GOOD REASON WILL HAVE IT REMOVED. 318ifdef LOCAL_DONT_CHECK_MODULE 319 my_checked_module := 320endif 321# Don't check build target module defined for the 2nd arch 322ifndef LOCAL_IS_HOST_MODULE 323ifdef LOCAL_2ND_ARCH_VAR_PREFIX 324 my_checked_module := 325endif 326endif 327 328########################################################### 329## Compatibiliy suite files. 330########################################################### 331ifdef LOCAL_COMPATIBILITY_SUITE 332ifneq ($(words $(LOCAL_COMPATIBILITY_SUITE)),1) 333$(error $(LOCAL_PATH):$(LOCAL_MODULE) LOCAL_COMPATIBILITY_SUITE can be only one name) 334endif 335 336# LOCAL_COMPATIBILITY_SUPPORT_FILES is a list of <src>[:<dest>]. 337my_compat_dist := $(foreach f, $(LOCAL_COMPATIBILITY_SUPPORT_FILES),\ 338 $(eval p := $(subst :,$(space),$(f)))\ 339 $(eval s := $(LOCAL_PATH)/$(word 1,$(p)))\ 340 $(eval d := $(COMPATIBILITY_TESTCASES_OUT_$(LOCAL_COMPATIBILITY_SUITE))/$(or $(word 2,$(p)),(word 1,$(p))))\ 341 $(s):$(d)) 342 343# The module itself. 344my_compat_dist += \ 345 $(LOCAL_BUILT_MODULE):$(COMPATIBILITY_TESTCASES_OUT_$(LOCAL_COMPATIBILITY_SUITE))/$(my_installed_module_stem) 346 347ifneq (,$(wildcard $(LOCAL_PATH)/AndroidTest.xml)) 348my_compat_dist += \ 349 $(LOCAL_PATH)/AndroidTest.xml:$(COMPATIBILITY_TESTCASES_OUT_$(LOCAL_COMPATIBILITY_SUITE))/$(LOCAL_MODULE).config 350endif 351 352ifneq (,$(wildcard $(LOCAL_PATH)/DynamicConfig.xml)) 353my_compat_dist += \ 354 $(LOCAL_PATH)/DynamicConfig.xml:$(COMPATIBILITY_TESTCASES_OUT_$(LOCAL_COMPATIBILITY_SUITE))/$(LOCAL_MODULE).dynamic 355endif 356 357my_compat_files := $(call copy-many-files, $(my_compat_dist)) 358 359COMPATIBILITY.$(LOCAL_COMPATIBILITY_SUITE).FILES := \ 360 $(COMPATIBILITY.$(LOCAL_COMPATIBILITY_SUITE).FILES) \ 361 $(my_compat_files) 362 363# Copy over the compatibility files when user runs mm/mmm. 364$(my_register_name) : $(my_compat_files) 365endif # LOCAL_COMPATIBILITY_SUITE 366 367########################################################### 368## Register with ALL_MODULES 369########################################################### 370 371ALL_MODULES += $(my_register_name) 372 373# Don't use += on subvars, or else they'll end up being 374# recursively expanded. 375ALL_MODULES.$(my_register_name).CLASS := \ 376 $(ALL_MODULES.$(my_register_name).CLASS) $(LOCAL_MODULE_CLASS) 377ALL_MODULES.$(my_register_name).PATH := \ 378 $(ALL_MODULES.$(my_register_name).PATH) $(LOCAL_PATH) 379ALL_MODULES.$(my_register_name).TAGS := \ 380 $(ALL_MODULES.$(my_register_name).TAGS) $(my_module_tags) 381ALL_MODULES.$(my_register_name).CHECKED := \ 382 $(ALL_MODULES.$(my_register_name).CHECKED) $(my_checked_module) 383ALL_MODULES.$(my_register_name).BUILT := \ 384 $(ALL_MODULES.$(my_register_name).BUILT) $(LOCAL_BUILT_MODULE) 385ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE)) 386ALL_MODULES.$(my_register_name).INSTALLED := \ 387 $(strip $(ALL_MODULES.$(my_register_name).INSTALLED) \ 388 $(LOCAL_INSTALLED_MODULE) $(my_init_rc_installed)) 389ALL_MODULES.$(my_register_name).BUILT_INSTALLED := \ 390 $(strip $(ALL_MODULES.$(my_register_name).BUILT_INSTALLED) \ 391 $(LOCAL_BUILT_MODULE):$(LOCAL_INSTALLED_MODULE) \ 392 $(addprefix $(my_init_rc_src):,$(my_init_rc_installed))) 393endif 394ifdef LOCAL_PICKUP_FILES 395# Files or directories ready to pick up by the build system 396# when $(LOCAL_BUILT_MODULE) is done. 397ALL_MODULES.$(my_register_name).PICKUP_FILES := \ 398 $(ALL_MODULES.$(my_register_name).PICKUP_FILES) $(LOCAL_PICKUP_FILES) 399endif 400my_required_modules := $(LOCAL_REQUIRED_MODULES) \ 401 $(LOCAL_REQUIRED_MODULES_$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) 402ifdef LOCAL_IS_HOST_MODULE 403my_required_modules += $(LOCAL_REQUIRED_MODULES_$($(my_prefix)OS)) 404endif 405ALL_MODULES.$(my_register_name).REQUIRED := \ 406 $(strip $(ALL_MODULES.$(my_register_name).REQUIRED) $(my_required_modules)) 407ALL_MODULES.$(my_register_name).EVENT_LOG_TAGS := \ 408 $(ALL_MODULES.$(my_register_name).EVENT_LOG_TAGS) $(event_log_tags) 409ALL_MODULES.$(my_register_name).MAKEFILE := \ 410 $(ALL_MODULES.$(my_register_name).MAKEFILE) $(LOCAL_MODULE_MAKEFILE) 411ifdef LOCAL_MODULE_OWNER 412ALL_MODULES.$(my_register_name).OWNER := \ 413 $(sort $(ALL_MODULES.$(my_register_name).OWNER) $(LOCAL_MODULE_OWNER)) 414endif 415ifdef LOCAL_2ND_ARCH_VAR_PREFIX 416ALL_MODULES.$(my_register_name).FOR_2ND_ARCH := true 417endif 418ALL_MODULES.$(my_register_name).FOR_HOST_CROSS := $(my_host_cross) 419 420INSTALLABLE_FILES.$(LOCAL_INSTALLED_MODULE).MODULE := $(my_register_name) 421 422########################################################## 423# Track module-level dependencies. 424# Use $(LOCAL_MODULE) instead of $(my_register_name) to ignore module's bitness. 425ALL_DEPS.MODULES := $(sort $(ALL_DEPS.MODULES) $(LOCAL_MODULE)) 426ALL_DEPS.$(LOCAL_MODULE).ALL_DEPS := $(sort \ 427 $(ALL_MODULES.$(LOCAL_MODULE).ALL_DEPS) \ 428 $(LOCAL_STATIC_LIBRARIES) \ 429 $(LOCAL_WHOLE_STATIC_LIBRARIES) \ 430 $(LOCAL_SHARED_LIBRARIES) \ 431 $(LOCAL_STATIC_JAVA_LIBRARIES) \ 432 $(LOCAL_JAVA_LIBRARIES)\ 433 $(LOCAL_JNI_SHARED_LIBRARIES)) 434 435ALL_DEPS.$(LOCAL_MODULE).LICENSE := $(sort $(ALL_DEPS.$(LOCAL_MODULE).LICENSE) $(license_files)) 436 437########################################################### 438## Take care of my_module_tags 439########################################################### 440 441# Keep track of all the tags we've seen. 442ALL_MODULE_TAGS := $(sort $(ALL_MODULE_TAGS) $(my_module_tags)) 443 444# Add this module name to the tag list of each specified tag. 445$(foreach tag,$(my_module_tags),\ 446 $(eval ALL_MODULE_NAME_TAGS.$(tag) += $(my_register_name))) 447 448########################################################### 449## umbrella targets used to verify builds 450########################################################### 451j_or_n := 452ifneq (,$(filter EXECUTABLES SHARED_LIBRARIES STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS))) 453j_or_n := native 454else 455ifneq (,$(filter JAVA_LIBRARIES APPS,$(LOCAL_MODULE_CLASS))) 456j_or_n := java 457endif 458endif 459ifdef LOCAL_IS_HOST_MODULE 460h_or_t := host 461else 462h_or_t := target 463endif 464 465ifdef j_or_n 466$(j_or_n) $(h_or_t) $(j_or_n)-$(h_or_t) : $(my_checked_module) 467ifneq (,$(filter $(my_module_tags),tests)) 468$(j_or_n)-$(h_or_t)-tests $(j_or_n)-tests $(h_or_t)-tests : $(my_checked_module) 469endif 470endif 471 472########################################################### 473## NOTICE files 474########################################################### 475 476include $(BUILD_NOTICE_FILE) 477