definitions.mk revision 3a08a9c0798eef3d340c6bb7c506ee0050a783e0
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## 18## Common build system definitions. Mostly standard 19## commands for building various types of targets, which 20## are used by others to construct the final targets. 21## 22 23# These are variables we use to collect overall lists 24# of things being processed. 25 26# Full paths to all of the documentation 27ALL_DOCS:= 28 29# The short names of all of the targets in the system. 30# For each element of ALL_MODULES, two other variables 31# are defined: 32# $(ALL_MODULES.$(target)).BUILT 33# $(ALL_MODULES.$(target)).INSTALLED 34# The BUILT variable contains LOCAL_BUILT_MODULE for that 35# target, and the INSTALLED variable contains the LOCAL_INSTALLED_MODULE. 36# Some targets may have multiple files listed in the BUILT and INSTALLED 37# sub-variables. 38ALL_MODULES:= 39 40# Full paths to targets that should be added to the "make droid" 41# set of installed targets. 42ALL_DEFAULT_INSTALLED_MODULES:= 43 44# The list of tags that have been defined by 45# LOCAL_MODULE_TAGS. Each word in this variable maps 46# to a corresponding ALL_MODULE_TAGS.<tagname> variable 47# that contains all of the INSTALLED_MODULEs with that tag. 48ALL_MODULE_TAGS:= 49 50# Similar to ALL_MODULE_TAGS, but contains the short names 51# of all targets for a particular tag. The top-level variable 52# won't have the list of tags; ust ALL_MODULE_TAGS to get 53# the list of all known tags. (This means that this variable 54# will always be empty; it's just here as a placeholder for 55# its sub-variables.) 56ALL_MODULE_NAME_TAGS:= 57 58# Full path to all files that are made by some tool 59ALL_GENERATED_SOURCES:= 60 61# Full path to all asm, C, C++, lex and yacc generated C files. 62# These all have an order-only dependency on the copied headers 63ALL_C_CPP_ETC_OBJECTS:= 64 65# The list of dynamic binaries that haven't been stripped/compressed/etc. 66ALL_ORIGINAL_DYNAMIC_BINARIES:= 67 68# These files go into the SDK 69ALL_SDK_FILES:= 70 71# Files for dalvik. This is often build without building the rest of the OS. 72INTERNAL_DALVIK_MODULES:= 73 74# All findbugs xml files 75ALL_FINDBUGS_FILES:= 76 77# GPL module license files 78ALL_GPL_MODULE_LICENSE_FILES:= 79 80# Target and host installed module's dependencies on shared libraries. 81# They are list of "<module_name>:<installed_file>:lib1,lib2...". 82TARGET_DEPENDENCIES_ON_SHARED_LIBRARIES := 83$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_DEPENDENCIES_ON_SHARED_LIBRARIES := 84HOST_DEPENDENCIES_ON_SHARED_LIBRARIES := 85$(HOST_2ND_ARCH_VAR_PREFIX)HOST_DEPENDENCIES_ON_SHARED_LIBRARIES := 86HOST_CROSS_DEPENDENCIES_ON_SHARED_LIBRARIES := 87$(HOST_CROSS_2ND_ARCH_VAR_PREFIX)HOST_CROSS_DEPENDENCIES_ON_SHARED_LIBRARIES := 88 89# Generated class file names for Android resource. 90# They are escaped and quoted so can be passed safely to a bash command. 91ANDROID_RESOURCE_GENERATED_CLASSES := 'R.class' 'R$$*.class' 'Manifest.class' 'Manifest$$*.class' 92 93# Display names for various build targets 94TARGET_DISPLAY := target 95HOST_DISPLAY := host 96HOST_CROSS_DISPLAY := host cross 97 98# All installed initrc files 99ALL_INIT_RC_INSTALLED_PAIRS := 100 101########################################################### 102## Debugging; prints a variable list to stdout 103########################################################### 104 105# $(1): variable name list, not variable values 106define print-vars 107$(foreach var,$(1), \ 108 $(info $(var):) \ 109 $(foreach word,$($(var)), \ 110 $(info $(space)$(space)$(word)) \ 111 ) \ 112 ) 113endef 114 115########################################################### 116## Evaluates to true if the string contains the word true, 117## and empty otherwise 118## $(1): a var to test 119########################################################### 120 121define true-or-empty 122$(filter true, $(1)) 123endef 124 125 126########################################################### 127## Retrieve the directory of the current makefile 128## Must be called before including any other makefile!! 129########################################################### 130 131# Figure out where we are. 132define my-dir 133$(strip \ 134 $(eval LOCAL_MODULE_MAKEFILE := $$(lastword $$(MAKEFILE_LIST))) \ 135 $(if $(filter $(BUILD_SYSTEM)/% $(OUT_DIR)/%,$(LOCAL_MODULE_MAKEFILE)), \ 136 $(error my-dir must be called before including any other makefile.) \ 137 , \ 138 $(patsubst %/,%,$(dir $(LOCAL_MODULE_MAKEFILE))) \ 139 ) \ 140 ) 141endef 142 143 144########################################################### 145## Retrieve a list of all makefiles immediately below some directory 146########################################################### 147 148define all-makefiles-under 149$(wildcard $(1)/*/Android.mk) 150endef 151 152########################################################### 153## Look under a directory for makefiles that don't have parent 154## makefiles. 155########################################################### 156 157# $(1): directory to search under 158# Ignores $(1)/Android.mk 159define first-makefiles-under 160$(shell build/tools/findleaves.py $(FIND_LEAVES_EXCLUDES) \ 161 --mindepth=2 $(addprefix --dir=,$(1)) Android.mk) 162endef 163 164########################################################### 165## Retrieve a list of all makefiles immediately below your directory 166## Must be called before including any other makefile!! 167########################################################### 168 169define all-subdir-makefiles 170$(call all-makefiles-under,$(call my-dir)) 171endef 172 173########################################################### 174## Look in the named list of directories for makefiles, 175## relative to the current directory. 176## Must be called before including any other makefile!! 177########################################################### 178 179# $(1): List of directories to look for under this directory 180define all-named-subdir-makefiles 181$(wildcard $(addsuffix /Android.mk, $(addprefix $(call my-dir)/,$(1)))) 182endef 183 184########################################################### 185## Find all of the directories under the named directories with 186## the specified name. 187## Meant to be used like: 188## INC_DIRS := $(call all-named-dirs-under,inc,.) 189########################################################### 190 191define all-named-dirs-under 192$(call find-subdir-files,$(2) -type d -name "$(1)") 193endef 194 195########################################################### 196## Find all the directories under the current directory that 197## haves name that match $(1) 198########################################################### 199 200define all-subdir-named-dirs 201$(call all-named-dirs-under,$(1),.) 202endef 203 204########################################################### 205## Find all of the files under the named directories with 206## the specified name. 207## Meant to be used like: 208## SRC_FILES := $(call all-named-files-under,*.h,src tests) 209########################################################### 210 211define all-named-files-under 212$(call find-files-in-subdirs,$(LOCAL_PATH),"$(1)",$(2)) 213endef 214 215########################################################### 216## Find all of the files under the current directory with 217## the specified name. 218########################################################### 219 220define all-subdir-named-files 221$(call all-named-files-under,$(1),.) 222endef 223 224########################################################### 225## Find all of the java files under the named directories. 226## Meant to be used like: 227## SRC_FILES := $(call all-java-files-under,src tests) 228########################################################### 229 230define all-java-files-under 231$(call all-named-files-under,*.java,$(1)) 232endef 233 234########################################################### 235## Find all of the java files from here. Meant to be used like: 236## SRC_FILES := $(call all-subdir-java-files) 237########################################################### 238 239define all-subdir-java-files 240$(call all-java-files-under,.) 241endef 242 243########################################################### 244## Find all of the c files under the named directories. 245## Meant to be used like: 246## SRC_FILES := $(call all-c-files-under,src tests) 247########################################################### 248 249define all-c-files-under 250$(call all-named-files-under,*.c,$(1)) 251endef 252 253########################################################### 254## Find all of the c files from here. Meant to be used like: 255## SRC_FILES := $(call all-subdir-c-files) 256########################################################### 257 258define all-subdir-c-files 259$(call all-c-files-under,.) 260endef 261 262########################################################### 263## Find all of the cpp files under the named directories. 264## LOCAL_CPP_EXTENSION is respected if set. 265## Meant to be used like: 266## SRC_FILES := $(call all-cpp-files-under,src tests) 267########################################################### 268 269define all-cpp-files-under 270$(sort $(patsubst ./%,%, \ 271 $(shell cd $(LOCAL_PATH) ; \ 272 find -L $(1) -name "*$(or $(LOCAL_CPP_EXTENSION),.cpp)" -and -not -name ".*") \ 273 )) 274endef 275 276########################################################### 277## Find all of the cpp files from here. Meant to be used like: 278## SRC_FILES := $(call all-subdir-cpp-files) 279########################################################### 280 281define all-subdir-cpp-files 282$(call all-cpp-files-under,.) 283endef 284 285########################################################### 286## Find all files named "I*.aidl" under the named directories, 287## which must be relative to $(LOCAL_PATH). The returned list 288## is relative to $(LOCAL_PATH). 289########################################################### 290 291define all-Iaidl-files-under 292$(call all-named-files-under,I*.aidl,$(1)) 293endef 294 295########################################################### 296## Find all of the "I*.aidl" files under $(LOCAL_PATH). 297########################################################### 298 299define all-subdir-Iaidl-files 300$(call all-Iaidl-files-under,.) 301endef 302 303########################################################### 304## Find all files named "*.vts" under the named directories, 305## which must be relative to $(LOCAL_PATH). The returned list 306## is relative to $(LOCAL_PATH). 307########################################################### 308 309define all-vts-files-under 310$(call all-named-files-under,*.vts,$(1)) 311endef 312 313########################################################### 314## Find all of the "*.vts" files under $(LOCAL_PATH). 315########################################################### 316 317define all-subdir-vts-files 318$(call all-vts-files-under,.) 319endef 320 321########################################################### 322## Find all of the logtags files under the named directories. 323## Meant to be used like: 324## SRC_FILES := $(call all-logtags-files-under,src) 325########################################################### 326 327define all-logtags-files-under 328$(call all-named-files-under,*.logtags,$(1)) 329endef 330 331########################################################### 332## Find all of the .proto files under the named directories. 333## Meant to be used like: 334## SRC_FILES := $(call all-proto-files-under,src) 335########################################################### 336 337define all-proto-files-under 338$(call all-named-files-under,*.proto,$(1)) 339endef 340 341########################################################### 342## Find all of the RenderScript files under the named directories. 343## Meant to be used like: 344## SRC_FILES := $(call all-renderscript-files-under,src) 345########################################################### 346 347define all-renderscript-files-under 348$(call find-subdir-files,$(1) \( -name "*.rs" -or -name "*.fs" \) -and -not -name ".*") 349endef 350 351########################################################### 352## Find all of the S files under the named directories. 353## Meant to be used like: 354## SRC_FILES := $(call all-c-files-under,src tests) 355########################################################### 356 357define all-S-files-under 358$(call all-named-files-under,*.S,$(1)) 359endef 360 361########################################################### 362## Find all of the html files under the named directories. 363## Meant to be used like: 364## SRC_FILES := $(call all-html-files-under,src tests) 365########################################################### 366 367define all-html-files-under 368$(call all-named-files-under,*.html,$(1)) 369endef 370 371########################################################### 372## Find all of the html files from here. Meant to be used like: 373## SRC_FILES := $(call all-subdir-html-files) 374########################################################### 375 376define all-subdir-html-files 377$(call all-html-files-under,.) 378endef 379 380########################################################### 381## Find all of the files matching pattern 382## SRC_FILES := $(call find-subdir-files, <pattern>) 383########################################################### 384 385define find-subdir-files 386$(sort $(patsubst ./%,%,$(shell cd $(LOCAL_PATH) ; find -L $(1)))) 387endef 388 389########################################################### 390# find the files in the subdirectory $1 of LOCAL_DIR 391# matching pattern $2, filtering out files $3 392# e.g. 393# SRC_FILES += $(call find-subdir-subdir-files, \ 394# css, *.cpp, DontWantThis.cpp) 395########################################################### 396 397define find-subdir-subdir-files 398$(sort $(filter-out $(patsubst %,$(1)/%,$(3)),$(patsubst ./%,%,$(shell cd \ 399 $(LOCAL_PATH) ; find -L $(1) -maxdepth 1 -name $(2))))) 400endef 401 402########################################################### 403## Find all of the files matching pattern 404## SRC_FILES := $(call all-subdir-java-files) 405########################################################### 406 407define find-subdir-assets 408$(sort $(if $(1),$(patsubst ./%,%, \ 409 $(shell if [ -d $(1) ] ; then cd $(1) ; find -L ./ -not -name '.*' -and -type f ; fi)), \ 410 $(warning Empty argument supplied to find-subdir-assets) \ 411)) 412endef 413 414########################################################### 415## Find various file types in a list of directories relative to $(LOCAL_PATH) 416########################################################### 417 418define find-other-java-files 419$(call all-java-files-under,$(1)) 420endef 421 422define find-other-html-files 423$(call all-html-files-under,$(1)) 424endef 425 426########################################################### 427# Use utility find to find given files in the given subdirs. 428# This function uses $(1), instead of LOCAL_PATH as the base. 429# $(1): the base dir, relative to the root of the source tree. 430# $(2): the file name pattern to be passed to find as "-name". 431# $(3): a list of subdirs of the base dir. 432# Returns: a list of paths relative to the base dir. 433########################################################### 434 435define find-files-in-subdirs 436$(sort $(patsubst ./%,%, \ 437 $(shell cd $(1) ; \ 438 find -L $(3) -name $(2) -and -not -name ".*") \ 439 )) 440endef 441 442########################################################### 443## Scan through each directory of $(1) looking for files 444## that match $(2) using $(wildcard). Useful for seeing if 445## a given directory or one of its parents contains 446## a particular file. Returns the first match found, 447## starting furthest from the root. 448########################################################### 449 450define find-parent-file 451$(strip \ 452 $(eval _fpf := $(sort $(wildcard $(foreach f, $(2), $(strip $(1))/$(f))))) \ 453 $(if $(_fpf),$(_fpf), \ 454 $(if $(filter-out ./ .,$(1)), \ 455 $(call find-parent-file,$(patsubst %/,%,$(dir $(1))),$(2)) \ 456 ) \ 457 ) \ 458) 459endef 460 461########################################################### 462## Function we can evaluate to introduce a dynamic dependency 463########################################################### 464 465define add-dependency 466$(1): $(2) 467endef 468 469########################################################### 470## Reverse order of a list 471########################################################### 472 473define reverse-list 474$(if $(1),$(call reverse-list,$(wordlist 2,$(words $(1)),$(1)))) $(firstword $(1)) 475endef 476 477########################################################### 478## The intermediates directory. Where object files go for 479## a given target. We could technically get away without 480## the "_intermediates" suffix on the directory, but it's 481## nice to be able to grep for that string to find out if 482## anyone's abusing the system. 483########################################################### 484 485# $(1): target class, like "APPS" 486# $(2): target name, like "NotePad" 487# $(3): if non-empty, this is a HOST target. 488# $(4): if non-empty, force the intermediates to be COMMON 489# $(5): if non-empty, force the intermediates to be for the 2nd arch 490# $(6): if non-empty, force the intermediates to be for the host cross os 491define intermediates-dir-for 492$(strip \ 493 $(eval _idfClass := $(strip $(1))) \ 494 $(if $(_idfClass),, \ 495 $(error $(LOCAL_PATH): Class not defined in call to intermediates-dir-for)) \ 496 $(eval _idfName := $(strip $(2))) \ 497 $(if $(_idfName),, \ 498 $(error $(LOCAL_PATH): Name not defined in call to intermediates-dir-for)) \ 499 $(eval _idfPrefix := $(if $(strip $(3)),$(if $(strip $(6)),HOST_CROSS,HOST),TARGET)) \ 500 $(eval _idf2ndArchPrefix := $(if $(strip $(5)),$(TARGET_2ND_ARCH_VAR_PREFIX))) \ 501 $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \ 502 $(eval _idfIntBase := $($(_idfPrefix)_OUT_COMMON_INTERMEDIATES)) \ 503 ,$(if $(filter $(_idfClass),$(PER_ARCH_MODULE_CLASSES)),\ 504 $(eval _idfIntBase := $($(_idf2ndArchPrefix)$(_idfPrefix)_OUT_INTERMEDIATES)) \ 505 ,$(eval _idfIntBase := $($(_idfPrefix)_OUT_INTERMEDIATES)) \ 506 ) \ 507 ) \ 508 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \ 509) 510endef 511 512# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE 513# to determine the intermediates directory. 514# 515# $(1): if non-empty, force the intermediates to be COMMON 516# $(2): if non-empty, force the intermediates to be for the 2nd arch 517# $(3): if non-empty, force the intermediates to be for the host cross os 518define local-intermediates-dir 519$(strip \ 520 $(if $(strip $(LOCAL_MODULE_CLASS)),, \ 521 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-intermediates-dir)) \ 522 $(if $(strip $(LOCAL_MODULE)),, \ 523 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-intermediates-dir)) \ 524 $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(LOCAL_IS_HOST_MODULE),$(1),$(2),$(3)) \ 525) 526endef 527 528########################################################### 529## The generated sources directory. Placing generated 530## source files directly in the intermediates directory 531## causes problems for multiarch builds, where there are 532## two intermediates directories for a single target. Put 533## them in a separate directory, and they will be copied to 534## each intermediates directory automatically. 535########################################################### 536 537# $(1): target class, like "APPS" 538# $(2): target name, like "NotePad" 539# $(3): if non-empty, this is a HOST target. 540# $(4): if non-empty, force the generated sources to be COMMON 541define generated-sources-dir-for 542$(strip \ 543 $(eval _idfClass := $(strip $(1))) \ 544 $(if $(_idfClass),, \ 545 $(error $(LOCAL_PATH): Class not defined in call to generated-sources-dir-for)) \ 546 $(eval _idfName := $(strip $(2))) \ 547 $(if $(_idfName),, \ 548 $(error $(LOCAL_PATH): Name not defined in call to generated-sources-dir-for)) \ 549 $(eval _idfPrefix := $(if $(strip $(3)),HOST,TARGET)) \ 550 $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \ 551 $(eval _idfIntBase := $($(_idfPrefix)_OUT_COMMON_GEN)) \ 552 , \ 553 $(eval _idfIntBase := $($(_idfPrefix)_OUT_GEN)) \ 554 ) \ 555 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \ 556) 557endef 558 559# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE 560# to determine the generated sources directory. 561# 562# $(1): if non-empty, force the intermediates to be COMMON 563define local-generated-sources-dir 564$(strip \ 565 $(if $(strip $(LOCAL_MODULE_CLASS)),, \ 566 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-generated-sources-dir)) \ 567 $(if $(strip $(LOCAL_MODULE)),, \ 568 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-generated-sources-dir)) \ 569 $(call generated-sources-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(LOCAL_IS_HOST_MODULE),$(1)) \ 570) 571endef 572 573########################################################### 574## Convert "path/to/libXXX.so" to "-lXXX". 575## Any "path/to/libXXX.a" elements pass through unchanged. 576########################################################### 577 578define normalize-libraries 579$(foreach so,$(filter %.so,$(1)),-l$(patsubst lib%.so,%,$(notdir $(so))))\ 580$(filter-out %.so,$(1)) 581endef 582 583# TODO: change users to call the common version. 584define normalize-host-libraries 585$(call normalize-libraries,$(1)) 586endef 587 588define normalize-target-libraries 589$(call normalize-libraries,$(1)) 590endef 591 592########################################################### 593## Convert a list of short module names (e.g., "framework", "Browser") 594## into the list of files that are built for those modules. 595## NOTE: this won't return reliable results until after all 596## sub-makefiles have been included. 597## $(1): target list 598########################################################### 599 600define module-built-files 601$(foreach module,$(1),$(ALL_MODULES.$(module).BUILT)) 602endef 603 604########################################################### 605## Convert a list of short modules names (e.g., "framework", "Browser") 606## into the list of files that are installed for those modules. 607## NOTE: this won't return reliable results until after all 608## sub-makefiles have been included. 609## $(1): target list 610########################################################### 611 612define module-installed-files 613$(foreach module,$(1),$(ALL_MODULES.$(module).INSTALLED)) 614endef 615 616########################################################### 617## Convert a list of short modules names (e.g., "framework", "Browser") 618## into the list of files that should be used when linking 619## against that module as a public API. 620## TODO: Allow this for more than JAVA_LIBRARIES modules 621## NOTE: this won't return reliable results until after all 622## sub-makefiles have been included. 623## $(1): target list 624########################################################### 625 626define module-stubs-files 627$(foreach module,$(1),$(ALL_MODULES.$(module).STUBS)) 628endef 629 630########################################################### 631## Evaluates to the timestamp file for a doc module, which 632## is the dependency that should be used. 633## $(1): doc module 634########################################################### 635 636define doc-timestamp-for 637$(OUT_DOCS)/$(strip $(1))-timestamp 638endef 639 640 641########################################################### 642## Convert "core ext framework" to "out/.../javalib.jar ..." 643## $(1): library list 644## $(2): Non-empty if IS_HOST_MODULE 645########################################################### 646 647# $(1): library name 648# $(2): Non-empty if IS_HOST_MODULE 649define _java-lib-dir 650$(call intermediates-dir-for, \ 651 JAVA_LIBRARIES,$(1),$(2),COMMON) 652endef 653 654# $(1): library name 655# $(2): Non-empty if IS_HOST_MODULE 656define _java-lib-full-classes.jar 657$(call _java-lib-dir,$(1),$(2))/$(if $(2),javalib,classes)$(COMMON_JAVA_PACKAGE_SUFFIX) 658endef 659 660# Get the jar files (you can pass to "javac -classpath") of static or shared 661# Java libraries that you want to link against. 662# $(1): library name list 663# $(2): Non-empty if IS_HOST_MODULE 664define java-lib-files 665$(foreach lib,$(1),$(call _java-lib-full-classes.jar,$(lib),$(2))) 666endef 667 668# Get the dependency files (you can put on the right side of "|" of a build rule) 669# of the Java libraries. 670# $(1): library name list 671# $(2): Non-empty if IS_HOST_MODULE 672# Historically for target Java libraries we used a different file (javalib.jar) 673# as the dependency. 674# Now we can use classes.jar as dependency, so java-lib-deps is the same 675# as java-lib-files. 676define java-lib-deps 677$(call java-lib-files,$(1),$(2)) 678endef 679 680# Get the jar files (you can pass to "javac -classpath") of host dalvik Java libraries. 681# You can also use them as dependency files. 682# A host dalvik Java library is different from a host Java library in that 683# the java lib file is classes.jar, not javalib.jar. 684# $(1): library name list 685define host-dex-java-lib-files 686$(foreach lib,$(1),$(call _java-lib-dir,$(lib),true)/classes.jar) 687endef 688 689########################################################### 690## Convert "core ext framework" to "out/.../classes.jack ..." 691## $(1): library list 692## $(2): Non-empty if IS_HOST_MODULE 693########################################################### 694 695# $(1): library name 696# $(2): Non-empty if IS_HOST_MODULE 697define _jack-lib-full-classes 698$(call _java-lib-dir,$(1),$(2))/classes.jack 699endef 700 701# $(1): library name list 702# $(2): Non-empty if IS_HOST_MODULE 703define jack-lib-files 704$(foreach lib,$(1),$(call _jack-lib-full-classes,$(lib),$(2))) 705endef 706 707########################################################### 708## Run rot13 on a string 709## $(1): the string. Must be one line. 710########################################################### 711define rot13 712$(shell echo $(1) | tr 'a-zA-Z' 'n-za-mN-ZA-M') 713endef 714 715 716########################################################### 717## Returns true if $(1) and $(2) are equal. Returns 718## the empty string if they are not equal. 719########################################################### 720define streq 721$(strip $(if $(strip $(1)),\ 722 $(if $(strip $(2)),\ 723 $(if $(filter-out __,_$(subst $(strip $(1)),,$(strip $(2)))$(subst $(strip $(2)),,$(strip $(1)))_),,true), \ 724 ),\ 725 $(if $(strip $(2)),\ 726 ,\ 727 true)\ 728 )) 729endef 730 731########################################################### 732## Convert "a b c" into "a:b:c" 733########################################################### 734define normalize-path-list 735$(subst $(space),:,$(strip $(1))) 736endef 737 738########################################################### 739## Read the word out of a colon-separated list of words. 740## This has the same behavior as the built-in function 741## $(word n,str). 742## 743## The individual words may not contain spaces. 744## 745## $(1): 1 based index 746## $(2): value of the form a:b:c... 747########################################################### 748 749define word-colon 750$(word $(1),$(subst :,$(space),$(2))) 751endef 752 753########################################################### 754## Convert "a=b c= d e = f" into "a=b c=d e=f" 755## 756## $(1): list to collapse 757## $(2): if set, separator word; usually "=", ":", or ":=" 758## Defaults to "=" if not set. 759########################################################### 760 761define collapse-pairs 762$(eval _cpSEP := $(strip $(if $(2),$(2),=)))\ 763$(subst $(space)$(_cpSEP)$(space),$(_cpSEP),$(strip \ 764 $(subst $(_cpSEP), $(_cpSEP) ,$(1)))) 765endef 766 767########################################################### 768## Given a list of pairs, if multiple pairs have the same 769## first components, keep only the first pair. 770## 771## $(1): list of pairs 772## $(2): the separator word, such as ":", "=", etc. 773define uniq-pairs-by-first-component 774$(eval _upbfc_fc_set :=)\ 775$(strip $(foreach w,$(1), $(eval _first := $(word 1,$(subst $(2),$(space),$(w))))\ 776 $(if $(filter $(_upbfc_fc_set),$(_first)),,$(w)\ 777 $(eval _upbfc_fc_set += $(_first)))))\ 778$(eval _upbfc_fc_set :=)\ 779$(eval _first:=) 780endef 781 782########################################################### 783## MODULE_TAG set operations 784########################################################### 785 786# Given a list of tags, return the targets that specify 787# any of those tags. 788# $(1): tag list 789define modules-for-tag-list 790$(sort $(foreach tag,$(1),$(foreach m,$(ALL_MODULE_NAME_TAGS.$(tag)),$(ALL_MODULES.$(m).INSTALLED)))) 791endef 792 793# Same as modules-for-tag-list, but operates on 794# ALL_MODULE_NAME_TAGS. 795# $(1): tag list 796define module-names-for-tag-list 797$(sort $(foreach tag,$(1),$(ALL_MODULE_NAME_TAGS.$(tag)))) 798endef 799 800# Given an accept and reject list, find the matching 801# set of targets. If a target has multiple tags and 802# any of them are rejected, the target is rejected. 803# Reject overrides accept. 804# $(1): list of tags to accept 805# $(2): list of tags to reject 806#TODO(dbort): do $(if $(strip $(1)),$(1),$(ALL_MODULE_TAGS)) 807#TODO(jbq): as of 20100106 nobody uses the second parameter 808define get-tagged-modules 809$(filter-out \ 810 $(call modules-for-tag-list,$(2)), \ 811 $(call modules-for-tag-list,$(1))) 812endef 813 814########################################################### 815## Append a leaf to a base path. Properly deals with 816## base paths ending in /. 817## 818## $(1): base path 819## $(2): leaf path 820########################################################### 821 822define append-path 823$(subst //,/,$(1)/$(2)) 824endef 825 826 827########################################################### 828## Color-coded warnings and errors in build rules 829## 830## $(1): message to print 831########################################################### 832define echo-warning 833echo -e "\e[1;35mwarning:\e[0m \e[1m" $(1) "\e[0m\n" 834endef 835 836define echo-error 837echo -e "\e[1;31merror:\e[0m \e[1m" $(1) "\e[0m\n" 838endef 839 840 841########################################################### 842## Package filtering 843########################################################### 844 845# Given a list of installed modules (short or long names) 846# return a list of the packages (yes, .apk packages, not 847# modules in general) that are overridden by this list and, 848# therefore, should not be installed. 849# $(1): mixed list of installed modules 850# TODO: This is fragile; find a reliable way to get this information. 851define _get-package-overrides 852 $(eval ### Discard any words containing slashes, unless they end in .apk, \ 853 ### in which case trim off the directory component and the suffix. \ 854 ### If there are no slashes, keep the entire word.) 855 $(eval _gpo_names := $(subst /,@@@ @@@,$(1))) 856 $(eval _gpo_names := \ 857 $(filter %.apk,$(_gpo_names)) \ 858 $(filter-out %@@@ @@@%,$(_gpo_names))) 859 $(eval _gpo_names := $(patsubst %.apk,%,$(_gpo_names))) 860 $(eval _gpo_names := $(patsubst @@@%,%,$(_gpo_names))) 861 862 $(eval ### Remove any remaining words that contain dots.) 863 $(eval _gpo_names := $(subst .,@@@ @@@,$(_gpo_names))) 864 $(eval _gpo_names := $(filter-out %@@@ @@@%,$(_gpo_names))) 865 866 $(eval ### Now we have a list of any words that could possibly refer to \ 867 ### packages, although there may be words that do not. Only \ 868 ### real packages will be present under PACKAGES.*, though.) 869 $(foreach _gpo_name,$(_gpo_names),$(PACKAGES.$(_gpo_name).OVERRIDES)) 870endef 871 872define get-package-overrides 873$(sort $(strip $(call _get-package-overrides,$(1)))) 874endef 875 876########################################################### 877## Output the command lines, or not 878########################################################### 879 880ifeq ($(strip $(SHOW_COMMANDS)),) 881define pretty 882@echo $1 883endef 884else 885define pretty 886endef 887endif 888 889########################################################### 890## Commands for munging the dependency files the compiler generates 891########################################################### 892# $(1): the input .d file 893# $(2): the output .P file 894define transform-d-to-p-args 895$(hide) cp $(1) $(2); \ 896 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ 897 -e '/^$$/ d' -e 's/$$/ :/' < $(1) >> $(2); \ 898 rm -f $(1) 899endef 900 901define transform-d-to-p 902$(call transform-d-to-p-args,$(@:%.o=%.d),$(@:%.o=%.P)) 903endef 904 905########################################################### 906## Commands for including the dependency files the compiler generates 907########################################################### 908# $(1): the .P file 909# $(2): the main build target 910define include-depfile 911$(eval $(2) : .KATI_DEPFILE := $1) 912endef 913 914# $(1): object files 915define include-depfiles-for-objs 916$(foreach obj, $(1), $(call include-depfile, $(obj:%.o=%.P), $(obj))) 917endef 918 919########################################################### 920## Track source files compiled to objects 921########################################################### 922# $(1): list of sources 923# $(2): list of matching objects 924define track-src-file-obj 925$(eval $(call _track-src-file-obj,$(1))) 926endef 927define _track-src-file-obj 928i := w 929$(foreach s,$(1), 930my_tracked_src_files += $(s) 931my_src_file_obj_$(s) := $$(word $$(words $$(i)),$$(2)) 932i += w) 933endef 934 935# $(1): list of sources 936# $(2): list of matching generated sources 937define track-src-file-gen 938$(eval $(call _track-src-file-gen,$(2))) 939endef 940define _track-src-file-gen 941i := w 942$(foreach s,$(1), 943my_tracked_gen_files += $(s) 944my_src_file_gen_$(s) := $$(word $$(words $$(i)),$$(1)) 945i += w) 946endef 947 948# $(1): list of generated sources 949# $(2): list of matching objects 950define track-gen-file-obj 951$(call track-src-file-obj,$(foreach f,$(1),\ 952 $(or $(my_src_file_gen_$(f)),$(f))),$(2)) 953endef 954 955########################################################### 956## Commands for running lex 957########################################################### 958 959define transform-l-to-c-or-cpp 960@echo "Lex: $(PRIVATE_MODULE) <= $<" 961@mkdir -p $(dir $@) 962$(hide) $(LEX) -o$@ $< 963endef 964 965########################################################### 966## Commands for running yacc 967## 968########################################################### 969 970define transform-y-to-c-or-cpp 971@echo "Yacc: $(PRIVATE_MODULE) <= $<" 972@mkdir -p $(dir $@) 973$(YACC) $(PRIVATE_YACCFLAGS) \ 974 --defines=$(basename $@).h \ 975 -o $@ $< 976endef 977 978########################################################### 979## Commands to compile RenderScript to Java 980########################################################### 981 982## Merge multiple .d files generated by llvm-rs-cc. This is necessary 983## because ninja can handle only a single depfile per build target. 984## .d files generated by llvm-rs-cc define .stamp, .bc, and optionally 985## .java as build targets. However, there's no way to let ninja know 986## dependencies to .bc files and .java files, so we give up build 987## targets for them. As we write the .stamp file as the target by 988## ourselves, the awk script removes the first lines before the colon 989## and append a backslash to the last line to concatenate contents of 990## multiple files. 991# $(1): .d files to be merged 992# $(2): merged .d file 993define _merge-renderscript-d 994$(hide) echo '$@: $(backslash)' > $2 995$(foreach d,$1, \ 996 $(hide) awk 'start { sub(/( \\)?$$/, " \\"); print } /:/ { start=1 }' < $d >> $2$(newline)) 997$(hide) echo >> $2 998endef 999 1000define transform-renderscripts-to-java-and-bc 1001@echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)" 1002$(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR) 1003$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/res/raw 1004$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/src 1005$(hide) $(PRIVATE_RS_CC) \ 1006 -o $(PRIVATE_RS_OUTPUT_DIR)/res/raw \ 1007 -p $(PRIVATE_RS_OUTPUT_DIR)/src \ 1008 -d $(PRIVATE_RS_OUTPUT_DIR) \ 1009 -a $@ -MD \ 1010 $(addprefix -target-api , $(PRIVATE_RS_TARGET_API)) \ 1011 $(PRIVATE_RS_FLAGS) \ 1012 $(foreach inc,$(PRIVATE_RS_INCLUDES),$(addprefix -I , $(inc))) \ 1013 $(PRIVATE_RS_SOURCE_FILES) 1014$(call _merge-renderscript-d,$(PRIVATE_DEP_FILES),$@.d) 1015$(call transform-d-to-p-args,$@.d,$@.P) 1016$(hide) mkdir -p $(dir $@) 1017$(hide) touch $@ 1018endef 1019 1020define transform-bc-to-so 1021@echo "Renderscript compatibility: $(notdir $@) <= $(notdir $<)" 1022$(hide) mkdir -p $(dir $@) 1023$(hide) $(BCC_COMPAT) -O3 -o $(dir $@)/$(notdir $(<:.bc=.o)) -fPIC -shared \ 1024 -rt-path $(RS_PREBUILT_CLCORE) -mtriple $(RS_COMPAT_TRIPLE) $< 1025$(hide) $(PRIVATE_CXX) -shared -Wl,-soname,$(notdir $@) -nostdlib \ 1026 -Wl,-rpath,\$$ORIGIN/../lib \ 1027 $(dir $@)/$(notdir $(<:.bc=.o)) \ 1028 $(RS_PREBUILT_COMPILER_RT) \ 1029 -o $@ $(TARGET_GLOBAL_LDFLAGS) -Wl,--hash-style=sysv -L prebuilts/gcc/ \ 1030 $(RS_PREBUILT_LIBPATH) -L $(TARGET_OUT_INTERMEDIATE_LIBRARIES) \ 1031 -lRSSupport -lm -lc 1032endef 1033 1034########################################################### 1035## Commands to compile RenderScript to C++ 1036########################################################### 1037 1038define transform-renderscripts-to-cpp-and-bc 1039@echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)" 1040$(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR) 1041$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/ 1042$(hide) $(PRIVATE_RS_CC) \ 1043 -o $(PRIVATE_RS_OUTPUT_DIR)/ \ 1044 -d $(PRIVATE_RS_OUTPUT_DIR) \ 1045 -a $@ -MD \ 1046 -reflect-c++ \ 1047 $(addprefix -target-api , $(PRIVATE_RS_TARGET_API)) \ 1048 $(PRIVATE_RS_FLAGS) \ 1049 $(addprefix -I , $(PRIVATE_RS_INCLUDES)) \ 1050 $(PRIVATE_RS_SOURCE_FILES) 1051$(call _merge-renderscript-d,$(PRIVATE_DEP_FILES),$@.d) 1052$(call transform-d-to-p-args,$@.d,$@.P) 1053$(hide) mkdir -p $(dir $@) 1054$(hide) touch $@ 1055endef 1056 1057 1058########################################################### 1059## Commands for running aidl 1060########################################################### 1061 1062define transform-aidl-to-java 1063@mkdir -p $(dir $@) 1064@echo "Aidl: $(PRIVATE_MODULE) <= $<" 1065$(hide) $(AIDL) -d$(patsubst %.java,%.P,$@) $(PRIVATE_AIDL_FLAGS) $< $@ 1066endef 1067#$(AIDL) $(PRIVATE_AIDL_FLAGS) $< - | indent -nut -br -npcs -l1000 > $@ 1068 1069define transform-aidl-to-cpp 1070@mkdir -p $(dir $@) 1071@mkdir -p $(PRIVATE_HEADER_OUTPUT_DIR) 1072@echo "Generating C++ from AIDL: $(PRIVATE_MODULE) <= $<" 1073$(hide) $(AIDL_CPP) -d$(basename $@).aidl.P $(PRIVATE_AIDL_FLAGS) \ 1074 $< $(PRIVATE_HEADER_OUTPUT_DIR) $@ 1075endef 1076 1077## Given a .aidl file path, generate the rule to compile it a .java file 1078# $(1): a .aidl source file 1079# $(2): a directory to place the generated .java files in 1080# $(3): name of a variable to add the path to the generated source file to 1081# 1082# You must call this with $(eval). 1083define define-aidl-java-rule 1084define-aidl-java-rule-src := $(patsubst %.aidl,%.java,$(subst ../,dotdot/,$(addprefix $(2)/,$(1)))) 1085$$(define-aidl-java-rule-src) : $(LOCAL_PATH)/$(1) $(AIDL) 1086 $$(transform-aidl-to-java) 1087$(3) += $$(define-aidl-java-rule-src) 1088endef 1089 1090## Given a .aidl file path generate the rule to compile it a .cpp file. 1091# $(1): a .aidl source file 1092# $(2): a directory to place the generated .cpp files in 1093# $(3): name of a variable to add the path to the generated source file to 1094# 1095# You must call this with $(eval). 1096define define-aidl-cpp-rule 1097define-aidl-cpp-rule-src := $(patsubst %.aidl,%$(LOCAL_CPP_EXTENSION),$(subst ../,dotdot/,$(addprefix $(2)/,$(1)))) 1098$$(define-aidl-cpp-rule-src) : $(LOCAL_PATH)/$(1) $(AIDL_CPP) 1099 $$(transform-aidl-to-cpp) 1100$(3) += $$(define-aidl-cpp-rule-src) 1101endef 1102 1103########################################################### 1104## Commands for running vts 1105########################################################### 1106 1107define transform-vts-to-cpp 1108@mkdir -p $(dir $@) 1109@mkdir -p $(PRIVATE_HEADER_OUTPUT_DIR) 1110@echo "Generating C++ from VTS: $(PRIVATE_MODULE) <= $<" 1111$(hide) $(VTSC) -d$(basename $@).vts.P $(PRIVATE_VTS_FLAGS) \ 1112 $< $(PRIVATE_HEADER_OUTPUT_DIR) $@ 1113endef 1114 1115## Given a .vts file path generate the rule to compile it a .cpp file. 1116# $(1): a .vts source file 1117# $(2): a directory to place the generated .cpp files in 1118# $(3): name of a variable to add the path to the generated source file to 1119# 1120# You must call this with $(eval). 1121define define-vts-cpp-rule 1122define-vts-cpp-rule-src := $(patsubst %.vts,%$(LOCAL_CPP_EXTENSION),$(subst ../,dotdot/,$(addprefix $(2)/,$(1)))) 1123$$(define-vts-cpp-rule-src) : $(LOCAL_PATH)/$(1) $(VTSC) 1124 $$(transform-vts-to-cpp) 1125$(3) += $$(define-vts-cpp-rule-src) 1126endef 1127 1128########################################################### 1129## Commands for running java-event-log-tags.py 1130########################################################### 1131 1132define transform-logtags-to-java 1133@mkdir -p $(dir $@) 1134@echo "logtags: $@ <= $<" 1135$(hide) $(JAVATAGS) -o $@ $< $(PRIVATE_MERGED_TAG) 1136endef 1137 1138 1139########################################################### 1140## Commands for running protoc to compile .proto into .java 1141########################################################### 1142 1143define transform-proto-to-java 1144@mkdir -p $(dir $@) 1145@echo "Protoc: $@ <= $(PRIVATE_PROTO_SRC_FILES)" 1146@rm -rf $(PRIVATE_PROTO_JAVA_OUTPUT_DIR) 1147@mkdir -p $(PRIVATE_PROTO_JAVA_OUTPUT_DIR) 1148$(hide) for f in $(PRIVATE_PROTO_SRC_FILES); do \ 1149 $(PROTOC) \ 1150 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \ 1151 $(PRIVATE_PROTO_JAVA_OUTPUT_OPTION)="$(PRIVATE_PROTO_JAVA_OUTPUT_PARAMS):$(PRIVATE_PROTO_JAVA_OUTPUT_DIR)" \ 1152 $(PRIVATE_PROTOC_FLAGS) \ 1153 $$f || exit 33; \ 1154 done 1155$(hide) touch $@ 1156endef 1157 1158###################################################################### 1159## Commands for running protoc to compile .proto into .pb.cc (or.pb.c) and .pb.h 1160###################################################################### 1161define transform-proto-to-cc 1162@echo "Protoc: $@ <= $<" 1163@mkdir -p $(dir $@) 1164$(hide) $(PROTOC) \ 1165 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \ 1166 $(PRIVATE_PROTOC_FLAGS) \ 1167 $< 1168@# aprotoc outputs only .cc. Rename it to .cpp if necessary. 1169$(if $(PRIVATE_RENAME_CPP_EXT),\ 1170 $(hide) mv $(basename $@).cc $@) 1171endef 1172 1173 1174###################################################################### 1175## Commands for generating DBus adaptors from .dbus-xml files. 1176###################################################################### 1177define generate-dbus-adaptors 1178@echo "Generating DBus adaptors for $(PRIVATE_MODULE)" 1179@mkdir -p $(dir $@) 1180$(hide) $(DBUS_GENERATOR) \ 1181 --service-config=$(PRIVATE_DBUS_SERVICE_CONFIG) \ 1182 --adaptor=$@ \ 1183 $< 1184endef 1185 1186###################################################################### 1187## Commands for generating DBus proxies from .dbus-xml files. 1188###################################################################### 1189define generate-dbus-proxies 1190@echo "Generating DBus proxies for $(PRIVATE_MODULE)" 1191@mkdir -p $(dir $@) 1192$(hide) $(DBUS_GENERATOR) \ 1193 --service-config=$(PRIVATE_DBUS_SERVICE_CONFIG) \ 1194 --proxy=$@ \ 1195 $(filter %.dbus-xml,$^) 1196endef 1197 1198########################################################### 1199## Helper to set include paths form transform-*-to-o 1200########################################################### 1201define c-includes 1202$(addprefix -I , $(PRIVATE_C_INCLUDES)) \ 1203$$(cat $(PRIVATE_IMPORT_INCLUDES))\ 1204$(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),,\ 1205 $(addprefix -I ,\ 1206 $(filter-out $(PRIVATE_C_INCLUDES), \ 1207 $(PRIVATE_GLOBAL_C_INCLUDES))) \ 1208 $(addprefix -isystem ,\ 1209 $(filter-out $(PRIVATE_C_INCLUDES), \ 1210 $(PRIVATE_GLOBAL_C_SYSTEM_INCLUDES)))) 1211endef 1212 1213########################################################### 1214## Commands for running gcc to compile a C++ file 1215########################################################### 1216 1217define transform-cpp-to-o-compiler-args 1218 $(c-includes) \ 1219 -c \ 1220 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1221 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \ 1222 $(PRIVATE_TARGET_GLOBAL_CPPFLAGS) \ 1223 $(PRIVATE_ARM_CFLAGS) \ 1224 ) \ 1225 $(PRIVATE_RTTI_FLAG) \ 1226 $(PRIVATE_CFLAGS) \ 1227 $(PRIVATE_CPPFLAGS) \ 1228 $(PRIVATE_DEBUG_CFLAGS) \ 1229 $(PRIVATE_CFLAGS_NO_OVERRIDE) \ 1230 $(PRIVATE_CPPFLAGS_NO_OVERRIDE) 1231endef 1232 1233define clang-tidy-cpp 1234$(hide) $(PATH_TO_CLANG_TIDY) $(PRIVATE_TIDY_FLAGS) \ 1235 -checks=$(PRIVATE_TIDY_CHECKS) \ 1236 $< -- $(transform-cpp-to-o-compiler-args) 1237endef 1238 1239ifneq (,$(filter 1 true,$(WITH_TIDY_ONLY))) 1240define transform-cpp-to-o 1241$(if $(PRIVATE_TIDY_CHECKS), 1242 @echo "$($(PRIVATE_PREFIX)DISPLAY) tidy $(PRIVATE_ARM_MODE) C++: $<" 1243 $(clang-tidy-cpp)) 1244endef 1245else 1246define transform-cpp-to-o 1247@echo "$($(PRIVATE_PREFIX)DISPLAY) $(PRIVATE_ARM_MODE) C++: $(PRIVATE_MODULE) <= $<" 1248@mkdir -p $(dir $@) 1249$(if $(PRIVATE_TIDY_CHECKS),$(clang-tidy-cpp)) 1250$(hide) $(RELATIVE_PWD) $(PRIVATE_CXX) \ 1251 $(transform-cpp-to-o-compiler-args) \ 1252 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $< 1253$(hide) $(transform-d-to-p) 1254endef 1255endif 1256 1257 1258########################################################### 1259## Commands for running gcc to compile a C file 1260########################################################### 1261 1262# $(1): extra flags 1263define transform-c-or-s-to-o-compiler-args 1264 $(c-includes) \ 1265 -c \ 1266 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1267 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \ 1268 $(PRIVATE_TARGET_GLOBAL_CONLYFLAGS) \ 1269 $(PRIVATE_ARM_CFLAGS) \ 1270 ) \ 1271 $(1) 1272endef 1273 1274define transform-c-to-o-compiler-args 1275$(call transform-c-or-s-to-o-compiler-args, \ 1276 $(PRIVATE_CFLAGS) \ 1277 $(PRIVATE_CONLYFLAGS) \ 1278 $(PRIVATE_DEBUG_CFLAGS) \ 1279 $(PRIVATE_CFLAGS_NO_OVERRIDE)) 1280endef 1281 1282define clang-tidy-c 1283$(hide) $(PATH_TO_CLANG_TIDY) $(PRIVATE_TIDY_FLAGS) \ 1284 -checks=$(PRIVATE_TIDY_CHECKS) \ 1285 $< -- $(transform-c-to-o-compiler-args) 1286endef 1287 1288ifneq (,$(filter 1 true,$(WITH_TIDY_ONLY))) 1289define transform-c-to-o 1290$(if $(PRIVATE_TIDY_CHECKS), 1291 @echo "$($(PRIVATE_PREFIX)DISPLAY) tidy $(PRIVATE_ARM_MODE) C: $<" 1292 $(clang-tidy-c)) 1293endef 1294else 1295define transform-c-to-o 1296@echo "$($(PRIVATE_PREFIX)DISPLAY) $(PRIVATE_ARM_MODE) C: $(PRIVATE_MODULE) <= $<" 1297@mkdir -p $(dir $@) 1298$(if $(PRIVATE_TIDY_CHECKS),$(clang-tidy-c)) 1299$(hide) $(RELATIVE_PWD) $(PRIVATE_CC) \ 1300 $(transform-c-to-o-compiler-args) \ 1301 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $< 1302$(hide) $(transform-d-to-p) 1303endef 1304endif 1305 1306define transform-s-to-o-no-deps 1307@echo "$($(PRIVATE_PREFIX)DISPLAY) asm: $(PRIVATE_MODULE) <= $<" 1308@mkdir -p $(dir $@) 1309$(RELATIVE_PWD) $(PRIVATE_CC) \ 1310 $(call transform-c-or-s-to-o-compiler-args, $(PRIVATE_ASFLAGS)) \ 1311 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $< 1312endef 1313 1314define transform-s-to-o 1315$(transform-s-to-o-no-deps) 1316$(transform-d-to-p) 1317endef 1318 1319# YASM compilation 1320define transform-asm-to-o 1321@mkdir -p $(dir $@) 1322$(hide) $(YASM) \ 1323 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \ 1324 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_YASM_FLAGS) \ 1325 $(PRIVATE_ASFLAGS) \ 1326 -o $@ $< 1327endef 1328 1329########################################################### 1330## Commands for running gcc to compile an Objective-C file 1331## This should never happen for target builds but this 1332## will error at build time. 1333########################################################### 1334 1335define transform-m-to-o-no-deps 1336@echo "$($(PRIVATE_PREFIX)DISPLAY) ObjC: $(PRIVATE_MODULE) <= $<" 1337$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_DEBUG_CFLAGS)) 1338endef 1339 1340define transform-m-to-o 1341$(transform-m-to-o-no-deps) 1342$(transform-d-to-p) 1343endef 1344 1345########################################################### 1346## Commands for running gcc to compile a host C++ file 1347########################################################### 1348 1349define transform-host-cpp-to-o-compiler-args 1350 $(c-includes) \ 1351 -c \ 1352 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1353 $(PRIVATE_HOST_GLOBAL_CFLAGS) \ 1354 $(PRIVATE_HOST_GLOBAL_CPPFLAGS) \ 1355 ) \ 1356 $(PRIVATE_CFLAGS) \ 1357 $(PRIVATE_CPPFLAGS) \ 1358 $(PRIVATE_DEBUG_CFLAGS) \ 1359 $(PRIVATE_CFLAGS_NO_OVERRIDE) \ 1360 $(PRIVATE_CPPFLAGS_NO_OVERRIDE) 1361endef 1362 1363define clang-tidy-host-cpp 1364$(hide) $(PATH_TO_CLANG_TIDY) $(PRIVATE_TIDY_FLAGS) \ 1365 -checks=$(PRIVATE_TIDY_CHECKS) \ 1366 $< -- $(transform-host-cpp-to-o-compiler-args) 1367endef 1368 1369ifneq (,$(filter 1 true,$(WITH_TIDY_ONLY))) 1370define transform-host-cpp-to-o 1371$(if $(PRIVATE_TIDY_CHECKS), 1372 @echo "tidy $($(PRIVATE_PREFIX)DISPLAY) C++: $<" 1373 $(clang-tidy-host-cpp)) 1374endef 1375else 1376define transform-host-cpp-to-o 1377@echo "$($(PRIVATE_PREFIX)DISPLAY) C++: $(PRIVATE_MODULE) <= $<" 1378@mkdir -p $(dir $@) 1379$(if $(PRIVATE_TIDY_CHECKS),$(clang-tidy-host-cpp)) 1380$(hide) $(RELATIVE_PWD) $(PRIVATE_CXX) \ 1381 $(transform-host-cpp-to-o-compiler-args) \ 1382 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $< 1383$(hide) $(transform-d-to-p) 1384endef 1385endif 1386 1387 1388########################################################### 1389## Commands for running gcc to compile a host C file 1390########################################################### 1391 1392define transform-host-c-or-s-to-o-common-args 1393 $(c-includes) \ 1394 -c \ 1395 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1396 $(PRIVATE_HOST_GLOBAL_CFLAGS) \ 1397 $(PRIVATE_HOST_GLOBAL_CONLYFLAGS) \ 1398 ) 1399endef 1400 1401# $(1): extra flags 1402define transform-host-c-or-s-to-o-no-deps 1403@mkdir -p $(dir $@) 1404$(hide) $(RELATIVE_PWD) $(PRIVATE_CC) \ 1405 $(transform-host-c-or-s-to-o-common-args) \ 1406 $(1) \ 1407 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $< 1408endef 1409 1410define transform-host-c-to-o-compiler-args 1411 $(transform-host-c-or-s-to-o-common-args) \ 1412 $(PRIVATE_CFLAGS) $(PRIVATE_CONLYFLAGS) \ 1413 $(PRIVATE_DEBUG_CFLAGS) $(PRIVATE_CFLAGS_NO_OVERRIDE) 1414endef 1415 1416define clang-tidy-host-c 1417$(hide) $(PATH_TO_CLANG_TIDY) $(PRIVATE_TIDY_FLAGS) \ 1418 -checks=$(PRIVATE_TIDY_CHECKS) \ 1419 $< -- $(transform-host-c-to-o-compiler-args) 1420endef 1421 1422ifneq (,$(filter 1 true,$(WITH_TIDY_ONLY))) 1423define transform-host-c-to-o 1424$(if $(PRIVATE_TIDY_CHECKS), 1425 @echo "tidy $($(PRIVATE_PREFIX)DISPLAY) C: $<" 1426 $(clang-tidy-host-c)) 1427endef 1428else 1429define transform-host-c-to-o 1430@echo "$($(PRIVATE_PREFIX)DISPLAY) C: $(PRIVATE_MODULE) <= $<" 1431@mkdir -p $(dir $@) 1432$(if $(PRIVATE_TIDY_CHECKS), $(clang-tidy-host-c)) 1433$(hide) $(RELATIVE_PWD) $(PRIVATE_CC) \ 1434 $(transform-host-c-to-o-compiler-args) \ 1435 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $< 1436$(hide) $(transform-d-to-p) 1437endef 1438endif 1439 1440define transform-host-s-to-o-no-deps 1441@echo "$($(PRIVATE_PREFIX)DISPLAY) asm: $(PRIVATE_MODULE) <= $<" 1442$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS)) 1443endef 1444 1445define transform-host-s-to-o 1446$(transform-host-s-to-o-no-deps) 1447$(transform-d-to-p) 1448endef 1449 1450########################################################### 1451## Commands for running gcc to compile a host Objective-C file 1452########################################################### 1453 1454define transform-host-m-to-o-no-deps 1455@echo "$($(PRIVATE_PREFIX)DISPLAY) ObjC: $(PRIVATE_MODULE) <= $<" 1456$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_DEBUG_CFLAGS) $(PRIVATE_CFLAGS_NO_OVERRIDE)) 1457endef 1458 1459define transform-host-m-to-o 1460$(transform-host-m-to-o-no-deps) 1461$(transform-d-to-p) 1462endef 1463 1464########################################################### 1465## Commands for running gcc to compile a host Objective-C++ file 1466########################################################### 1467 1468define transform-host-mm-to-o 1469$(transform-host-cpp-to-o) 1470endef 1471 1472 1473########################################################### 1474## Rules to compile a single C/C++ source with ../ in the path 1475########################################################### 1476# Replace "../" in object paths with $(DOTDOT_REPLACEMENT). 1477DOTDOT_REPLACEMENT := dotdot/ 1478 1479## Rule to compile a C++ source file with ../ in the path. 1480## Must be called with $(eval). 1481# $(1): the C++ source file in LOCAL_SRC_FILES. 1482# $(2): the additional dependencies. 1483# $(3): the variable name to collect the output object file. 1484define compile-dotdot-cpp-file 1485o := $(intermediates)/$(patsubst %$(LOCAL_CPP_EXTENSION),%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1))) 1486$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2) 1487 $$(transform-$$(PRIVATE_HOST)cpp-to-o) 1488$$(call include-depfiles-for-objs, $$(o)) 1489$(3) += $$(o) 1490endef 1491 1492## Rule to compile a C source file with ../ in the path. 1493## Must be called with $(eval). 1494# $(1): the C source file in LOCAL_SRC_FILES. 1495# $(2): the additional dependencies. 1496# $(3): the variable name to collect the output object file. 1497define compile-dotdot-c-file 1498o := $(intermediates)/$(patsubst %.c,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1))) 1499$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2) 1500 $$(transform-$$(PRIVATE_HOST)c-to-o) 1501$$(call include-depfiles-for-objs, $$(o)) 1502$(3) += $$(o) 1503endef 1504 1505## Rule to compile a .S source file with ../ in the path. 1506## Must be called with $(eval). 1507# $(1): the .S source file in LOCAL_SRC_FILES. 1508# $(2): the additional dependencies. 1509# $(3): the variable name to collect the output object file. 1510define compile-dotdot-s-file 1511o := $(intermediates)/$(patsubst %.S,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1))) 1512$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2) 1513 $$(transform-$$(PRIVATE_HOST)s-to-o) 1514$$(call include-depfiles-for-objs, $$(o)) 1515$(3) += $$(o) 1516endef 1517 1518## Rule to compile a .s source file with ../ in the path. 1519## Must be called with $(eval). 1520# $(1): the .s source file in LOCAL_SRC_FILES. 1521# $(2): the additional dependencies. 1522# $(3): the variable name to collect the output object file. 1523define compile-dotdot-s-file-no-deps 1524o := $(intermediates)/$(patsubst %.s,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1))) 1525$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2) 1526 $$(transform-$$(PRIVATE_HOST)s-to-o-no-deps) 1527$(3) += $$(o) 1528endef 1529 1530########################################################### 1531## Commands for running ar 1532########################################################### 1533 1534define _concat-if-arg2-not-empty 1535$(if $(2),$(hide) $(1) $(2)) 1536endef 1537 1538# Split long argument list into smaller groups and call the command repeatedly 1539# Call the command at least once even if there are no arguments, as otherwise 1540# the output file won't be created. 1541# 1542# $(1): the command without arguments 1543# $(2): the arguments 1544define split-long-arguments 1545$(hide) $(1) $(wordlist 1,500,$(2)) 1546$(call _concat-if-arg2-not-empty,$(1),$(wordlist 501,1000,$(2))) 1547$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1001,1500,$(2))) 1548$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1501,2000,$(2))) 1549$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2001,2500,$(2))) 1550$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2501,3000,$(2))) 1551$(call _concat-if-arg2-not-empty,$(1),$(wordlist 3001,99999,$(2))) 1552endef 1553 1554# $(1): the full path of the source static library. 1555define _extract-and-include-single-target-whole-static-lib 1556$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\ 1557 rm -rf $$ldir; \ 1558 mkdir -p $$ldir; \ 1559 cp $(1) $$ldir; \ 1560 lib_to_include=$$ldir/$(notdir $(1)); \ 1561 filelist=; \ 1562 subdir=0; \ 1563 for f in `$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) t $(1)`; do \ 1564 if [ -e $$ldir/$$f ]; then \ 1565 mkdir $$ldir/$$subdir; \ 1566 ext=$$subdir/; \ 1567 subdir=$$((subdir+1)); \ 1568 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) m $$lib_to_include $$f; \ 1569 else \ 1570 ext=; \ 1571 fi; \ 1572 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) p $$lib_to_include $$f > $$ldir/$$ext$$f; \ 1573 filelist="$$filelist $$ldir/$$ext$$f"; \ 1574 done ; \ 1575 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \ 1576 $(PRIVATE_ARFLAGS) $@ $$filelist 1577 1578endef 1579 1580# $(1): the full path of the source static library. 1581define extract-and-include-whole-static-libs-first 1582$(if $(strip $(1)), 1583$(hide) cp $(1) $@) 1584endef 1585 1586define extract-and-include-target-whole-static-libs 1587$(call extract-and-include-whole-static-libs-first, $(firstword $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES))) 1588$(foreach lib,$(wordlist 2,999,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)), \ 1589 $(call _extract-and-include-single-target-whole-static-lib, $(lib))) 1590endef 1591 1592# Explicitly delete the archive first so that ar doesn't 1593# try to add to an existing archive. 1594define transform-o-to-static-lib 1595@echo "$($(PRIVATE_PREFIX)DISPLAY) StaticLib: $(PRIVATE_MODULE) ($@)" 1596@mkdir -p $(dir $@) 1597@rm -f $@ 1598$(extract-and-include-target-whole-static-libs) 1599$(call split-long-arguments,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) \ 1600 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \ 1601 $(PRIVATE_ARFLAGS) $@,$(PRIVATE_ALL_OBJECTS)) 1602endef 1603 1604########################################################### 1605## Commands for running host ar 1606########################################################### 1607 1608# $(1): the full path of the source static library. 1609define _extract-and-include-single-host-whole-static-lib 1610$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\ 1611 rm -rf $$ldir; \ 1612 mkdir -p $$ldir; \ 1613 cp $(1) $$ldir; \ 1614 lib_to_include=$$ldir/$(notdir $(1)); \ 1615 filelist=; \ 1616 subdir=0; \ 1617 for f in `$($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) t $(1) | \grep '\.o$$'`; do \ 1618 if [ -e $$ldir/$$f ]; then \ 1619 mkdir $$ldir/$$subdir; \ 1620 ext=$$subdir/; \ 1621 subdir=$$((subdir+1)); \ 1622 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) m $$lib_to_include $$f; \ 1623 else \ 1624 ext=; \ 1625 fi; \ 1626 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) p $$lib_to_include $$f > $$ldir/$$ext$$f; \ 1627 filelist="$$filelist $$ldir/$$ext$$f"; \ 1628 done ; \ 1629 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)GLOBAL_ARFLAGS) \ 1630 $(PRIVATE_ARFLAGS) $@ $$filelist 1631 1632endef 1633 1634define extract-and-include-host-whole-static-libs 1635$(call extract-and-include-whole-static-libs-first, $(firstword $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES))) 1636$(foreach lib,$(wordlist 2,999,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)), \ 1637 $(call _extract-and-include-single-host-whole-static-lib, $(lib))) 1638endef 1639 1640ifeq ($(HOST_OS),darwin) 1641# On Darwin the host ar fails if there is nothing to add to .a at all. 1642# We work around by adding a dummy.o and then deleting it. 1643define create-dummy.o-if-no-objs 1644$(if $(PRIVATE_ALL_OBJECTS),,$(hide) touch $(dir $@)dummy.o) 1645endef 1646 1647define get-dummy.o-if-no-objs 1648$(if $(PRIVATE_ALL_OBJECTS),,$(dir $@)dummy.o) 1649endef 1650 1651define delete-dummy.o-if-no-objs 1652$(if $(PRIVATE_ALL_OBJECTS),,$(hide) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) d $@ $(dir $@)dummy.o \ 1653 && rm -f $(dir $@)dummy.o) 1654endef 1655endif # HOST_OS is darwin 1656 1657# Explicitly delete the archive first so that ar doesn't 1658# try to add to an existing archive. 1659define transform-host-o-to-static-lib 1660@echo "$($(PRIVATE_PREFIX)DISPLAY) StaticLib: $(PRIVATE_MODULE) ($@)" 1661@mkdir -p $(dir $@) 1662@rm -f $@ 1663$(extract-and-include-host-whole-static-libs) 1664$(create-dummy.o-if-no-objs) 1665$(call split-long-arguments,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) \ 1666 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)GLOBAL_ARFLAGS) \ 1667 $(PRIVATE_ARFLAGS) $@,$(PRIVATE_ALL_OBJECTS) $(get-dummy.o-if-no-objs)) 1668$(delete-dummy.o-if-no-objs) 1669endef 1670 1671 1672########################################################### 1673## Commands for running gcc to link a shared library or package 1674########################################################### 1675 1676# ld just seems to be so finicky with command order that we allow 1677# it to be overriden en-masse see combo/linux-arm.make for an example. 1678ifneq ($(HOST_CUSTOM_LD_COMMAND),true) 1679define transform-host-o-to-shared-lib-inner 1680$(hide) $(PRIVATE_CXX) \ 1681 -Wl,-rpath-link=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)OUT_INTERMEDIATE_LIBRARIES) \ 1682 -Wl,-rpath,\$$ORIGIN/../$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)OUT_SHARED_LIBRARIES)) \ 1683 -Wl,-rpath,\$$ORIGIN/$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)OUT_SHARED_LIBRARIES)) \ 1684 -shared -Wl,-soname,$(notdir $@) \ 1685 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)GLOBAL_LD_DIRS) \ 1686 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1687 $(PRIVATE_HOST_GLOBAL_LDFLAGS) \ 1688 ) \ 1689 $(PRIVATE_LDFLAGS) \ 1690 $(PRIVATE_ALL_OBJECTS) \ 1691 -Wl,--whole-archive \ 1692 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 1693 -Wl,--no-whole-archive \ 1694 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ 1695 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 1696 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ 1697 $(if $(filter true,$(NATIVE_COVERAGE)),-lgcov) \ 1698 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_HOST_LIBPROFILE_RT)) \ 1699 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ 1700 -o $@ \ 1701 $(PRIVATE_LDLIBS) 1702endef 1703endif 1704 1705define transform-host-o-to-shared-lib 1706@echo "$($(PRIVATE_PREFIX)DISPLAY) SharedLib: $(PRIVATE_MODULE) ($@)" 1707@mkdir -p $(dir $@) 1708$(transform-host-o-to-shared-lib-inner) 1709endef 1710 1711define transform-host-o-to-package 1712@echo "$($(PRIVATE_PREFIX)DISPLAY) Package: $(PRIVATE_MODULE) ($@)" 1713@mkdir -p $(dir $@) 1714$(transform-host-o-to-shared-lib-inner) 1715endef 1716 1717 1718########################################################### 1719## Commands for running gcc to link a shared library or package 1720########################################################### 1721 1722define transform-o-to-shared-lib-inner 1723$(hide) $(PRIVATE_CXX) \ 1724 -nostdlib -Wl,-soname,$(notdir $@) \ 1725 -Wl,--gc-sections \ 1726 $(if $(filter true,$(PRIVATE_CLANG)),-shared,-Wl$(comma)-shared) \ 1727 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \ 1728 $(PRIVATE_TARGET_CRTBEGIN_SO_O) \ 1729 $(PRIVATE_ALL_OBJECTS) \ 1730 -Wl,--whole-archive \ 1731 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 1732 -Wl,--no-whole-archive \ 1733 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ 1734 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 1735 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ 1736 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_COVERAGE_LIB)) \ 1737 $(PRIVATE_TARGET_LIBATOMIC) \ 1738 $(PRIVATE_TARGET_LIBGCC) \ 1739 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \ 1740 $(PRIVATE_LDFLAGS) \ 1741 $(PRIVATE_ALL_SHARED_LIBRARIES) \ 1742 -o $@ \ 1743 $(PRIVATE_TARGET_CRTEND_SO_O) \ 1744 $(PRIVATE_LDLIBS) 1745endef 1746 1747define transform-o-to-shared-lib 1748@echo "$($(PRIVATE_PREFIX)DISPLAY) SharedLib: $(PRIVATE_MODULE) ($@)" 1749@mkdir -p $(dir $@) 1750$(transform-o-to-shared-lib-inner) 1751endef 1752 1753########################################################### 1754## Commands for filtering a target executable or library 1755########################################################### 1756 1757ifneq ($(TARGET_BUILD_VARIANT),user) 1758 TARGET_STRIP_EXTRA = && $(PRIVATE_OBJCOPY) --add-gnu-debuglink=$< $@ 1759 TARGET_STRIP_KEEP_SYMBOLS_EXTRA = --add-gnu-debuglink=$< 1760endif 1761 1762define transform-to-stripped 1763@echo "$($(PRIVATE_PREFIX)DISPLAY) Strip: $(PRIVATE_MODULE) ($@)" 1764@mkdir -p $(dir $@) 1765$(hide) $(PRIVATE_STRIP) --strip-all $< -o $@ \ 1766 $(if $(PRIVATE_NO_DEBUGLINK),,$(TARGET_STRIP_EXTRA)) 1767endef 1768 1769define transform-to-stripped-keep-mini-debug-info 1770@echo "$($(PRIVATE_PREFIX)DISPLAY) Strip (mini debug info): $(PRIVATE_MODULE) ($@)" 1771@mkdir -p $(dir $@) 1772$(hide) $(PRIVATE_NM) -D $< --format=posix --defined-only | awk '{ print $$1 }' | sort >$@.dynsyms 1773$(hide) $(PRIVATE_NM) $< --format=posix --defined-only | awk '{ if ($$2 == "T" || $$2 == "t" || $$2 == "D") print $$1 }' | sort >$@.funcsyms 1774$(hide) comm -13 $@.dynsyms $@.funcsyms >$@.keep_symbols 1775$(hide) $(PRIVATE_OBJCOPY) --only-keep-debug $< $@.debug 1776$(hide) $(PRIVATE_OBJCOPY) --rename-section .debug_frame=saved_debug_frame $@.debug $@.mini_debuginfo 1777$(hide) $(PRIVATE_OBJCOPY) -S --remove-section .gdb_index --remove-section .comment --keep-symbols=$@.keep_symbols $@.mini_debuginfo 1778$(hide) $(PRIVATE_OBJCOPY) --rename-section saved_debug_frame=.debug_frame $@.mini_debuginfo 1779$(hide) $(PRIVATE_STRIP) --strip-all -R .comment $< -o $@ 1780$(hide) rm -f $@.mini_debuginfo.xz 1781$(hide) xz $@.mini_debuginfo 1782$(hide) $(PRIVATE_OBJCOPY) --add-section .gnu_debugdata=$@.mini_debuginfo.xz $@ 1783$(hide) rm -f $@.dynsyms $@.funcsyms $@.keep_symbols $@.debug $@.mini_debuginfo.xz 1784endef 1785 1786define transform-to-stripped-keep-symbols 1787@echo "$($(PRIVATE_PREFIX)DISPLAY) Strip (keep symbols): $(PRIVATE_MODULE) ($@)" 1788@mkdir -p $(dir $@) 1789$(hide) $(PRIVATE_OBJCOPY) \ 1790 `$(PRIVATE_READELF) -S $< | awk '/.debug_/ {print "-R " $$2}' | xargs` \ 1791 $(TARGET_STRIP_KEEP_SYMBOLS_EXTRA) $< $@ 1792endef 1793 1794########################################################### 1795## Commands for packing a target executable or library 1796########################################################### 1797 1798define pack-elf-relocations 1799@echo "$($(PRIVATE_PREFIX)DISPLAY) Pack Relocations: $(PRIVATE_MODULE) ($@)" 1800$(copy-file-to-target) 1801$(hide) $(RELOCATION_PACKER) $@ 1802endef 1803 1804########################################################### 1805## Commands for running gcc to link an executable 1806########################################################### 1807 1808define transform-o-to-executable-inner 1809$(hide) $(PRIVATE_CXX) -pie \ 1810 -nostdlib -Bdynamic \ 1811 -Wl,-dynamic-linker,$(PRIVATE_LINKER) \ 1812 -Wl,--gc-sections \ 1813 -Wl,-z,nocopyreloc \ 1814 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \ 1815 -Wl,-rpath-link=$(PRIVATE_TARGET_OUT_INTERMEDIATE_LIBRARIES) \ 1816 $(PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O) \ 1817 $(PRIVATE_ALL_OBJECTS) \ 1818 -Wl,--whole-archive \ 1819 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 1820 -Wl,--no-whole-archive \ 1821 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ 1822 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 1823 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ 1824 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_COVERAGE_LIB)) \ 1825 $(PRIVATE_TARGET_LIBATOMIC) \ 1826 $(PRIVATE_TARGET_LIBGCC) \ 1827 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \ 1828 $(PRIVATE_LDFLAGS) \ 1829 $(PRIVATE_ALL_SHARED_LIBRARIES) \ 1830 -o $@ \ 1831 $(PRIVATE_TARGET_CRTEND_O) \ 1832 $(PRIVATE_LDLIBS) 1833endef 1834 1835define transform-o-to-executable 1836@echo "$($(PRIVATE_PREFIX)DISPLAY) Executable: $(PRIVATE_MODULE) ($@)" 1837@mkdir -p $(dir $@) 1838$(transform-o-to-executable-inner) 1839endef 1840 1841 1842########################################################### 1843## Commands for linking a static executable. In practice, 1844## we only use this on arm, so the other platforms don't 1845## have transform-o-to-static-executable defined. 1846## Clang driver needs -static to create static executable. 1847## However, bionic/linker uses -shared to overwrite. 1848## Linker for x86 targets does not allow coexistance of -static and -shared, 1849## so we add -static only if -shared is not used. 1850########################################################### 1851 1852define transform-o-to-static-executable-inner 1853$(hide) $(PRIVATE_CXX) \ 1854 -nostdlib -Bstatic \ 1855 $(if $(filter $(PRIVATE_LDFLAGS),-shared),,-static) \ 1856 -Wl,--gc-sections \ 1857 -o $@ \ 1858 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \ 1859 $(PRIVATE_TARGET_CRTBEGIN_STATIC_O) \ 1860 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \ 1861 $(PRIVATE_LDFLAGS) \ 1862 $(PRIVATE_ALL_OBJECTS) \ 1863 -Wl,--whole-archive \ 1864 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 1865 -Wl,--no-whole-archive \ 1866 $(call normalize-target-libraries,$(filter-out %libcompiler_rt.a,$(filter-out %libc_nomalloc.a,$(filter-out %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))))) \ 1867 -Wl,--start-group \ 1868 $(call normalize-target-libraries,$(filter %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \ 1869 $(call normalize-target-libraries,$(filter %libc_nomalloc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \ 1870 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_COVERAGE_LIB)) \ 1871 $(PRIVATE_TARGET_LIBATOMIC) \ 1872 $(call normalize-target-libraries,$(filter %libcompiler_rt.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \ 1873 $(PRIVATE_TARGET_LIBGCC) \ 1874 -Wl,--end-group \ 1875 $(PRIVATE_TARGET_CRTEND_O) 1876endef 1877 1878define transform-o-to-static-executable 1879@echo "$($(PRIVATE_PREFIX)DISPLAY) StaticExecutable: $(PRIVATE_MODULE) ($@)" 1880@mkdir -p $(dir $@) 1881$(transform-o-to-static-executable-inner) 1882endef 1883 1884 1885########################################################### 1886## Commands for running gcc to link a host executable 1887########################################################### 1888ifdef BUILD_HOST_static 1889HOST_FPIE_FLAGS := 1890else 1891HOST_FPIE_FLAGS := -pie 1892# Force the correct entry point to workaround a bug in binutils that manifests with -pie 1893ifeq ($(HOST_CROSS_OS),windows) 1894HOST_CROSS_FPIE_FLAGS += -Wl,-e_mainCRTStartup 1895endif 1896endif 1897 1898ifneq ($(HOST_CUSTOM_LD_COMMAND),true) 1899define transform-host-o-to-executable-inner 1900$(hide) $(PRIVATE_CXX) \ 1901 $(PRIVATE_ALL_OBJECTS) \ 1902 -Wl,--whole-archive \ 1903 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 1904 -Wl,--no-whole-archive \ 1905 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ 1906 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 1907 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ 1908 $(if $(filter true,$(NATIVE_COVERAGE)),-lgcov) \ 1909 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_HOST_LIBPROFILE_RT)) \ 1910 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ 1911 -Wl,-rpath-link=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)OUT_INTERMEDIATE_LIBRARIES) \ 1912 $(foreach path,$(PRIVATE_RPATHS), \ 1913 -Wl,-rpath,\$$ORIGIN/$(path)) \ 1914 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)GLOBAL_LD_DIRS) \ 1915 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1916 $(PRIVATE_HOST_GLOBAL_LDFLAGS) \ 1917 ) \ 1918 $(PRIVATE_LDFLAGS) \ 1919 -o $@ \ 1920 $(PRIVATE_LDLIBS) 1921endef 1922endif 1923 1924define transform-host-o-to-executable 1925@echo "$($(PRIVATE_PREFIX)DISPLAY) Executable: $(PRIVATE_MODULE) ($@)" 1926@mkdir -p $(dir $@) 1927$(transform-host-o-to-executable-inner) 1928endef 1929 1930 1931########################################################### 1932## Commands for running javac to make .class files 1933########################################################### 1934 1935# Add BUILD_NUMBER to apps default version name if it's unbundled build. 1936ifdef TARGET_BUILD_APPS 1937TARGET_BUILD_WITH_APPS_VERSION_NAME := true 1938endif 1939 1940ifdef TARGET_BUILD_WITH_APPS_VERSION_NAME 1941APPS_DEFAULT_VERSION_NAME := $(PLATFORM_VERSION)-$(BUILD_NUMBER_FROM_FILE) 1942else 1943APPS_DEFAULT_VERSION_NAME := $(PLATFORM_VERSION) 1944endif 1945 1946# TODO: Right now we generate the asset resources twice, first as part 1947# of generating the Java classes, then at the end when packaging the final 1948# assets. This should be changed to do one of two things: (1) Don't generate 1949# any resource files the first time, only create classes during that stage; 1950# or (2) Don't use the -c flag with the second stage, instead taking the 1951# resource files from the first stage as additional input. My original intent 1952# was to use approach (2), but this requires a little more work in the tool. 1953# Maybe we should just use approach (1). 1954 1955# This rule creates the R.java and Manifest.java files, both of which 1956# are PRODUCT-neutral. Don't pass PRIVATE_PRODUCT_AAPT_CONFIG to this invocation. 1957define create-resource-java-files 1958@mkdir -p $(PRIVATE_SOURCE_INTERMEDIATES_DIR) 1959@mkdir -p $(dir $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) 1960$(hide) $(AAPT) package $(PRIVATE_AAPT_FLAGS) -m \ 1961 $(eval # PRIVATE_PRODUCT_AAPT_CONFIG is intentionally missing-- see comment.) \ 1962 $(addprefix -J , $(PRIVATE_SOURCE_INTERMEDIATES_DIR)) \ 1963 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \ 1964 $(addprefix -P , $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) \ 1965 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \ 1966 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \ 1967 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \ 1968 $(addprefix -G , $(PRIVATE_PROGUARD_OPTIONS_FILE)) \ 1969 $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \ 1970 $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \ 1971 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,--version-code $(PLATFORM_SDK_VERSION)) \ 1972 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,--version-name $(APPS_DEFAULT_VERSION_NAME)) \ 1973 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \ 1974 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \ 1975 --skip-symbols-without-default-localization 1976endef 1977 1978# Search for generated R.java/Manifest.java, copy the found R.java as $@. 1979# Also copy them to a central 'R' directory to make it easier to add the files to an IDE. 1980define find-generated-R.java 1981$(hide) for GENERATED_MANIFEST_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \ 1982 -name Manifest.java 2> /dev/null`; do \ 1983 dir=`awk '/package/{gsub(/\./,"/",$$2);gsub(/;/,"",$$2);print $$2;exit}' $$GENERATED_MANIFEST_FILE`; \ 1984 mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \ 1985 $(ACP) -fp $$GENERATED_MANIFEST_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \ 1986 done; 1987$(hide) for GENERATED_R_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \ 1988 -name R.java 2> /dev/null`; do \ 1989 dir=`awk '/package/{gsub(/\./,"/",$$2);gsub(/;/,"",$$2);print $$2;exit}' $$GENERATED_R_FILE`; \ 1990 mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \ 1991 $(ACP) -fp $$GENERATED_R_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir \ 1992 || exit 31; \ 1993 $(ACP) -fp $$GENERATED_R_FILE $@ || exit 32; \ 1994 done; 1995@# Ensure that the target file is always created, i.e. also in case we did not 1996@# enter the GENERATED_R_FILE-loop above. This avoids unnecessary rebuilding. 1997$(hide) touch $@ 1998endef 1999 2000########################################################### 2001# AAPT2 compilation and link 2002########################################################### 2003define aapt2-compile-one-resource-file 2004@mkdir -p $(dir $@) 2005$(hide) $(AAPT2) compile -o $(dir $@) $(PRIVATE_AAPT2_CFLAGS) --legacy $< 2006endef 2007 2008define aapt2-compile-resource-dirs 2009@mkdir -p $(dir $@) 2010$(hide) $(AAPT2) compile -o $@ $(addprefix --dir ,$(PRIVATE_SOURCE_RES_DIRS)) \ 2011 $(PRIVATE_AAPT2_CFLAGS) --legacy 2012endef 2013 2014# Set up rule to compile one resource file with aapt2. 2015# Must be called with $(eval). 2016# $(1): the source file 2017# $(2): the output file 2018define aapt2-compile-one-resource-file-rule 2019$(2) : $(1) $(AAPT2) 2020 @echo "AAPT2 compile $$@ <- $$<" 2021 $$(call aapt2-compile-one-resource-file) 2022endef 2023 2024# Convert input resource file path to output file path. 2025# values-[config]/<file>.xml -> values-[config]_<file>.arsc.flat; 2026# For other resource file, just replace the last "/" with "_" and 2027# add .flat extension. 2028# 2029# $(1): the input resource file path 2030# $(2): the base dir of the output file path 2031# Returns: the compiled output file path 2032define aapt2-compiled-resource-out-file 2033$(eval _p_w := $(strip $(subst /,$(space),$(dir $(1)))))$(2)/$(subst $(space),/,$(_p_w))_$(if $(filter values%,$(lastword $(_p_w))),$(patsubst %.xml,%.arsc,$(notdir $(1))),$(notdir $(1))).flat 2034endef 2035 2036define aapt2-link 2037@mkdir -p $(dir $@) 2038$(call dump-words-to-file,$(PRIVATE_RES_FLAT),$(dir $@)aapt2-flat-list) 2039$(hide) $(AAPT2) link -o $@ \ 2040 $(PRIVATE_AAPT_FLAGS) \ 2041 $(addprefix --manifest ,$(PRIVATE_ANDROID_MANIFEST)) \ 2042 $(addprefix -I ,$(PRIVATE_AAPT_INCLUDES)) \ 2043 $(addprefix -I ,$(PRIVATE_SHARED_ANDROID_LIBRARIES)) \ 2044 $(addprefix --java ,$(PRIVATE_SOURCE_INTERMEDIATES_DIR)) \ 2045 $(addprefix --proguard ,$(PRIVATE_PROGUARD_OPTIONS_FILE)) \ 2046 $(addprefix --min-sdk-version ,$(PRIVATE_DEFAULT_APP_TARGET_SDK)) \ 2047 $(addprefix --target-sdk-version ,$(PRIVATE_DEFAULT_APP_TARGET_SDK)) \ 2048 $(if $(filter --product,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --product ,$(PRIVATE_TARGET_AAPT_CHARACTERISTICS))) \ 2049 $(addprefix -c ,$(PRIVATE_PRODUCT_AAPT_CONFIG)) \ 2050 $(addprefix --preferred-density ,$(PRIVATE_PRODUCT_AAPT_PREF_CONFIG)) \ 2051 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,--version-code $(PLATFORM_SDK_VERSION)) \ 2052 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,--version-name $(APPS_DEFAULT_VERSION_NAME)) \ 2053 $(addprefix --rename-manifest-package ,$(PRIVATE_MANIFEST_PACKAGE_NAME)) \ 2054 $(addprefix --rename-instrumentation-target-package ,$(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \ 2055 $(addprefix -R , $(PRIVATE_OVERLAY_FLAT)) \ 2056 \@$(dir $@)aapt2-flat-list 2057endef 2058 2059########################################################### 2060xlint_unchecked := -Xlint:unchecked 2061 2062# emit-line, <word list>, <output file> 2063define emit-line 2064 $(if $(1),echo -n '$(strip $(1)) ' >> $(2)) 2065endef 2066 2067# dump-words-to-file, <word list>, <output file> 2068define dump-words-to-file 2069 @rm -f $(2) 2070 @touch $(2) 2071 @$(call emit-line,$(wordlist 1,500,$(1)),$(2)) 2072 @$(call emit-line,$(wordlist 501,1000,$(1)),$(2)) 2073 @$(call emit-line,$(wordlist 1001,1500,$(1)),$(2)) 2074 @$(call emit-line,$(wordlist 1501,2000,$(1)),$(2)) 2075 @$(call emit-line,$(wordlist 2001,2500,$(1)),$(2)) 2076 @$(call emit-line,$(wordlist 2501,3000,$(1)),$(2)) 2077 @$(call emit-line,$(wordlist 3001,3500,$(1)),$(2)) 2078 @$(call emit-line,$(wordlist 3501,4000,$(1)),$(2)) 2079 @$(call emit-line,$(wordlist 4001,4500,$(1)),$(2)) 2080 @$(call emit-line,$(wordlist 4501,5000,$(1)),$(2)) 2081 @$(call emit-line,$(wordlist 5001,5500,$(1)),$(2)) 2082 @$(call emit-line,$(wordlist 5501,6000,$(1)),$(2)) 2083 @$(call emit-line,$(wordlist 6001,6500,$(1)),$(2)) 2084 @$(call emit-line,$(wordlist 6501,7000,$(1)),$(2)) 2085 @$(call emit-line,$(wordlist 7001,7500,$(1)),$(2)) 2086 @$(call emit-line,$(wordlist 7501,8000,$(1)),$(2)) 2087 @$(call emit-line,$(wordlist 8001,8500,$(1)),$(2)) 2088 @$(call emit-line,$(wordlist 8501,9000,$(1)),$(2)) 2089 @$(call emit-line,$(wordlist 9001,9500,$(1)),$(2)) 2090 @$(call emit-line,$(wordlist 9501,10000,$(1)),$(2)) 2091 @$(call emit-line,$(wordlist 10001,10500,$(1)),$(2)) 2092 @$(call emit-line,$(wordlist 10501,11000,$(1)),$(2)) 2093 @$(call emit-line,$(wordlist 11001,11500,$(1)),$(2)) 2094 @$(call emit-line,$(wordlist 11501,12000,$(1)),$(2)) 2095 @$(call emit-line,$(wordlist 12001,12500,$(1)),$(2)) 2096 @$(call emit-line,$(wordlist 12501,13000,$(1)),$(2)) 2097 @$(call emit-line,$(wordlist 13001,13500,$(1)),$(2)) 2098 @$(if $(wordlist 13501,13502,$(1)),$(error Too many words ($(words $(1))))) 2099endef 2100 2101# For a list of jar files, unzip them to a specified directory, 2102# but make sure that no META-INF files come along for the ride, 2103# unless PRIVATE_DONT_DELETE_JAR_META_INF is set. 2104# 2105# $(1): files to unzip 2106# $(2): destination directory 2107define unzip-jar-files 2108 $(hide) for f in $(1); \ 2109 do \ 2110 if [ ! -f $$f ]; then \ 2111 echo Missing file $$f; \ 2112 exit 1; \ 2113 fi; \ 2114 unzip -qo $$f -d $(2); \ 2115 done 2116 $(if $(PRIVATE_DONT_DELETE_JAR_META_INF),,$(hide) rm -rf $(2)/META-INF) 2117endef 2118 2119# Call jack 2120# 2121define call-jack 2122 JACK_VERSION=$(PRIVATE_JACK_VERSION) $(JACK) $(DEFAULT_JACK_EXTRA_ARGS) 2123endef 2124 2125# Common definition to invoke javac on the host and target. 2126# 2127# Some historical notes: 2128# - below we write the list of java files to java-source-list to avoid argument 2129# list length problems with Cygwin 2130# - we filter out duplicate java file names because eclipse's compiler 2131# doesn't like them. 2132# 2133# $(1): javac 2134# $(2): bootclasspath 2135define compile-java 2136$(hide) rm -f $@ 2137$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) 2138$(hide) mkdir -p $(dir $@) 2139$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR) 2140$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)) 2141$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list) 2142$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \ 2143 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' -and -not -name '.*' >> $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list; \ 2144fi 2145$(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \ 2146 | $(NORMALIZE_PATH) | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq 2147$(hide) if [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \ 2148 $(1) -encoding UTF-8 \ 2149 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \ 2150 $(2) \ 2151 $(addprefix -classpath ,$(strip \ 2152 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \ 2153 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \ 2154 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \ 2155 $(PRIVATE_JAVACFLAGS) \ 2156 \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \ 2157 || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 ) \ 2158fi 2159$(if $(PRIVATE_JAVA_LAYERS_FILE), $(hide) build/tools/java-layers.py \ 2160 $(PRIVATE_JAVA_LAYERS_FILE) \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq,) 2161$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list 2162$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq 2163$(if $(PRIVATE_JAR_EXCLUDE_FILES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) \ 2164 -name $(word 1, $(PRIVATE_JAR_EXCLUDE_FILES)) \ 2165 $(addprefix -o -name , $(wordlist 2, 999, $(PRIVATE_JAR_EXCLUDE_FILES))) \ 2166 | xargs rm -rf) 2167$(if $(PRIVATE_JAR_PACKAGES), \ 2168 $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -mindepth 1 -type f \ 2169 $(foreach pkg, $(PRIVATE_JAR_PACKAGES), \ 2170 -not -path $(PRIVATE_CLASS_INTERMEDIATES_DIR)/$(subst .,/,$(pkg))/\*) -delete ; \ 2171 find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -empty -delete) 2172$(if $(PRIVATE_JAR_EXCLUDE_PACKAGES), $(hide) rm -rf \ 2173 $(foreach pkg, $(PRIVATE_JAR_EXCLUDE_PACKAGES), \ 2174 $(PRIVATE_CLASS_INTERMEDIATES_DIR)/$(subst .,/,$(pkg)))) 2175$(if $(PRIVATE_JAR_MANIFEST), \ 2176 $(hide) sed -e "s/%BUILD_NUMBER%/$(BUILD_NUMBER_FROM_FILE)/" \ 2177 $(PRIVATE_JAR_MANIFEST) > $(dir $@)/manifest.mf && \ 2178 jar -cfm $@ $(dir $@)/manifest.mf \ 2179 -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) ., \ 2180 $(hide) jar -cf $@ -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .) 2181$(if $(PRIVATE_EXTRA_JAR_ARGS),$(call add-java-resources-to,$@)) 2182endef 2183 2184define transform-java-to-classes.jar 2185@echo "$($(PRIVATE_PREFIX)DISPLAY) Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))" 2186$(call compile-java,$(TARGET_JAVAC),$(PRIVATE_BOOTCLASSPATH)) 2187endef 2188 2189# Invoke Jack to compile java from source to dex and jack files. 2190# 2191# Some historical notes: 2192# - below we write the list of java files to java-source-list to avoid argument 2193# list length problems with Cygwin 2194# - we filter out duplicate java file names because Jack doesn't like them. 2195define jack-java-to-dex 2196$(hide) rm -f $@ 2197$(hide) rm -f $(PRIVATE_CLASSES_JACK) 2198$(hide) rm -rf $(PRIVATE_JACK_INTERMEDIATES_DIR) 2199$(hide) mkdir -p $(dir $@) 2200$(hide) mkdir -p $(dir $(PRIVATE_CLASSES_JACK)) 2201$(hide) mkdir -p $(PRIVATE_JACK_INTERMEDIATES_DIR) 2202$(if $(PRIVATE_JACK_INCREMENTAL_DIR),$(hide) mkdir -p $(PRIVATE_JACK_INCREMENTAL_DIR)) 2203$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list) 2204$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \ 2205 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list; \ 2206fi 2207$(hide) tr ' ' '\n' < $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list \ 2208 | $(NORMALIZE_PATH) | sort -u > $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq 2209$(if $(PRIVATE_JACK_PROGUARD_FLAGS), \ 2210 $(hide) echo -basedirectory $(CURDIR) > $@.flags; \ 2211 echo $(PRIVATE_JACK_PROGUARD_FLAGS) >> $@.flags; \ 2212) 2213$(if $(PRIVATE_EXTRA_JAR_ARGS), 2214 $(hide) mkdir -p $@.res.tmp 2215 $(hide) $(call create-empty-package-at,$@.res.tmp.zip) 2216 $(hide) $(call add-java-resources-to,$@.res.tmp.zip) 2217 $(hide) unzip -qo $@.res.tmp.zip -d $@.res.tmp 2218 $(hide) rm $@.res.tmp.zip) 2219$(hide) if [ -s $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \ 2220 export tmpEcjArg="@$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq"; \ 2221else \ 2222 export tmpEcjArg=""; \ 2223fi; \ 2224$(call call-jack) \ 2225 $(strip $(PRIVATE_JACK_FLAGS)) \ 2226 $(strip $(PRIVATE_JACK_COVERAGE_OPTIONS)) \ 2227 $(if $(NO_OPTIMIZE_DX), \ 2228 -D jack.dex.optimize="false") \ 2229 $(if $(PRIVATE_RMTYPEDEFS), \ 2230 -D jack.android.remove-typedef="true") \ 2231 $(addprefix --classpath ,$(strip \ 2232 $(call normalize-path-list,$(PRIVATE_JACK_SHARED_LIBRARIES)))) \ 2233 $(addprefix --import ,$(call reverse-list,$(PRIVATE_STATIC_JACK_LIBRARIES))) \ 2234 $(if $(PRIVATE_EXTRA_JAR_ARGS),--import-resource $@.res.tmp) \ 2235 -D jack.android.min-api-level=$(PRIVATE_JACK_MIN_SDK_VERSION) \ 2236 -D jack.import.resource.policy=keep-first \ 2237 -D jack.import.type.policy=keep-first \ 2238 --output-jack $(PRIVATE_CLASSES_JACK) \ 2239 $(if $(PRIVATE_JACK_INCREMENTAL_DIR),--incremental-folder $(PRIVATE_JACK_INCREMENTAL_DIR)) \ 2240 --output-dex $(PRIVATE_JACK_INTERMEDIATES_DIR) \ 2241 $(addprefix --config-jarjar ,$(strip $(PRIVATE_JARJAR_RULES))) \ 2242 $(if $(PRIVATE_JACK_PROGUARD_FLAGS),--config-proguard $@.flags) \ 2243 $$tmpEcjArg \ 2244 || ( rm -rf $(PRIVATE_CLASSES_JACK); exit 41 ) 2245$(hide) mv $(PRIVATE_JACK_INTERMEDIATES_DIR)/classes*.dex $(dir $@) 2246$(hide) rm -f $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list 2247$(if $(PRIVATE_EXTRA_JAR_ARGS),$(hide) rm -rf $@.res.tmp) 2248$(hide) mv $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq $(PRIVATE_JACK_INTERMEDIATES_DIR).java-source-list 2249$(if $(PRIVATE_JAR_PACKAGES), $(hide) echo unsupported options PRIVATE_JAR_PACKAGES in $@; exit 53) 2250$(if $(PRIVATE_JAR_EXCLUDE_PACKAGES), $(hide) echo unsupported options JAR_EXCLUDE_PACKAGES in $@; exit 53) 2251$(if $(PRIVATE_JAR_MANIFEST), $(hide) echo unsupported options JAR_MANIFEST in $@; exit 53) 2252endef 2253 2254# Invoke Jack to compile java source just to check it compiles correctly. 2255# 2256# Some historical notes: 2257# - below we write the list of java files to java-source-list to avoid argument 2258# list length problems with Cygwin 2259# - we filter out duplicate java file names because Jack doesn't like them. 2260define jack-check-java 2261$(hide) rm -f $@ 2262$(hide) rm -f $@.java-source-list 2263$(hide) rm -f $@.java-source-list-uniq 2264$(hide) mkdir -p $(dir $@) 2265$(if $(PRIVATE_JACK_INCREMENTAL_DIR),$(hide) mkdir -p $(PRIVATE_JACK_INCREMENTAL_DIR)) 2266$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$@.java-source-list) 2267$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \ 2268 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $@.java-source-list; \ 2269fi 2270$(hide) tr ' ' '\n' < $@.java-source-list \ 2271 | sort -u > $@.java-source-list-uniq 2272$(hide) if [ -s $@.java-source-list-uniq ] ; then \ 2273 $(call call-jack) \ 2274 $(strip $(PRIVATE_JACK_FLAGS)) \ 2275 $(addprefix --classpath ,$(strip \ 2276 $(call normalize-path-list,$(call reverse-list,$(PRIVATE_STATIC_JACK_LIBRARIES)) $(PRIVATE_JACK_SHARED_LIBRARIES)))) \ 2277 -D jack.import.resource.policy=keep-first \ 2278 -D jack.android.min-api-level=$(PRIVATE_JACK_MIN_SDK_VERSION) \ 2279 -D jack.import.type.policy=keep-first \ 2280 $(if $(PRIVATE_JACK_INCREMENTAL_DIR),--incremental-folder $(PRIVATE_JACK_INCREMENTAL_DIR)) \ 2281 @$@.java-source-list-uniq; \ 2282fi 2283touch $@ 2284endef 2285 2286define transform-jar-to-jack 2287 $(hide) mkdir -p $(dir $@) 2288 $(hide) mkdir -p $@.tmpjill.res 2289 $(hide) unzip -qo $< -d $@.tmpjill.res 2290 $(hide) find $@.tmpjill.res -iname "*.class" -delete 2291 $(hide) $(call call-jack) \ 2292 $(PRIVATE_JACK_FLAGS) \ 2293 -D jack.import.resource.policy=keep-first \ 2294 -D jack.import.type.policy=keep-first \ 2295 -D jack.android.min-api-level=$(PRIVATE_JACK_MIN_SDK_VERSION) \ 2296 --import $< \ 2297 --import-resource $@.tmpjill.res \ 2298 --output-jack $@ 2299 $(hide) rm -rf $@.tmpjill.res 2300endef 2301 2302# Moves $1.tmp to $1 if necessary. This is designed to be used with 2303# .KATI_RESTAT. For kati, this function doesn't update the timestamp 2304# of $1 when $1.tmp is identical to $1 so that ninja won't rebuild 2305# targets which depend on $1. 2306define commit-change-for-toc 2307$(hide) if cmp -s $1.tmp $1 ; then \ 2308 rm $1.tmp ; \ 2309else \ 2310 mv $1.tmp $1 ; \ 2311fi 2312endef 2313 2314## Rule to create a table of contents from a .jar file. 2315## Must be called with $(eval). 2316# $(1): A .jar file 2317define _transform-jar-to-toc 2318$1.toc: $1 | $(IJAR) 2319 @echo Generating TOC: $$@ 2320 $(hide) $(IJAR) $$< $$@.tmp 2321 $$(call commit-change-for-toc,$$@) 2322endef 2323 2324## Define a rule which generates .jar.toc and mark it as .KATI_RESTAT. 2325# $(1): A .jar file 2326define define-jar-to-toc-rule 2327$(eval $(call _transform-jar-to-toc,$1))\ 2328$(eval .KATI_RESTAT: $1.toc) 2329endef 2330 2331ifeq (,$(TARGET_BUILD_APPS)) 2332 2333## Rule to create a table of contents from a .dex file. 2334## Must be called with $(eval). 2335# $(1): The directory which contains classes*.dex files 2336define _transform-dex-to-toc 2337$1/classes.dex.toc: PRIVATE_INPUT_DEX_FILES := $1/classes*.dex 2338$1/classes.dex.toc: $1/classes.dex $(DEXDUMP) 2339 @echo Generating TOC: $$@ 2340 $(hide) ANDROID_LOG_TAGS="*:e" $(DEXDUMP) -l xml $$(PRIVATE_INPUT_DEX_FILES) > $$@.tmp 2341 $$(call commit-change-for-toc,$$@) 2342endef 2343 2344## Define a rule which generates .dex.toc and mark it as .KATI_RESTAT. 2345# $(1): The directory which contains classes*.dex files 2346define define-dex-to-toc-rule 2347$(eval $(call _transform-dex-to-toc,$1))\ 2348$(eval .KATI_RESTAT: $1/classes.dex.toc) 2349endef 2350 2351else 2352 2353# Turn off .toc optimization for apps build as we cannot build dexdump. 2354define define-dex-to-toc-rule 2355endef 2356 2357endif # TARGET_BUILD_APPS 2358 2359 2360# Invoke Jack to compile java from source to jack files without shrink or obfuscation. 2361# 2362# Some historical notes: 2363# - below we write the list of java files to java-source-list to avoid argument 2364# list length problems with Cygwin 2365# - we filter out duplicate java file names because Jack doesn't like them. 2366define java-to-jack 2367$(hide) rm -f $@ 2368$(hide) rm -rf $(PRIVATE_JACK_INTERMEDIATES_DIR) 2369$(hide) mkdir -p $(dir $@) 2370$(hide) mkdir -p $(PRIVATE_JACK_INTERMEDIATES_DIR) 2371$(if $(PRIVATE_JACK_INCREMENTAL_DIR),$(hide) mkdir -p $(PRIVATE_JACK_INCREMENTAL_DIR)) 2372$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list) 2373$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \ 2374 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list; \ 2375fi 2376$(hide) tr ' ' '\n' < $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list \ 2377 | $(NORMALIZE_PATH) | sort -u > $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq 2378$(if $(PRIVATE_JACK_PROGUARD_FLAGS), \ 2379 $(hide) echo -basedirectory $(CURDIR) > $@.flags; \ 2380 echo $(PRIVATE_JACK_PROGUARD_FLAGS) >> $@.flags; \ 2381) 2382$(if $(PRIVATE_EXTRA_JAR_ARGS), 2383 $(hide) mkdir -p $@.res.tmp 2384 $(hide) $(call create-empty-package-at,$@.res.tmp.zip) 2385 $(hide) $(call add-java-resources-to,$@.res.tmp.zip) 2386 $(hide) unzip -qo $@.res.tmp.zip -d $@.res.tmp 2387 $(hide) rm $@.res.tmp.zip) 2388$(hide) if [ -s $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \ 2389 export tmpEcjArg="@$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq"; \ 2390else \ 2391 export tmpEcjArg=""; \ 2392fi; \ 2393$(call call-jack) \ 2394 $(strip $(PRIVATE_JACK_FLAGS)) \ 2395 $(if $(NO_OPTIMIZE_DX), \ 2396 -D jack.dex.optimize="false") \ 2397 $(addprefix --classpath ,$(strip \ 2398 $(call normalize-path-list,$(PRIVATE_JACK_SHARED_LIBRARIES)))) \ 2399 $(addprefix --import ,$(call reverse-list,$(PRIVATE_STATIC_JACK_LIBRARIES))) \ 2400 $(if $(PRIVATE_EXTRA_JAR_ARGS),--import-resource $@.res.tmp) \ 2401 -D jack.import.resource.policy=keep-first \ 2402 -D jack.import.type.policy=keep-first \ 2403 -D jack.android.min-api-level=$(PRIVATE_JACK_MIN_SDK_VERSION) \ 2404 $(if $(PRIVATE_JACK_INCREMENTAL_DIR),--incremental-folder $(PRIVATE_JACK_INCREMENTAL_DIR)) \ 2405 --output-jack $@ \ 2406 $(addprefix --config-jarjar ,$(strip $(PRIVATE_JARJAR_RULES))) \ 2407 $(if $(PRIVATE_JACK_PROGUARD_FLAGS),--config-proguard $@.flags) \ 2408 $$tmpEcjArg \ 2409 || ( rm -f $@ ; exit 41 ) 2410$(hide) rm -f $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list 2411$(if $(PRIVATE_EXTRA_JAR_ARGS),$(hide) rm -rf $@.res.tmp) 2412$(hide) mv $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq $(PRIVATE_JACK_INTERMEDIATES_DIR).java-source-list 2413$(if $(PRIVATE_JAR_PACKAGES), $(hide) echo unsupported options PRIVATE_JAR_PACKAGES in $@; exit 53) 2414$(if $(PRIVATE_JAR_EXCLUDE_PACKAGES), $(hide) echo unsupported options JAR_EXCLUDE_PACKAGES in $@; exit 53) 2415$(if $(PRIVATE_JAR_MANIFEST), $(hide) echo unsupported options JAR_MANIFEST in $@; exit 53) 2416endef 2417 2418define transform-classes.jar-to-emma 2419$(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \ 2420 $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR) \ 2421 $(addprefix -ix , $(PRIVATE_EMMA_COVERAGE_FILTER)) 2422endef 2423 2424# Create a mostly-empty .jar file that we'll add to later. 2425# The MacOS jar tool doesn't like creating empty jar files, 2426# so we need to give it something. 2427# $(1) package to create 2428define create-empty-package-at 2429@mkdir -p $(dir $(1)) 2430$(hide) touch $(dir $(1))zipdummy 2431$(hide) (cd $(dir $(1)) && jar cf $(notdir $(1)) zipdummy) 2432$(hide) zip -qd $(1) zipdummy 2433$(hide) rm $(dir $(1))zipdummy 2434endef 2435 2436# Create a mostly-empty .jar file that we'll add to later. 2437# The MacOS jar tool doesn't like creating empty jar files, 2438# so we need to give it something. 2439define create-empty-package 2440$(call create-empty-package-at,$@) 2441endef 2442 2443#TODO: we kinda want to build different asset packages for 2444# different configurations, then combine them later (or something). 2445# Per-locale, etc. 2446# A list of dynamic and static parameters; build layers for 2447# dynamic params that lay over the static ones. 2448#TODO: update the manifest to point to the package file 2449#Note that the version numbers are given to aapt as simple default 2450#values; applications can override these by explicitly stating 2451#them in their manifest. 2452define add-assets-to-package 2453$(hide) $(AAPT) package -u $(PRIVATE_AAPT_FLAGS) \ 2454 $(addprefix -c , $(PRIVATE_PRODUCT_AAPT_CONFIG)) \ 2455 $(addprefix --preferred-density , $(PRIVATE_PRODUCT_AAPT_PREF_CONFIG)) \ 2456 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \ 2457 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \ 2458 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \ 2459 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \ 2460 $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \ 2461 $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \ 2462 $(if $(filter --product,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --product , $(PRIVATE_TARGET_AAPT_CHARACTERISTICS))) \ 2463 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,--version-code $(PLATFORM_SDK_VERSION)) \ 2464 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,--version-name $(APPS_DEFAULT_VERSION_NAME)) \ 2465 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \ 2466 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \ 2467 --skip-symbols-without-default-localization \ 2468 -F $@ 2469endef 2470 2471# We need the extra blank line, so that the command will be on a separate line. 2472# $(1): the ABI name 2473# $(2): the list of shared libraies 2474define _add-jni-shared-libs-to-package-per-abi 2475$(hide) cp $(2) $(dir $@)lib/$(1) 2476 2477endef 2478 2479# For apps_only build, don't uncompress/page-align the jni libraries, 2480# because the apk may be run on older platforms that don't support loading jni directly from apk. 2481ifdef TARGET_BUILD_APPS 2482JNI_COMPRESS_FLAGS := 2483ZIPALIGN_PAGE_ALIGN_FLAGS := 2484else 2485JNI_COMPRESS_FLAGS := -0 2486ZIPALIGN_PAGE_ALIGN_FLAGS := -p 2487endif 2488 2489define add-jni-shared-libs-to-package 2490$(hide) rm -rf $(dir $@)lib 2491$(hide) mkdir -p $(addprefix $(dir $@)lib/,$(PRIVATE_JNI_SHARED_LIBRARIES_ABI)) 2492$(foreach abi,$(PRIVATE_JNI_SHARED_LIBRARIES_ABI),\ 2493 $(call _add-jni-shared-libs-to-package-per-abi,$(abi),\ 2494 $(patsubst $(abi):%,%,$(filter $(abi):%,$(PRIVATE_JNI_SHARED_LIBRARIES))))) 2495$(hide) (cd $(dir $@) && zip -qrX $(JNI_COMPRESS_FLAGS) $(notdir $@) lib) 2496$(hide) rm -rf $(dir $@)lib 2497endef 2498 2499#TODO: update the manifest to point to the dex file 2500define add-dex-to-package 2501$(call add-dex-to-package-arg,$@) 2502endef 2503 2504# $(1): the package file. 2505define add-dex-to-package-arg 2506$(hide) find $(dir $(PRIVATE_DEX_FILE)) -maxdepth 1 -name "classes*.dex" | sort | xargs zip -qjX $(1) 2507endef 2508 2509# Add java resources added by the current module. 2510# $(1) destination package 2511# 2512define add-java-resources-to 2513$(call dump-words-to-file, $(PRIVATE_EXTRA_JAR_ARGS), $(1).jar-arg-list) 2514$(hide) jar uf $(1) @$(1).jar-arg-list 2515@rm -f $(1).jar-arg-list 2516endef 2517 2518# Add resources carried by static Jack libraries. 2519# 2520define add-carried-jack-resources 2521 $(hide) if [ -d $(PRIVATE_JACK_INTERMEDIATES_DIR) ] ; then \ 2522 find $(PRIVATE_JACK_INTERMEDIATES_DIR) -type f | sort \ 2523 | sed -e "s?^$(PRIVATE_JACK_INTERMEDIATES_DIR)/? -C \"$(PRIVATE_JACK_INTERMEDIATES_DIR)\" \"?" -e "s/$$/\"/" \ 2524 > $(dir $@)jack_res_jar_flags; \ 2525 if [ -s $(dir $@)jack_res_jar_flags ] ; then \ 2526 jar uf $@ @$(dir $@)jack_res_jar_flags; \ 2527 fi; \ 2528fi 2529endef 2530 2531# Returns the minSdkVersion of the specified APK as a decimal number. If the 2532# version is a codename, returns the current platform SDK version (always a 2533# decimal number) instead. If the APK does not specify a minSdkVersion, returns 2534# 0 to match how the Android platform interprets this situation at runtime. 2535# 2536# This currently substitutes any version which contains characters other than 2537# digits with the current platform's API Level number. This is because I 2538# couldn't figure out an easy way to perform the substitution only for the 2539# version codes listed in PLATFORM_VERSION_ALL_CODENAMES. 2540define get-package-min-sdk-version-int 2541$$(($(AAPT) dump badging $(1) 2>&1 | grep '^sdkVersion' || echo "sdkVersion:'0'") \ 2542 | cut -d"'" -f2 | \ 2543 sed -e s/^.*[^0-9].*$$/$(PLATFORM_SDK_VERSION)/) 2544endef 2545 2546# Sign a package using the specified key/cert. 2547# 2548define sign-package 2549$(call sign-package-arg,$@) 2550endef 2551 2552# $(1): the package file we are signing. 2553define sign-package-arg 2554$(hide) mv $(1) $(1).unsigned 2555$(hide) java -Djava.library.path=$(SIGNAPK_JNI_LIBRARY_PATH) -jar $(SIGNAPK_JAR) \ 2556 --min-sdk-version $(call get-package-min-sdk-version-int,$@.unsigned) \ 2557 $(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) \ 2558 $(PRIVATE_ADDITIONAL_CERTIFICATES) $(1).unsigned $(1).signed 2559$(hide) mv $(1).signed $(1) 2560endef 2561 2562# Align STORED entries of a package on 4-byte boundaries to make them easier to mmap. 2563# 2564define align-package 2565$(hide) if ! $(ZIPALIGN) -c $(ZIPALIGN_PAGE_ALIGN_FLAGS) 4 $@ >/dev/null ; then \ 2566 mv $@ $@.unaligned; \ 2567 $(ZIPALIGN) \ 2568 -f \ 2569 $(ZIPALIGN_PAGE_ALIGN_FLAGS) \ 2570 4 \ 2571 $@.unaligned $@.aligned; \ 2572 mv $@.aligned $@; \ 2573 fi 2574endef 2575 2576# Remove dynamic timestamps from packages 2577# 2578define remove-timestamps-from-package 2579$(hide) $(ZIPTIME) $@ 2580endef 2581 2582# Uncompress shared libraries embedded in an apk. 2583# 2584define uncompress-shared-libs 2585$(hide) if (zipinfo $@ $(PRIVATE_EMBEDDED_JNI_LIBS) 2>/dev/null | grep -v ' stor ' >/dev/null) ; then \ 2586 rm -rf $(dir $@)uncompressedlibs && mkdir $(dir $@)uncompressedlibs; \ 2587 unzip $@ $(PRIVATE_EMBEDDED_JNI_LIBS) -d $(dir $@)uncompressedlibs && \ 2588 zip -d $@ 'lib/*.so' && \ 2589 ( cd $(dir $@)uncompressedlibs && find lib -type f | sort | zip -D -X -0 ../$(notdir $@) -@ ) && \ 2590 rm -rf $(dir $@)uncompressedlibs; \ 2591 fi 2592endef 2593 2594# TODO(joeo): If we can ever upgrade to post 3.81 make and get the 2595# new prebuilt rules to work, we should change this to copy the 2596# resources to the out directory and then copy the resources. 2597 2598# Note: we intentionally don't clean PRIVATE_CLASS_INTERMEDIATES_DIR 2599# in transform-java-to-classes for the sake of vm-tests. 2600define transform-host-java-to-package 2601@echo "$($(PRIVATE_PREFIX)DISPLAY) Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))" 2602$(call compile-java,$(HOST_JAVAC),$(PRIVATE_BOOTCLASSPATH)) 2603endef 2604 2605########################################################### 2606## Commands for copying files 2607########################################################### 2608 2609# Define a rule to copy a header. Used via $(eval) by copy_headers.make. 2610# $(1): source header 2611# $(2): destination header 2612define copy-one-header 2613$(2): $(1) 2614 @echo "Header: $$@" 2615 $$(copy-file-to-new-target-with-cp) 2616endef 2617 2618# Define a rule to copy a file. For use via $(eval). 2619# $(1): source file 2620# $(2): destination file 2621define copy-one-file 2622$(2): $(1) 2623 @echo "Copy: $$@" 2624 $$(copy-file-to-target) 2625endef 2626 2627# Copies many files. 2628# $(1): The files to copy. Each entry is a ':' separated src:dst pair 2629# Evaluates to the list of the dst files (ie suitable for a dependency list) 2630define copy-many-files 2631$(foreach f, $(1), $(strip \ 2632 $(eval _cmf_tuple := $(subst :, ,$(f))) \ 2633 $(eval _cmf_src := $(word 1,$(_cmf_tuple))) \ 2634 $(eval _cmf_dest := $(word 2,$(_cmf_tuple))) \ 2635 $(eval $(call copy-one-file,$(_cmf_src),$(_cmf_dest))) \ 2636 $(_cmf_dest))) 2637endef 2638 2639# Copy the file only if it's a well-formed xml file. For use via $(eval). 2640# $(1): source file 2641# $(2): destination file, must end with .xml. 2642define copy-xml-file-checked 2643$(2): $(1) 2644 @echo "Copy xml: $$@" 2645 $(hide) xmllint $$< >/dev/null # Don't print the xml file to stdout. 2646 $$(copy-file-to-target) 2647endef 2648 2649# The -t option to acp and the -p option to cp is 2650# required for OSX. OSX has a ridiculous restriction 2651# where it's an error for a .a file's modification time 2652# to disagree with an internal timestamp, and this 2653# macro is used to install .a files (among other things). 2654 2655# Copy a single file from one place to another, 2656# preserving permissions and overwriting any existing 2657# file. 2658# When we used acp, it could not handle high resolution timestamps 2659# on file systems like ext4. Because of that, '-t' option was disabled 2660# and copy-file-to-target was identical to copy-file-to-new-target. 2661# Keep the behavior until we audit and ensure that switching this back 2662# won't break anything. 2663define copy-file-to-target 2664@mkdir -p $(dir $@) 2665$(hide) rm -f $@ 2666$(hide) cp $< $@ 2667endef 2668 2669# The same as copy-file-to-target, but use the local 2670# cp command instead of acp. 2671define copy-file-to-target-with-cp 2672@mkdir -p $(dir $@) 2673$(hide) rm -f $@ 2674$(hide) cp -p $< $@ 2675endef 2676 2677# The same as copy-file-to-target, but use the zipalign tool to do so. 2678define copy-file-to-target-with-zipalign 2679@mkdir -p $(dir $@) 2680$(hide) rm -f $@ 2681$(hide) $(ZIPALIGN) -f 4 $< $@ 2682endef 2683 2684# The same as copy-file-to-target, but strip out "# comment"-style 2685# comments (for config files and such). 2686define copy-file-to-target-strip-comments 2687@mkdir -p $(dir $@) 2688$(hide) rm -f $@ 2689$(hide) sed -e 's/#.*$$//' -e 's/[ \t]*$$//' -e '/^$$/d' < $< > $@ 2690endef 2691 2692# The same as copy-file-to-target, but don't preserve 2693# the old modification time. 2694define copy-file-to-new-target 2695@mkdir -p $(dir $@) 2696$(hide) rm -f $@ 2697$(hide) cp $< $@ 2698endef 2699 2700# The same as copy-file-to-new-target, but use the local 2701# cp command instead of acp. 2702define copy-file-to-new-target-with-cp 2703@mkdir -p $(dir $@) 2704$(hide) rm -f $@ 2705$(hide) cp $< $@ 2706endef 2707 2708# Copy a prebuilt file to a target location. 2709define transform-prebuilt-to-target 2710@echo "$($(PRIVATE_PREFIX)DISPLAY) Prebuilt: $(PRIVATE_MODULE) ($@)" 2711$(copy-file-to-target) 2712endef 2713 2714# Copy a prebuilt file to a target location, using zipalign on it. 2715define transform-prebuilt-to-target-with-zipalign 2716@echo "$($(PRIVATE_PREFIX)DISPLAY) Prebuilt APK: $(PRIVATE_MODULE) ($@)" 2717$(copy-file-to-target-with-zipalign) 2718endef 2719 2720# Copy a prebuilt file to a target location, stripping "# comment" comments. 2721define transform-prebuilt-to-target-strip-comments 2722@echo "$($(PRIVATE_PREFIX)DISPLAY) Prebuilt: $(PRIVATE_MODULE) ($@)" 2723$(copy-file-to-target-strip-comments) 2724endef 2725 2726# Copy a list of files/directories to target location, with sub dir structure preserved. 2727# For example $(HOST_OUT_EXECUTABLES)/aapt -> $(staging)/bin/aapt . 2728# $(1): the source list of files/directories. 2729# $(2): the path prefix to strip. In the above example it would be $(HOST_OUT). 2730# $(3): the target location. 2731define copy-files-with-structure 2732$(foreach t,$(1),\ 2733 $(eval s := $(patsubst $(2)%,%,$(t)))\ 2734 $(hide) mkdir -p $(dir $(3)/$(s)); cp -Rf $(t) $(3)/$(s)$(newline)) 2735endef 2736 2737# Define a rule to create a symlink to a file. 2738# $(1): full path to source 2739# $(2): source (may be relative) 2740# $(3): full path to destination 2741define symlink-file 2742$(eval $(_symlink-file)) 2743endef 2744 2745# Order-only dependency because make/ninja will follow the link when checking 2746# the timestamp, so the file must exist 2747define _symlink-file 2748$(3): | $(1) 2749 @echo "Symlink: $$@ -> $(2)" 2750 @mkdir -p $(dir $$@) 2751 @rm -rf $$@ 2752 $(hide) ln -sf $(2) $$@ 2753endef 2754 2755########################################################### 2756## Commands to call Proguard 2757########################################################### 2758define transform-jar-to-proguard 2759@echo Proguard: $@ 2760$(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS) \ 2761 $(addprefix -injars , $(PRIVATE_EXTRA_INPUT_JAR)) 2762endef 2763 2764########################################################### 2765## Stuff source generated from one-off tools 2766########################################################### 2767 2768define transform-generated-source 2769@echo "$($(PRIVATE_PREFIX)DISPLAY) Generated: $(PRIVATE_MODULE) <= $<" 2770@mkdir -p $(dir $@) 2771$(hide) $(PRIVATE_CUSTOM_TOOL) 2772endef 2773 2774 2775########################################################### 2776## Assertions about attributes of the target 2777########################################################### 2778 2779# $(1): The file to check 2780ifndef get-file-size 2781$(error HOST_OS must define get-file-size) 2782endif 2783 2784# Convert a partition data size (eg, as reported in /proc/mtd) to the 2785# size of the image used to flash that partition (which includes a 2786# spare area for each page). 2787# $(1): the partition data size 2788define image-size-from-data-size 2789$(strip $(eval _isfds_value := $$(shell echo $$$$(($(1) / $(BOARD_NAND_PAGE_SIZE) * \ 2790 ($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE))))))\ 2791$(if $(filter 0, $(_isfds_value)),$(shell echo $$(($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE)))),$(_isfds_value))\ 2792$(eval _isfds_value :=)) 2793endef 2794 2795# $(1): The file(s) to check (often $@) 2796# $(2): The maximum total image size, in decimal bytes. 2797# Make sure to take into account any reserved space needed for the FS. 2798# 2799# If $(2) is empty, evaluates to "true" 2800# 2801# Reserve bad blocks. Make sure that MAX(1% of partition size, 2 blocks) 2802# is left over after the image has been flashed. Round the 1% up to the 2803# next whole flash block size. 2804define assert-max-file-size 2805$(if $(2), \ 2806 size=$$(for i in $(1); do $(call get-file-size,$$i); echo +; done; echo 0); \ 2807 total=$$(( $$( echo "$$size" ) )); \ 2808 printname=$$(echo -n "$(1)" | tr " " +); \ 2809 img_blocksize=$(call image-size-from-data-size,$(BOARD_FLASH_BLOCK_SIZE)); \ 2810 twoblocks=$$((img_blocksize * 2)); \ 2811 onepct=$$((((($(2) / 100) - 1) / img_blocksize + 1) * img_blocksize)); \ 2812 reserve=$$((twoblocks > onepct ? twoblocks : onepct)); \ 2813 maxsize=$$(($(2) - reserve)); \ 2814 echo "$$printname maxsize=$$maxsize blocksize=$$img_blocksize total=$$total reserve=$$reserve"; \ 2815 if [ "$$total" -gt "$$maxsize" ]; then \ 2816 echo "error: $$printname too large ($$total > [$(2) - $$reserve])"; \ 2817 false; \ 2818 elif [ "$$total" -gt $$((maxsize - 32768)) ]; then \ 2819 echo "WARNING: $$printname approaching size limit ($$total now; limit $$maxsize)"; \ 2820 fi \ 2821 , \ 2822 true \ 2823 ) 2824endef 2825 2826# Like assert-max-file-size, but the second argument is a partition 2827# size, which we'll convert to a max image size before checking it 2828# against the files. 2829# 2830# $(1): The file(s) to check (often $@) 2831# $(2): The partition size. 2832define assert-max-image-size 2833$(if $(2), \ 2834 $(call assert-max-file-size,$(1),$(call image-size-from-data-size,$(2)))) 2835endef 2836 2837 2838########################################################### 2839## Define device-specific radio files 2840########################################################### 2841INSTALLED_RADIOIMAGE_TARGET := 2842 2843# Copy a radio image file to the output location, and add it to 2844# INSTALLED_RADIOIMAGE_TARGET. 2845# $(1): filename 2846define add-radio-file 2847 $(eval $(call add-radio-file-internal,$(1),$(notdir $(1)))) 2848endef 2849define add-radio-file-internal 2850INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2) 2851$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) 2852 $$(transform-prebuilt-to-target) 2853endef 2854 2855# Version of add-radio-file that also arranges for the version of the 2856# file to be checked against the contents of 2857# $(TARGET_BOARD_INFO_FILE). 2858# $(1): filename 2859# $(2): name of version variable in board-info (eg, "version-baseband") 2860define add-radio-file-checked 2861 $(eval $(call add-radio-file-checked-internal,$(1),$(notdir $(1)),$(2))) 2862endef 2863define add-radio-file-checked-internal 2864INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2) 2865BOARD_INFO_CHECK += $(3):$(LOCAL_PATH)/$(1) 2866$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) 2867 $$(transform-prebuilt-to-target) 2868endef 2869 2870 2871########################################################### 2872# Override the package defined in $(1), setting the 2873# variables listed below differently. 2874# 2875# $(1): The makefile to override (relative to the source 2876# tree root) 2877# $(2): Old LOCAL_PACKAGE_NAME value. 2878# $(3): New LOCAL_PACKAGE_NAME value. 2879# $(4): New LOCAL_MANIFEST_PACKAGE_NAME value. 2880# $(5): New LOCAL_CERTIFICATE value. 2881# $(6): New LOCAL_INSTRUMENTATION_FOR value. 2882# $(7): New LOCAL_MANIFEST_INSTRUMENTATION_FOR value. 2883# 2884# Note that LOCAL_PACKAGE_OVERRIDES is NOT cleared in 2885# clear_vars.mk. 2886########################################################### 2887define inherit-package 2888 $(eval $(call inherit-package-internal,$(1),$(2),$(3),$(4),$(5),$(6),$(7))) 2889endef 2890 2891define inherit-package-internal 2892 LOCAL_PACKAGE_OVERRIDES \ 2893 := $(strip $(1))||$(strip $(2))||$(strip $(3))||$(strip $(4))||&&$(strip $(5))||&&$(strip $(6))||&&$(strip $(7)) $(LOCAL_PACKAGE_OVERRIDES) 2894 include $(1) 2895 LOCAL_PACKAGE_OVERRIDES \ 2896 := $(wordlist 1,$(words $(LOCAL_PACKAGE_OVERRIDES)), $(LOCAL_PACKAGE_OVERRIDES)) 2897endef 2898 2899# To be used with inherit-package above 2900# Evalutes to true if the package was overridden 2901define set-inherited-package-variables 2902$(strip $(call set-inherited-package-variables-internal)) 2903endef 2904 2905define keep-or-override 2906$(eval $(1) := $(if $(2),$(2),$($(1)))) 2907endef 2908 2909define set-inherited-package-variables-internal 2910 $(eval _o := $(subst ||, ,$(lastword $(LOCAL_PACKAGE_OVERRIDES)))) 2911 $(eval _n := $(subst ||, ,$(firstword $(LOCAL_PACKAGE_OVERRIDES)))) 2912 $(if $(filter $(word 2,$(_n)),$(LOCAL_PACKAGE_NAME)), \ 2913 $(eval LOCAL_PACKAGE_NAME := $(word 3,$(_o))) \ 2914 $(eval LOCAL_MANIFEST_PACKAGE_NAME := $(word 4,$(_o))) \ 2915 $(call keep-or-override,LOCAL_CERTIFICATE,$(patsubst &&%,%,$(word 5,$(_o)))) \ 2916 $(call keep-or-override,LOCAL_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 6,$(_o)))) \ 2917 $(call keep-or-override,LOCAL_MANIFEST_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 7,$(_o)))) \ 2918 $(eval LOCAL_OVERRIDES_PACKAGES := $(sort $(LOCAL_OVERRIDES_PACKAGES) $(word 2,$(_o)))) \ 2919 true \ 2920 ,) 2921endef 2922 2923########################################################### 2924## API Check 2925########################################################### 2926 2927# eval this to define a rule that runs apicheck. 2928# 2929# Args: 2930# $(1) target 2931# $(2) stable api file 2932# $(3) api file to be tested 2933# $(4) stable removed api file 2934# $(5) removed api file to be tested 2935# $(6) arguments for apicheck 2936# $(7) command to run if apicheck failed 2937# $(8) target dependent on this api check 2938# $(9) additional dependencies 2939define check-api 2940$(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(strip $(1))-timestamp: $(2) $(3) $(4) $(APICHECK) $(9) 2941 @echo "Checking API:" $(1) 2942 $(hide) ( $(APICHECK_COMMAND) $(6) $(2) $(3) $(4) $(5) || ( $(7) ; exit 38 ) ) 2943 $(hide) mkdir -p $$(dir $$@) 2944 $(hide) touch $$@ 2945$(8): $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(strip $(1))-timestamp 2946endef 2947 2948## Whether to build from source if prebuilt alternative exists 2949########################################################### 2950# $(1): module name 2951# $(2): LOCAL_PATH 2952# Expands to empty string if not from source. 2953ifeq (true,$(ANDROID_BUILD_FROM_SOURCE)) 2954define if-build-from-source 2955true 2956endef 2957else 2958define if-build-from-source 2959$(if $(filter $(ANDROID_NO_PREBUILT_MODULES),$(1))$(filter \ 2960 $(addsuffix %,$(ANDROID_NO_PREBUILT_PATHS)),$(2)),true) 2961endef 2962endif 2963 2964# Include makefile $(1) if build from source for module $(2) 2965# $(1): the makefile to include 2966# $(2): module name 2967# $(3): LOCAL_PATH 2968define include-if-build-from-source 2969$(if $(call if-build-from-source,$(2),$(3)),$(eval include $(1))) 2970endef 2971 2972# Return the arch for the source file of a prebuilt 2973# Return "none" if no matching arch found and return empty 2974# if the input is empty, so the result can be passed to 2975# LOCAL_MODULE_TARGET_ARCH. 2976# $(1) the list of archs supported by the prebuilt 2977define get-prebuilt-src-arch 2978$(strip $(if $(filter $(TARGET_ARCH),$(1)),$(TARGET_ARCH),\ 2979 $(if $(filter $(TARGET_2ND_ARCH),$(1)),$(TARGET_2ND_ARCH),$(if $(1),none)))) 2980endef 2981 2982# ############################################################### 2983# Set up statistics gathering 2984# ############################################################### 2985STATS.MODULE_TYPE := \ 2986 HOST_STATIC_LIBRARY \ 2987 HOST_SHARED_LIBRARY \ 2988 STATIC_LIBRARY \ 2989 SHARED_LIBRARY \ 2990 EXECUTABLE \ 2991 HOST_EXECUTABLE \ 2992 PACKAGE \ 2993 PHONY_PACKAGE \ 2994 HOST_PREBUILT \ 2995 PREBUILT \ 2996 MULTI_PREBUILT \ 2997 JAVA_LIBRARY \ 2998 STATIC_JAVA_LIBRARY \ 2999 HOST_JAVA_LIBRARY \ 3000 DROIDDOC \ 3001 COPY_HEADERS \ 3002 NATIVE_TEST \ 3003 NATIVE_BENCHMARK \ 3004 HOST_NATIVE_TEST \ 3005 FUZZ_TEST \ 3006 HOST_FUZZ_TEST \ 3007 STATIC_TEST_LIBRARY \ 3008 HOST_STATIC_TEST_LIBRARY \ 3009 NOTICE_FILE \ 3010 HOST_DALVIK_JAVA_LIBRARY \ 3011 HOST_DALVIK_STATIC_JAVA_LIBRARY \ 3012 base_rules 3013 3014$(foreach $(s),$(STATS.MODULE_TYPE),$(eval STATS.MODULE_TYPE.$(s) :=)) 3015define record-module-type 3016$(strip $(if $(LOCAL_RECORDED_MODULE_TYPE),, 3017 $(if $(filter-out $(SOONG_ANDROID_MK),$(LOCAL_MODULE_MAKEFILE)), 3018 $(if $(filter $(1),$(STATS.MODULE_TYPE)), 3019 $(eval LOCAL_RECORDED_MODULE_TYPE := true) 3020 $(eval STATS.MODULE_TYPE.$(1) += 1), 3021 $(error Invalid module type: $(1)))))) 3022endef 3023 3024########################################################### 3025## Other includes 3026########################################################### 3027 3028# ----------------------------------------------------------------- 3029# Rules and functions to help copy important files to DIST_DIR 3030# when requested. 3031include $(BUILD_SYSTEM)/distdir.mk 3032 3033# Include any vendor specific definitions.mk file 3034-include $(TOPDIR)vendor/*/build/core/definitions.mk 3035-include $(TOPDIR)device/*/build/core/definitions.mk 3036-include $(TOPDIR)product/*/build/core/definitions.mk 3037 3038# broken: 3039# $(foreach file,$^,$(if $(findstring,.a,$(suffix $file)),-l$(file),$(file))) 3040 3041########################################################### 3042## Misc notes 3043########################################################### 3044 3045#DEPDIR = .deps 3046#df = $(DEPDIR)/$(*F) 3047 3048#SRCS = foo.c bar.c ... 3049 3050#%.o : %.c 3051# @$(MAKEDEPEND); \ 3052# cp $(df).d $(df).P; \ 3053# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ 3054# -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \ 3055# rm -f $(df).d 3056# $(COMPILE.c) -o $@ $< 3057 3058#-include $(SRCS:%.c=$(DEPDIR)/%.P) 3059 3060 3061#%.o : %.c 3062# $(COMPILE.c) -MD -o $@ $< 3063# @cp $*.d $*.P; \ 3064# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ 3065# -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \ 3066# rm -f $*.d 3067