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