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