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