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