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