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