base_rules.mk revision 447d69678e6ba108a2f9e034c876a8859015fe17
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 my_prefix := HOST_ 38 my_host := host- 39else 40 my_prefix := TARGET_ 41 my_host := 42endif 43 44my_module_tags := $(LOCAL_MODULE_TAGS) 45 46########################################################### 47## Validate and define fallbacks for input LOCAL_* variables. 48########################################################### 49 50## Dump a .csv file of all modules and their tags 51#ifneq ($(tag-list-first-time),false) 52#$(shell rm -f tag-list.csv) 53#tag-list-first-time := false 54#endif 55#$(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) 56 57LOCAL_UNINSTALLABLE_MODULE := $(strip $(LOCAL_UNINSTALLABLE_MODULE)) 58my_module_tags := $(sort $(my_module_tags)) 59ifeq (,$(my_module_tags)) 60 my_module_tags := optional 61endif 62 63# User tags are not allowed anymore. Fail early because it will not be installed 64# like it used to be. 65ifneq ($(filter $(my_module_tags),user),) 66 $(warning *** Module name: $(LOCAL_MODULE)) 67 $(warning *** Makefile location: $(LOCAL_MODULE_MAKEFILE)) 68 $(warning * ) 69 $(warning * Module is attempting to use the 'user' tag. This) 70 $(warning * used to cause the module to be installed automatically.) 71 $(warning * Now, the module must be listed in the PRODUCT_PACKAGES) 72 $(warning * section of a product makefile to have it installed.) 73 $(warning * ) 74 $(error user tag detected on module.) 75endif 76 77# Only the tags mentioned in this test are expected to be set by module 78# makefiles. Anything else is either a typo or a source of unexpected 79# behaviors. 80ifneq ($(filter-out debug eng tests optional samples,$(my_module_tags)),) 81$(warning unusual tags $(my_module_tags) on $(LOCAL_MODULE) at $(LOCAL_PATH)) 82endif 83 84# Add implicit tags. 85# 86# If the local directory or one of its parents contains a MODULE_LICENSE_GPL 87# file, tag the module as "gnu". Search for "*_GPL*", "*_LGPL*" and "*_MPL*" 88# so that we can also find files like MODULE_LICENSE_GPL_AND_AFL 89# 90license_files := $(call find-parent-file,$(LOCAL_PATH),MODULE_LICENSE*) 91gpl_license_file := $(call find-parent-file,$(LOCAL_PATH),MODULE_LICENSE*_GPL* MODULE_LICENSE*_MPL* MODULE_LICENSE*_LGPL*) 92ifneq ($(gpl_license_file),) 93 my_module_tags += gnu 94 ALL_GPL_MODULE_LICENSE_FILES := $(sort $(ALL_GPL_MODULE_LICENSE_FILES) $(gpl_license_file)) 95endif 96 97LOCAL_MODULE_CLASS := $(strip $(LOCAL_MODULE_CLASS)) 98ifneq ($(words $(LOCAL_MODULE_CLASS)),1) 99 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS must contain exactly one word, not "$(LOCAL_MODULE_CLASS)") 100endif 101 102my_32_64_bit_suffix := $(if $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)IS_64_BIT),64,32) 103 104ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE)) 105my_multilib_module_path := $(strip $(LOCAL_MODULE_PATH_$(my_32_64_bit_suffix))) 106ifdef my_multilib_module_path 107my_module_path := $(my_multilib_module_path) 108else 109my_module_path := $(strip $(LOCAL_MODULE_PATH)) 110endif 111my_module_relative_path := $(strip $(LOCAL_MODULE_RELATIVE_PATH)) 112ifeq ($(my_module_path),) 113 ifdef LOCAL_IS_HOST_MODULE 114 partition_tag := 115 else 116 ifeq (true,$(LOCAL_PROPRIETARY_MODULE)) 117 partition_tag := _VENDOR 118 else ifeq (true,$(LOCAL_OEM_MODULE)) 119 partition_tag := _OEM 120 else ifeq (true,$(LOCAL_ODM_MODULE)) 121 partition_tag := _ODM 122 else 123 # The definition of should-install-to-system will be different depending 124 # on which goal (e.g., sdk or just droid) is being built. 125 partition_tag := $(if $(call should-install-to-system,$(my_module_tags)),,_DATA) 126 endif 127 endif 128 install_path_var := $(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT$(partition_tag)_$(LOCAL_MODULE_CLASS) 129 ifeq (true,$(LOCAL_PRIVILEGED_MODULE)) 130 install_path_var := $(install_path_var)_PRIVILEGED 131 endif 132 133 my_module_path := $($(install_path_var)) 134 ifeq ($(strip $(my_module_path)),) 135 $(error $(LOCAL_PATH): unhandled install path "$(install_path_var) for $(LOCAL_MODULE)") 136 endif 137endif 138ifneq ($(my_module_relative_path),) 139 my_module_path := $(my_module_path)/$(my_module_relative_path) 140endif 141endif # not LOCAL_UNINSTALLABLE_MODULE 142 143ifneq ($(strip $(LOCAL_BUILT_MODULE)$(LOCAL_INSTALLED_MODULE)),) 144 $(error $(LOCAL_PATH): LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE must not be defined by component makefiles) 145endif 146 147my_register_name := $(LOCAL_MODULE) 148ifdef LOCAL_2ND_ARCH_VAR_PREFIX 149ifndef LOCAL_NO_2ND_ARCH_MODULE_SUFFIX 150my_register_name := $(LOCAL_MODULE)$($(my_prefix)2ND_ARCH_MODULE_SUFFIX) 151endif 152endif 153# Make sure that this IS_HOST/CLASS/MODULE combination is unique. 154module_id := MODULE.$(if \ 155 $(LOCAL_IS_HOST_MODULE),HOST,TARGET).$(LOCAL_MODULE_CLASS).$(my_register_name) 156ifdef $(module_id) 157$(error $(LOCAL_PATH): $(module_id) already defined by $($(module_id))) 158endif 159$(module_id) := $(LOCAL_PATH) 160 161intermediates := $(call local-intermediates-dir,,$(LOCAL_2ND_ARCH_VAR_PREFIX)) 162intermediates.COMMON := $(call local-intermediates-dir,COMMON) 163generated_sources_dir := $(call local-generated-sources-dir) 164 165########################################################### 166# Pick a name for the intermediate and final targets 167########################################################### 168include $(BUILD_SYSTEM)/configure_module_stem.mk 169 170# OVERRIDE_BUILT_MODULE_PATH is only allowed to be used by the 171# internal SHARED_LIBRARIES build files. 172OVERRIDE_BUILT_MODULE_PATH := $(strip $(OVERRIDE_BUILT_MODULE_PATH)) 173ifdef OVERRIDE_BUILT_MODULE_PATH 174 ifneq ($(LOCAL_MODULE_CLASS),SHARED_LIBRARIES) 175 $(error $(LOCAL_PATH): Illegal use of OVERRIDE_BUILT_MODULE_PATH) 176 endif 177 built_module_path := $(OVERRIDE_BUILT_MODULE_PATH) 178else 179 built_module_path := $(intermediates) 180endif 181LOCAL_BUILT_MODULE := $(built_module_path)/$(my_built_module_stem) 182 183ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE)) 184 # Apk and its attachments reside in its own subdir. 185 ifeq ($(LOCAL_MODULE_CLASS),APPS) 186 # framework-res.apk doesn't like the additional layer. 187 ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true) 188 my_module_path := $(my_module_path)/$(LOCAL_MODULE) 189 endif 190 endif 191 LOCAL_INSTALLED_MODULE := $(my_module_path)/$(my_installed_module_stem) 192endif 193 194# Assemble the list of targets to create PRIVATE_ variables for. 195LOCAL_INTERMEDIATE_TARGETS += $(LOCAL_BUILT_MODULE) 196 197 198########################################################### 199## make clean- targets 200########################################################### 201cleantarget := clean-$(my_register_name) 202$(cleantarget) : PRIVATE_MODULE := $(my_register_name) 203$(cleantarget) : PRIVATE_CLEAN_FILES := \ 204 $(LOCAL_BUILT_MODULE) \ 205 $(LOCAL_INSTALLED_MODULE) \ 206 $(intermediates) 207$(cleantarget):: 208 @echo "Clean: $(PRIVATE_MODULE)" 209 $(hide) rm -rf $(PRIVATE_CLEAN_FILES) 210 211########################################################### 212## Common definitions for module. 213########################################################### 214$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_PATH:=$(LOCAL_PATH) 215$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_IS_HOST_MODULE := $(LOCAL_IS_HOST_MODULE) 216$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_HOST:= $(my_host) 217$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_INTERMEDIATES_DIR:= $(intermediates) 218$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_2ND_ARCH_VAR_PREFIX := $(LOCAL_2ND_ARCH_VAR_PREFIX) 219 220# Tell the module and all of its sub-modules who it is. 221$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_MODULE:= $(my_register_name) 222 223# Provide a short-hand for building this module. 224# We name both BUILT and INSTALLED in case 225# LOCAL_UNINSTALLABLE_MODULE is set. 226.PHONY: $(my_register_name) 227$(my_register_name): $(LOCAL_BUILT_MODULE) $(LOCAL_INSTALLED_MODULE) 228 229########################################################### 230## Module installation rule 231########################################################### 232 233# Some hosts do not have ACP; override the LOCAL version if that's the case. 234ifneq ($(strip $(HOST_ACP_UNAVAILABLE)),) 235 LOCAL_ACP_UNAVAILABLE := $(strip $(HOST_ACP_UNAVAILABLE)) 236endif 237 238ifndef LOCAL_UNINSTALLABLE_MODULE 239 # Define a copy rule to install the module. 240 # acp and libraries that it uses can't use acp for 241 # installation; hence, LOCAL_ACP_UNAVAILABLE. 242$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := $(LOCAL_POST_INSTALL_CMD) 243ifneq ($(LOCAL_ACP_UNAVAILABLE),true) 244$(LOCAL_INSTALLED_MODULE): $(LOCAL_BUILT_MODULE) | $(ACP) 245 @echo "Install: $@" 246 $(copy-file-to-new-target) 247 $(PRIVATE_POST_INSTALL_CMD) 248else 249$(LOCAL_INSTALLED_MODULE): $(LOCAL_BUILT_MODULE) 250 @echo "Install: $@" 251 $(copy-file-to-target-with-cp) 252endif 253 254# Rule to install the module's companion init.rc. 255my_init_rc := $(LOCAL_INIT_RC_$(my_32_64_bit_suffix)) 256my_init_rc_src := 257my_init_rc_installed := 258ifndef my_init_rc 259my_init_rc := $(LOCAL_INIT_RC) 260# Make sure we don't define the rule twice in multilib module. 261LOCAL_INIT_RC := 262endif 263ifdef my_init_rc 264my_init_rc_src := $(LOCAL_PATH)/$(my_init_rc) 265my_init_rc_installed := $(TARGET_OUT$(partition_tag)_ETC)/init/$(notdir $(my_init_rc_src)) 266$(my_init_rc_installed) : $(my_init_rc_src) | $(ACP) 267 @echo "Install: $@" 268 $(copy-file-to-new-target) 269 270$(my_register_name) : $(my_init_rc_installed) 271endif # my_init_rc 272endif # !LOCAL_UNINSTALLABLE_MODULE 273 274########################################################### 275## CHECK_BUILD goals 276########################################################### 277my_checked_module := 278# If nobody has defined a more specific module for the 279# checked modules, use LOCAL_BUILT_MODULE. 280ifdef LOCAL_CHECKED_MODULE 281 my_checked_module := $(LOCAL_CHECKED_MODULE) 282else 283 my_checked_module := $(LOCAL_BUILT_MODULE) 284endif 285 286# If they request that this module not be checked, then don't. 287# PLEASE DON'T SET THIS. ANY PLACES THAT SET THIS WITHOUT 288# GOOD REASON WILL HAVE IT REMOVED. 289ifdef LOCAL_DONT_CHECK_MODULE 290 my_checked_module := 291endif 292# Don't check build target module defined for the 2nd arch 293ifndef LOCAL_IS_HOST_MODULE 294ifdef LOCAL_2ND_ARCH_VAR_PREFIX 295 my_checked_module := 296endif 297endif 298 299########################################################### 300## Register with ALL_MODULES 301########################################################### 302 303ALL_MODULES += $(my_register_name) 304 305# Don't use += on subvars, or else they'll end up being 306# recursively expanded. 307ALL_MODULES.$(my_register_name).CLASS := \ 308 $(ALL_MODULES.$(my_register_name).CLASS) $(LOCAL_MODULE_CLASS) 309ALL_MODULES.$(my_register_name).PATH := \ 310 $(ALL_MODULES.$(my_register_name).PATH) $(LOCAL_PATH) 311ALL_MODULES.$(my_register_name).TAGS := \ 312 $(ALL_MODULES.$(my_register_name).TAGS) $(my_module_tags) 313ALL_MODULES.$(my_register_name).CHECKED := \ 314 $(ALL_MODULES.$(my_register_name).CHECKED) $(my_checked_module) 315ALL_MODULES.$(my_register_name).BUILT := \ 316 $(ALL_MODULES.$(my_register_name).BUILT) $(LOCAL_BUILT_MODULE) 317ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE)) 318ALL_MODULES.$(my_register_name).INSTALLED := \ 319 $(strip $(ALL_MODULES.$(my_register_name).INSTALLED) \ 320 $(LOCAL_INSTALLED_MODULE) $(my_init_rc_installed)) 321ALL_MODULES.$(my_register_name).BUILT_INSTALLED := \ 322 $(strip $(ALL_MODULES.$(my_register_name).BUILT_INSTALLED) \ 323 $(LOCAL_BUILT_MODULE):$(LOCAL_INSTALLED_MODULE) \ 324 $(addprefix $(my_init_rc_src):,$(my_init_rc_installed))) 325endif 326ifdef LOCAL_PICKUP_FILES 327# Files or directories ready to pick up by the build system 328# when $(LOCAL_BUILT_MODULE) is done. 329ALL_MODULES.$(my_register_name).PICKUP_FILES := \ 330 $(ALL_MODULES.$(my_register_name).PICKUP_FILES) $(LOCAL_PICKUP_FILES) 331endif 332my_required_modules := $(LOCAL_REQUIRED_MODULES) \ 333 $(LOCAL_REQUIRED_MODULES_$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) 334ifdef LOCAL_IS_HOST_MODULE 335my_required_modules += $(LOCAL_REQUIRED_MODULES_$($(my_prefix)OS)) 336endif 337ALL_MODULES.$(my_register_name).REQUIRED := \ 338 $(strip $(ALL_MODULES.$(my_register_name).REQUIRED) $(my_required_modules)) 339ALL_MODULES.$(my_register_name).MAKEFILE := \ 340 $(ALL_MODULES.$(my_register_name).MAKEFILE) $(LOCAL_MODULE_MAKEFILE) 341ifdef LOCAL_MODULE_OWNER 342ALL_MODULES.$(my_register_name).OWNER := \ 343 $(sort $(ALL_MODULES.$(my_register_name).OWNER) $(LOCAL_MODULE_OWNER)) 344endif 345ifdef LOCAL_2ND_ARCH_VAR_PREFIX 346ALL_MODULES.$(my_register_name).FOR_2ND_ARCH := true 347endif 348 349INSTALLABLE_FILES.$(LOCAL_INSTALLED_MODULE).MODULE := $(my_register_name) 350 351########################################################## 352# Track module-level dependencies. 353# Use $(LOCAL_MODULE) instead of $(my_register_name) to ignore module's bitness. 354ALL_DEPS.MODULES := $(sort $(ALL_DEPS.MODULES) $(LOCAL_MODULE)) 355ALL_DEPS.$(LOCAL_MODULE).ALL_DEPS := $(sort \ 356 $(ALL_MODULES.$(LOCAL_MODULE).ALL_DEPS) \ 357 $(LOCAL_STATIC_LIBRARIES) \ 358 $(LOCAL_WHOLE_STATIC_LIBRARIES) \ 359 $(LOCAL_SHARED_LIBRARIES) \ 360 $(LOCAL_STATIC_JAVA_LIBRARIES) \ 361 $(LOCAL_JAVA_LIBRARIES)\ 362 $(LOCAL_JNI_SHARED_LIBRARIES)) 363 364ALL_DEPS.$(LOCAL_MODULE).LICENSE := $(sort $(ALL_DEPS.$(LOCAL_MODULE).LICENSE) $(license_files)) 365 366########################################################### 367## Take care of my_module_tags 368########################################################### 369 370# Keep track of all the tags we've seen. 371ALL_MODULE_TAGS := $(sort $(ALL_MODULE_TAGS) $(my_module_tags)) 372 373# Add this module name to the tag list of each specified tag. 374$(foreach tag,$(my_module_tags),\ 375 $(eval ALL_MODULE_NAME_TAGS.$(tag) += $(my_register_name))) 376 377########################################################### 378## umbrella targets used to verify builds 379########################################################### 380j_or_n := 381ifneq (,$(filter EXECUTABLES SHARED_LIBRARIES STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS))) 382j_or_n := native 383else 384ifneq (,$(filter JAVA_LIBRARIES APPS,$(LOCAL_MODULE_CLASS))) 385j_or_n := java 386endif 387endif 388ifdef LOCAL_IS_HOST_MODULE 389h_or_t := host 390else 391h_or_t := target 392endif 393 394ifdef j_or_n 395$(j_or_n) $(h_or_t) $(j_or_n)-$(h_or_t) : $(my_checked_module) 396ifneq (,$(filter $(my_module_tags),tests)) 397$(j_or_n)-$(h_or_t)-tests $(j_or_n)-tests $(h_or_t)-tests : $(my_checked_module) 398endif 399endif 400 401########################################################### 402## NOTICE files 403########################################################### 404 405include $(BUILD_NOTICE_FILE) 406