OSDN Git Service

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