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