2 # Copyright (C) 2008 The Android Open Source Project
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
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.
23 # These are variables we use to collect overall lists
24 # of things being processed.
26 # Full paths to all of the documentation
29 # The short names of all of the targets in the system.
30 # For each element of ALL_MODULES, two other variables
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
40 # Full paths to targets that should be added to the "make droid"
41 # set of installed targets.
42 ALL_DEFAULT_INSTALLED_MODULES:=
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.
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
56 ALL_MODULE_NAME_TAGS:=
58 # Full paths to all prebuilt files that will be copied
59 # (used to make the dependency on acp)
62 # Full path to all files that are made by some tool
63 ALL_GENERATED_SOURCES:=
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
67 ALL_C_CPP_ETC_OBJECTS:=
69 # The list of dynamic binaries that haven't been stripped/compressed/etc.
70 ALL_ORIGINAL_DYNAMIC_BINARIES:=
72 # These files go into the SDK
75 # Files for dalvik. This is often build without building the rest of the OS.
76 INTERNAL_DALVIK_MODULES:=
78 # All findbugs xml files
81 # GPL module license files
82 ALL_GPL_MODULE_LICENSE_FILES:=
84 # Target and host installed module's dependencies on shared libraries.
85 # They are list of "<module_name>:<installed_file>:lib1,lib2...".
86 TARGET_DEPENDENCIES_ON_SHARED_LIBRARIES :=
87 $(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_DEPENDENCIES_ON_SHARED_LIBRARIES :=
88 HOST_DEPENDENCIES_ON_SHARED_LIBRARIES :=
89 $(HOST_2ND_ARCH_VAR_PREFIX)HOST_DEPENDENCIES_ON_SHARED_LIBRARIES :=
91 # Generated class file names for Android resource.
92 # They are escaped and quoted so can be passed safely to a bash command.
93 ANDROID_RESOURCE_GENERATED_CLASSES := 'R.class' 'R$$*.class' 'Manifest.class' 'Manifest$$*.class'
95 ###########################################################
96 ## Debugging; prints a variable list to stdout
97 ###########################################################
99 # $(1): variable name list, not variable values
101 $(foreach var,$(1), \
103 $(foreach word,$($(var)), \
104 $(info $(space)$(space)$(word)) \
109 ###########################################################
110 ## Evaluates to true if the string contains the word true,
111 ## and empty otherwise
112 ## $(1): a var to test
113 ###########################################################
120 ###########################################################
121 ## Retrieve the directory of the current makefile
122 ## Must be called before including any other makefile!!
123 ###########################################################
125 # Figure out where we are.
128 $(eval LOCAL_MODULE_MAKEFILE := $$(lastword $$(MAKEFILE_LIST))) \
129 $(if $(filter $(BUILD_SYSTEM)/% $(OUT_DIR)/%,$(LOCAL_MODULE_MAKEFILE)), \
130 $(error my-dir must be called before including any other makefile.) \
132 $(patsubst %/,%,$(dir $(LOCAL_MODULE_MAKEFILE))) \
137 ###########################################################
138 ## Retrieve a list of all makefiles immediately below some directory
139 ###########################################################
141 define all-makefiles-under
142 $(wildcard $(1)/*/Android.mk)
145 ###########################################################
146 ## Look under a directory for makefiles that don't have parent
148 ###########################################################
150 # $(1): directory to search under
151 # Ignores $(1)/Android.mk
152 define first-makefiles-under
153 $(shell build/tools/findleaves.py $(FIND_LEAVES_EXCLUDES) \
154 --mindepth=2 $(1) Android.mk)
157 ###########################################################
158 ## Retrieve a list of all makefiles immediately below your directory
159 ## Must be called before including any other makefile!!
160 ###########################################################
162 define all-subdir-makefiles
163 $(call all-makefiles-under,$(call my-dir))
166 ###########################################################
167 ## Look in the named list of directories for makefiles,
168 ## relative to the current directory.
169 ## Must be called before including any other makefile!!
170 ###########################################################
172 # $(1): List of directories to look for under this directory
173 define all-named-subdir-makefiles
174 $(wildcard $(addsuffix /Android.mk, $(addprefix $(call my-dir)/,$(1))))
177 ###########################################################
178 ## Find all of the directories under the named directories with
179 ## the specified name.
180 ## Meant to be used like:
181 ## INC_DIRS := $(call all-named-dirs-under,inc,.)
182 ###########################################################
184 define all-named-dirs-under
185 $(call find-subdir-files,$(2) -type d -name "$(1)")
188 ###########################################################
189 ## Find all the directories under the current directory that
190 ## haves name that match $(1)
191 ###########################################################
193 define all-subdir-named-dirs
194 $(call all-named-dirs-under,$(1),.)
197 ###########################################################
198 ## Find all of the files under the named directories with
199 ## the specified name.
200 ## Meant to be used like:
201 ## SRC_FILES := $(call all-named-files-under,*.h,src tests)
202 ###########################################################
204 define all-named-files-under
205 $(call find-files-in-subdirs,$(LOCAL_PATH),"$(1)",$(2))
208 ###########################################################
209 ## Find all of the files under the current directory with
210 ## the specified name.
211 ###########################################################
213 define all-subdir-named-files
214 $(call all-named-files-under,$(1),.)
217 ###########################################################
218 ## Find all of the java files under the named directories.
219 ## Meant to be used like:
220 ## SRC_FILES := $(call all-java-files-under,src tests)
221 ###########################################################
223 define all-java-files-under
224 $(call all-named-files-under,*.java,$(1))
227 ###########################################################
228 ## Find all of the java files from here. Meant to be used like:
229 ## SRC_FILES := $(call all-subdir-java-files)
230 ###########################################################
232 define all-subdir-java-files
233 $(call all-java-files-under,.)
236 ###########################################################
237 ## Find all of the c files under the named directories.
238 ## Meant to be used like:
239 ## SRC_FILES := $(call all-c-files-under,src tests)
240 ###########################################################
242 define all-c-files-under
243 $(call all-named-files-under,*.c,$(1))
246 ###########################################################
247 ## Find all of the c files from here. Meant to be used like:
248 ## SRC_FILES := $(call all-subdir-c-files)
249 ###########################################################
251 define all-subdir-c-files
252 $(call all-c-files-under,.)
255 ###########################################################
256 ## Find all of the cpp files under the named directories.
257 ## LOCAL_CPP_EXTENSION is respected if set.
258 ## Meant to be used like:
259 ## SRC_FILES := $(call all-cpp-files-under,src tests)
260 ###########################################################
262 define all-cpp-files-under
263 $(sort $(patsubst ./%,%, \
264 $(shell cd $(LOCAL_PATH) ; \
265 find -L $(1) -name "*$(or $(LOCAL_CPP_EXTENSION),.cpp)" -and -not -name ".*") \
269 ###########################################################
270 ## Find all of the cpp files from here. Meant to be used like:
271 ## SRC_FILES := $(call all-subdir-cpp-files)
272 ###########################################################
274 define all-subdir-cpp-files
275 $(call all-cpp-files-under,.)
278 ###########################################################
279 ## Find all files named "I*.aidl" under the named directories,
280 ## which must be relative to $(LOCAL_PATH). The returned list
281 ## is relative to $(LOCAL_PATH).
282 ###########################################################
284 define all-Iaidl-files-under
285 $(call all-named-files-under,I*.aidl,$(1))
288 ###########################################################
289 ## Find all of the "I*.aidl" files under $(LOCAL_PATH).
290 ###########################################################
292 define all-subdir-Iaidl-files
293 $(call all-Iaidl-files-under,.)
296 ###########################################################
297 ## Find all of the logtags files under the named directories.
298 ## Meant to be used like:
299 ## SRC_FILES := $(call all-logtags-files-under,src)
300 ###########################################################
302 define all-logtags-files-under
303 $(call all-named-files-under,*.logtags,$(1))
306 ###########################################################
307 ## Find all of the .proto files under the named directories.
308 ## Meant to be used like:
309 ## SRC_FILES := $(call all-proto-files-under,src)
310 ###########################################################
312 define all-proto-files-under
313 $(call all-named-files-under,*.proto,$(1))
316 ###########################################################
317 ## Find all of the RenderScript files under the named directories.
318 ## Meant to be used like:
319 ## SRC_FILES := $(call all-renderscript-files-under,src)
320 ###########################################################
322 define all-renderscript-files-under
323 $(call find-subdir-files,$(1) \( -name "*.rs" -or -name "*.fs" \) -and -not -name ".*")
326 ###########################################################
327 ## Find all of the S files under the named directories.
328 ## Meant to be used like:
329 ## SRC_FILES := $(call all-c-files-under,src tests)
330 ###########################################################
332 define all-S-files-under
333 $(call all-named-files-under,*.S,$(1))
336 ###########################################################
337 ## Find all of the html files under the named directories.
338 ## Meant to be used like:
339 ## SRC_FILES := $(call all-html-files-under,src tests)
340 ###########################################################
342 define all-html-files-under
343 $(call all-named-files-under,*.html,$(1))
346 ###########################################################
347 ## Find all of the html files from here. Meant to be used like:
348 ## SRC_FILES := $(call all-subdir-html-files)
349 ###########################################################
351 define all-subdir-html-files
352 $(call all-html-files-under,.)
355 ###########################################################
356 ## Find all of the files matching pattern
357 ## SRC_FILES := $(call find-subdir-files, <pattern>)
358 ###########################################################
360 define find-subdir-files
361 $(sort $(patsubst ./%,%,$(shell cd $(LOCAL_PATH) ; find -L $(1))))
364 ###########################################################
365 # find the files in the subdirectory $1 of LOCAL_DIR
366 # matching pattern $2, filtering out files $3
368 # SRC_FILES += $(call find-subdir-subdir-files, \
369 # css, *.cpp, DontWantThis.cpp)
370 ###########################################################
372 define find-subdir-subdir-files
373 $(sort $(filter-out $(patsubst %,$(1)/%,$(3)),$(patsubst ./%,%,$(shell cd \
374 $(LOCAL_PATH) ; find -L $(1) -maxdepth 1 -name $(2)))))
377 ###########################################################
378 ## Find all of the files matching pattern
379 ## SRC_FILES := $(call all-subdir-java-files)
380 ###########################################################
382 define find-subdir-assets
383 $(sort $(if $(1),$(patsubst ./%,%, \
384 $(shell if [ -d $(1) ] ; then cd $(1) ; find ./ -not -name '.*' -and -type f -and -not -type l ; fi)), \
385 $(warning Empty argument supplied to find-subdir-assets) \
389 ###########################################################
390 ## Find various file types in a list of directories relative to $(LOCAL_PATH)
391 ###########################################################
393 define find-other-java-files
394 $(call all-java-files-under,$(1))
397 define find-other-html-files
398 $(call all-html-files-under,$(1))
401 ###########################################################
402 # Use utility find to find given files in the given subdirs.
403 # This function uses $(1), instead of LOCAL_PATH as the base.
404 # $(1): the base dir, relative to the root of the source tree.
405 # $(2): the file name pattern to be passed to find as "-name".
406 # $(3): a list of subdirs of the base dir.
407 # Returns: a list of paths relative to the base dir.
408 ###########################################################
410 define find-files-in-subdirs
411 $(sort $(patsubst ./%,%, \
413 find -L $(3) -name $(2) -and -not -name ".*") \
417 ###########################################################
418 ## Scan through each directory of $(1) looking for files
419 ## that match $(2) using $(wildcard). Useful for seeing if
420 ## a given directory or one of its parents contains
421 ## a particular file. Returns the first match found,
422 ## starting furthest from the root.
423 ###########################################################
425 define find-parent-file
427 $(eval _fpf := $(wildcard $(foreach f, $(2), $(strip $(1))/$(f)))) \
428 $(if $(_fpf),$(_fpf), \
429 $(if $(filter-out ./ .,$(1)), \
430 $(call find-parent-file,$(patsubst %/,%,$(dir $(1))),$(2)) \
436 ###########################################################
437 ## Function we can evaluate to introduce a dynamic dependency
438 ###########################################################
440 define add-dependency
444 ###########################################################
445 ## Reverse order of a list
446 ###########################################################
449 $(if $(1),$(call reverse-list,$(wordlist 2,$(words $(1)),$(1)))) $(firstword $(1))
452 ###########################################################
453 ## The intermediates directory. Where object files go for
454 ## a given target. We could technically get away without
455 ## the "_intermediates" suffix on the directory, but it's
456 ## nice to be able to grep for that string to find out if
457 ## anyone's abusing the system.
458 ###########################################################
460 # $(1): target class, like "APPS"
461 # $(2): target name, like "NotePad"
462 # $(3): if non-empty, this is a HOST target.
463 # $(4): if non-empty, force the intermediates to be COMMON
464 # $(5): if non-empty, force the intermedistes to be for the 2nd arch
465 define intermediates-dir-for
467 $(eval _idfClass := $(strip $(1))) \
468 $(if $(_idfClass),, \
469 $(error $(LOCAL_PATH): Class not defined in call to intermediates-dir-for)) \
470 $(eval _idfName := $(strip $(2))) \
472 $(error $(LOCAL_PATH): Name not defined in call to intermediates-dir-for)) \
473 $(eval _idfPrefix := $(if $(strip $(3)),HOST,TARGET)) \
474 $(eval _idf2ndArchPrefix := $(if $(strip $(5)),$(TARGET_2ND_ARCH_VAR_PREFIX))) \
475 $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
476 $(eval _idfIntBase := $($(_idfPrefix)_OUT_COMMON_INTERMEDIATES)) \
477 ,$(if $(filter $(_idfClass),SHARED_LIBRARIES STATIC_LIBRARIES EXECUTABLES GYP),\
478 $(eval _idfIntBase := $($(_idf2ndArchPrefix)$(_idfPrefix)_OUT_INTERMEDIATES)) \
479 ,$(eval _idfIntBase := $($(_idfPrefix)_OUT_INTERMEDIATES)) \
482 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
486 # Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE
487 # to determine the intermediates directory.
489 # $(1): if non-empty, force the intermediates to be COMMON
490 # $(2): if non-empty, force the intermediates to be for the 2nd arch
491 define local-intermediates-dir
493 $(if $(strip $(LOCAL_MODULE_CLASS)),, \
494 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-intermediates-dir)) \
495 $(if $(strip $(LOCAL_MODULE)),, \
496 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-intermediates-dir)) \
497 $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(LOCAL_IS_HOST_MODULE),$(1),$(2)) \
501 ###########################################################
502 ## The generated sources directory. Placing generated
503 ## source files directly in the intermediates directory
504 ## causes problems for multiarch builds, where there are
505 ## two intermediates directories for a single target. Put
506 ## them in a separate directory, and they will be copied to
507 ## each intermediates directory automatically.
508 ###########################################################
510 # $(1): target class, like "APPS"
511 # $(2): target name, like "NotePad"
512 # $(3): if non-empty, this is a HOST target.
513 # $(4): if non-empty, force the generated sources to be COMMON
514 define generated-sources-dir-for
516 $(eval _idfClass := $(strip $(1))) \
517 $(if $(_idfClass),, \
518 $(error $(LOCAL_PATH): Class not defined in call to generated-sources-dir-for)) \
519 $(eval _idfName := $(strip $(2))) \
521 $(error $(LOCAL_PATH): Name not defined in call to generated-sources-dir-for)) \
522 $(eval _idfPrefix := $(if $(strip $(3)),HOST,TARGET)) \
523 $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
524 $(eval _idfIntBase := $($(_idfPrefix)_OUT_GEN_COMMON)) \
526 $(eval _idfIntBase := $($(_idfPrefix)_OUT_GEN)) \
528 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
532 # Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE
533 # to determine the generated sources directory.
535 # $(1): if non-empty, force the intermediates to be COMMON
536 define local-generated-sources-dir
538 $(if $(strip $(LOCAL_MODULE_CLASS)),, \
539 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-generated-sources-dir)) \
540 $(if $(strip $(LOCAL_MODULE)),, \
541 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-generated-sources-dir)) \
542 $(call generated-sources-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(LOCAL_IS_HOST_MODULE),$(1)) \
546 ###########################################################
547 ## Convert "path/to/libXXX.so" to "-lXXX".
548 ## Any "path/to/libXXX.a" elements pass through unchanged.
549 ###########################################################
551 define normalize-libraries
552 $(foreach so,$(filter %.so,$(1)),-l$(patsubst lib%.so,%,$(notdir $(so))))\
553 $(filter-out %.so,$(1))
556 # TODO: change users to call the common version.
557 define normalize-host-libraries
558 $(call normalize-libraries,$(1))
561 define normalize-target-libraries
562 $(call normalize-libraries,$(1))
565 ###########################################################
566 ## Convert a list of short module names (e.g., "framework", "Browser")
567 ## into the list of files that are built for those modules.
568 ## NOTE: this won't return reliable results until after all
569 ## sub-makefiles have been included.
571 ###########################################################
573 define module-built-files
574 $(foreach module,$(1),$(ALL_MODULES.$(module).BUILT))
577 ###########################################################
578 ## Convert a list of short modules names (e.g., "framework", "Browser")
579 ## into the list of files that are installed for those modules.
580 ## NOTE: this won't return reliable results until after all
581 ## sub-makefiles have been included.
583 ###########################################################
585 define module-installed-files
586 $(foreach module,$(1),$(ALL_MODULES.$(module).INSTALLED))
589 ###########################################################
590 ## Convert a list of short modules names (e.g., "framework", "Browser")
591 ## into the list of files that should be used when linking
592 ## against that module as a public API.
593 ## TODO: Allow this for more than JAVA_LIBRARIES modules
594 ## NOTE: this won't return reliable results until after all
595 ## sub-makefiles have been included.
597 ###########################################################
599 define module-stubs-files
600 $(foreach module,$(1),$(ALL_MODULES.$(module).STUBS))
603 ###########################################################
604 ## Evaluates to the timestamp file for a doc module, which
605 ## is the dependency that should be used.
607 ###########################################################
609 define doc-timestamp-for
610 $(OUT_DOCS)/$(strip $(1))-timestamp
614 ###########################################################
615 ## Convert "core ext framework" to "out/.../javalib.jar ..."
616 ## $(1): library list
617 ## $(2): Non-empty if IS_HOST_MODULE
618 ###########################################################
621 # $(2): Non-empty if IS_HOST_MODULE
623 $(call intermediates-dir-for, \
624 JAVA_LIBRARIES,$(1),$(2),COMMON)
628 # $(2): Non-empty if IS_HOST_MODULE
629 define _java-lib-full-classes.jar
630 $(call _java-lib-dir,$(1),$(2))/classes$(COMMON_JAVA_PACKAGE_SUFFIX)
633 # $(1): library name list
634 # $(2): Non-empty if IS_HOST_MODULE
635 define java-lib-files
636 $(foreach lib,$(1),$(call _java-lib-full-classes.jar,$(lib),$(2)))
640 # $(2): Non-empty if IS_HOST_MODULE
641 define _java-lib-full-dep
642 $(call _java-lib-dir,$(1),$(2))/$(if $(2),javalib,classes)$(COMMON_JAVA_PACKAGE_SUFFIX)
645 # $(1): library name list
646 # $(2): Non-empty if IS_HOST_MODULE
648 $(foreach lib,$(1),$(call _java-lib-full-dep,$(lib),$(2)))
651 ###########################################################
652 ## Convert "core ext framework" to "out/.../classes.jack ..."
653 ## $(1): library list
654 ## $(2): Non-empty if IS_HOST_MODULE
655 ###########################################################
658 # $(2): Non-empty if IS_HOST_MODULE
659 define _jack-lib-full-classes
660 $(call _java-lib-dir,$(1),$(2))/classes.jack
663 # $(1): library name list
664 # $(2): Non-empty if IS_HOST_MODULE
665 define jack-lib-files
666 $(foreach lib,$(1),$(call _jack-lib-full-classes,$(lib),$(2)))
670 # $(2): Non-empty if IS_HOST_MODULE
671 define _jack-lib-full-dep
672 $(call _jack-lib-full-classes,$(1),$(2))
675 # $(1): library name list
676 # $(2): Non-empty if IS_HOST_MODULE
678 $(foreach lib,$(1),$(call _jack-lib-full-dep,$(lib),$(2)))
681 ###########################################################
682 ## Run rot13 on a string
683 ## $(1): the string. Must be one line.
684 ###########################################################
686 $(shell echo $(1) | tr 'a-zA-Z' 'n-za-mN-ZA-M')
690 ###########################################################
691 ## Returns true if $(1) and $(2) are equal. Returns
692 ## the empty string if they are not equal.
693 ###########################################################
695 $(strip $(if $(strip $(1)),\
697 $(if $(filter-out __,_$(subst $(strip $(1)),,$(strip $(2)))$(subst $(strip $(2)),,$(strip $(1)))_),,true), \
705 ###########################################################
706 ## Convert "a b c" into "a:b:c"
707 ###########################################################
708 define normalize-path-list
709 $(subst $(space),:,$(strip $(1)))
712 ###########################################################
713 ## Read the word out of a colon-separated list of words.
714 ## This has the same behavior as the built-in function
717 ## The individual words may not contain spaces.
719 ## $(1): 1 based index
720 ## $(2): value of the form a:b:c...
721 ###########################################################
724 $(word $(1),$(subst :,$(space),$(2)))
727 ###########################################################
728 ## Convert "a=b c= d e = f" into "a=b c=d e=f"
730 ## $(1): list to collapse
731 ## $(2): if set, separator word; usually "=", ":", or ":="
732 ## Defaults to "=" if not set.
733 ###########################################################
735 define collapse-pairs
736 $(eval _cpSEP := $(strip $(if $(2),$(2),=)))\
737 $(subst $(space)$(_cpSEP)$(space),$(_cpSEP),$(strip \
738 $(subst $(_cpSEP), $(_cpSEP) ,$(1))))
741 ###########################################################
742 ## Given a list of pairs, if multiple pairs have the same
743 ## first components, keep only the first pair.
745 ## $(1): list of pairs
746 ## $(2): the separator word, such as ":", "=", etc.
747 define uniq-pairs-by-first-component
748 $(eval _upbfc_fc_set :=)\
749 $(strip $(foreach w,$(1), $(eval _first := $(word 1,$(subst $(2),$(space),$(w))))\
750 $(if $(filter $(_upbfc_fc_set),$(_first)),,$(w)\
751 $(eval _upbfc_fc_set += $(_first)))))\
752 $(eval _upbfc_fc_set :=)\
756 ###########################################################
757 ## MODULE_TAG set operations
758 ###########################################################
760 # Given a list of tags, return the targets that specify
763 define modules-for-tag-list
764 $(sort $(foreach tag,$(1),$(foreach m,$(ALL_MODULE_NAME_TAGS.$(tag)),$(ALL_MODULES.$(m).INSTALLED))))
767 # Same as modules-for-tag-list, but operates on
768 # ALL_MODULE_NAME_TAGS.
770 define module-names-for-tag-list
771 $(sort $(foreach tag,$(1),$(ALL_MODULE_NAME_TAGS.$(tag))))
774 # Given an accept and reject list, find the matching
775 # set of targets. If a target has multiple tags and
776 # any of them are rejected, the target is rejected.
777 # Reject overrides accept.
778 # $(1): list of tags to accept
779 # $(2): list of tags to reject
780 #TODO(dbort): do $(if $(strip $(1)),$(1),$(ALL_MODULE_TAGS))
781 #TODO(jbq): as of 20100106 nobody uses the second parameter
782 define get-tagged-modules
784 $(call modules-for-tag-list,$(2)), \
785 $(call modules-for-tag-list,$(1)))
788 ###########################################################
789 ## Append a leaf to a base path. Properly deals with
790 ## base paths ending in /.
794 ###########################################################
797 $(subst //,/,$(1)/$(2))
801 ###########################################################
803 ###########################################################
805 # Given a list of installed modules (short or long names)
806 # return a list of the packages (yes, .apk packages, not
807 # modules in general) that are overridden by this list and,
808 # therefore, should not be installed.
809 # $(1): mixed list of installed modules
810 # TODO: This is fragile; find a reliable way to get this information.
811 define _get-package-overrides
812 $(eval ### Discard any words containing slashes, unless they end in .apk, \
813 ### in which case trim off the directory component and the suffix. \
814 ### If there are no slashes, keep the entire word.)
815 $(eval _gpo_names := $(subst /,@@@ @@@,$(1)))
816 $(eval _gpo_names := \
817 $(filter %.apk,$(_gpo_names)) \
818 $(filter-out %@@@ @@@%,$(_gpo_names)))
819 $(eval _gpo_names := $(patsubst %.apk,%,$(_gpo_names)))
820 $(eval _gpo_names := $(patsubst @@@%,%,$(_gpo_names)))
822 $(eval ### Remove any remaining words that contain dots.)
823 $(eval _gpo_names := $(subst .,@@@ @@@,$(_gpo_names)))
824 $(eval _gpo_names := $(filter-out %@@@ @@@%,$(_gpo_names)))
826 $(eval ### Now we have a list of any words that could possibly refer to \
827 ### packages, although there may be words that do not. Only \
828 ### real packages will be present under PACKAGES.*, though.)
829 $(foreach _gpo_name,$(_gpo_names),$(PACKAGES.$(_gpo_name).OVERRIDES))
832 define get-package-overrides
833 $(sort $(strip $(call _get-package-overrides,$(1))))
836 ###########################################################
837 ## Output the command lines, or not
838 ###########################################################
840 ifeq ($(strip $(SHOW_COMMANDS)),)
851 ###########################################################
852 ## Dump the variables that are associated with targets
853 ###########################################################
855 define dump-module-variables
856 @echo all_dependencies=$^
857 @echo PRIVATE_YACCFLAGS=$(PRIVATE_YACCFLAGS);
858 @echo PRIVATE_CFLAGS=$(PRIVATE_CFLAGS);
859 @echo PRIVATE_CPPFLAGS=$(PRIVATE_CPPFLAGS);
860 @echo PRIVATE_DEBUG_CFLAGS=$(PRIVATE_DEBUG_CFLAGS);
861 @echo PRIVATE_C_INCLUDES=$(PRIVATE_C_INCLUDES);
862 @echo PRIVATE_LDFLAGS=$(PRIVATE_LDFLAGS);
863 @echo PRIVATE_LDLIBS=$(PRIVATE_LDLIBS);
864 @echo PRIVATE_ARFLAGS=$(PRIVATE_ARFLAGS);
865 @echo PRIVATE_AAPT_FLAGS=$(PRIVATE_AAPT_FLAGS);
866 @echo PRIVATE_DX_FLAGS=$(PRIVATE_DX_FLAGS);
867 @echo PRIVATE_JAVACFLAGS=$(PRIVATE_JAVACFLAGS);
868 @echo PRIVATE_JAVA_LIBRARIES=$(PRIVATE_JAVA_LIBRARIES);
869 @echo PRIVATE_ALL_SHARED_LIBRARIES=$(PRIVATE_ALL_SHARED_LIBRARIES);
870 @echo PRIVATE_ALL_STATIC_LIBRARIES=$(PRIVATE_ALL_STATIC_LIBRARIES);
871 @echo PRIVATE_ALL_WHOLE_STATIC_LIBRARIES=$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES);
872 @echo PRIVATE_ALL_OBJECTS=$(PRIVATE_ALL_OBJECTS);
873 @echo PRIVATE_NO_CRT=$(PRIVATE_NO_CRT);
876 ###########################################################
877 ## Commands for using sed to replace given variable values
878 ###########################################################
880 define transform-variables
882 @echo "Sed: $(if $(PRIVATE_MODULE),$(PRIVATE_MODULE),$@) <= $<"
883 $(hide) sed $(foreach var,$(REPLACE_VARS),-e "s/{{$(var)}}/$(subst /,\/,$(PWD)/$($(var)))/g") $< >$@
884 $(hide) if [ "$(suffix $@)" = ".sh" ]; then chmod a+rx $@; fi
888 ###########################################################
889 ## Commands for munging the dependency files GCC generates
890 ###########################################################
891 # $(1): the input .d file
892 # $(2): the output .P file
893 define transform-d-to-p-args
894 $(hide) cp $(1) $(2); \
895 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
896 -e '/^$$/ d' -e 's/$$/ :/' < $(1) >> $(2); \
900 define transform-d-to-p
901 $(call transform-d-to-p-args,$(@:%.o=%.d),$(@:%.o=%.P))
904 ###########################################################
905 ## Commands for running lex
906 ###########################################################
908 define transform-l-to-cpp
910 @echo "Lex: $(PRIVATE_MODULE) <= $<"
911 $(hide) $(LEX) -o$@ $<
914 ###########################################################
915 ## Commands for running yacc
917 ## Because the extension of c++ files can change, the
918 ## extension must be specified in $1.
919 ## E.g, "$(call transform-y-to-cpp,.cpp)"
920 ###########################################################
922 define transform-y-to-cpp
924 @echo "Yacc: $(PRIVATE_MODULE) <= $<"
925 $(YACC) $(PRIVATE_YACCFLAGS) -o $@ $<
926 touch $(@:$1=$(YACC_HEADER_SUFFIX))
927 echo '#ifndef '$(@F:$1=_h) > $(@:$1=.h)
928 echo '#define '$(@F:$1=_h) >> $(@:$1=.h)
929 cat $(@:$1=$(YACC_HEADER_SUFFIX)) >> $(@:$1=.h)
930 echo '#endif' >> $(@:$1=.h)
933 ###########################################################
934 ## Commands to compile RenderScript to Java
935 ###########################################################
937 define transform-renderscripts-to-java-and-bc
938 @echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)"
939 $(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR)
940 $(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/res/raw
941 $(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/src
942 $(hide) $(PRIVATE_RS_CC) \
943 -o $(PRIVATE_RS_OUTPUT_DIR)/res/raw \
944 -p $(PRIVATE_RS_OUTPUT_DIR)/src \
945 -d $(PRIVATE_RS_OUTPUT_DIR) \
947 $(addprefix -target-api , $(PRIVATE_RS_TARGET_API)) \
948 $(PRIVATE_RS_FLAGS) \
949 $(foreach inc,$(PRIVATE_RS_INCLUDES),$(addprefix -I , $(inc))) \
950 $(PRIVATE_RS_SOURCE_FILES)
951 $(foreach d,$(PRIVATE_DEP_FILES),\
952 $(call transform-d-to-p-args,$(d),$(d:%.d=%.P))$(newline))
953 $(hide) mkdir -p $(dir $@)
957 define transform-bc-to-so
958 @echo "Renderscript compatibility: $(notdir $@) <= $(notdir $<)"
959 $(hide) mkdir -p $(dir $@)
960 $(hide) $(BCC_COMPAT) -O3 -o $(dir $@)/$(notdir $(<:.bc=.o)) -fPIC -shared \
961 -rt-path $(RS_PREBUILT_CLCORE) -mtriple $(RS_COMPAT_TRIPLE) $<
962 $(hide) $(PRIVATE_CXX) -shared -Wl,-soname,$(notdir $@) -nostdlib \
963 -Wl,-rpath,\$$ORIGIN/../lib \
964 $(dir $@)/$(notdir $(<:.bc=.o)) \
965 $(RS_PREBUILT_COMPILER_RT) \
966 -o $@ $(TARGET_GLOBAL_LDFLAGS) -Wl,--hash-style=sysv -L prebuilts/gcc/ \
967 $(RS_PREBUILT_LIBPATH) -L $(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
971 ###########################################################
972 ## Commands to compile RenderScript to C++
973 ###########################################################
975 define transform-renderscripts-to-cpp-and-bc
976 @echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)"
977 $(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR)
978 $(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/
979 $(hide) $(PRIVATE_RS_CC) \
980 -o $(PRIVATE_RS_OUTPUT_DIR)/ \
981 -d $(PRIVATE_RS_OUTPUT_DIR) \
984 $(PRIVATE_RS_FLAGS) \
985 $(addprefix -I , $(PRIVATE_RS_INCLUDES)) \
986 $(PRIVATE_RS_SOURCE_FILES)
987 $(foreach d,$(PRIVATE_DEP_FILES),\
988 $(call transform-d-to-p-args,$(d),$(d:%.d=%.P))$(newline))
989 $(hide) mkdir -p $(dir $@)
994 ###########################################################
995 ## Commands for running aidl
996 ###########################################################
998 define transform-aidl-to-java
1000 @echo "Aidl: $(PRIVATE_MODULE) <= $<"
1001 $(hide) $(AIDL) -d$(patsubst %.java,%.P,$@) $(PRIVATE_AIDL_FLAGS) $< $@
1003 #$(AIDL) $(PRIVATE_AIDL_FLAGS) $< - | indent -nut -br -npcs -l1000 > $@
1006 ###########################################################
1007 ## Commands for running java-event-log-tags.py
1008 ###########################################################
1010 define transform-logtags-to-java
1012 @echo "logtags: $@ <= $<"
1013 $(hide) $(JAVATAGS) -o $@ $^
1017 ###########################################################
1018 ## Commands for running protoc to compile .proto into .java
1019 ###########################################################
1021 define transform-proto-to-java
1023 @echo "Protoc: $@ <= $(PRIVATE_PROTO_SRC_FILES)"
1024 @rm -rf $(PRIVATE_PROTO_JAVA_OUTPUT_DIR)
1025 @mkdir -p $(PRIVATE_PROTO_JAVA_OUTPUT_DIR)
1026 $(hide) for f in $(PRIVATE_PROTO_SRC_FILES); do \
1028 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
1029 $(PRIVATE_PROTO_JAVA_OUTPUT_OPTION)="$(PRIVATE_PROTO_JAVA_OUTPUT_PARAMS):$(PRIVATE_PROTO_JAVA_OUTPUT_DIR)" \
1030 $(PRIVATE_PROTOC_FLAGS) \
1036 ######################################################################
1037 ## Commands for running protoc to compile .proto into .pb.cc (or.pb.c) and .pb.h
1038 ######################################################################
1039 define transform-proto-to-cc
1041 @echo "Protoc: $@ <= $<"
1043 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
1044 $(PRIVATE_PROTOC_FLAGS) \
1048 ###########################################################
1049 ## Commands for running gcc to compile a C++ file
1050 ###########################################################
1052 define transform-cpp-to-o
1054 @echo "target $(PRIVATE_ARM_MODE) C++: $(PRIVATE_MODULE) <= $<"
1055 $(hide) $(PRIVATE_CXX) \
1056 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
1057 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
1058 $(addprefix -isystem ,\
1059 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1060 $(filter-out $(PRIVATE_C_INCLUDES), \
1061 $(PRIVATE_TARGET_PROJECT_INCLUDES) \
1062 $(PRIVATE_TARGET_C_INCLUDES)))) \
1064 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1065 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
1066 $(PRIVATE_TARGET_GLOBAL_CPPFLAGS) \
1067 $(PRIVATE_ARM_CFLAGS) \
1069 $(PRIVATE_RTTI_FLAG) \
1071 $(PRIVATE_CPPFLAGS) \
1072 $(PRIVATE_DEBUG_CFLAGS) \
1073 $(GLOBAL_CFLAGS_NO_OVERRIDE) \
1074 $(GLOBAL_CPPFLAGS_NO_OVERRIDE) \
1075 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
1080 ###########################################################
1081 ## Commands for running gcc to compile a C file
1082 ###########################################################
1085 define transform-c-or-s-to-o-no-deps
1087 $(hide) $(PRIVATE_CC) \
1088 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
1089 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
1090 $(addprefix -isystem ,\
1091 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1092 $(filter-out $(PRIVATE_C_INCLUDES), \
1093 $(PRIVATE_TARGET_PROJECT_INCLUDES) \
1094 $(PRIVATE_TARGET_C_INCLUDES)))) \
1096 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1097 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
1098 $(PRIVATE_TARGET_GLOBAL_CONLYFLAGS) \
1099 $(PRIVATE_ARM_CFLAGS) \
1102 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
1105 define transform-c-to-o-no-deps
1106 @echo "target $(PRIVATE_ARM_MODE) C: $(PRIVATE_MODULE) <= $<"
1107 $(call transform-c-or-s-to-o-no-deps, \
1109 $(PRIVATE_CONLYFLAGS) \
1110 $(PRIVATE_DEBUG_CFLAGS) \
1111 $(GLOBAL_CFLAGS_NO_OVERRIDE))
1114 define transform-s-to-o-no-deps
1115 @echo "target asm: $(PRIVATE_MODULE) <= $<"
1116 $(call transform-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
1119 define transform-c-to-o
1120 $(transform-c-to-o-no-deps)
1124 define transform-s-to-o
1125 $(transform-s-to-o-no-deps)
1130 define transform-asm-to-o
1133 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
1134 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_YASM_FLAGS) \
1135 $(PRIVATE_ASFLAGS) \
1139 ###########################################################
1140 ## Commands for running gcc to compile an Objective-C file
1141 ## This should never happen for target builds but this
1142 ## will error at build time.
1143 ###########################################################
1145 define transform-m-to-o-no-deps
1146 @echo "target ObjC: $(PRIVATE_MODULE) <= $<"
1147 $(call transform-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_DEBUG_CFLAGS))
1150 define transform-m-to-o
1151 $(transform-m-to-o-no-deps)
1155 ###########################################################
1156 ## Commands for running gcc to compile a host C++ file
1157 ###########################################################
1159 define transform-host-cpp-to-o
1161 @echo "host C++: $(PRIVATE_MODULE) <= $<"
1162 $(hide) $(PRIVATE_CXX) \
1163 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
1164 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
1165 $(addprefix -isystem ,\
1166 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1167 $(filter-out $(PRIVATE_C_INCLUDES), \
1168 $(HOST_PROJECT_INCLUDES) \
1169 $(PRIVATE_HOST_C_INCLUDES)))) \
1171 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1172 $(PRIVATE_HOST_GLOBAL_CFLAGS) \
1173 $(PRIVATE_HOST_GLOBAL_CPPFLAGS) \
1176 $(PRIVATE_CPPFLAGS) \
1177 $(PRIVATE_DEBUG_CFLAGS) \
1178 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
1183 ###########################################################
1184 ## Commands for running gcc to compile a host C file
1185 ###########################################################
1188 define transform-host-c-or-s-to-o-no-deps
1190 $(hide) $(PRIVATE_CC) \
1191 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
1192 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
1193 $(addprefix -isystem ,\
1194 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1195 $(filter-out $(PRIVATE_C_INCLUDES), \
1196 $(HOST_PROJECT_INCLUDES) \
1197 $(PRIVATE_HOST_C_INCLUDES)))) \
1199 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1200 $(PRIVATE_HOST_GLOBAL_CFLAGS) \
1201 $(PRIVATE_HOST_GLOBAL_CONLYFLAGS) \
1204 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
1207 define transform-host-c-to-o-no-deps
1208 @echo "host C: $(PRIVATE_MODULE) <= $<"
1209 $(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_CONLYFLAGS) $(PRIVATE_DEBUG_CFLAGS))
1212 define transform-host-s-to-o-no-deps
1213 @echo "host asm: $(PRIVATE_MODULE) <= $<"
1214 $(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
1217 define transform-host-c-to-o
1218 $(transform-host-c-to-o-no-deps)
1222 define transform-host-s-to-o
1223 $(transform-host-s-to-o-no-deps)
1227 ###########################################################
1228 ## Commands for running gcc to compile a host Objective-C file
1229 ###########################################################
1231 define transform-host-m-to-o-no-deps
1232 @echo "host ObjC: $(PRIVATE_MODULE) <= $<"
1233 $(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_DEBUG_CFLAGS))
1236 define transform-host-m-to-o
1237 $(transform-host-m-to-o-no-deps)
1242 ###########################################################
1243 ## Rules to compile a single C/C++ source with ../ in the path
1244 ###########################################################
1245 # Replace "../" in object paths with $(DOTDOT_REPLACEMENT).
1246 DOTDOT_REPLACEMENT := dotdot/
1248 ## Rule to compile a C++ source file with ../ in the path.
1249 ## Must be called with $(eval).
1250 # $(1): the C++ source file in LOCAL_SRC_FILES.
1251 # $(2): the additional dependencies.
1252 # $(3): the variable name to collect the output object file.
1253 define compile-dotdot-cpp-file
1254 o := $(intermediates)/$(patsubst %$(LOCAL_CPP_EXTENSION),%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
1255 $$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2)
1256 $$(transform-$$(PRIVATE_HOST)cpp-to-o)
1257 -include $$(o:%.o=%.P)
1261 ## Rule to compile a C source file with ../ in the path.
1262 ## Must be called with $(eval).
1263 # $(1): the C source file in LOCAL_SRC_FILES.
1264 # $(2): the additional dependencies.
1265 # $(3): the variable name to collect the output object file.
1266 define compile-dotdot-c-file
1267 o := $(intermediates)/$(patsubst %.c,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
1268 $$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2)
1269 $$(transform-$$(PRIVATE_HOST)c-to-o)
1270 -include $$(o:%.o=%.P)
1274 ## Rule to compile a .S source file with ../ in the path.
1275 ## Must be called with $(eval).
1276 # $(1): the .S source file in LOCAL_SRC_FILES.
1277 # $(2): the additional dependencies.
1278 # $(3): the variable name to collect the output object file.
1279 define compile-dotdot-s-file
1280 o := $(intermediates)/$(patsubst %.S,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
1281 $$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2)
1282 $$(transform-$$(PRIVATE_HOST)s-to-o)
1283 -include $$(o:%.o=%.P)
1287 ## Rule to compile a .s source file with ../ in the path.
1288 ## Must be called with $(eval).
1289 # $(1): the .s source file in LOCAL_SRC_FILES.
1290 # $(2): the additional dependencies.
1291 # $(3): the variable name to collect the output object file.
1292 define compile-dotdot-s-file-no-deps
1293 o := $(intermediates)/$(patsubst %.s,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
1294 $$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2)
1295 $$(transform-$$(PRIVATE_HOST)s-to-o-no-deps)
1299 ###########################################################
1300 ## Commands for running ar
1301 ###########################################################
1303 define _concat-if-arg2-not-empty
1304 $(if $(2),$(hide) $(1) $(2))
1307 # Split long argument list into smaller groups and call the command repeatedly
1308 # Call the command at least once even if there are no arguments, as otherwise
1309 # the output file won't be created.
1311 # $(1): the command without arguments
1312 # $(2): the arguments
1313 define split-long-arguments
1314 $(hide) $(1) $(wordlist 1,500,$(2))
1315 $(call _concat-if-arg2-not-empty,$(1),$(wordlist 501,1000,$(2)))
1316 $(call _concat-if-arg2-not-empty,$(1),$(wordlist 1001,1500,$(2)))
1317 $(call _concat-if-arg2-not-empty,$(1),$(wordlist 1501,2000,$(2)))
1318 $(call _concat-if-arg2-not-empty,$(1),$(wordlist 2001,2500,$(2)))
1319 $(call _concat-if-arg2-not-empty,$(1),$(wordlist 2501,3000,$(2)))
1320 $(call _concat-if-arg2-not-empty,$(1),$(wordlist 3001,99999,$(2)))
1323 # $(1): the full path of the source static library.
1324 define _extract-and-include-single-target-whole-static-lib
1325 @echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(strip $(1))]"
1326 $(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\
1330 lib_to_include=$$ldir/$(notdir $(1)); \
1333 for f in `$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) t $(1)`; do \
1334 if [ -e $$ldir/$$f ]; then \
1335 mkdir $$ldir/$$subdir; \
1337 subdir=$$((subdir+1)); \
1338 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) m $$lib_to_include $$f; \
1342 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) p $$lib_to_include $$f > $$ldir/$$ext$$f; \
1343 filelist="$$filelist $$ldir/$$ext$$f"; \
1345 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \
1346 $(PRIVATE_ARFLAGS) $@ $$filelist
1350 # $(1): the full path of the source static library.
1351 define extract-and-include-whole-static-libs-first
1353 @echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(strip $(1))]"
1357 define extract-and-include-target-whole-static-libs
1358 $(call extract-and-include-whole-static-libs-first, $(firstword $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)))
1359 $(foreach lib,$(wordlist 2,999,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)), \
1360 $(call _extract-and-include-single-target-whole-static-lib, $(lib)))
1363 # Explicitly delete the archive first so that ar doesn't
1364 # try to add to an existing archive.
1365 define transform-o-to-static-lib
1368 $(extract-and-include-target-whole-static-libs)
1369 @echo "target StaticLib: $(PRIVATE_MODULE) ($@)"
1370 $(call split-long-arguments,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) \
1371 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \
1372 $(PRIVATE_ARFLAGS) $@,$(PRIVATE_ALL_OBJECTS))
1375 ###########################################################
1376 ## Commands for running host ar
1377 ###########################################################
1379 # $(1): the full path of the source static library.
1380 define _extract-and-include-single-host-whole-static-lib
1381 @echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(strip $(1))]"
1382 $(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\
1386 lib_to_include=$$ldir/$(notdir $(1)); \
1389 for f in `$($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_AR) t $(1) | \grep '\.o$$'`; do \
1390 if [ -e $$ldir/$$f ]; then \
1391 mkdir $$ldir/$$subdir; \
1393 subdir=$$((subdir+1)); \
1394 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_AR) m $$lib_to_include $$f; \
1398 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_AR) p $$lib_to_include $$f > $$ldir/$$ext$$f; \
1399 filelist="$$filelist $$ldir/$$ext$$f"; \
1401 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_ARFLAGS) \
1402 $(PRIVATE_ARFLAGS) $@ $$filelist
1406 define extract-and-include-host-whole-static-libs
1407 $(call extract-and-include-whole-static-libs-first, $(firstword $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)))
1408 $(foreach lib,$(wordlist 2,999,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)), \
1409 $(call _extract-and-include-single-host-whole-static-lib, $(lib)))
1412 # Explicitly delete the archive first so that ar doesn't
1413 # try to add to an existing archive.
1414 define transform-host-o-to-static-lib
1417 $(extract-and-include-host-whole-static-libs)
1418 @echo "host StaticLib: $(PRIVATE_MODULE) ($@)"
1419 $(call split-long-arguments,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_AR) \
1420 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_ARFLAGS) \
1421 $(PRIVATE_ARFLAGS) $@,$(PRIVATE_ALL_OBJECTS))
1425 ###########################################################
1426 ## Commands for running gcc to link a shared library or package
1427 ###########################################################
1429 # ld just seems to be so finicky with command order that we allow
1430 # it to be overriden en-masse see combo/linux-arm.make for an example.
1431 ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1432 define transform-host-o-to-shared-lib-inner
1433 $(hide) $(PRIVATE_CXX) \
1434 -Wl,-rpath-link=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_OUT_INTERMEDIATE_LIBRARIES) \
1435 -Wl,-rpath,\$$ORIGIN/../$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_OUT_SHARED_LIBRARIES)) \
1436 -Wl,-rpath,\$$ORIGIN/$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_OUT_SHARED_LIBRARIES)) \
1437 -shared -Wl,-soname,$(notdir $@) \
1438 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_LD_DIRS) \
1439 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1440 $(PRIVATE_HOST_GLOBAL_LDFLAGS) \
1442 $(PRIVATE_LDFLAGS) \
1443 $(PRIVATE_ALL_OBJECTS) \
1444 -Wl,--whole-archive \
1445 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1446 -Wl,--no-whole-archive \
1447 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
1448 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1449 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
1450 $(if $(filter true,$(NATIVE_COVERAGE)),-lgcov) \
1451 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_HOST_LIBPROFILE_RT)) \
1452 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1458 define transform-host-o-to-shared-lib
1460 @echo "host SharedLib: $(PRIVATE_MODULE) ($@)"
1461 $(transform-host-o-to-shared-lib-inner)
1464 define transform-host-o-to-package
1466 @echo "host Package: $(PRIVATE_MODULE) ($@)"
1467 $(transform-host-o-to-shared-lib-inner)
1471 ###########################################################
1472 ## Commands for running gcc to link a shared library or package
1473 ###########################################################
1475 define transform-o-to-shared-lib-inner
1476 $(hide) $(PRIVATE_CXX) \
1477 -nostdlib -Wl,-soname,$(notdir $@) \
1479 $(if $(filter true,$(PRIVATE_CLANG)),-shared,-Wl$(comma)-shared) \
1480 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
1481 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_SO_O)) \
1482 $(PRIVATE_ALL_OBJECTS) \
1483 -Wl,--whole-archive \
1484 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1485 -Wl,--no-whole-archive \
1486 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
1487 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1488 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
1489 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBGCOV)) \
1490 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBPROFILE_RT)) \
1491 $(PRIVATE_TARGET_LIBATOMIC) \
1492 $(PRIVATE_TARGET_LIBGCC) \
1493 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1495 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
1496 $(PRIVATE_LDFLAGS) \
1497 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_SO_O)) \
1501 define transform-o-to-shared-lib
1503 @echo "target SharedLib: $(PRIVATE_MODULE) ($@)"
1504 $(transform-o-to-shared-lib-inner)
1508 ###########################################################
1509 ## Commands for filtering a target executable or library
1510 ###########################################################
1512 ifneq ($(TARGET_BUILD_VARIANT),user)
1513 TARGET_STRIP_EXTRA = && $(PRIVATE_OBJCOPY) --add-gnu-debuglink=$< $@
1514 TARGET_STRIP_KEEP_SYMBOLS_EXTRA = --add-gnu-debuglink=$<
1517 define transform-to-stripped
1519 @echo "target Strip: $(PRIVATE_MODULE) ($@)"
1520 $(hide) $(PRIVATE_STRIP) --strip-all $< -o $@ \
1521 $(if $(PRIVATE_NO_DEBUGLINK),,$(TARGET_STRIP_EXTRA))
1524 define transform-to-stripped-keep-symbols
1526 @echo "target Strip (keep symbols): $(PRIVATE_MODULE) ($@)"
1527 $(hide) $(PRIVATE_OBJCOPY) \
1528 `$(PRIVATE_READELF) -S $< | awk '/.debug_/ {print "-R " $$2}' | xargs` \
1529 $(TARGET_STRIP_KEEP_SYMBOLS_EXTRA) $< $@
1532 ###########################################################
1533 ## Commands for packing a target executable or library
1534 ###########################################################
1536 define pack-elf-relocations
1537 $(copy-file-to-target)
1538 @echo "target Pack Relocations: $(PRIVATE_MODULE) ($@)"
1539 $(hide) $(RELOCATION_PACKER) $@
1542 ###########################################################
1543 ## Commands for running gcc to link an executable
1544 ###########################################################
1546 define transform-o-to-executable-inner
1547 $(hide) $(PRIVATE_CXX) -pie \
1548 -nostdlib -Bdynamic \
1549 -Wl,-dynamic-linker,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_LINKER) \
1551 -Wl,-z,nocopyreloc \
1552 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
1553 -Wl,-rpath-link=$(PRIVATE_TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1554 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O)) \
1555 $(PRIVATE_ALL_OBJECTS) \
1556 -Wl,--whole-archive \
1557 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1558 -Wl,--no-whole-archive \
1559 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
1560 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1561 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
1562 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBGCOV)) \
1563 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBPROFILE_RT)) \
1564 $(PRIVATE_TARGET_LIBATOMIC) \
1565 $(PRIVATE_TARGET_LIBGCC) \
1566 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1568 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
1569 $(PRIVATE_LDFLAGS) \
1570 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O)) \
1574 define transform-o-to-executable
1576 @echo "target Executable: $(PRIVATE_MODULE) ($@)"
1577 $(transform-o-to-executable-inner)
1581 ###########################################################
1582 ## Commands for linking a static executable. In practice,
1583 ## we only use this on arm, so the other platforms don't
1584 ## have transform-o-to-static-executable defined.
1585 ## Clang driver needs -static to create static executable.
1586 ## However, bionic/linker uses -shared to overwrite.
1587 ## Linker for x86 targets does not allow coexistance of -static and -shared,
1588 ## so we add -static only if -shared is not used.
1589 ###########################################################
1591 define transform-o-to-static-executable-inner
1592 $(hide) $(PRIVATE_CXX) \
1593 -nostdlib -Bstatic \
1594 $(if $(filter $(PRIVATE_LDFLAGS),-shared),,-static) \
1597 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
1598 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_STATIC_O)) \
1599 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
1600 $(PRIVATE_LDFLAGS) \
1601 $(PRIVATE_ALL_OBJECTS) \
1602 -Wl,--whole-archive \
1603 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1604 -Wl,--no-whole-archive \
1605 $(call normalize-target-libraries,$(filter-out %libcompiler_rt.a,$(filter-out %libc_nomalloc.a,$(filter-out %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))))) \
1607 $(call normalize-target-libraries,$(filter %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
1608 $(call normalize-target-libraries,$(filter %libc_nomalloc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
1609 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBGCOV)) \
1610 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBPROFILE_RT)) \
1611 $(PRIVATE_TARGET_LIBATOMIC) \
1612 $(call normalize-target-libraries,$(filter %libcompiler_rt.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
1613 $(PRIVATE_TARGET_LIBGCC) \
1615 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
1618 define transform-o-to-static-executable
1620 @echo "target StaticExecutable: $(PRIVATE_MODULE) ($@)"
1621 $(transform-o-to-static-executable-inner)
1625 ###########################################################
1626 ## Commands for running gcc to link a host executable
1627 ###########################################################
1628 ifdef BUILD_HOST_static
1631 HOST_FPIE_FLAGS := -pie
1632 # Force the correct entry point to workaround a bug in binutils that manifests with -pie
1633 ifeq ($(HOST_OS),windows)
1634 HOST_FPIE_FLAGS += -Wl,-e_mainCRTStartup
1638 ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1639 define transform-host-o-to-executable-inner
1640 $(hide) $(PRIVATE_CXX) \
1641 $(PRIVATE_ALL_OBJECTS) \
1642 -Wl,--whole-archive \
1643 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1644 -Wl,--no-whole-archive \
1645 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
1646 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1647 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
1648 $(if $(filter true,$(NATIVE_COVERAGE)),-lgcov) \
1649 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_HOST_LIBPROFILE_RT)) \
1650 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1651 -Wl,-rpath-link=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_OUT_INTERMEDIATE_LIBRARIES) \
1652 -Wl,-rpath,\$$ORIGIN/../$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_OUT_SHARED_LIBRARIES)) \
1653 -Wl,-rpath,\$$ORIGIN/$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_OUT_SHARED_LIBRARIES)) \
1654 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_LD_DIRS) \
1655 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1656 $(PRIVATE_HOST_GLOBAL_LDFLAGS) \
1658 $(PRIVATE_LDFLAGS) \
1664 define transform-host-o-to-executable
1666 @echo "host Executable: $(PRIVATE_MODULE) ($@)"
1667 $(transform-host-o-to-executable-inner)
1671 ###########################################################
1672 ## Commands for running javac to make .class files
1673 ###########################################################
1675 # Add BUILD_NUMBER to apps default version name if it's unbundled build.
1676 ifdef TARGET_BUILD_APPS
1677 APPS_DEFAULT_VERSION_NAME := $(PLATFORM_VERSION)-$(BUILD_NUMBER)
1679 APPS_DEFAULT_VERSION_NAME := $(PLATFORM_VERSION)
1682 # TODO: Right now we generate the asset resources twice, first as part
1683 # of generating the Java classes, then at the end when packaging the final
1684 # assets. This should be changed to do one of two things: (1) Don't generate
1685 # any resource files the first time, only create classes during that stage;
1686 # or (2) Don't use the -c flag with the second stage, instead taking the
1687 # resource files from the first stage as additional input. My original intent
1688 # was to use approach (2), but this requires a little more work in the tool.
1689 # Maybe we should just use approach (1).
1691 # This rule creates the R.java and Manifest.java files, both of which
1692 # are PRODUCT-neutral. Don't pass PRIVATE_PRODUCT_AAPT_CONFIG to this invocation.
1693 define create-resource-java-files
1694 @mkdir -p $(PRIVATE_SOURCE_INTERMEDIATES_DIR)
1695 @mkdir -p $(dir $(PRIVATE_RESOURCE_PUBLICS_OUTPUT))
1696 $(hide) $(AAPT) package $(PRIVATE_AAPT_FLAGS) -m \
1697 $(eval # PRIVATE_PRODUCT_AAPT_CONFIG is intentionally missing-- see comment.) \
1698 $(addprefix -J , $(PRIVATE_SOURCE_INTERMEDIATES_DIR)) \
1699 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
1700 $(addprefix -P , $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) \
1701 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
1702 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
1703 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
1704 $(addprefix -G , $(PRIVATE_PROGUARD_OPTIONS_FILE)) \
1705 $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
1706 $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
1707 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,--version-code $(PLATFORM_SDK_VERSION)) \
1708 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,--version-name $(APPS_DEFAULT_VERSION_NAME)) \
1709 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
1710 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \
1711 --skip-symbols-without-default-localization
1714 ifeq ($(HOST_OS),windows)
1717 xlint_unchecked := -Xlint:unchecked
1720 # emit-line, <word list>, <output file>
1722 $(if $(1),echo -n '$(strip $(1)) ' >> $(2))
1725 # dump-words-to-file, <word list>, <output file>
1726 define dump-words-to-file
1728 @$(call emit-line,$(wordlist 1,200,$(1)),$(2))
1729 @$(call emit-line,$(wordlist 201,400,$(1)),$(2))
1730 @$(call emit-line,$(wordlist 401,600,$(1)),$(2))
1731 @$(call emit-line,$(wordlist 601,800,$(1)),$(2))
1732 @$(call emit-line,$(wordlist 801,1000,$(1)),$(2))
1733 @$(call emit-line,$(wordlist 1001,1200,$(1)),$(2))
1734 @$(call emit-line,$(wordlist 1201,1400,$(1)),$(2))
1735 @$(call emit-line,$(wordlist 1401,1600,$(1)),$(2))
1736 @$(call emit-line,$(wordlist 1601,1800,$(1)),$(2))
1737 @$(call emit-line,$(wordlist 1801,2000,$(1)),$(2))
1738 @$(call emit-line,$(wordlist 2001,2200,$(1)),$(2))
1739 @$(call emit-line,$(wordlist 2201,2400,$(1)),$(2))
1740 @$(call emit-line,$(wordlist 2401,2600,$(1)),$(2))
1741 @$(call emit-line,$(wordlist 2601,2800,$(1)),$(2))
1742 @$(call emit-line,$(wordlist 2801,3000,$(1)),$(2))
1743 @$(call emit-line,$(wordlist 3001,3200,$(1)),$(2))
1744 @$(call emit-line,$(wordlist 3201,3400,$(1)),$(2))
1745 @$(call emit-line,$(wordlist 3401,3600,$(1)),$(2))
1746 @$(call emit-line,$(wordlist 3601,3800,$(1)),$(2))
1747 @$(call emit-line,$(wordlist 3801,4000,$(1)),$(2))
1748 @$(call emit-line,$(wordlist 4001,4200,$(1)),$(2))
1749 @$(call emit-line,$(wordlist 4201,4400,$(1)),$(2))
1750 @$(call emit-line,$(wordlist 4401,4600,$(1)),$(2))
1751 @$(call emit-line,$(wordlist 4601,4800,$(1)),$(2))
1752 @$(call emit-line,$(wordlist 4801,5000,$(1)),$(2))
1753 @$(if $(wordlist 5001,5002,$(1)),$(error Too many words ($(words $(1)))))
1756 # For a list of jar files, unzip them to a specified directory,
1757 # but make sure that no META-INF files come along for the ride.
1759 # $(1): files to unzip
1760 # $(2): destination directory
1761 define unzip-jar-files
1762 $(hide) for f in $(1); \
1764 if [ ! -f $$f ]; then \
1765 echo Missing file $$f; \
1768 unzip -qo $$f -d $(2); \
1770 $(if $(PRIVATE_DONT_DELETE_JAR_META_INF),,;rm -rf $(2)/META-INF)
1773 # Common definition to invoke javac on the host and target.
1775 # Some historical notes:
1776 # - below we write the list of java files to java-source-list to avoid argument
1777 # list length problems with Cygwin
1778 # - we filter out duplicate java file names because eclipse's compiler
1779 # doesn't like them.
1782 # $(2): bootclasspath
1785 $(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1786 $(hide) mkdir -p $(dir $@)
1787 $(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1788 $(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES),$(PRIVATE_CLASS_INTERMEDIATES_DIR))
1789 $(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list)
1790 $(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
1791 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list; \
1793 $(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \
1794 | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
1795 $(hide) if [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
1796 $(1) -encoding UTF-8 \
1797 $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) \
1798 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
1800 $(addprefix -classpath ,$(strip \
1801 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \
1802 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
1803 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
1804 $(PRIVATE_JAVACFLAGS) \
1805 \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \
1806 || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 ) \
1808 $(if $(PRIVATE_JAVA_LAYERS_FILE), $(hide) build/tools/java-layers.py \
1809 $(PRIVATE_JAVA_LAYERS_FILE) \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq,)
1810 $(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list
1811 $(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
1812 $(if $(PRIVATE_JAR_EXCLUDE_FILES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
1813 -name $(word 1, $(PRIVATE_JAR_EXCLUDE_FILES)) \
1814 $(addprefix -o -name , $(wordlist 2, 999, $(PRIVATE_JAR_EXCLUDE_FILES))) \
1816 $(if $(PRIVATE_JAR_PACKAGES), \
1817 $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -mindepth 1 -type f \
1818 $(foreach pkg, $(PRIVATE_JAR_PACKAGES), \
1819 -not -path $(PRIVATE_CLASS_INTERMEDIATES_DIR)/$(subst .,/,$(pkg))/\*) -delete ; \
1820 find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -empty -delete)
1821 $(if $(PRIVATE_JAR_EXCLUDE_PACKAGES), $(hide) rm -rf \
1822 $(foreach pkg, $(PRIVATE_JAR_EXCLUDE_PACKAGES), \
1823 $(PRIVATE_CLASS_INTERMEDIATES_DIR)/$(subst .,/,$(pkg))))
1824 $(if $(PRIVATE_RMTYPEDEFS), $(hide) $(RMTYPEDEFS) -v $(PRIVATE_CLASS_INTERMEDIATES_DIR))
1825 $(if $(PRIVATE_JAR_MANIFEST), \
1826 $(hide) sed -e 's/%BUILD_NUMBER%/$(BUILD_NUMBER)/' \
1827 $(PRIVATE_JAR_MANIFEST) > $(dir $@)/manifest.mf && \
1828 jar -cfm $@ $(dir $@)/manifest.mf \
1829 -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) ., \
1830 $(hide) jar -cf $@ -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .)
1831 $(if $(PRIVATE_EXTRA_JAR_ARGS),$(call add-java-resources-to,$@))
1834 define transform-java-to-classes.jar
1835 @echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
1836 $(call compile-java,$(TARGET_JAVAC),$(PRIVATE_BOOTCLASSPATH))
1839 # Invoke Jack to compile java from source to dex and jack files.
1841 # Some historical notes:
1842 # - below we write the list of java files to java-source-list to avoid argument
1843 # list length problems with Cygwin
1844 # - we filter out duplicate java file names because Jack doesn't like them.
1845 define jack-java-to-dex
1847 $(hide) rm -f $(PRIVATE_CLASSES_JACK)
1848 $(hide) rm -rf $(PRIVATE_JACK_INTERMEDIATES_DIR)
1849 $(hide) mkdir -p $(dir $@)
1850 $(hide) mkdir -p $(dir $(PRIVATE_CLASSES_JACK))
1851 $(hide) mkdir -p $(PRIVATE_JACK_INTERMEDIATES_DIR)
1852 $(if $(PRIVATE_JACK_INCREMENTAL_DIR),$(hide) mkdir -p $(PRIVATE_JACK_INCREMENTAL_DIR))
1853 $(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list)
1854 $(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
1855 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list; \
1857 $(hide) tr ' ' '\n' < $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list \
1858 | sort -u > $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq
1859 $(if $(PRIVATE_JACK_PROGUARD_FLAGS), \
1860 $(hide) echo -basedirectory $(CURDIR) > $@.flags; \
1861 echo $(PRIVATE_JACK_PROGUARD_FLAGS) >> $@.flags; \
1863 $(if $(PRIVATE_EXTRA_JAR_ARGS),
1864 $(hide) mkdir -p $@.res.tmp
1865 $(hide) $(call create-empty-package-at,$@.res.tmp.zip)
1866 $(hide) $(call add-java-resources-to,$@.res.tmp.zip)
1867 $(hide) $(call unzip-jar-files,$@.res.tmp.zip,$@.res.tmp)
1868 $(hide) rm $@.res.tmp.zip)
1869 $(hide) if [ -s $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
1870 export tmpEcjArg="@$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq"; \
1872 export tmpEcjArg=""; \
1874 $(call call-jack,$(PRIVATE_JACK_VM_ARGS),$(PRIVATE_JACK_EXTRA_ARGS)) \
1875 $(strip $(PRIVATE_JACK_FLAGS)) \
1876 $(strip $(PRIVATE_JACK_DEBUG_FLAGS)) \
1877 $(if $(NO_OPTIMIZE_DX), \
1878 -D jack.dex.optimize="false") \
1879 $(if $(PRIVATE_RMTYPEDEFS), \
1880 -D jack.android.remove-typedef="true") \
1881 $(addprefix --classpath ,$(strip \
1882 $(call normalize-path-list,$(PRIVATE_BOOTCLASSPATH_JAVA_LIBRARIES) $(PRIVATE_ALL_JACK_LIBRARIES)))) \
1883 $(addprefix --import ,$(call reverse-list,$(PRIVATE_STATIC_JACK_LIBRARIES))) \
1884 $(if $(PRIVATE_EXTRA_JAR_ARGS),--import-resource $@.res.tmp) \
1885 -D jack.import.resource.policy=keep-first \
1886 -D jack.import.type.policy=keep-first \
1887 --output-jack $(PRIVATE_CLASSES_JACK) \
1888 -D jack.java.source.version=1.7 \
1889 $(if $(PRIVATE_JACK_INCREMENTAL_DIR),--incremental-folder $(PRIVATE_JACK_INCREMENTAL_DIR)) \
1890 --output-dex $(PRIVATE_JACK_INTERMEDIATES_DIR) \
1891 $(addprefix --config-jarjar ,$(strip $(PRIVATE_JARJAR_RULES))) \
1892 $(if $(PRIVATE_JACK_PROGUARD_FLAGS),--config-proguard $@.flags) \
1894 || ( rm -rf $(PRIVATE_CLASSES_JACK); rm -rf $(PRIVATE_JACK_INTERMEDIATES_DIR); exit 41 )
1895 $(hide) mv $(PRIVATE_JACK_INTERMEDIATES_DIR)/classes*.dex $(dir $@)
1896 $(hide) rm -f $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list
1897 $(if $(PRIVATE_EXTRA_JAR_ARGS),$(hide) rm -rf $@.res.tmp)
1898 $(hide) mv $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq $(PRIVATE_JACK_INTERMEDIATES_DIR).java-source-list
1899 $(if $(PRIVATE_JAR_PACKAGES), $(hide) echo unsupported options PRIVATE_JAR_PACKAGES in $@; exit 53)
1900 $(if $(PRIVATE_JAR_EXCLUDE_PACKAGES), $(hide) echo unsupported options JAR_EXCLUDE_PACKAGES in $@; exit 53)
1901 $(if $(PRIVATE_JAR_MANIFEST), $(hide) echo unsupported options JAR_MANIFEST in $@; exit 53)
1904 define transform-jar-to-jack
1905 $(hide) mkdir -p $(dir $@)
1906 $(JILL) $(PRIVATE_JILL_FLAGS) --output $@.tmpjill.jack $<
1907 $(hide) mkdir -p $@.tmpjill.res
1908 $(hide) $(call unzip-jar-files,$<,$@.tmpjill.res)
1909 $(hide) find $@.tmpjill.res -iname "*.class" -delete
1910 $(hide) $(call call-jack,$(PRIVATE_JACK_VM_ARGS),$(PRIVATE_JACK_EXTRA_ARGS)) \
1911 -D jack.import.resource.policy=keep-first \
1912 -D jack.import.type.policy=keep-first \
1913 --import $@.tmpjill.jack \
1914 --import-resource $@.tmpjill.res \
1916 $(hide) rm -rf $@.tmpjill.res
1917 $(hide) rm $@.tmpjill.jack
1921 # Invoke Jack to compile java from source to jack files without shrink or obfuscation.
1923 # Some historical notes:
1924 # - below we write the list of java files to java-source-list to avoid argument
1925 # list length problems with Cygwin
1926 # - we filter out duplicate java file names because Jack doesn't like them.
1929 $(hide) rm -rf $(PRIVATE_JACK_INTERMEDIATES_DIR)
1930 $(hide) mkdir -p $(dir $@)
1931 $(hide) mkdir -p $(PRIVATE_JACK_INTERMEDIATES_DIR)
1932 $(if $(PRIVATE_JACK_INCREMENTAL_DIR),$(hide) mkdir -p $(PRIVATE_JACK_INCREMENTAL_DIR))
1933 $(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list)
1934 $(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
1935 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list; \
1937 $(hide) tr ' ' '\n' < $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list \
1938 | sort -u > $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq
1939 $(if $(PRIVATE_JACK_PROGUARD_FLAGS), \
1940 $(hide) echo -basedirectory $(CURDIR) > $@.flags; \
1941 echo $(PRIVATE_JACK_PROGUARD_FLAGS) >> $@.flags; \
1943 $(if $(PRIVATE_EXTRA_JAR_ARGS),
1944 $(hide) mkdir -p $@.res.tmp
1945 $(hide) $(call create-empty-package-at,$@.res.tmp.zip)
1946 $(hide) $(call add-java-resources-to,$@.res.tmp.zip)
1947 $(hide) unzip -qo $@.res.tmp.zip -d $@.res.tmp
1948 $(hide) rm $@.res.tmp.zip)
1949 $(hide) if [ -s $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
1950 export tmpEcjArg="@$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq"; \
1952 export tmpEcjArg=""; \
1954 $(call call-jack,$(PRIVATE_JACK_VM_ARGS),$(PRIVATE_JACK_EXTRA_ARGS)) \
1955 $(strip $(PRIVATE_JACK_FLAGS)) \
1956 $(strip $(PRIVATE_JACK_DEBUG_FLAGS)) \
1957 $(if $(NO_OPTIMIZE_DX), \
1958 -D jack.dex.optimize="false") \
1959 $(addprefix --classpath ,$(strip \
1960 $(call normalize-path-list,$(PRIVATE_BOOTCLASSPATH_JAVA_LIBRARIES) $(PRIVATE_ALL_JACK_LIBRARIES)))) \
1961 $(addprefix --import ,$(call reverse-list,$(PRIVATE_STATIC_JACK_LIBRARIES))) \
1962 $(if $(PRIVATE_EXTRA_JAR_ARGS),--import-resource $@.res.tmp) \
1963 -D jack.import.resource.policy=keep-first \
1964 -D jack.import.type.policy=keep-first \
1965 -D jack.java.source.version=1.7 \
1966 $(if $(PRIVATE_JACK_INCREMENTAL_DIR),--incremental-folder $(PRIVATE_JACK_INCREMENTAL_DIR)) \
1968 $(addprefix --config-jarjar ,$(strip $(PRIVATE_JARJAR_RULES))) \
1969 $(if $(PRIVATE_JACK_PROGUARD_FLAGS),--config-proguard $@.flags) \
1971 || ( rm -f $@ ; exit 41 )
1972 $(hide) rm -f $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list
1973 $(if $(PRIVATE_EXTRA_JAR_ARGS),$(hide) rm -rf $@.res.tmp)
1974 $(hide) mv $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq $(PRIVATE_JACK_INTERMEDIATES_DIR).java-source-list
1975 $(if $(PRIVATE_JAR_PACKAGES), $(hide) echo unsupported options PRIVATE_JAR_PACKAGES in $@; exit 53)
1976 $(if $(PRIVATE_JAR_EXCLUDE_PACKAGES), $(hide) echo unsupported options JAR_EXCLUDE_PACKAGES in $@; exit 53)
1977 $(if $(PRIVATE_JAR_MANIFEST), $(hide) echo unsupported options JAR_MANIFEST in $@; exit 53)
1980 define transform-classes.jar-to-emma
1981 $(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \
1982 $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR) \
1983 $(addprefix -ix , $(PRIVATE_EMMA_COVERAGE_FILTER))
1986 #TODO: use a smaller -Xmx value for most libraries;
1987 # only core.jar and framework.jar need a heap this big.
1988 # Avoid the memory arguments on Windows, dx fails to load for some reason with them.
1989 define transform-classes.jar-to-dex
1990 @echo "target Dex: $(PRIVATE_MODULE)"
1992 $(hide) rm -f $(dir $@)classes*.dex
1994 $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx2048M) \
1995 --dex --output=$(dir $@) \
1996 $(if $(NO_OPTIMIZE_DX), \
1998 $(if $(GENERATE_DEX_DEBUG), \
2000 --dump-to=$(@:.dex=.lst) \
2001 --dump-width=1000) \
2002 $(PRIVATE_DX_FLAGS) \
2006 # Create a mostly-empty .jar file that we'll add to later.
2007 # The MacOS jar tool doesn't like creating empty jar files,
2008 # so we need to give it something.
2009 # $(1) package to create
2010 define create-empty-package-at
2011 @mkdir -p $(dir $(1))
2012 $(hide) touch $(dir $(1))zipdummy
2013 $(hide) (cd $(dir $(1)) && jar cf $(notdir $(1)) zipdummy)
2014 $(hide) zip -qd $(1) zipdummy
2015 $(hide) rm $(dir $(1))zipdummy
2018 # Create a mostly-empty .jar file that we'll add to later.
2019 # The MacOS jar tool doesn't like creating empty jar files,
2020 # so we need to give it something.
2021 define create-empty-package
2022 $(call create-empty-package-at,$@)
2025 # Copy an arhchive file and delete any class files and empty folders inside.
2026 # $(1): the source archive file.
2027 # $(2): the destination archive file.
2028 define initialize-package-file
2029 @mkdir -p $(dir $(2))
2030 $(hide) cp -f $(1) $(2)
2031 $(hide) zip -qd $(2) "*.class" \
2032 $(if $(strip $(PRIVATE_DONT_DELETE_JAR_DIRS)),,"*/") \
2033 || true # Ignore the error when nothing to delete.
2036 #TODO: we kinda want to build different asset packages for
2037 # different configurations, then combine them later (or something).
2039 # A list of dynamic and static parameters; build layers for
2040 # dynamic params that lay over the static ones.
2041 #TODO: update the manifest to point to the package file
2042 #Note that the version numbers are given to aapt as simple default
2043 #values; applications can override these by explicitly stating
2044 #them in their manifest.
2045 define add-assets-to-package
2046 $(hide) $(AAPT) package -u $(PRIVATE_AAPT_FLAGS) \
2047 $(addprefix -c , $(PRIVATE_PRODUCT_AAPT_CONFIG)) \
2048 $(addprefix --preferred-density , $(PRIVATE_PRODUCT_AAPT_PREF_CONFIG)) \
2049 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
2050 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
2051 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
2052 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
2053 $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
2054 $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
2055 $(if $(filter --product,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --product , $(TARGET_AAPT_CHARACTERISTICS))) \
2056 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,--version-code $(PLATFORM_SDK_VERSION)) \
2057 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,--version-name $(APPS_DEFAULT_VERSION_NAME)) \
2058 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
2059 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \
2060 --skip-symbols-without-default-localization \
2064 # We need the extra blank line, so that the command will be on a separate line.
2065 # $(1): the ABI name
2066 # $(2): the list of shared libraies
2067 define _add-jni-shared-libs-to-package-per-abi
2068 $(hide) cp $(2) $(dir $@)lib/$(1)
2072 # For apps_only build, don't uncompress/page-align the jni libraries,
2073 # because the apk may be run on older platforms that don't support loading jni directly from apk.
2074 ifdef TARGET_BUILD_APPS
2075 JNI_COMPRESS_FLAGS :=
2076 ZIPALIGN_PAGE_ALIGN_FLAGS :=
2078 JNI_COMPRESS_FLAGS := -0
2079 ZIPALIGN_PAGE_ALIGN_FLAGS := -p
2082 define add-jni-shared-libs-to-package
2083 $(hide) rm -rf $(dir $@)lib
2084 $(hide) mkdir -p $(addprefix $(dir $@)lib/,$(PRIVATE_JNI_SHARED_LIBRARIES_ABI))
2085 $(foreach abi,$(PRIVATE_JNI_SHARED_LIBRARIES_ABI),\
2086 $(call _add-jni-shared-libs-to-package-per-abi,$(abi),\
2087 $(patsubst $(abi):%,%,$(filter $(abi):%,$(PRIVATE_JNI_SHARED_LIBRARIES)))))
2088 $(hide) (cd $(dir $@) && zip -r $(JNI_COMPRESS_FLAGS) $(notdir $@) lib)
2089 $(hide) rm -rf $(dir $@)lib
2092 #TODO: update the manifest to point to the dex file
2093 define add-dex-to-package
2094 $(hide) zip -qj $@ $(dir $(PRIVATE_DEX_FILE))classes*.dex
2097 # Add java resources added by the current module.
2098 # $(1) destination package
2100 define add-java-resources-to
2101 $(call dump-words-to-file, $(PRIVATE_EXTRA_JAR_ARGS), $(1).jar-arg-list)
2102 $(hide) jar uf $(1) @$(1).jar-arg-list
2103 @rm -f $(1).jar-arg-list
2106 # Add resources carried by static Jack libraries.
2108 define add-carried-jack-resources
2109 $(hide) if [ -d $(PRIVATE_JACK_INTERMEDIATES_DIR) ] ; then \
2110 jack_res_jar_flags=$$(find $(PRIVATE_JACK_INTERMEDIATES_DIR) -type f \
2111 | sed -e "s?^$(PRIVATE_JACK_INTERMEDIATES_DIR)/? -C $(PRIVATE_JACK_INTERMEDIATES_DIR) ?"); \
2112 if [ -n "$$jack_res_jar_flags" ] ; then \
2113 echo $$jack_res_jar_flags >$(dir $@)jack_res_jar_flags; \
2114 jar uf $@ $$jack_res_jar_flags; \
2119 # Sign a package using the specified key/cert.
2122 $(hide) mv $@ $@.unsigned
2123 $(hide) java -jar $(SIGNAPK_JAR) \
2124 $(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) \
2125 $(PRIVATE_ADDITIONAL_CERTIFICATES) $@.unsigned $@.signed
2126 $(hide) mv $@.signed $@
2129 # Align STORED entries of a package on 4-byte boundaries to make them easier to mmap.
2131 define align-package
2132 $(hide) mv $@ $@.unaligned
2133 $(hide) $(ZIPALIGN) \
2135 $(ZIPALIGN_PAGE_ALIGN_FLAGS) \
2137 $@.unaligned $@.aligned
2138 $(hide) mv $@.aligned $@
2141 # Uncompress shared libraries embedded in an apk.
2143 define uncompress-shared-libs
2144 $(hide) if unzip -l $@ $(PRIVATE_EMBEDDED_JNI_LIBS) >/dev/null ; then \
2145 rm -rf $(dir $@)uncompressedlibs && mkdir $(dir $@)uncompressedlibs; \
2146 unzip $@ $(PRIVATE_EMBEDDED_JNI_LIBS) -d $(dir $@)uncompressedlibs && \
2147 zip -d $@ 'lib/*.so' && \
2148 ( cd $(dir $@)uncompressedlibs && zip -D -r -0 ../$(notdir $@) lib ) && \
2149 rm -rf $(dir $@)uncompressedlibs; \
2153 define install-dex-debug
2154 $(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.dex" ]; then \
2155 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
2156 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.dex \
2157 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).dex; \
2159 $(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.lst" ]; then \
2160 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
2161 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.lst \
2162 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).lst; \
2166 # TODO(joeo): If we can ever upgrade to post 3.81 make and get the
2167 # new prebuilt rules to work, we should change this to copy the
2168 # resources to the out directory and then copy the resources.
2170 # Note: we intentionally don't clean PRIVATE_CLASS_INTERMEDIATES_DIR
2171 # in transform-java-to-classes for the sake of vm-tests.
2172 define transform-host-java-to-package
2173 @echo "host Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
2174 $(call compile-java,$(HOST_JAVAC),$(PRIVATE_BOOTCLASSPATH))
2177 ###########################################################
2178 ## Commands for copying files
2179 ###########################################################
2181 # Define a rule to copy a header. Used via $(eval) by copy_headers.make.
2182 # $(1): source header
2183 # $(2): destination header
2184 define copy-one-header
2187 $$(copy-file-to-new-target-with-cp)
2190 # Define a rule to copy a file. For use via $(eval).
2192 # $(2): destination file
2193 define copy-one-file
2196 $$(copy-file-to-target)
2199 # Copies many files.
2200 # $(1): The files to copy. Each entry is a ':' separated src:dst pair
2201 # Evaluates to the list of the dst files (ie suitable for a dependency list)
2202 define copy-many-files
2203 $(foreach f, $(1), $(strip \
2204 $(eval _cmf_tuple := $(subst :, ,$(f))) \
2205 $(eval _cmf_src := $(word 1,$(_cmf_tuple))) \
2206 $(eval _cmf_dest := $(word 2,$(_cmf_tuple))) \
2207 $(eval $(call copy-one-file,$(_cmf_src),$(_cmf_dest))) \
2211 # Copy the file only if it's a well-formed xml file. For use via $(eval).
2213 # $(2): destination file, must end with .xml.
2214 define copy-xml-file-checked
2216 @echo "Copy xml: $$@"
2217 $(hide) xmllint $$< >/dev/null # Don't print the xml file to stdout.
2218 $$(copy-file-to-target)
2221 # The -t option to acp and the -p option to cp is
2222 # required for OSX. OSX has a ridiculous restriction
2223 # where it's an error for a .a file's modification time
2224 # to disagree with an internal timestamp, and this
2225 # macro is used to install .a files (among other things).
2227 # Copy a single file from one place to another,
2228 # preserving permissions and overwriting any existing
2230 # We disable the "-t" option for acp cannot handle
2231 # high resolution timestamp correctly on file systems like ext4.
2232 # Therefore copy-file-to-target is the same as copy-file-to-new-target.
2233 define copy-file-to-target
2235 $(hide) $(ACP) -fp $< $@
2238 # The same as copy-file-to-target, but use the local
2239 # cp command instead of acp.
2240 define copy-file-to-target-with-cp
2242 $(hide) cp -fp $< $@
2245 # The same as copy-file-to-target, but use the zipalign tool to do so.
2246 define copy-file-to-target-with-zipalign
2248 $(hide) $(ZIPALIGN) -f 4 $< $@
2251 # The same as copy-file-to-target, but strip out "# comment"-style
2252 # comments (for config files and such).
2253 define copy-file-to-target-strip-comments
2255 $(hide) sed -e 's/#.*$$//' -e 's/[ \t]*$$//' -e '/^$$/d' < $< > $@
2258 # The same as copy-file-to-target, but don't preserve
2259 # the old modification time.
2260 define copy-file-to-new-target
2262 $(hide) $(ACP) -fp $< $@
2265 # The same as copy-file-to-new-target, but use the local
2266 # cp command instead of acp.
2267 define copy-file-to-new-target-with-cp
2272 # Copy a prebuilt file to a target location.
2273 define transform-prebuilt-to-target
2274 @echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"
2275 $(copy-file-to-target)
2278 # Copy a prebuilt file to a target location, using zipalign on it.
2279 define transform-prebuilt-to-target-with-zipalign
2280 @echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt APK: $(PRIVATE_MODULE) ($@)"
2281 $(copy-file-to-target-with-zipalign)
2284 # Copy a prebuilt file to a target location, stripping "# comment" comments.
2285 define transform-prebuilt-to-target-strip-comments
2286 @echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"
2287 $(copy-file-to-target-strip-comments)
2290 # Copy a list of files/directories to target location, with sub dir structure preserved.
2291 # For example $(HOST_OUT_EXECUTABLES)/aapt -> $(staging)/bin/aapt .
2292 # $(1): the source list of files/directories.
2293 # $(2): the path prefix to strip. In the above example it would be $(HOST_OUT).
2294 # $(3): the target location.
2295 define copy-files-with-structure
2297 $(eval s := $(patsubst $(2)%,%,$(t)))\
2298 $(hide) mkdir -p $(dir $(3)/$(s)); cp -Rf $(t) $(3)/$(s)$(newline))
2302 ###########################################################
2303 ## Commands to call Proguard
2304 ###########################################################
2305 define transform-jar-to-proguard
2307 $(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS) \
2308 $(addprefix -injars , $(PRIVATE_EXTRA_INPUT_JAR))
2311 ###########################################################
2312 ## Stuff source generated from one-off tools
2313 ###########################################################
2315 define transform-generated-source
2316 @echo "target Generated: $(PRIVATE_MODULE) <= $<"
2318 $(hide) $(PRIVATE_CUSTOM_TOOL)
2322 ###########################################################
2323 ## Assertions about attributes of the target
2324 ###########################################################
2326 # $(1): The file to check
2327 ifndef get-file-size
2328 $(error HOST_OS must define get-file-size)
2331 # Convert a partition data size (eg, as reported in /proc/mtd) to the
2332 # size of the image used to flash that partition (which includes a
2333 # spare area for each page).
2334 # $(1): the partition data size
2335 define image-size-from-data-size
2336 $(strip $(eval _isfds_value := $$(shell echo $$$$(($(1) / $(BOARD_NAND_PAGE_SIZE) * \
2337 ($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE))))))\
2338 $(if $(filter 0, $(_isfds_value)),$(shell echo $$(($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE)))),$(_isfds_value))\
2339 $(eval _isfds_value :=))
2342 # $(1): The file(s) to check (often $@)
2343 # $(2): The maximum total image size, in decimal bytes.
2344 # Make sure to take into account any reserved space needed for the FS.
2346 # If $(2) is empty, evaluates to "true"
2348 # Reserve bad blocks. Make sure that MAX(1% of partition size, 2 blocks)
2349 # is left over after the image has been flashed. Round the 1% up to the
2350 # next whole flash block size.
2351 define assert-max-file-size
2353 size=$$(for i in $(1); do $(call get-file-size,$$i); echo +; done; echo 0); \
2354 total=$$(( $$( echo "$$size" ) )); \
2355 printname=$$(echo -n "$(1)" | tr " " +); \
2356 img_blocksize=$(call image-size-from-data-size,$(BOARD_FLASH_BLOCK_SIZE)); \
2357 twoblocks=$$((img_blocksize * 2)); \
2358 onepct=$$((((($(2) / 100) - 1) / img_blocksize + 1) * img_blocksize)); \
2359 reserve=$$((twoblocks > onepct ? twoblocks : onepct)); \
2360 maxsize=$$(($(2) - reserve)); \
2361 echo "$$printname maxsize=$$maxsize blocksize=$$img_blocksize total=$$total reserve=$$reserve"; \
2362 if [ "$$total" -gt "$$maxsize" ]; then \
2363 echo "error: $$printname too large ($$total > [$(2) - $$reserve])"; \
2365 elif [ "$$total" -gt $$((maxsize - 32768)) ]; then \
2366 echo "WARNING: $$printname approaching size limit ($$total now; limit $$maxsize)"; \
2373 # Like assert-max-file-size, but the second argument is a partition
2374 # size, which we'll convert to a max image size before checking it
2375 # against the files.
2377 # $(1): The file(s) to check (often $@)
2378 # $(2): The partition size.
2379 define assert-max-image-size
2381 $(call assert-max-file-size,$(1),$(call image-size-from-data-size,$(2))))
2385 ###########################################################
2386 ## Define device-specific radio files
2387 ###########################################################
2388 INSTALLED_RADIOIMAGE_TARGET :=
2390 # Copy a radio image file to the output location, and add it to
2391 # INSTALLED_RADIOIMAGE_TARGET.
2393 define add-radio-file
2394 $(eval $(call add-radio-file-internal,$(1),$(notdir $(1))))
2396 define add-radio-file-internal
2397 INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
2398 $$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP)
2399 $$(transform-prebuilt-to-target)
2402 # Version of add-radio-file that also arranges for the version of the
2403 # file to be checked against the contents of
2404 # $(TARGET_BOARD_INFO_FILE).
2406 # $(2): name of version variable in board-info (eg, "version-baseband")
2407 define add-radio-file-checked
2408 $(eval $(call add-radio-file-checked-internal,$(1),$(notdir $(1)),$(2)))
2410 define add-radio-file-checked-internal
2411 INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
2412 BOARD_INFO_CHECK += $(3):$(LOCAL_PATH)/$(1)
2413 $$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP)
2414 $$(transform-prebuilt-to-target)
2418 ###########################################################
2419 # Override the package defined in $(1), setting the
2420 # variables listed below differently.
2422 # $(1): The makefile to override (relative to the source
2424 # $(2): Old LOCAL_PACKAGE_NAME value.
2425 # $(3): New LOCAL_PACKAGE_NAME value.
2426 # $(4): New LOCAL_MANIFEST_PACKAGE_NAME value.
2427 # $(5): New LOCAL_CERTIFICATE value.
2428 # $(6): New LOCAL_INSTRUMENTATION_FOR value.
2429 # $(7): New LOCAL_MANIFEST_INSTRUMENTATION_FOR value.
2431 # Note that LOCAL_PACKAGE_OVERRIDES is NOT cleared in
2433 ###########################################################
2434 define inherit-package
2435 $(eval $(call inherit-package-internal,$(1),$(2),$(3),$(4),$(5),$(6),$(7)))
2438 define inherit-package-internal
2439 LOCAL_PACKAGE_OVERRIDES \
2440 := $(strip $(1))||$(strip $(2))||$(strip $(3))||$(strip $(4))||&&$(strip $(5))||&&$(strip $(6))||&&$(strip $(7)) $(LOCAL_PACKAGE_OVERRIDES)
2442 LOCAL_PACKAGE_OVERRIDES \
2443 := $(wordlist 1,$(words $(LOCAL_PACKAGE_OVERRIDES)), $(LOCAL_PACKAGE_OVERRIDES))
2446 # To be used with inherit-package above
2447 # Evalutes to true if the package was overridden
2448 define set-inherited-package-variables
2449 $(strip $(call set-inherited-package-variables-internal))
2452 define keep-or-override
2453 $(eval $(1) := $(if $(2),$(2),$($(1))))
2456 define set-inherited-package-variables-internal
2457 $(eval _o := $(subst ||, ,$(lastword $(LOCAL_PACKAGE_OVERRIDES))))
2458 $(eval _n := $(subst ||, ,$(firstword $(LOCAL_PACKAGE_OVERRIDES))))
2459 $(if $(filter $(word 2,$(_n)),$(LOCAL_PACKAGE_NAME)), \
2460 $(eval LOCAL_PACKAGE_NAME := $(word 3,$(_o))) \
2461 $(eval LOCAL_MANIFEST_PACKAGE_NAME := $(word 4,$(_o))) \
2462 $(call keep-or-override,LOCAL_CERTIFICATE,$(patsubst &&%,%,$(word 5,$(_o)))) \
2463 $(call keep-or-override,LOCAL_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 6,$(_o)))) \
2464 $(call keep-or-override,LOCAL_MANIFEST_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 7,$(_o)))) \
2465 $(eval LOCAL_OVERRIDES_PACKAGES := $(sort $(LOCAL_OVERRIDES_PACKAGES) $(word 2,$(_o)))) \
2470 ###########################################################
2472 ###########################################################
2474 # eval this to define a rule that runs apicheck.
2478 # $(2) stable api file
2479 # $(3) api file to be tested
2480 # $(4) stable removed api file
2481 # $(5) removed api file to be tested
2482 # $(6) arguments for apicheck
2483 # $(7) command to run if apicheck failed
2484 # $(8) target dependent on this api check
2485 # $(9) additional dependencies
2487 $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(strip $(1))-timestamp: $(2) $(3) $(4) $(APICHECK) $(9)
2488 @echo "Checking API:" $(1)
2489 $(hide) ( $(APICHECK_COMMAND) $(6) $(2) $(3) $(4) $(5) || ( $(7) ; exit 38 ) )
2490 $(hide) mkdir -p $$(dir $$@)
2492 $(8): $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(strip $(1))-timestamp
2495 ## Whether to build from source if prebuilt alternative exists
2496 ###########################################################
2499 # Expands to empty string if not from source.
2500 ifeq (true,$(ANDROID_BUILD_FROM_SOURCE))
2501 define if-build-from-source
2505 define if-build-from-source
2506 $(if $(filter $(ANDROID_NO_PREBUILT_MODULES),$(1))$(filter \
2507 $(addsuffix %,$(ANDROID_NO_PREBUILT_PATHS)),$(2)),true)
2511 # Include makefile $(1) if build from source for module $(2)
2512 # $(1): the makefile to include
2515 define include-if-build-from-source
2516 $(if $(call if-build-from-source,$(2),$(3)),$(eval include $(1)))
2519 # Return the arch for the source file of a prebuilt
2520 # Return "none" if no matching arch found, so the result can be passed to
2521 # LOCAL_MODULE_TARGET_ARCH.
2522 # $(1) the list of archs supported by the prebuilt
2523 define get-prebuilt-src-arch
2524 $(strip $(if $(filter $(TARGET_ARCH),$(1)),$(TARGET_ARCH),\
2525 $(if $(filter $(TARGET_2ND_ARCH),$(1)),$(TARGET_2ND_ARCH),none)))
2528 ###########################################################
2530 ###########################################################
2532 # -----------------------------------------------------------------
2533 # Rules and functions to help copy important files to DIST_DIR
2535 include $(BUILD_SYSTEM)/distdir.mk
2537 # Include any vendor specific definitions.mk file
2538 -include $(TOPDIR)vendor/*/build/core/definitions.mk
2539 -include $(TOPDIR)device/*/build/core/definitions.mk
2542 # $(foreach file,$^,$(if $(findstring,.a,$(suffix $file)),-l$(file),$(file)))
2544 ###########################################################
2546 ###########################################################
2549 #df = $(DEPDIR)/$(*F)
2551 #SRCS = foo.c bar.c ...
2555 # cp $(df).d $(df).P; \
2556 # sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
2557 # -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \
2559 # $(COMPILE.c) -o $@ $<
2561 #-include $(SRCS:%.c=$(DEPDIR)/%.P)
2565 # $(COMPILE.c) -MD -o $@ $<
2567 # sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
2568 # -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \