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