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/prelinked.
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 ###########################################################
82 ## Debugging; prints a variable list to stdout
83 ###########################################################
85 # $(1): variable name list, not variable values
89 $(foreach word,$($(var)), \
90 $(info $(space)$(space)$(word)) \
95 ###########################################################
96 ## Evaluates to true if the string contains the word true,
97 ## and empty otherwise
98 ## $(1): a var to test
99 ###########################################################
106 ###########################################################
107 ## Retrieve the directory of the current makefile
108 ###########################################################
110 # Figure out where we are.
113 $(eval md_file_ := $$(lastword $$(MAKEFILE_LIST))) \
114 $(if $(filter $(CLEAR_VARS),$(md_file_)), \
115 $(error LOCAL_PATH must be set before including $$(CLEAR_VARS)) \
117 $(patsubst %/,%,$(dir $(md_file_))) \
122 ###########################################################
123 ## Retrieve a list of all makefiles immediately below some directory
124 ###########################################################
126 define all-makefiles-under
127 $(wildcard $(1)/*/Android.mk)
130 ###########################################################
131 ## Look under a directory for makefiles that don't have parent
133 ###########################################################
135 # $(1): directory to search under
136 # Ignores $(1)/Android.mk
137 define first-makefiles-under
138 $(shell build/tools/findleaves.py --prune=out --prune=.repo --prune=.git \
139 --mindepth=2 $(1) Android.mk)
142 ###########################################################
143 ## Retrieve a list of all makefiles immediately below your directory
144 ###########################################################
146 define all-subdir-makefiles
147 $(call all-makefiles-under,$(call my-dir))
150 ###########################################################
151 ## Look in the named list of directories for makefiles,
152 ## relative to the current directory.
153 ###########################################################
155 # $(1): List of directories to look for under this directory
156 define all-named-subdir-makefiles
157 $(wildcard $(addsuffix /Android.mk, $(addprefix $(my-dir)/,$(1))))
160 ###########################################################
161 ## Find all of the java files under the named directories.
162 ## Meant to be used like:
163 ## SRC_FILES := $(call all-java-files-under,src tests)
164 ###########################################################
166 define all-java-files-under
168 $(shell cd $(LOCAL_PATH) ; \
169 find $(1) -name "*.java" -and -not -name ".*") \
173 ###########################################################
174 ## Find all of the java files from here. Meant to be used like:
175 ## SRC_FILES := $(call all-subdir-java-files)
176 ###########################################################
178 define all-subdir-java-files
179 $(call all-java-files-under,.)
182 ###########################################################
183 ## Find all of the c files under the named directories.
184 ## Meant to be used like:
185 ## SRC_FILES := $(call all-c-files-under,src tests)
186 ###########################################################
188 define all-c-files-under
190 $(shell cd $(LOCAL_PATH) ; \
191 find $(1) -name "*.c" -and -not -name ".*") \
195 ###########################################################
196 ## Find all of the c files from here. Meant to be used like:
197 ## SRC_FILES := $(call all-subdir-c-files)
198 ###########################################################
200 define all-subdir-c-files
201 $(call all-c-files-under,.)
204 ###########################################################
205 ## Find all files named "I*.aidl" under the named directories,
206 ## which must be relative to $(LOCAL_PATH). The returned list
207 ## is relative to $(LOCAL_PATH).
208 ###########################################################
210 define all-Iaidl-files-under
212 $(shell cd $(LOCAL_PATH) ; \
213 find $(1) -name "I*.aidl" -and -not -name ".*") \
217 ###########################################################
218 ## Find all of the "I*.aidl" files under $(LOCAL_PATH).
219 ###########################################################
221 define all-subdir-Iaidl-files
222 $(call all-Iaidl-files-under,.)
225 ###########################################################
226 ## Find all of the logtags files under the named directories.
227 ## Meant to be used like:
228 ## SRC_FILES := $(call all-logtags-files-under,src)
229 ###########################################################
231 define all-logtags-files-under
233 $(shell cd $(LOCAL_PATH) ; \
234 find $(1) -name "*.logtags" -and -not -name ".*") \
238 ###########################################################
239 ## Find all of the html files under the named directories.
240 ## Meant to be used like:
241 ## SRC_FILES := $(call all-html-files-under,src tests)
242 ###########################################################
244 define all-html-files-under
246 $(shell cd $(LOCAL_PATH) ; \
247 find $(1) -name "*.html" -and -not -name ".*") \
251 ###########################################################
252 ## Find all of the html files from here. Meant to be used like:
253 ## SRC_FILES := $(call all-subdir-html-files)
254 ###########################################################
256 define all-subdir-html-files
257 $(call all-html-files-under,.)
260 ###########################################################
261 ## Find all of the files matching pattern
262 ## SRC_FILES := $(call find-subdir-files, <pattern>)
263 ###########################################################
265 define find-subdir-files
266 $(patsubst ./%,%,$(shell cd $(LOCAL_PATH) ; find $(1)))
269 ###########################################################
270 # find the files in the subdirectory $1 of LOCAL_DIR
271 # matching pattern $2, filtering out files $3
273 # SRC_FILES += $(call find-subdir-subdir-files, \
274 # css, *.cpp, DontWantThis.cpp)
275 ###########################################################
277 define find-subdir-subdir-files
278 $(filter-out $(patsubst %,$(1)/%,$(3)),$(patsubst ./%,%,$(shell cd \
279 $(LOCAL_PATH) ; find $(1) -maxdepth 1 -name $(2))))
282 ###########################################################
283 ## Find all of the files matching pattern
284 ## SRC_FILES := $(call all-subdir-java-files)
285 ###########################################################
287 define find-subdir-assets
288 $(if $(1),$(patsubst ./%,%, \
289 $(shell if [ -d $(1) ] ; then cd $(1) ; find ./ -type f -and -not -type l ; fi)), \
290 $(warning Empty argument supplied to find-subdir-assets) \
294 ###########################################################
295 ## Find various file types in a list of directories relative to $(LOCAL_PATH)
296 ###########################################################
298 define find-other-java-files
299 $(call find-subdir-files,$(1) -name "*.java" -and -not -name ".*")
302 define find-other-html-files
303 $(call find-subdir-files,$(1) -name "*.html" -and -not -name ".*")
306 ###########################################################
307 ## Scan through each directory of $(1) looking for files
308 ## that match $(2) using $(wildcard). Useful for seeing if
309 ## a given directory or one of its parents contains
310 ## a particular file. Returns the first match found,
311 ## starting furthest from the root.
312 ###########################################################
314 define find-parent-file
316 $(eval _fpf := $(wildcard $(strip $(1))/$(strip $(2)))) \
317 $(if $(_fpf),$(_fpf), \
318 $(if $(filter-out ./ .,$(1)), \
319 $(call find-parent-file,$(patsubst %/,%,$(dir $(1))),$(2)) \
325 ###########################################################
326 ## Function we can evaluate to introduce a dynamic dependency
327 ###########################################################
329 define add-dependency
333 ###########################################################
334 ## Set up the dependencies for a prebuilt target
335 ## $(call add-prebuilt-file, srcfile, [targetclass])
336 ###########################################################
338 define add-prebuilt-file
339 $(eval $(include-prebuilt))
342 define include-prebuilt
343 include $$(CLEAR_VARS)
344 LOCAL_SRC_FILES := $(1)
345 LOCAL_BUILT_MODULE_STEM := $(1)
346 LOCAL_MODULE_SUFFIX := $$(suffix $(1))
347 LOCAL_MODULE := $$(basename $(1))
348 LOCAL_MODULE_CLASS := $(2)
349 include $$(BUILD_PREBUILT)
352 ###########################################################
353 ## do multiple prebuilts
354 ## $(call target class, files ...)
355 ###########################################################
357 define add-prebuilt-files
358 $(foreach f,$(2),$(call add-prebuilt-file,$f,$(1)))
363 ###########################################################
364 ## The intermediates directory. Where object files go for
365 ## a given target. We could technically get away without
366 ## the "_intermediates" suffix on the directory, but it's
367 ## nice to be able to grep for that string to find out if
368 ## anyone's abusing the system.
369 ###########################################################
371 # $(1): target class, like "APPS"
372 # $(2): target name, like "NotePad"
373 # $(3): if non-empty, this is a HOST target.
374 # $(4): if non-empty, force the intermediates to be COMMON
375 define intermediates-dir-for
377 $(eval _idfClass := $(strip $(1))) \
378 $(if $(_idfClass),, \
379 $(error $(LOCAL_PATH): Class not defined in call to intermediates-dir-for)) \
380 $(eval _idfName := $(strip $(2))) \
382 $(error $(LOCAL_PATH): Name not defined in call to intermediates-dir-for)) \
383 $(eval _idfPrefix := $(if $(strip $(3)),HOST,TARGET)) \
384 $(if $(filter $(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
385 $(eval _idfIntBase := $($(_idfPrefix)_OUT_COMMON_INTERMEDIATES)) \
387 $(eval _idfIntBase := $($(_idfPrefix)_OUT_INTERMEDIATES)) \
389 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
393 # Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE
394 # to determine the intermediates directory.
396 # $(1): if non-empty, force the intermediates to be COMMON
397 define local-intermediates-dir
399 $(if $(strip $(LOCAL_MODULE_CLASS)),, \
400 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-intermediates-dir)) \
401 $(if $(strip $(LOCAL_MODULE)),, \
402 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-intermediates-dir)) \
403 $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(LOCAL_IS_HOST_MODULE),$(1)) \
407 ###########################################################
408 ## Convert "path/to/libXXX.so" to "-lXXX".
409 ## Any "path/to/libXXX.a" elements pass through unchanged.
410 ###########################################################
412 define normalize-libraries
413 $(foreach so,$(filter %.so,$(1)),-l$(patsubst lib%.so,%,$(notdir $(so))))\
414 $(filter-out %.so,$(1))
417 # TODO: change users to call the common version.
418 define normalize-host-libraries
419 $(call normalize-libraries,$(1))
422 define normalize-target-libraries
423 $(call normalize-libraries,$(1))
426 ###########################################################
427 ## Convert a list of short module names (e.g., "framework", "Browser")
428 ## into the list of files that are built for those modules.
429 ## NOTE: this won't return reliable results until after all
430 ## sub-makefiles have been included.
432 ###########################################################
434 define module-built-files
435 $(foreach module,$(1),$(ALL_MODULES.$(module).BUILT))
438 ###########################################################
439 ## Convert a list of short modules names (e.g., "framework", "Browser")
440 ## into the list of files that are installed for those modules.
441 ## NOTE: this won't return reliable results until after all
442 ## sub-makefiles have been included.
444 ###########################################################
446 define module-installed-files
447 $(foreach module,$(1),$(ALL_MODULES.$(module).INSTALLED))
450 ###########################################################
451 ## Convert a list of short modules names (e.g., "framework", "Browser")
452 ## into the list of files that should be used when linking
453 ## against that module as a public API.
454 ## TODO: Allow this for more than JAVA_LIBRARIES modules
455 ## NOTE: this won't return reliable results until after all
456 ## sub-makefiles have been included.
458 ###########################################################
460 define module-stubs-files
461 $(foreach module,$(1),$(ALL_MODULES.$(module).STUBS))
464 ###########################################################
465 ## Evaluates to the timestamp file for a doc module, which
466 ## is the dependency that should be used.
468 ###########################################################
470 define doc-timestamp-for
471 $(OUT_DOCS)/$(strip $(1))-timestamp
475 ###########################################################
476 ## Convert "framework framework-res ext" to "out/.../javalib.jar ..."
477 ## This lets us treat framework-res as a normal library.
478 ## $(1): library list
479 ## $(2): Non-empty if IS_HOST_MODULE
480 ###########################################################
483 # $(2): Non-empty if IS_HOST_MODULE
485 $(call intermediates-dir-for, \
486 $(if $(filter framework-res,$(1)),APPS,JAVA_LIBRARIES),$(1),$(2))
490 define _java-lib-classes.jar
491 $(if $(filter framework-res,$(1)),package$(COMMON_ANDROID_PACKAGE_SUFFIX),classes$(COMMON_JAVA_PACKAGE_SUFFIX))
495 # $(2): Non-empty if IS_HOST_MODULE
496 define _java-lib-full-classes.jar
497 $(call _java-lib-dir,$(1),$(2))/$(call _java-lib-classes.jar,$(1))
500 # $(1): library name list
501 # $(2): Non-empty if IS_HOST_MODULE
502 define java-lib-files
503 $(foreach lib,$(1),$(call _java-lib-full-classes.jar,$(lib),$(2)))
508 $(if $(filter framework-res,$(1)),package$(COMMON_ANDROID_PACKAGE_SUFFIX),javalib$(COMMON_JAVA_PACKAGE_SUFFIX))
512 # $(2): Non-empty if IS_HOST_MODULE
513 define _java-lib-full-dep
514 $(call _java-lib-dir,$(1),$(2))/$(call _java-lib-dep,$(1))
517 # $(1): library name list
518 # $(2): Non-empty if IS_HOST_MODULE
520 $(foreach lib,$(1),$(call _java-lib-full-dep,$(lib),$(2)))
523 ###########################################################
524 ## Convert "a b c" into "a:b:c"
525 ###########################################################
528 space := $(empty) $(empty)
530 define normalize-path-list
531 $(subst $(space),:,$(strip $(1)))
534 ###########################################################
535 ## Read the word out of a colon-separated list of words.
536 ## This has the same behavior as the built-in function
539 ## The individual words may not contain spaces.
541 ## $(1): 1 based index
542 ## $(2): value of the form a:b:c...
543 ###########################################################
546 $(word $(1),$(subst :,$(space),$(2)))
549 ###########################################################
550 ## Convert "a=b c= d e = f" into "a=b c=d e=f"
552 ## $(1): list to collapse
553 ## $(2): if set, separator word; usually "=", ":", or ":="
554 ## Defaults to "=" if not set.
555 ###########################################################
557 define collapse-pairs
558 $(eval _cpSEP := $(strip $(if $(2),$(2),=)))\
559 $(subst $(space)$(_cpSEP)$(space),$(_cpSEP),$(strip \
560 $(subst $(_cpSEP), $(_cpSEP) ,$(1))))
563 ###########################################################
564 ## MODULE_TAG set operations
565 ###########################################################
567 # Given a list of tags, return the targets that specify
570 define modules-for-tag-list
571 $(sort $(foreach tag,$(1),$(ALL_MODULE_TAGS.$(tag))))
574 # Same as modules-for-tag-list, but operates on
575 # ALL_MODULE_NAME_TAGS.
577 define module-names-for-tag-list
578 $(sort $(foreach tag,$(1),$(ALL_MODULE_NAME_TAGS.$(tag))))
581 # Given an accept and reject list, find the matching
582 # set of targets. If a target has multiple tags and
583 # any of them are rejected, the target is rejected.
584 # Reject overrides accept.
585 # $(1): list of tags to accept
586 # $(2): list of tags to reject
587 #TODO(dbort): do $(if $(strip $(1)),$(1),$(ALL_MODULE_TAGS))
588 #TODO(jbq): as of 20100106 nobody uses the second parameter
589 define get-tagged-modules
591 $(call modules-for-tag-list,$(2)), \
592 $(call modules-for-tag-list,$(1)))
595 ###########################################################
596 ## Append a leaf to a base path. Properly deals with
597 ## base paths ending in /.
601 ###########################################################
604 $(subst //,/,$(1)/$(2))
608 ###########################################################
610 ###########################################################
612 # Given a list of installed modules (short or long names)
613 # return a list of the packages (yes, .apk packages, not
614 # modules in general) that are overridden by this list and,
615 # therefore, should not be installed.
616 # $(1): mixed list of installed modules
617 # TODO: This is fragile; find a reliable way to get this information.
618 define _get-package-overrides
619 $(eval ### Discard any words containing slashes, unless they end in .apk, \
620 ### in which case trim off the directory component and the suffix. \
621 ### If there are no slashes, keep the entire word.)
622 $(eval _gpo_names := $(subst /,@@@ @@@,$(1)))
623 $(eval _gpo_names := \
624 $(filter %.apk,$(_gpo_names)) \
625 $(filter-out %@@@ @@@%,$(_gpo_names)))
626 $(eval _gpo_names := $(patsubst %.apk,%,$(_gpo_names)))
627 $(eval _gpo_names := $(patsubst @@@%,%,$(_gpo_names)))
629 $(eval ### Remove any remaining words that contain dots.)
630 $(eval _gpo_names := $(subst .,@@@ @@@,$(_gpo_names)))
631 $(eval _gpo_names := $(filter-out %@@@ @@@%,$(_gpo_names)))
633 $(eval ### Now we have a list of any words that could possibly refer to \
634 ### packages, although there may be words that do not. Only \
635 ### real packages will be present under PACKAGES.*, though.)
636 $(foreach _gpo_name,$(_gpo_names),$(PACKAGES.$(_gpo_name).OVERRIDES))
639 define get-package-overrides
640 $(strip $(sort $(call _get-package-overrides,$(1))))
643 ###########################################################
644 ## Output the command lines, or not
645 ###########################################################
647 ifeq ($(strip $(SHOW_COMMANDS)),)
658 ###########################################################
659 ## Dump the variables that are associated with targets
660 ###########################################################
662 define dump-module-variables
663 @echo all_dependencies=$^
664 @echo PRIVATE_YACCFLAGS=$(PRIVATE_YACCFLAGS);
665 @echo PRIVATE_CFLAGS=$(PRIVATE_CFLAGS);
666 @echo PRIVATE_CPPFLAGS=$(PRIVATE_CPPFLAGS);
667 @echo PRIVATE_DEBUG_CFLAGS=$(PRIVATE_DEBUG_CFLAGS);
668 @echo PRIVATE_C_INCLUDES=$(PRIVATE_C_INCLUDES);
669 @echo PRIVATE_LDFLAGS=$(PRIVATE_LDFLAGS);
670 @echo PRIVATE_LDLIBS=$(PRIVATE_LDLIBS);
671 @echo PRIVATE_ARFLAGS=$(PRIVATE_ARFLAGS);
672 @echo PRIVATE_AAPT_FLAGS=$(PRIVATE_AAPT_FLAGS);
673 @echo PRIVATE_DX_FLAGS=$(PRIVATE_DX_FLAGS);
674 @echo PRIVATE_JAVACFLAGS=$(PRIVATE_JAVACFLAGS);
675 @echo PRIVATE_JAVA_LIBRARIES=$(PRIVATE_JAVA_LIBRARIES);
676 @echo PRIVATE_ALL_SHARED_LIBRARIES=$(PRIVATE_ALL_SHARED_LIBRARIES);
677 @echo PRIVATE_ALL_STATIC_LIBRARIES=$(PRIVATE_ALL_STATIC_LIBRARIES);
678 @echo PRIVATE_ALL_WHOLE_STATIC_LIBRARIES=$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES);
679 @echo PRIVATE_ALL_OBJECTS=$(PRIVATE_ALL_OBJECTS);
682 ###########################################################
683 ## Commands for using sed to replace given variable values
684 ###########################################################
686 define transform-variables
688 @echo "Sed: $(if $(PRIVATE_MODULE),$(PRIVATE_MODULE),$@) <= $<"
689 $(hide) sed $(foreach var,$(REPLACE_VARS),-e "s/{{$(var)}}/$(subst /,\/,$(PWD)/$($(var)))/g") $< >$@
690 $(hide) if [ "$(suffix $@)" = ".sh" ]; then chmod a+rx $@; fi
694 ###########################################################
695 ## Commands for munging the dependency files GCC generates
696 ###########################################################
698 define transform-d-to-p
699 @cp $(@:%.o=%.d) $(@:%.o=%.P); \
700 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
701 -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
705 ###########################################################
706 ## Commands for running lex
707 ###########################################################
709 define transform-l-to-cpp
711 @echo "Lex: $(PRIVATE_MODULE) <= $<"
712 $(hide) $(LEX) -o$@ $<
715 ###########################################################
716 ## Commands for running yacc
718 ## Because the extension of c++ files can change, the
719 ## extension must be specified in $1.
720 ## E.g, "$(call transform-y-to-cpp,.cpp)"
721 ###########################################################
723 define transform-y-to-cpp
725 @echo "Yacc: $(PRIVATE_MODULE) <= $<"
726 $(YACC) $(PRIVATE_YACCFLAGS) -o $@ $<
727 touch $(@:$1=$(YACC_HEADER_SUFFIX))
728 echo '#ifndef '$(@F:$1=_h) > $(@:$1=.h)
729 echo '#define '$(@F:$1=_h) >> $(@:$1=.h)
730 cat $(@:$1=$(YACC_HEADER_SUFFIX)) >> $(@:$1=.h)
731 echo '#endif' >> $(@:$1=.h)
732 rm -f $(@:$1=$(YACC_HEADER_SUFFIX))
736 ###########################################################
737 ## Commands for running aidl
738 ###########################################################
740 define transform-aidl-to-java
742 @echo "Aidl: $(PRIVATE_MODULE) <= $<"
743 $(hide) $(AIDL) -d$(patsubst %.java,%.P,$@) $(PRIVATE_AIDL_FLAGS) $< $@
745 #$(AIDL) $(PRIVATE_AIDL_FLAGS) $< - | indent -nut -br -npcs -l1000 > $@
748 ###########################################################
749 ## Commands for running java-event-log-tags.py
750 ###########################################################
752 define transform-logtags-to-java
754 @echo "logtags: $@ <= $<"
755 $(hide) $(JAVATAGS) -o $@ $^
759 ###########################################################
760 ## Commands for running gcc to compile a C++ file
761 ###########################################################
763 define transform-cpp-to-o
765 @echo "target $(PRIVATE_ARM_MODE) C++: $(PRIVATE_MODULE) <= $<"
766 $(hide) $(PRIVATE_CXX) \
768 $(PRIVATE_C_INCLUDES) \
769 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
770 $(TARGET_PROJECT_INCLUDES) \
771 $(TARGET_C_INCLUDES) \
777 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
778 $(TARGET_GLOBAL_CFLAGS) \
779 $(TARGET_GLOBAL_CPPFLAGS) \
780 $(PRIVATE_ARM_CFLAGS) \
784 $(PRIVATE_CPPFLAGS) \
785 $(PRIVATE_DEBUG_CFLAGS) \
787 $(hide) $(transform-d-to-p)
791 ###########################################################
792 ## Commands for running gcc to compile a C file
793 ###########################################################
796 define transform-c-or-s-to-o-no-deps
798 $(hide) $(PRIVATE_CC) \
800 $(PRIVATE_C_INCLUDES) \
801 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
802 $(TARGET_PROJECT_INCLUDES) \
803 $(TARGET_C_INCLUDES) \
809 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
810 $(TARGET_GLOBAL_CFLAGS) \
811 $(PRIVATE_ARM_CFLAGS) \
815 $(PRIVATE_DEBUG_CFLAGS) \
819 define transform-c-to-o-no-deps
820 @echo "target $(PRIVATE_ARM_MODE) C: $(PRIVATE_MODULE) <= $<"
821 $(call transform-c-or-s-to-o-no-deps, )
824 define transform-s-to-o-no-deps
825 @echo "target asm: $(PRIVATE_MODULE) <= $<"
826 $(call transform-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
829 define transform-c-to-o
830 $(transform-c-to-o-no-deps)
831 $(hide) $(transform-d-to-p)
834 define transform-s-to-o
835 $(transform-s-to-o-no-deps)
836 $(hide) $(transform-d-to-p)
839 ###########################################################
840 ## Commands for running gcc to compile an Objective-C file
841 ## This should never happen for target builds but this
842 ## will error at build time.
843 ###########################################################
845 define transform-m-to-o-no-deps
846 @echo "target ObjC: $(PRIVATE_MODULE) <= $<"
847 $(call transform-c-or-s-to-o-no-deps)
850 define transform-m-to-o
851 $(transform-m-to-o-no-deps)
852 $(hide) $(transform-d-to-p)
855 ###########################################################
856 ## Commands for running gcc to compile a host C++ file
857 ###########################################################
859 define transform-host-cpp-to-o
861 @echo "host C++: $(PRIVATE_MODULE) <= $<"
862 $(hide) $(PRIVATE_CXX) \
864 $(PRIVATE_C_INCLUDES) \
865 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
866 $(HOST_PROJECT_INCLUDES) \
873 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
874 $(HOST_GLOBAL_CFLAGS) \
875 $(HOST_GLOBAL_CPPFLAGS) \
878 $(PRIVATE_CPPFLAGS) \
879 $(PRIVATE_DEBUG_CFLAGS) \
885 ###########################################################
886 ## Commands for running gcc to compile a host C file
887 ###########################################################
890 define transform-host-c-or-s-to-o-no-deps
892 $(hide) $(PRIVATE_CC) \
894 $(PRIVATE_C_INCLUDES) \
895 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
896 $(HOST_PROJECT_INCLUDES) \
903 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
904 $(HOST_GLOBAL_CFLAGS) \
908 $(PRIVATE_DEBUG_CFLAGS) \
912 define transform-host-c-to-o-no-deps
913 @echo "host C: $(PRIVATE_MODULE) <= $<"
914 $(call transform-host-c-or-s-to-o-no-deps, )
917 define transform-host-s-to-o-no-deps
918 @echo "host asm: $(PRIVATE_MODULE) <= $<"
919 $(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
922 define transform-host-c-to-o
923 $(transform-host-c-to-o-no-deps)
927 define transform-host-s-to-o
928 $(transform-host-s-to-o-no-deps)
932 ###########################################################
933 ## Commands for running gcc to compile a host Objective-C file
934 ###########################################################
936 define transform-host-m-to-o-no-deps
937 @echo "host ObjC: $(PRIVATE_MODULE) <= $<"
938 $(call transform-host-c-or-s-to-o-no-deps)
941 define tranform-host-m-to-o
942 $(transform-host-m-to-o-no-deps)
946 ###########################################################
947 ## Commands for running ar
948 ###########################################################
950 define extract-and-include-target-whole-static-libs
951 $(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \
952 @echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(lib)]"; \
953 ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(lib)))_objs;\
957 for f in `$(TARGET_AR) t $(lib)`; do \
958 $(TARGET_AR) p $(lib) $$f > $$ldir/$$f; \
959 filelist="$$filelist $$ldir/$$f"; \
961 $(TARGET_AR) $(TARGET_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $$filelist;\
965 # Explicitly delete the archive first so that ar doesn't
966 # try to add to an existing archive.
967 define transform-o-to-static-lib
970 $(extract-and-include-target-whole-static-libs)
971 @echo "target StaticLib: $(PRIVATE_MODULE) ($@)"
972 $(hide) echo $^ | xargs $(TARGET_AR) $(TARGET_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@
975 ###########################################################
976 ## Commands for running host ar
977 ###########################################################
979 define extract-and-include-host-whole-static-libs
980 $(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \
981 @echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(lib)]"; \
982 ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(lib)))_objs;\
986 for f in `$(HOST_AR) t $(lib) | grep '\.o$$'`; do \
987 $(HOST_AR) p $(lib) $$f > $$ldir/$$f; \
988 filelist="$$filelist $$ldir/$$f"; \
990 $(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $$filelist;\
994 # Explicitly delete the archive first so that ar doesn't
995 # try to add to an existing archive.
996 define transform-host-o-to-static-lib
999 $(extract-and-include-host-whole-static-libs)
1000 @echo "host StaticLib: $(PRIVATE_MODULE) ($@)"
1001 echo $(filter %.o, $^) | \
1002 xargs $(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@
1006 ###########################################################
1007 ## Commands for running gcc to link a shared library or package
1008 ###########################################################
1010 # ld just seems to be so finicky with command order that we allow
1011 # it to be overriden en-masse see combo/linux-arm.make for an example.
1012 ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1013 define transform-host-o-to-shared-lib-inner
1015 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1016 -Wl,-rpath,\$$ORIGIN/../lib \
1017 -shared -Wl,-soname,$(notdir $@) \
1018 $(PRIVATE_LDFLAGS) \
1019 $(HOST_GLOBAL_LD_DIRS) \
1020 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1021 $(HOST_GLOBAL_LDFLAGS) \
1023 $(PRIVATE_ALL_OBJECTS) \
1024 -Wl,--whole-archive \
1025 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1026 -Wl,--no-whole-archive \
1027 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1028 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1034 define transform-host-o-to-shared-lib
1036 @echo "host SharedLib: $(PRIVATE_MODULE) ($@)"
1037 $(hide) $(transform-host-o-to-shared-lib-inner)
1040 define transform-host-o-to-package
1042 @echo "host Package: $(PRIVATE_MODULE) ($@)"
1043 $(hide) $(transform-host-o-to-shared-lib-inner)
1047 ###########################################################
1048 ## Commands for running gcc to link a shared library or package
1049 ###########################################################
1051 #echo >$@.vers "{"; \
1052 #echo >>$@.vers " global:"; \
1053 #$(BUILD_SYSTEM)/filter_symbols.sh $(TARGET_NM) " " ";" $(filter %.o,$^) | sort -u >>$@.vers; \
1054 #echo >>$@.vers " local:"; \
1055 #echo >>$@.vers " *;"; \
1056 #echo >>$@.vers "};"; \
1058 # -Wl,--version-script=$@.vers \
1060 # ld just seems to be so finicky with command order that we allow
1061 # it to be overriden en-masse see combo/linux-arm.make for an example.
1062 ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1063 define transform-o-to-shared-lib-inner
1065 $(TARGET_GLOBAL_LDFLAGS) \
1066 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1067 -Wl,-rpath,\$$ORIGIN/../lib \
1068 -shared -Wl,-soname,$(notdir $@) \
1069 $(PRIVATE_LDFLAGS) \
1070 $(TARGET_GLOBAL_LD_DIRS) \
1071 $(PRIVATE_ALL_OBJECTS) \
1072 -Wl,--whole-archive \
1073 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1074 -Wl,--no-whole-archive \
1075 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1076 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1082 define transform-o-to-shared-lib
1084 @echo "target SharedLib: $(PRIVATE_MODULE) ($@)"
1085 $(hide) $(transform-o-to-shared-lib-inner)
1088 define transform-o-to-package
1090 @echo "target Package: $(PRIVATE_MODULE) ($@)"
1091 $(hide) $(transform-o-to-shared-lib-inner)
1095 ###########################################################
1096 ## Commands for filtering a target executable or library
1097 ###########################################################
1099 # Because of bug 743462 ("Prelinked image magic gets stripped
1100 # by arm-elf-objcopy"), we have to use soslim to strip target
1102 define transform-to-stripped
1104 @echo "target Strip: $(PRIVATE_MODULE) ($@)"
1105 $(hide) $(SOSLIM) --strip --shady --quiet $< --outfile $@
1108 define transform-to-prelinked
1110 @echo "target Prelink: $(PRIVATE_MODULE) ($@)"
1111 $(hide) $(APRIORI) \
1112 --prelinkmap $(TARGET_PRELINKER_MAP) \
1120 ###########################################################
1121 ## Commands for running gcc to link an executable
1122 ###########################################################
1124 ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1125 define transform-o-to-executable-inner
1127 $(TARGET_GLOBAL_LDFLAGS) \
1128 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1129 $(TARGET_GLOBAL_LD_DIRS) \
1130 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1131 -Wl,-rpath,\$$ORIGIN/../lib \
1132 $(PRIVATE_LDFLAGS) \
1133 $(TARGET_GLOBAL_LD_DIRS) \
1134 $(PRIVATE_ALL_OBJECTS) \
1135 -Wl,--whole-archive \
1136 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1137 -Wl,--no-whole-archive \
1138 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1139 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1145 define transform-o-to-executable
1147 @echo "target Executable: $(PRIVATE_MODULE) ($@)"
1148 $(hide) $(transform-o-to-executable-inner)
1152 ###########################################################
1153 ## Commands for running gcc to link a statically linked
1154 ## executable. In practice, we only use this on arm, so
1155 ## the other platforms don't have the
1156 ## transform-o-to-static-executable defined
1157 ###########################################################
1159 ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1160 define transform-o-to-static-executable-inner
1164 define transform-o-to-static-executable
1166 @echo "target StaticExecutable: $(PRIVATE_MODULE) ($@)"
1167 $(hide) $(transform-o-to-static-executable-inner)
1171 ###########################################################
1172 ## Commands for running gcc to link a host executable
1173 ###########################################################
1175 ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1176 define transform-host-o-to-executable-inner
1178 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1179 -Wl,-rpath,\$$ORIGIN/../lib \
1180 $(HOST_GLOBAL_LD_DIRS) \
1181 $(PRIVATE_LDFLAGS) \
1182 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1183 $(HOST_GLOBAL_LDFLAGS) \
1185 $(PRIVATE_ALL_OBJECTS) \
1186 -Wl,--whole-archive \
1187 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1188 -Wl,--no-whole-archive \
1189 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1190 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1196 define transform-host-o-to-executable
1198 @echo "host Executable: $(PRIVATE_MODULE) ($@)"
1199 $(hide) $(transform-host-o-to-executable-inner)
1203 ###########################################################
1204 ## Commands for running javac to make .class files
1205 ###########################################################
1207 #@echo "Source intermediates dir: $(PRIVATE_SOURCE_INTERMEDIATES_DIR)"
1208 #@echo "Source intermediates: $$(find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java')"
1210 # TODO: Right now we generate the asset resources twice, first as part
1211 # of generating the Java classes, then at the end when packaging the final
1212 # assets. This should be changed to do one of two things: (1) Don't generate
1213 # any resource files the first time, only create classes during that stage;
1214 # or (2) Don't use the -c flag with the second stage, instead taking the
1215 # resource files from the first stage as additional input. My original intent
1216 # was to use approach (2), but this requires a little more work in the tool.
1217 # Maybe we should just use approach (1).
1219 # This rule creates the R.java and Manifest.java files, both of which
1220 # are PRODUCT-neutral. Don't pass PRODUCT_AAPT_CONFIG to this invocation.
1221 define create-resource-java-files
1222 @mkdir -p $(PRIVATE_SOURCE_INTERMEDIATES_DIR)
1223 @mkdir -p $(dir $(PRIVATE_RESOURCE_PUBLICS_OUTPUT))
1224 $(hide) $(AAPT) package $(PRIVATE_AAPT_FLAGS) -m -z \
1225 $(eval # PRODUCT_AAPT_CONFIG is intentionally missing-- see comment.) \
1226 $(addprefix -J , $(PRIVATE_SOURCE_INTERMEDIATES_DIR)) \
1227 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
1228 $(addprefix -P , $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) \
1229 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
1230 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
1231 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
1232 $(addprefix -G , $(PRIVATE_PROGUARD_OPTIONS_FILE)) \
1233 $(addprefix --min-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
1234 $(addprefix --target-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
1235 $(addprefix --version-code , $(PLATFORM_SDK_VERSION)) \
1236 $(addprefix --version-name , $(PLATFORM_VERSION)) \
1237 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME))
1240 ifeq ($(HOST_OS),windows)
1243 #xlint_unchecked := -Xlint:unchecked
1246 # emit-line, <word list>, <output file>
1248 $(if $(1),echo -n '$(strip $(1)) ' >> $(2))
1251 # dump-words-to-file, <word list>, <output file>
1252 define dump-words-to-file
1254 @$(call emit-line,$(wordlist 1,200,$(1)),$(2))
1255 @$(call emit-line,$(wordlist 201,400,$(1)),$(2))
1256 @$(call emit-line,$(wordlist 401,600,$(1)),$(2))
1257 @$(call emit-line,$(wordlist 601,800,$(1)),$(2))
1258 @$(call emit-line,$(wordlist 801,1000,$(1)),$(2))
1259 @$(call emit-line,$(wordlist 1001,1200,$(1)),$(2))
1260 @$(call emit-line,$(wordlist 1201,1400,$(1)),$(2))
1261 @$(call emit-line,$(wordlist 1401,1600,$(1)),$(2))
1262 @$(call emit-line,$(wordlist 1601,1800,$(1)),$(2))
1263 @$(call emit-line,$(wordlist 1801,2000,$(1)),$(2))
1264 @$(call emit-line,$(wordlist 2001,2200,$(1)),$(2))
1265 @$(call emit-line,$(wordlist 2201,2400,$(1)),$(2))
1266 @$(call emit-line,$(wordlist 2401,2600,$(1)),$(2))
1267 @$(call emit-line,$(wordlist 2601,2800,$(1)),$(2))
1268 @$(call emit-line,$(wordlist 2801,3000,$(1)),$(2))
1269 @$(call emit-line,$(wordlist 3001,3200,$(1)),$(2))
1270 @$(call emit-line,$(wordlist 3201,3400,$(1)),$(2))
1271 @$(call emit-line,$(wordlist 3401,3600,$(1)),$(2))
1272 @$(call emit-line,$(wordlist 3601,3800,$(1)),$(2))
1273 @$(call emit-line,$(wordlist 3801,4000,$(1)),$(2))
1274 @$(if $(wordlist 4001,4002,$(1)),$(error Too many words ($(words $(1)))))
1277 # For a list of jar files, unzip them to a specified directory,
1278 # but make sure that no META-INF files come along for the ride.
1280 # $(1): files to unzip
1281 # $(2): destination directory
1282 define unzip-jar-files
1283 $(hide) for f in $(1); \
1285 if [ ! -f $$f ]; then \
1286 echo Missing file $$f; \
1289 unzip -qo $$f -d $(2); \
1290 (cd $(2) && rm -rf META-INF); \
1294 # below we write the list of java files to java-source-list to avoid argument
1295 # list length problems with Cygwin we filter out duplicate java file names
1296 # because eclipse's compiler doesn't like them.
1297 define transform-java-to-classes.jar
1298 @echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
1300 $(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1301 $(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1302 $(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES), \
1303 $(PRIVATE_CLASS_INTERMEDIATES_DIR))
1304 $(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list)
1305 $(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
1306 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list; \
1308 $(hide) tr ' ' '\n' < $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list \
1309 | sort -u > $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list-uniq
1310 $(hide) $(TARGET_JAVAC) -encoding ascii $(PRIVATE_BOOTCLASSPATH) \
1311 $(addprefix -classpath ,$(strip \
1312 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \
1313 $(PRIVATE_JAVACFLAGS) $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) $(xlint_unchecked) \
1314 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
1315 \@$(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list-uniq \
1316 || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 )
1317 $(hide) rm -f $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list
1318 $(hide) rm -f $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list-uniq
1319 $(hide) mkdir -p $(dir $@)
1320 $(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \
1321 $@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
1322 $(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1325 define transform-classes.jar-to-emma
1326 $(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \
1327 $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR)
1330 #TODO: use a smaller -Xmx value for most libraries;
1331 # only core.jar and framework.jar need a heap this big.
1332 # Avoid the memory arguments on Windows, dx fails to load for some reason with them.
1333 define transform-classes.jar-to-dex
1334 @echo "target Dex: $(PRIVATE_MODULE)"
1337 $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx1536M) \
1339 $(if $(NO_OPTIMIZE_DX), \
1341 $(if $(GENERATE_DEX_DEBUG), \
1343 --dump-to=$(@:.dex=.lst) \
1344 --dump-width=1000) \
1345 $(PRIVATE_DX_FLAGS) \
1349 # Create a mostly-empty .jar file that we'll add to later.
1350 # The MacOS jar tool doesn't like creating empty jar files,
1351 # so we need to give it something.
1352 define create-empty-package
1354 $(hide) touch $(dir $@)/dummy
1355 $(hide) (cd $(dir $@) && jar cf $(notdir $@) dummy)
1356 $(hide) zip -qd $@ dummy
1357 $(hide) rm $(dir $@)/dummy
1360 #TODO: we kinda want to build different asset packages for
1361 # different configurations, then combine them later (or something).
1363 # A list of dynamic and static parameters; build layers for
1364 # dynamic params that lay over the static ones.
1365 #TODO: update the manifest to point to the package file
1366 #Note that the version numbers are given to aapt as simple default
1367 #values; applications can override these by explicitly stating
1368 #them in their manifest.
1369 define add-assets-to-package
1370 $(hide) $(AAPT) package -z -u $(PRIVATE_AAPT_FLAGS) \
1371 $(addprefix -c , $(PRODUCT_AAPT_CONFIG)) \
1372 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
1373 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
1374 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
1375 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
1376 $(addprefix --min-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
1377 $(addprefix --target-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
1378 $(addprefix --version-code , $(PLATFORM_SDK_VERSION)) \
1379 $(addprefix --version-name , $(PLATFORM_VERSION)) \
1380 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
1384 #TODO: Allow library directory to be specified based on the target
1385 # CPU and ABI instead of being hard coded as armeabi.
1386 define add-jni-shared-libs-to-package
1387 $(hide) rm -rf $(dir $@)lib
1388 $(hide) mkdir -p $(dir $@)lib/armeabi
1389 $(hide) cp $(PRIVATE_JNI_SHARED_LIBRARIES) $(dir $@)lib/armeabi
1390 $(hide) (cd $(dir $@) && zip -r $(notdir $@) lib)
1391 $(hide) rm -rf $(dir $@)lib
1394 #TODO: update the manifest to point to the dex file
1395 define add-dex-to-package
1396 $(hide) $(AAPT) add -k $@ $(PRIVATE_DEX_FILE)
1399 define add-java-resources-to-package
1400 $(hide) jar uf $@ $(PRIVATE_EXTRA_JAR_ARGS)
1403 # Sign a package using the specified key/cert.
1406 $(hide) mv $@ $@.unsigned
1407 $(hide) java -jar $(SIGNAPK_JAR) \
1408 $(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) $@.unsigned $@.signed
1409 $(hide) mv $@.signed $@
1412 # Align STORED entries of a package on 4-byte boundaries
1413 # to make them easier to mmap.
1415 define align-package
1416 $(hide) mv $@ $@.unaligned
1417 $(hide) $(ZIPALIGN) -f 4 $@.unaligned $@.aligned
1418 $(hide) mv $@.aligned $@
1421 define install-dex-debug
1422 $(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.dex" ]; then \
1423 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
1424 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.dex \
1425 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).dex; \
1427 $(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.lst" ]; then \
1428 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
1429 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.lst \
1430 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).lst; \
1434 # TODO(joeo): If we can ever upgrade to post 3.81 make and get the
1435 # new prebuilt rules to work, we should change this to copy the
1436 # resources to the out directory and then copy the resources.
1438 # Note: not using aapt tool for this because we aren't making
1439 # an android package for the host.
1440 define transform-host-java-to-package
1441 @echo "host Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
1443 @rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1445 @mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1446 $(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES), \
1447 $(PRIVATE_CLASS_INTERMEDIATES_DIR))
1448 $(call dump-words-to-file,$(sort\
1449 $(PRIVATE_JAVA_SOURCES)),\
1450 $(PRIVATE_INTERMEDIATES_DIR)/java-source-list-uniq)
1451 $(hide) $(HOST_JAVAC) -encoding ascii -g \
1452 $(PRIVATE_JAVACFLAGS) $(xlint_unchecked) \
1453 $(addprefix -classpath ,$(strip \
1454 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \
1455 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR)\
1456 \@$(PRIVATE_INTERMEDIATES_DIR)/java-source-list-uniq || \
1457 ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 )
1458 $(hide) rm -f $(PRIVATE_INTERMEDIATES_DIR)/java-source-list
1459 $(hide) rm -f $(PRIVATE_INTERMEDIATES_DIR)/java-source-list-uniq
1460 $(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \
1461 $@ $(PRIVATE_JAR_MANIFEST) $(PRIVATE_EXTRA_JAR_ARGS) \
1462 -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
1465 ###########################################################
1466 ## Obfuscate a jar file
1467 ###########################################################
1469 # PRIVATE_KEEP_FILE is a file containing a list of classes
1470 # PRIVATE_INTERMEDIATES_DIR is a directory we can use for temporary files
1471 # The module using this must depend on
1472 # $(HOST_OUT_JAVA_LIBRARIES)/proguard-4.0.1.jar
1473 define obfuscate-jar
1474 @echo "Obfuscate jar: $(notdir $@) ($@)"
1477 @mkdir -p $(PRIVATE_INTERMEDIATES_DIR)
1478 $(hide) sed -e 's/^/-keep class /' < $(PRIVATE_KEEP_FILE) > \
1479 $(PRIVATE_INTERMEDIATES_DIR)/keep.pro
1480 $(hide) java -Xmx512M -jar $(HOST_OUT_JAVA_LIBRARIES)/proguard-4.0.1.jar \
1484 -dontnote -dontwarn \
1485 -printmapping $(PRIVATE_INTERMEDIATES_DIR)/out.map \
1487 -renamesourcefileattribute SourceFile \
1488 -keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod \
1490 -keepclassmembers "class * { public protected *; }" \
1491 @$(PRIVATE_INTERMEDIATES_DIR)/keep.pro
1494 ###########################################################
1495 ## Commands for copying files
1496 ###########################################################
1498 # Define a rule to copy a header. Used via $(eval) by copy_headers.make.
1499 # $(1): source header
1500 # $(2): destination header
1501 define copy-one-header
1504 $$(copy-file-to-new-target-with-cp)
1507 # Define a rule to copy a file. For use via $(eval).
1509 # $(2): destination file
1510 define copy-one-file
1513 $$(copy-file-to-target)
1516 # The -t option to acp and the -p option to cp is
1517 # required for OSX. OSX has a ridiculous restriction
1518 # where it's an error for a .a file's modification time
1519 # to disagree with an internal timestamp, and this
1520 # macro is used to install .a files (among other things).
1522 # Copy a single file from one place to another,
1523 # preserving permissions and overwriting any existing
1525 define copy-file-to-target
1527 $(hide) $(ACP) -fpt $< $@
1530 # The same as copy-file-to-target, but use the local
1531 # cp command instead of acp.
1532 define copy-file-to-target-with-cp
1534 $(hide) cp -fp $< $@
1537 # The same as copy-file-to-target, but use the zipalign tool to do so.
1538 define copy-file-to-target-with-zipalign
1540 $(hide) $(ZIPALIGN) -f 4 $< $@
1543 # The same as copy-file-to-target, but strip out "# comment"-style
1544 # comments (for config files and such).
1545 define copy-file-to-target-strip-comments
1547 $(hide) sed -e 's/#.*$$//' -e 's/[ \t]*$$//' -e '/^$$/d' < $< > $@
1550 # The same as copy-file-to-target, but don't preserve
1551 # the old modification time.
1552 define copy-file-to-new-target
1554 $(hide) $(ACP) -fp $< $@
1557 # The same as copy-file-to-new-target, but use the local
1558 # cp command instead of acp.
1559 define copy-file-to-new-target-with-cp
1564 # Copy a prebuilt file to a target location.
1565 define transform-prebuilt-to-target
1566 @echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"
1567 $(copy-file-to-target)
1570 # Copy a prebuilt file to a target location, using zipalign on it.
1571 define transform-prebuilt-to-target-with-zipalign
1572 @echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt APK: $(PRIVATE_MODULE) ($@)"
1573 $(copy-file-to-target-with-zipalign)
1576 # Copy a prebuilt file to a target location, stripping "# comment" comments.
1577 define transform-prebuilt-to-target-strip-comments
1578 @echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"
1579 $(copy-file-to-target-strip-comments)
1582 ###########################################################
1583 ## On some platforms (MacOS), after copying a static
1584 ## library, ranlib must be run to update an internal
1586 ###########################################################
1588 ifeq ($(HOST_RUN_RANLIB_AFTER_COPYING),true)
1589 define transform-host-ranlib-copy-hack
1590 $(hide) ranlib $@ || true
1593 define transform-host-ranlib-copy-hack
1598 ifeq ($(TARGET_RUN_RANLIB_AFTER_COPYING),true)
1599 define transform-ranlib-copy-hack
1603 define transform-ranlib-copy-hack
1609 ###########################################################
1610 ## Commands to call Proguard
1611 ###########################################################
1613 # Command to copy the file with acp, if proguard is disabled.
1614 define proguard-disabled-commands
1616 $(hide) $(ACP) $< $@
1619 # Command to call Proguard
1620 # $(1): extra flags for instrumentation.
1621 define proguard-enabled-commands
1623 $(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS) $(1)
1626 # Figure out the proguard dictionary file of the module that is instrumentationed for.
1627 define get-instrumentation-proguard-flags
1628 $(if $(PRIVATE_INSTRUMENTATION_FOR),$(if $(ALL_MODULES.$(PRIVATE_INSTRUMENTATION_FOR).PROGUARD_ENABLED),-applymapping $(call intermediates-dir-for,APPS,$(PRIVATE_INSTRUMENTATION_FOR),,COMMON)/proguard_dictionary))
1631 define transform-jar-to-proguard
1632 $(eval _instrumentation_proguard_flags:=$(call get-instrumentation-proguard-flags))
1633 $(eval _enable_proguard:=$(PRIVATE_PROGUARD_ENABLED)$(_instrumentation_proguard_flags))
1634 $(if $(_enable_proguard),$(call proguard-enabled-commands,$(_instrumentation_proguard_flags)),$(call proguard-disabled-commands))
1635 $(eval _instrumentation_proguard_flags:=)
1636 $(eval _enable_proguard:=)
1640 ###########################################################
1641 ## Stuff source generated from one-off tools
1642 ###########################################################
1644 define transform-generated-source
1645 @echo "target Generated: $(PRIVATE_MODULE) <= $<"
1647 $(hide) $(PRIVATE_CUSTOM_TOOL)
1651 ###########################################################
1652 ## Assertions about attributes of the target
1653 ###########################################################
1655 # $(1): The file to check
1656 ifndef get-file-size
1657 $(error HOST_OS must define get-file-size)
1660 # Convert a partition data size (eg, as reported in /proc/mtd) to the
1661 # size of the image used to flash that partition (which includes a
1662 # 64-byte spare area for each 2048-byte page).
1663 # $(1): the partition data size
1664 define image-size-from-data-size
1665 $(shell echo $$(($(1) / 2048 * (2048+64))))
1668 # $(1): The file(s) to check (often $@)
1669 # $(2): The maximum total image size, in decimal bytes
1670 # $(3): the type of filesystem "yaffs" or "raw"
1672 # If $(2) is empty, evaluates to "true"
1674 # Reserve bad blocks. Make sure that MAX(1% of partition size, 2 blocks)
1675 # is left over after the image has been flashed. Round the 1% up to the
1676 # next whole flash block size.
1677 define assert-max-file-size
1679 size=$$(for i in $(1); do $(call get-file-size,$$i); echo +; done; echo 0); \
1680 total=$$(( $$( echo "$$size" ) )); \
1681 printname=$$(echo -n "$(1)" | tr " " +); \
1682 echo "$$printname total size is $$total"; \
1683 img_blocksize=$(call image-size-from-data-size,$(BOARD_FLASH_BLOCK_SIZE)); \
1684 if [ "$(3)" == "yaffs" ]; then \
1689 twoblocks=$$((img_blocksize * 2)); \
1690 onepct=$$((((($(2) / 100) - 1) / img_blocksize + 1) * img_blocksize)); \
1691 reserve=$$(((twoblocks > onepct ? twoblocks : onepct) + \
1692 reservedblocks * img_blocksize)); \
1693 maxsize=$$(($(2) - reserve)); \
1694 if [ "$$total" -gt "$$maxsize" ]; then \
1695 echo "error: $$printname too large ($$total > [$(2) - $$reserve])"; \
1697 elif [ "$$total" -gt $$((maxsize - 32768)) ]; then \
1698 echo "WARNING: $$printname approaching size limit ($$total now; limit $$maxsize)"; \
1705 # Like assert-max-file-size, but the second argument is a partition
1706 # size, which we'll convert to a max image size before checking it
1707 # against the files.
1709 # $(1): The file(s) to check (often $@)
1710 # $(2): The partition size.
1711 define assert-max-image-size
1713 $(call assert-max-file-size,$(1),$(call image-size-from-data-size,$(2))), \
1718 ###########################################################
1719 ## Define device-specific radio files
1720 ###########################################################
1722 # Copy a radio image file to the output location, and add it to
1723 # INSTALLED_RADIOIMAGE_TARGET.
1725 define add-radio-file
1726 $(eval $(call add-radio-file-internal,$(1),$(notdir $(1))))
1728 define add-radio-file-internal
1729 INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
1730 ALL_PREBUILT += $$(PRODUCT_OUT)/$(2)
1731 $$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP)
1732 $$(transform-prebuilt-to-target)
1736 ###########################################################
1737 # Override the package defined in $(1), setting the
1738 # variables listed below differently.
1740 # $(1): The makefile to override (relative to the source
1742 # $(2): Old LOCAL_PACKAGE_NAME value.
1743 # $(3): New LOCAL_PACKAGE_NAME value.
1744 # $(4): New LOCALE_MANIFEST_PACKAGE_NAME value.
1745 # $(5): New LOCAL_CERTIFICATE value.
1747 # Note that LOCAL_PACKAGE_OVERRIDES is NOT cleared in
1749 ###########################################################
1750 define inherit-package
1751 $(eval $(call inherit-package-internal,$(1),$(2),$(3),$(4)))
1754 define inherit-package-internal
1755 LOCAL_PACKAGE_OVERRIDES \
1756 := $(strip $(1))||$(strip $(2))||$(strip $(3))||$(strip $(4))||$(strip $(5)) $(LOCAL_PACKAGE_OVERRIDES)
1758 LOCAL_PACKAGE_OVERRIDES \
1759 := $(wordlist 1,$(words $(LOCAL_PACKAGE_OVERRIDES)), $(LOCAL_PACKAGE_OVERRIDES))
1762 # To be used with inherit-package above
1763 # Evalutes to true if the package was overridden
1764 define set-inherited-package-variables
1765 $(strip $(call set-inherited-package-variables-internal))
1768 define keep-or-override
1769 $(eval $(1) := $(if $(2),$(2),$($(1))))
1772 define set-inherited-package-variables-internal
1773 $(eval _o := $(subst ||, ,$(lastword $(LOCAL_PACKAGE_OVERRIDES))))
1774 $(eval _n := $(subst ||, ,$(firstword $(LOCAL_PACKAGE_OVERRIDES))))
1775 $(if $(filter $(word 2,$(_n)),$(LOCAL_PACKAGE_NAME)), \
1776 $(eval LOCAL_PACKAGE_NAME := $(word 3,$(_o))) \
1777 $(eval LOCAL_MANIFEST_PACKAGE_NAME := $(word 4,$(_o))) \
1778 $(call keep-or-override,LOCAL_CERTIFICATE,$(word 5,$(_o))) \
1779 $(eval LOCAL_OVERRIDES_PACKAGES := $(sort $(LOCAL_OVERRIDES_PACKAGES) $(word 2,$(_o)))) \
1785 ###########################################################
1787 ###########################################################
1789 # -----------------------------------------------------------------
1790 # Rules and functions to help copy important files to DIST_DIR
1792 include $(BUILD_SYSTEM)/distdir.mk
1796 # $(foreach file,$^,$(if $(findstring,.a,$(suffix $file)),-l$(file),$(file)))
1798 ###########################################################
1800 ###########################################################
1803 #df = $(DEPDIR)/$(*F)
1805 #SRCS = foo.c bar.c ...
1809 # cp $(df).d $(df).P; \
1810 # sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
1811 # -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \
1813 # $(COMPILE.c) -o $@ $<
1815 #-include $(SRCS:%.c=$(DEPDIR)/%.P)
1819 # $(COMPILE.c) -MD -o $@ $<
1821 # sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
1822 # -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \