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