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