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