definitions.mk revision 700b88e1451f216d137d8a356496bf51712512c6
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$(HOST_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$(TARGET_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 1089# Because of bug 743462 ("Prelinked image magic gets stripped 1090# by arm-elf-objcopy"), we have to use soslim to strip target 1091# binaries. 1092define transform-to-stripped 1093@mkdir -p $(dir $@) 1094@echo "target Strip: $(PRIVATE_MODULE) ($@)" 1095$(hide) $(SOSLIM) --strip --shady --quiet $< --outfile $@ 1096endef 1097 1098define transform-to-prelinked 1099@mkdir -p $(dir $@) 1100@echo "target Prelink: $(PRIVATE_MODULE) ($@)" 1101$(hide) $(APRIORI) \ 1102 --prelinkmap $(TARGET_PRELINKER_MAP) \ 1103 --locals-only \ 1104 --quiet \ 1105 $< \ 1106 --output $@ 1107endef 1108 1109 1110########################################################### 1111## Commands for running gcc to link an executable 1112########################################################### 1113 1114ifneq ($(TARGET_CUSTOM_LD_COMMAND),true) 1115define transform-o-to-executable-inner 1116$(TARGET_CXX) \ 1117 $(TARGET_GLOBAL_LDFLAGS) \ 1118 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \ 1119 $(TARGET_GLOBAL_LD_DIRS) \ 1120 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \ 1121 -Wl,-rpath,\$$ORIGIN/../lib \ 1122 $(PRIVATE_LDFLAGS) \ 1123 $(TARGET_GLOBAL_LD_DIRS) \ 1124 $(PRIVATE_ALL_OBJECTS) \ 1125 -Wl,--whole-archive \ 1126 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 1127 -Wl,--no-whole-archive \ 1128 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 1129 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ 1130 -o $@ \ 1131 $(PRIVATE_LDLIBS) 1132endef 1133endif 1134 1135define transform-o-to-executable 1136@mkdir -p $(dir $@) 1137@echo "target Executable: $(PRIVATE_MODULE) ($@)" 1138$(hide) $(transform-o-to-executable-inner) 1139endef 1140 1141 1142########################################################### 1143## Commands for running gcc to link a statically linked 1144## executable. In practice, we only use this on arm, so 1145## the other platforms don't have the 1146## transform-o-to-static-executable defined 1147########################################################### 1148 1149ifneq ($(TARGET_CUSTOM_LD_COMMAND),true) 1150define transform-o-to-static-executable-inner 1151endef 1152endif 1153 1154define transform-o-to-static-executable 1155@mkdir -p $(dir $@) 1156@echo "target StaticExecutable: $(PRIVATE_MODULE) ($@)" 1157$(hide) $(transform-o-to-static-executable-inner) 1158endef 1159 1160 1161########################################################### 1162## Commands for running gcc to link a host executable 1163########################################################### 1164 1165ifneq ($(HOST_CUSTOM_LD_COMMAND),true) 1166define transform-host-o-to-executable-inner 1167$(HOST_CXX) \ 1168 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \ 1169 -Wl,-rpath,\$$ORIGIN/../lib \ 1170 $(HOST_GLOBAL_LD_DIRS) \ 1171 $(PRIVATE_LDFLAGS) \ 1172 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \ 1173 $(HOST_GLOBAL_LDFLAGS) \ 1174 ) \ 1175 $(PRIVATE_ALL_OBJECTS) \ 1176 -Wl,--whole-archive \ 1177 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 1178 -Wl,--no-whole-archive \ 1179 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 1180 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ 1181 -o $@ \ 1182 $(PRIVATE_LDLIBS) 1183endef 1184endif 1185 1186define transform-host-o-to-executable 1187@mkdir -p $(dir $@) 1188@echo "host Executable: $(PRIVATE_MODULE) ($@)" 1189$(hide) $(transform-host-o-to-executable-inner) 1190endef 1191 1192 1193########################################################### 1194## Commands for running javac to make .class files 1195########################################################### 1196 1197#@echo "Source intermediates dir: $(PRIVATE_SOURCE_INTERMEDIATES_DIR)" 1198#@echo "Source intermediates: $$(find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java')" 1199 1200# TODO: Right now we generate the asset resources twice, first as part 1201# of generating the Java classes, then at the end when packaging the final 1202# assets. This should be changed to do one of two things: (1) Don't generate 1203# any resource files the first time, only create classes during that stage; 1204# or (2) Don't use the -c flag with the second stage, instead taking the 1205# resource files from the first stage as additional input. My original intent 1206# was to use approach (2), but this requires a little more work in the tool. 1207# Maybe we should just use approach (1). 1208 1209# This rule creates the R.java and Manifest.java files, both of which 1210# are PRODUCT-neutral. Don't pass PRODUCT_AAPT_CONFIG to this invocation. 1211define create-resource-java-files 1212@mkdir -p $(PRIVATE_SOURCE_INTERMEDIATES_DIR) 1213@mkdir -p $(dir $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) 1214$(hide) $(AAPT) package $(PRIVATE_AAPT_FLAGS) -m \ 1215 $(eval # PRODUCT_AAPT_CONFIG is intentionally missing-- see comment.) \ 1216 $(addprefix -J , $(PRIVATE_SOURCE_INTERMEDIATES_DIR)) \ 1217 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \ 1218 $(addprefix -P , $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) \ 1219 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \ 1220 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \ 1221 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \ 1222 $(addprefix -G , $(PRIVATE_PROGUARD_OPTIONS_FILE)) \ 1223 $(addprefix --min-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \ 1224 $(addprefix --target-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \ 1225 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \ 1226 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION))) \ 1227 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \ 1228 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) 1229endef 1230 1231ifeq ($(HOST_OS),windows) 1232xlint_unchecked := 1233else 1234#xlint_unchecked := -Xlint:unchecked 1235endif 1236 1237# emit-line, <word list>, <output file> 1238define emit-line 1239 $(if $(1),echo -n '$(strip $(1)) ' >> $(2)) 1240endef 1241 1242# dump-words-to-file, <word list>, <output file> 1243define dump-words-to-file 1244 @rm -f $(2) 1245 @$(call emit-line,$(wordlist 1,200,$(1)),$(2)) 1246 @$(call emit-line,$(wordlist 201,400,$(1)),$(2)) 1247 @$(call emit-line,$(wordlist 401,600,$(1)),$(2)) 1248 @$(call emit-line,$(wordlist 601,800,$(1)),$(2)) 1249 @$(call emit-line,$(wordlist 801,1000,$(1)),$(2)) 1250 @$(call emit-line,$(wordlist 1001,1200,$(1)),$(2)) 1251 @$(call emit-line,$(wordlist 1201,1400,$(1)),$(2)) 1252 @$(call emit-line,$(wordlist 1401,1600,$(1)),$(2)) 1253 @$(call emit-line,$(wordlist 1601,1800,$(1)),$(2)) 1254 @$(call emit-line,$(wordlist 1801,2000,$(1)),$(2)) 1255 @$(call emit-line,$(wordlist 2001,2200,$(1)),$(2)) 1256 @$(call emit-line,$(wordlist 2201,2400,$(1)),$(2)) 1257 @$(call emit-line,$(wordlist 2401,2600,$(1)),$(2)) 1258 @$(call emit-line,$(wordlist 2601,2800,$(1)),$(2)) 1259 @$(call emit-line,$(wordlist 2801,3000,$(1)),$(2)) 1260 @$(call emit-line,$(wordlist 3001,3200,$(1)),$(2)) 1261 @$(call emit-line,$(wordlist 3201,3400,$(1)),$(2)) 1262 @$(call emit-line,$(wordlist 3401,3600,$(1)),$(2)) 1263 @$(call emit-line,$(wordlist 3601,3800,$(1)),$(2)) 1264 @$(call emit-line,$(wordlist 3801,4000,$(1)),$(2)) 1265 @$(if $(wordlist 4001,4002,$(1)),$(error Too many words ($(words $(1))))) 1266endef 1267 1268# For a list of jar files, unzip them to a specified directory, 1269# but make sure that no META-INF files come along for the ride. 1270# 1271# $(1): files to unzip 1272# $(2): destination directory 1273define unzip-jar-files 1274 $(hide) for f in $(1); \ 1275 do \ 1276 if [ ! -f $$f ]; then \ 1277 echo Missing file $$f; \ 1278 exit 1; \ 1279 fi; \ 1280 unzip -qo $$f -d $(2); \ 1281 (cd $(2) && rm -rf META-INF); \ 1282 done 1283endef 1284 1285# below we write the list of java files to java-source-list to avoid argument 1286# list length problems with Cygwin we filter out duplicate java file names 1287# because eclipse's compiler doesn't like them. 1288define transform-java-to-classes.jar 1289@echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))" 1290$(hide) rm -f $@ 1291$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) 1292$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR) 1293$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES), \ 1294 $(PRIVATE_CLASS_INTERMEDIATES_DIR)) 1295$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list) 1296$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \ 1297 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list; \ 1298fi 1299$(hide) tr ' ' '\n' < $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list \ 1300 | sort -u > $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list-uniq 1301$(hide) $(TARGET_JAVAC) -encoding ascii $(PRIVATE_BOOTCLASSPATH) \ 1302 $(addprefix -classpath ,$(strip \ 1303 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \ 1304 $(PRIVATE_JAVACFLAGS) $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) $(xlint_unchecked) \ 1305 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \ 1306 \@$(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list-uniq \ 1307 || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 ) 1308$(hide) rm -f $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list 1309$(hide) rm -f $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list-uniq 1310$(hide) mkdir -p $(dir $@) 1311$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \ 1312 $@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) . 1313$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) 1314endef 1315 1316define transform-classes.jar-to-emma 1317$(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \ 1318 $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR) \ 1319 $(addprefix -ix , $(PRIVATE_EMMA_COVERAGE_FILTER)) 1320endef 1321 1322#TODO: use a smaller -Xmx value for most libraries; 1323# only core.jar and framework.jar need a heap this big. 1324# Avoid the memory arguments on Windows, dx fails to load for some reason with them. 1325define transform-classes.jar-to-dex 1326@echo "target Dex: $(PRIVATE_MODULE)" 1327@mkdir -p $(dir $@) 1328$(hide) $(DX) \ 1329 $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx1536M) \ 1330 --dex --output=$@ \ 1331 $(if $(NO_OPTIMIZE_DX), \ 1332 --no-optimize) \ 1333 $(if $(GENERATE_DEX_DEBUG), \ 1334 --debug --verbose \ 1335 --dump-to=$(@:.dex=.lst) \ 1336 --dump-width=1000) \ 1337 $(PRIVATE_DX_FLAGS) \ 1338 $< 1339endef 1340 1341# Create a mostly-empty .jar file that we'll add to later. 1342# The MacOS jar tool doesn't like creating empty jar files, 1343# so we need to give it something. 1344define create-empty-package 1345@mkdir -p $(dir $@) 1346$(hide) touch $(dir $@)/dummy 1347$(hide) (cd $(dir $@) && jar cf $(notdir $@) dummy) 1348$(hide) zip -qd $@ dummy 1349$(hide) rm $(dir $@)/dummy 1350endef 1351 1352#TODO: we kinda want to build different asset packages for 1353# different configurations, then combine them later (or something). 1354# Per-locale, etc. 1355# A list of dynamic and static parameters; build layers for 1356# dynamic params that lay over the static ones. 1357#TODO: update the manifest to point to the package file 1358#Note that the version numbers are given to aapt as simple default 1359#values; applications can override these by explicitly stating 1360#them in their manifest. 1361define add-assets-to-package 1362$(hide) $(AAPT) package -u $(PRIVATE_AAPT_FLAGS) \ 1363 $(addprefix -c , $(PRODUCT_AAPT_CONFIG)) \ 1364 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \ 1365 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \ 1366 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \ 1367 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \ 1368 $(addprefix --min-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \ 1369 $(addprefix --target-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \ 1370 $(addprefix --product , $(TARGET_AAPT_CHARACTERISTICS)) \ 1371 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \ 1372 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION))) \ 1373 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \ 1374 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \ 1375 -F $@ 1376endef 1377 1378define add-jni-shared-libs-to-package 1379$(hide) rm -rf $(dir $@)lib 1380$(hide) mkdir -p $(dir $@)lib/$(TARGET_CPU_ABI) 1381$(hide) cp $(PRIVATE_JNI_SHARED_LIBRARIES) $(dir $@)lib/$(TARGET_CPU_ABI) 1382$(hide) (cd $(dir $@) && zip -r $(notdir $@) lib) 1383$(hide) rm -rf $(dir $@)lib 1384endef 1385 1386#TODO: update the manifest to point to the dex file 1387define add-dex-to-package 1388$(if $(filter classes.dex,$(notdir $(PRIVATE_DEX_FILE))),\ 1389$(hide) $(AAPT) add -k $@ $(PRIVATE_DEX_FILE),\ 1390$(eval _adtp_classes.dex := $(dir $(PRIVATE_DEX_FILE))/classes.dex)\ 1391$(hide) cp $(PRIVATE_DEX_FILE) $(_adtp_classes.dex) && \ 1392$(AAPT) add -k $@ $(_adtp_classes.dex) && \ 1393rm -f $(_adtp_classes.dex)) 1394endef 1395 1396define add-java-resources-to-package 1397$(hide) jar uf $@ $(PRIVATE_EXTRA_JAR_ARGS) 1398endef 1399 1400# Sign a package using the specified key/cert. 1401# 1402define sign-package 1403$(hide) mv $@ $@.unsigned 1404$(hide) java -jar $(SIGNAPK_JAR) \ 1405 $(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) $@.unsigned $@.signed 1406$(hide) mv $@.signed $@ 1407endef 1408 1409# Align STORED entries of a package on 4-byte boundaries 1410# to make them easier to mmap. 1411# 1412define align-package 1413$(hide) mv $@ $@.unaligned 1414$(hide) $(ZIPALIGN) -f 4 $@.unaligned $@.aligned 1415$(hide) mv $@.aligned $@ 1416endef 1417 1418define install-dex-debug 1419$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.dex" ]; then \ 1420 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \ 1421 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.dex \ 1422 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).dex; \ 1423 fi 1424$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.lst" ]; then \ 1425 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \ 1426 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.lst \ 1427 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).lst; \ 1428 fi 1429endef 1430 1431# TODO(joeo): If we can ever upgrade to post 3.81 make and get the 1432# new prebuilt rules to work, we should change this to copy the 1433# resources to the out directory and then copy the resources. 1434 1435# Note: not using aapt tool for this because we aren't making 1436# an android package for the host. 1437define transform-host-java-to-package 1438@echo "host Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))" 1439@rm -f $@ 1440@rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) 1441@mkdir -p $(dir $@) 1442@mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR) 1443$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES), \ 1444 $(PRIVATE_CLASS_INTERMEDIATES_DIR)) 1445$(call dump-words-to-file,$(sort\ 1446 $(PRIVATE_JAVA_SOURCES)),\ 1447 $(PRIVATE_INTERMEDIATES_DIR)/java-source-list-uniq) 1448$(hide) $(HOST_JAVAC) -encoding ascii -g \ 1449 $(PRIVATE_JAVACFLAGS) $(xlint_unchecked) \ 1450 $(addprefix -classpath ,$(strip \ 1451 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \ 1452 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR)\ 1453 \@$(PRIVATE_INTERMEDIATES_DIR)/java-source-list-uniq || \ 1454 ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 ) 1455$(hide) rm -f $(PRIVATE_INTERMEDIATES_DIR)/java-source-list 1456$(hide) rm -f $(PRIVATE_INTERMEDIATES_DIR)/java-source-list-uniq 1457$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \ 1458 $@ $(PRIVATE_JAR_MANIFEST) $(PRIVATE_EXTRA_JAR_ARGS) \ 1459 -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) . 1460endef 1461 1462########################################################### 1463## Obfuscate a jar file 1464########################################################### 1465 1466# PRIVATE_KEEP_FILE is a file containing a list of classes 1467# PRIVATE_INTERMEDIATES_DIR is a directory we can use for temporary files 1468# The module using this must depend on 1469# $(HOST_OUT_JAVA_LIBRARIES)/proguard-4.0.1.jar 1470define obfuscate-jar 1471@echo "Obfuscate jar: $(notdir $@) ($@)" 1472@mkdir -p $(dir $@) 1473@rm -f $@ 1474@mkdir -p $(PRIVATE_INTERMEDIATES_DIR) 1475$(hide) sed -e 's/^/-keep class /' < $(PRIVATE_KEEP_FILE) > \ 1476 $(PRIVATE_INTERMEDIATES_DIR)/keep.pro 1477$(hide) java -Xmx512M -jar $(HOST_OUT_JAVA_LIBRARIES)/proguard-4.0.1.jar \ 1478 -injars $< \ 1479 -outjars $@ \ 1480 -target 1.5 \ 1481 -dontnote -dontwarn \ 1482 -printmapping $(PRIVATE_INTERMEDIATES_DIR)/out.map \ 1483 -forceprocessing \ 1484 -renamesourcefileattribute SourceFile \ 1485 -keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod \ 1486 -repackageclasses \ 1487 -keepclassmembers "class * { public protected *; }" \ 1488 @$(PRIVATE_INTERMEDIATES_DIR)/keep.pro 1489endef 1490 1491########################################################### 1492## Commands for copying files 1493########################################################### 1494 1495# Define a rule to copy a header. Used via $(eval) by copy_headers.make. 1496# $(1): source header 1497# $(2): destination header 1498define copy-one-header 1499$(2): $(1) 1500 @echo "Header: $$@" 1501 $$(copy-file-to-new-target-with-cp) 1502endef 1503 1504# Define a rule to copy a file. For use via $(eval). 1505# $(1): source file 1506# $(2): destination file 1507define copy-one-file 1508$(2): $(1) | $(ACP) 1509 @echo "Copy: $$@" 1510 $$(copy-file-to-target) 1511endef 1512 1513# The -t option to acp and the -p option to cp is 1514# required for OSX. OSX has a ridiculous restriction 1515# where it's an error for a .a file's modification time 1516# to disagree with an internal timestamp, and this 1517# macro is used to install .a files (among other things). 1518 1519# Copy a single file from one place to another, 1520# preserving permissions and overwriting any existing 1521# file. 1522define copy-file-to-target 1523@mkdir -p $(dir $@) 1524$(hide) $(ACP) -fpt $< $@ 1525endef 1526 1527# The same as copy-file-to-target, but use the local 1528# cp command instead of acp. 1529define copy-file-to-target-with-cp 1530@mkdir -p $(dir $@) 1531$(hide) cp -fp $< $@ 1532endef 1533 1534# The same as copy-file-to-target, but use the zipalign tool to do so. 1535define copy-file-to-target-with-zipalign 1536@mkdir -p $(dir $@) 1537$(hide) $(ZIPALIGN) -f 4 $< $@ 1538endef 1539 1540# The same as copy-file-to-target, but strip out "# comment"-style 1541# comments (for config files and such). 1542define copy-file-to-target-strip-comments 1543@mkdir -p $(dir $@) 1544$(hide) sed -e 's/#.*$$//' -e 's/[ \t]*$$//' -e '/^$$/d' < $< > $@ 1545endef 1546 1547# The same as copy-file-to-target, but don't preserve 1548# the old modification time. 1549define copy-file-to-new-target 1550@mkdir -p $(dir $@) 1551$(hide) $(ACP) -fp $< $@ 1552endef 1553 1554# The same as copy-file-to-new-target, but use the local 1555# cp command instead of acp. 1556define copy-file-to-new-target-with-cp 1557@mkdir -p $(dir $@) 1558$(hide) cp -f $< $@ 1559endef 1560 1561# Copy a prebuilt file to a target location. 1562define transform-prebuilt-to-target 1563@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)" 1564$(copy-file-to-target) 1565endef 1566 1567# Copy a prebuilt file to a target location, using zipalign on it. 1568define transform-prebuilt-to-target-with-zipalign 1569@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt APK: $(PRIVATE_MODULE) ($@)" 1570$(copy-file-to-target-with-zipalign) 1571endef 1572 1573# Copy a prebuilt file to a target location, stripping "# comment" comments. 1574define transform-prebuilt-to-target-strip-comments 1575@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)" 1576$(copy-file-to-target-strip-comments) 1577endef 1578 1579########################################################### 1580## On some platforms (MacOS), after copying a static 1581## library, ranlib must be run to update an internal 1582## timestamp!?!?! 1583########################################################### 1584 1585ifeq ($(HOST_RUN_RANLIB_AFTER_COPYING),true) 1586define transform-host-ranlib-copy-hack 1587 $(hide) ranlib $@ || true 1588endef 1589else 1590define transform-host-ranlib-copy-hack 1591true 1592endef 1593endif 1594 1595ifeq ($(TARGET_RUN_RANLIB_AFTER_COPYING),true) 1596define transform-ranlib-copy-hack 1597 $(hide) ranlib $@ 1598endef 1599else 1600define transform-ranlib-copy-hack 1601true 1602endef 1603endif 1604 1605 1606########################################################### 1607## Commands to call Proguard 1608########################################################### 1609 1610# Command to copy the file with acp, if proguard is disabled. 1611define proguard-disabled-commands 1612@echo Copying: $@ 1613$(hide) $(ACP) $< $@ 1614endef 1615 1616# Command to call Proguard 1617# $(1): extra flags for instrumentation. 1618define proguard-enabled-commands 1619@echo Proguard: $@ 1620$(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS) $(1) 1621endef 1622 1623# Figure out the proguard dictionary file of the module that is instrumentationed for. 1624define get-instrumentation-proguard-flags 1625$(if $(PRIVATE_INSTRUMENTATION_FOR),$(if $(ALL_MODULES.$(PRIVATE_INSTRUMENTATION_FOR).PROGUARD_ENABLED),-applymapping $(call intermediates-dir-for,APPS,$(PRIVATE_INSTRUMENTATION_FOR),,COMMON)/proguard_dictionary)) 1626endef 1627 1628define transform-jar-to-proguard 1629$(eval _instrumentation_proguard_flags:=$(call get-instrumentation-proguard-flags)) 1630$(eval _enable_proguard:=$(PRIVATE_PROGUARD_ENABLED)$(_instrumentation_proguard_flags)) 1631$(if $(_enable_proguard),$(call proguard-enabled-commands,$(_instrumentation_proguard_flags)),$(call proguard-disabled-commands)) 1632$(eval _instrumentation_proguard_flags:=) 1633$(eval _enable_proguard:=) 1634endef 1635 1636 1637########################################################### 1638## Stuff source generated from one-off tools 1639########################################################### 1640 1641define transform-generated-source 1642@echo "target Generated: $(PRIVATE_MODULE) <= $<" 1643@mkdir -p $(dir $@) 1644$(hide) $(PRIVATE_CUSTOM_TOOL) 1645endef 1646 1647 1648########################################################### 1649## Assertions about attributes of the target 1650########################################################### 1651 1652# $(1): The file to check 1653ifndef get-file-size 1654$(error HOST_OS must define get-file-size) 1655endif 1656 1657# Convert a partition data size (eg, as reported in /proc/mtd) to the 1658# size of the image used to flash that partition (which includes a 1659# 64-byte spare area for each 2048-byte page). 1660# $(1): the partition data size 1661define image-size-from-data-size 1662$(shell echo $$(($(1) / 2048 * (2048+64)))) 1663endef 1664 1665# $(1): The file(s) to check (often $@) 1666# $(2): The maximum total image size, in decimal bytes 1667# $(3): the type of filesystem "yaffs" or "raw" 1668# 1669# If $(2) is empty, evaluates to "true" 1670# 1671# Reserve bad blocks. Make sure that MAX(1% of partition size, 2 blocks) 1672# is left over after the image has been flashed. Round the 1% up to the 1673# next whole flash block size. 1674define assert-max-file-size 1675$(if $(2), \ 1676 size=$$(for i in $(1); do $(call get-file-size,$$i); echo +; done; echo 0); \ 1677 total=$$(( $$( echo "$$size" ) )); \ 1678 printname=$$(echo -n "$(1)" | tr " " +); \ 1679 echo "$$printname total size is $$total"; \ 1680 img_blocksize=$(call image-size-from-data-size,$(BOARD_FLASH_BLOCK_SIZE)); \ 1681 if [ "$(3)" == "yaffs" ]; then \ 1682 reservedblocks=8; \ 1683 else \ 1684 reservedblocks=0; \ 1685 fi; \ 1686 twoblocks=$$((img_blocksize * 2)); \ 1687 onepct=$$((((($(2) / 100) - 1) / img_blocksize + 1) * img_blocksize)); \ 1688 reserve=$$(((twoblocks > onepct ? twoblocks : onepct) + \ 1689 reservedblocks * img_blocksize)); \ 1690 maxsize=$$(($(2) - reserve)); \ 1691 if [ "$$total" -gt "$$maxsize" ]; then \ 1692 echo "error: $$printname too large ($$total > [$(2) - $$reserve])"; \ 1693 false; \ 1694 elif [ "$$total" -gt $$((maxsize - 32768)) ]; then \ 1695 echo "WARNING: $$printname approaching size limit ($$total now; limit $$maxsize)"; \ 1696 fi \ 1697 , \ 1698 true \ 1699 ) 1700endef 1701 1702# Like assert-max-file-size, but the second argument is a partition 1703# size, which we'll convert to a max image size before checking it 1704# against the files. 1705# 1706# $(1): The file(s) to check (often $@) 1707# $(2): The partition size. 1708define assert-max-image-size 1709$(if $(2), \ 1710 $(call assert-max-file-size,$(1),$(call image-size-from-data-size,$(2))), \ 1711 true) 1712endef 1713 1714 1715########################################################### 1716## Define device-specific radio files 1717########################################################### 1718 1719# Copy a radio image file to the output location, and add it to 1720# INSTALLED_RADIOIMAGE_TARGET. 1721# $(1): filename 1722define add-radio-file 1723 $(eval $(call add-radio-file-internal,$(1),$(notdir $(1)))) 1724endef 1725define add-radio-file-internal 1726INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2) 1727ALL_PREBUILT += $$(PRODUCT_OUT)/$(2) 1728$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP) 1729 $$(transform-prebuilt-to-target) 1730endef 1731 1732 1733########################################################### 1734# Override the package defined in $(1), setting the 1735# variables listed below differently. 1736# 1737# $(1): The makefile to override (relative to the source 1738# tree root) 1739# $(2): Old LOCAL_PACKAGE_NAME value. 1740# $(3): New LOCAL_PACKAGE_NAME value. 1741# $(4): New LOCAL_MANIFEST_PACKAGE_NAME value. 1742# $(5): New LOCAL_CERTIFICATE value. 1743# $(6): New LOCAL_INSTRUMENTATION_FOR value. 1744# $(7): New LOCAL_MANIFEST_INSTRUMENTATION_FOR value. 1745# 1746# Note that LOCAL_PACKAGE_OVERRIDES is NOT cleared in 1747# clear_vars.mk. 1748########################################################### 1749define inherit-package 1750 $(eval $(call inherit-package-internal,$(1),$(2),$(3),$(4),$(5),$(6),$(7))) 1751endef 1752 1753define inherit-package-internal 1754 LOCAL_PACKAGE_OVERRIDES \ 1755 := $(strip $(1))||$(strip $(2))||$(strip $(3))||$(strip $(4))||&&$(strip $(5))||&&$(strip $(6))||&&$(strip $(7)) $(LOCAL_PACKAGE_OVERRIDES) 1756 include $(1) 1757 LOCAL_PACKAGE_OVERRIDES \ 1758 := $(wordlist 1,$(words $(LOCAL_PACKAGE_OVERRIDES)), $(LOCAL_PACKAGE_OVERRIDES)) 1759endef 1760 1761# To be used with inherit-package above 1762# Evalutes to true if the package was overridden 1763define set-inherited-package-variables 1764$(strip $(call set-inherited-package-variables-internal)) 1765endef 1766 1767define keep-or-override 1768$(eval $(1) := $(if $(2),$(2),$($(1)))) 1769endef 1770 1771define set-inherited-package-variables-internal 1772 $(eval _o := $(subst ||, ,$(lastword $(LOCAL_PACKAGE_OVERRIDES)))) 1773 $(eval _n := $(subst ||, ,$(firstword $(LOCAL_PACKAGE_OVERRIDES)))) 1774 $(if $(filter $(word 2,$(_n)),$(LOCAL_PACKAGE_NAME)), \ 1775 $(eval LOCAL_PACKAGE_NAME := $(word 3,$(_o))) \ 1776 $(eval LOCAL_MANIFEST_PACKAGE_NAME := $(word 4,$(_o))) \ 1777 $(call keep-or-override,LOCAL_CERTIFICATE,$(patsubst &&%,%,$(word 5,$(_o)))) \ 1778 $(call keep-or-override,LOCAL_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 6,$(_o)))) \ 1779 $(call keep-or-override,LOCAL_MANIFEST_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 7,$(_o)))) \ 1780 $(eval LOCAL_OVERRIDES_PACKAGES := $(sort $(LOCAL_OVERRIDES_PACKAGES) $(word 2,$(_o)))) \ 1781 true \ 1782 ,) 1783endef 1784 1785 1786########################################################### 1787## Other includes 1788########################################################### 1789 1790# ----------------------------------------------------------------- 1791# Rules and functions to help copy important files to DIST_DIR 1792# when requested. 1793include $(BUILD_SYSTEM)/distdir.mk 1794 1795# ----------------------------------------------------------------- 1796# The modules allowed to use a user tag 1797include $(BUILD_SYSTEM)/user_tags.mk 1798 1799# broken: 1800# $(foreach file,$^,$(if $(findstring,.a,$(suffix $file)),-l$(file),$(file))) 1801 1802########################################################### 1803## Misc notes 1804########################################################### 1805 1806#DEPDIR = .deps 1807#df = $(DEPDIR)/$(*F) 1808 1809#SRCS = foo.c bar.c ... 1810 1811#%.o : %.c 1812# @$(MAKEDEPEND); \ 1813# cp $(df).d $(df).P; \ 1814# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ 1815# -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \ 1816# rm -f $(df).d 1817# $(COMPILE.c) -o $@ $< 1818 1819#-include $(SRCS:%.c=$(DEPDIR)/%.P) 1820 1821 1822#%.o : %.c 1823# $(COMPILE.c) -MD -o $@ $< 1824# @cp $*.d $*.P; \ 1825# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ 1826# -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \ 1827# rm -f $*.d 1828