definitions.mk revision e7be6ffa985c7db458f927b74a2cbc34071de040
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) 851endef 852 853########################################################### 854## Commands to compile RenderScript to Java 855########################################################### 856 857define transform-renderscripts-to-java-and-bc 858@echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)" 859$(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR) 860$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/res/raw 861$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/src 862$(hide) $(PRIVATE_RS_CC) \ 863 -o $(PRIVATE_RS_OUTPUT_DIR)/res/raw \ 864 -p $(PRIVATE_RS_OUTPUT_DIR)/src \ 865 -d $(PRIVATE_RS_OUTPUT_DIR) \ 866 -a $@ -MD \ 867 $(addprefix -target-api , $(PRIVATE_RS_TARGET_API)) \ 868 $(PRIVATE_RS_FLAGS) \ 869 $(foreach inc,$(PRIVATE_RS_INCLUDES),$(addprefix -I , $(inc))) \ 870 $(PRIVATE_RS_SOURCE_FILES) 871$(hide) mkdir -p $(dir $@) 872$(hide) touch $@ 873endef 874 875define transform-bc-to-so 876@echo "Renderscript compatibility: $(notdir $@) <= $(notdir $<)" 877$(hide) mkdir -p $(dir $@) 878$(hide) $(BCC_COMPAT) -O3 -o $(dir $@)/$(notdir $(<:.bc=.o)) -fPIC -shared \ 879 -rt-path $(RS_PREBUILT_CLCORE) -mtriple $(RS_TRIPLE) $< 880$(hide) $(PRIVATE_CXX) -shared -Wl,-soname,$(notdir $@) -nostdlib \ 881 -Wl,-rpath,\$$ORIGIN/../lib \ 882 $(dir $@)/$(notdir $(<:.bc=.o)) \ 883 $(RS_PREBUILT_COMPILER_RT) \ 884 -o $@ -L prebuilts/gcc/ \ 885 -L $(TARGET_OUT_INTERMEDIATE_LIBRARIES) $(RS_PREBUILT_LIBPATH) \ 886 -lRSSupport -lm -lc 887endef 888 889########################################################### 890## Commands to compile RenderScript to C++ 891########################################################### 892 893define transform-renderscripts-to-cpp-and-bc 894@echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)" 895$(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR) 896$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/ 897$(hide) $(PRIVATE_RS_CC) \ 898 -o $(PRIVATE_RS_OUTPUT_DIR)/ \ 899 -d $(PRIVATE_RS_OUTPUT_DIR) \ 900 -a $@ -MD \ 901 -reflect-c++ \ 902 $(PRIVATE_RS_FLAGS) \ 903 $(foreach inc,$(PRIVATE_RS_INCLUDES),$(addprefix -I , $(inc))) \ 904 $(PRIVATE_RS_SOURCE_FILES) 905$(hide) mkdir -p $(dir $@) 906$(hide) touch $@ 907endef 908 909 910########################################################### 911## Commands for running aidl 912########################################################### 913 914define transform-aidl-to-java 915@mkdir -p $(dir $@) 916@echo "Aidl: $(PRIVATE_MODULE) <= $<" 917$(hide) $(AIDL) -d$(patsubst %.java,%.P,$@) $(PRIVATE_AIDL_FLAGS) $< $@ 918endef 919#$(AIDL) $(PRIVATE_AIDL_FLAGS) $< - | indent -nut -br -npcs -l1000 > $@ 920 921 922########################################################### 923## Commands for running java-event-log-tags.py 924########################################################### 925 926define transform-logtags-to-java 927@mkdir -p $(dir $@) 928@echo "logtags: $@ <= $<" 929$(hide) $(JAVATAGS) -o $@ $^ 930endef 931 932 933########################################################### 934## Commands for running protoc to compile .proto into .java 935########################################################### 936 937define transform-proto-to-java 938@mkdir -p $(dir $@) 939@echo "Protoc: $@ <= $(PRIVATE_PROTO_SRC_FILES)" 940@rm -rf $(PRIVATE_PROTO_JAVA_OUTPUT_DIR) 941@mkdir -p $(PRIVATE_PROTO_JAVA_OUTPUT_DIR) 942$(hide) for f in $(PRIVATE_PROTO_SRC_FILES); do \ 943 $(PROTOC) \ 944 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \ 945 $(PRIVATE_PROTO_JAVA_OUTPUT_OPTION)="$(PRIVATE_PROTO_JAVA_OUTPUT_PARAMS):$(PRIVATE_PROTO_JAVA_OUTPUT_DIR)" \ 946 $(PRIVATE_PROTOC_FLAGS) \ 947 $$f || exit 33; \ 948 done 949$(hide) touch $@ 950endef 951 952###################################################################### 953## Commands for running protoc to compile .proto into .pb.cc and .pb.h 954###################################################################### 955define transform-proto-to-cc 956@mkdir -p $(dir $@) 957@echo "Protoc: $@ <= $<" 958$(hide) $(PROTOC) \ 959 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \ 960 $(PRIVATE_PROTOC_FLAGS) \ 961 --cpp_out=$(PRIVATE_PROTO_CC_OUTPUT_DIR) $< 962endef 963 964 965########################################################### 966## Commands for running gcc to compile a C++ file 967########################################################### 968 969define transform-cpp-to-o 970@mkdir -p $(dir $@) 971@echo "target $(PRIVATE_ARM_MODE) C++: $(PRIVATE_MODULE) <= $<" 972$(hide) $(PRIVATE_CXX) \ 973 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \ 974 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \ 975 $(addprefix -isystem ,\ 976 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 977 $(filter-out $(PRIVATE_C_INCLUDES), \ 978 $(PRIVATE_TARGET_PROJECT_INCLUDES) \ 979 $(PRIVATE_TARGET_C_INCLUDES)))) \ 980 -c \ 981 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 982 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \ 983 $(PRIVATE_TARGET_GLOBAL_CPPFLAGS) \ 984 $(PRIVATE_ARM_CFLAGS) \ 985 ) \ 986 $(PRIVATE_RTTI_FLAG) \ 987 $(PRIVATE_CFLAGS) \ 988 $(PRIVATE_CPPFLAGS) \ 989 $(PRIVATE_DEBUG_CFLAGS) \ 990 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $< 991$(transform-d-to-p) 992endef 993 994 995########################################################### 996## Commands for running gcc to compile a C file 997########################################################### 998 999# $(1): extra flags 1000define transform-c-or-s-to-o-no-deps 1001@mkdir -p $(dir $@) 1002$(hide) $(PRIVATE_CC) \ 1003 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \ 1004 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \ 1005 $(addprefix -isystem ,\ 1006 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1007 $(filter-out $(PRIVATE_C_INCLUDES), \ 1008 $(PRIVATE_TARGET_PROJECT_INCLUDES) \ 1009 $(PRIVATE_TARGET_C_INCLUDES)))) \ 1010 -c \ 1011 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1012 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \ 1013 $(PRIVATE_ARM_CFLAGS) \ 1014 ) \ 1015 $(1) \ 1016 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $< 1017endef 1018 1019define transform-c-to-o-no-deps 1020@echo "target $(PRIVATE_ARM_MODE) C: $(PRIVATE_MODULE) <= $<" 1021$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_CONLYFLAGS) $(PRIVATE_DEBUG_CFLAGS)) 1022endef 1023 1024define transform-s-to-o-no-deps 1025@echo "target asm: $(PRIVATE_MODULE) <= $<" 1026$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS)) 1027endef 1028 1029define transform-c-to-o 1030$(transform-c-to-o-no-deps) 1031$(transform-d-to-p) 1032endef 1033 1034define transform-s-to-o 1035$(transform-s-to-o-no-deps) 1036$(transform-d-to-p) 1037endef 1038 1039########################################################### 1040## Commands for running gcc to compile an Objective-C file 1041## This should never happen for target builds but this 1042## will error at build time. 1043########################################################### 1044 1045define transform-m-to-o-no-deps 1046@echo "target ObjC: $(PRIVATE_MODULE) <= $<" 1047$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_DEBUG_CFLAGS)) 1048endef 1049 1050define transform-m-to-o 1051$(transform-m-to-o-no-deps) 1052$(transform-d-to-p) 1053endef 1054 1055########################################################### 1056## Commands for running gcc to compile a host C++ file 1057########################################################### 1058 1059define transform-host-cpp-to-o 1060@mkdir -p $(dir $@) 1061@echo "host C++: $(PRIVATE_MODULE) <= $<" 1062$(hide) $(PRIVATE_CXX) \ 1063 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \ 1064 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \ 1065 $(addprefix -isystem ,\ 1066 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1067 $(filter-out $(PRIVATE_C_INCLUDES), \ 1068 $(HOST_PROJECT_INCLUDES) \ 1069 $(PRIVATE_HOST_C_INCLUDES)))) \ 1070 -c \ 1071 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1072 $(PRIVATE_HOST_GLOBAL_CFLAGS) \ 1073 $(PRIVATE_HOST_GLOBAL_CPPFLAGS) \ 1074 ) \ 1075 $(PRIVATE_CFLAGS) \ 1076 $(PRIVATE_CPPFLAGS) \ 1077 $(PRIVATE_DEBUG_CFLAGS) \ 1078 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $< 1079$(transform-d-to-p) 1080endef 1081 1082 1083########################################################### 1084## Commands for running gcc to compile a host C file 1085########################################################### 1086 1087# $(1): extra flags 1088define transform-host-c-or-s-to-o-no-deps 1089@mkdir -p $(dir $@) 1090$(hide) $(PRIVATE_CC) \ 1091 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \ 1092 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \ 1093 $(addprefix -isystem ,\ 1094 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1095 $(filter-out $(PRIVATE_C_INCLUDES), \ 1096 $(HOST_PROJECT_INCLUDES) \ 1097 $(PRIVATE_HOST_C_INCLUDES)))) \ 1098 -c \ 1099 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1100 $(PRIVATE_HOST_GLOBAL_CFLAGS) \ 1101 ) \ 1102 $(1) \ 1103 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $< 1104endef 1105 1106define transform-host-c-to-o-no-deps 1107@echo "host C: $(PRIVATE_MODULE) <= $<" 1108$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_CONLYFLAGS) $(PRIVATE_DEBUG_CFLAGS)) 1109endef 1110 1111define transform-host-s-to-o-no-deps 1112@echo "host asm: $(PRIVATE_MODULE) <= $<" 1113$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS)) 1114endef 1115 1116define transform-host-c-to-o 1117$(transform-host-c-to-o-no-deps) 1118$(transform-d-to-p) 1119endef 1120 1121define transform-host-s-to-o 1122$(transform-host-s-to-o-no-deps) 1123$(transform-d-to-p) 1124endef 1125 1126########################################################### 1127## Commands for running gcc to compile a host Objective-C file 1128########################################################### 1129 1130define transform-host-m-to-o-no-deps 1131@echo "host ObjC: $(PRIVATE_MODULE) <= $<" 1132$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_DEBUG_CFLAGS)) 1133endef 1134 1135define transform-host-m-to-o 1136$(transform-host-m-to-o-no-deps) 1137$(transform-d-to-p) 1138endef 1139 1140########################################################### 1141## Commands for running ar 1142########################################################### 1143 1144define _concat-if-arg2-not-empty 1145$(if $(2),$(hide) $(1) $(2)) 1146endef 1147 1148# Split long argument list into smaller groups and call the command repeatedly 1149# Call the command at least once even if there are no arguments, as otherwise 1150# the output file won't be created. 1151# 1152# $(1): the command without arguments 1153# $(2): the arguments 1154define split-long-arguments 1155$(hide) $(1) $(wordlist 1,500,$(2)) 1156$(call _concat-if-arg2-not-empty,$(1),$(wordlist 501,1000,$(2))) 1157$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1001,1500,$(2))) 1158$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1501,2000,$(2))) 1159$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2001,2500,$(2))) 1160$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2501,3000,$(2))) 1161$(call _concat-if-arg2-not-empty,$(1),$(wordlist 3001,99999,$(2))) 1162endef 1163 1164# $(1): the full path of the source static library. 1165define _extract-and-include-single-target-whole-static-lib 1166@echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(1)]" 1167$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\ 1168 rm -rf $$ldir; \ 1169 mkdir -p $$ldir; \ 1170 filelist=; \ 1171 for f in `$(TARGET_AR) t $(1)`; do \ 1172 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) p $(1) $$f > $$ldir/$$f; \ 1173 filelist="$$filelist $$ldir/$$f"; \ 1174 done ; \ 1175 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \ 1176 $(PRIVATE_ARFLAGS) $@ $$filelist 1177 1178endef 1179 1180define extract-and-include-target-whole-static-libs 1181$(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \ 1182 $(call _extract-and-include-single-target-whole-static-lib, $(lib))) 1183endef 1184 1185# Explicitly delete the archive first so that ar doesn't 1186# try to add to an existing archive. 1187define transform-o-to-static-lib 1188@mkdir -p $(dir $@) 1189@rm -f $@ 1190$(extract-and-include-target-whole-static-libs) 1191@echo "target StaticLib: $(PRIVATE_MODULE) ($@)" 1192$(call split-long-arguments,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \ 1193 $(PRIVATE_ARFLAGS) $@,$(filter %.o, $^)) 1194endef 1195 1196########################################################### 1197## Commands for running host ar 1198########################################################### 1199 1200# $(1): the full path of the source static library. 1201define _extract-and-include-single-host-whole-static-lib 1202@echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(1)]" 1203$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\ 1204 rm -rf $$ldir; \ 1205 mkdir -p $$ldir; \ 1206 filelist=; \ 1207 for f in `$(HOST_AR) t $(1) | \grep '\.o$$'`; do \ 1208 $(HOST_AR) p $(1) $$f > $$ldir/$$f; \ 1209 filelist="$$filelist $$ldir/$$f"; \ 1210 done ; \ 1211 $(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $$filelist 1212 1213endef 1214 1215define extract-and-include-host-whole-static-libs 1216$(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \ 1217 $(call _extract-and-include-single-host-whole-static-lib, $(lib))) 1218endef 1219 1220# Explicitly delete the archive first so that ar doesn't 1221# try to add to an existing archive. 1222define transform-host-o-to-static-lib 1223@mkdir -p $(dir $@) 1224@rm -f $@ 1225$(extract-and-include-host-whole-static-libs) 1226@echo "host StaticLib: $(PRIVATE_MODULE) ($@)" 1227$(call split-long-arguments,$(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@,$(filter %.o, $^)) 1228endef 1229 1230 1231########################################################### 1232## Commands for running gcc to link a shared library or package 1233########################################################### 1234 1235# ld just seems to be so finicky with command order that we allow 1236# it to be overriden en-masse see combo/linux-arm.make for an example. 1237ifneq ($(HOST_CUSTOM_LD_COMMAND),true) 1238define transform-host-o-to-shared-lib-inner 1239$(hide) $(PRIVATE_CXX) \ 1240 -Wl,-rpath-link=$(HOST_OUT_INTERMEDIATE_LIBRARIES) \ 1241 -Wl,-rpath,\$$ORIGIN/../lib \ 1242 -shared -Wl,-soname,$(notdir $@) \ 1243 $(HOST_GLOBAL_LD_DIRS) \ 1244 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1245 $(PRIVATE_HOST_GLOBAL_LDFLAGS) \ 1246 ) \ 1247 $(PRIVATE_LDFLAGS) \ 1248 $(PRIVATE_ALL_OBJECTS) \ 1249 -Wl,--whole-archive \ 1250 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 1251 -Wl,--no-whole-archive \ 1252 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ 1253 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 1254 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ 1255 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ 1256 -o $@ \ 1257 $(PRIVATE_LDLIBS) 1258endef 1259endif 1260 1261define transform-host-o-to-shared-lib 1262@mkdir -p $(dir $@) 1263@echo "host SharedLib: $(PRIVATE_MODULE) ($@)" 1264$(transform-host-o-to-shared-lib-inner) 1265endef 1266 1267define transform-host-o-to-package 1268@mkdir -p $(dir $@) 1269@echo "host Package: $(PRIVATE_MODULE) ($@)" 1270$(transform-host-o-to-shared-lib-inner) 1271endef 1272 1273 1274########################################################### 1275## Commands for running gcc to link a shared library or package 1276########################################################### 1277 1278#echo >$@.vers "{"; \ 1279#echo >>$@.vers " global:"; \ 1280#$(BUILD_SYSTEM)/filter_symbols.sh $(TARGET_NM) " " ";" $(filter %.o,$^) | sort -u >>$@.vers; \ 1281#echo >>$@.vers " local:"; \ 1282#echo >>$@.vers " *;"; \ 1283#echo >>$@.vers "};"; \ 1284 1285# -Wl,--version-script=$@.vers \ 1286 1287# ld just seems to be so finicky with command order that we allow 1288# it to be overriden en-masse see combo/linux-arm.make for an example. 1289ifneq ($(TARGET_CUSTOM_LD_COMMAND),true) 1290define transform-o-to-shared-lib-inner 1291$(hide) $(PRIVATE_CXX) \ 1292 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \ 1293 -Wl,-rpath-link=$(PRIVATE_TARGET_OUT_INTERMEDIATE_LIBRARIES) \ 1294 -Wl,-rpath,\$$ORIGIN/../lib \ 1295 -shared -Wl,-soname,$(notdir $@) \ 1296 $(PRIVATE_LDFLAGS) \ 1297 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \ 1298 $(PRIVATE_ALL_OBJECTS) \ 1299 -Wl,--whole-archive \ 1300 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 1301 -Wl,--no-whole-archive \ 1302 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ 1303 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 1304 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ 1305 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ 1306 -o $@ \ 1307 $(PRIVATE_LDLIBS) 1308endef 1309endif 1310 1311define transform-o-to-shared-lib 1312@mkdir -p $(dir $@) 1313@echo "target SharedLib: $(PRIVATE_MODULE) ($@)" 1314$($(PRIVATE_2ND_ARCH_VAR_PREFIX)transform-o-to-shared-lib-inner) 1315endef 1316 1317 1318########################################################### 1319## Commands for filtering a target executable or library 1320########################################################### 1321 1322define transform-to-stripped 1323@mkdir -p $(dir $@) 1324@echo "target Strip: $(PRIVATE_MODULE) ($@)" 1325$(hide) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_STRIP_COMMAND) 1326endef 1327 1328 1329########################################################### 1330## Commands for running gcc to link an executable 1331########################################################### 1332 1333ifneq ($(TARGET_CUSTOM_LD_COMMAND),true) 1334define transform-o-to-executable-inner 1335$(hide) $(PRIVATE_CXX) \ 1336 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \ 1337 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \ 1338 -Wl,-rpath-link=$(PRIVATE_TARGET_OUT_INTERMEDIATE_LIBRARIES) \ 1339 -Wl,-rpath,\$$ORIGIN/../lib \ 1340 $(PRIVATE_LDFLAGS) \ 1341 $(PRIVATE_ALL_OBJECTS) \ 1342 -Wl,--whole-archive \ 1343 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 1344 -Wl,--no-whole-archive \ 1345 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ 1346 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 1347 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ 1348 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ 1349 -o $@ \ 1350 $(PRIVATE_LDLIBS) 1351endef 1352endif 1353 1354define transform-o-to-executable 1355@mkdir -p $(dir $@) 1356@echo "target Executable: $(PRIVATE_MODULE) ($@)" 1357$($(PRIVATE_2ND_ARCH_VAR_PREFIX)transform-o-to-executable-inner) 1358endef 1359 1360 1361########################################################### 1362## Commands for running gcc to link a statically linked 1363## executable. In practice, we only use this on arm, so 1364## the other platforms don't have the 1365## transform-o-to-static-executable defined 1366########################################################### 1367 1368ifneq ($(TARGET_CUSTOM_LD_COMMAND),true) 1369define transform-o-to-static-executable-inner 1370endef 1371endif 1372 1373define transform-o-to-static-executable 1374@mkdir -p $(dir $@) 1375@echo "target StaticExecutable: $(PRIVATE_MODULE) ($@)" 1376$($(PRIVATE_2ND_ARCH_VAR_PREFIX)transform-o-to-static-executable-inner) 1377endef 1378 1379 1380########################################################### 1381## Commands for running gcc to link a host executable 1382########################################################### 1383 1384ifneq ($(HOST_CUSTOM_LD_COMMAND),true) 1385define transform-host-o-to-executable-inner 1386$(hide) $(PRIVATE_CXX) \ 1387 $(PRIVATE_ALL_OBJECTS) \ 1388 -Wl,--whole-archive \ 1389 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 1390 -Wl,--no-whole-archive \ 1391 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ 1392 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 1393 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ 1394 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ 1395 -Wl,-rpath-link=$(HOST_OUT_INTERMEDIATE_LIBRARIES) \ 1396 -Wl,-rpath,\$$ORIGIN/../lib \ 1397 $(HOST_GLOBAL_LD_DIRS) \ 1398 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1399 $(PRIVATE_HOST_GLOBAL_LDFLAGS) \ 1400 -fPIE -pie \ 1401 ) \ 1402 $(PRIVATE_LDFLAGS) \ 1403 -o $@ \ 1404 $(PRIVATE_LDLIBS) 1405endef 1406endif 1407 1408define transform-host-o-to-executable 1409@mkdir -p $(dir $@) 1410@echo "host Executable: $(PRIVATE_MODULE) ($@)" 1411$(transform-host-o-to-executable-inner) 1412endef 1413 1414 1415########################################################### 1416## Commands for running javac to make .class files 1417########################################################### 1418 1419#@echo "Source intermediates dir: $(PRIVATE_SOURCE_INTERMEDIATES_DIR)" 1420#@echo "Source intermediates: $$(find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java')" 1421 1422# TODO: Right now we generate the asset resources twice, first as part 1423# of generating the Java classes, then at the end when packaging the final 1424# assets. This should be changed to do one of two things: (1) Don't generate 1425# any resource files the first time, only create classes during that stage; 1426# or (2) Don't use the -c flag with the second stage, instead taking the 1427# resource files from the first stage as additional input. My original intent 1428# was to use approach (2), but this requires a little more work in the tool. 1429# Maybe we should just use approach (1). 1430 1431# This rule creates the R.java and Manifest.java files, both of which 1432# are PRODUCT-neutral. Don't pass PRIVATE_PRODUCT_AAPT_CONFIG to this invocation. 1433define create-resource-java-files 1434@mkdir -p $(PRIVATE_SOURCE_INTERMEDIATES_DIR) 1435@mkdir -p $(dir $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) 1436$(hide) $(AAPT) package $(PRIVATE_AAPT_FLAGS) -m \ 1437 $(eval # PRIVATE_PRODUCT_AAPT_CONFIG is intentionally missing-- see comment.) \ 1438 $(addprefix -J , $(PRIVATE_SOURCE_INTERMEDIATES_DIR)) \ 1439 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \ 1440 $(addprefix -P , $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) \ 1441 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \ 1442 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \ 1443 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \ 1444 $(addprefix -G , $(PRIVATE_PROGUARD_OPTIONS_FILE)) \ 1445 $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \ 1446 $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \ 1447 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \ 1448 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION)-$(BUILD_NUMBER))) \ 1449 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \ 1450 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) 1451endef 1452 1453ifeq ($(HOST_OS),windows) 1454xlint_unchecked := 1455else 1456xlint_unchecked := -Xlint:unchecked 1457endif 1458 1459ifeq (true, $(ENABLE_INCREMENTALJAVAC)) 1460incremental_dex := --incremental 1461else 1462incremental_dex := 1463endif 1464 1465# emit-line, <word list>, <output file> 1466define emit-line 1467 $(if $(1),echo -n '$(strip $(1)) ' >> $(2)) 1468endef 1469 1470# dump-words-to-file, <word list>, <output file> 1471define dump-words-to-file 1472 @rm -f $(2) 1473 @$(call emit-line,$(wordlist 1,200,$(1)),$(2)) 1474 @$(call emit-line,$(wordlist 201,400,$(1)),$(2)) 1475 @$(call emit-line,$(wordlist 401,600,$(1)),$(2)) 1476 @$(call emit-line,$(wordlist 601,800,$(1)),$(2)) 1477 @$(call emit-line,$(wordlist 801,1000,$(1)),$(2)) 1478 @$(call emit-line,$(wordlist 1001,1200,$(1)),$(2)) 1479 @$(call emit-line,$(wordlist 1201,1400,$(1)),$(2)) 1480 @$(call emit-line,$(wordlist 1401,1600,$(1)),$(2)) 1481 @$(call emit-line,$(wordlist 1601,1800,$(1)),$(2)) 1482 @$(call emit-line,$(wordlist 1801,2000,$(1)),$(2)) 1483 @$(call emit-line,$(wordlist 2001,2200,$(1)),$(2)) 1484 @$(call emit-line,$(wordlist 2201,2400,$(1)),$(2)) 1485 @$(call emit-line,$(wordlist 2401,2600,$(1)),$(2)) 1486 @$(call emit-line,$(wordlist 2601,2800,$(1)),$(2)) 1487 @$(call emit-line,$(wordlist 2801,3000,$(1)),$(2)) 1488 @$(call emit-line,$(wordlist 3001,3200,$(1)),$(2)) 1489 @$(call emit-line,$(wordlist 3201,3400,$(1)),$(2)) 1490 @$(call emit-line,$(wordlist 3401,3600,$(1)),$(2)) 1491 @$(call emit-line,$(wordlist 3601,3800,$(1)),$(2)) 1492 @$(call emit-line,$(wordlist 3801,4000,$(1)),$(2)) 1493 @$(call emit-line,$(wordlist 4001,4200,$(1)),$(2)) 1494 @$(call emit-line,$(wordlist 4201,4400,$(1)),$(2)) 1495 @$(call emit-line,$(wordlist 4401,4600,$(1)),$(2)) 1496 @$(call emit-line,$(wordlist 4601,4800,$(1)),$(2)) 1497 @$(call emit-line,$(wordlist 4801,5000,$(1)),$(2)) 1498 @$(if $(wordlist 5001,5002,$(1)),$(error Too many words ($(words $(1))))) 1499endef 1500 1501# For a list of jar files, unzip them to a specified directory, 1502# but make sure that no META-INF files come along for the ride. 1503# 1504# $(1): files to unzip 1505# $(2): destination directory 1506define unzip-jar-files 1507 $(hide) for f in $(1); \ 1508 do \ 1509 if [ ! -f $$f ]; then \ 1510 echo Missing file $$f; \ 1511 exit 1; \ 1512 fi; \ 1513 unzip -qo $$f -d $(2); \ 1514 done \ 1515 $(if $(PRIVATE_DONT_DELETE_JAR_META_INF),,;rm -rf $(2)/META-INF) 1516endef 1517 1518# Common definition to invoke javac on the host and target. 1519# 1520# Some historical notes: 1521# - below we write the list of java files to java-source-list to avoid argument 1522# list length problems with Cygwin 1523# - we filter out duplicate java file names because eclipse's compiler 1524# doesn't like them. 1525# 1526# $(1): javac 1527# $(2): bootclasspath 1528define compile-java 1529$(hide) rm -f $@ 1530$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) 1531$(hide) mkdir -p $(dir $@) 1532$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR) 1533$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)) 1534$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list) 1535$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \ 1536 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list; \ 1537fi 1538$(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \ 1539 | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq 1540$(hide) if [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \ 1541 $(1) -encoding UTF-8 \ 1542 $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) \ 1543 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \ 1544 $(2) \ 1545 $(addprefix -classpath ,$(strip \ 1546 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \ 1547 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \ 1548 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \ 1549 $(PRIVATE_JAVACFLAGS) \ 1550 \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \ 1551 || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 ) \ 1552fi 1553$(if $(PRIVATE_JAVA_LAYERS_FILE), $(hide) build/tools/java-layers.py \ 1554 $(PRIVATE_JAVA_LAYERS_FILE) \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq,) 1555$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list 1556$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq 1557$(if $(PRIVATE_JAR_EXCLUDE_FILES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) \ 1558 -name $(word 1, $(PRIVATE_JAR_EXCLUDE_FILES)) \ 1559 $(addprefix -o -name , $(wordlist 2, 999, $(PRIVATE_JAR_EXCLUDE_FILES))) \ 1560 | xargs rm -rf) 1561$(if $(PRIVATE_JAR_PACKAGES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -mindepth 1 -type d \ 1562 $(foreach pkg, $(PRIVATE_JAR_PACKAGES), \ 1563 -not -path $(PRIVATE_CLASS_INTERMEDIATES_DIR)/$(subst .,/,$(pkg))) \ 1564 | xargs rm -rf) 1565$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \ 1566 $@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) . 1567endef 1568 1569define transform-java-to-classes.jar 1570@echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))" 1571$(call compile-java,$(TARGET_JAVAC),$(PRIVATE_BOOTCLASSPATH)) 1572endef 1573 1574# Override the above definitions if we want to do incremetal javac 1575ifeq (true, $(ENABLE_INCREMENTALJAVAC)) 1576define compile-java 1577$(hide) mkdir -p $(dir $@) 1578$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR) 1579$(hide) touch $(PRIVATE_CLASS_INTERMEDIATES_DIR)/newstamp 1580$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)) 1581$(hide) if [ -e $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stamp ] ; then \ 1582 newerFlag=$$(echo -n "-newer $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stamp") ; \ 1583 fi ; \ 1584 find $(PRIVATE_JAVA_SOURCES) $$newerFlag > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list ; \ 1585 if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \ 1586 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' $$newerFlag >> $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list; \ 1587 fi 1588$(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \ 1589 | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq 1590@echo "(Incremental) build source files:" 1591@cat $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq 1592$(hide) if [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \ 1593 $(1) -encoding UTF-8 \ 1594 $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) \ 1595 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \ 1596 $(2) \ 1597 $(addprefix -classpath ,$(strip \ 1598 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES) $(PRIVATE_CLASS_INTERMEDIATES_DIR)))) \ 1599 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \ 1600 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \ 1601 $(PRIVATE_JAVACFLAGS) \ 1602 \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \ 1603 || ( exit 41 ) \ 1604fi 1605$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list 1606$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq 1607$(hide) rm -f $@ 1608$(if $(PRIVATE_JAR_EXCLUDE_FILES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) \ 1609 -name $(word 1, $(PRIVATE_JAR_EXCLUDE_FILES)) \ 1610 $(addprefix -o -name , $(wordlist 2, 999, $(PRIVATE_JAR_EXCLUDE_FILES))) \ 1611 | xargs rm -rf) 1612$(if $(PRIVATE_JAR_PACKAGES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -mindepth 1 -type d \ 1613 $(foreach pkg, $(PRIVATE_JAR_PACKAGES), \ 1614 -not -path $(PRIVATE_CLASS_INTERMEDIATES_DIR)/$(subst .,/,$(pkg))) \ 1615 | xargs rm -rf) 1616$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \ 1617 $@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) . 1618$(hide) mv $(PRIVATE_CLASS_INTERMEDIATES_DIR)/newstamp $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stamp 1619endef 1620 1621define transform-java-to-classes.jar 1622@echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))" 1623$(call compile-java,$(TARGET_JAVAC),$(PRIVATE_BOOTCLASSPATH)) 1624endef 1625endif # ENABLE_INCREMENTALJAVAC 1626 1627define transform-classes.jar-to-emma 1628$(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \ 1629 $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR) \ 1630 $(addprefix -ix , $(PRIVATE_EMMA_COVERAGE_FILTER)) 1631endef 1632 1633#TODO: use a smaller -Xmx value for most libraries; 1634# only core.jar and framework.jar need a heap this big. 1635# Avoid the memory arguments on Windows, dx fails to load for some reason with them. 1636define transform-classes.jar-to-dex 1637@echo "target Dex: $(PRIVATE_MODULE)" 1638@mkdir -p $(dir $@) 1639$(hide) $(DX) \ 1640 $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx2048M) \ 1641 --dex --output=$@ \ 1642 $(incremental_dex) \ 1643 $(if $(NO_OPTIMIZE_DX), \ 1644 --no-optimize) \ 1645 $(if $(GENERATE_DEX_DEBUG), \ 1646 --debug --verbose \ 1647 --dump-to=$(@:.dex=.lst) \ 1648 --dump-width=1000) \ 1649 $(PRIVATE_DX_FLAGS) \ 1650 $< 1651endef 1652 1653# Create a mostly-empty .jar file that we'll add to later. 1654# The MacOS jar tool doesn't like creating empty jar files, 1655# so we need to give it something. 1656define create-empty-package 1657@mkdir -p $(dir $@) 1658$(hide) touch $(dir $@)/dummy 1659$(hide) (cd $(dir $@) && jar cf $(notdir $@) dummy) 1660$(hide) zip -qd $@ dummy 1661$(hide) rm $(dir $@)/dummy 1662endef 1663 1664#TODO: we kinda want to build different asset packages for 1665# different configurations, then combine them later (or something). 1666# Per-locale, etc. 1667# A list of dynamic and static parameters; build layers for 1668# dynamic params that lay over the static ones. 1669#TODO: update the manifest to point to the package file 1670#Note that the version numbers are given to aapt as simple default 1671#values; applications can override these by explicitly stating 1672#them in their manifest. 1673define add-assets-to-package 1674$(hide) $(AAPT) package -u $(PRIVATE_AAPT_FLAGS) \ 1675 $(addprefix -c , $(PRIVATE_PRODUCT_AAPT_CONFIG)) \ 1676 $(addprefix --preferred-configurations , $(PRIVATE_PRODUCT_AAPT_PREF_CONFIG)) \ 1677 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \ 1678 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \ 1679 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \ 1680 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \ 1681 $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \ 1682 $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \ 1683 $(addprefix --product , $(TARGET_AAPT_CHARACTERISTICS)) \ 1684 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \ 1685 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION)-$(BUILD_NUMBER))) \ 1686 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \ 1687 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \ 1688 -F $@ 1689endef 1690 1691define add-jni-shared-libs-to-package 1692$(hide) rm -rf $(dir $@)lib 1693$(hide) mkdir -p $(dir $@)lib/$(PRIVATE_JNI_SHARED_LIBRARIES_ABI) 1694$(hide) cp $(PRIVATE_JNI_SHARED_LIBRARIES) $(dir $@)lib/$(PRIVATE_JNI_SHARED_LIBRARIES_ABI) 1695$(hide) (cd $(dir $@) && zip -r $(notdir $@) lib) 1696$(hide) rm -rf $(dir $@)lib 1697endef 1698 1699#TODO: update the manifest to point to the dex file 1700define add-dex-to-package 1701$(if $(filter classes.dex,$(notdir $(PRIVATE_DEX_FILE))),\ 1702$(hide) zip -qj $@ $(PRIVATE_DEX_FILE),\ 1703$(hide) _adtp_classes_dex=$(dir $(PRIVATE_DEX_FILE))classes.dex; \ 1704cp $(PRIVATE_DEX_FILE) $$_adtp_classes_dex && \ 1705zip -qj $@ $$_adtp_classes_dex && rm -f $$_adtp_classes_dex) 1706endef 1707 1708# Add java resources added by the current module. 1709# 1710define add-java-resources-to-package 1711$(call dump-words-to-file, $(PRIVATE_EXTRA_JAR_ARGS), $(dir $@)jar-arg-list) 1712$(hide) jar uf $@ @$(dir $@)jar-arg-list 1713@rm -f $(dir $@)jar-arg-list 1714endef 1715 1716# Add java resources carried by static Java libraries. 1717# 1718define add-carried-java-resources 1719$(hide) if [ -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) ] ; then \ 1720 java_res_jar_flags=$$(find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -type f -a -not -name "*.class" \ 1721 | sed -e "s?^$(PRIVATE_CLASS_INTERMEDIATES_DIR)/? -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) ?"); \ 1722 if [ -n "$$java_res_jar_flags" ] ; then \ 1723 echo $$java_res_jar_flags >$(dir $@)java_res_jar_flags; \ 1724 jar uf $@ $$java_res_jar_flags; \ 1725 fi; \ 1726fi 1727endef 1728 1729# Sign a package using the specified key/cert. 1730# 1731define sign-package 1732$(hide) mv $@ $@.unsigned 1733$(hide) java -jar $(SIGNAPK_JAR) \ 1734 $(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) \ 1735 $(PRIVATE_ADDITIONAL_CERTIFICATES) $@.unsigned $@.signed 1736$(hide) mv $@.signed $@ 1737endef 1738 1739# Align STORED entries of a package on 4-byte boundaries 1740# to make them easier to mmap. 1741# 1742define align-package 1743$(hide) mv $@ $@.unaligned 1744$(hide) $(ZIPALIGN) -f 4 $@.unaligned $@.aligned 1745$(hide) mv $@.aligned $@ 1746endef 1747 1748define install-dex-debug 1749$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.dex" ]; then \ 1750 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \ 1751 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.dex \ 1752 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).dex; \ 1753 fi 1754$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.lst" ]; then \ 1755 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \ 1756 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.lst \ 1757 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).lst; \ 1758 fi 1759endef 1760 1761# TODO(joeo): If we can ever upgrade to post 3.81 make and get the 1762# new prebuilt rules to work, we should change this to copy the 1763# resources to the out directory and then copy the resources. 1764 1765# Note: we intentionally don't clean PRIVATE_CLASS_INTERMEDIATES_DIR 1766# in transform-java-to-classes for the sake of vm-tests. 1767define transform-host-java-to-package 1768@echo "host Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))" 1769$(call compile-java,$(HOST_JAVAC),$(PRIVATE_BOOTCLASSPATH)) 1770$(if $(PRIVATE_EXTRA_JAR_ARGS), $(call add-java-resources-to-package)) 1771endef 1772 1773########################################################### 1774## Commands for copying files 1775########################################################### 1776 1777# Define a rule to copy a header. Used via $(eval) by copy_headers.make. 1778# $(1): source header 1779# $(2): destination header 1780define copy-one-header 1781$(2): $(1) 1782 @echo "Header: $$@" 1783 $$(copy-file-to-new-target-with-cp) 1784endef 1785 1786# Define a rule to copy a file. For use via $(eval). 1787# $(1): source file 1788# $(2): destination file 1789define copy-one-file 1790$(2): $(1) | $(ACP) 1791 @echo "Copy: $$@" 1792 $$(copy-file-to-target) 1793endef 1794 1795# Copies many files. 1796# $(1): The files to copy. Each entry is a ':' separated src:dst pair 1797# Evaluates to the list of the dst files (ie suitable for a dependency list) 1798define copy-many-files 1799$(foreach f, $(1), $(strip \ 1800 $(eval _cmf_tuple := $(subst :, ,$(f))) \ 1801 $(eval _cmf_src := $(word 1,$(_cmf_tuple))) \ 1802 $(eval _cmf_dest := $(word 2,$(_cmf_tuple))) \ 1803 $(eval $(call copy-one-file,$(_cmf_src),$(_cmf_dest))) \ 1804 $(_cmf_dest))) 1805endef 1806 1807# Copy the file only if it's a well-formed xml file. For use via $(eval). 1808# $(1): source file 1809# $(2): destination file, must end with .xml. 1810define copy-xml-file-checked 1811$(2): $(1) | $(ACP) 1812 @echo "Copy xml: $$@" 1813 $(hide) xmllint $$< >/dev/null # Don't print the xml file to stdout. 1814 $$(copy-file-to-target) 1815endef 1816 1817# The -t option to acp and the -p option to cp is 1818# required for OSX. OSX has a ridiculous restriction 1819# where it's an error for a .a file's modification time 1820# to disagree with an internal timestamp, and this 1821# macro is used to install .a files (among other things). 1822 1823# Copy a single file from one place to another, 1824# preserving permissions and overwriting any existing 1825# file. 1826# We disable the "-t" option for acp cannot handle 1827# high resolution timestamp correctly on file systems like ext4. 1828# Therefore copy-file-to-target is the same as copy-file-to-new-target. 1829define copy-file-to-target 1830@mkdir -p $(dir $@) 1831$(hide) $(ACP) -fp $< $@ 1832endef 1833 1834# The same as copy-file-to-target, but use the local 1835# cp command instead of acp. 1836define copy-file-to-target-with-cp 1837@mkdir -p $(dir $@) 1838$(hide) cp -fp $< $@ 1839endef 1840 1841# The same as copy-file-to-target, but use the zipalign tool to do so. 1842define copy-file-to-target-with-zipalign 1843@mkdir -p $(dir $@) 1844$(hide) $(ZIPALIGN) -f 4 $< $@ 1845endef 1846 1847# The same as copy-file-to-target, but strip out "# comment"-style 1848# comments (for config files and such). 1849define copy-file-to-target-strip-comments 1850@mkdir -p $(dir $@) 1851$(hide) sed -e 's/#.*$$//' -e 's/[ \t]*$$//' -e '/^$$/d' < $< > $@ 1852endef 1853 1854# The same as copy-file-to-target, but don't preserve 1855# the old modification time. 1856define copy-file-to-new-target 1857@mkdir -p $(dir $@) 1858$(hide) $(ACP) -fp $< $@ 1859endef 1860 1861# The same as copy-file-to-new-target, but use the local 1862# cp command instead of acp. 1863define copy-file-to-new-target-with-cp 1864@mkdir -p $(dir $@) 1865$(hide) cp -f $< $@ 1866endef 1867 1868# Copy a prebuilt file to a target location. 1869define transform-prebuilt-to-target 1870@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)" 1871$(copy-file-to-target) 1872endef 1873 1874# Copy a prebuilt file to a target location, using zipalign on it. 1875define transform-prebuilt-to-target-with-zipalign 1876@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt APK: $(PRIVATE_MODULE) ($@)" 1877$(copy-file-to-target-with-zipalign) 1878endef 1879 1880# Copy a prebuilt file to a target location, stripping "# comment" comments. 1881define transform-prebuilt-to-target-strip-comments 1882@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)" 1883$(copy-file-to-target-strip-comments) 1884endef 1885 1886########################################################### 1887## On some platforms (MacOS), after copying a static 1888## library, ranlib must be run to update an internal 1889## timestamp!?!?! 1890########################################################### 1891 1892ifeq ($(HOST_RUN_RANLIB_AFTER_COPYING),true) 1893define transform-host-ranlib-copy-hack 1894 $(hide) ranlib $@ || true 1895endef 1896else 1897define transform-host-ranlib-copy-hack 1898@true 1899endef 1900endif 1901 1902ifeq ($(TARGET_RUN_RANLIB_AFTER_COPYING),true) 1903define transform-ranlib-copy-hack 1904 $(hide) ranlib $@ 1905endef 1906else 1907define transform-ranlib-copy-hack 1908@true 1909endef 1910endif 1911 1912 1913########################################################### 1914## Commands to call Proguard 1915########################################################### 1916define transform-jar-to-proguard 1917@echo Proguard: $@ 1918$(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS) \ 1919 $(addprefix -injars , $(PRIVATE_EXTRA_INPUT_JAR)) 1920endef 1921 1922########################################################### 1923## Stuff source generated from one-off tools 1924########################################################### 1925 1926define transform-generated-source 1927@echo "target Generated: $(PRIVATE_MODULE) <= $<" 1928@mkdir -p $(dir $@) 1929$(hide) $(PRIVATE_CUSTOM_TOOL) 1930endef 1931 1932 1933########################################################### 1934## Assertions about attributes of the target 1935########################################################### 1936 1937# $(1): The file to check 1938ifndef get-file-size 1939$(error HOST_OS must define get-file-size) 1940endif 1941 1942# Convert a partition data size (eg, as reported in /proc/mtd) to the 1943# size of the image used to flash that partition (which includes a 1944# spare area for each page). 1945# $(1): the partition data size 1946define image-size-from-data-size 1947$(strip $(eval _isfds_value := $$(shell echo $$$$(($(1) / $(BOARD_NAND_PAGE_SIZE) * \ 1948 ($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE))))))\ 1949$(if $(filter 0, $(_isfds_value)),$(shell echo $$(($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE)))),$(_isfds_value))\ 1950$(eval _isfds_value :=)) 1951endef 1952 1953# $(1): The file(s) to check (often $@) 1954# $(2): The maximum total image size, in decimal bytes 1955# $(3): the type of filesystem "yaffs" or "raw" 1956# 1957# If $(2) is empty, evaluates to "true" 1958# 1959# Reserve bad blocks. Make sure that MAX(1% of partition size, 2 blocks) 1960# is left over after the image has been flashed. Round the 1% up to the 1961# next whole flash block size. 1962define assert-max-file-size 1963$(if $(2), \ 1964 size=$$(for i in $(1); do $(call get-file-size,$$i); echo +; done; echo 0); \ 1965 total=$$(( $$( echo "$$size" ) )); \ 1966 printname=$$(echo -n "$(1)" | tr " " +); \ 1967 img_blocksize=$(call image-size-from-data-size,$(BOARD_FLASH_BLOCK_SIZE)); \ 1968 if [ "$(3)" == "yaffs" ]; then \ 1969 reservedblocks=8; \ 1970 else \ 1971 reservedblocks=0; \ 1972 fi; \ 1973 twoblocks=$$((img_blocksize * 2)); \ 1974 onepct=$$((((($(2) / 100) - 1) / img_blocksize + 1) * img_blocksize)); \ 1975 reserve=$$(((twoblocks > onepct ? twoblocks : onepct) + \ 1976 reservedblocks * img_blocksize)); \ 1977 maxsize=$$(($(2) - reserve)); \ 1978 echo "$$printname maxsize=$$maxsize blocksize=$$img_blocksize total=$$total reserve=$$reserve"; \ 1979 if [ "$$total" -gt "$$maxsize" ]; then \ 1980 echo "error: $$printname too large ($$total > [$(2) - $$reserve])"; \ 1981 false; \ 1982 elif [ "$$total" -gt $$((maxsize - 32768)) ]; then \ 1983 echo "WARNING: $$printname approaching size limit ($$total now; limit $$maxsize)"; \ 1984 fi \ 1985 , \ 1986 true \ 1987 ) 1988endef 1989 1990# Like assert-max-file-size, but the second argument is a partition 1991# size, which we'll convert to a max image size before checking it 1992# against the files. 1993# 1994# $(1): The file(s) to check (often $@) 1995# $(2): The partition size. 1996define assert-max-image-size 1997$(if $(2), \ 1998 $(call assert-max-file-size,$(1),$(call image-size-from-data-size,$(2))), \ 1999 true) 2000endef 2001 2002 2003########################################################### 2004## Define device-specific radio files 2005########################################################### 2006INSTALLED_RADIOIMAGE_TARGET := 2007 2008# Copy a radio image file to the output location, and add it to 2009# INSTALLED_RADIOIMAGE_TARGET. 2010# $(1): filename 2011define add-radio-file 2012 $(eval $(call add-radio-file-internal,$(1),$(notdir $(1)))) 2013endef 2014define add-radio-file-internal 2015INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2) 2016$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP) 2017 $$(transform-prebuilt-to-target) 2018endef 2019 2020# Version of add-radio-file that also arranges for the version of the 2021# file to be checked against the contents of 2022# $(TARGET_BOARD_INFO_FILE). 2023# $(1): filename 2024# $(2): name of version variable in board-info (eg, "version-baseband") 2025define add-radio-file-checked 2026 $(eval $(call add-radio-file-checked-internal,$(1),$(notdir $(1)),$(2))) 2027endef 2028define add-radio-file-checked-internal 2029INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2) 2030BOARD_INFO_CHECK += $(3):$(LOCAL_PATH)/$(1) 2031$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP) 2032 $$(transform-prebuilt-to-target) 2033endef 2034 2035 2036########################################################### 2037# Override the package defined in $(1), setting the 2038# variables listed below differently. 2039# 2040# $(1): The makefile to override (relative to the source 2041# tree root) 2042# $(2): Old LOCAL_PACKAGE_NAME value. 2043# $(3): New LOCAL_PACKAGE_NAME value. 2044# $(4): New LOCAL_MANIFEST_PACKAGE_NAME value. 2045# $(5): New LOCAL_CERTIFICATE value. 2046# $(6): New LOCAL_INSTRUMENTATION_FOR value. 2047# $(7): New LOCAL_MANIFEST_INSTRUMENTATION_FOR value. 2048# 2049# Note that LOCAL_PACKAGE_OVERRIDES is NOT cleared in 2050# clear_vars.mk. 2051########################################################### 2052define inherit-package 2053 $(eval $(call inherit-package-internal,$(1),$(2),$(3),$(4),$(5),$(6),$(7))) 2054endef 2055 2056define inherit-package-internal 2057 LOCAL_PACKAGE_OVERRIDES \ 2058 := $(strip $(1))||$(strip $(2))||$(strip $(3))||$(strip $(4))||&&$(strip $(5))||&&$(strip $(6))||&&$(strip $(7)) $(LOCAL_PACKAGE_OVERRIDES) 2059 include $(1) 2060 LOCAL_PACKAGE_OVERRIDES \ 2061 := $(wordlist 1,$(words $(LOCAL_PACKAGE_OVERRIDES)), $(LOCAL_PACKAGE_OVERRIDES)) 2062endef 2063 2064# To be used with inherit-package above 2065# Evalutes to true if the package was overridden 2066define set-inherited-package-variables 2067$(strip $(call set-inherited-package-variables-internal)) 2068endef 2069 2070define keep-or-override 2071$(eval $(1) := $(if $(2),$(2),$($(1)))) 2072endef 2073 2074define set-inherited-package-variables-internal 2075 $(eval _o := $(subst ||, ,$(lastword $(LOCAL_PACKAGE_OVERRIDES)))) 2076 $(eval _n := $(subst ||, ,$(firstword $(LOCAL_PACKAGE_OVERRIDES)))) 2077 $(if $(filter $(word 2,$(_n)),$(LOCAL_PACKAGE_NAME)), \ 2078 $(eval LOCAL_PACKAGE_NAME := $(word 3,$(_o))) \ 2079 $(eval LOCAL_MANIFEST_PACKAGE_NAME := $(word 4,$(_o))) \ 2080 $(call keep-or-override,LOCAL_CERTIFICATE,$(patsubst &&%,%,$(word 5,$(_o)))) \ 2081 $(call keep-or-override,LOCAL_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 6,$(_o)))) \ 2082 $(call keep-or-override,LOCAL_MANIFEST_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 7,$(_o)))) \ 2083 $(eval LOCAL_OVERRIDES_PACKAGES := $(sort $(LOCAL_OVERRIDES_PACKAGES) $(word 2,$(_o)))) \ 2084 true \ 2085 ,) 2086endef 2087 2088########################################################### 2089## Expand a module name list with REQUIRED modules 2090########################################################### 2091# $(1): The variable name that holds the initial module name list. 2092# the variable will be modified to hold the expanded results. 2093# $(2): The initial module name list. 2094# Returns empty string (maybe with some whitespaces). 2095define expand-required-modules 2096$(eval _erm_new_modules := $(sort $(filter-out $($(1)),\ 2097 $(foreach m,$(2),$(ALL_MODULES.$(m).REQUIRED)))))\ 2098$(if $(_erm_new_modules),$(eval $(1) += $(_erm_new_modules))\ 2099 $(call expand-required-modules,$(1),$(_erm_new_modules))) 2100endef 2101 2102########################################################### 2103## API Check 2104########################################################### 2105 2106# eval this to define a rule that runs apicheck. 2107# 2108# Args: 2109# $(1) target 2110# $(2) stable api file 2111# $(3) api file to be tested 2112# $(4) arguments for apicheck 2113# $(5) command to run if apicheck failed 2114# $(6) target dependent on this api check 2115# $(7) additional dependencies 2116define check-api 2117$(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(strip $(1))-timestamp: $(2) $(3) $(APICHECK) $(7) 2118 @echo "Checking API:" $(1) 2119 $(hide) ( $(APICHECK_COMMAND) $(4) $(2) $(3) || ( $(5) ; exit 38 ) ) 2120 $(hide) mkdir -p $$(dir $$@) 2121 $(hide) touch $$@ 2122$(6): $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(strip $(1))-timestamp 2123endef 2124 2125## Whether to build from source if prebuilt alternative exists 2126########################################################### 2127# $(1): module name 2128# $(2): LOCAL_PATH 2129# Expands to empty string if not from source. 2130ifeq (true,$(ANDROID_BUILD_FROM_SOURCE)) 2131define if-build-from-source 2132true 2133endef 2134else 2135define if-build-from-source 2136$(if $(filter $(ANDROID_NO_PREBUILT_MODULES),$(1))$(filter \ 2137 $(addsuffix %,$(ANDROID_NO_PREBUILT_PATHS)),$(2)),true) 2138endef 2139endif 2140 2141# Include makefile $(1) if build from source for module $(2) 2142# $(1): the makefile to include 2143# $(2): module name 2144# $(3): LOCAL_PATH 2145define include-if-build-from-source 2146$(if $(call if-build-from-source,$(2),$(3)),$(eval include $(1))) 2147endef 2148 2149## Return the arch for the source file of a prebuilt 2150# $(1) the list of archs supported by the prebuilt 2151define get-prebuilt-src-arch 2152$(strip $(if $(filter $(TARGET_ARCH),$(1)),$(TARGET_ARCH),\ 2153 $(if $(filter $(TARGET_2ND_ARCH),$(1)),$(TARGET_2ND_ARCH)))) 2154endef 2155 2156########################################################### 2157## Other includes 2158########################################################### 2159 2160# ----------------------------------------------------------------- 2161# Rules and functions to help copy important files to DIST_DIR 2162# when requested. 2163include $(BUILD_SYSTEM)/distdir.mk 2164 2165# Include any vendor specific definitions.mk file 2166-include $(TOPDIR)vendor/*/build/core/definitions.mk 2167 2168# broken: 2169# $(foreach file,$^,$(if $(findstring,.a,$(suffix $file)),-l$(file),$(file))) 2170 2171########################################################### 2172## Misc notes 2173########################################################### 2174 2175#DEPDIR = .deps 2176#df = $(DEPDIR)/$(*F) 2177 2178#SRCS = foo.c bar.c ... 2179 2180#%.o : %.c 2181# @$(MAKEDEPEND); \ 2182# cp $(df).d $(df).P; \ 2183# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ 2184# -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \ 2185# rm -f $(df).d 2186# $(COMPILE.c) -o $@ $< 2187 2188#-include $(SRCS:%.c=$(DEPDIR)/%.P) 2189 2190 2191#%.o : %.c 2192# $(COMPILE.c) -MD -o $@ $< 2193# @cp $*.d $*.P; \ 2194# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ 2195# -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \ 2196# rm -f $*.d 2197