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