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