blob: ac431df6aed733595fb2b259216d54b21929d27c [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###########################################################
Jean-Baptiste Queru79ee7bf2011-01-27 12:19:43 -0800239## Find all of the .proto files under the named directories.
240## Meant to be used like:
241## SRC_FILES := $(call all-proto-files-under,src)
242###########################################################
243
244define all-proto-files-under
245$(patsubst ./%,%, \
246 $(shell cd $(LOCAL_PATH) ; \
247 find $(1) -name "*.proto" -and -not -name ".*") \
248 )
249endef
250
251###########################################################
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)) \
Ying Wanga83940f2010-09-24 18:09:04 -0700397 $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800398 $(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###########################################################
Ying Wang912f8282010-09-28 17:27:56 -0700489## Convert "core ext framework" to "out/.../javalib.jar ..."
The Android Open Source Project88b60792009-03-03 19:28:42 -0800490## $(1): library list
491## $(2): Non-empty if IS_HOST_MODULE
492###########################################################
493
494# $(1): library name
495# $(2): Non-empty if IS_HOST_MODULE
496define _java-lib-dir
497$(call intermediates-dir-for, \
Ying Wang912f8282010-09-28 17:27:56 -0700498 JAVA_LIBRARIES,$(1),$(2),COMMON)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800499endef
500
501# $(1): library name
502# $(2): Non-empty if IS_HOST_MODULE
503define _java-lib-full-classes.jar
Ying Wang912f8282010-09-28 17:27:56 -0700504$(call _java-lib-dir,$(1),$(2))/classes$(COMMON_JAVA_PACKAGE_SUFFIX)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800505endef
506
507# $(1): library name list
508# $(2): Non-empty if IS_HOST_MODULE
509define java-lib-files
510$(foreach lib,$(1),$(call _java-lib-full-classes.jar,$(lib),$(2)))
511endef
512
513# $(1): library name
The Android Open Source Project88b60792009-03-03 19:28:42 -0800514# $(2): Non-empty if IS_HOST_MODULE
515define _java-lib-full-dep
Ying Wang912f8282010-09-28 17:27:56 -0700516$(call _java-lib-dir,$(1),$(2))/javalib$(COMMON_JAVA_PACKAGE_SUFFIX)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800517endef
518
519# $(1): library name list
520# $(2): Non-empty if IS_HOST_MODULE
521define java-lib-deps
522$(foreach lib,$(1),$(call _java-lib-full-dep,$(lib),$(2)))
523endef
524
525###########################################################
526## Convert "a b c" into "a:b:c"
527###########################################################
528
529empty :=
530space := $(empty) $(empty)
531
532define normalize-path-list
533$(subst $(space),:,$(strip $(1)))
534endef
535
536###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700537## Read the word out of a colon-separated list of words.
538## This has the same behavior as the built-in function
539## $(word n,str).
540##
541## The individual words may not contain spaces.
542##
543## $(1): 1 based index
544## $(2): value of the form a:b:c...
545###########################################################
546
547define word-colon
548$(word $(1),$(subst :,$(space),$(2)))
549endef
550
551###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800552## Convert "a=b c= d e = f" into "a=b c=d e=f"
553##
554## $(1): list to collapse
555## $(2): if set, separator word; usually "=", ":", or ":="
556## Defaults to "=" if not set.
557###########################################################
558
559define collapse-pairs
560$(eval _cpSEP := $(strip $(if $(2),$(2),=)))\
561$(subst $(space)$(_cpSEP)$(space),$(_cpSEP),$(strip \
562 $(subst $(_cpSEP), $(_cpSEP) ,$(1))))
563endef
564
The Android Open Source Project88b60792009-03-03 19:28:42 -0800565###########################################################
566## MODULE_TAG set operations
567###########################################################
568
569# Given a list of tags, return the targets that specify
570# any of those tags.
571# $(1): tag list
572define modules-for-tag-list
573$(sort $(foreach tag,$(1),$(ALL_MODULE_TAGS.$(tag))))
574endef
575
576# Same as modules-for-tag-list, but operates on
577# ALL_MODULE_NAME_TAGS.
578# $(1): tag list
579define module-names-for-tag-list
580$(sort $(foreach tag,$(1),$(ALL_MODULE_NAME_TAGS.$(tag))))
581endef
582
583# Given an accept and reject list, find the matching
584# set of targets. If a target has multiple tags and
585# any of them are rejected, the target is rejected.
586# Reject overrides accept.
587# $(1): list of tags to accept
588# $(2): list of tags to reject
589#TODO(dbort): do $(if $(strip $(1)),$(1),$(ALL_MODULE_TAGS))
Jean-Baptiste Queru75127b72010-01-07 11:44:22 -0800590#TODO(jbq): as of 20100106 nobody uses the second parameter
The Android Open Source Project88b60792009-03-03 19:28:42 -0800591define get-tagged-modules
592$(filter-out \
593 $(call modules-for-tag-list,$(2)), \
594 $(call modules-for-tag-list,$(1)))
595endef
596
Joe Onorato64d85d02009-04-09 19:31:12 -0700597###########################################################
598## Append a leaf to a base path. Properly deals with
599## base paths ending in /.
600##
601## $(1): base path
602## $(2): leaf path
603###########################################################
604
605define append-path
606$(subst //,/,$(1)/$(2))
607endef
608
The Android Open Source Project88b60792009-03-03 19:28:42 -0800609
610###########################################################
611## Package filtering
612###########################################################
613
614# Given a list of installed modules (short or long names)
615# return a list of the packages (yes, .apk packages, not
616# modules in general) that are overridden by this list and,
617# therefore, should not be installed.
618# $(1): mixed list of installed modules
619# TODO: This is fragile; find a reliable way to get this information.
620define _get-package-overrides
621 $(eval ### Discard any words containing slashes, unless they end in .apk, \
622 ### in which case trim off the directory component and the suffix. \
623 ### If there are no slashes, keep the entire word.)
624 $(eval _gpo_names := $(subst /,@@@ @@@,$(1)))
625 $(eval _gpo_names := \
626 $(filter %.apk,$(_gpo_names)) \
627 $(filter-out %@@@ @@@%,$(_gpo_names)))
628 $(eval _gpo_names := $(patsubst %.apk,%,$(_gpo_names)))
629 $(eval _gpo_names := $(patsubst @@@%,%,$(_gpo_names)))
630
631 $(eval ### Remove any remaining words that contain dots.)
632 $(eval _gpo_names := $(subst .,@@@ @@@,$(_gpo_names)))
633 $(eval _gpo_names := $(filter-out %@@@ @@@%,$(_gpo_names)))
634
635 $(eval ### Now we have a list of any words that could possibly refer to \
636 ### packages, although there may be words that do not. Only \
637 ### real packages will be present under PACKAGES.*, though.)
638 $(foreach _gpo_name,$(_gpo_names),$(PACKAGES.$(_gpo_name).OVERRIDES))
639endef
640
641define get-package-overrides
642$(strip $(sort $(call _get-package-overrides,$(1))))
643endef
644
645###########################################################
646## Output the command lines, or not
647###########################################################
648
649ifeq ($(strip $(SHOW_COMMANDS)),)
650define pretty
651@echo $1
652endef
653hide := @
654else
655define pretty
656endef
657hide :=
658endif
659
660###########################################################
661## Dump the variables that are associated with targets
662###########################################################
663
664define dump-module-variables
665@echo all_dependencies=$^
666@echo PRIVATE_YACCFLAGS=$(PRIVATE_YACCFLAGS);
667@echo PRIVATE_CFLAGS=$(PRIVATE_CFLAGS);
668@echo PRIVATE_CPPFLAGS=$(PRIVATE_CPPFLAGS);
669@echo PRIVATE_DEBUG_CFLAGS=$(PRIVATE_DEBUG_CFLAGS);
670@echo PRIVATE_C_INCLUDES=$(PRIVATE_C_INCLUDES);
671@echo PRIVATE_LDFLAGS=$(PRIVATE_LDFLAGS);
672@echo PRIVATE_LDLIBS=$(PRIVATE_LDLIBS);
673@echo PRIVATE_ARFLAGS=$(PRIVATE_ARFLAGS);
674@echo PRIVATE_AAPT_FLAGS=$(PRIVATE_AAPT_FLAGS);
675@echo PRIVATE_DX_FLAGS=$(PRIVATE_DX_FLAGS);
Brian Carlstromf184a0f2010-02-01 11:13:32 -0800676@echo PRIVATE_JAVACFLAGS=$(PRIVATE_JAVACFLAGS);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800677@echo PRIVATE_JAVA_LIBRARIES=$(PRIVATE_JAVA_LIBRARIES);
678@echo PRIVATE_ALL_SHARED_LIBRARIES=$(PRIVATE_ALL_SHARED_LIBRARIES);
679@echo PRIVATE_ALL_STATIC_LIBRARIES=$(PRIVATE_ALL_STATIC_LIBRARIES);
680@echo PRIVATE_ALL_WHOLE_STATIC_LIBRARIES=$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES);
681@echo PRIVATE_ALL_OBJECTS=$(PRIVATE_ALL_OBJECTS);
682endef
683
684###########################################################
685## Commands for using sed to replace given variable values
686###########################################################
687
688define transform-variables
689@mkdir -p $(dir $@)
690@echo "Sed: $(if $(PRIVATE_MODULE),$(PRIVATE_MODULE),$@) <= $<"
691$(hide) sed $(foreach var,$(REPLACE_VARS),-e "s/{{$(var)}}/$(subst /,\/,$(PWD)/$($(var)))/g") $< >$@
692$(hide) if [ "$(suffix $@)" = ".sh" ]; then chmod a+rx $@; fi
693endef
694
695
696###########################################################
697## Commands for munging the dependency files GCC generates
698###########################################################
699
700define transform-d-to-p
701@cp $(@:%.o=%.d) $(@:%.o=%.P); \
702 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
703 -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
704 rm -f $(@:%.o=%.d)
705endef
706
707###########################################################
708## Commands for running lex
709###########################################################
710
711define transform-l-to-cpp
712@mkdir -p $(dir $@)
713@echo "Lex: $(PRIVATE_MODULE) <= $<"
714$(hide) $(LEX) -o$@ $<
715endef
716
717###########################################################
718## Commands for running yacc
719##
720## Because the extension of c++ files can change, the
721## extension must be specified in $1.
722## E.g, "$(call transform-y-to-cpp,.cpp)"
723###########################################################
724
725define transform-y-to-cpp
726@mkdir -p $(dir $@)
727@echo "Yacc: $(PRIVATE_MODULE) <= $<"
728$(YACC) $(PRIVATE_YACCFLAGS) -o $@ $<
729touch $(@:$1=$(YACC_HEADER_SUFFIX))
730echo '#ifndef '$(@F:$1=_h) > $(@:$1=.h)
731echo '#define '$(@F:$1=_h) >> $(@:$1=.h)
732cat $(@:$1=$(YACC_HEADER_SUFFIX)) >> $(@:$1=.h)
733echo '#endif' >> $(@:$1=.h)
734rm -f $(@:$1=$(YACC_HEADER_SUFFIX))
735endef
736
737
738###########################################################
739## Commands for running aidl
740###########################################################
741
742define transform-aidl-to-java
743@mkdir -p $(dir $@)
744@echo "Aidl: $(PRIVATE_MODULE) <= $<"
745$(hide) $(AIDL) -d$(patsubst %.java,%.P,$@) $(PRIVATE_AIDL_FLAGS) $< $@
746endef
747#$(AIDL) $(PRIVATE_AIDL_FLAGS) $< - | indent -nut -br -npcs -l1000 > $@
748
749
Doug Zongker9bd49622009-11-30 14:28:59 -0800750###########################################################
751## Commands for running java-event-log-tags.py
752###########################################################
753
754define transform-logtags-to-java
755@mkdir -p $(dir $@)
756@echo "logtags: $@ <= $<"
Doug Zongkerabfbbe22010-02-16 14:32:08 -0800757$(hide) $(JAVATAGS) -o $@ $^
Doug Zongker9bd49622009-11-30 14:28:59 -0800758endef
759
The Android Open Source Project88b60792009-03-03 19:28:42 -0800760
761###########################################################
Jean-Baptiste Queru79ee7bf2011-01-27 12:19:43 -0800762## Commands for running protoc to compile .proto into .java
763###########################################################
764
765define transform-proto-to-java
766@mkdir -p $(dir $@)
767@echo "Protoc: $@ <= $(PRIVATE_PROTO_SRC_FILES)"
768@rm -rf $(PRIVATE_PROTO_JAVA_OUTPUT_DIR)
769@mkdir -p $(PRIVATE_PROTO_JAVA_OUTPUT_DIR)
770$(hide) $(PROTOC) \
771 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
772 $(PRIVATE_PROTO_JAVA_OUTPUT_OPTION)=$(PRIVATE_PROTO_JAVA_OUTPUT_DIR) \
773 $(PRIVATE_PROTO_SRC_FILES)
774$(hide) touch $@
775endef
776
777######################################################################
778## Commands for running protoc to compile .proto into .pb.cc and .pb.h
779######################################################################
780define transform-proto-to-cc
781@mkdir -p $(dir $@)
782@echo "Protoc: $@ <= $<"
783$(hide) $(PROTOC) \
784 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
785 --cpp_out=$(PRIVATE_PROTO_CC_OUTPUT_DIR) $<
786endef
787
788
789###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800790## Commands for running gcc to compile a C++ file
791###########################################################
792
793define transform-cpp-to-o
794@mkdir -p $(dir $@)
795@echo "target $(PRIVATE_ARM_MODE) C++: $(PRIVATE_MODULE) <= $<"
796$(hide) $(PRIVATE_CXX) \
797 $(foreach incdir, \
Patrick Scott98252562010-02-08 17:28:15 -0500798 $(PRIVATE_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800799 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -0700800 $(PRIVATE_TARGET_PROJECT_INCLUDES) \
801 $(PRIVATE_TARGET_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800802 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800803 , \
804 -I $(incdir) \
805 ) \
806 -c \
807 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -0700808 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
809 $(PRIVATE_TARGET_GLOBAL_CPPFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800810 $(PRIVATE_ARM_CFLAGS) \
811 ) \
812 -fno-rtti \
813 $(PRIVATE_CFLAGS) \
814 $(PRIVATE_CPPFLAGS) \
815 $(PRIVATE_DEBUG_CFLAGS) \
816 -MD -o $@ $<
817$(hide) $(transform-d-to-p)
818endef
819
820
821###########################################################
822## Commands for running gcc to compile a C file
823###########################################################
824
825# $(1): extra flags
826define transform-c-or-s-to-o-no-deps
827@mkdir -p $(dir $@)
828$(hide) $(PRIVATE_CC) \
829 $(foreach incdir, \
Patrick Scott98252562010-02-08 17:28:15 -0500830 $(PRIVATE_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800831 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -0700832 $(PRIVATE_TARGET_PROJECT_INCLUDES) \
833 $(PRIVATE_TARGET_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800834 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800835 , \
836 -I $(incdir) \
837 ) \
838 -c \
839 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -0700840 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800841 $(PRIVATE_ARM_CFLAGS) \
842 ) \
843 $(PRIVATE_CFLAGS) \
844 $(1) \
845 $(PRIVATE_DEBUG_CFLAGS) \
846 -MD -o $@ $<
847endef
848
849define transform-c-to-o-no-deps
850@echo "target $(PRIVATE_ARM_MODE) C: $(PRIVATE_MODULE) <= $<"
851$(call transform-c-or-s-to-o-no-deps, )
852endef
853
854define transform-s-to-o-no-deps
855@echo "target asm: $(PRIVATE_MODULE) <= $<"
856$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
857endef
858
859define transform-c-to-o
860$(transform-c-to-o-no-deps)
861$(hide) $(transform-d-to-p)
862endef
863
864define transform-s-to-o
865$(transform-s-to-o-no-deps)
866$(hide) $(transform-d-to-p)
867endef
868
869###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +0200870## Commands for running gcc to compile an Objective-C file
871## This should never happen for target builds but this
872## will error at build time.
873###########################################################
874
875define transform-m-to-o-no-deps
876@echo "target ObjC: $(PRIVATE_MODULE) <= $<"
877$(call transform-c-or-s-to-o-no-deps)
878endef
879
880define transform-m-to-o
881$(transform-m-to-o-no-deps)
882$(hide) $(transform-d-to-p)
883endef
884
885###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800886## Commands for running gcc to compile a host C++ file
887###########################################################
888
889define transform-host-cpp-to-o
890@mkdir -p $(dir $@)
891@echo "host C++: $(PRIVATE_MODULE) <= $<"
892$(hide) $(PRIVATE_CXX) \
893 $(foreach incdir, \
Patrick Scott98252562010-02-08 17:28:15 -0500894 $(PRIVATE_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800895 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
896 $(HOST_PROJECT_INCLUDES) \
897 $(HOST_C_INCLUDES) \
898 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800899 , \
900 -I $(incdir) \
901 ) \
902 -c \
903 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
904 $(HOST_GLOBAL_CFLAGS) \
905 $(HOST_GLOBAL_CPPFLAGS) \
906 ) \
907 $(PRIVATE_CFLAGS) \
908 $(PRIVATE_CPPFLAGS) \
909 $(PRIVATE_DEBUG_CFLAGS) \
910 -MD -o $@ $<
911$(transform-d-to-p)
912endef
913
914
915###########################################################
916## Commands for running gcc to compile a host C file
917###########################################################
918
919# $(1): extra flags
920define transform-host-c-or-s-to-o-no-deps
921@mkdir -p $(dir $@)
922$(hide) $(PRIVATE_CC) \
923 $(foreach incdir, \
Patrick Scott98252562010-02-08 17:28:15 -0500924 $(PRIVATE_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800925 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
926 $(HOST_PROJECT_INCLUDES) \
927 $(HOST_C_INCLUDES) \
928 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800929 , \
930 -I $(incdir) \
931 ) \
932 -c \
933 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
934 $(HOST_GLOBAL_CFLAGS) \
935 ) \
936 $(PRIVATE_CFLAGS) \
937 $(1) \
938 $(PRIVATE_DEBUG_CFLAGS) \
939 -MD -o $@ $<
940endef
941
942define transform-host-c-to-o-no-deps
943@echo "host C: $(PRIVATE_MODULE) <= $<"
944$(call transform-host-c-or-s-to-o-no-deps, )
945endef
946
947define transform-host-s-to-o-no-deps
948@echo "host asm: $(PRIVATE_MODULE) <= $<"
949$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
950endef
951
952define transform-host-c-to-o
953$(transform-host-c-to-o-no-deps)
954$(transform-d-to-p)
955endef
956
957define transform-host-s-to-o
958$(transform-host-s-to-o-no-deps)
959$(transform-d-to-p)
960endef
961
962###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +0200963## Commands for running gcc to compile a host Objective-C file
964###########################################################
965
966define transform-host-m-to-o-no-deps
967@echo "host ObjC: $(PRIVATE_MODULE) <= $<"
968$(call transform-host-c-or-s-to-o-no-deps)
969endef
970
971define tranform-host-m-to-o
972$(transform-host-m-to-o-no-deps)
973$(transform-d-to-p)
974endef
975
976###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800977## Commands for running ar
978###########################################################
979
Dan Bornstein3d02eac2009-10-21 11:12:56 -0700980define extract-and-include-target-whole-static-libs
Dima Zavin46e9bec2009-05-27 19:41:07 -0700981$(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \
Colin Cross9ca21642010-05-04 15:42:22 -0700982 $(hide) echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(lib)]"; \
Dima Zavin46e9bec2009-05-27 19:41:07 -0700983 ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(lib)))_objs;\
984 rm -rf $$ldir; \
985 mkdir -p $$ldir; \
986 filelist=; \
987 for f in `$(TARGET_AR) t $(lib)`; do \
988 $(TARGET_AR) p $(lib) $$f > $$ldir/$$f; \
989 filelist="$$filelist $$ldir/$$f"; \
990 done ; \
991 $(TARGET_AR) $(TARGET_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $$filelist;\
992)
993endef
994
The Android Open Source Project88b60792009-03-03 19:28:42 -0800995# Explicitly delete the archive first so that ar doesn't
996# try to add to an existing archive.
997define transform-o-to-static-lib
998@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800999@rm -f $@
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001000$(extract-and-include-target-whole-static-libs)
Dima Zavin46e9bec2009-05-27 19:41:07 -07001001@echo "target StaticLib: $(PRIVATE_MODULE) ($@)"
Colin Cross9ca21642010-05-04 15:42:22 -07001002$(hide) echo $(filter %.o, $^) | \
1003 xargs $(TARGET_AR) $(TARGET_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@
The Android Open Source Project88b60792009-03-03 19:28:42 -08001004endef
1005
1006###########################################################
1007## Commands for running host ar
1008###########################################################
1009
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001010define extract-and-include-host-whole-static-libs
1011$(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \
1012 @echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(lib)]"; \
1013 ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(lib)))_objs;\
1014 rm -rf $$ldir; \
1015 mkdir -p $$ldir; \
1016 filelist=; \
Dan Bornstein6581fed2009-10-22 13:14:41 -07001017 for f in `$(HOST_AR) t $(lib) | grep '\.o$$'`; do \
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001018 $(HOST_AR) p $(lib) $$f > $$ldir/$$f; \
1019 filelist="$$filelist $$ldir/$$f"; \
1020 done ; \
1021 $(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $$filelist;\
1022)
1023endef
1024
The Android Open Source Project88b60792009-03-03 19:28:42 -08001025# Explicitly delete the archive first so that ar doesn't
1026# try to add to an existing archive.
1027define transform-host-o-to-static-lib
1028@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001029@rm -f $@
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001030$(extract-and-include-host-whole-static-libs)
Dan Bornstein6bffc912009-10-15 13:01:36 -07001031@echo "host StaticLib: $(PRIVATE_MODULE) ($@)"
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001032echo $(filter %.o, $^) | \
1033 xargs $(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@
The Android Open Source Project88b60792009-03-03 19:28:42 -08001034endef
1035
1036
1037###########################################################
1038## Commands for running gcc to link a shared library or package
1039###########################################################
1040
1041# ld just seems to be so finicky with command order that we allow
1042# it to be overriden en-masse see combo/linux-arm.make for an example.
1043ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1044define transform-host-o-to-shared-lib-inner
David 'Digit' Turner60a1e882011-01-12 23:31:29 +01001045$(PRIVATE_CXX) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001046 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1047 -Wl,-rpath,\$$ORIGIN/../lib \
1048 -shared -Wl,-soname,$(notdir $@) \
1049 $(PRIVATE_LDFLAGS) \
1050 $(HOST_GLOBAL_LD_DIRS) \
1051 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1052 $(HOST_GLOBAL_LDFLAGS) \
1053 ) \
1054 $(PRIVATE_ALL_OBJECTS) \
1055 -Wl,--whole-archive \
1056 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1057 -Wl,--no-whole-archive \
1058 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1059 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1060 -o $@ \
1061 $(PRIVATE_LDLIBS)
1062endef
1063endif
1064
1065define transform-host-o-to-shared-lib
1066@mkdir -p $(dir $@)
1067@echo "host SharedLib: $(PRIVATE_MODULE) ($@)"
1068$(hide) $(transform-host-o-to-shared-lib-inner)
1069endef
1070
1071define transform-host-o-to-package
1072@mkdir -p $(dir $@)
1073@echo "host Package: $(PRIVATE_MODULE) ($@)"
1074$(hide) $(transform-host-o-to-shared-lib-inner)
1075endef
1076
1077
1078###########################################################
1079## Commands for running gcc to link a shared library or package
1080###########################################################
1081
1082#echo >$@.vers "{"; \
1083#echo >>$@.vers " global:"; \
1084#$(BUILD_SYSTEM)/filter_symbols.sh $(TARGET_NM) " " ";" $(filter %.o,$^) | sort -u >>$@.vers; \
1085#echo >>$@.vers " local:"; \
1086#echo >>$@.vers " *;"; \
1087#echo >>$@.vers "};"; \
1088
1089# -Wl,--version-script=$@.vers \
1090
1091# ld just seems to be so finicky with command order that we allow
1092# it to be overriden en-masse see combo/linux-arm.make for an example.
1093ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1094define transform-o-to-shared-lib-inner
David 'Digit' Turner60a1e882011-01-12 23:31:29 +01001095$(PRIVATE_CXX) \
Ying Wang1a081002010-07-13 14:55:47 -07001096 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001097 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1098 -Wl,-rpath,\$$ORIGIN/../lib \
1099 -shared -Wl,-soname,$(notdir $@) \
1100 $(PRIVATE_LDFLAGS) \
Ying Wang1a081002010-07-13 14:55:47 -07001101 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001102 $(PRIVATE_ALL_OBJECTS) \
1103 -Wl,--whole-archive \
1104 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1105 -Wl,--no-whole-archive \
1106 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1107 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1108 -o $@ \
1109 $(PRIVATE_LDLIBS)
1110endef
1111endif
1112
1113define transform-o-to-shared-lib
1114@mkdir -p $(dir $@)
1115@echo "target SharedLib: $(PRIVATE_MODULE) ($@)"
1116$(hide) $(transform-o-to-shared-lib-inner)
1117endef
1118
1119define transform-o-to-package
1120@mkdir -p $(dir $@)
1121@echo "target Package: $(PRIVATE_MODULE) ($@)"
1122$(hide) $(transform-o-to-shared-lib-inner)
1123endef
1124
1125
1126###########################################################
1127## Commands for filtering a target executable or library
1128###########################################################
1129
The Android Open Source Project88b60792009-03-03 19:28:42 -08001130define transform-to-stripped
1131@mkdir -p $(dir $@)
1132@echo "target Strip: $(PRIVATE_MODULE) ($@)"
Bruce Beare45ac4342010-06-24 14:02:00 -07001133$(hide) $(TARGET_STRIP_COMMAND)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001134endef
1135
1136define transform-to-prelinked
1137@mkdir -p $(dir $@)
1138@echo "target Prelink: $(PRIVATE_MODULE) ($@)"
1139$(hide) $(APRIORI) \
1140 --prelinkmap $(TARGET_PRELINKER_MAP) \
1141 --locals-only \
1142 --quiet \
1143 $< \
1144 --output $@
1145endef
1146
1147
1148###########################################################
1149## Commands for running gcc to link an executable
1150###########################################################
1151
1152ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1153define transform-o-to-executable-inner
David 'Digit' Turner60a1e882011-01-12 23:31:29 +01001154$(PRIVATE_CXX) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001155 $(TARGET_GLOBAL_LDFLAGS) \
1156 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1157 $(TARGET_GLOBAL_LD_DIRS) \
1158 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1159 -Wl,-rpath,\$$ORIGIN/../lib \
1160 $(PRIVATE_LDFLAGS) \
1161 $(TARGET_GLOBAL_LD_DIRS) \
1162 $(PRIVATE_ALL_OBJECTS) \
1163 -Wl,--whole-archive \
1164 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1165 -Wl,--no-whole-archive \
1166 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1167 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1168 -o $@ \
1169 $(PRIVATE_LDLIBS)
1170endef
1171endif
1172
1173define transform-o-to-executable
1174@mkdir -p $(dir $@)
1175@echo "target Executable: $(PRIVATE_MODULE) ($@)"
1176$(hide) $(transform-o-to-executable-inner)
1177endef
1178
1179
1180###########################################################
1181## Commands for running gcc to link a statically linked
1182## executable. In practice, we only use this on arm, so
1183## the other platforms don't have the
1184## transform-o-to-static-executable defined
1185###########################################################
1186
1187ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1188define transform-o-to-static-executable-inner
1189endef
1190endif
1191
1192define transform-o-to-static-executable
1193@mkdir -p $(dir $@)
1194@echo "target StaticExecutable: $(PRIVATE_MODULE) ($@)"
1195$(hide) $(transform-o-to-static-executable-inner)
1196endef
1197
1198
1199###########################################################
1200## Commands for running gcc to link a host executable
1201###########################################################
1202
1203ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1204define transform-host-o-to-executable-inner
David 'Digit' Turner60a1e882011-01-12 23:31:29 +01001205$(PRIVATE_CXX) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001206 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1207 -Wl,-rpath,\$$ORIGIN/../lib \
1208 $(HOST_GLOBAL_LD_DIRS) \
1209 $(PRIVATE_LDFLAGS) \
1210 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1211 $(HOST_GLOBAL_LDFLAGS) \
1212 ) \
1213 $(PRIVATE_ALL_OBJECTS) \
1214 -Wl,--whole-archive \
1215 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1216 -Wl,--no-whole-archive \
1217 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1218 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1219 -o $@ \
1220 $(PRIVATE_LDLIBS)
1221endef
1222endif
1223
1224define transform-host-o-to-executable
1225@mkdir -p $(dir $@)
1226@echo "host Executable: $(PRIVATE_MODULE) ($@)"
1227$(hide) $(transform-host-o-to-executable-inner)
1228endef
1229
1230
1231###########################################################
1232## Commands for running javac to make .class files
1233###########################################################
1234
1235#@echo "Source intermediates dir: $(PRIVATE_SOURCE_INTERMEDIATES_DIR)"
1236#@echo "Source intermediates: $$(find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java')"
1237
1238# TODO: Right now we generate the asset resources twice, first as part
1239# of generating the Java classes, then at the end when packaging the final
1240# assets. This should be changed to do one of two things: (1) Don't generate
1241# any resource files the first time, only create classes during that stage;
1242# or (2) Don't use the -c flag with the second stage, instead taking the
1243# resource files from the first stage as additional input. My original intent
1244# was to use approach (2), but this requires a little more work in the tool.
1245# Maybe we should just use approach (1).
1246
1247# This rule creates the R.java and Manifest.java files, both of which
1248# are PRODUCT-neutral. Don't pass PRODUCT_AAPT_CONFIG to this invocation.
1249define create-resource-java-files
1250@mkdir -p $(PRIVATE_SOURCE_INTERMEDIATES_DIR)
1251@mkdir -p $(dir $(PRIVATE_RESOURCE_PUBLICS_OUTPUT))
Ying Wangc61d5932010-03-10 16:02:42 -08001252$(hide) $(AAPT) package $(PRIVATE_AAPT_FLAGS) -m \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001253 $(eval # PRODUCT_AAPT_CONFIG is intentionally missing-- see comment.) \
1254 $(addprefix -J , $(PRIVATE_SOURCE_INTERMEDIATES_DIR)) \
1255 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
1256 $(addprefix -P , $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) \
1257 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
1258 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001259 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
Joe Onorato2daa2b32009-08-30 13:39:24 -07001260 $(addprefix -G , $(PRIVATE_PROGUARD_OPTIONS_FILE)) \
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001261 $(addprefix --min-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
1262 $(addprefix --target-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
Ying Wang1ae607a2010-06-23 13:34:22 -07001263 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \
1264 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION))) \
Ying Wang8c254822010-03-16 16:13:56 -07001265 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07001266 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001267endef
1268
1269ifeq ($(HOST_OS),windows)
1270xlint_unchecked :=
1271else
Jeffrey Chyan7adbf972010-07-07 13:42:19 -05001272xlint_unchecked := -Xlint:unchecked
The Android Open Source Project88b60792009-03-03 19:28:42 -08001273endif
1274
1275# emit-line, <word list>, <output file>
1276define emit-line
1277 $(if $(1),echo -n '$(strip $(1)) ' >> $(2))
1278endef
1279
1280# dump-words-to-file, <word list>, <output file>
1281define dump-words-to-file
1282 @rm -f $(2)
1283 @$(call emit-line,$(wordlist 1,200,$(1)),$(2))
1284 @$(call emit-line,$(wordlist 201,400,$(1)),$(2))
1285 @$(call emit-line,$(wordlist 401,600,$(1)),$(2))
1286 @$(call emit-line,$(wordlist 601,800,$(1)),$(2))
1287 @$(call emit-line,$(wordlist 801,1000,$(1)),$(2))
1288 @$(call emit-line,$(wordlist 1001,1200,$(1)),$(2))
1289 @$(call emit-line,$(wordlist 1201,1400,$(1)),$(2))
1290 @$(call emit-line,$(wordlist 1401,1600,$(1)),$(2))
1291 @$(call emit-line,$(wordlist 1601,1800,$(1)),$(2))
1292 @$(call emit-line,$(wordlist 1801,2000,$(1)),$(2))
1293 @$(call emit-line,$(wordlist 2001,2200,$(1)),$(2))
1294 @$(call emit-line,$(wordlist 2201,2400,$(1)),$(2))
1295 @$(call emit-line,$(wordlist 2401,2600,$(1)),$(2))
1296 @$(call emit-line,$(wordlist 2601,2800,$(1)),$(2))
1297 @$(call emit-line,$(wordlist 2801,3000,$(1)),$(2))
1298 @$(call emit-line,$(wordlist 3001,3200,$(1)),$(2))
1299 @$(call emit-line,$(wordlist 3201,3400,$(1)),$(2))
1300 @$(call emit-line,$(wordlist 3401,3600,$(1)),$(2))
1301 @$(call emit-line,$(wordlist 3601,3800,$(1)),$(2))
1302 @$(call emit-line,$(wordlist 3801,4000,$(1)),$(2))
1303 @$(if $(wordlist 4001,4002,$(1)),$(error Too many words ($(words $(1)))))
1304endef
1305
1306# For a list of jar files, unzip them to a specified directory,
1307# but make sure that no META-INF files come along for the ride.
1308#
1309# $(1): files to unzip
1310# $(2): destination directory
1311define unzip-jar-files
1312 $(hide) for f in $(1); \
1313 do \
1314 if [ ! -f $$f ]; then \
1315 echo Missing file $$f; \
1316 exit 1; \
1317 fi; \
Sriram Ramanf1a55f82009-06-09 15:08:29 -07001318 unzip -qo $$f -d $(2); \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001319 (cd $(2) && rm -rf META-INF); \
1320 done
1321endef
1322
Joe Onorato64d85d02009-04-09 19:31:12 -07001323# below we write the list of java files to java-source-list to avoid argument
1324# list length problems with Cygwin we filter out duplicate java file names
1325# because eclipse's compiler doesn't like them.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001326define transform-java-to-classes.jar
1327@echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
Joe Onorato64d85d02009-04-09 19:31:12 -07001328$(hide) rm -f $@
1329$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1330$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001331$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES), \
1332 $(PRIVATE_CLASS_INTERMEDIATES_DIR))
Joe Onoratoe334d252009-07-17 15:33:40 -04001333$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list)
Joe Onorato64d85d02009-04-09 19:31:12 -07001334$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
Joe Onoratoe334d252009-07-17 15:33:40 -04001335 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 -08001336fi
Joe Onoratoe334d252009-07-17 15:33:40 -04001337$(hide) tr ' ' '\n' < $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list \
1338 | sort -u > $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list-uniq
The Android Open Source Project88b60792009-03-03 19:28:42 -08001339$(hide) $(TARGET_JAVAC) -encoding ascii $(PRIVATE_BOOTCLASSPATH) \
1340 $(addprefix -classpath ,$(strip \
1341 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \
Jeffrey Chyan7adbf972010-07-07 13:42:19 -05001342 $(PRIVATE_JAVACFLAGS) $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) \
1343 $(if $(findstring true,$(LOCAL_WARNINGS_ENABLE)),$(xlint_unchecked),) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001344 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
Joe Onoratoe334d252009-07-17 15:33:40 -04001345 \@$(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list-uniq \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001346 || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 )
Joe Onoratoe334d252009-07-17 15:33:40 -04001347$(hide) rm -f $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list
1348$(hide) rm -f $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list-uniq
Joe Onorato64d85d02009-04-09 19:31:12 -07001349$(hide) mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001350$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \
1351 $@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
Joe Onorato64d85d02009-04-09 19:31:12 -07001352$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001353endef
1354
1355define transform-classes.jar-to-emma
1356$(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \
Guang Zhu18b75562010-05-13 16:46:21 -07001357 $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR) \
Guang Zhu9cd3d8c2010-06-15 13:31:25 -07001358 $(addprefix -ix , $(PRIVATE_EMMA_COVERAGE_FILTER))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001359endef
1360
1361#TODO: use a smaller -Xmx value for most libraries;
1362# only core.jar and framework.jar need a heap this big.
Raphaelf6ff4c52009-08-18 14:43:32 -07001363# 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 -08001364define transform-classes.jar-to-dex
1365@echo "target Dex: $(PRIVATE_MODULE)"
1366@mkdir -p $(dir $@)
Raphaelf6ff4c52009-08-18 14:43:32 -07001367$(hide) $(DX) \
1368 $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx1536M) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001369 --dex --output=$@ \
1370 $(if $(NO_OPTIMIZE_DX), \
1371 --no-optimize) \
1372 $(if $(GENERATE_DEX_DEBUG), \
1373 --debug --verbose \
1374 --dump-to=$(@:.dex=.lst) \
1375 --dump-width=1000) \
1376 $(PRIVATE_DX_FLAGS) \
1377 $<
1378endef
1379
1380# Create a mostly-empty .jar file that we'll add to later.
1381# The MacOS jar tool doesn't like creating empty jar files,
1382# so we need to give it something.
1383define create-empty-package
1384@mkdir -p $(dir $@)
1385$(hide) touch $(dir $@)/dummy
1386$(hide) (cd $(dir $@) && jar cf $(notdir $@) dummy)
1387$(hide) zip -qd $@ dummy
1388$(hide) rm $(dir $@)/dummy
1389endef
1390
1391#TODO: we kinda want to build different asset packages for
1392# different configurations, then combine them later (or something).
1393# Per-locale, etc.
1394# A list of dynamic and static parameters; build layers for
1395# dynamic params that lay over the static ones.
1396#TODO: update the manifest to point to the package file
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001397#Note that the version numbers are given to aapt as simple default
1398#values; applications can override these by explicitly stating
1399#them in their manifest.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001400define add-assets-to-package
Ying Wangc61d5932010-03-10 16:02:42 -08001401$(hide) $(AAPT) package -u $(PRIVATE_AAPT_FLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001402 $(addprefix -c , $(PRODUCT_AAPT_CONFIG)) \
1403 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
1404 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
1405 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
1406 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001407 $(addprefix --min-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
1408 $(addprefix --target-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
Joe Onorato700b88e2010-10-05 17:33:58 -04001409 $(addprefix --product , $(TARGET_AAPT_CHARACTERISTICS)) \
Ying Wang1ae607a2010-06-23 13:34:22 -07001410 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \
1411 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION))) \
Jeff Hamiltonbb67d212010-02-05 22:36:42 -06001412 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07001413 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001414 -F $@
1415endef
1416
The Android Open Source Project88b60792009-03-03 19:28:42 -08001417define add-jni-shared-libs-to-package
1418$(hide) rm -rf $(dir $@)lib
Bruce Beare5b9f19e2010-05-05 09:47:16 -07001419$(hide) mkdir -p $(dir $@)lib/$(TARGET_CPU_ABI)
1420$(hide) cp $(PRIVATE_JNI_SHARED_LIBRARIES) $(dir $@)lib/$(TARGET_CPU_ABI)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001421$(hide) (cd $(dir $@) && zip -r $(notdir $@) lib)
1422$(hide) rm -rf $(dir $@)lib
1423endef
1424
The Android Open Source Project88b60792009-03-03 19:28:42 -08001425#TODO: update the manifest to point to the dex file
1426define add-dex-to-package
Ying Wang957fea52010-09-23 11:48:38 -07001427$(if $(filter classes.dex,$(notdir $(PRIVATE_DEX_FILE))),\
1428$(hide) $(AAPT) add -k $@ $(PRIVATE_DEX_FILE),\
1429$(eval _adtp_classes.dex := $(dir $(PRIVATE_DEX_FILE))/classes.dex)\
1430$(hide) cp $(PRIVATE_DEX_FILE) $(_adtp_classes.dex) && \
1431$(AAPT) add -k $@ $(_adtp_classes.dex) && \
1432rm -f $(_adtp_classes.dex))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001433endef
1434
1435define add-java-resources-to-package
1436$(hide) jar uf $@ $(PRIVATE_EXTRA_JAR_ARGS)
1437endef
1438
1439# Sign a package using the specified key/cert.
1440#
1441define sign-package
1442$(hide) mv $@ $@.unsigned
1443$(hide) java -jar $(SIGNAPK_JAR) \
1444 $(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) $@.unsigned $@.signed
1445$(hide) mv $@.signed $@
1446endef
1447
1448# Align STORED entries of a package on 4-byte boundaries
1449# to make them easier to mmap.
1450#
1451define align-package
1452$(hide) mv $@ $@.unaligned
1453$(hide) $(ZIPALIGN) -f 4 $@.unaligned $@.aligned
1454$(hide) mv $@.aligned $@
1455endef
1456
1457define install-dex-debug
1458$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.dex" ]; then \
1459 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
1460 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.dex \
1461 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).dex; \
1462 fi
1463$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.lst" ]; then \
1464 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
1465 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.lst \
1466 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).lst; \
1467 fi
1468endef
1469
1470# TODO(joeo): If we can ever upgrade to post 3.81 make and get the
1471# new prebuilt rules to work, we should change this to copy the
1472# resources to the out directory and then copy the resources.
1473
1474# Note: not using aapt tool for this because we aren't making
1475# an android package for the host.
1476define transform-host-java-to-package
1477@echo "host Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
1478@rm -f $@
1479@rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1480@mkdir -p $(dir $@)
1481@mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1482$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES), \
1483 $(PRIVATE_CLASS_INTERMEDIATES_DIR))
1484$(call dump-words-to-file,$(sort\
1485 $(PRIVATE_JAVA_SOURCES)),\
Joe Onorato483d9242009-06-18 13:11:58 -07001486 $(PRIVATE_INTERMEDIATES_DIR)/java-source-list-uniq)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001487$(hide) $(HOST_JAVAC) -encoding ascii -g \
Brian Carlstromf184a0f2010-02-01 11:13:32 -08001488 $(PRIVATE_JAVACFLAGS) $(xlint_unchecked) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001489 $(addprefix -classpath ,$(strip \
1490 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \
1491 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR)\
Joe Onorato483d9242009-06-18 13:11:58 -07001492 \@$(PRIVATE_INTERMEDIATES_DIR)/java-source-list-uniq || \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001493 ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 )
Joe Onorato483d9242009-06-18 13:11:58 -07001494$(hide) rm -f $(PRIVATE_INTERMEDIATES_DIR)/java-source-list
1495$(hide) rm -f $(PRIVATE_INTERMEDIATES_DIR)/java-source-list-uniq
The Android Open Source Project88b60792009-03-03 19:28:42 -08001496$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \
1497 $@ $(PRIVATE_JAR_MANIFEST) $(PRIVATE_EXTRA_JAR_ARGS) \
1498 -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
1499endef
1500
1501###########################################################
1502## Obfuscate a jar file
1503###########################################################
1504
1505# PRIVATE_KEEP_FILE is a file containing a list of classes
1506# PRIVATE_INTERMEDIATES_DIR is a directory we can use for temporary files
1507# The module using this must depend on
1508# $(HOST_OUT_JAVA_LIBRARIES)/proguard-4.0.1.jar
1509define obfuscate-jar
1510@echo "Obfuscate jar: $(notdir $@) ($@)"
1511@mkdir -p $(dir $@)
1512@rm -f $@
1513@mkdir -p $(PRIVATE_INTERMEDIATES_DIR)
1514$(hide) sed -e 's/^/-keep class /' < $(PRIVATE_KEEP_FILE) > \
1515 $(PRIVATE_INTERMEDIATES_DIR)/keep.pro
1516$(hide) java -Xmx512M -jar $(HOST_OUT_JAVA_LIBRARIES)/proguard-4.0.1.jar \
1517 -injars $< \
1518 -outjars $@ \
1519 -target 1.5 \
1520 -dontnote -dontwarn \
1521 -printmapping $(PRIVATE_INTERMEDIATES_DIR)/out.map \
1522 -forceprocessing \
1523 -renamesourcefileattribute SourceFile \
1524 -keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod \
1525 -repackageclasses \
1526 -keepclassmembers "class * { public protected *; }" \
1527 @$(PRIVATE_INTERMEDIATES_DIR)/keep.pro
1528endef
1529
1530###########################################################
1531## Commands for copying files
1532###########################################################
1533
1534# Define a rule to copy a header. Used via $(eval) by copy_headers.make.
1535# $(1): source header
1536# $(2): destination header
1537define copy-one-header
1538$(2): $(1)
1539 @echo "Header: $$@"
1540 $$(copy-file-to-new-target-with-cp)
1541endef
1542
1543# Define a rule to copy a file. For use via $(eval).
1544# $(1): source file
1545# $(2): destination file
1546define copy-one-file
1547$(2): $(1) | $(ACP)
1548 @echo "Copy: $$@"
1549 $$(copy-file-to-target)
1550endef
1551
1552# The -t option to acp and the -p option to cp is
1553# required for OSX. OSX has a ridiculous restriction
1554# where it's an error for a .a file's modification time
1555# to disagree with an internal timestamp, and this
1556# macro is used to install .a files (among other things).
1557
1558# Copy a single file from one place to another,
1559# preserving permissions and overwriting any existing
1560# file.
1561define copy-file-to-target
1562@mkdir -p $(dir $@)
1563$(hide) $(ACP) -fpt $< $@
1564endef
1565
1566# The same as copy-file-to-target, but use the local
1567# cp command instead of acp.
1568define copy-file-to-target-with-cp
1569@mkdir -p $(dir $@)
1570$(hide) cp -fp $< $@
1571endef
1572
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07001573# The same as copy-file-to-target, but use the zipalign tool to do so.
1574define copy-file-to-target-with-zipalign
1575@mkdir -p $(dir $@)
1576$(hide) $(ZIPALIGN) -f 4 $< $@
1577endef
1578
Doug Zongker1046d202009-08-06 13:02:19 -07001579# The same as copy-file-to-target, but strip out "# comment"-style
1580# comments (for config files and such).
1581define copy-file-to-target-strip-comments
1582@mkdir -p $(dir $@)
1583$(hide) sed -e 's/#.*$$//' -e 's/[ \t]*$$//' -e '/^$$/d' < $< > $@
1584endef
1585
The Android Open Source Project88b60792009-03-03 19:28:42 -08001586# The same as copy-file-to-target, but don't preserve
1587# the old modification time.
1588define copy-file-to-new-target
1589@mkdir -p $(dir $@)
1590$(hide) $(ACP) -fp $< $@
1591endef
1592
1593# The same as copy-file-to-new-target, but use the local
1594# cp command instead of acp.
1595define copy-file-to-new-target-with-cp
1596@mkdir -p $(dir $@)
1597$(hide) cp -f $< $@
1598endef
1599
1600# Copy a prebuilt file to a target location.
1601define transform-prebuilt-to-target
1602@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"
1603$(copy-file-to-target)
1604endef
1605
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07001606# Copy a prebuilt file to a target location, using zipalign on it.
1607define transform-prebuilt-to-target-with-zipalign
1608@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt APK: $(PRIVATE_MODULE) ($@)"
1609$(copy-file-to-target-with-zipalign)
1610endef
1611
Doug Zongker1046d202009-08-06 13:02:19 -07001612# Copy a prebuilt file to a target location, stripping "# comment" comments.
1613define transform-prebuilt-to-target-strip-comments
1614@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"
1615$(copy-file-to-target-strip-comments)
1616endef
1617
The Android Open Source Project88b60792009-03-03 19:28:42 -08001618###########################################################
1619## On some platforms (MacOS), after copying a static
1620## library, ranlib must be run to update an internal
1621## timestamp!?!?!
1622###########################################################
1623
1624ifeq ($(HOST_RUN_RANLIB_AFTER_COPYING),true)
1625define transform-host-ranlib-copy-hack
1626 $(hide) ranlib $@ || true
1627endef
1628else
1629define transform-host-ranlib-copy-hack
1630true
1631endef
1632endif
1633
1634ifeq ($(TARGET_RUN_RANLIB_AFTER_COPYING),true)
1635define transform-ranlib-copy-hack
1636 $(hide) ranlib $@
1637endef
1638else
1639define transform-ranlib-copy-hack
1640true
1641endef
1642endif
1643
1644
1645###########################################################
Ying Wang3b2bdf12010-02-01 09:51:23 -08001646## Commands to call Proguard
1647###########################################################
1648
1649# Command to copy the file with acp, if proguard is disabled.
1650define proguard-disabled-commands
1651@echo Copying: $@
1652$(hide) $(ACP) $< $@
1653endef
1654
1655# Command to call Proguard
1656# $(1): extra flags for instrumentation.
1657define proguard-enabled-commands
1658@echo Proguard: $@
1659$(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS) $(1)
1660endef
1661
1662# Figure out the proguard dictionary file of the module that is instrumentationed for.
1663define get-instrumentation-proguard-flags
1664$(if $(PRIVATE_INSTRUMENTATION_FOR),$(if $(ALL_MODULES.$(PRIVATE_INSTRUMENTATION_FOR).PROGUARD_ENABLED),-applymapping $(call intermediates-dir-for,APPS,$(PRIVATE_INSTRUMENTATION_FOR),,COMMON)/proguard_dictionary))
1665endef
1666
1667define transform-jar-to-proguard
1668$(eval _instrumentation_proguard_flags:=$(call get-instrumentation-proguard-flags))
1669$(eval _enable_proguard:=$(PRIVATE_PROGUARD_ENABLED)$(_instrumentation_proguard_flags))
1670$(if $(_enable_proguard),$(call proguard-enabled-commands,$(_instrumentation_proguard_flags)),$(call proguard-disabled-commands))
1671$(eval _instrumentation_proguard_flags:=)
1672$(eval _enable_proguard:=)
1673endef
1674
1675
1676###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001677## Stuff source generated from one-off tools
1678###########################################################
1679
1680define transform-generated-source
1681@echo "target Generated: $(PRIVATE_MODULE) <= $<"
1682@mkdir -p $(dir $@)
1683$(hide) $(PRIVATE_CUSTOM_TOOL)
1684endef
1685
1686
1687###########################################################
1688## Assertions about attributes of the target
1689###########################################################
1690
1691# $(1): The file to check
1692ifndef get-file-size
1693$(error HOST_OS must define get-file-size)
1694endif
1695
Doug Zongker4647f122009-07-02 09:00:54 -07001696# Convert a partition data size (eg, as reported in /proc/mtd) to the
1697# size of the image used to flash that partition (which includes a
Lars Svensson9cb8c282010-12-06 15:24:58 +01001698# spare area for each page).
Doug Zongker4647f122009-07-02 09:00:54 -07001699# $(1): the partition data size
1700define image-size-from-data-size
Lars Svensson9cb8c282010-12-06 15:24:58 +01001701$(shell echo $$(($(1) / $(BOARD_NAND_PAGE_SIZE) * \
1702 ($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE)))))
Doug Zongker4647f122009-07-02 09:00:54 -07001703endef
1704
1705# $(1): The file(s) to check (often $@)
1706# $(2): The maximum total image size, in decimal bytes
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001707# $(3): the type of filesystem "yaffs" or "raw"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001708#
1709# If $(2) is empty, evaluates to "true"
1710#
1711# Reserve bad blocks. Make sure that MAX(1% of partition size, 2 blocks)
1712# is left over after the image has been flashed. Round the 1% up to the
1713# next whole flash block size.
1714define assert-max-file-size
1715$(if $(2), \
Doug Zongker742fa572009-07-08 12:09:04 -07001716 size=$$(for i in $(1); do $(call get-file-size,$$i); echo +; done; echo 0); \
1717 total=$$(( $$( echo "$$size" ) )); \
Doug Zongker4647f122009-07-02 09:00:54 -07001718 printname=$$(echo -n "$(1)" | tr " " +); \
1719 echo "$$printname total size is $$total"; \
1720 img_blocksize=$(call image-size-from-data-size,$(BOARD_FLASH_BLOCK_SIZE)); \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001721 if [ "$(3)" == "yaffs" ]; then \
Doug Zongker93d9ff42009-09-14 17:46:41 -07001722 reservedblocks=8; \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001723 else \
Doug Zongker4ac1ba62009-08-25 20:38:50 -07001724 reservedblocks=0; \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001725 fi; \
Doug Zongker4647f122009-07-02 09:00:54 -07001726 twoblocks=$$((img_blocksize * 2)); \
1727 onepct=$$((((($(2) / 100) - 1) / img_blocksize + 1) * img_blocksize)); \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001728 reserve=$$(((twoblocks > onepct ? twoblocks : onepct) + \
1729 reservedblocks * img_blocksize)); \
Doug Zongker4647f122009-07-02 09:00:54 -07001730 maxsize=$$(($(2) - reserve)); \
1731 if [ "$$total" -gt "$$maxsize" ]; then \
1732 echo "error: $$printname too large ($$total > [$(2) - $$reserve])"; \
1733 false; \
Doug Zongker742fa572009-07-08 12:09:04 -07001734 elif [ "$$total" -gt $$((maxsize - 32768)) ]; then \
Doug Zongker4647f122009-07-02 09:00:54 -07001735 echo "WARNING: $$printname approaching size limit ($$total now; limit $$maxsize)"; \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001736 fi \
1737 , \
1738 true \
1739 )
1740endef
1741
Doug Zongker8510a1e2009-08-07 16:38:08 -07001742# Like assert-max-file-size, but the second argument is a partition
1743# size, which we'll convert to a max image size before checking it
1744# against the files.
1745#
1746# $(1): The file(s) to check (often $@)
1747# $(2): The partition size.
1748define assert-max-image-size
1749$(if $(2), \
1750 $(call assert-max-file-size,$(1),$(call image-size-from-data-size,$(2))), \
1751 true)
1752endef
1753
Doug Zongkere01100c2009-06-19 17:12:18 -07001754
1755###########################################################
1756## Define device-specific radio files
1757###########################################################
1758
1759# Copy a radio image file to the output location, and add it to
1760# INSTALLED_RADIOIMAGE_TARGET.
1761# $(1): filename
1762define add-radio-file
Doug Zongker14833602010-02-02 13:12:04 -08001763 $(eval $(call add-radio-file-internal,$(1),$(notdir $(1))))
Doug Zongkere01100c2009-06-19 17:12:18 -07001764endef
1765define add-radio-file-internal
Doug Zongker14833602010-02-02 13:12:04 -08001766INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
1767ALL_PREBUILT += $$(PRODUCT_OUT)/$(2)
1768$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP)
Doug Zongkere01100c2009-06-19 17:12:18 -07001769 $$(transform-prebuilt-to-target)
1770endef
1771
1772
The Android Open Source Project88b60792009-03-03 19:28:42 -08001773###########################################################
Joe Onorato899e62a2010-02-04 17:37:21 -08001774# Override the package defined in $(1), setting the
1775# variables listed below differently.
1776#
1777# $(1): The makefile to override (relative to the source
1778# tree root)
1779# $(2): Old LOCAL_PACKAGE_NAME value.
1780# $(3): New LOCAL_PACKAGE_NAME value.
Ying Wang3dae0ee2010-09-02 15:41:01 -07001781# $(4): New LOCAL_MANIFEST_PACKAGE_NAME value.
1782# $(5): New LOCAL_CERTIFICATE value.
1783# $(6): New LOCAL_INSTRUMENTATION_FOR value.
1784# $(7): New LOCAL_MANIFEST_INSTRUMENTATION_FOR value.
Joe Onorato899e62a2010-02-04 17:37:21 -08001785#
1786# Note that LOCAL_PACKAGE_OVERRIDES is NOT cleared in
1787# clear_vars.mk.
1788###########################################################
1789define inherit-package
Ying Wang3dae0ee2010-09-02 15:41:01 -07001790 $(eval $(call inherit-package-internal,$(1),$(2),$(3),$(4),$(5),$(6),$(7)))
Joe Onorato899e62a2010-02-04 17:37:21 -08001791endef
1792
1793define inherit-package-internal
1794 LOCAL_PACKAGE_OVERRIDES \
Ying Wang3dae0ee2010-09-02 15:41:01 -07001795 := $(strip $(1))||$(strip $(2))||$(strip $(3))||$(strip $(4))||&&$(strip $(5))||&&$(strip $(6))||&&$(strip $(7)) $(LOCAL_PACKAGE_OVERRIDES)
Joe Onorato899e62a2010-02-04 17:37:21 -08001796 include $(1)
1797 LOCAL_PACKAGE_OVERRIDES \
1798 := $(wordlist 1,$(words $(LOCAL_PACKAGE_OVERRIDES)), $(LOCAL_PACKAGE_OVERRIDES))
1799endef
1800
1801# To be used with inherit-package above
1802# Evalutes to true if the package was overridden
1803define set-inherited-package-variables
1804$(strip $(call set-inherited-package-variables-internal))
1805endef
1806
1807define keep-or-override
1808$(eval $(1) := $(if $(2),$(2),$($(1))))
1809endef
1810
1811define set-inherited-package-variables-internal
1812 $(eval _o := $(subst ||, ,$(lastword $(LOCAL_PACKAGE_OVERRIDES))))
1813 $(eval _n := $(subst ||, ,$(firstword $(LOCAL_PACKAGE_OVERRIDES))))
1814 $(if $(filter $(word 2,$(_n)),$(LOCAL_PACKAGE_NAME)), \
1815 $(eval LOCAL_PACKAGE_NAME := $(word 3,$(_o))) \
1816 $(eval LOCAL_MANIFEST_PACKAGE_NAME := $(word 4,$(_o))) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07001817 $(call keep-or-override,LOCAL_CERTIFICATE,$(patsubst &&%,%,$(word 5,$(_o)))) \
1818 $(call keep-or-override,LOCAL_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 6,$(_o)))) \
1819 $(call keep-or-override,LOCAL_MANIFEST_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 7,$(_o)))) \
Joe Onorato899e62a2010-02-04 17:37:21 -08001820 $(eval LOCAL_OVERRIDES_PACKAGES := $(sort $(LOCAL_OVERRIDES_PACKAGES) $(word 2,$(_o)))) \
1821 true \
1822 ,)
1823endef
1824
1825
1826###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001827## Other includes
1828###########################################################
1829
1830# -----------------------------------------------------------------
1831# Rules and functions to help copy important files to DIST_DIR
1832# when requested.
1833include $(BUILD_SYSTEM)/distdir.mk
1834
Jean-Baptiste Queru39de4322010-09-03 16:32:58 -07001835# -----------------------------------------------------------------
1836# The modules allowed to use a user tag
1837include $(BUILD_SYSTEM)/user_tags.mk
The Android Open Source Project88b60792009-03-03 19:28:42 -08001838
1839# broken:
1840# $(foreach file,$^,$(if $(findstring,.a,$(suffix $file)),-l$(file),$(file)))
1841
1842###########################################################
1843## Misc notes
1844###########################################################
1845
1846#DEPDIR = .deps
1847#df = $(DEPDIR)/$(*F)
1848
1849#SRCS = foo.c bar.c ...
1850
1851#%.o : %.c
1852# @$(MAKEDEPEND); \
1853# cp $(df).d $(df).P; \
1854# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
1855# -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \
1856# rm -f $(df).d
1857# $(COMPILE.c) -o $@ $<
1858
1859#-include $(SRCS:%.c=$(DEPDIR)/%.P)
1860
1861
1862#%.o : %.c
1863# $(COMPILE.c) -MD -o $@ $<
1864# @cp $*.d $*.P; \
1865# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
1866# -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \
1867# rm -f $*.d