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