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