definitions.mk revision 009f48b00f086213ec1e2f6619b45c0291ab4f44
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 := 872ND_TARGET_DEPENDENCIES_ON_SHARED_LIBRARIES := 88HOST_DEPENDENCIES_ON_SHARED_LIBRARIES := 89 90# Generated class file names for Android resource. 91# They are escaped and quoted so can be passed safely to a bash command. 92ANDROID_RESOURCE_GENERATED_CLASSES := 'R.class' 'R$$*.class' 'Manifest.class' 'Manifest$$*.class' 93 94########################################################### 95## Debugging; prints a variable list to stdout 96########################################################### 97 98# $(1): variable name list, not variable values 99define print-vars 100$(foreach var,$(1), \ 101 $(info $(var):) \ 102 $(foreach word,$($(var)), \ 103 $(info $(space)$(space)$(word)) \ 104 ) \ 105 ) 106endef 107 108########################################################### 109## Evaluates to true if the string contains the word true, 110## and empty otherwise 111## $(1): a var to test 112########################################################### 113 114define true-or-empty 115$(filter true, $(1)) 116endef 117 118 119########################################################### 120## Retrieve the directory of the current makefile 121## Must be called before including any other makefile!! 122########################################################### 123 124# Figure out where we are. 125define my-dir 126$(strip \ 127 $(eval LOCAL_MODULE_MAKEFILE := $$(lastword $$(MAKEFILE_LIST))) \ 128 $(if $(filter $(BUILD_SYSTEM)/% $(OUT_DIR)/%,$(LOCAL_MODULE_MAKEFILE)), \ 129 $(error my-dir must be called before including any other makefile.) \ 130 , \ 131 $(patsubst %/,%,$(dir $(LOCAL_MODULE_MAKEFILE))) \ 132 ) \ 133 ) 134endef 135 136########################################################### 137## Retrieve a list of all makefiles immediately below some directory 138########################################################### 139 140define all-makefiles-under 141$(wildcard $(1)/*/Android.mk) 142endef 143 144########################################################### 145## Look under a directory for makefiles that don't have parent 146## makefiles. 147########################################################### 148 149# $(1): directory to search under 150# Ignores $(1)/Android.mk 151define first-makefiles-under 152$(shell build/tools/findleaves.py --prune=$(OUT_DIR) --prune=.repo --prune=.git \ 153 --mindepth=2 $(1) Android.mk) 154endef 155 156########################################################### 157## Retrieve a list of all makefiles immediately below your directory 158## Must be called before including any other makefile!! 159########################################################### 160 161define all-subdir-makefiles 162$(call all-makefiles-under,$(call my-dir)) 163endef 164 165########################################################### 166## Look in the named list of directories for makefiles, 167## relative to the current directory. 168## Must be called before including any other makefile!! 169########################################################### 170 171# $(1): List of directories to look for under this directory 172define all-named-subdir-makefiles 173$(wildcard $(addsuffix /Android.mk, $(addprefix $(call my-dir)/,$(1)))) 174endef 175 176########################################################### 177## Find all of the java files under the named directories. 178## Meant to be used like: 179## SRC_FILES := $(call all-java-files-under,src tests) 180########################################################### 181 182define all-java-files-under 183$(patsubst ./%,%, \ 184 $(shell cd $(LOCAL_PATH) ; \ 185 find -L $(1) -name "*.java" -and -not -name ".*") \ 186 ) 187endef 188 189########################################################### 190## Find all of the java files from here. Meant to be used like: 191## SRC_FILES := $(call all-subdir-java-files) 192########################################################### 193 194define all-subdir-java-files 195$(call all-java-files-under,.) 196endef 197 198########################################################### 199## Find all of the c files under the named directories. 200## Meant to be used like: 201## SRC_FILES := $(call all-c-files-under,src tests) 202########################################################### 203 204define all-c-files-under 205$(patsubst ./%,%, \ 206 $(shell cd $(LOCAL_PATH) ; \ 207 find -L $(1) -name "*.c" -and -not -name ".*") \ 208 ) 209endef 210 211########################################################### 212## Find all of the c files from here. Meant to be used like: 213## SRC_FILES := $(call all-subdir-c-files) 214########################################################### 215 216define all-subdir-c-files 217$(call all-c-files-under,.) 218endef 219 220########################################################### 221## Find all files named "I*.aidl" under the named directories, 222## which must be relative to $(LOCAL_PATH). The returned list 223## is relative to $(LOCAL_PATH). 224########################################################### 225 226define all-Iaidl-files-under 227$(patsubst ./%,%, \ 228 $(shell cd $(LOCAL_PATH) ; \ 229 find -L $(1) -name "I*.aidl" -and -not -name ".*") \ 230 ) 231endef 232 233########################################################### 234## Find all of the "I*.aidl" files under $(LOCAL_PATH). 235########################################################### 236 237define all-subdir-Iaidl-files 238$(call all-Iaidl-files-under,.) 239endef 240 241########################################################### 242## Find all of the logtags files under the named directories. 243## Meant to be used like: 244## SRC_FILES := $(call all-logtags-files-under,src) 245########################################################### 246 247define all-logtags-files-under 248$(patsubst ./%,%, \ 249 $(shell cd $(LOCAL_PATH) ; \ 250 find -L $(1) -name "*.logtags" -and -not -name ".*") \ 251 ) 252endef 253 254########################################################### 255## Find all of the .proto files under the named directories. 256## Meant to be used like: 257## SRC_FILES := $(call all-proto-files-under,src) 258########################################################### 259 260define all-proto-files-under 261$(patsubst ./%,%, \ 262 $(shell cd $(LOCAL_PATH) ; \ 263 find -L $(1) -name "*.proto" -and -not -name ".*") \ 264 ) 265endef 266 267########################################################### 268## Find all of the RenderScript files under the named directories. 269## Meant to be used like: 270## SRC_FILES := $(call all-renderscript-files-under,src) 271########################################################### 272 273define all-renderscript-files-under 274$(patsubst ./%,%, \ 275 $(shell cd $(LOCAL_PATH) ; \ 276 find -L $(1) \( -name "*.rs" -or -name "*.fs" \) -and -not -name ".*") \ 277 ) 278endef 279 280########################################################### 281## Find all of the S files under the named directories. 282## Meant to be used like: 283## SRC_FILES := $(call all-c-files-under,src tests) 284########################################################### 285 286define all-S-files-under 287$(patsubst ./%,%, \ 288 $(shell cd $(LOCAL_PATH) ; \ 289 find -L $(1) -name "*.S" -and -not -name ".*") \ 290 ) 291endef 292 293########################################################### 294## Find all of the html files under the named directories. 295## Meant to be used like: 296## SRC_FILES := $(call all-html-files-under,src tests) 297########################################################### 298 299define all-html-files-under 300$(patsubst ./%,%, \ 301 $(shell cd $(LOCAL_PATH) ; \ 302 find -L $(1) -name "*.html" -and -not -name ".*") \ 303 ) 304endef 305 306########################################################### 307## Find all of the html files from here. Meant to be used like: 308## SRC_FILES := $(call all-subdir-html-files) 309########################################################### 310 311define all-subdir-html-files 312$(call all-html-files-under,.) 313endef 314 315########################################################### 316## Find all of the files matching pattern 317## SRC_FILES := $(call find-subdir-files, <pattern>) 318########################################################### 319 320define find-subdir-files 321$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) ; find -L $(1))) 322endef 323 324########################################################### 325# find the files in the subdirectory $1 of LOCAL_DIR 326# matching pattern $2, filtering out files $3 327# e.g. 328# SRC_FILES += $(call find-subdir-subdir-files, \ 329# css, *.cpp, DontWantThis.cpp) 330########################################################### 331 332define find-subdir-subdir-files 333$(filter-out $(patsubst %,$(1)/%,$(3)),$(patsubst ./%,%,$(shell cd \ 334 $(LOCAL_PATH) ; find -L $(1) -maxdepth 1 -name $(2)))) 335endef 336 337########################################################### 338## Find all of the files matching pattern 339## SRC_FILES := $(call all-subdir-java-files) 340########################################################### 341 342define find-subdir-assets 343$(if $(1),$(patsubst ./%,%, \ 344 $(shell if [ -d $(1) ] ; then cd $(1) ; find ./ -not -name '.*' -and -type f -and -not -type l ; fi)), \ 345 $(warning Empty argument supplied to find-subdir-assets) \ 346) 347endef 348 349########################################################### 350## Find various file types in a list of directories relative to $(LOCAL_PATH) 351########################################################### 352 353define find-other-java-files 354 $(call find-subdir-files,$(1) -name "*.java" -and -not -name ".*") 355endef 356 357define find-other-html-files 358 $(call find-subdir-files,$(1) -name "*.html" -and -not -name ".*") 359endef 360 361########################################################### 362# Use utility find to find given files in the given subdirs. 363# This function uses $(1), instead of LOCAL_PATH as the base. 364# $(1): the base dir, relative to the root of the source tree. 365# $(2): the file name pattern to be passed to find as "-name". 366# $(3): a list of subdirs of the base dir. 367# Returns: a list of paths relative to the base dir. 368########################################################### 369 370define find-files-in-subdirs 371$(patsubst ./%,%, \ 372 $(shell cd $(1) ; \ 373 find -L $(3) -name $(2) -and -not -name ".*") \ 374 ) 375endef 376 377########################################################### 378## Scan through each directory of $(1) looking for files 379## that match $(2) using $(wildcard). Useful for seeing if 380## a given directory or one of its parents contains 381## a particular file. Returns the first match found, 382## starting furthest from the root. 383########################################################### 384 385define find-parent-file 386$(strip \ 387 $(eval _fpf := $(wildcard $(foreach f, $(2), $(strip $(1))/$(f)))) \ 388 $(if $(_fpf),$(_fpf), \ 389 $(if $(filter-out ./ .,$(1)), \ 390 $(call find-parent-file,$(patsubst %/,%,$(dir $(1))),$(2)) \ 391 ) \ 392 ) \ 393) 394endef 395 396########################################################### 397## Function we can evaluate to introduce a dynamic dependency 398########################################################### 399 400define add-dependency 401$(1): $(2) 402endef 403 404########################################################### 405## The intermediates directory. Where object files go for 406## a given target. We could technically get away without 407## the "_intermediates" suffix on the directory, but it's 408## nice to be able to grep for that string to find out if 409## anyone's abusing the system. 410########################################################### 411 412# $(1): target class, like "APPS" 413# $(2): target name, like "NotePad" 414# $(3): if non-empty, this is a HOST target. 415# $(4): if non-empty, force the intermediates to be COMMON 416# $(5): if non-empty, force the intermedistes to be for the 2nd arch 417define intermediates-dir-for 418$(strip \ 419 $(eval _idfClass := $(strip $(1))) \ 420 $(if $(_idfClass),, \ 421 $(error $(LOCAL_PATH): Class not defined in call to intermediates-dir-for)) \ 422 $(eval _idfName := $(strip $(2))) \ 423 $(if $(_idfName),, \ 424 $(error $(LOCAL_PATH): Name not defined in call to intermediates-dir-for)) \ 425 $(eval _idfPrefix := $(if $(strip $(3)),HOST,TARGET)) \ 426 $(eval _idf2ndArchPrefix := $(if $(strip $(5)),$(TARGET_2ND_ARCH_VAR_PREFIX))) \ 427 $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \ 428 $(eval _idfIntBase := $($(_idfPrefix)_OUT_COMMON_INTERMEDIATES)) \ 429 , \ 430 $(eval _idfIntBase := $($(_idf2ndArchPrefix)$(_idfPrefix)_OUT_INTERMEDIATES)) \ 431 ) \ 432 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \ 433) 434endef 435 436# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE 437# to determine the intermediates directory. 438# 439# $(1): if non-empty, force the intermediates to be COMMON 440# $(2): if non-empty, force the intermediates to be for the 2nd arch 441define local-intermediates-dir 442$(strip \ 443 $(if $(strip $(LOCAL_MODULE_CLASS)),, \ 444 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-intermediates-dir)) \ 445 $(if $(strip $(LOCAL_MODULE)),, \ 446 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-intermediates-dir)) \ 447 $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(LOCAL_IS_HOST_MODULE),$(1),$(2)) \ 448) 449endef 450 451########################################################### 452## The generated sources directory. Placing generated 453## source files directly in the intermediates directory 454## causes problems for multiarch builds, where there are 455## two intermediates directories for a single target. Put 456## them in a separate directory, and they will be copied to 457## each intermediates directory automatically. 458########################################################### 459 460# $(1): target class, like "APPS" 461# $(2): target name, like "NotePad" 462# $(3): if non-empty, this is a HOST target. 463# $(4): if non-empty, force the generated sources to be COMMON 464define generated-sources-dir-for 465$(strip \ 466 $(eval _idfClass := $(strip $(1))) \ 467 $(if $(_idfClass),, \ 468 $(error $(LOCAL_PATH): Class not defined in call to generated-sources-dir-for)) \ 469 $(eval _idfName := $(strip $(2))) \ 470 $(if $(_idfName),, \ 471 $(error $(LOCAL_PATH): Name not defined in call to generated-sources-dir-for)) \ 472 $(eval _idfPrefix := $(if $(strip $(3)),HOST,TARGET)) \ 473 $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \ 474 $(eval _idfIntBase := $($(_idfPrefix)_OUT_GEN_COMMON)) \ 475 , \ 476 $(eval _idfIntBase := $($(_idfPrefix)_OUT_GEN)) \ 477 ) \ 478 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \ 479) 480endef 481 482# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE 483# to determine the generated sources directory. 484# 485# $(1): if non-empty, force the intermediates to be COMMON 486define local-generated-sources-dir 487$(strip \ 488 $(if $(strip $(LOCAL_MODULE_CLASS)),, \ 489 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-generated-sources-dir)) \ 490 $(if $(strip $(LOCAL_MODULE)),, \ 491 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-generated-sources-dir)) \ 492 $(call generated-sources-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(LOCAL_IS_HOST_MODULE),$(1)) \ 493) 494endef 495 496########################################################### 497## Convert "path/to/libXXX.so" to "-lXXX". 498## Any "path/to/libXXX.a" elements pass through unchanged. 499########################################################### 500 501define normalize-libraries 502$(foreach so,$(filter %.so,$(1)),-l$(patsubst lib%.so,%,$(notdir $(so))))\ 503$(filter-out %.so,$(1)) 504endef 505 506# TODO: change users to call the common version. 507define normalize-host-libraries 508$(call normalize-libraries,$(1)) 509endef 510 511define normalize-target-libraries 512$(call normalize-libraries,$(1)) 513endef 514 515########################################################### 516## Convert a list of short module names (e.g., "framework", "Browser") 517## into the list of files that are built for those modules. 518## NOTE: this won't return reliable results until after all 519## sub-makefiles have been included. 520## $(1): target list 521########################################################### 522 523define module-built-files 524$(foreach module,$(1),$(ALL_MODULES.$(module).BUILT)) 525endef 526 527########################################################### 528## Convert a list of short modules names (e.g., "framework", "Browser") 529## into the list of files that are installed for those modules. 530## NOTE: this won't return reliable results until after all 531## sub-makefiles have been included. 532## $(1): target list 533########################################################### 534 535define module-installed-files 536$(foreach module,$(1),$(ALL_MODULES.$(module).INSTALLED)) 537endef 538 539########################################################### 540## Convert a list of short modules names (e.g., "framework", "Browser") 541## into the list of files that should be used when linking 542## against that module as a public API. 543## TODO: Allow this for more than JAVA_LIBRARIES modules 544## NOTE: this won't return reliable results until after all 545## sub-makefiles have been included. 546## $(1): target list 547########################################################### 548 549define module-stubs-files 550$(foreach module,$(1),$(ALL_MODULES.$(module).STUBS)) 551endef 552 553########################################################### 554## Evaluates to the timestamp file for a doc module, which 555## is the dependency that should be used. 556## $(1): doc module 557########################################################### 558 559define doc-timestamp-for 560$(OUT_DOCS)/$(strip $(1))-timestamp 561endef 562 563 564########################################################### 565## Convert "core ext framework" to "out/.../javalib.jar ..." 566## $(1): library list 567## $(2): Non-empty if IS_HOST_MODULE 568########################################################### 569 570# $(1): library name 571# $(2): Non-empty if IS_HOST_MODULE 572define _java-lib-dir 573$(call intermediates-dir-for, \ 574 JAVA_LIBRARIES,$(1),$(2),COMMON) 575endef 576 577# $(1): library name 578# $(2): Non-empty if IS_HOST_MODULE 579define _java-lib-full-classes.jar 580$(call _java-lib-dir,$(1),$(2))/classes$(COMMON_JAVA_PACKAGE_SUFFIX) 581endef 582 583# $(1): library name list 584# $(2): Non-empty if IS_HOST_MODULE 585define java-lib-files 586$(foreach lib,$(1),$(call _java-lib-full-classes.jar,$(lib),$(2))) 587endef 588 589# $(1): library name 590# $(2): Non-empty if IS_HOST_MODULE 591define _java-lib-full-dep 592$(call _java-lib-dir,$(1),$(2))/$(if $(2),javalib,classes)$(COMMON_JAVA_PACKAGE_SUFFIX) 593endef 594 595# $(1): library name list 596# $(2): Non-empty if IS_HOST_MODULE 597define java-lib-deps 598$(foreach lib,$(1),$(call _java-lib-full-dep,$(lib),$(2))) 599endef 600 601########################################################### 602## Run rot13 on a string 603## $(1): the string. Must be one line. 604########################################################### 605define rot13 606$(shell echo $(1) | tr 'a-zA-Z' 'n-za-mN-ZA-M') 607endef 608 609 610########################################################### 611## Returns true if $(1) and $(2) are equal. Returns 612## the empty string if they are not equal. 613########################################################### 614define streq 615$(strip $(if $(strip $(1)),\ 616 $(if $(strip $(2)),\ 617 $(if $(filter-out __,_$(subst $(strip $(1)),,$(strip $(2)))$(subst $(strip $(2)),,$(strip $(1)))_),,true), \ 618 ),\ 619 $(if $(strip $(2)),\ 620 ,\ 621 true)\ 622 )) 623endef 624 625########################################################### 626## Convert "a b c" into "a:b:c" 627########################################################### 628define normalize-path-list 629$(subst $(space),:,$(strip $(1))) 630endef 631 632########################################################### 633## Read the word out of a colon-separated list of words. 634## This has the same behavior as the built-in function 635## $(word n,str). 636## 637## The individual words may not contain spaces. 638## 639## $(1): 1 based index 640## $(2): value of the form a:b:c... 641########################################################### 642 643define word-colon 644$(word $(1),$(subst :,$(space),$(2))) 645endef 646 647########################################################### 648## Convert "a=b c= d e = f" into "a=b c=d e=f" 649## 650## $(1): list to collapse 651## $(2): if set, separator word; usually "=", ":", or ":=" 652## Defaults to "=" if not set. 653########################################################### 654 655define collapse-pairs 656$(eval _cpSEP := $(strip $(if $(2),$(2),=)))\ 657$(subst $(space)$(_cpSEP)$(space),$(_cpSEP),$(strip \ 658 $(subst $(_cpSEP), $(_cpSEP) ,$(1)))) 659endef 660 661########################################################### 662## Given a list of pairs, if multiple pairs have the same 663## first components, keep only the first pair. 664## 665## $(1): list of pairs 666## $(2): the separator word, such as ":", "=", etc. 667define uniq-pairs-by-first-component 668$(eval _upbfc_fc_set :=)\ 669$(strip $(foreach w,$(1), $(eval _first := $(word 1,$(subst $(2),$(space),$(w))))\ 670 $(if $(filter $(_upbfc_fc_set),$(_first)),,$(w)\ 671 $(eval _upbfc_fc_set += $(_first)))))\ 672$(eval _upbfc_fc_set :=)\ 673$(eval _first:=) 674endef 675 676########################################################### 677## MODULE_TAG set operations 678########################################################### 679 680# Given a list of tags, return the targets that specify 681# any of those tags. 682# $(1): tag list 683define modules-for-tag-list 684$(sort $(foreach tag,$(1),$(ALL_MODULE_TAGS.$(tag)))) 685endef 686 687# Same as modules-for-tag-list, but operates on 688# ALL_MODULE_NAME_TAGS. 689# $(1): tag list 690define module-names-for-tag-list 691$(sort $(foreach tag,$(1),$(ALL_MODULE_NAME_TAGS.$(tag)))) 692endef 693 694# Given an accept and reject list, find the matching 695# set of targets. If a target has multiple tags and 696# any of them are rejected, the target is rejected. 697# Reject overrides accept. 698# $(1): list of tags to accept 699# $(2): list of tags to reject 700#TODO(dbort): do $(if $(strip $(1)),$(1),$(ALL_MODULE_TAGS)) 701#TODO(jbq): as of 20100106 nobody uses the second parameter 702define get-tagged-modules 703$(filter-out \ 704 $(call modules-for-tag-list,$(2)), \ 705 $(call modules-for-tag-list,$(1))) 706endef 707 708########################################################### 709## Append a leaf to a base path. Properly deals with 710## base paths ending in /. 711## 712## $(1): base path 713## $(2): leaf path 714########################################################### 715 716define append-path 717$(subst //,/,$(1)/$(2)) 718endef 719 720 721########################################################### 722## Package filtering 723########################################################### 724 725# Given a list of installed modules (short or long names) 726# return a list of the packages (yes, .apk packages, not 727# modules in general) that are overridden by this list and, 728# therefore, should not be installed. 729# $(1): mixed list of installed modules 730# TODO: This is fragile; find a reliable way to get this information. 731define _get-package-overrides 732 $(eval ### Discard any words containing slashes, unless they end in .apk, \ 733 ### in which case trim off the directory component and the suffix. \ 734 ### If there are no slashes, keep the entire word.) 735 $(eval _gpo_names := $(subst /,@@@ @@@,$(1))) 736 $(eval _gpo_names := \ 737 $(filter %.apk,$(_gpo_names)) \ 738 $(filter-out %@@@ @@@%,$(_gpo_names))) 739 $(eval _gpo_names := $(patsubst %.apk,%,$(_gpo_names))) 740 $(eval _gpo_names := $(patsubst @@@%,%,$(_gpo_names))) 741 742 $(eval ### Remove any remaining words that contain dots.) 743 $(eval _gpo_names := $(subst .,@@@ @@@,$(_gpo_names))) 744 $(eval _gpo_names := $(filter-out %@@@ @@@%,$(_gpo_names))) 745 746 $(eval ### Now we have a list of any words that could possibly refer to \ 747 ### packages, although there may be words that do not. Only \ 748 ### real packages will be present under PACKAGES.*, though.) 749 $(foreach _gpo_name,$(_gpo_names),$(PACKAGES.$(_gpo_name).OVERRIDES)) 750endef 751 752define get-package-overrides 753$(sort $(strip $(call _get-package-overrides,$(1)))) 754endef 755 756########################################################### 757## Output the command lines, or not 758########################################################### 759 760ifeq ($(strip $(SHOW_COMMANDS)),) 761define pretty 762@echo $1 763endef 764hide := @ 765else 766define pretty 767endef 768hide := 769endif 770 771########################################################### 772## Dump the variables that are associated with targets 773########################################################### 774 775define dump-module-variables 776@echo all_dependencies=$^ 777@echo PRIVATE_YACCFLAGS=$(PRIVATE_YACCFLAGS); 778@echo PRIVATE_CFLAGS=$(PRIVATE_CFLAGS); 779@echo PRIVATE_CPPFLAGS=$(PRIVATE_CPPFLAGS); 780@echo PRIVATE_DEBUG_CFLAGS=$(PRIVATE_DEBUG_CFLAGS); 781@echo PRIVATE_C_INCLUDES=$(PRIVATE_C_INCLUDES); 782@echo PRIVATE_LDFLAGS=$(PRIVATE_LDFLAGS); 783@echo PRIVATE_LDLIBS=$(PRIVATE_LDLIBS); 784@echo PRIVATE_ARFLAGS=$(PRIVATE_ARFLAGS); 785@echo PRIVATE_AAPT_FLAGS=$(PRIVATE_AAPT_FLAGS); 786@echo PRIVATE_DX_FLAGS=$(PRIVATE_DX_FLAGS); 787@echo PRIVATE_JAVACFLAGS=$(PRIVATE_JAVACFLAGS); 788@echo PRIVATE_JAVA_LIBRARIES=$(PRIVATE_JAVA_LIBRARIES); 789@echo PRIVATE_ALL_SHARED_LIBRARIES=$(PRIVATE_ALL_SHARED_LIBRARIES); 790@echo PRIVATE_ALL_STATIC_LIBRARIES=$(PRIVATE_ALL_STATIC_LIBRARIES); 791@echo PRIVATE_ALL_WHOLE_STATIC_LIBRARIES=$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES); 792@echo PRIVATE_ALL_OBJECTS=$(PRIVATE_ALL_OBJECTS); 793@echo PRIVATE_NO_CRT=$(PRIVATE_NO_CRT); 794endef 795 796########################################################### 797## Commands for using sed to replace given variable values 798########################################################### 799 800define transform-variables 801@mkdir -p $(dir $@) 802@echo "Sed: $(if $(PRIVATE_MODULE),$(PRIVATE_MODULE),$@) <= $<" 803$(hide) sed $(foreach var,$(REPLACE_VARS),-e "s/{{$(var)}}/$(subst /,\/,$(PWD)/$($(var)))/g") $< >$@ 804$(hide) if [ "$(suffix $@)" = ".sh" ]; then chmod a+rx $@; fi 805endef 806 807 808########################################################### 809## Commands for munging the dependency files GCC generates 810########################################################### 811# $(1): the input .d file 812# $(2): the output .P file 813define transform-d-to-p-args 814$(hide) cp $(1) $(2); \ 815 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ 816 -e '/^$$/ d' -e 's/$$/ :/' < $(1) >> $(2); \ 817 rm -f $(1) 818endef 819 820define transform-d-to-p 821$(call transform-d-to-p-args,$(@:%.o=%.d),$(@:%.o=%.P)) 822endef 823 824########################################################### 825## Commands for running lex 826########################################################### 827 828define transform-l-to-cpp 829@mkdir -p $(dir $@) 830@echo "Lex: $(PRIVATE_MODULE) <= $<" 831$(hide) $(LEX) -o$@ $< 832endef 833 834########################################################### 835## Commands for running yacc 836## 837## Because the extension of c++ files can change, the 838## extension must be specified in $1. 839## E.g, "$(call transform-y-to-cpp,.cpp)" 840########################################################### 841 842define transform-y-to-cpp 843@mkdir -p $(dir $@) 844@echo "Yacc: $(PRIVATE_MODULE) <= $<" 845$(YACC) $(PRIVATE_YACCFLAGS) -o $@ $< 846touch $(@:$1=$(YACC_HEADER_SUFFIX)) 847echo '#ifndef '$(@F:$1=_h) > $(@:$1=.h) 848echo '#define '$(@F:$1=_h) >> $(@:$1=.h) 849cat $(@:$1=$(YACC_HEADER_SUFFIX)) >> $(@:$1=.h) 850echo '#endif' >> $(@:$1=.h) 851rm -f $(@:$1=$(YACC_HEADER_SUFFIX)) 852endef 853 854########################################################### 855## Commands to compile RenderScript to Java 856########################################################### 857 858define transform-renderscripts-to-java-and-bc 859@echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)" 860$(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR) 861$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/res/raw 862$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/src 863$(hide) $(PRIVATE_RS_CC) \ 864 -o $(PRIVATE_RS_OUTPUT_DIR)/res/raw \ 865 -p $(PRIVATE_RS_OUTPUT_DIR)/src \ 866 -d $(PRIVATE_RS_OUTPUT_DIR) \ 867 -a $@ -MD \ 868 $(addprefix -target-api , $(PRIVATE_RS_TARGET_API)) \ 869 $(PRIVATE_RS_FLAGS) \ 870 $(foreach inc,$(PRIVATE_RS_INCLUDES),$(addprefix -I , $(inc))) \ 871 $(PRIVATE_RS_SOURCE_FILES) 872$(hide) mkdir -p $(dir $@) 873$(hide) touch $@ 874endef 875 876define transform-bc-to-so 877@echo "Renderscript compatibility: $(notdir $@) <= $(notdir $<)" 878$(hide) mkdir -p $(dir $@) 879$(hide) $(BCC_COMPAT) -O3 -o $(dir $@)/$(notdir $(<:.bc=.o)) -fPIC -shared \ 880 -rt-path $(RS_PREBUILT_CLCORE) -mtriple $(RS_TRIPLE) $< 881$(hide) $(PRIVATE_CXX) -shared -Wl,-soname,$(notdir $@) -nostdlib \ 882 -Wl,-rpath,\$$ORIGIN/../lib \ 883 $(dir $@)/$(notdir $(<:.bc=.o)) \ 884 $(RS_PREBUILT_COMPILER_RT) \ 885 -o $@ -L prebuilts/gcc/ \ 886 -L $(TARGET_OUT_INTERMEDIATE_LIBRARIES) $(RS_PREBUILT_LIBPATH) \ 887 -lRSSupport -lm -lc 888endef 889 890########################################################### 891## Commands to compile RenderScript to C++ 892########################################################### 893 894define transform-renderscripts-to-cpp-and-bc 895@echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)" 896$(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR) 897$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/ 898$(hide) $(PRIVATE_RS_CC) \ 899 -o $(PRIVATE_RS_OUTPUT_DIR)/ \ 900 -d $(PRIVATE_RS_OUTPUT_DIR) \ 901 -a $@ -MD \ 902 -reflect-c++ \ 903 $(PRIVATE_RS_FLAGS) \ 904 $(foreach inc,$(PRIVATE_RS_INCLUDES),$(addprefix -I , $(inc))) \ 905 $(PRIVATE_RS_SOURCE_FILES) 906$(hide) mkdir -p $(dir $@) 907$(hide) touch $@ 908endef 909 910 911########################################################### 912## Commands for running aidl 913########################################################### 914 915define transform-aidl-to-java 916@mkdir -p $(dir $@) 917@echo "Aidl: $(PRIVATE_MODULE) <= $<" 918$(hide) $(AIDL) -d$(patsubst %.java,%.P,$@) $(PRIVATE_AIDL_FLAGS) $< $@ 919endef 920#$(AIDL) $(PRIVATE_AIDL_FLAGS) $< - | indent -nut -br -npcs -l1000 > $@ 921 922 923########################################################### 924## Commands for running java-event-log-tags.py 925########################################################### 926 927define transform-logtags-to-java 928@mkdir -p $(dir $@) 929@echo "logtags: $@ <= $<" 930$(hide) $(JAVATAGS) -o $@ $^ 931endef 932 933 934########################################################### 935## Commands for running protoc to compile .proto into .java 936########################################################### 937 938define transform-proto-to-java 939@mkdir -p $(dir $@) 940@echo "Protoc: $@ <= $(PRIVATE_PROTO_SRC_FILES)" 941@rm -rf $(PRIVATE_PROTO_JAVA_OUTPUT_DIR) 942@mkdir -p $(PRIVATE_PROTO_JAVA_OUTPUT_DIR) 943$(hide) for f in $(PRIVATE_PROTO_SRC_FILES); do \ 944 $(PROTOC) \ 945 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \ 946 $(PRIVATE_PROTO_JAVA_OUTPUT_OPTION)="$(PRIVATE_PROTO_JAVA_OUTPUT_PARAMS):$(PRIVATE_PROTO_JAVA_OUTPUT_DIR)" \ 947 $(PRIVATE_PROTOC_FLAGS) \ 948 $$f || exit 33; \ 949 done 950$(hide) touch $@ 951endef 952 953###################################################################### 954## Commands for running protoc to compile .proto into .pb.cc and .pb.h 955###################################################################### 956define transform-proto-to-cc 957@mkdir -p $(dir $@) 958@echo "Protoc: $@ <= $<" 959$(hide) $(PROTOC) \ 960 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \ 961 $(PRIVATE_PROTOC_FLAGS) \ 962 --cpp_out=$(PRIVATE_PROTO_CC_OUTPUT_DIR) $< 963endef 964 965 966########################################################### 967## Commands for running gcc to compile a C++ file 968########################################################### 969 970define transform-cpp-to-o 971@mkdir -p $(dir $@) 972@echo "target $(PRIVATE_ARM_MODE) C++: $(PRIVATE_MODULE) <= $<" 973$(hide) $(PRIVATE_CXX) \ 974 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \ 975 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \ 976 $(addprefix -isystem ,\ 977 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 978 $(filter-out $(PRIVATE_C_INCLUDES), \ 979 $(PRIVATE_TARGET_PROJECT_INCLUDES) \ 980 $(PRIVATE_TARGET_C_INCLUDES)))) \ 981 -c \ 982 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 983 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \ 984 $(PRIVATE_TARGET_GLOBAL_CPPFLAGS) \ 985 $(PRIVATE_ARM_CFLAGS) \ 986 ) \ 987 $(PRIVATE_RTTI_FLAG) \ 988 $(PRIVATE_CFLAGS) \ 989 $(PRIVATE_CPPFLAGS) \ 990 $(PRIVATE_DEBUG_CFLAGS) \ 991 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $< 992$(transform-d-to-p) 993endef 994 995 996########################################################### 997## Commands for running gcc to compile a C file 998########################################################### 999 1000# $(1): extra flags 1001define transform-c-or-s-to-o-no-deps 1002@mkdir -p $(dir $@) 1003$(hide) $(PRIVATE_CC) \ 1004 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \ 1005 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \ 1006 $(addprefix -isystem ,\ 1007 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1008 $(filter-out $(PRIVATE_C_INCLUDES), \ 1009 $(PRIVATE_TARGET_PROJECT_INCLUDES) \ 1010 $(PRIVATE_TARGET_C_INCLUDES)))) \ 1011 -c \ 1012 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1013 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \ 1014 $(PRIVATE_ARM_CFLAGS) \ 1015 ) \ 1016 $(1) \ 1017 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $< 1018endef 1019 1020define transform-c-to-o-no-deps 1021@echo "target $(PRIVATE_ARM_MODE) C: $(PRIVATE_MODULE) <= $<" 1022$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_CONLYFLAGS) $(PRIVATE_DEBUG_CFLAGS)) 1023endef 1024 1025define transform-s-to-o-no-deps 1026@echo "target asm: $(PRIVATE_MODULE) <= $<" 1027$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS)) 1028endef 1029 1030define transform-c-to-o 1031$(transform-c-to-o-no-deps) 1032$(transform-d-to-p) 1033endef 1034 1035define transform-s-to-o 1036$(transform-s-to-o-no-deps) 1037$(transform-d-to-p) 1038endef 1039 1040########################################################### 1041## Commands for running gcc to compile an Objective-C file 1042## This should never happen for target builds but this 1043## will error at build time. 1044########################################################### 1045 1046define transform-m-to-o-no-deps 1047@echo "target ObjC: $(PRIVATE_MODULE) <= $<" 1048$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_DEBUG_CFLAGS)) 1049endef 1050 1051define transform-m-to-o 1052$(transform-m-to-o-no-deps) 1053$(transform-d-to-p) 1054endef 1055 1056########################################################### 1057## Commands for running gcc to compile a host C++ file 1058########################################################### 1059 1060define transform-host-cpp-to-o 1061@mkdir -p $(dir $@) 1062@echo "host C++: $(PRIVATE_MODULE) <= $<" 1063$(hide) $(PRIVATE_CXX) \ 1064 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \ 1065 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \ 1066 $(addprefix -isystem ,\ 1067 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1068 $(filter-out $(PRIVATE_C_INCLUDES), \ 1069 $(HOST_PROJECT_INCLUDES) \ 1070 $(PRIVATE_HOST_C_INCLUDES)))) \ 1071 -c \ 1072 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1073 $(PRIVATE_HOST_GLOBAL_CFLAGS) \ 1074 $(PRIVATE_HOST_GLOBAL_CPPFLAGS) \ 1075 ) \ 1076 $(PRIVATE_CFLAGS) \ 1077 $(PRIVATE_CPPFLAGS) \ 1078 $(PRIVATE_DEBUG_CFLAGS) \ 1079 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $< 1080$(transform-d-to-p) 1081endef 1082 1083 1084########################################################### 1085## Commands for running gcc to compile a host C file 1086########################################################### 1087 1088# $(1): extra flags 1089define transform-host-c-or-s-to-o-no-deps 1090@mkdir -p $(dir $@) 1091$(hide) $(PRIVATE_CC) \ 1092 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \ 1093 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \ 1094 $(addprefix -isystem ,\ 1095 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1096 $(filter-out $(PRIVATE_C_INCLUDES), \ 1097 $(HOST_PROJECT_INCLUDES) \ 1098 $(PRIVATE_HOST_C_INCLUDES)))) \ 1099 -c \ 1100 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1101 $(PRIVATE_HOST_GLOBAL_CFLAGS) \ 1102 ) \ 1103 $(1) \ 1104 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $< 1105endef 1106 1107define transform-host-c-to-o-no-deps 1108@echo "host C: $(PRIVATE_MODULE) <= $<" 1109$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_CONLYFLAGS) $(PRIVATE_DEBUG_CFLAGS)) 1110endef 1111 1112define transform-host-s-to-o-no-deps 1113@echo "host asm: $(PRIVATE_MODULE) <= $<" 1114$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS)) 1115endef 1116 1117define transform-host-c-to-o 1118$(transform-host-c-to-o-no-deps) 1119$(transform-d-to-p) 1120endef 1121 1122define transform-host-s-to-o 1123$(transform-host-s-to-o-no-deps) 1124$(transform-d-to-p) 1125endef 1126 1127########################################################### 1128## Commands for running gcc to compile a host Objective-C file 1129########################################################### 1130 1131define transform-host-m-to-o-no-deps 1132@echo "host ObjC: $(PRIVATE_MODULE) <= $<" 1133$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_DEBUG_CFLAGS)) 1134endef 1135 1136define transform-host-m-to-o 1137$(transform-host-m-to-o-no-deps) 1138$(transform-d-to-p) 1139endef 1140 1141########################################################### 1142## Commands for running ar 1143########################################################### 1144 1145define _concat-if-arg2-not-empty 1146$(if $(2),$(hide) $(1) $(2)) 1147endef 1148 1149# Split long argument list into smaller groups and call the command repeatedly 1150# Call the command at least once even if there are no arguments, as otherwise 1151# the output file won't be created. 1152# 1153# $(1): the command without arguments 1154# $(2): the arguments 1155define split-long-arguments 1156$(hide) $(1) $(wordlist 1,500,$(2)) 1157$(call _concat-if-arg2-not-empty,$(1),$(wordlist 501,1000,$(2))) 1158$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1001,1500,$(2))) 1159$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1501,2000,$(2))) 1160$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2001,2500,$(2))) 1161$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2501,3000,$(2))) 1162$(call _concat-if-arg2-not-empty,$(1),$(wordlist 3001,99999,$(2))) 1163endef 1164 1165# $(1): the full path of the source static library. 1166define _extract-and-include-single-target-whole-static-lib 1167@echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(1)]" 1168$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\ 1169 rm -rf $$ldir; \ 1170 mkdir -p $$ldir; \ 1171 filelist=; \ 1172 for f in `$(TARGET_AR) t $(1)`; do \ 1173 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) p $(1) $$f > $$ldir/$$f; \ 1174 filelist="$$filelist $$ldir/$$f"; \ 1175 done ; \ 1176 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \ 1177 $(PRIVATE_ARFLAGS) $@ $$filelist 1178 1179endef 1180 1181define extract-and-include-target-whole-static-libs 1182$(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \ 1183 $(call _extract-and-include-single-target-whole-static-lib, $(lib))) 1184endef 1185 1186# Explicitly delete the archive first so that ar doesn't 1187# try to add to an existing archive. 1188define transform-o-to-static-lib 1189@mkdir -p $(dir $@) 1190@rm -f $@ 1191$(extract-and-include-target-whole-static-libs) 1192@echo "target StaticLib: $(PRIVATE_MODULE) ($@)" 1193$(call split-long-arguments,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \ 1194 $(PRIVATE_ARFLAGS) $@,$(filter %.o, $^)) 1195endef 1196 1197########################################################### 1198## Commands for running host ar 1199########################################################### 1200 1201# $(1): the full path of the source static library. 1202define _extract-and-include-single-host-whole-static-lib 1203@echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(1)]" 1204$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\ 1205 rm -rf $$ldir; \ 1206 mkdir -p $$ldir; \ 1207 filelist=; \ 1208 for f in `$(HOST_AR) t $(1) | \grep '\.o$$'`; do \ 1209 $(HOST_AR) p $(1) $$f > $$ldir/$$f; \ 1210 filelist="$$filelist $$ldir/$$f"; \ 1211 done ; \ 1212 $(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $$filelist 1213 1214endef 1215 1216define extract-and-include-host-whole-static-libs 1217$(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \ 1218 $(call _extract-and-include-single-host-whole-static-lib, $(lib))) 1219endef 1220 1221# Explicitly delete the archive first so that ar doesn't 1222# try to add to an existing archive. 1223define transform-host-o-to-static-lib 1224@mkdir -p $(dir $@) 1225@rm -f $@ 1226$(extract-and-include-host-whole-static-libs) 1227@echo "host StaticLib: $(PRIVATE_MODULE) ($@)" 1228$(call split-long-arguments,$(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@,$(filter %.o, $^)) 1229endef 1230 1231 1232########################################################### 1233## Commands for running gcc to link a shared library or package 1234########################################################### 1235 1236# ld just seems to be so finicky with command order that we allow 1237# it to be overriden en-masse see combo/linux-arm.make for an example. 1238ifneq ($(HOST_CUSTOM_LD_COMMAND),true) 1239define transform-host-o-to-shared-lib-inner 1240$(hide) $(PRIVATE_CXX) \ 1241 -Wl,-rpath-link=$(HOST_OUT_INTERMEDIATE_LIBRARIES) \ 1242 -Wl,-rpath,\$$ORIGIN/../lib \ 1243 -shared -Wl,-soname,$(notdir $@) \ 1244 $(HOST_GLOBAL_LD_DIRS) \ 1245 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1246 $(PRIVATE_HOST_GLOBAL_LDFLAGS) \ 1247 ) \ 1248 $(PRIVATE_LDFLAGS) \ 1249 $(PRIVATE_ALL_OBJECTS) \ 1250 -Wl,--whole-archive \ 1251 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 1252 -Wl,--no-whole-archive \ 1253 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ 1254 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 1255 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ 1256 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ 1257 -o $@ \ 1258 $(PRIVATE_LDLIBS) 1259endef 1260endif 1261 1262define transform-host-o-to-shared-lib 1263@mkdir -p $(dir $@) 1264@echo "host SharedLib: $(PRIVATE_MODULE) ($@)" 1265$(transform-host-o-to-shared-lib-inner) 1266endef 1267 1268define transform-host-o-to-package 1269@mkdir -p $(dir $@) 1270@echo "host Package: $(PRIVATE_MODULE) ($@)" 1271$(transform-host-o-to-shared-lib-inner) 1272endef 1273 1274 1275########################################################### 1276## Commands for running gcc to link a shared library or package 1277########################################################### 1278 1279#echo >$@.vers "{"; \ 1280#echo >>$@.vers " global:"; \ 1281#$(BUILD_SYSTEM)/filter_symbols.sh $(TARGET_NM) " " ";" $(filter %.o,$^) | sort -u >>$@.vers; \ 1282#echo >>$@.vers " local:"; \ 1283#echo >>$@.vers " *;"; \ 1284#echo >>$@.vers "};"; \ 1285 1286# -Wl,--version-script=$@.vers \ 1287 1288# ld just seems to be so finicky with command order that we allow 1289# it to be overriden en-masse see combo/linux-arm.make for an example. 1290ifneq ($(TARGET_CUSTOM_LD_COMMAND),true) 1291define transform-o-to-shared-lib-inner 1292$(hide) $(PRIVATE_CXX) \ 1293 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \ 1294 -Wl,-rpath-link=$(PRIVATE_TARGET_OUT_INTERMEDIATE_LIBRARIES) \ 1295 -Wl,-rpath,\$$ORIGIN/../lib \ 1296 -shared -Wl,-soname,$(notdir $@) \ 1297 $(PRIVATE_LDFLAGS) \ 1298 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \ 1299 $(PRIVATE_ALL_OBJECTS) \ 1300 -Wl,--whole-archive \ 1301 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 1302 -Wl,--no-whole-archive \ 1303 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ 1304 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 1305 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ 1306 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ 1307 -o $@ \ 1308 $(PRIVATE_LDLIBS) 1309endef 1310endif 1311 1312define transform-o-to-shared-lib 1313@mkdir -p $(dir $@) 1314@echo "target SharedLib: $(PRIVATE_MODULE) ($@)" 1315$($(PRIVATE_2ND_ARCH_VAR_PREFIX)transform-o-to-shared-lib-inner) 1316endef 1317 1318 1319########################################################### 1320## Commands for filtering a target executable or library 1321########################################################### 1322 1323define transform-to-stripped 1324@mkdir -p $(dir $@) 1325@echo "target Strip: $(PRIVATE_MODULE) ($@)" 1326$(hide) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_STRIP_COMMAND) 1327endef 1328 1329 1330########################################################### 1331## Commands for running gcc to link an executable 1332########################################################### 1333 1334ifneq ($(TARGET_CUSTOM_LD_COMMAND),true) 1335define transform-o-to-executable-inner 1336$(hide) $(PRIVATE_CXX) \ 1337 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \ 1338 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \ 1339 -Wl,-rpath-link=$(PRIVATE_TARGET_OUT_INTERMEDIATE_LIBRARIES) \ 1340 -Wl,-rpath,\$$ORIGIN/../lib \ 1341 $(PRIVATE_LDFLAGS) \ 1342 $(PRIVATE_ALL_OBJECTS) \ 1343 -Wl,--whole-archive \ 1344 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 1345 -Wl,--no-whole-archive \ 1346 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ 1347 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 1348 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ 1349 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ 1350 -o $@ \ 1351 $(PRIVATE_LDLIBS) 1352endef 1353endif 1354 1355define transform-o-to-executable 1356@mkdir -p $(dir $@) 1357@echo "target Executable: $(PRIVATE_MODULE) ($@)" 1358$($(PRIVATE_2ND_ARCH_VAR_PREFIX)transform-o-to-executable-inner) 1359endef 1360 1361 1362########################################################### 1363## Commands for running gcc to link a statically linked 1364## executable. In practice, we only use this on arm, so 1365## the other platforms don't have the 1366## transform-o-to-static-executable defined 1367########################################################### 1368 1369ifneq ($(TARGET_CUSTOM_LD_COMMAND),true) 1370define transform-o-to-static-executable-inner 1371endef 1372endif 1373 1374define transform-o-to-static-executable 1375@mkdir -p $(dir $@) 1376@echo "target StaticExecutable: $(PRIVATE_MODULE) ($@)" 1377$($(PRIVATE_2ND_ARCH_VAR_PREFIX)transform-o-to-static-executable-inner) 1378endef 1379 1380 1381########################################################### 1382## Commands for running gcc to link a host executable 1383########################################################### 1384 1385ifneq ($(HOST_CUSTOM_LD_COMMAND),true) 1386define transform-host-o-to-executable-inner 1387$(hide) $(PRIVATE_CXX) \ 1388 $(PRIVATE_ALL_OBJECTS) \ 1389 -Wl,--whole-archive \ 1390 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 1391 -Wl,--no-whole-archive \ 1392 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ 1393 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 1394 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ 1395 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ 1396 -Wl,-rpath-link=$(HOST_OUT_INTERMEDIATE_LIBRARIES) \ 1397 -Wl,-rpath,\$$ORIGIN/../lib \ 1398 $(HOST_GLOBAL_LD_DIRS) \ 1399 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1400 $(PRIVATE_HOST_GLOBAL_LDFLAGS) \ 1401 -fPIE -pie \ 1402 ) \ 1403 $(PRIVATE_LDFLAGS) \ 1404 -o $@ \ 1405 $(PRIVATE_LDLIBS) 1406endef 1407endif 1408 1409define transform-host-o-to-executable 1410@mkdir -p $(dir $@) 1411@echo "host Executable: $(PRIVATE_MODULE) ($@)" 1412$(transform-host-o-to-executable-inner) 1413endef 1414 1415 1416########################################################### 1417## Commands for running javac to make .class files 1418########################################################### 1419 1420#@echo "Source intermediates dir: $(PRIVATE_SOURCE_INTERMEDIATES_DIR)" 1421#@echo "Source intermediates: $$(find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java')" 1422 1423# TODO: Right now we generate the asset resources twice, first as part 1424# of generating the Java classes, then at the end when packaging the final 1425# assets. This should be changed to do one of two things: (1) Don't generate 1426# any resource files the first time, only create classes during that stage; 1427# or (2) Don't use the -c flag with the second stage, instead taking the 1428# resource files from the first stage as additional input. My original intent 1429# was to use approach (2), but this requires a little more work in the tool. 1430# Maybe we should just use approach (1). 1431 1432# This rule creates the R.java and Manifest.java files, both of which 1433# are PRODUCT-neutral. Don't pass PRIVATE_PRODUCT_AAPT_CONFIG to this invocation. 1434define create-resource-java-files 1435@mkdir -p $(PRIVATE_SOURCE_INTERMEDIATES_DIR) 1436@mkdir -p $(dir $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) 1437$(hide) $(AAPT) package $(PRIVATE_AAPT_FLAGS) -m \ 1438 $(eval # PRIVATE_PRODUCT_AAPT_CONFIG is intentionally missing-- see comment.) \ 1439 $(addprefix -J , $(PRIVATE_SOURCE_INTERMEDIATES_DIR)) \ 1440 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \ 1441 $(addprefix -P , $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) \ 1442 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \ 1443 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \ 1444 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \ 1445 $(addprefix -G , $(PRIVATE_PROGUARD_OPTIONS_FILE)) \ 1446 $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \ 1447 $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \ 1448 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \ 1449 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION)-$(BUILD_NUMBER))) \ 1450 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \ 1451 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) 1452endef 1453 1454ifeq ($(HOST_OS),windows) 1455xlint_unchecked := 1456else 1457xlint_unchecked := -Xlint:unchecked 1458endif 1459 1460ifeq (true, $(ENABLE_INCREMENTALJAVAC)) 1461incremental_dex := --incremental 1462else 1463incremental_dex := 1464endif 1465 1466# emit-line, <word list>, <output file> 1467define emit-line 1468 $(if $(1),echo -n '$(strip $(1)) ' >> $(2)) 1469endef 1470 1471# dump-words-to-file, <word list>, <output file> 1472define dump-words-to-file 1473 @rm -f $(2) 1474 @$(call emit-line,$(wordlist 1,200,$(1)),$(2)) 1475 @$(call emit-line,$(wordlist 201,400,$(1)),$(2)) 1476 @$(call emit-line,$(wordlist 401,600,$(1)),$(2)) 1477 @$(call emit-line,$(wordlist 601,800,$(1)),$(2)) 1478 @$(call emit-line,$(wordlist 801,1000,$(1)),$(2)) 1479 @$(call emit-line,$(wordlist 1001,1200,$(1)),$(2)) 1480 @$(call emit-line,$(wordlist 1201,1400,$(1)),$(2)) 1481 @$(call emit-line,$(wordlist 1401,1600,$(1)),$(2)) 1482 @$(call emit-line,$(wordlist 1601,1800,$(1)),$(2)) 1483 @$(call emit-line,$(wordlist 1801,2000,$(1)),$(2)) 1484 @$(call emit-line,$(wordlist 2001,2200,$(1)),$(2)) 1485 @$(call emit-line,$(wordlist 2201,2400,$(1)),$(2)) 1486 @$(call emit-line,$(wordlist 2401,2600,$(1)),$(2)) 1487 @$(call emit-line,$(wordlist 2601,2800,$(1)),$(2)) 1488 @$(call emit-line,$(wordlist 2801,3000,$(1)),$(2)) 1489 @$(call emit-line,$(wordlist 3001,3200,$(1)),$(2)) 1490 @$(call emit-line,$(wordlist 3201,3400,$(1)),$(2)) 1491 @$(call emit-line,$(wordlist 3401,3600,$(1)),$(2)) 1492 @$(call emit-line,$(wordlist 3601,3800,$(1)),$(2)) 1493 @$(call emit-line,$(wordlist 3801,4000,$(1)),$(2)) 1494 @$(call emit-line,$(wordlist 4001,4200,$(1)),$(2)) 1495 @$(call emit-line,$(wordlist 4201,4400,$(1)),$(2)) 1496 @$(call emit-line,$(wordlist 4401,4600,$(1)),$(2)) 1497 @$(call emit-line,$(wordlist 4601,4800,$(1)),$(2)) 1498 @$(call emit-line,$(wordlist 4801,5000,$(1)),$(2)) 1499 @$(if $(wordlist 5001,5002,$(1)),$(error Too many words ($(words $(1))))) 1500endef 1501 1502# For a list of jar files, unzip them to a specified directory, 1503# but make sure that no META-INF files come along for the ride. 1504# 1505# $(1): files to unzip 1506# $(2): destination directory 1507define unzip-jar-files 1508 $(hide) for f in $(1); \ 1509 do \ 1510 if [ ! -f $$f ]; then \ 1511 echo Missing file $$f; \ 1512 exit 1; \ 1513 fi; \ 1514 unzip -qo $$f -d $(2); \ 1515 done \ 1516 $(if $(PRIVATE_DONT_DELETE_JAR_META_INF),,;rm -rf $(2)/META-INF) 1517endef 1518 1519# Common definition to invoke javac on the host and target. 1520# 1521# Some historical notes: 1522# - below we write the list of java files to java-source-list to avoid argument 1523# list length problems with Cygwin 1524# - we filter out duplicate java file names because eclipse's compiler 1525# doesn't like them. 1526# 1527# $(1): javac 1528# $(2): bootclasspath 1529define compile-java 1530$(hide) rm -f $@ 1531$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) 1532$(hide) mkdir -p $(dir $@) 1533$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR) 1534$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)) 1535$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list) 1536$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \ 1537 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list; \ 1538fi 1539$(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \ 1540 | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq 1541$(hide) if [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \ 1542 $(1) -encoding UTF-8 \ 1543 $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) \ 1544 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \ 1545 $(2) \ 1546 $(addprefix -classpath ,$(strip \ 1547 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \ 1548 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \ 1549 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \ 1550 $(PRIVATE_JAVACFLAGS) \ 1551 \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \ 1552 || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 ) \ 1553fi 1554$(if $(PRIVATE_JAVA_LAYERS_FILE), $(hide) build/tools/java-layers.py \ 1555 $(PRIVATE_JAVA_LAYERS_FILE) \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq,) 1556$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list 1557$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq 1558$(if $(PRIVATE_JAR_EXCLUDE_FILES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) \ 1559 -name $(word 1, $(PRIVATE_JAR_EXCLUDE_FILES)) \ 1560 $(addprefix -o -name , $(wordlist 2, 999, $(PRIVATE_JAR_EXCLUDE_FILES))) \ 1561 | xargs rm -rf) 1562$(if $(PRIVATE_JAR_PACKAGES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -mindepth 1 -type d \ 1563 $(foreach pkg, $(PRIVATE_JAR_PACKAGES), \ 1564 -not -path $(PRIVATE_CLASS_INTERMEDIATES_DIR)/$(subst .,/,$(pkg))) \ 1565 | xargs rm -rf) 1566$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \ 1567 $@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) . 1568endef 1569 1570define transform-java-to-classes.jar 1571@echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))" 1572$(call compile-java,$(TARGET_JAVAC),$(PRIVATE_BOOTCLASSPATH)) 1573endef 1574 1575# Override the above definitions if we want to do incremetal javac 1576ifeq (true, $(ENABLE_INCREMENTALJAVAC)) 1577define compile-java 1578$(hide) mkdir -p $(dir $@) 1579$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR) 1580$(hide) touch $(PRIVATE_CLASS_INTERMEDIATES_DIR)/newstamp 1581$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)) 1582$(hide) if [ -e $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stamp ] ; then \ 1583 newerFlag=$$(echo -n "-newer $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stamp") ; \ 1584 fi ; \ 1585 find $(PRIVATE_JAVA_SOURCES) $$newerFlag > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list ; \ 1586 if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \ 1587 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' $$newerFlag >> $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list; \ 1588 fi 1589$(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \ 1590 | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq 1591@echo "(Incremental) build source files:" 1592@cat $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq 1593$(hide) if [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \ 1594 $(1) -encoding UTF-8 \ 1595 $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) \ 1596 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \ 1597 $(2) \ 1598 $(addprefix -classpath ,$(strip \ 1599 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES) $(PRIVATE_CLASS_INTERMEDIATES_DIR)))) \ 1600 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \ 1601 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \ 1602 $(PRIVATE_JAVACFLAGS) \ 1603 \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \ 1604 || ( exit 41 ) \ 1605fi 1606$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list 1607$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq 1608$(hide) rm -f $@ 1609$(if $(PRIVATE_JAR_EXCLUDE_FILES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) \ 1610 -name $(word 1, $(PRIVATE_JAR_EXCLUDE_FILES)) \ 1611 $(addprefix -o -name , $(wordlist 2, 999, $(PRIVATE_JAR_EXCLUDE_FILES))) \ 1612 | xargs rm -rf) 1613$(if $(PRIVATE_JAR_PACKAGES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -mindepth 1 -type d \ 1614 $(foreach pkg, $(PRIVATE_JAR_PACKAGES), \ 1615 -not -path $(PRIVATE_CLASS_INTERMEDIATES_DIR)/$(subst .,/,$(pkg))) \ 1616 | xargs rm -rf) 1617$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \ 1618 $@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) . 1619$(hide) mv $(PRIVATE_CLASS_INTERMEDIATES_DIR)/newstamp $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stamp 1620endef 1621 1622define transform-java-to-classes.jar 1623@echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))" 1624$(call compile-java,$(TARGET_JAVAC),$(PRIVATE_BOOTCLASSPATH)) 1625endef 1626endif # ENABLE_INCREMENTALJAVAC 1627 1628define transform-classes.jar-to-emma 1629$(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \ 1630 $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR) \ 1631 $(addprefix -ix , $(PRIVATE_EMMA_COVERAGE_FILTER)) 1632endef 1633 1634#TODO: use a smaller -Xmx value for most libraries; 1635# only core.jar and framework.jar need a heap this big. 1636# Avoid the memory arguments on Windows, dx fails to load for some reason with them. 1637define transform-classes.jar-to-dex 1638@echo "target Dex: $(PRIVATE_MODULE)" 1639@mkdir -p $(dir $@) 1640$(hide) $(DX) \ 1641 $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx2048M) \ 1642 --dex --output=$@ \ 1643 $(incremental_dex) \ 1644 $(if $(NO_OPTIMIZE_DX), \ 1645 --no-optimize) \ 1646 $(if $(GENERATE_DEX_DEBUG), \ 1647 --debug --verbose \ 1648 --dump-to=$(@:.dex=.lst) \ 1649 --dump-width=1000) \ 1650 $(PRIVATE_DX_FLAGS) \ 1651 $< 1652endef 1653 1654# Create a mostly-empty .jar file that we'll add to later. 1655# The MacOS jar tool doesn't like creating empty jar files, 1656# so we need to give it something. 1657define create-empty-package 1658@mkdir -p $(dir $@) 1659$(hide) touch $(dir $@)/dummy 1660$(hide) (cd $(dir $@) && jar cf $(notdir $@) dummy) 1661$(hide) zip -qd $@ dummy 1662$(hide) rm $(dir $@)/dummy 1663endef 1664 1665#TODO: we kinda want to build different asset packages for 1666# different configurations, then combine them later (or something). 1667# Per-locale, etc. 1668# A list of dynamic and static parameters; build layers for 1669# dynamic params that lay over the static ones. 1670#TODO: update the manifest to point to the package file 1671#Note that the version numbers are given to aapt as simple default 1672#values; applications can override these by explicitly stating 1673#them in their manifest. 1674define add-assets-to-package 1675$(hide) $(AAPT) package -u $(PRIVATE_AAPT_FLAGS) \ 1676 $(addprefix -c , $(PRIVATE_PRODUCT_AAPT_CONFIG)) \ 1677 $(addprefix --preferred-configurations , $(PRIVATE_PRODUCT_AAPT_PREF_CONFIG)) \ 1678 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \ 1679 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \ 1680 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \ 1681 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \ 1682 $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \ 1683 $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \ 1684 $(addprefix --product , $(TARGET_AAPT_CHARACTERISTICS)) \ 1685 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \ 1686 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION)-$(BUILD_NUMBER))) \ 1687 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \ 1688 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \ 1689 -F $@ 1690endef 1691 1692define add-jni-shared-libs-to-package 1693$(hide) rm -rf $(dir $@)lib 1694$(hide) mkdir -p $(dir $@)lib/$(PRIVATE_JNI_SHARED_LIBRARIES_ABI) 1695$(hide) cp $(PRIVATE_JNI_SHARED_LIBRARIES) $(dir $@)lib/$(PRIVATE_JNI_SHARED_LIBRARIES_ABI) 1696$(hide) (cd $(dir $@) && zip -r $(notdir $@) lib) 1697$(hide) rm -rf $(dir $@)lib 1698endef 1699 1700#TODO: update the manifest to point to the dex file 1701define add-dex-to-package 1702$(if $(filter classes.dex,$(notdir $(PRIVATE_DEX_FILE))),\ 1703$(hide) zip -qj $@ $(PRIVATE_DEX_FILE),\ 1704$(hide) _adtp_classes_dex=$(dir $(PRIVATE_DEX_FILE))classes.dex; \ 1705cp $(PRIVATE_DEX_FILE) $$_adtp_classes_dex && \ 1706zip -qj $@ $$_adtp_classes_dex && rm -f $$_adtp_classes_dex) 1707endef 1708 1709# Add java resources added by the current module. 1710# 1711define add-java-resources-to-package 1712$(call dump-words-to-file, $(PRIVATE_EXTRA_JAR_ARGS), $(dir $@)jar-arg-list) 1713$(hide) jar uf $@ @$(dir $@)jar-arg-list 1714@rm -f $(dir $@)jar-arg-list 1715endef 1716 1717# Add java resources carried by static Java libraries. 1718# 1719define add-carried-java-resources 1720$(hide) if [ -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) ] ; then \ 1721 java_res_jar_flags=$$(find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -type f -a -not -name "*.class" \ 1722 | sed -e "s?^$(PRIVATE_CLASS_INTERMEDIATES_DIR)/? -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) ?"); \ 1723 if [ -n "$$java_res_jar_flags" ] ; then \ 1724 echo $$java_res_jar_flags >$(dir $@)java_res_jar_flags; \ 1725 jar uf $@ $$java_res_jar_flags; \ 1726 fi; \ 1727fi 1728endef 1729 1730# Sign a package using the specified key/cert. 1731# 1732define sign-package 1733$(hide) mv $@ $@.unsigned 1734$(hide) java -jar $(SIGNAPK_JAR) \ 1735 $(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) \ 1736 $(PRIVATE_ADDITIONAL_CERTIFICATES) $@.unsigned $@.signed 1737$(hide) mv $@.signed $@ 1738endef 1739 1740# Align STORED entries of a package on 4-byte boundaries 1741# to make them easier to mmap. 1742# 1743define align-package 1744$(hide) mv $@ $@.unaligned 1745$(hide) $(ZIPALIGN) -f 4 $@.unaligned $@.aligned 1746$(hide) mv $@.aligned $@ 1747endef 1748 1749define install-dex-debug 1750$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.dex" ]; then \ 1751 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \ 1752 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.dex \ 1753 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).dex; \ 1754 fi 1755$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.lst" ]; then \ 1756 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \ 1757 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.lst \ 1758 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).lst; \ 1759 fi 1760endef 1761 1762# TODO(joeo): If we can ever upgrade to post 3.81 make and get the 1763# new prebuilt rules to work, we should change this to copy the 1764# resources to the out directory and then copy the resources. 1765 1766# Note: we intentionally don't clean PRIVATE_CLASS_INTERMEDIATES_DIR 1767# in transform-java-to-classes for the sake of vm-tests. 1768define transform-host-java-to-package 1769@echo "host Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))" 1770$(call compile-java,$(HOST_JAVAC),$(PRIVATE_BOOTCLASSPATH)) 1771$(if $(PRIVATE_EXTRA_JAR_ARGS), $(call add-java-resources-to-package)) 1772endef 1773 1774########################################################### 1775## Commands for copying files 1776########################################################### 1777 1778# Define a rule to copy a header. Used via $(eval) by copy_headers.make. 1779# $(1): source header 1780# $(2): destination header 1781define copy-one-header 1782$(2): $(1) 1783 @echo "Header: $$@" 1784 $$(copy-file-to-new-target-with-cp) 1785endef 1786 1787# Define a rule to copy a file. For use via $(eval). 1788# $(1): source file 1789# $(2): destination file 1790define copy-one-file 1791$(2): $(1) | $(ACP) 1792 @echo "Copy: $$@" 1793 $$(copy-file-to-target) 1794endef 1795 1796# Copies many files. 1797# $(1): The files to copy. Each entry is a ':' separated src:dst pair 1798# Evaluates to the list of the dst files (ie suitable for a dependency list) 1799define copy-many-files 1800$(foreach f, $(1), $(strip \ 1801 $(eval _cmf_tuple := $(subst :, ,$(f))) \ 1802 $(eval _cmf_src := $(word 1,$(_cmf_tuple))) \ 1803 $(eval _cmf_dest := $(word 2,$(_cmf_tuple))) \ 1804 $(eval $(call copy-one-file,$(_cmf_src),$(_cmf_dest))) \ 1805 $(_cmf_dest))) 1806endef 1807 1808# Copy the file only if it's a well-formed xml file. For use via $(eval). 1809# $(1): source file 1810# $(2): destination file, must end with .xml. 1811define copy-xml-file-checked 1812$(2): $(1) | $(ACP) 1813 @echo "Copy xml: $$@" 1814 $(hide) xmllint $$< >/dev/null # Don't print the xml file to stdout. 1815 $$(copy-file-to-target) 1816endef 1817 1818# The -t option to acp and the -p option to cp is 1819# required for OSX. OSX has a ridiculous restriction 1820# where it's an error for a .a file's modification time 1821# to disagree with an internal timestamp, and this 1822# macro is used to install .a files (among other things). 1823 1824# Copy a single file from one place to another, 1825# preserving permissions and overwriting any existing 1826# file. 1827# We disable the "-t" option for acp cannot handle 1828# high resolution timestamp correctly on file systems like ext4. 1829# Therefore copy-file-to-target is the same as copy-file-to-new-target. 1830define copy-file-to-target 1831@mkdir -p $(dir $@) 1832$(hide) $(ACP) -fp $< $@ 1833endef 1834 1835# The same as copy-file-to-target, but use the local 1836# cp command instead of acp. 1837define copy-file-to-target-with-cp 1838@mkdir -p $(dir $@) 1839$(hide) cp -fp $< $@ 1840endef 1841 1842# The same as copy-file-to-target, but use the zipalign tool to do so. 1843define copy-file-to-target-with-zipalign 1844@mkdir -p $(dir $@) 1845$(hide) $(ZIPALIGN) -f 4 $< $@ 1846endef 1847 1848# The same as copy-file-to-target, but strip out "# comment"-style 1849# comments (for config files and such). 1850define copy-file-to-target-strip-comments 1851@mkdir -p $(dir $@) 1852$(hide) sed -e 's/#.*$$//' -e 's/[ \t]*$$//' -e '/^$$/d' < $< > $@ 1853endef 1854 1855# The same as copy-file-to-target, but don't preserve 1856# the old modification time. 1857define copy-file-to-new-target 1858@mkdir -p $(dir $@) 1859$(hide) $(ACP) -fp $< $@ 1860endef 1861 1862# The same as copy-file-to-new-target, but use the local 1863# cp command instead of acp. 1864define copy-file-to-new-target-with-cp 1865@mkdir -p $(dir $@) 1866$(hide) cp -f $< $@ 1867endef 1868 1869# Copy a prebuilt file to a target location. 1870define transform-prebuilt-to-target 1871@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)" 1872$(copy-file-to-target) 1873endef 1874 1875# Copy a prebuilt file to a target location, using zipalign on it. 1876define transform-prebuilt-to-target-with-zipalign 1877@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt APK: $(PRIVATE_MODULE) ($@)" 1878$(copy-file-to-target-with-zipalign) 1879endef 1880 1881# Copy a prebuilt file to a target location, stripping "# comment" comments. 1882define transform-prebuilt-to-target-strip-comments 1883@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)" 1884$(copy-file-to-target-strip-comments) 1885endef 1886 1887########################################################### 1888## On some platforms (MacOS), after copying a static 1889## library, ranlib must be run to update an internal 1890## timestamp!?!?! 1891########################################################### 1892 1893ifeq ($(HOST_RUN_RANLIB_AFTER_COPYING),true) 1894define transform-host-ranlib-copy-hack 1895 $(hide) ranlib $@ || true 1896endef 1897else 1898define transform-host-ranlib-copy-hack 1899@true 1900endef 1901endif 1902 1903ifeq ($(TARGET_RUN_RANLIB_AFTER_COPYING),true) 1904define transform-ranlib-copy-hack 1905 $(hide) ranlib $@ 1906endef 1907else 1908define transform-ranlib-copy-hack 1909@true 1910endef 1911endif 1912 1913 1914########################################################### 1915## Commands to call Proguard 1916########################################################### 1917define transform-jar-to-proguard 1918@echo Proguard: $@ 1919$(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS) \ 1920 $(addprefix -injars , $(PRIVATE_EXTRA_INPUT_JAR)) 1921endef 1922 1923########################################################### 1924## Stuff source generated from one-off tools 1925########################################################### 1926 1927define transform-generated-source 1928@echo "target Generated: $(PRIVATE_MODULE) <= $<" 1929@mkdir -p $(dir $@) 1930$(hide) $(PRIVATE_CUSTOM_TOOL) 1931endef 1932 1933 1934########################################################### 1935## Assertions about attributes of the target 1936########################################################### 1937 1938# $(1): The file to check 1939ifndef get-file-size 1940$(error HOST_OS must define get-file-size) 1941endif 1942 1943# Convert a partition data size (eg, as reported in /proc/mtd) to the 1944# size of the image used to flash that partition (which includes a 1945# spare area for each page). 1946# $(1): the partition data size 1947define image-size-from-data-size 1948$(strip $(eval _isfds_value := $$(shell echo $$$$(($(1) / $(BOARD_NAND_PAGE_SIZE) * \ 1949 ($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE))))))\ 1950$(if $(filter 0, $(_isfds_value)),$(shell echo $$(($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE)))),$(_isfds_value))\ 1951$(eval _isfds_value :=)) 1952endef 1953 1954# $(1): The file(s) to check (often $@) 1955# $(2): The maximum total image size, in decimal bytes 1956# $(3): the type of filesystem "yaffs" or "raw" 1957# 1958# If $(2) is empty, evaluates to "true" 1959# 1960# Reserve bad blocks. Make sure that MAX(1% of partition size, 2 blocks) 1961# is left over after the image has been flashed. Round the 1% up to the 1962# next whole flash block size. 1963define assert-max-file-size 1964$(if $(2), \ 1965 size=$$(for i in $(1); do $(call get-file-size,$$i); echo +; done; echo 0); \ 1966 total=$$(( $$( echo "$$size" ) )); \ 1967 printname=$$(echo -n "$(1)" | tr " " +); \ 1968 img_blocksize=$(call image-size-from-data-size,$(BOARD_FLASH_BLOCK_SIZE)); \ 1969 if [ "$(3)" == "yaffs" ]; then \ 1970 reservedblocks=8; \ 1971 else \ 1972 reservedblocks=0; \ 1973 fi; \ 1974 twoblocks=$$((img_blocksize * 2)); \ 1975 onepct=$$((((($(2) / 100) - 1) / img_blocksize + 1) * img_blocksize)); \ 1976 reserve=$$(((twoblocks > onepct ? twoblocks : onepct) + \ 1977 reservedblocks * img_blocksize)); \ 1978 maxsize=$$(($(2) - reserve)); \ 1979 echo "$$printname maxsize=$$maxsize blocksize=$$img_blocksize total=$$total reserve=$$reserve"; \ 1980 if [ "$$total" -gt "$$maxsize" ]; then \ 1981 echo "error: $$printname too large ($$total > [$(2) - $$reserve])"; \ 1982 false; \ 1983 elif [ "$$total" -gt $$((maxsize - 32768)) ]; then \ 1984 echo "WARNING: $$printname approaching size limit ($$total now; limit $$maxsize)"; \ 1985 fi \ 1986 , \ 1987 true \ 1988 ) 1989endef 1990 1991# Like assert-max-file-size, but the second argument is a partition 1992# size, which we'll convert to a max image size before checking it 1993# against the files. 1994# 1995# $(1): The file(s) to check (often $@) 1996# $(2): The partition size. 1997define assert-max-image-size 1998$(if $(2), \ 1999 $(call assert-max-file-size,$(1),$(call image-size-from-data-size,$(2))), \ 2000 true) 2001endef 2002 2003 2004########################################################### 2005## Define device-specific radio files 2006########################################################### 2007INSTALLED_RADIOIMAGE_TARGET := 2008 2009# Copy a radio image file to the output location, and add it to 2010# INSTALLED_RADIOIMAGE_TARGET. 2011# $(1): filename 2012define add-radio-file 2013 $(eval $(call add-radio-file-internal,$(1),$(notdir $(1)))) 2014endef 2015define add-radio-file-internal 2016INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2) 2017$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP) 2018 $$(transform-prebuilt-to-target) 2019endef 2020 2021# Version of add-radio-file that also arranges for the version of the 2022# file to be checked against the contents of 2023# $(TARGET_BOARD_INFO_FILE). 2024# $(1): filename 2025# $(2): name of version variable in board-info (eg, "version-baseband") 2026define add-radio-file-checked 2027 $(eval $(call add-radio-file-checked-internal,$(1),$(notdir $(1)),$(2))) 2028endef 2029define add-radio-file-checked-internal 2030INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2) 2031BOARD_INFO_CHECK += $(3):$(LOCAL_PATH)/$(1) 2032$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP) 2033 $$(transform-prebuilt-to-target) 2034endef 2035 2036 2037########################################################### 2038# Override the package defined in $(1), setting the 2039# variables listed below differently. 2040# 2041# $(1): The makefile to override (relative to the source 2042# tree root) 2043# $(2): Old LOCAL_PACKAGE_NAME value. 2044# $(3): New LOCAL_PACKAGE_NAME value. 2045# $(4): New LOCAL_MANIFEST_PACKAGE_NAME value. 2046# $(5): New LOCAL_CERTIFICATE value. 2047# $(6): New LOCAL_INSTRUMENTATION_FOR value. 2048# $(7): New LOCAL_MANIFEST_INSTRUMENTATION_FOR value. 2049# 2050# Note that LOCAL_PACKAGE_OVERRIDES is NOT cleared in 2051# clear_vars.mk. 2052########################################################### 2053define inherit-package 2054 $(eval $(call inherit-package-internal,$(1),$(2),$(3),$(4),$(5),$(6),$(7))) 2055endef 2056 2057define inherit-package-internal 2058 LOCAL_PACKAGE_OVERRIDES \ 2059 := $(strip $(1))||$(strip $(2))||$(strip $(3))||$(strip $(4))||&&$(strip $(5))||&&$(strip $(6))||&&$(strip $(7)) $(LOCAL_PACKAGE_OVERRIDES) 2060 include $(1) 2061 LOCAL_PACKAGE_OVERRIDES \ 2062 := $(wordlist 1,$(words $(LOCAL_PACKAGE_OVERRIDES)), $(LOCAL_PACKAGE_OVERRIDES)) 2063endef 2064 2065# To be used with inherit-package above 2066# Evalutes to true if the package was overridden 2067define set-inherited-package-variables 2068$(strip $(call set-inherited-package-variables-internal)) 2069endef 2070 2071define keep-or-override 2072$(eval $(1) := $(if $(2),$(2),$($(1)))) 2073endef 2074 2075define set-inherited-package-variables-internal 2076 $(eval _o := $(subst ||, ,$(lastword $(LOCAL_PACKAGE_OVERRIDES)))) 2077 $(eval _n := $(subst ||, ,$(firstword $(LOCAL_PACKAGE_OVERRIDES)))) 2078 $(if $(filter $(word 2,$(_n)),$(LOCAL_PACKAGE_NAME)), \ 2079 $(eval LOCAL_PACKAGE_NAME := $(word 3,$(_o))) \ 2080 $(eval LOCAL_MANIFEST_PACKAGE_NAME := $(word 4,$(_o))) \ 2081 $(call keep-or-override,LOCAL_CERTIFICATE,$(patsubst &&%,%,$(word 5,$(_o)))) \ 2082 $(call keep-or-override,LOCAL_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 6,$(_o)))) \ 2083 $(call keep-or-override,LOCAL_MANIFEST_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 7,$(_o)))) \ 2084 $(eval LOCAL_OVERRIDES_PACKAGES := $(sort $(LOCAL_OVERRIDES_PACKAGES) $(word 2,$(_o)))) \ 2085 true \ 2086 ,) 2087endef 2088 2089########################################################### 2090## Expand a module name list with REQUIRED modules 2091########################################################### 2092# $(1): The variable name that holds the initial module name list. 2093# the variable will be modified to hold the expanded results. 2094# $(2): The initial module name list. 2095# Returns empty string (maybe with some whitespaces). 2096define expand-required-modules 2097$(eval _erm_new_modules := $(sort $(filter-out $($(1)),\ 2098 $(foreach m,$(2),$(ALL_MODULES.$(m).REQUIRED)))))\ 2099$(if $(_erm_new_modules),$(eval $(1) += $(_erm_new_modules))\ 2100 $(call expand-required-modules,$(1),$(_erm_new_modules))) 2101endef 2102 2103########################################################### 2104## API Check 2105########################################################### 2106 2107# eval this to define a rule that runs apicheck. 2108# 2109# Args: 2110# $(1) target 2111# $(2) stable api file 2112# $(3) api file to be tested 2113# $(4) arguments for apicheck 2114# $(5) command to run if apicheck failed 2115# $(6) target dependent on this api check 2116# $(7) additional dependencies 2117define check-api 2118$(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(strip $(1))-timestamp: $(2) $(3) $(APICHECK) $(7) 2119 @echo "Checking API:" $(1) 2120 $(hide) ( $(APICHECK_COMMAND) $(4) $(2) $(3) || ( $(5) ; exit 38 ) ) 2121 $(hide) mkdir -p $$(dir $$@) 2122 $(hide) touch $$@ 2123$(6): $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(strip $(1))-timestamp 2124endef 2125 2126## Whether to build from source if prebuilt alternative exists 2127########################################################### 2128# $(1): module name 2129# $(2): LOCAL_PATH 2130# Expands to empty string if not from source. 2131ifeq (true,$(ANDROID_BUILD_FROM_SOURCE)) 2132define if-build-from-source 2133true 2134endef 2135else 2136define if-build-from-source 2137$(if $(filter $(ANDROID_NO_PREBUILT_MODULES),$(1))$(filter \ 2138 $(addsuffix %,$(ANDROID_NO_PREBUILT_PATHS)),$(2)),true) 2139endef 2140endif 2141 2142# Include makefile $(1) if build from source for module $(2) 2143# $(1): the makefile to include 2144# $(2): module name 2145# $(3): LOCAL_PATH 2146define include-if-build-from-source 2147$(if $(call if-build-from-source,$(2),$(3)),$(eval include $(1))) 2148endef 2149 2150## Return the arch for the source file of a prebuilt 2151# $(1) the list of archs supported by the prebuilt 2152define get-prebuilt-src-arch 2153$(strip $(if $(filter $(TARGET_ARCH),$(1)),$(TARGET_ARCH),\ 2154 $(if $(filter $(TARGET_2ND_ARCH),$(1)),$(TARGET_2ND_ARCH)))) 2155endef 2156 2157########################################################### 2158## Other includes 2159########################################################### 2160 2161# ----------------------------------------------------------------- 2162# Rules and functions to help copy important files to DIST_DIR 2163# when requested. 2164include $(BUILD_SYSTEM)/distdir.mk 2165 2166# Include any vendor specific definitions.mk file 2167-include $(TOPDIR)vendor/*/build/core/definitions.mk 2168 2169# broken: 2170# $(foreach file,$^,$(if $(findstring,.a,$(suffix $file)),-l$(file),$(file))) 2171 2172########################################################### 2173## Misc notes 2174########################################################### 2175 2176#DEPDIR = .deps 2177#df = $(DEPDIR)/$(*F) 2178 2179#SRCS = foo.c bar.c ... 2180 2181#%.o : %.c 2182# @$(MAKEDEPEND); \ 2183# cp $(df).d $(df).P; \ 2184# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ 2185# -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \ 2186# rm -f $(df).d 2187# $(COMPILE.c) -o $@ $< 2188 2189#-include $(SRCS:%.c=$(DEPDIR)/%.P) 2190 2191 2192#%.o : %.c 2193# $(COMPILE.c) -MD -o $@ $< 2194# @cp $*.d $*.P; \ 2195# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ 2196# -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \ 2197# rm -f $*.d 2198