# # Copyright (C) 2008 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. #
## ## Common build system definitions. Mostly standard ## commands for building various types of targets, which ## are used by others to construct the final targets. ##
# These are variables we use to collect overall lists # of things being processed.
# Full paths to all of the documentation
ALL_DOCS:=
# The short names of all of the targets in the system. # For each element of ALL_MODULES, two other variables # are defined: # $(ALL_MODULES.$(target)).BUILT # $(ALL_MODULES.$(target)).INSTALLED # The BUILT variable contains LOCAL_BUILT_MODULE for that # target, and the INSTALLED variable contains the LOCAL_INSTALLED_MODULE. # Some targets may have multiple files listed in the BUILT and INSTALLED # sub-variables.
ALL_MODULES:=
ALL_MAKE_MODULE_INFO_JSON_MODULES:=
# The relative paths of the non-module targets in the system.
ALL_NON_MODULES:=
NON_MODULES_WITHOUT_LICENSE_METADATA:=
# List of copied targets that need license metadata copied.
ALL_COPIED_TARGETS:=
# Full paths to targets that should be added to the "make droid" # set of installed targets.
ALL_DEFAULT_INSTALLED_MODULES:=
# Full path to all asm, C, C++, lex and yacc generated C files. # These all have an order-only dependency on the copied headers
ALL_C_CPP_ETC_OBJECTS:=
# These files go into the SDK
ALL_SDK_FILES:=
# Files for dalvik. This is often build without building the rest of the OS.
INTERNAL_DALVIK_MODULES:=
# Packages with certificate violation
CERTIFICATE_VIOLATION_MODULES :=
# Target and host installed module's dependencies on shared libraries. # They are list of "<module_name>:<installed_file>:lib1,lib2...".
TARGET_DEPENDENCIES_ON_SHARED_LIBRARIES :=
$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_DEPENDENCIES_ON_SHARED_LIBRARIES :=
HOST_DEPENDENCIES_ON_SHARED_LIBRARIES :=
$(HOST_2ND_ARCH_VAR_PREFIX)HOST_DEPENDENCIES_ON_SHARED_LIBRARIES :=
HOST_CROSS_DEPENDENCIES_ON_SHARED_LIBRARIES :=
$(HOST_CROSS_2ND_ARCH_VAR_PREFIX)HOST_CROSS_DEPENDENCIES_ON_SHARED_LIBRARIES :=
# Generated class file names for Android resource. # They are escaped and quoted so can be passed safely to a bash command.
ANDROID_RESOURCE_GENERATED_CLASSES := 'R.class''R$$*.class''Manifest.class''Manifest$$*.class'
# Display names for various build targets
TARGET_DISPLAY := target
HOST_DISPLAY := host
HOST_CROSS_DISPLAY := host cross
# All installed initrc files
ALL_INIT_RC_INSTALLED_PAIRS :=
# All installed vintf manifest fragments for a partition at
ALL_VINTF_MANIFEST_FRAGMENTS_LIST:=
# All compatibility suites mentioned in LOCAL_COMPATIBILITY_SUITE
ALL_COMPATIBILITY_SUITES :=
# All compatibility suite files to dist.
ALL_COMPATIBILITY_DIST_FILES :=
# All LINK_TYPE entries
ALL_LINK_TYPES :=
# All exported/imported include entries
EXPORTS_LIST :=
# All modules already converted to Soong
SOONG_ALREADY_CONV :=
########################################################### ## Debugging; prints a variable list to stdout ###########################################################
########################################################### ## Evaluates to true if the string contains the word true, ## and empty otherwise ## $(1): a var to test ###########################################################
########################################################### ## Retrieve the directory of the current makefile ## Must be called before including any other makefile!! ###########################################################
# Figure out where we are. define my-dir
$(strip \
$(eval LOCAL_MODULE_MAKEFILE := $$(lastword $$(MAKEFILE_LIST))) \
$(if $(filter $(BUILD_SYSTEM)/% $(OUT_DIR)/%,$(LOCAL_MODULE_MAKEFILE)), \
$(error my-dir must be called before including any other makefile.) \
, \
$(patsubst %/,%,$(dir $(LOCAL_MODULE_MAKEFILE))) \
) \
) endef
########################################################### ## Retrieve a list of all makefiles immediately below some directory ###########################################################
########################################################### ## Look under a directory for makefiles that don't have parent ## makefiles. ###########################################################
# $(1): directory to search under # Ignores $(1)/Android.mk define first-makefiles-under
$(shell build/make/tools/findleaves.py $(FIND_LEAVES_EXCLUDES) \
--mindepth=2 $(addprefix --dir=,$(1)) Android.mk) endef
########################################################### ## Retrieve a list of all makefiles immediately below your directory ## Must be called before including any other makefile!! ###########################################################
########################################################### ## Look in the named list of directories for makefiles, ## relative to the current directory. ## Must be called before including any other makefile!! ###########################################################
# $(1): List of directories to look for under this directory defineall-named-subdir-makefiles
$(wildcard $(addsuffix /Android.mk, $(addprefix $(call my-dir)/,$(1)))) endef
########################################################### ## Find all of the directories under the named directories with ## the specified name. ## Meant to be used like: ## INC_DIRS := $(call all-named-dirs-under,inc,.) ###########################################################
defineall-named-dirs-under
$(call find-subdir-files,$(2) -type d -name "$(1)") endef
########################################################### ## Find all the directories under the current directory that ## haves name that match $(1) ###########################################################
########################################################### ## Find all of the files under the named directories with ## the specified name. ## Meant to be used like: ## SRC_FILES := $(call all-named-files-under,*.h,src tests) ###########################################################
########################################################### ## Find all of the files under the current directory with ## the specified name. ###########################################################
########################################################### ## Find all of the java files under the named directories. ## Meant to be used like: ## SRC_FILES := $(call all-java-files-under,src tests) ###########################################################
########################################################### ## Find all of the java files from here. Meant to be used like: ## SRC_FILES := $(call all-subdir-java-files) ###########################################################
########################################################### ## Find all of the c files under the named directories. ## Meant to be used like: ## SRC_FILES := $(call all-c-files-under,src tests) ###########################################################
########################################################### ## Find all of the c files from here. Meant to be used like: ## SRC_FILES := $(call all-subdir-c-files) ###########################################################
########################################################### ## Find all of the cpp files under the named directories. ## LOCAL_CPP_EXTENSION is respected if set. ## Meant to be used like: ## SRC_FILES := $(call all-cpp-files-under,src tests) ###########################################################
########################################################### ## Find all of the cpp files from here. Meant to be used like: ## SRC_FILES := $(call all-subdir-cpp-files) ###########################################################
########################################################### ## Find all files named "I*.aidl" under the named directories, ## which must be relative to $(LOCAL_PATH). The returned list ## is relative to $(LOCAL_PATH). ###########################################################
########################################################### ## Find all of the "I*.aidl" files under $(LOCAL_PATH). ###########################################################
########################################################### ## Find all files named "*.vts" under the named directories, ## which must be relative to $(LOCAL_PATH). The returned list ## is relative to $(LOCAL_PATH). ###########################################################
########################################################### ## Find all of the "*.vts" files under $(LOCAL_PATH). ###########################################################
########################################################### ## Find all of the logtags files under the named directories. ## Meant to be used like: ## SRC_FILES := $(call all-logtags-files-under,src) ###########################################################
########################################################### ## Find all of the .proto files under the named directories. ## Meant to be used like: ## SRC_FILES := $(call all-proto-files-under,src) ###########################################################
########################################################### ## Find all of the RenderScript files under the named directories. ## Meant to be used like: ## SRC_FILES := $(call all-renderscript-files-under,src) ###########################################################
########################################################### ## Find all of the S files under the named directories. ## Meant to be used like: ## SRC_FILES := $(call all-c-files-under,src tests) ###########################################################
########################################################### ## Find all of the html files under the named directories. ## Meant to be used like: ## SRC_FILES := $(call all-html-files-under,src tests) ###########################################################
########################################################### ## Find all of the html files from here. Meant to be used like: ## SRC_FILES := $(call all-subdir-html-files) ###########################################################
########################################################### ## Find all of the files matching pattern ## SRC_FILES := $(call all-subdir-java-files) ###########################################################
define find-subdir-assets
$(sort $(if $(1),$(patsubst ./%,%, \
$(shell if [ -d $(1) ] ; then cd $(1) ; find -L ./ -not -name '.*' -and -type f ; fi)), \
$(warning Empty argument supplied to find-subdir-assets in $(LOCAL_PATH)) \
)) endef
########################################################### ## Find various file types in a list of directories relative to $(LOCAL_PATH) ###########################################################
########################################################### # Use utility find to find given files in the given subdirs. # This function uses $(1), instead of LOCAL_PATH as the base. # $(1): the base dir, relative to the root of the source tree. # $(2): the file name pattern to be passed to find as "-name". # $(3): a list of subdirs of the base dir. # Returns: a list of paths relative to the base dir. ###########################################################
########################################################### ## Scan through each directory of $(1) looking for files ## that match $(2) using $(wildcard). Useful for seeing if ## a given directory or one of its parents contains ## a particular file. Returns the first match found, ## starting furthest from the root. ###########################################################
########################################################### ## Find test data in a form required by LOCAL_TEST_DATA ## $(1): the base dir, relative to the root of the source tree. ## $(2): the file name pattern to be passed to find as "-name" ## $(3): a list of subdirs of the base dir ###########################################################
########################################################### ## Function we can evaluate to introduce a dynamic dependency ###########################################################
define add-dependency
$(1): $(2) endef
########################################################### ## Reverse order of a list ###########################################################
########################################################### ## Sometimes a notice dependency will reference an unadorned ## module name that only appears in ALL_MODULES adorned with ## an ARCH suffix or a `host_cross_` prefix. ## ## After all of the modules are processed in base_rules.mk, ## replace all such dependencies with every matching adorned ## module name. ###########################################################
########################################################### ## Declares the rule to report targets with no license metadata. ########################################################### define report-missing-licenses-rule
.PHONY: reportmissinglicenses
reportmissinglicenses: PRIVATE_NON_MODULES:=$(sort $(NON_MODULES_WITHOUT_LICENSE_METADATA) $(TARGETS_MISSING_LICENSE_METADATA))
reportmissinglicenses: PRIVATE_COPIED_FILES:=$(sort $(filter $(NON_MODULES_WITHOUT_LICENSE_METADATA) $(TARGETS_MISSING_LICENSE_METADATA),\
$(foreach _pair,$(PRODUCT_COPY_FILES), $(PRODUCT_OUT)/$(call word-colon,2,$(_pair)))))
reportmissinglicenses:
@echo Reporting $$(words $$(PRIVATE_NON_MODULES)) targets without license metadata
$$(foreach t,$$(PRIVATE_NON_MODULES),if ! [ -h $$(t) ]; thenecho No license metadata for $$(t) >&2; fi;)
$$(foreach t,$$(PRIVATE_COPIED_FILES),if ! [ -h $$(t) ]; thenecho No license metadata for copied file $$(t) >&2; fi;) echo $$(words $$(PRIVATE_NON_MODULES)) targets missing license metadata >&2
endef
########################################################### # Returns the unique list of built license metadata files. ########################################################### defineall-license-metadata
$(sort \
$(foreach t,$(ALL_NON_MODULES),$(if $(filter 0p,$(ALL_TARGETS.$(t).META_LIC)),, $(ALL_TARGETS.$(t).META_LIC))) \
$(foreach m,$(ALL_MODULES), $(ALL_MODULES.$(m).META_LIC)) \
) endef
########################################################### # Declares the rule to report all library names used in any notice files. ########################################################### define report-all-notice-library-names-rule
$(strip $(eval _all := $(callall-license-metadata)))
.PHONY: reportallnoticelibrarynames
reportallnoticelibrarynames: PRIVATE_LIST_FILE := $(call license-metadata-dir,COMMON)/filelist
reportallnoticelibrarynames: | $(COMPLIANCENOTICE_SHIPPEDLIBS)
reportallnoticelibrarynames: $(_all)
@echo Reporting notice library names for at least $$(words $(_all)) license metadata files
$(hide) rm -f $$(PRIVATE_LIST_FILE)
$(hide) mkdir -p $$(dir $$(PRIVATE_LIST_FILE))
$(hide) find out -name '*meta_lic' -type f -printf '"%p"\n' >$$(PRIVATE_LIST_FILE)
OUT_DIR=$(OUT_DIR) $(COMPLIANCENOTICE_SHIPPEDLIBS) @$$(PRIVATE_LIST_FILE) endef
########################################################### # Declares the rule to build all license metadata. ########################################################### define build-all-license-metadata-rule
$(strip $(eval _all := $(callall-license-metadata)))
.PHONY: alllicensemetadata
alllicensemetadata: $(_all)
@echo Building all $(words $(_all)) license metadata files endef
########################################################### ## Returns correct _idfPrefix from the list: ## { HOST, HOST_CROSS, TARGET } ########################################################### # the following rules checked in order: # ($1 is in {HOST_CROSS} => $1; # ($1 is empty) => TARGET; # ($2 is not empty) => HOST_CROSS; # => HOST; define find-idf-prefix
$(strip \
$(eval _idf_pfx_:=$(strip $(filter HOST_CROSS,$(1)))) \
$(eval _idf_pfx_:=$(if $(strip $(1)),$(if $(_idf_pfx_),$(_idf_pfx_),$(if $(strip $(2)),HOST_CROSS,HOST)),TARGET)) \
$(_idf_pfx_)
) endef
########################################################### ## The intermediates directory. Where object files go for ## a given target. We could technically get away without ## the "_intermediates" suffix on the directory, but it's ## nice to be able to grep for that string to find out if ## anyone's abusing the system. ###########################################################
# $(1): target class, like "APPS" # $(2): target name, like "NotePad" # $(3): { HOST, HOST_CROSS, <empty (TARGET)>, <other non-empty (HOST)> } # $(4): if non-empty, force the intermediates to be COMMON # $(5): if non-empty, force the intermediates to be for the 2nd arch # $(6): if non-empty, force the intermediates to be for the host cross os define intermediates-dir-for
$(strip \
$(eval _idfClass := $(strip $(1))) \
$(if $(_idfClass),, \
$(error $(LOCAL_PATH): Class not defined in call to intermediates-dir-for)) \
$(eval _idfName := $(strip $(2))) \
$(if $(_idfName),, \
$(error $(LOCAL_PATH): Name not defined in call to intermediates-dir-for)) \
$(eval _idfPrefix := $(call find-idf-prefix,$(3),$(6))) \
$(eval _idf2ndArchPrefix := $(if $(strip $(5)),$(TARGET_2ND_ARCH_VAR_PREFIX))) \
$(if $(filter $(_idfPrefix)_$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
$(eval _idfIntBase := $($(_idfPrefix)_OUT_COMMON_INTERMEDIATES)) \
,$(if $(filter $(_idfClass),$(PER_ARCH_MODULE_CLASSES)),\
$(eval _idfIntBase := $($(_idf2ndArchPrefix)$(_idfPrefix)_OUT_INTERMEDIATES)) \
,$(eval _idfIntBase := $($(_idfPrefix)_OUT_INTERMEDIATES)) \
) \
) \
$(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
) endef
# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE # to determine the intermediates directory. # # $(1): if non-empty, force the intermediates to be COMMON # $(2): if non-empty, force the intermediates to be for the 2nd arch # $(3): if non-empty, force the intermediates to be for the host cross os define local-intermediates-dir
$(strip \
$(if $(strip $(LOCAL_MODULE_CLASS)),, \
$(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-intermediates-dir)) \
$(if $(strip $(LOCAL_MODULE)),, \
$(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-intermediates-dir)) \
$(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(if $(strip $(LOCAL_IS_HOST_MODULE)),HOST),$(1),$(2),$(3)) \
) endef
# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE # to determine the intermediates directory. # # $(1): if non-empty, force the intermediates to be COMMON # $(2): if non-empty, force the intermediates to be for the 2nd arch # $(3): if non-empty, force the intermediates to be for the host cross os define local-meta-intermediates-dir
$(strip \
$(if $(strip $(LOCAL_MODULE_CLASS)),, \
$(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-meta-intermediates-dir)) \
$(if $(strip $(LOCAL_MODULE)),, \
$(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-meta-intermediates-dir)) \
$(call intermediates-dir-for,META$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(if $(strip $(LOCAL_IS_HOST_MODULE)),HOST),$(1),$(2),$(3)) \
) endef
########################################################### ## The generated sources directory. Placing generated ## source files directly in the intermediates directory ## causes problems for multiarch builds, where there are ## two intermediates directories for a single target. Put ## them in a separate directory, and they will be copied to ## each intermediates directory automatically. ###########################################################
# $(1): target class, like "APPS" # $(2): target name, like "NotePad" # $(3): { HOST, HOST_CROSS, <empty (TARGET)>, <other non-empty (HOST)> } # $(4): if non-empty, force the generated sources to be COMMON define generated-sources-dir-for
$(strip \
$(eval _idfClass := $(strip $(1))) \
$(if $(_idfClass),, \
$(error $(LOCAL_PATH): Class not defined in call to generated-sources-dir-for)) \
$(eval _idfName := $(strip $(2))) \
$(if $(_idfName),, \
$(error $(LOCAL_PATH): Name not defined in call to generated-sources-dir-for)) \
$(eval _idfPrefix := $(call find-idf-prefix,$(3),)) \
$(if $(filter $(_idfPrefix)_$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
$(eval _idfIntBase := $($(_idfPrefix)_OUT_COMMON_GEN)) \
, \
$(eval _idfIntBase := $($(_idfPrefix)_OUT_GEN)) \
) \
$(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
) endef
# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE # to determine the generated sources directory. # # $(1): if non-empty, force the intermediates to be COMMON define local-generated-sources-dir
$(strip \
$(if $(strip $(LOCAL_MODULE_CLASS)),, \
$(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-generated-sources-dir)) \
$(if $(strip $(LOCAL_MODULE)),, \
$(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-generated-sources-dir)) \
$(call generated-sources-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(if $(strip $(LOCAL_IS_HOST_MODULE)),HOST),$(1)) \
) endef
########################################################### ## The packaging directory for a module. Similar to intermedates, but ## in a location that will be wiped by an m installclean. ###########################################################
# $(1): subdir in PACKAGING # $(2): target class, like "APPS" # $(3): target name, like "NotePad" # $(4): { HOST, HOST_CROSS, <empty (TARGET)>, <other non-empty (HOST)> } define packaging-dir-for
$(strip \
$(eval _pdfClass := $(strip $(2))) \
$(if $(_pdfClass),, \
$(error $(LOCAL_PATH): Class not defined in call to generated-sources-dir-for)) \
$(eval _pdfName := $(strip $(3))) \
$(if $(_pdfName),, \
$(error $(LOCAL_PATH): Name not defined in call to generated-sources-dir-for)) \
$(call intermediates-dir-for,PACKAGING,$(1),$(4))/$(_pdfClass)/$(_pdfName)_intermediates \
) endef
# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE # to determine the packaging directory. # # $(1): subdir in PACKAGING define local-packaging-dir
$(strip \
$(if $(strip $(LOCAL_MODULE_CLASS)),, \
$(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-generated-sources-dir)) \
$(if $(strip $(LOCAL_MODULE)),, \
$(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-generated-sources-dir)) \
$(call packaging-dir-for,$(1),$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(if $(strip $(LOCAL_IS_HOST_MODULE)),HOST)) \
) endef
########################################################### ## Convert a list of short module names (e.g., "framework", "Browser") ## into the list of files that are built for those modules. ## NOTE: this won't return reliable results until after all ## sub-makefiles have been included. ## $(1): target list ###########################################################
########################################################### ## Convert a list of short modules names (e.g., "framework", "Browser") ## into the list of files that are installed for those modules. ## NOTE: this won't return reliable results until after all ## sub-makefiles have been included. ## $(1): target list ###########################################################
########################################################### ## Convert a list of short modules names (e.g., "framework", "Browser") ## into the list of files that are built *for the target* for those modules. ## NOTE: this won't return reliable results until after all ## sub-makefiles have been included. ## $(1): target list ###########################################################
########################################################### ## Convert a list of short modules names (e.g., "framework", "Browser") ## into the list of files that should be used when linking ## against that module as a public API. ## TODO: Allow this for more than JAVA_LIBRARIES modules ## NOTE: this won't return reliable results until after all ## sub-makefiles have been included. ## $(1): target list ###########################################################
########################################################### ## Evaluates to the timestamp file for a doc module, which ## is the dependency that should be used. ## $(1): doc module ###########################################################
########################################################### ## Convert "core ext framework" to "out/.../javalib.jar ..." ## $(1): library list ## $(2): Non-empty if IS_HOST_MODULE ###########################################################
# Get the jar files (you can pass to "javac -classpath") of static or shared # Java libraries that you want to link against. # $(1): library name list # $(2): Non-empty if IS_HOST_MODULE define java-lib-files
$(foreach lib,$(1),$(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),$(2),COMMON)/classes.jar) endef
# Get the header jar files (you can pass to "javac -classpath") of static or shared # Java libraries that you want to link against. # $(1): library name list # $(2): Non-empty if IS_HOST_MODULE ifneq ($(TURBINE_ENABLED),false) define java-lib-header-files
$(foreach lib,$(1),$(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),$(2),COMMON)/classes-header.jar) endef else define java-lib-header-files
$(call java-lib-files,$(1),$(2)) endef endif
# Get the dependency files (you can put on the right side of "|" of a build rule) # of the Java libraries. # $(1): library name list # $(2): Non-empty if IS_HOST_MODULE # Historically for target Java libraries we used a different file (javalib.jar) # as the dependency. # Now we can use classes.jar as dependency, so java-lib-deps is the same # as java-lib-files. define java-lib-deps
$(call java-lib-files,$(1),$(2)) endef
# Get the jar files (you can pass to "javac -classpath") of static or shared # APK libraries that you want to link against. # $(1): library name list define app-lib-files
$(foreach lib,$(1),$(call intermediates-dir-for,APPS,$(lib),,COMMON)/classes.jar) endef
# Get the header jar files (you can pass to "javac -classpath") of static or shared # APK libraries that you want to link against. # $(1): library name list ifneq ($(TURBINE_ENABLED),false) define app-lib-header-files
$(foreach lib,$(1),$(call intermediates-dir-for,APPS,$(lib),,COMMON)/classes-header.jar) endef else define app-lib-header-files
$(call app-lib-files,$(1)) endef endif
# Get the exported-sdk-libs files which collectively give you the list of exported java sdk # lib names that are (transitively) exported from the given set of java libs # $(1): library name list define exported-sdk-libs-files
$(foreach lib,$(1),$(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,COMMON)/exported-sdk-libs) endef
########################################################### ## Append a leaf to a base path. Properly deals with ## base paths ending in /. ## ## $(1): base path ## $(2): leaf path ###########################################################
define append-path
$(subst //,/,$(1)/$(2)) endef
########################################################### ## Color-coded warnings and errors ## Use echo-(warning|error) in a build rule ## Use pretty-(warning|error) instead of $(warning)/$(error) ###########################################################
ESC_BOLD := \033[1m
ESC_WARNING := \033[35m
ESC_ERROR := \033[31m
ESC_RESET := \033[0m
# $(1): path (and optionally line) information # $(2): message to print defineecho-warning echo -e "$(ESC_BOLD)$(1): $(ESC_WARNING)warning:$(ESC_RESET)$(ESC_BOLD)"'$(subst ','\'',$(2))'"$(ESC_RESET)" >&2 endef
# $(1): path (and optionally line) information # $(2): message to print defineecho-error echo -e "$(ESC_BOLD)$(1): $(ESC_ERROR)error:$(ESC_RESET)$(ESC_BOLD)"'$(subst ','\'',$(2))'"$(ESC_RESET)" >&2 endef
########################################################### ## Commands for including the dependency files the compiler generates ########################################################### # $(1): the .P file # $(2): the main build target defineinclude-depfile
$(eval $(2) : .KATI_DEPFILE := $1) endef
########################################################### ## Track source files compiled to objects ########################################################### # $(1): list of sources # $(2): list of matching objects define track-src-file-obj
$(eval $(call _track-src-file-obj,$(1))) endef define _track-src-file-obj
i := w
$(foreach s,$(1),
my_tracked_src_files += $(s)
my_src_file_obj_$(s) := $$(word $$(words $$(i)),$$(2))
i += w) endef
# $(1): list of sources # $(2): list of matching generated sources define track-src-file-gen
$(eval $(call _track-src-file-gen,$(2))) endef define _track-src-file-gen
i := w
$(foreach s,$(1),
my_tracked_gen_files += $(s)
my_src_file_gen_$(s) := $$(word $$(words $$(i)),$$(1))
i += w) endef
# $(1): list of generated sources # $(2): list of matching objects define track-gen-file-obj
$(call track-src-file-obj,$(foreach f,$(1),\
$(or $(my_src_file_gen_$(f)),$(f))),$(2)) endef
########################################################### ## Commands for running lex ###########################################################
########################################################### ## Commands to compile RenderScript to Java ###########################################################
## Merge multiple .d files generated by llvm-rs-cc. This is necessary ## because ninja can handle only a single depfile per build target. ## .d files generated by llvm-rs-cc define .stamp, .bc, and optionally ## .java as build targets. However, there's no way to let ninja know ## dependencies to .bc files and .java files, so we give up build ## targets for them. As we write the .stamp file as the target by ## ourselves, the awk script removes the first lines before the colon ## and append a backslash to the last line to concatenate contents of ## multiple files. # $(1): .d files to be merged # $(2): merged .d file define _merge-renderscript-d
$(hide) echo'$@: $(backslash)' > $2
$(foreach d,$1, \
$(hide) awk 'start { sub(/( \\)?$$/, " \\"); print } /:/ { start=1 }' < $d >> $2$(newline))
$(hide) echo >> $2 endef
########################################################### ## Commands to compile RenderScript to C++ ###########################################################
## Given a .aidl file path, generate the rule to compile it a .java file # $(1): a .aidl source file # $(2): a directory to place the generated .java files in # $(3): name of a variable to add the path to the generated source file to # # You must call this with $(eval). definedefine-aidl-java-rule
define_aidl_java_rule_src := $(patsubst %.aidl,%.java,$(subst ../,dotdot/,$(addprefix $(2)/,$(1))))
$$(define_aidl_java_rule_src) : $(callclean-path,$(LOCAL_PATH)/$(1)) $(AIDL)
$$(transform-aidl-to-java)
$(3) += $$(define_aidl_java_rule_src) endef
## Given a .aidl file path generate the rule to compile it a .cpp file. # $(1): a .aidl source file # $(2): a directory to place the generated .cpp files in # $(3): name of a variable to add the path to the generated source file to # # You must call this with $(eval). definedefine-aidl-cpp-rule
define_aidl_cpp_rule_src := $(patsubst %.aidl,%$(LOCAL_CPP_EXTENSION),$(subst ../,dotdot/,$(addprefix $(2)/,$(1))))
$$(define_aidl_cpp_rule_src) : $(callclean-path,$(LOCAL_PATH)/$(1)) $(AIDL_CPP)
$$(transform-aidl-to-cpp)
$(3) += $$(define_aidl_cpp_rule_src) endef
########################################################### ## Commands for running vts ###########################################################
## Given a .vts file path generate the rule to compile it a .cpp file. # $(1): a .vts source file # $(2): a directory to place the generated .cpp files in # $(3): name of a variable to add the path to the generated source file to # # You must call this with $(eval). definedefine-vts-cpp-rule
define_vts_cpp_rule_src := $(patsubst %.vts,%$(LOCAL_CPP_EXTENSION),$(subst ../,dotdot/,$(addprefix $(2)/,$(1))))
$$(define_vts_cpp_rule_src) : $(LOCAL_PATH)/$(1) $(VTSC)
$$(transform-vts-to-cpp)
$(3) += $$(define_vts_cpp_rule_src) endef
########################################################### ## Commands for running java-event-log-tags.py ###########################################################
########################################################### ## Commands for running protoc to compile .proto into .java ###########################################################
###################################################################### ## Commands for running protoc to compile .proto into .pb.cc (or.pb.c) and .pb.h ######################################################################
define transform-proto-to-cc
@echo"Protoc: $@ <= $<"
@mkdir -p $(dir $@)
$(hide) \
$(PROTOC) \
$(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
$(PRIVATE_PROTOC_FLAGS) \
$<
@# aprotoc outputs only .cc. Rename it to .cpp if necessary.
$(if $(PRIVATE_RENAME_CPP_EXT),\
$(hide) mv $(basename $@).cc $@) endef
########################################################### ## Helper to set include paths form transform-*-to-o ########################################################### define c-includes
$(addprefix -I , $(PRIVATE_C_INCLUDES)) \
$(foreach i,$(PRIVATE_IMPORTED_INCLUDES),$(EXPORTS.$(i)))\
$(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),,\
$(addprefix -I ,\
$(filter-out $(PRIVATE_C_INCLUDES), \
$(PRIVATE_GLOBAL_C_INCLUDES))) \
$(addprefix -isystem ,\
$(filter-out $(PRIVATE_C_INCLUDES), \
$(PRIVATE_GLOBAL_C_SYSTEM_INCLUDES)))) endef
########################################################### ## Commands for running gcc to compile a C++ file ###########################################################
# PATH_TO_CLANG_TIDY is defined in build/soong definecall-clang-tidy
$(PATH_TO_CLANG_TIDY) \
$(PRIVATE_TIDY_FLAGS) \
-checks=$(PRIVATE_TIDY_CHECKS) endef
########################################################### ## Commands for running gcc to compile a C file ###########################################################
########################################################### ## Commands for running gcc to compile an Objective-C file ## This should never happen for target builds but this ## will error at build time. ###########################################################
########################################################### ## Commands for running gcc to compile a host C++ file ###########################################################
########################################################### ## Commands for running gcc to compile a host C file ###########################################################
########################################################### ## Commands for running gcc to compile a host Objective-C file ###########################################################
########################################################### ## Commands for running gcc to compile a host Objective-C++ file ###########################################################
########################################################### ## Rules to compile a single C/C++ source with ../ in the path ########################################################### # Replace "../" in object paths with $(DOTDOT_REPLACEMENT).
DOTDOT_REPLACEMENT := dotdot/
## Rule to compile a C++ source file with ../ in the path. ## Must be called with $(eval). # $(1): the C++ source file in LOCAL_SRC_FILES. # $(2): the additional dependencies. # $(3): the variable name to collect the output object file. # $(4): the ninja pool to use for the rule define compile-dotdot-cpp-file
o := $(intermediates)/$(patsubst %$(LOCAL_CPP_EXTENSION),%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
$$(o) : .KATI_NINJA_POOL := $(4)
$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2) $(CLANG_CXX)
$$(transform-$$(PRIVATE_HOST)cpp-to-o)
$$(callinclude-depfiles-for-objs, $$(o))
$(3) += $$(o) endef
## Rule to compile a C source file with ../ in the path. ## Must be called with $(eval). # $(1): the C source file in LOCAL_SRC_FILES. # $(2): the additional dependencies. # $(3): the variable name to collect the output object file. # $(4): the ninja pool to use for the rule define compile-dotdot-c-file
o := $(intermediates)/$(patsubst %.c,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
$$(o) : .KATI_NINJA_POOL := $(4)
$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2) $(CLANG)
$$(transform-$$(PRIVATE_HOST)c-to-o)
$$(callinclude-depfiles-for-objs, $$(o))
$(3) += $$(o) endef
## Rule to compile a .S source file with ../ in the path. ## Must be called with $(eval). # $(1): the .S source file in LOCAL_SRC_FILES. # $(2): the additional dependencies. # $(3): the variable name to collect the output object file. # $(4): the ninja pool to use for the rule define compile-dotdot-s-file
o := $(intermediates)/$(patsubst %.S,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
$$(o) : .KATI_NINJA_POOL := $(4)
$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2) $(CLANG)
$$(transform-$$(PRIVATE_HOST)s-to-o)
$$(callinclude-depfiles-for-objs, $$(o))
$(3) += $$(o) endef
## Rule to compile a .s source file with ../ in the path. ## Must be called with $(eval). # $(1): the .s source file in LOCAL_SRC_FILES. # $(2): the additional dependencies. # $(3): the variable name to collect the output object file. # $(4): the ninja pool to use for the rule define compile-dotdot-s-file-no-deps
o := $(intermediates)/$(patsubst %.s,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
$$(o) : .KATI_NINJA_POOL := $(4)
$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2) $(CLANG)
$$(transform-$$(PRIVATE_HOST)s-to-o)
$(3) += $$(o) endef
########################################################### ## Commands for running ar ###########################################################
# Split long argument list into smaller groups and call the command repeatedly # Call the command at least once even if there are no arguments, as otherwise # the output file won't be created. # # $(1): the command without arguments # $(2): the arguments define split-long-arguments
$(hide) $(1) $(wordlist 1,500,$(2))
$(call _concat-if-arg2-not-empty,$(1),$(wordlist 501,1000,$(2)))
$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1001,1500,$(2)))
$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1501,2000,$(2)))
$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2001,2500,$(2)))
$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2501,3000,$(2)))
$(call _concat-if-arg2-not-empty,$(1),$(wordlist 3001,99999,$(2))) endef
# $(1): the full path of the source static library. # $(2): the full path of the destination static library. define _extract-and-include-single-target-whole-static-lib
$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\ rm -rf $$ldir; \
mkdir -p $$ldir; \ cp $(1) $$ldir; \
lib_to_include=$$ldir/$(notdir $(1)); \
filelist=; \
subdir=0; \ for f in `$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) t $(1)`; do \ if [ -e $$ldir/$$f ]; then \
mkdir $$ldir/$$subdir; \
ext=$$subdir/; \
subdir=$$((subdir+1)); \
$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) m $$lib_to_include $$f; \ else \
ext=; \ fi; \
$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) p $$lib_to_include $$f > $$ldir/$$ext$$f; \
filelist="$$filelist $$ldir/$$ext$$f"; \ done ; \
$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \
$(PRIVATE_ARFLAGS) $(2) $$filelist
endef
# $(1): the full path of the source static library. # $(2): the full path of the destination static library. define extract-and-include-whole-static-libs-first
$(if $(strip $(1)),
$(hide) cp $(1) $(2)) endef
# $(1): the full path of the destination static library. define extract-and-include-target-whole-static-libs
$(call extract-and-include-whole-static-libs-first, $(firstword $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)),$(1))
$(foreach lib,$(wordlist 2,999,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)), \
$(call _extract-and-include-single-target-whole-static-lib, $(lib), $(1))) endef
# Explicitly delete the archive first so that ar doesn't # try to add to an existing archive. define transform-o-to-static-lib
@echo"$($(PRIVATE_PREFIX)DISPLAY) StaticLib: $(PRIVATE_MODULE) ($@)"
@mkdir -p $(dir $@)
@rm -f $@ $@.tmp
$(call extract-and-include-target-whole-static-libs,$@.tmp)
$(call split-long-arguments,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) \
$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \
$(PRIVATE_ARFLAGS) \
$@.tmp,$(PRIVATE_ALL_OBJECTS))
$(hide) mv -f $@.tmp $@ endef
########################################################### ## Commands for running host ar ###########################################################
# $(1): the full path of the source static library. # $(2): the full path of the destination static library. define _extract-and-include-single-host-whole-static-lib
$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\ rm -rf $$ldir; \
mkdir -p $$ldir; \ cp $(1) $$ldir; \
lib_to_include=$$ldir/$(notdir $(1)); \
filelist=; \
subdir=0; \ for f in `$($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) t $(1) | \grep '\.o$$'`; do \ if [ -e $$ldir/$$f ]; then \
mkdir $$ldir/$$subdir; \
ext=$$subdir/; \
subdir=$$((subdir+1)); \
$($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) m $$lib_to_include $$f; \ else \
ext=; \ fi; \
$($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) p $$lib_to_include $$f > $$ldir/$$ext$$f; \
filelist="$$filelist $$ldir/$$ext$$f"; \ done ; \
$($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)GLOBAL_ARFLAGS) \
$(2) $$filelist
ifeq ($(HOST_OS),darwin) # On Darwin the host ar fails if there is nothing to add to .a at all. # We work around by adding a dummy.o and then deleting it. define create-dummy.o-if-no-objs
$(if $(PRIVATE_ALL_OBJECTS),,$(hide) touch $(dir $(1))dummy.o) endef
definedelete-dummy.o-if-no-objs
$(if $(PRIVATE_ALL_OBJECTS),,$(hide) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) d $(1) $(dir $(1))dummy.o \
&& rm -f $(dir $(1))dummy.o) endef else
create-dummy.o-if-no-objs =
get-dummy.o-if-no-objs = delete-dummy.o-if-no-objs = endif# HOST_OS is darwin
# Explicitly delete the archive first so that ar doesn't # try to add to an existing archive. define transform-host-o-to-static-lib
@echo"$($(PRIVATE_PREFIX)DISPLAY) StaticLib: $(PRIVATE_MODULE) ($@)"
@mkdir -p $(dir $@)
@rm -f $@ $@.tmp
$(call extract-and-include-host-whole-static-libs,$@.tmp)
$(call create-dummy.o-if-no-objs,$@.tmp)
$(call split-long-arguments,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) \
$($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)GLOBAL_ARFLAGS) $@.tmp,\
$(PRIVATE_ALL_OBJECTS) $(call get-dummy.o-if-no-objs,$@.tmp))
$(calldelete-dummy.o-if-no-objs,$@.tmp)
$(hide) mv -f $@.tmp $@ endef
########################################################### ## Commands for running gcc to link a shared library or package ###########################################################
# ld just seems to be so finicky with command order that we allow # it to be overriden en-masse see combo/linux-arm.make for an example. ifneq ($(HOST_CUSTOM_LD_COMMAND),true) define transform-host-o-to-shared-lib-inner
$(hide) $(PRIVATE_CXX_LINK) \
-Wl,-rpath,\$$ORIGIN/../$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)OUT_SHARED_LIBRARIES)) \
-Wl,-rpath,\$$ORIGIN/$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)OUT_SHARED_LIBRARIES)) \
-shared -Wl,-soname,$(notdir $@) \
$(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
$(PRIVATE_HOST_GLOBAL_LDFLAGS) \
) \
$(PRIVATE_LDFLAGS) \
$(PRIVATE_CRTBEGIN) \
$(PRIVATE_ALL_OBJECTS) \
-Wl,--whole-archive \
$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES) \
-Wl,--no-whole-archive \
$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
$(PRIVATE_ALL_STATIC_LIBRARIES) \
$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
$(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_HOST_LIBPROFILE_RT)) \
$(PRIVATE_LIBCRT_BUILTINS) \
$(PRIVATE_ALL_SHARED_LIBRARIES) \
-o $@ \
$(PRIVATE_CRTEND) \
$(PRIVATE_LDLIBS) endef endif
########################################################### ## Commands for running gcc to link a shared library or package ###########################################################
########################################################### ## Commands for running gcc to link an executable ###########################################################
########################################################### ## Commands for linking a static executable. In practice, ## we only use this on arm, so the other platforms don't ## have transform-o-to-static-executable defined. ## Clang driver needs -static to create static executable. ## However, bionic/linker uses -shared to overwrite. ## Linker for x86 targets does not allow coexistance of -static and -shared, ## so we add -static only if -shared is not used. ###########################################################
########################################################### ## Commands for running gcc to link a host executable ###########################################################
########################################################### ## Commands for running javac to make .class files ###########################################################
# Search for generated R.java in $1, copy the found R.java as $2. define find-generated-R.java
$(hide) for GENERATED_R_FILE in `find $(1) \
-name R.java 2> /dev/null`; do \ cp $$GENERATED_R_FILE $(2) || exit 32; \ done;
@# Ensure that the target file is always created, i.e. also in case we did not
@# enter the GENERATED_R_FILE-loop above. This avoids unnecessary rebuilding.
$(hide) touch $(2) endef
# Set up rule to compile one resource file with aapt2. # Must be called with $(eval). # $(1): the source file # $(2): the output file define aapt2-compile-one-resource-file-rule
$(2) : $(1) $(AAPT2)
@echo"AAPT2 compile $$@ <- $$<"
$$(call aapt2-compile-one-resource-file) endef
# Convert input resource file path to output file path. # values-[config]/<file>.xml -> values-[config]_<file>.arsc.flat; # For other resource file, just replace the last "/" with "_" and # add .flat extension. # # $(1): the input resource file path # $(2): the base dir of the output file path # Returns: the compiled output file path define aapt2-compiled-resource-out-file
$(strip \
$(eval _p_w := $(strip $(subst /,$(space),$(dir $(callclean-path,$(1))))))
$(2)/$(subst $(space),/,$(_p_w))_$(if $(filter values%,$(lastword $(_p_w))),$(patsubst %.xml,%.arsc,$(notdir $(1))),$(notdir $(1))).flat) endef
# Runs jarjar on an input file. Jarjar doesn't exit with a nonzero return code # when there is a syntax error in a rules file and doesn't write the output # file, so removes the output file before running jarjar and check if it exists # after running jarjar. define transform-jarjar echo $($(PRIVATE_PREFIX)DISPLAY) JarJar: $@ rm -f $@
$(JAVA) -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@
[ -e $@ ] || (echo"Missing output file"; exit 1) endef
# Moves $1.tmp to $1 if necessary. This is designed to be used with # .KATI_RESTAT. For kati, this function doesn't update the timestamp # of $1 when $1.tmp is identical to $1 so that ninja won't rebuild # targets which depend on $1. define commit-change-for-toc
$(hide) if cmp -s $1.tmp $1 ; then \ rm $1.tmp ; \ else \
mv $1.tmp $1 ; \ fi endef
ifeq (,$(TARGET_BUILD_APPS))
## Rule to create a table of contents from a .dex file. ## Must be called with $(eval). # $(1): The directory which contains classes*.dex files define _transform-dex-to-toc
$1/classes.dex.toc: PRIVATE_INPUT_DEX_FILES := $1/classes*.dex
$1/classes.dex.toc: $1/classes.dex $(DEXDUMP)
@echo Generating TOC: $$@
$(hide) ANDROID_LOG_TAGS="*:e" $(DEXDUMP) -l xml $$(PRIVATE_INPUT_DEX_FILES) > $$@.tmp
$$(call commit-change-for-toc,$$@) endef
## Define a rule which generates .dex.toc and mark it as .KATI_RESTAT. # $(1): The directory which contains classes*.dex files definedefine-dex-to-toc-rule
$(eval $(call _transform-dex-to-toc,$1))\
$(eval .KATI_RESTAT: $1/classes.dex.toc) endef
else
# Turn off .toc optimization for apps build as we cannot build dexdump. definedefine-dex-to-toc-rule endef
endif# TARGET_BUILD_APPS
# Takes an sdk version that might be PLATFORM_VERSION_CODENAME (for example P), # returns a number greater than the highest existing sdk version if it is, or # the input if it is not. define codename-or-sdk-to-sdk
$(if $(filter $(1),$(PLATFORM_VERSION_CODENAME)),10000,$(1)) endef
# Uses LOCAL_SDK_VERSION and PLATFORM_SDK_VERSION to determine a compileSdkVersion # in the form of a number or a codename (28 or P) define module-sdk-version
$(strip \
$(if $(filter-out current system_current test_current core_current,$(LOCAL_SDK_VERSION)), \
$(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION)), \
$(PLATFORM_SDK_VERSION))) endef
# Uses LOCAL_SDK_VERSION and DEFAULT_APP_TARGET_SDK to determine # a targetSdkVersion in the form of a number or a codename (28 or P). define module-target-sdk-version
$(strip \
$(if $(filter-out current system_current test_current core_current,$(LOCAL_SDK_VERSION)), \
$(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION)), \
$(DEFAULT_APP_TARGET_SDK))) endef
# Uses LOCAL_MIN_SDK_VERSION, LOCAL_SDK_VERSION and DEFAULT_APP_TARGET_SDK to determine # a minSdkVersion in the form of a number or a codename (28 or P). define module-min-sdk-version
$(if $(LOCAL_MIN_SDK_VERSION),$(LOCAL_MIN_SDK_VERSION),$(call module-target-sdk-version)) endef
# Checks if module is in vendor or product define module-in-vendor-or-product
$(if $(filter true,$(LOCAL_IN_VENDOR) $(LOCAL_IN_PRODUCT)),true) endef
# We need the extra blank line, so that the command will be on a separate line. # $(1): the package # $(2): the ABI name # $(3): the list of shared libraies define _add-jni-shared-libs-to-package-per-abi
$(hide) cp $(3) $(dir $(1))lib/$(2)
# Add java resources added by the current module to an existing package. # $(1) destination package. define add-java-resources-to
$(call _java-resources,$(1),u) endef
# Add java resources added by the current module to a new jar. # $(1) destination jar. define create-java-resources-jar
$(call _java-resources,$(1),c) endef
# TODO(joeo): If we can ever upgrade to post 3.81 make and get the # new prebuilt rules to work, we should change this to copy the # resources to the out directory and then copy the resources.
# Note: we intentionally don't clean PRIVATE_CLASS_INTERMEDIATES_DIR # in transform-java-to-classes for the sake of vm-tests. define transform-host-java-to-package
@echo"Host Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
$(call compile-java,$(HOST_JAVAC),$(PRIVATE_ALL_JAVA_LIBRARIES)) endef
# Note: we intentionally don't clean PRIVATE_CLASS_INTERMEDIATES_DIR # in transform-java-to-classes for the sake of vm-tests. define transform-host-java-to-dalvik-package
@echo"Dalvik Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
$(call compile-java,$(HOST_JAVAC),$(PRIVATE_ALL_JAVA_HEADER_LIBRARIES)) endef
########################################################### ## Commands for copying files ###########################################################
# Define a rule to copy a header. Used via $(eval) by copy_headers.make. # $(1): source header # $(2): destination header definecopy-one-header
$(2): $(1)
@echo"Header: $$@"
$$(copy-file-to-new-target-with-cp) endef
# Define a rule to copy a file. For use via $(eval). # $(1): source file # $(2): destination file definecopy-one-file
$(2): $(1)
@echo"Copy: $$@"
$$(copy-file-to-target) endef
# Define a rule to copy a license metadata file. For use via $(eval). # $(1): source license metadata file # $(2): destination license metadata file # $(3): built targets # $(4): installed targets definecopy-one-license-metadata-file
$(2): PRIVATE_BUILT=$(3)
$(2): PRIVATE_INSTALLED=$(4)
$(2): $(1)
@echo"Copy: $$@"
$$(callcopy-license-metadata-file-to-target,$$(PRIVATE_BUILT),$$(PRIVATE_INSTALLED)) endef
# Create copy pair for compatibility suite # Filter out $(LOCAL_INSTALLED_MODULE) to prevent overriding target # $(1): source path # $(2): destination path # The format of copy pair is src:dst define compat-copy-pair
$(if $(filter-out $(2), $(LOCAL_INSTALLED_MODULE)), $(1):$(2)) endef
# Create copy pair for $(1) $(2) # If $(2) is substring of $(3) do nothing. # $(1): source path # $(2): destination path # $(3): filter-out target # The format of copy pair is src:dst define filter-copy-pair
$(if $(findstring $(2), $(3)),,$(1):$(2)) endef
# Copies many files. # $(1): The files to copy. Each entry is a ':' separated src:dst pair # $(2): An optional directory to prepend to the destination # Evaluates to the list of the dst files (ie suitable for a dependency list) definecopy-many-files
$(foreach f, $(1), $(strip \
$(eval _cmf_tuple := $(subst :, ,$(f))) \
$(eval _cmf_src := $(word 1,$(_cmf_tuple))) \
$(eval _cmf_dest := $(word 2,$(_cmf_tuple))) \
$(if $(strip $(2)), \
$(eval _cmf_dest := $(patsubst %/,%,$(strip $(2)))/$(patsubst /%,%,$(_cmf_dest)))) \
$(if $(filter-out $(_cmf_src), $(_cmf_dest)), \
$(eval $(callcopy-one-file,$(_cmf_src),$(_cmf_dest)))) \
$(_cmf_dest))) endef
# Copy the file only if it's a well-formed init script file. For use via $(eval). # $(1): source file # $(2): destination file definecopy-init-script-file-checked
ifdef TARGET_BUILD_UNBUNDLED # TODO (b/185624993): Remove the check on TARGET_BUILD_UNBUNDLED when host_init_verifier can run # without requiring the HIDL interface map.
$(2): $(1) elseifneq ($(HOST_OS),darwin) # Host init verifier doesn't exist on darwin.
$(2): \
$(1) \
$(HOST_INIT_VERIFIER) \
$(call intermediates-dir-for,ETC,passwd_system)/passwd_system \
$(call intermediates-dir-for,ETC,passwd_system_ext)/passwd_system_ext \
$(call intermediates-dir-for,ETC,passwd_vendor)/passwd_vendor \
$(call intermediates-dir-for,ETC,passwd_odm)/passwd_odm \
$(call intermediates-dir-for,ETC,passwd_product)/passwd_product \
$(call intermediates-dir-for,ETC,plat_property_contexts)/plat_property_contexts \
$(call intermediates-dir-for,ETC,system_ext_property_contexts)/system_ext_property_contexts \
$(call intermediates-dir-for,ETC,product_property_contexts)/product_property_contexts \
$(call intermediates-dir-for,ETC,vendor_property_contexts)/vendor_property_contexts \
$(call intermediates-dir-for,ETC,odm_property_contexts)/odm_property_contexts
$(hide) $(HOST_INIT_VERIFIER) \
-p $(call intermediates-dir-for,ETC,passwd_system)/passwd_system \
-p $(call intermediates-dir-for,ETC,passwd_system_ext)/passwd_system_ext \
-p $(call intermediates-dir-for,ETC,passwd_vendor)/passwd_vendor \
-p $(call intermediates-dir-for,ETC,passwd_odm)/passwd_odm \
-p $(call intermediates-dir-for,ETC,passwd_product)/passwd_product \
--property-contexts=$(call intermediates-dir-for,ETC,plat_property_contexts)/plat_property_contexts \
--property-contexts=$(call intermediates-dir-for,ETC,system_ext_property_contexts)/system_ext_property_contexts \
--property-contexts=$(call intermediates-dir-for,ETC,product_property_contexts)/product_property_contexts \
--property-contexts=$(call intermediates-dir-for,ETC,vendor_property_contexts)/vendor_property_contexts \
--property-contexts=$(call intermediates-dir-for,ETC,odm_property_contexts)/odm_property_contexts \
$$< else
$(2): $(1) endif
@echo"Copy init script: $$@"
$$(copy-file-to-target) endef
# Copies many init script files and check they are well-formed. # $(1): The init script files to copy. Each entry is a ':' separated src:dst pair. definecopy-many-init-script-files-checked
$(foreach f, $(1), $(strip \
$(eval _cmf_tuple := $(subst :, ,$(f))) \
$(eval _cmf_src := $(word 1,$(_cmf_tuple))) \
$(eval _cmf_dest := $(word 2,$(_cmf_tuple))) \
$(eval $(callcopy-init-script-file-checked,$(_cmf_src),$(_cmf_dest))))) endef
# Copy the file only if it's a well-formed xml file. For use via $(eval). # $(1): source file # $(2): destination file, must end with .xml. definecopy-xml-file-checked
$(2): $(1) $(XMLLINT)
@echo"Copy xml: $$@"
$(hide) $(XMLLINT) $$< >/dev/null # Don't print the xml file to stdout.
$$(copy-file-to-target) endef
# Copies many xml files and check they are well-formed. # $(1): The xml files to copy. Each entry is a ':' separated src:dst pair. # Evaluates to the list of the dst files. (ie suitable for a dependency list.) definecopy-many-xml-files-checked
$(foreach f, $(1), $(strip \
$(eval _cmf_tuple := $(subst :, ,$(f))) \
$(eval _cmf_src := $(word 1,$(_cmf_tuple))) \
$(eval _cmf_dest := $(word 2,$(_cmf_tuple))) \
$(eval $(callcopy-xml-file-checked,$(_cmf_src),$(_cmf_dest))) \
$(_cmf_dest))) endef
# Copy the file only if it is a well-formed manifest file. For use viea $(eval) # $(1): source file # $(2): destination file definecopy-vintf-manifest-checked
$(2): $(1) $(HOST_OUT_EXECUTABLES)/assemble_vintf
@echo"Copy xml: $$@"
$(hide) mkdir -p "$$(dir $$@)"
$(hide) VINTF_IGNORE_TARGET_FCM_VERSION=true\
$(HOST_OUT_EXECUTABLES)/assemble_vintf -i $$< -o $$@ endef
# Copies many vintf manifest files checked. # $(1): The files to copy. Each entry is a ':' separated src:dst pair definecopy-many-vintf-manifest-files-checked
$(foreach f, $(1), $(strip \
$(eval _cmf_tuple := $(subst :, ,$(f))) \
$(eval _cmf_src := $(word 1,$(_cmf_tuple))) \
$(eval _cmf_dest := $(word 2,$(_cmf_tuple))) \
$(eval $(callcopy-vintf-manifest-checked,$(_cmf_src),$(_cmf_dest))))) endef
# Copy the file only if it's not an ELF file. For use via $(eval). # $(1): source file # $(2): destination file # $(3): message to print on error definecopy-non-elf-file-checked
$(eval check_non_elf_file_timestamp := \
$(call intermediates-dir-for,FAKE,check-non-elf-file-timestamps)/$(2).timestamp)
$(check_non_elf_file_timestamp): $(1) $(LLVM_READOBJ)
@echo"Check non-ELF: $$<"
$(hide) mkdir -p "$$(dir $$@)"
$(hide) rm -f "$$@"
$(hide) \ if $(LLVM_READOBJ) -h "$$<"2>/dev/null | grep -q "^Format: elf"; then \
$(callecho-error,$(2),$(3)); \
$(callecho-error,$(2),found ELF file: $$<); \
false; \ fi
$(hide) touch "$$@"
# The -t option to acp and the -p option to cp is # required for OSX. OSX has a ridiculous restriction # where it's an error for a .a file's modification time # to disagree with an internal timestamp, and this # macro is used to install .a files (among other things).
# Copy a single file from one place to another, # preserving permissions and overwriting any existing # file. # When we used acp, it could not handle high resolution timestamps # on file systems like ext4. Because of that, '-t' option was disabled # and copy-file-to-target was identical to copy-file-to-new-target. # Keep the behavior until we audit and ensure that switching this back # won't break anything. definecopy-file-to-target
@mkdir -p $(dir $@)
$(hide) rm -f $@
$(hide) cp"$<""$@" endef
# Same as copy-file-to-target, but assume file is a licenes metadata file, # and append built from $(1) and installed from $(2). definecopy-license-metadata-file-to-target
@mkdir -p $(dir $@)
$(hide) rm -f $@
$(hide) cp"$<""$@" $(strip \
$(foreach b,$(1), && (grep -F 'built: "'"$(b)"'"'"$@" >/dev/null || echo'built: "'"$(b)"'"' >>"$@")) \
$(foreach i,$(2), && (grep -F 'installed: "'"$(i)"'"'"$@" >/dev/null || echo'installed: "'"$(i)"'"' >>"$@")) \
) endef
# The same as copy-file-to-target, but use the local # cp command instead of acp. definecopy-file-to-target-with-cp
@mkdir -p $(dir $@)
$(hide) rm -f $@
$(hide) cp -p "$<""$@" endef
# The same as copy-file-to-target, but don't preserve # the old modification time. definecopy-file-to-new-target
@mkdir -p $(dir $@)
$(hide) rm -f $@
$(hide) cp $< $@ endef
# The same as copy-file-to-new-target, but use the local # cp command instead of acp. definecopy-file-to-new-target-with-cp
@mkdir -p $(dir $@)
$(hide) rm -f $@
$(hide) cp $< $@ endef
# The same as copy-file-to-new-target, but preserve symlinks. Symlinks are # converted to absolute to not break. definecopy-file-or-link-to-new-target
@mkdir -p $(dir $@)
$(hide) rm -f $@
$(hide) if [ -h $< ]; then \
ln -s $$(realpath $<) $@; \ else \ cp $< $@; \ fi endef
# Copy a prebuilt file to a target location. define transform-prebuilt-to-target
@echo"$($(PRIVATE_PREFIX)DISPLAY) Prebuilt: $(PRIVATE_MODULE) ($@)"
$(copy-file-to-target) endef
# Copy a prebuilt file to a target location, but preserve symlinks rather than # dereference them. definecopy-or-link-prebuilt-to-target
@echo"$($(PRIVATE_PREFIX)DISPLAY) Prebuilt: $(PRIVATE_MODULE) ($@)"
$(copy-file-or-link-to-new-target) endef
# Copy a list of files/directories to target location, with sub dir structure preserved. # For example $(HOST_OUT_EXECUTABLES)/aapt -> $(staging)/bin/aapt . # $(1): the source list of files/directories. # $(2): the path prefix to strip. In the above example it would be $(HOST_OUT). # $(3): the target location. definecopy-files-with-structure
$(foreach t,$(1),\
$(eval s := $(patsubst $(2)%,%,$(t)))\
$(hide) mkdir -p $(dir $(3)/$(s)); cp -Rf $(t) $(3)/$(s)$(newline)) endef
# Define a rule to create a symlink to a file. # $(1): any dependencies # $(2): source (may be relative) # $(3): full path to destination define symlink-file
$(eval $(_symlink-file))
$(eval $(call declare-license-metadata,$(3),,,,,,))
$(eval $(call declare-license-deps,$(3),$(1))) endef
# Copy an apk to a target location while removing classes*.dex # $(1): source file # $(2): destination file # $(3): LOCAL_STRIP_DEX, if non-empty then strip classes*.dex define dexpreopt-copy-jar
$(2): $(1)
@echo"Copy: $$@"
$$(copy-file-to-target)
$(if $(3),$$(call dexpreopt-remove-classes.dex,$$@)) endef
# $(1): the .jar or .apk to remove classes.dex. Note that if all dex files # are uncompressed in the archive, then dexopt will not do a copy of the dex # files and we should not strip. define dexpreopt-remove-classes.dex
$(hide) if (zipinfo $1'*.dex'2>/dev/null | grep -v ' stor ' >/dev/null) ; then \
zip --quiet --delete $(1) classes.dex; \
dex_index=2; \ while zip --quiet --delete $(1) classes$${dex_index}.dex > /dev/null; do \
let dex_index=dex_index+1; \ done \ fi endef
# Copy an unstripped binary to the symbols directory while also extracting # a hash mapping to the mapping directory. # $(1): unstripped intermediates file # $(2): path in symbols directory # $(3): path in elf_symbol_mapping packaging directory definecopy-unstripped-elf-file-with-mapping
$(call _copy-symbols-file-with-mapping,$(1),$(2),elf,$(3)) endef
# Copy an R8 dictionary to the packaging directory while also extracting # a hash mapping to the mapping directory. # $(1): unstripped intermediates file # $(2): path in packaging directory # $(3): path in mappings packaging directory definecopy-r8-dictionary-file-with-mapping
$(call _copy-symbols-file-with-mapping,$(1),$(2),r8,$(3)) endef
# Copy an unstripped binary or R8 dictionary to the symbols directory # while also extracting a hash mapping to the mapping directory. # $(1): unstripped intermediates file # $(2): path in symbols directory # $(3): file type (elf or r8) # $(4): path in the mappings directory # # Regarding the restats at the end: I think you should only need to use KATI_RESTAT on $(2), but # there appears to be a bug in kati where it was not adding restat=true in the ninja file unless we # also added 4 to KATI_RESTAT. define _copy-symbols-file-with-mapping
$(2): .KATI_IMPLICIT_OUTPUTS := $(4)
$(2): $(SYMBOLS_MAP)
$(2): $(1)
@echo"Copy symbols with mapping: $$@"
$$(copy-file-to-target)
$(SYMBOLS_MAP) -$(strip $(3)) $(2) -write_if_changed $(4)
.KATI_RESTAT: $(2)
.KATI_RESTAT: $(4) endef
########################################################### ## Commands to call R8 ###########################################################
# Use --debug flag for eng builds by default ifeq (eng,$(TARGET_BUILD_VARIANT))
R8_DEBUG_MODE := --debug else
R8_DEBUG_MODE := endif
########################################################### ## Assertions about attributes of the target ###########################################################
# $(1): The file to check define get-file-size
stat -c "%s""$(1)" | tr -d '\n' endef
# $(1): The file(s) to check (often $@) # $(2): The partition size. define assert-max-image-size
$(if $(2), \
size=$$(for i in $(1); do $(call get-file-size,$$i); echo +; done; echo0); \
total=$$(( $$( echo"$$size" ) )); \
printname=$$(echo -n "$(1)" | tr " " +); \
maxsize=$$(($(2))); \ if [ "$$total" -gt "$$maxsize" ]; then \ echo"error: $$printname too large ($$total > $$maxsize)"; \
false; \ elif [ "$$total" -gt $$((maxsize - 32768)) ]; then \ echo"WARNING: $$printname approaching size limit ($$total now; limit $$maxsize)"; \ fi \
, \
true \
) endef
########################################################### ## Define device-specific radio files ###########################################################
INSTALLED_RADIOIMAGE_TARGET :=
# Copy a radio image file to the output location, and add it to # INSTALLED_RADIOIMAGE_TARGET. # $(1): filename define add-radio-file
$(eval $(call add-radio-file-internal,$(1),$(notdir $(1)))) endef define add-radio-file-internal
INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1)
$$(transform-prebuilt-to-target) endef
# Version of add-radio-file that also arranges for the version of the # file to be checked against the contents of # $(TARGET_BOARD_INFO_FILE). # $(1): filename # $(2): name of version variable in board-info (eg, "version-baseband") define add-radio-file-checked
$(eval $(call add-radio-file-checked-internal,$(1),$(notdir $(1)),$(2))) endef define add-radio-file-checked-internal
INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
BOARD_INFO_CHECK += $(3):$(LOCAL_PATH)/$(1)
$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1)
$$(transform-prebuilt-to-target) endef
## Whether to build from source if prebuilt alternative exists ########################################################### # $(1): module name # $(2): LOCAL_PATH # Expands to empty string if not from source. ifeq (true,$(ANDROID_BUILD_FROM_SOURCE)) defineif-build-from-source
true endef else defineif-build-from-source
$(if $(filter $(ANDROID_NO_PREBUILT_MODULES),$(1))$(filter \
$(addsuffix %,$(ANDROID_NO_PREBUILT_PATHS)),$(2)),true) endef endif
# Include makefile $(1) if build from source for module $(2) # $(1): the makefile to include # $(2): module name # $(3): LOCAL_PATH defineinclude-if-build-from-source
$(if $(callif-build-from-source,$(2),$(3)),$(evalinclude $(1))) endef
# Return the arch for the source file of a prebuilt # Return "none" if no matching arch found and return empty # if the input is empty, so the result can be passed to # LOCAL_MODULE_TARGET_ARCH. # $(1) the list of archs supported by the prebuilt define get-prebuilt-src-arch
$(strip $(if $(filter $(TARGET_ARCH),$(1)),$(TARGET_ARCH),\
$(if $(filter $(TARGET_2ND_ARCH),$(1)),$(TARGET_2ND_ARCH),$(if $(1),none)))) endef
########################################################### ## Compatibility suite tools ###########################################################
# Return a list of output directories for a given suite and the current LOCAL_MODULE. # Can be passed a subdirectory to use for the common testcase directory. define compatibility_suite_dirs
$(strip \
$(if $(COMPATIBILITY_TESTCASES_OUT_$(1)), \
$(if $(COMPATIBILITY_TESTCASES_OUT_INCLUDE_MODULE_FOLDER_$(1))$(LOCAL_COMPATIBILITY_PER_TESTCASE_DIRECTORY),\
$(COMPATIBILITY_TESTCASES_OUT_$(1))/$(LOCAL_MODULE)$(2),\
$(COMPATIBILITY_TESTCASES_OUT_$(1)))) \
$($(my_prefix)OUT_TESTCASES)/$(LOCAL_MODULE)$(2)) endef
# For each suite: # 1. Copy the files to the many suite output directories. # And for test config files, we'll check the .xml is well-formed before copy. # 2. Add all the files to each suite's dependent files list. # 3. Do the dependency addition to my_all_targets. # 4. Save the module name to COMPATIBILITY.$(suite).MODULES for each suite. # 5. Collect files to dist to ALL_COMPATIBILITY_DIST_FILES. # Requires for each suite: use my_compat_dist_config_$(suite) to define the test config. # and use my_compat_dist_$(suite) to define the others. define create-suite-dependencies
$(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \
$(eval $(if $(strip $(module_license_metadata)),\
$$(foreach f,$$(my_compat_dist_$(suite)),$$(call declare-copy-target-license-metadata,$$(call word-colon,2,$$(f)),$$(call word-colon,1,$$(f)))),\
$$(eval my_test_data += $$(my_compat_dist_$(suite))) \
)) \
$(eval $(if $(strip $(module_license_metadata)),\
$$(foreach f,$$(my_compat_dist_config_$(suite)),$$(call declare-copy-target-license-metadata,$$(call word-colon,2,$$(f)),$$(call word-colon,1,$$(f)))),\
$$(eval my_test_config += $$(my_compat_dist_config_$(suite))) \
)) \
$(if $(filter $(suite),$(ALL_COMPATIBILITY_SUITES)),,\
$(eval ALL_COMPATIBILITY_SUITES += $(suite)) \
$(eval COMPATIBILITY.$(suite).FILES :=) \
$(eval COMPATIBILITY.$(suite).MODULES :=) \
$(eval COMPATIBILITY.$(suite).API_MAP_FILES :=)) \
$(eval COMPATIBILITY.$(suite).FILES += \
$$(foreach f,$$(my_compat_dist_$(suite)),$$(call word-colon,2,$$(f))) \
$$(foreach f,$$(my_compat_dist_config_$(suite)),$$(call word-colon,2,$$(f))) \
$$(my_compat_dist_test_data_$(suite))) \
$(eval COMPATIBILITY.$(suite).ARCH_DIRS.$(my_register_name) := $(my_compat_module_arch_dir_$(suite).$(my_register_name))) \
$(eval COMPATIBILITY.$(suite).API_MAP_FILES += $$(my_compat_api_map_$(suite))) \
$(eval COMPATIBILITY.$(suite).SOONG_INSTALLED_COMPATIBILITY_SUPPORT_FILES += $(LOCAL_SOONG_INSTALLED_COMPATIBILITY_SUPPORT_FILES)) \
$(if $(LOCAL_IS_SOONG_MODULE),, \
$(eval ALL_COMPATIBILITY_DIST_FILES += $$(my_compat_dist_$(suite)))) \
$(eval COMPATIBILITY.$(suite).MODULES += $$(my_register_name))) \
$(eval $(my_all_targets) : \
$(sort $(foreach suite,$(LOCAL_COMPATIBILITY_SUITE), \
$(foreach f,$(my_compat_dist_$(suite)), $(call word-colon,2,$(f))))) \
$(if $(LOCAL_IS_SOONG_MODULE), \
$(sort $(foreach p,$(foreach suite,$(LOCAL_COMPATIBILITY_SUITE),$(my_compat_dist_config_$(suite))),$(call word-colon,2,$(p)))), \
$(callcopy-many-xml-files-checked, \
$(sort $(foreach suite,$(LOCAL_COMPATIBILITY_SUITE),$(my_compat_dist_config_$(suite))))))) endef
# Remove "dir .." combinations (but keep ".. ..") # # $(1): The expanded path, where / is converted to ' ' to work with $(word) define _clean-path-strip-dotdot
$(strip \
$(if $(word 2,$(1)),
$(if $(call streq,$(word 2,$(1)),..),
$(if $(call streq,$(word 1,$(1)),..),
$(word 1,$(1)) $(call _clean-path-strip-dotdot,$(wordlist 2,$(words $(1)),$(1)))
,
$(call _clean-path-strip-dotdot,$(wordlist 3,$(words $(1)),$(1)))
)
,
$(word 1,$(1)) $(call _clean-path-strip-dotdot,$(wordlist 2,$(words $(1)),$(1)))
)
,
$(1)
)
) endef
# Remove any leading .. from the path (in case of /..) # # Should only be called if the original path started with / # $(1): The expanded path, where / is converted to ' ' to work with $(word) define _clean-path-strip-root-dotdots
$(strip $(if $(call streq,$(firstword $(1)),..),
$(call _clean-path-strip-root-dotdots,$(wordlist 2,$(words $(1)),$(1))),
$(1))) endef
# Call _clean-path-strip-dotdot until the path stops changing # $(1): Non-empty if this path started with a / # $(2): The expanded path, where / is converted to ' ' to work with $(word) define _clean-path-expanded
$(strip \
$(eval _ep := $(call _clean-path-strip-dotdot,$(2)))
$(if $(1),$(eval _ep := $(call _clean-path-strip-root-dotdots,$(_ep))))
$(if $(call streq,$(2),$(_ep)),
$(_ep),
$(call _clean-path-expanded,$(1),$(_ep)))) endef
# Clean the file path -- remove //, dir/.., extra . # # This should be the same semantics as golang's filepath.Clean # # $(1): The file path to clean defineclean-path
$(strip \
$(if $(call streq,$(words $(1)),1),
$(eval _rooted := $(filter /%,$(1)))
$(eval _expanded_path := $(filter-out .,$(subst /,$(space),$(1))))
$(eval _path := $(if $(_rooted),/)$(subst $(space),/,$(call _clean-path-expanded,$(_rooted),$(_expanded_path))))
$(if $(_path),
$(_path),
.
)
,
$(if $(call streq,$(words $(1)),0),
.,
$(error Callclean-path with only one path (without spaces))
)
)
) endef
########################################################### ## Given a filepath, returns nonempty if the path cannot be ## validated to be contained in the current directory ## This is, this function checks for '/' and '..' ## ## $(1): path to validate define try-validate-path-is-subdir
$(strip \
$(if $(filter /%,$(1)),
$(1) starts with a slash
)
$(if $(filter ../%,$(callclean-path,$(1))),
$(1) escapes its parent using '..'
)
$(if $(strip $(1)),
, '$(1)' is empty
)
) endef
########################################################### ## Given a space-delimited list of filepaths, returns ## nonempty if any cannot be validated to be contained in ## the current directory ## ## $(1): path list to validate define try-validate-paths-are-subdirs
$(strip \
$(foreach my_path,$(1),\
$(call try-validate-path-is-subdir,$(my_path))\
)
) endef
########################################################### ## Tests of try-validate-path-is-subdir ## and try-validate-paths-are-subdirs define test-validate-paths-are-subdirs
$(eval my_error := $(call try-validate-path-is-subdir,/tmp)) \
$(if $(call streq,$(my_error),/tmp starts with a slash),
,
$(error incorrect error message for path /tmp. Got '$(my_error)')
) \
$(eval my_error := $(call try-validate-path-is-subdir,../sibling)) \
$(if $(call streq,$(my_error),../sibling escapes its parent using '..'),
,
$(error incorrect error message for path ../sibling. Got '$(my_error)')
) \
$(eval my_error := $(call try-validate-path-is-subdir,child/../../sibling)) \
$(if $(call streq,$(my_error),child/../../sibling escapes its parent using '..'),
,
$(error incorrect error message for path child/../../sibling. Got '$(my_error)')
) \
$(eval my_error := $(call try-validate-path-is-subdir,)) \
$(if $(call streq,$(my_error),'' is empty),
,
$(error incorrect error message for empty path ''. Got '$(my_error)')
) \
$(eval my_error := $(call try-validate-path-is-subdir,subdir/subsubdir)) \
$(if $(call streq,$(my_error),),
,
$(error rejected valid path 'subdir/subsubdir'. Got '$(my_error)')
)
$(eval my_error := $(call try-validate-paths-are-subdirs,a/b /c/d e/f))
$(if $(call streq,$(my_error),/c/d starts with a slash),
,
$(error incorrect error message for path list 'a/b /c/d e/f'. Got '$(my_error)')
)
$(eval my_error := $(call try-validate-paths-are-subdirs,a/b c/d))
$(if $(call streq,$(my_error),),
,
$(error rejected valid path list 'a/b c/d'. Got '$(my_error)')
) endef # run test
$(strip $(call test-validate-paths-are-subdirs))
########################################################### ## Validate jacoco class filters and convert them to ## file arguments ## Jacoco class filters are comma-separated lists of class ## files (android.app.Application), and may have '*' as the ## last character to match all classes in a package ## including subpackages. define jacoco-class-filter-to-file-args
$(strip $(call jacoco-validate-file-args,\
$(subst $(comma),$(space),\
$(subst .,/,\
$(strip $(1)))))) endef
define jacoco-validate-file-args
$(strip $(1)\
$(call validate-paths-are-subdirs,$(1))
$(foreach arg,$(1),\
$(if $(findstring ?,$(arg)),$(call pretty-error,\ '?' filters are not supported in LOCAL_JACK_COVERAGE_INCLUDE_FILTER or LOCAL_JACK_COVERAGE_EXCLUDE_FILTER))\
$(if $(findstring *,$(patsubst %*,%,$(arg))),$(call pretty-error,\ '*' is only supported at the end of a filter in LOCAL_JACK_COVERAGE_INCLUDE_FILTER or LOCAL_JACK_COVERAGE_EXCLUDE_FILTER))\
)) endef
########################################################### ## Other includes ###########################################################
# Include any vendor specific definitions.mk file
-include $(TOPDIR)vendor/*/build/core/definitions.mk
-include $(TOPDIR)device/*/build/core/definitions.mk
-include $(TOPDIR)product/*/build/core/definitions.mk # Also the project-specific definitions.mk file
-include $(TOPDIR)vendor/*/*/build/core/definitions.mk
-include $(TOPDIR)device/*/*/build/core/definitions.mk
-include $(TOPDIR)product/*/*/build/core/definitions.mk
########################################################### # Append the information to generate a RRO package for the # source module. # # $(1): Source module name. # $(2): Whether $(3) is a manifest package name or not. # $(3): Manifest package name if $(2) is true. # Otherwise, android manifest file path of the # source module. # $(4): Whether LOCAL_EXPORT_PACKAGE_RESOURCES is set or # not for the source module. # $(5): Resource overlay list. # $(6): Target partition ########################################################### define append_enforce_rro_sources
$(eval ENFORCE_RRO_SOURCES += \
$(strip $(1))||$(strip $(2))||$(strip $(3))||$(strip $(4))||$(call normalize-path-list, $(strip $(5)))||$(strip $(6)) \
) endef
########################################################### ## Find system_$(VER) in LOCAL_SDK_VERSION ## note: system_server_* is excluded. It's a different API surface ## ## $(1): LOCAL_SDK_VERSION ########################################################### define has-system-sdk-version
$(filter-out system_server_%,$(filter system_%,$(1))) endef
########################################################### ## Get numerical version in LOCAL_SDK_VERSION ## ## $(1): LOCAL_SDK_VERSION ########################################################### define get-numeric-sdk-version
$(filter-out current,\
$(if $(call has-system-sdk-version,$(1)),$(patsubst system_%,%,$(1)),$(1))) endef
########################################################### ## Verify module name meets character requirements: ## a-z A-Z 0-9 ## _.+-,@~ ## ## This is a subset of bazel's target name restrictions: ## https://docs.bazel.build/versions/master/build-ref.html#name ## ## Kati has problems with '=': https://github.com/google/kati/issues/138 ########################################################### define verify-module-name
$(if $(filter-out $(LOCAL_MODULE),$(subst /,,$(LOCAL_MODULE))), \
$(call pretty-warning,Module name contains a /$(comma) use LOCAL_MODULE_STEM and LOCAL_MODULE_RELATIVE_PATH instead)) \
$(if $(call _invalid-name-chars,$(LOCAL_MODULE)), \
$(call pretty-error,Invalid characters in module name: $(call _invalid-name-chars,$(LOCAL_MODULE)))) endef define _invalid-name-chars
$(subst _,,$(subst .,,$(subst +,,$(subst -,,$(subst $(comma),,$(subst @,,$(subst ~,,$(subst 0,,$(subst 1,,$(subst 2,,$(subst 3,,$(subst 4,,$(subst 5,,$(subst 6,,$(subst 7,,$(subst 8,,$(subst 9,,$(subst a,,$(subst b,,$(subst c,,$(subst d,,$(subst e,,$(subst f,,$(subst g,,$(subst h,,$(subst i,,$(subst j,,$(subst k,,$(subst l,,$(subst m,,$(subst n,,$(subst o,,$(subst p,,$(subst q,,$(subst r,,$(subst s,,$(subst t,,$(subst u,,$(subst v,,$(subst w,,$(subst x,,$(subst y,,$(subst z,,$(call to-lower,$(1))))))))))))))))))))))))))))))))))))))))))))) endef
.KATI_READONLY := verify-module-name _invalid-name-chars
########################################################### ## Verify module stem meets character requirements: ## a-z A-Z 0-9 ## _.+-,@~ ## ## This is a subset of bazel's target name restrictions: ## https://docs.bazel.build/versions/master/build-ref.html#name ## ## $(1): The module stem variable to check ########################################################### define verify-module-stem
$(if $(filter-out $($(1)),$(subst /,,$($(1)))), \
$(call pretty-warning,Module stem \($(1)\) contains a /$(comma) use LOCAL_MODULE_RELATIVE_PATH instead)) \
$(if $(call _invalid-name-chars,$($(1))), \
$(call pretty-error,Invalid characters in module stem \($(1)\): $(call _invalid-name-chars,$($(1))))) endef
.KATI_READONLY := verify-module-stem
$(KATI_obsolete_var \
create-empty-package \
initialize-package-file \
add-jni-shared-libs-to-package \
inherit-package,\
These functions have been removed)
########################################################### ## Verify the variants of a VNDK library are identical ## ## $(1): Path to the core variant shared library file. ## $(2): Path to the vendor variant shared library file. ## $(3): TOOLS_PREFIX ###########################################################
LIBRARY_IDENTITY_CHECK_SCRIPT := build/make/tools/check_identical_lib.sh define verify-vndk-libs-identical
@echo"Checking VNDK vendor variant: $(2)"
$(hide) CLANG_BIN="$(LLVM_PREBUILTS_PATH)" \
CROSS_COMPILE="$(strip $(3))" \
XZ="$(XZ)" \
$(LIBRARY_IDENTITY_CHECK_SCRIPT) $(SOONG_STRIP_PATH) $(1) $(2) endef
# Convert Soong libraries that have SDK variant define use_soong_sdk_libraries
$(foreach l,$(1),$(if $(filter $(l),$(SOONG_SDK_VARIANT_MODULES)),\
$(l).sdk,$(l))) endef
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.94Bemerkung:
(vorverarbeitet am 2026-06-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.