blob: c236c0ebbe0fd1938f64a16dbd84f23e760d72db [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 Wanga5fc87a2010-11-02 18:43:16 -0700239## 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###########################################################
Ying Wang0bd59a02010-07-15 17:17:52 -0700252## Find all of the RenderScript files under the named directories.
253## Meant to be used like:
254## SRC_FILES := $(call all-renderscript-files-under,src)
255###########################################################
256
257define all-renderscript-files-under
258$(patsubst ./%,%, \
259 $(shell cd $(LOCAL_PATH) ; \
260 find $(1) -name "*.rs" -and -not -name ".*") \
261 )
262endef
263
264###########################################################
Jean-Baptiste Queru0a3cfdc2009-12-17 17:47:28 -0800265## Find all of the html files under the named directories.
266## Meant to be used like:
267## SRC_FILES := $(call all-html-files-under,src tests)
268###########################################################
269
270define all-html-files-under
271$(patsubst ./%,%, \
272 $(shell cd $(LOCAL_PATH) ; \
273 find $(1) -name "*.html" -and -not -name ".*") \
274 )
275endef
276
277###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800278## Find all of the html files from here. Meant to be used like:
279## SRC_FILES := $(call all-subdir-html-files)
280###########################################################
281
282define all-subdir-html-files
Jean-Baptiste Queru0a3cfdc2009-12-17 17:47:28 -0800283$(call all-html-files-under,.)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800284endef
285
286###########################################################
287## Find all of the files matching pattern
288## SRC_FILES := $(call find-subdir-files, <pattern>)
289###########################################################
290
291define find-subdir-files
292$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) ; find $(1)))
293endef
294
295###########################################################
296# find the files in the subdirectory $1 of LOCAL_DIR
297# matching pattern $2, filtering out files $3
298# e.g.
299# SRC_FILES += $(call find-subdir-subdir-files, \
300# css, *.cpp, DontWantThis.cpp)
301###########################################################
302
303define find-subdir-subdir-files
304$(filter-out $(patsubst %,$(1)/%,$(3)),$(patsubst ./%,%,$(shell cd \
305 $(LOCAL_PATH) ; find $(1) -maxdepth 1 -name $(2))))
306endef
307
308###########################################################
309## Find all of the files matching pattern
310## SRC_FILES := $(call all-subdir-java-files)
311###########################################################
312
313define find-subdir-assets
314$(if $(1),$(patsubst ./%,%, \
315 $(shell if [ -d $(1) ] ; then cd $(1) ; find ./ -type f -and -not -type l ; fi)), \
316 $(warning Empty argument supplied to find-subdir-assets) \
317)
318endef
319
320###########################################################
321## Find various file types in a list of directories relative to $(LOCAL_PATH)
322###########################################################
323
324define find-other-java-files
325 $(call find-subdir-files,$(1) -name "*.java" -and -not -name ".*")
326endef
327
328define find-other-html-files
329 $(call find-subdir-files,$(1) -name "*.html" -and -not -name ".*")
330endef
331
332###########################################################
333## Scan through each directory of $(1) looking for files
334## that match $(2) using $(wildcard). Useful for seeing if
335## a given directory or one of its parents contains
336## a particular file. Returns the first match found,
337## starting furthest from the root.
338###########################################################
339
340define find-parent-file
341$(strip \
342 $(eval _fpf := $(wildcard $(strip $(1))/$(strip $(2)))) \
343 $(if $(_fpf),$(_fpf), \
344 $(if $(filter-out ./ .,$(1)), \
345 $(call find-parent-file,$(patsubst %/,%,$(dir $(1))),$(2)) \
346 ) \
347 ) \
348)
349endef
350
351###########################################################
352## Function we can evaluate to introduce a dynamic dependency
353###########################################################
354
355define add-dependency
356$(1): $(2)
357endef
358
359###########################################################
360## Set up the dependencies for a prebuilt target
361## $(call add-prebuilt-file, srcfile, [targetclass])
362###########################################################
363
364define add-prebuilt-file
365 $(eval $(include-prebuilt))
366endef
367
368define include-prebuilt
369 include $$(CLEAR_VARS)
370 LOCAL_SRC_FILES := $(1)
371 LOCAL_BUILT_MODULE_STEM := $(1)
372 LOCAL_MODULE_SUFFIX := $$(suffix $(1))
373 LOCAL_MODULE := $$(basename $(1))
374 LOCAL_MODULE_CLASS := $(2)
375 include $$(BUILD_PREBUILT)
376endef
377
378###########################################################
379## do multiple prebuilts
380## $(call target class, files ...)
381###########################################################
382
383define add-prebuilt-files
384 $(foreach f,$(2),$(call add-prebuilt-file,$f,$(1)))
385endef
386
387
388
389###########################################################
390## The intermediates directory. Where object files go for
391## a given target. We could technically get away without
392## the "_intermediates" suffix on the directory, but it's
393## nice to be able to grep for that string to find out if
394## anyone's abusing the system.
395###########################################################
396
397# $(1): target class, like "APPS"
398# $(2): target name, like "NotePad"
399# $(3): if non-empty, this is a HOST target.
400# $(4): if non-empty, force the intermediates to be COMMON
401define intermediates-dir-for
402$(strip \
403 $(eval _idfClass := $(strip $(1))) \
404 $(if $(_idfClass),, \
405 $(error $(LOCAL_PATH): Class not defined in call to intermediates-dir-for)) \
406 $(eval _idfName := $(strip $(2))) \
407 $(if $(_idfName),, \
408 $(error $(LOCAL_PATH): Name not defined in call to intermediates-dir-for)) \
409 $(eval _idfPrefix := $(if $(strip $(3)),HOST,TARGET)) \
Ying Wanga83940f2010-09-24 18:09:04 -0700410 $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800411 $(eval _idfIntBase := $($(_idfPrefix)_OUT_COMMON_INTERMEDIATES)) \
412 , \
413 $(eval _idfIntBase := $($(_idfPrefix)_OUT_INTERMEDIATES)) \
414 ) \
415 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
416)
417endef
418
419# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE
420# to determine the intermediates directory.
421#
422# $(1): if non-empty, force the intermediates to be COMMON
423define local-intermediates-dir
424$(strip \
425 $(if $(strip $(LOCAL_MODULE_CLASS)),, \
426 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-intermediates-dir)) \
427 $(if $(strip $(LOCAL_MODULE)),, \
428 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-intermediates-dir)) \
429 $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(LOCAL_IS_HOST_MODULE),$(1)) \
430)
431endef
432
433###########################################################
434## Convert "path/to/libXXX.so" to "-lXXX".
435## Any "path/to/libXXX.a" elements pass through unchanged.
436###########################################################
437
438define normalize-libraries
439$(foreach so,$(filter %.so,$(1)),-l$(patsubst lib%.so,%,$(notdir $(so))))\
440$(filter-out %.so,$(1))
441endef
442
443# TODO: change users to call the common version.
444define normalize-host-libraries
445$(call normalize-libraries,$(1))
446endef
447
448define normalize-target-libraries
449$(call normalize-libraries,$(1))
450endef
451
452###########################################################
453## Convert a list of short module names (e.g., "framework", "Browser")
454## into the list of files that are built for those modules.
455## NOTE: this won't return reliable results until after all
456## sub-makefiles have been included.
457## $(1): target list
458###########################################################
459
460define module-built-files
461$(foreach module,$(1),$(ALL_MODULES.$(module).BUILT))
462endef
463
464###########################################################
465## Convert a list of short modules names (e.g., "framework", "Browser")
466## into the list of files that are installed for those modules.
467## NOTE: this won't return reliable results until after all
468## sub-makefiles have been included.
469## $(1): target list
470###########################################################
471
472define module-installed-files
473$(foreach module,$(1),$(ALL_MODULES.$(module).INSTALLED))
474endef
475
476###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700477## Convert a list of short modules names (e.g., "framework", "Browser")
478## into the list of files that should be used when linking
479## against that module as a public API.
480## TODO: Allow this for more than JAVA_LIBRARIES modules
481## NOTE: this won't return reliable results until after all
482## sub-makefiles have been included.
483## $(1): target list
484###########################################################
485
486define module-stubs-files
487$(foreach module,$(1),$(ALL_MODULES.$(module).STUBS))
488endef
489
490###########################################################
491## Evaluates to the timestamp file for a doc module, which
492## is the dependency that should be used.
493## $(1): doc module
494###########################################################
495
496define doc-timestamp-for
497$(OUT_DOCS)/$(strip $(1))-timestamp
498endef
499
500
501###########################################################
Ying Wang912f8282010-09-28 17:27:56 -0700502## Convert "core ext framework" to "out/.../javalib.jar ..."
The Android Open Source Project88b60792009-03-03 19:28:42 -0800503## $(1): library list
504## $(2): Non-empty if IS_HOST_MODULE
505###########################################################
506
507# $(1): library name
508# $(2): Non-empty if IS_HOST_MODULE
509define _java-lib-dir
510$(call intermediates-dir-for, \
Ying Wang912f8282010-09-28 17:27:56 -0700511 JAVA_LIBRARIES,$(1),$(2),COMMON)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800512endef
513
514# $(1): library name
515# $(2): Non-empty if IS_HOST_MODULE
516define _java-lib-full-classes.jar
Ying Wang912f8282010-09-28 17:27:56 -0700517$(call _java-lib-dir,$(1),$(2))/classes$(COMMON_JAVA_PACKAGE_SUFFIX)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800518endef
519
520# $(1): library name list
521# $(2): Non-empty if IS_HOST_MODULE
522define java-lib-files
523$(foreach lib,$(1),$(call _java-lib-full-classes.jar,$(lib),$(2)))
524endef
525
526# $(1): library name
The Android Open Source Project88b60792009-03-03 19:28:42 -0800527# $(2): Non-empty if IS_HOST_MODULE
528define _java-lib-full-dep
Ying Wang912f8282010-09-28 17:27:56 -0700529$(call _java-lib-dir,$(1),$(2))/javalib$(COMMON_JAVA_PACKAGE_SUFFIX)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800530endef
531
532# $(1): library name list
533# $(2): Non-empty if IS_HOST_MODULE
534define java-lib-deps
535$(foreach lib,$(1),$(call _java-lib-full-dep,$(lib),$(2)))
536endef
537
538###########################################################
Joe Onorato8dc8faa2010-09-14 13:09:48 -0400539## Run rot13 on a string
540## $(1): the string. Must be one line.
541###########################################################
542define rot13
543$(shell echo $(1) | tr 'a-zA-Z' 'n-za-mN-ZA-M')
544endef
545
546
547###########################################################
548## Returns true if $(1) and $(2) are equal. Returns
549## the empty string if they are not equal.
550###########################################################
551define streq
552$(strip $(if $(strip $(1)),\
553 $(if $(strip $(2)),\
554 $(if $(filter-out __,_$(subst $(strip $(1)),,$(strip $(2)))$(subst $(strip $(2)),,$(strip $(1)))_),,true), \
555 ),\
556 $(if $(strip $(2)),\
557 ,\
558 true)\
559 ))
560endef
561
562###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800563## Convert "a b c" into "a:b:c"
564###########################################################
565
566empty :=
567space := $(empty) $(empty)
568
569define normalize-path-list
570$(subst $(space),:,$(strip $(1)))
571endef
572
573###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700574## Read the word out of a colon-separated list of words.
575## This has the same behavior as the built-in function
576## $(word n,str).
577##
578## The individual words may not contain spaces.
579##
580## $(1): 1 based index
581## $(2): value of the form a:b:c...
582###########################################################
583
584define word-colon
585$(word $(1),$(subst :,$(space),$(2)))
586endef
587
588###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800589## Convert "a=b c= d e = f" into "a=b c=d e=f"
590##
591## $(1): list to collapse
592## $(2): if set, separator word; usually "=", ":", or ":="
593## Defaults to "=" if not set.
594###########################################################
595
596define collapse-pairs
597$(eval _cpSEP := $(strip $(if $(2),$(2),=)))\
598$(subst $(space)$(_cpSEP)$(space),$(_cpSEP),$(strip \
599 $(subst $(_cpSEP), $(_cpSEP) ,$(1))))
600endef
601
The Android Open Source Project88b60792009-03-03 19:28:42 -0800602###########################################################
603## MODULE_TAG set operations
604###########################################################
605
606# Given a list of tags, return the targets that specify
607# any of those tags.
608# $(1): tag list
609define modules-for-tag-list
610$(sort $(foreach tag,$(1),$(ALL_MODULE_TAGS.$(tag))))
611endef
612
613# Same as modules-for-tag-list, but operates on
614# ALL_MODULE_NAME_TAGS.
615# $(1): tag list
616define module-names-for-tag-list
617$(sort $(foreach tag,$(1),$(ALL_MODULE_NAME_TAGS.$(tag))))
618endef
619
620# Given an accept and reject list, find the matching
621# set of targets. If a target has multiple tags and
622# any of them are rejected, the target is rejected.
623# Reject overrides accept.
624# $(1): list of tags to accept
625# $(2): list of tags to reject
626#TODO(dbort): do $(if $(strip $(1)),$(1),$(ALL_MODULE_TAGS))
Jean-Baptiste Queru75127b72010-01-07 11:44:22 -0800627#TODO(jbq): as of 20100106 nobody uses the second parameter
The Android Open Source Project88b60792009-03-03 19:28:42 -0800628define get-tagged-modules
629$(filter-out \
630 $(call modules-for-tag-list,$(2)), \
631 $(call modules-for-tag-list,$(1)))
632endef
633
Joe Onorato64d85d02009-04-09 19:31:12 -0700634###########################################################
635## Append a leaf to a base path. Properly deals with
636## base paths ending in /.
637##
638## $(1): base path
639## $(2): leaf path
640###########################################################
641
642define append-path
643$(subst //,/,$(1)/$(2))
644endef
645
The Android Open Source Project88b60792009-03-03 19:28:42 -0800646
647###########################################################
648## Package filtering
649###########################################################
650
651# Given a list of installed modules (short or long names)
652# return a list of the packages (yes, .apk packages, not
653# modules in general) that are overridden by this list and,
654# therefore, should not be installed.
655# $(1): mixed list of installed modules
656# TODO: This is fragile; find a reliable way to get this information.
657define _get-package-overrides
658 $(eval ### Discard any words containing slashes, unless they end in .apk, \
659 ### in which case trim off the directory component and the suffix. \
660 ### If there are no slashes, keep the entire word.)
661 $(eval _gpo_names := $(subst /,@@@ @@@,$(1)))
662 $(eval _gpo_names := \
663 $(filter %.apk,$(_gpo_names)) \
664 $(filter-out %@@@ @@@%,$(_gpo_names)))
665 $(eval _gpo_names := $(patsubst %.apk,%,$(_gpo_names)))
666 $(eval _gpo_names := $(patsubst @@@%,%,$(_gpo_names)))
667
668 $(eval ### Remove any remaining words that contain dots.)
669 $(eval _gpo_names := $(subst .,@@@ @@@,$(_gpo_names)))
670 $(eval _gpo_names := $(filter-out %@@@ @@@%,$(_gpo_names)))
671
672 $(eval ### Now we have a list of any words that could possibly refer to \
673 ### packages, although there may be words that do not. Only \
674 ### real packages will be present under PACKAGES.*, though.)
675 $(foreach _gpo_name,$(_gpo_names),$(PACKAGES.$(_gpo_name).OVERRIDES))
676endef
677
678define get-package-overrides
679$(strip $(sort $(call _get-package-overrides,$(1))))
680endef
681
682###########################################################
683## Output the command lines, or not
684###########################################################
685
686ifeq ($(strip $(SHOW_COMMANDS)),)
687define pretty
688@echo $1
689endef
690hide := @
691else
692define pretty
693endef
694hide :=
695endif
696
697###########################################################
698## Dump the variables that are associated with targets
699###########################################################
700
701define dump-module-variables
702@echo all_dependencies=$^
703@echo PRIVATE_YACCFLAGS=$(PRIVATE_YACCFLAGS);
704@echo PRIVATE_CFLAGS=$(PRIVATE_CFLAGS);
705@echo PRIVATE_CPPFLAGS=$(PRIVATE_CPPFLAGS);
706@echo PRIVATE_DEBUG_CFLAGS=$(PRIVATE_DEBUG_CFLAGS);
707@echo PRIVATE_C_INCLUDES=$(PRIVATE_C_INCLUDES);
708@echo PRIVATE_LDFLAGS=$(PRIVATE_LDFLAGS);
709@echo PRIVATE_LDLIBS=$(PRIVATE_LDLIBS);
710@echo PRIVATE_ARFLAGS=$(PRIVATE_ARFLAGS);
711@echo PRIVATE_AAPT_FLAGS=$(PRIVATE_AAPT_FLAGS);
712@echo PRIVATE_DX_FLAGS=$(PRIVATE_DX_FLAGS);
Brian Carlstromf184a0f2010-02-01 11:13:32 -0800713@echo PRIVATE_JAVACFLAGS=$(PRIVATE_JAVACFLAGS);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800714@echo PRIVATE_JAVA_LIBRARIES=$(PRIVATE_JAVA_LIBRARIES);
715@echo PRIVATE_ALL_SHARED_LIBRARIES=$(PRIVATE_ALL_SHARED_LIBRARIES);
716@echo PRIVATE_ALL_STATIC_LIBRARIES=$(PRIVATE_ALL_STATIC_LIBRARIES);
717@echo PRIVATE_ALL_WHOLE_STATIC_LIBRARIES=$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES);
718@echo PRIVATE_ALL_OBJECTS=$(PRIVATE_ALL_OBJECTS);
719endef
720
721###########################################################
722## Commands for using sed to replace given variable values
723###########################################################
724
725define transform-variables
726@mkdir -p $(dir $@)
727@echo "Sed: $(if $(PRIVATE_MODULE),$(PRIVATE_MODULE),$@) <= $<"
728$(hide) sed $(foreach var,$(REPLACE_VARS),-e "s/{{$(var)}}/$(subst /,\/,$(PWD)/$($(var)))/g") $< >$@
729$(hide) if [ "$(suffix $@)" = ".sh" ]; then chmod a+rx $@; fi
730endef
731
732
733###########################################################
734## Commands for munging the dependency files GCC generates
735###########################################################
736
737define transform-d-to-p
738@cp $(@:%.o=%.d) $(@:%.o=%.P); \
739 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
740 -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
741 rm -f $(@:%.o=%.d)
742endef
743
744###########################################################
745## Commands for running lex
746###########################################################
747
748define transform-l-to-cpp
749@mkdir -p $(dir $@)
750@echo "Lex: $(PRIVATE_MODULE) <= $<"
751$(hide) $(LEX) -o$@ $<
752endef
753
754###########################################################
755## Commands for running yacc
756##
757## Because the extension of c++ files can change, the
758## extension must be specified in $1.
759## E.g, "$(call transform-y-to-cpp,.cpp)"
760###########################################################
761
762define transform-y-to-cpp
763@mkdir -p $(dir $@)
764@echo "Yacc: $(PRIVATE_MODULE) <= $<"
765$(YACC) $(PRIVATE_YACCFLAGS) -o $@ $<
766touch $(@:$1=$(YACC_HEADER_SUFFIX))
767echo '#ifndef '$(@F:$1=_h) > $(@:$1=.h)
768echo '#define '$(@F:$1=_h) >> $(@:$1=.h)
769cat $(@:$1=$(YACC_HEADER_SUFFIX)) >> $(@:$1=.h)
770echo '#endif' >> $(@:$1=.h)
771rm -f $(@:$1=$(YACC_HEADER_SUFFIX))
772endef
773
Ying Wang0bd59a02010-07-15 17:17:52 -0700774###########################################################
775## Commands to compile RenderScript
776###########################################################
Ying Wang0bd59a02010-07-15 17:17:52 -0700777
778define transform-renderscripts-to-java-and-bc
779@echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)"
780$(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR)
781$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/res/raw
782$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/src
Shih-wei Liaod01fadb2010-10-08 16:57:46 -0700783$(hide) $(LLVM_RS_CC) \
Ying Wangebfddaa2010-07-30 18:37:29 -0700784 -o $(PRIVATE_RS_OUTPUT_DIR)/res/raw \
785 -p $(PRIVATE_RS_OUTPUT_DIR)/src \
Ying Wang24e1c012010-10-07 18:57:57 -0700786 -d $(PRIVATE_RS_OUTPUT_DIR) \
787 -a $@ -MD \
Ying Wang51280272010-09-01 13:28:52 -0700788 $(foreach inc,$(PRIVATE_RS_INCLUDES),$(addprefix -I , $(inc))) \
Ying Wangebfddaa2010-07-30 18:37:29 -0700789 $(PRIVATE_RS_SOURCE_FILES)
Shih-wei Liaoc6560302010-10-23 03:07:13 -0700790#$(hide) $(LLVM_RS_LINK) \
791# $(PRIVATE_RS_OUTPUT_DIR)/res/raw/*.bc
Ying Wang0bd59a02010-07-15 17:17:52 -0700792$(hide) mkdir -p $(dir $@)
793$(hide) touch $@
794endef
795
The Android Open Source Project88b60792009-03-03 19:28:42 -0800796
797###########################################################
798## Commands for running aidl
799###########################################################
800
801define transform-aidl-to-java
802@mkdir -p $(dir $@)
803@echo "Aidl: $(PRIVATE_MODULE) <= $<"
804$(hide) $(AIDL) -d$(patsubst %.java,%.P,$@) $(PRIVATE_AIDL_FLAGS) $< $@
805endef
806#$(AIDL) $(PRIVATE_AIDL_FLAGS) $< - | indent -nut -br -npcs -l1000 > $@
807
808
Doug Zongker9bd49622009-11-30 14:28:59 -0800809###########################################################
810## Commands for running java-event-log-tags.py
811###########################################################
812
813define transform-logtags-to-java
814@mkdir -p $(dir $@)
815@echo "logtags: $@ <= $<"
Doug Zongkerabfbbe22010-02-16 14:32:08 -0800816$(hide) $(JAVATAGS) -o $@ $^
Doug Zongker9bd49622009-11-30 14:28:59 -0800817endef
818
The Android Open Source Project88b60792009-03-03 19:28:42 -0800819
820###########################################################
Ying Wanga5fc87a2010-11-02 18:43:16 -0700821## Commands for running protoc to compile .proto into .java
822###########################################################
823
824define transform-proto-to-java
825@mkdir -p $(dir $@)
826@echo "Protoc: $@ <= $(PRIVATE_PROTO_SRC_FILES)"
827@rm -rf $(PRIVATE_PROTO_JAVA_OUTPUT_DIR)
828@mkdir -p $(PRIVATE_PROTO_JAVA_OUTPUT_DIR)
829$(hide) $(PROTOC) \
830 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
831 $(PRIVATE_PROTO_JAVA_OUTPUT_OPTION)=$(PRIVATE_PROTO_JAVA_OUTPUT_DIR) \
832 $(PRIVATE_PROTO_SRC_FILES)
833$(hide) touch $@
834endef
835
836######################################################################
837## Commands for running protoc to compile .proto into .pb.cc and .pb.h
838######################################################################
839define transform-proto-to-cc
840@mkdir -p $(dir $@)
841@echo "Protoc: $@ <= $<"
842$(hide) $(PROTOC) \
843 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
844 --cpp_out=$(PRIVATE_PROTO_CC_OUTPUT_DIR) $<
845endef
846
847
848###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800849## Commands for running gcc to compile a C++ file
850###########################################################
851
852define transform-cpp-to-o
853@mkdir -p $(dir $@)
854@echo "target $(PRIVATE_ARM_MODE) C++: $(PRIVATE_MODULE) <= $<"
855$(hide) $(PRIVATE_CXX) \
856 $(foreach incdir, \
Patrick Scott98252562010-02-08 17:28:15 -0500857 $(PRIVATE_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800858 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -0700859 $(PRIVATE_TARGET_PROJECT_INCLUDES) \
860 $(PRIVATE_TARGET_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800861 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800862 , \
863 -I $(incdir) \
864 ) \
865 -c \
866 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -0700867 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
868 $(PRIVATE_TARGET_GLOBAL_CPPFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800869 $(PRIVATE_ARM_CFLAGS) \
870 ) \
871 -fno-rtti \
872 $(PRIVATE_CFLAGS) \
873 $(PRIVATE_CPPFLAGS) \
874 $(PRIVATE_DEBUG_CFLAGS) \
875 -MD -o $@ $<
876$(hide) $(transform-d-to-p)
877endef
878
879
880###########################################################
881## Commands for running gcc to compile a C file
882###########################################################
883
884# $(1): extra flags
885define transform-c-or-s-to-o-no-deps
886@mkdir -p $(dir $@)
887$(hide) $(PRIVATE_CC) \
888 $(foreach incdir, \
Patrick Scott98252562010-02-08 17:28:15 -0500889 $(PRIVATE_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800890 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -0700891 $(PRIVATE_TARGET_PROJECT_INCLUDES) \
892 $(PRIVATE_TARGET_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800893 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800894 , \
895 -I $(incdir) \
896 ) \
897 -c \
898 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -0700899 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800900 $(PRIVATE_ARM_CFLAGS) \
901 ) \
902 $(PRIVATE_CFLAGS) \
903 $(1) \
904 $(PRIVATE_DEBUG_CFLAGS) \
905 -MD -o $@ $<
906endef
907
908define transform-c-to-o-no-deps
909@echo "target $(PRIVATE_ARM_MODE) C: $(PRIVATE_MODULE) <= $<"
910$(call transform-c-or-s-to-o-no-deps, )
911endef
912
913define transform-s-to-o-no-deps
914@echo "target asm: $(PRIVATE_MODULE) <= $<"
915$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
916endef
917
918define transform-c-to-o
919$(transform-c-to-o-no-deps)
920$(hide) $(transform-d-to-p)
921endef
922
923define transform-s-to-o
924$(transform-s-to-o-no-deps)
925$(hide) $(transform-d-to-p)
926endef
927
928###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +0200929## Commands for running gcc to compile an Objective-C file
930## This should never happen for target builds but this
931## will error at build time.
932###########################################################
933
934define transform-m-to-o-no-deps
935@echo "target ObjC: $(PRIVATE_MODULE) <= $<"
936$(call transform-c-or-s-to-o-no-deps)
937endef
938
939define transform-m-to-o
940$(transform-m-to-o-no-deps)
941$(hide) $(transform-d-to-p)
942endef
943
944###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800945## Commands for running gcc to compile a host C++ file
946###########################################################
947
948define transform-host-cpp-to-o
949@mkdir -p $(dir $@)
950@echo "host C++: $(PRIVATE_MODULE) <= $<"
951$(hide) $(PRIVATE_CXX) \
952 $(foreach incdir, \
Patrick Scott98252562010-02-08 17:28:15 -0500953 $(PRIVATE_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800954 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
955 $(HOST_PROJECT_INCLUDES) \
956 $(HOST_C_INCLUDES) \
957 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800958 , \
959 -I $(incdir) \
960 ) \
961 -c \
962 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
963 $(HOST_GLOBAL_CFLAGS) \
964 $(HOST_GLOBAL_CPPFLAGS) \
965 ) \
966 $(PRIVATE_CFLAGS) \
967 $(PRIVATE_CPPFLAGS) \
968 $(PRIVATE_DEBUG_CFLAGS) \
969 -MD -o $@ $<
970$(transform-d-to-p)
971endef
972
973
974###########################################################
975## Commands for running gcc to compile a host C file
976###########################################################
977
978# $(1): extra flags
979define transform-host-c-or-s-to-o-no-deps
980@mkdir -p $(dir $@)
981$(hide) $(PRIVATE_CC) \
982 $(foreach incdir, \
Patrick Scott98252562010-02-08 17:28:15 -0500983 $(PRIVATE_C_INCLUDES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800984 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
985 $(HOST_PROJECT_INCLUDES) \
986 $(HOST_C_INCLUDES) \
987 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800988 , \
989 -I $(incdir) \
990 ) \
991 -c \
992 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
993 $(HOST_GLOBAL_CFLAGS) \
994 ) \
995 $(PRIVATE_CFLAGS) \
996 $(1) \
997 $(PRIVATE_DEBUG_CFLAGS) \
998 -MD -o $@ $<
999endef
1000
1001define transform-host-c-to-o-no-deps
1002@echo "host C: $(PRIVATE_MODULE) <= $<"
1003$(call transform-host-c-or-s-to-o-no-deps, )
1004endef
1005
1006define transform-host-s-to-o-no-deps
1007@echo "host asm: $(PRIVATE_MODULE) <= $<"
1008$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
1009endef
1010
1011define transform-host-c-to-o
1012$(transform-host-c-to-o-no-deps)
1013$(transform-d-to-p)
1014endef
1015
1016define transform-host-s-to-o
1017$(transform-host-s-to-o-no-deps)
1018$(transform-d-to-p)
1019endef
1020
1021###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001022## Commands for running gcc to compile a host Objective-C file
1023###########################################################
1024
1025define transform-host-m-to-o-no-deps
1026@echo "host ObjC: $(PRIVATE_MODULE) <= $<"
1027$(call transform-host-c-or-s-to-o-no-deps)
1028endef
1029
1030define tranform-host-m-to-o
1031$(transform-host-m-to-o-no-deps)
1032$(transform-d-to-p)
1033endef
1034
1035###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001036## Commands for running ar
1037###########################################################
1038
Ying Wange4b24eb2010-05-27 11:55:39 -07001039define _concat-if-arg2-not-empty
1040$(if $(2),$(hide) $(1) $(2))
1041endef
1042
1043# Split long argument list into smaller groups and call the command repeatedly
1044#
1045# $(1): the command without arguments
1046# $(2): the arguments
1047define split-long-arguments
1048$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1,500,$(2)))
1049$(call _concat-if-arg2-not-empty,$(1),$(wordlist 501,1000,$(2)))
1050$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1001,1500,$(2)))
1051$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1501,2000,$(2)))
1052$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2001,2500,$(2)))
1053$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2501,3000,$(2)))
1054$(call _concat-if-arg2-not-empty,$(1),$(wordlist 3001,99999,$(2)))
1055endef
1056
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001057define extract-and-include-target-whole-static-libs
Dima Zavin46e9bec2009-05-27 19:41:07 -07001058$(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \
Colin Cross9ca21642010-05-04 15:42:22 -07001059 $(hide) echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(lib)]"; \
Dima Zavin46e9bec2009-05-27 19:41:07 -07001060 ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(lib)))_objs;\
1061 rm -rf $$ldir; \
1062 mkdir -p $$ldir; \
1063 filelist=; \
1064 for f in `$(TARGET_AR) t $(lib)`; do \
1065 $(TARGET_AR) p $(lib) $$f > $$ldir/$$f; \
1066 filelist="$$filelist $$ldir/$$f"; \
1067 done ; \
1068 $(TARGET_AR) $(TARGET_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $$filelist;\
1069)
1070endef
1071
The Android Open Source Project88b60792009-03-03 19:28:42 -08001072# Explicitly delete the archive first so that ar doesn't
1073# try to add to an existing archive.
1074define transform-o-to-static-lib
1075@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001076@rm -f $@
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001077$(extract-and-include-target-whole-static-libs)
Dima Zavin46e9bec2009-05-27 19:41:07 -07001078@echo "target StaticLib: $(PRIVATE_MODULE) ($@)"
Ying Wange4b24eb2010-05-27 11:55:39 -07001079$(call split-long-arguments,$(TARGET_AR) $(TARGET_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@,$(filter %.o, $^))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001080endef
1081
1082###########################################################
1083## Commands for running host ar
1084###########################################################
1085
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001086define extract-and-include-host-whole-static-libs
1087$(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \
Ying Wange4b24eb2010-05-27 11:55:39 -07001088 $(hide) echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(lib)]"; \
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001089 ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(lib)))_objs;\
1090 rm -rf $$ldir; \
1091 mkdir -p $$ldir; \
1092 filelist=; \
Dan Bornstein6581fed2009-10-22 13:14:41 -07001093 for f in `$(HOST_AR) t $(lib) | grep '\.o$$'`; do \
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001094 $(HOST_AR) p $(lib) $$f > $$ldir/$$f; \
1095 filelist="$$filelist $$ldir/$$f"; \
1096 done ; \
1097 $(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $$filelist;\
1098)
1099endef
1100
The Android Open Source Project88b60792009-03-03 19:28:42 -08001101# Explicitly delete the archive first so that ar doesn't
1102# try to add to an existing archive.
1103define transform-host-o-to-static-lib
1104@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001105@rm -f $@
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001106$(extract-and-include-host-whole-static-libs)
Dan Bornstein6bffc912009-10-15 13:01:36 -07001107@echo "host StaticLib: $(PRIVATE_MODULE) ($@)"
Ying Wange4b24eb2010-05-27 11:55:39 -07001108$(call split-long-arguments,$(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@,$(filter %.o, $^))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001109endef
1110
1111
1112###########################################################
1113## Commands for running gcc to link a shared library or package
1114###########################################################
1115
1116# ld just seems to be so finicky with command order that we allow
1117# it to be overriden en-masse see combo/linux-arm.make for an example.
1118ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1119define transform-host-o-to-shared-lib-inner
1120$(HOST_CXX) \
1121 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1122 -Wl,-rpath,\$$ORIGIN/../lib \
1123 -shared -Wl,-soname,$(notdir $@) \
1124 $(PRIVATE_LDFLAGS) \
1125 $(HOST_GLOBAL_LD_DIRS) \
1126 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1127 $(HOST_GLOBAL_LDFLAGS) \
1128 ) \
1129 $(PRIVATE_ALL_OBJECTS) \
1130 -Wl,--whole-archive \
1131 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1132 -Wl,--no-whole-archive \
1133 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1134 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1135 -o $@ \
1136 $(PRIVATE_LDLIBS)
1137endef
1138endif
1139
1140define transform-host-o-to-shared-lib
1141@mkdir -p $(dir $@)
1142@echo "host SharedLib: $(PRIVATE_MODULE) ($@)"
1143$(hide) $(transform-host-o-to-shared-lib-inner)
1144endef
1145
1146define transform-host-o-to-package
1147@mkdir -p $(dir $@)
1148@echo "host Package: $(PRIVATE_MODULE) ($@)"
1149$(hide) $(transform-host-o-to-shared-lib-inner)
1150endef
1151
1152
1153###########################################################
1154## Commands for running gcc to link a shared library or package
1155###########################################################
1156
1157#echo >$@.vers "{"; \
1158#echo >>$@.vers " global:"; \
1159#$(BUILD_SYSTEM)/filter_symbols.sh $(TARGET_NM) " " ";" $(filter %.o,$^) | sort -u >>$@.vers; \
1160#echo >>$@.vers " local:"; \
1161#echo >>$@.vers " *;"; \
1162#echo >>$@.vers "};"; \
1163
1164# -Wl,--version-script=$@.vers \
1165
1166# ld just seems to be so finicky with command order that we allow
1167# it to be overriden en-masse see combo/linux-arm.make for an example.
1168ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1169define transform-o-to-shared-lib-inner
1170$(TARGET_CXX) \
Ying Wang1a081002010-07-13 14:55:47 -07001171 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001172 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1173 -Wl,-rpath,\$$ORIGIN/../lib \
1174 -shared -Wl,-soname,$(notdir $@) \
1175 $(PRIVATE_LDFLAGS) \
Ying Wang1a081002010-07-13 14:55:47 -07001176 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001177 $(PRIVATE_ALL_OBJECTS) \
1178 -Wl,--whole-archive \
1179 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1180 -Wl,--no-whole-archive \
1181 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1182 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1183 -o $@ \
1184 $(PRIVATE_LDLIBS)
1185endef
1186endif
1187
1188define transform-o-to-shared-lib
1189@mkdir -p $(dir $@)
1190@echo "target SharedLib: $(PRIVATE_MODULE) ($@)"
1191$(hide) $(transform-o-to-shared-lib-inner)
1192endef
1193
1194define transform-o-to-package
1195@mkdir -p $(dir $@)
1196@echo "target Package: $(PRIVATE_MODULE) ($@)"
1197$(hide) $(transform-o-to-shared-lib-inner)
1198endef
1199
1200
1201###########################################################
1202## Commands for filtering a target executable or library
1203###########################################################
1204
The Android Open Source Project88b60792009-03-03 19:28:42 -08001205define transform-to-stripped
1206@mkdir -p $(dir $@)
1207@echo "target Strip: $(PRIVATE_MODULE) ($@)"
Bruce Beare45ac4342010-06-24 14:02:00 -07001208$(hide) $(TARGET_STRIP_COMMAND)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001209endef
1210
1211define transform-to-prelinked
1212@mkdir -p $(dir $@)
1213@echo "target Prelink: $(PRIVATE_MODULE) ($@)"
1214$(hide) $(APRIORI) \
1215 --prelinkmap $(TARGET_PRELINKER_MAP) \
1216 --locals-only \
1217 --quiet \
1218 $< \
1219 --output $@
1220endef
1221
1222
1223###########################################################
1224## Commands for running gcc to link an executable
1225###########################################################
1226
1227ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1228define transform-o-to-executable-inner
1229$(TARGET_CXX) \
1230 $(TARGET_GLOBAL_LDFLAGS) \
1231 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1232 $(TARGET_GLOBAL_LD_DIRS) \
1233 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1234 -Wl,-rpath,\$$ORIGIN/../lib \
1235 $(PRIVATE_LDFLAGS) \
1236 $(TARGET_GLOBAL_LD_DIRS) \
1237 $(PRIVATE_ALL_OBJECTS) \
1238 -Wl,--whole-archive \
1239 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1240 -Wl,--no-whole-archive \
1241 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1242 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1243 -o $@ \
1244 $(PRIVATE_LDLIBS)
1245endef
1246endif
1247
1248define transform-o-to-executable
1249@mkdir -p $(dir $@)
1250@echo "target Executable: $(PRIVATE_MODULE) ($@)"
1251$(hide) $(transform-o-to-executable-inner)
1252endef
1253
1254
1255###########################################################
1256## Commands for running gcc to link a statically linked
1257## executable. In practice, we only use this on arm, so
1258## the other platforms don't have the
1259## transform-o-to-static-executable defined
1260###########################################################
1261
1262ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1263define transform-o-to-static-executable-inner
1264endef
1265endif
1266
1267define transform-o-to-static-executable
1268@mkdir -p $(dir $@)
1269@echo "target StaticExecutable: $(PRIVATE_MODULE) ($@)"
1270$(hide) $(transform-o-to-static-executable-inner)
1271endef
1272
1273
1274###########################################################
1275## Commands for running gcc to link a host executable
1276###########################################################
1277
1278ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1279define transform-host-o-to-executable-inner
1280$(HOST_CXX) \
1281 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1282 -Wl,-rpath,\$$ORIGIN/../lib \
1283 $(HOST_GLOBAL_LD_DIRS) \
1284 $(PRIVATE_LDFLAGS) \
1285 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1286 $(HOST_GLOBAL_LDFLAGS) \
1287 ) \
1288 $(PRIVATE_ALL_OBJECTS) \
1289 -Wl,--whole-archive \
1290 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1291 -Wl,--no-whole-archive \
1292 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1293 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1294 -o $@ \
1295 $(PRIVATE_LDLIBS)
1296endef
1297endif
1298
1299define transform-host-o-to-executable
1300@mkdir -p $(dir $@)
1301@echo "host Executable: $(PRIVATE_MODULE) ($@)"
1302$(hide) $(transform-host-o-to-executable-inner)
1303endef
1304
1305
1306###########################################################
1307## Commands for running javac to make .class files
1308###########################################################
1309
1310#@echo "Source intermediates dir: $(PRIVATE_SOURCE_INTERMEDIATES_DIR)"
1311#@echo "Source intermediates: $$(find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java')"
1312
1313# TODO: Right now we generate the asset resources twice, first as part
1314# of generating the Java classes, then at the end when packaging the final
1315# assets. This should be changed to do one of two things: (1) Don't generate
1316# any resource files the first time, only create classes during that stage;
1317# or (2) Don't use the -c flag with the second stage, instead taking the
1318# resource files from the first stage as additional input. My original intent
1319# was to use approach (2), but this requires a little more work in the tool.
1320# Maybe we should just use approach (1).
1321
1322# This rule creates the R.java and Manifest.java files, both of which
1323# are PRODUCT-neutral. Don't pass PRODUCT_AAPT_CONFIG to this invocation.
1324define create-resource-java-files
1325@mkdir -p $(PRIVATE_SOURCE_INTERMEDIATES_DIR)
1326@mkdir -p $(dir $(PRIVATE_RESOURCE_PUBLICS_OUTPUT))
Ying Wangc61d5932010-03-10 16:02:42 -08001327$(hide) $(AAPT) package $(PRIVATE_AAPT_FLAGS) -m \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001328 $(eval # PRODUCT_AAPT_CONFIG is intentionally missing-- see comment.) \
1329 $(addprefix -J , $(PRIVATE_SOURCE_INTERMEDIATES_DIR)) \
1330 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
1331 $(addprefix -P , $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) \
1332 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
1333 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001334 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
Joe Onorato2daa2b32009-08-30 13:39:24 -07001335 $(addprefix -G , $(PRIVATE_PROGUARD_OPTIONS_FILE)) \
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001336 $(addprefix --min-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
1337 $(addprefix --target-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
Ying Wang1ae607a2010-06-23 13:34:22 -07001338 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \
Ying Wang8f5069b2010-06-29 11:08:13 -07001339 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION)-$(BUILD_NUMBER))) \
Ying Wang8c254822010-03-16 16:13:56 -07001340 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07001341 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001342endef
1343
1344ifeq ($(HOST_OS),windows)
1345xlint_unchecked :=
1346else
Jeffrey Chyan7adbf972010-07-07 13:42:19 -05001347xlint_unchecked := -Xlint:unchecked
The Android Open Source Project88b60792009-03-03 19:28:42 -08001348endif
1349
1350# emit-line, <word list>, <output file>
1351define emit-line
1352 $(if $(1),echo -n '$(strip $(1)) ' >> $(2))
1353endef
1354
1355# dump-words-to-file, <word list>, <output file>
1356define dump-words-to-file
1357 @rm -f $(2)
1358 @$(call emit-line,$(wordlist 1,200,$(1)),$(2))
1359 @$(call emit-line,$(wordlist 201,400,$(1)),$(2))
1360 @$(call emit-line,$(wordlist 401,600,$(1)),$(2))
1361 @$(call emit-line,$(wordlist 601,800,$(1)),$(2))
1362 @$(call emit-line,$(wordlist 801,1000,$(1)),$(2))
1363 @$(call emit-line,$(wordlist 1001,1200,$(1)),$(2))
1364 @$(call emit-line,$(wordlist 1201,1400,$(1)),$(2))
1365 @$(call emit-line,$(wordlist 1401,1600,$(1)),$(2))
1366 @$(call emit-line,$(wordlist 1601,1800,$(1)),$(2))
1367 @$(call emit-line,$(wordlist 1801,2000,$(1)),$(2))
1368 @$(call emit-line,$(wordlist 2001,2200,$(1)),$(2))
1369 @$(call emit-line,$(wordlist 2201,2400,$(1)),$(2))
1370 @$(call emit-line,$(wordlist 2401,2600,$(1)),$(2))
1371 @$(call emit-line,$(wordlist 2601,2800,$(1)),$(2))
1372 @$(call emit-line,$(wordlist 2801,3000,$(1)),$(2))
1373 @$(call emit-line,$(wordlist 3001,3200,$(1)),$(2))
1374 @$(call emit-line,$(wordlist 3201,3400,$(1)),$(2))
1375 @$(call emit-line,$(wordlist 3401,3600,$(1)),$(2))
1376 @$(call emit-line,$(wordlist 3601,3800,$(1)),$(2))
1377 @$(call emit-line,$(wordlist 3801,4000,$(1)),$(2))
Jesse Wilson72c941a2010-05-04 16:33:49 -07001378 @$(call emit-line,$(wordlist 4001,4200,$(1)),$(2))
1379 @$(call emit-line,$(wordlist 4201,4400,$(1)),$(2))
1380 @$(call emit-line,$(wordlist 4401,4600,$(1)),$(2))
1381 @$(call emit-line,$(wordlist 4601,4800,$(1)),$(2))
1382 @$(call emit-line,$(wordlist 4801,5000,$(1)),$(2))
1383 @$(if $(wordlist 5001,5002,$(1)),$(error Too many words ($(words $(1)))))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001384endef
1385
1386# For a list of jar files, unzip them to a specified directory,
1387# but make sure that no META-INF files come along for the ride.
1388#
1389# $(1): files to unzip
1390# $(2): destination directory
1391define unzip-jar-files
1392 $(hide) for f in $(1); \
1393 do \
1394 if [ ! -f $$f ]; then \
1395 echo Missing file $$f; \
1396 exit 1; \
1397 fi; \
Sriram Ramanf1a55f82009-06-09 15:08:29 -07001398 unzip -qo $$f -d $(2); \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001399 (cd $(2) && rm -rf META-INF); \
1400 done
1401endef
1402
Joe Onorato64d85d02009-04-09 19:31:12 -07001403# below we write the list of java files to java-source-list to avoid argument
1404# list length problems with Cygwin we filter out duplicate java file names
1405# because eclipse's compiler doesn't like them.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001406define transform-java-to-classes.jar
1407@echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
Joe Onorato64d85d02009-04-09 19:31:12 -07001408$(hide) rm -f $@
1409$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1410$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001411$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES), \
1412 $(PRIVATE_CLASS_INTERMEDIATES_DIR))
Joe Onoratoe334d252009-07-17 15:33:40 -04001413$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list)
Joe Onorato64d85d02009-04-09 19:31:12 -07001414$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
Joe Onoratoe334d252009-07-17 15:33:40 -04001415 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 -08001416fi
Joe Onoratoe334d252009-07-17 15:33:40 -04001417$(hide) tr ' ' '\n' < $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list \
1418 | sort -u > $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list-uniq
The Android Open Source Project88b60792009-03-03 19:28:42 -08001419$(hide) $(TARGET_JAVAC) -encoding ascii $(PRIVATE_BOOTCLASSPATH) \
1420 $(addprefix -classpath ,$(strip \
1421 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \
Jeffrey Chyan7adbf972010-07-07 13:42:19 -05001422 $(PRIVATE_JAVACFLAGS) $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) \
1423 $(if $(findstring true,$(LOCAL_WARNINGS_ENABLE)),$(xlint_unchecked),) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001424 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
Joe Onoratoe334d252009-07-17 15:33:40 -04001425 \@$(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list-uniq \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001426 || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 )
Joe Onoratoe334d252009-07-17 15:33:40 -04001427$(hide) rm -f $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list
1428$(hide) rm -f $(dir $(PRIVATE_CLASS_INTERMEDIATES_DIR))/java-source-list-uniq
Joe Onorato64d85d02009-04-09 19:31:12 -07001429$(hide) mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001430$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \
1431 $@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
Joe Onorato64d85d02009-04-09 19:31:12 -07001432$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001433endef
1434
1435define transform-classes.jar-to-emma
1436$(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \
Guang Zhu155afe32010-03-10 15:48:03 -08001437 $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR) \
Guang Zhu9cd3d8c2010-06-15 13:31:25 -07001438 $(addprefix -ix , $(PRIVATE_EMMA_COVERAGE_FILTER))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001439endef
1440
1441#TODO: use a smaller -Xmx value for most libraries;
1442# only core.jar and framework.jar need a heap this big.
Raphaelf6ff4c52009-08-18 14:43:32 -07001443# 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 -08001444define transform-classes.jar-to-dex
1445@echo "target Dex: $(PRIVATE_MODULE)"
1446@mkdir -p $(dir $@)
Raphaelf6ff4c52009-08-18 14:43:32 -07001447$(hide) $(DX) \
1448 $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx1536M) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001449 --dex --output=$@ \
1450 $(if $(NO_OPTIMIZE_DX), \
1451 --no-optimize) \
1452 $(if $(GENERATE_DEX_DEBUG), \
1453 --debug --verbose \
1454 --dump-to=$(@:.dex=.lst) \
1455 --dump-width=1000) \
1456 $(PRIVATE_DX_FLAGS) \
1457 $<
1458endef
1459
1460# Create a mostly-empty .jar file that we'll add to later.
1461# The MacOS jar tool doesn't like creating empty jar files,
1462# so we need to give it something.
1463define create-empty-package
1464@mkdir -p $(dir $@)
1465$(hide) touch $(dir $@)/dummy
1466$(hide) (cd $(dir $@) && jar cf $(notdir $@) dummy)
1467$(hide) zip -qd $@ dummy
1468$(hide) rm $(dir $@)/dummy
1469endef
1470
1471#TODO: we kinda want to build different asset packages for
1472# different configurations, then combine them later (or something).
1473# Per-locale, etc.
1474# A list of dynamic and static parameters; build layers for
1475# dynamic params that lay over the static ones.
1476#TODO: update the manifest to point to the package file
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001477#Note that the version numbers are given to aapt as simple default
1478#values; applications can override these by explicitly stating
1479#them in their manifest.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001480define add-assets-to-package
Ying Wangc61d5932010-03-10 16:02:42 -08001481$(hide) $(AAPT) package -u $(PRIVATE_AAPT_FLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001482 $(addprefix -c , $(PRODUCT_AAPT_CONFIG)) \
1483 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
1484 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
1485 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
1486 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001487 $(addprefix --min-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
1488 $(addprefix --target-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
Joe Onorato700b88e2010-10-05 17:33:58 -04001489 $(addprefix --product , $(TARGET_AAPT_CHARACTERISTICS)) \
Ying Wang1ae607a2010-06-23 13:34:22 -07001490 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \
Ying Wang8f5069b2010-06-29 11:08:13 -07001491 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION)-$(BUILD_NUMBER))) \
Jeff Hamiltonbb67d212010-02-05 22:36:42 -06001492 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07001493 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001494 -F $@
1495endef
1496
The Android Open Source Project88b60792009-03-03 19:28:42 -08001497define add-jni-shared-libs-to-package
1498$(hide) rm -rf $(dir $@)lib
Jack Palevicha0ab29b2010-06-18 15:38:07 +08001499$(hide) mkdir -p $(dir $@)lib/$(PRIVATE_JNI_SHARED_LIBRARIES_ABI)
1500$(hide) cp $(PRIVATE_JNI_SHARED_LIBRARIES) $(dir $@)lib/$(PRIVATE_JNI_SHARED_LIBRARIES_ABI)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001501$(hide) (cd $(dir $@) && zip -r $(notdir $@) lib)
1502$(hide) rm -rf $(dir $@)lib
1503endef
1504
The Android Open Source Project88b60792009-03-03 19:28:42 -08001505#TODO: update the manifest to point to the dex file
1506define add-dex-to-package
Ying Wang957fea52010-09-23 11:48:38 -07001507$(if $(filter classes.dex,$(notdir $(PRIVATE_DEX_FILE))),\
1508$(hide) $(AAPT) add -k $@ $(PRIVATE_DEX_FILE),\
1509$(eval _adtp_classes.dex := $(dir $(PRIVATE_DEX_FILE))/classes.dex)\
1510$(hide) cp $(PRIVATE_DEX_FILE) $(_adtp_classes.dex) && \
1511$(AAPT) add -k $@ $(_adtp_classes.dex) && \
1512rm -f $(_adtp_classes.dex))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001513endef
1514
1515define add-java-resources-to-package
1516$(hide) jar uf $@ $(PRIVATE_EXTRA_JAR_ARGS)
1517endef
1518
1519# Sign a package using the specified key/cert.
1520#
1521define sign-package
1522$(hide) mv $@ $@.unsigned
1523$(hide) java -jar $(SIGNAPK_JAR) \
1524 $(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) $@.unsigned $@.signed
1525$(hide) mv $@.signed $@
1526endef
1527
1528# Align STORED entries of a package on 4-byte boundaries
1529# to make them easier to mmap.
1530#
1531define align-package
1532$(hide) mv $@ $@.unaligned
1533$(hide) $(ZIPALIGN) -f 4 $@.unaligned $@.aligned
1534$(hide) mv $@.aligned $@
1535endef
1536
1537define install-dex-debug
1538$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.dex" ]; then \
1539 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
1540 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.dex \
1541 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).dex; \
1542 fi
1543$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.lst" ]; then \
1544 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
1545 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.lst \
1546 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).lst; \
1547 fi
1548endef
1549
1550# TODO(joeo): If we can ever upgrade to post 3.81 make and get the
1551# new prebuilt rules to work, we should change this to copy the
1552# resources to the out directory and then copy the resources.
1553
1554# Note: not using aapt tool for this because we aren't making
1555# an android package for the host.
1556define transform-host-java-to-package
1557@echo "host Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
1558@rm -f $@
1559@rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1560@mkdir -p $(dir $@)
1561@mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1562$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES), \
1563 $(PRIVATE_CLASS_INTERMEDIATES_DIR))
1564$(call dump-words-to-file,$(sort\
1565 $(PRIVATE_JAVA_SOURCES)),\
Joe Onorato483d9242009-06-18 13:11:58 -07001566 $(PRIVATE_INTERMEDIATES_DIR)/java-source-list-uniq)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001567$(hide) $(HOST_JAVAC) -encoding ascii -g \
Brian Carlstromf184a0f2010-02-01 11:13:32 -08001568 $(PRIVATE_JAVACFLAGS) $(xlint_unchecked) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001569 $(addprefix -classpath ,$(strip \
1570 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \
1571 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR)\
Joe Onorato483d9242009-06-18 13:11:58 -07001572 \@$(PRIVATE_INTERMEDIATES_DIR)/java-source-list-uniq || \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001573 ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 )
Joe Onorato483d9242009-06-18 13:11:58 -07001574$(hide) rm -f $(PRIVATE_INTERMEDIATES_DIR)/java-source-list
1575$(hide) rm -f $(PRIVATE_INTERMEDIATES_DIR)/java-source-list-uniq
The Android Open Source Project88b60792009-03-03 19:28:42 -08001576$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \
1577 $@ $(PRIVATE_JAR_MANIFEST) $(PRIVATE_EXTRA_JAR_ARGS) \
1578 -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
1579endef
1580
1581###########################################################
1582## Obfuscate a jar file
1583###########################################################
1584
1585# PRIVATE_KEEP_FILE is a file containing a list of classes
1586# PRIVATE_INTERMEDIATES_DIR is a directory we can use for temporary files
1587# The module using this must depend on
1588# $(HOST_OUT_JAVA_LIBRARIES)/proguard-4.0.1.jar
1589define obfuscate-jar
1590@echo "Obfuscate jar: $(notdir $@) ($@)"
1591@mkdir -p $(dir $@)
1592@rm -f $@
1593@mkdir -p $(PRIVATE_INTERMEDIATES_DIR)
1594$(hide) sed -e 's/^/-keep class /' < $(PRIVATE_KEEP_FILE) > \
1595 $(PRIVATE_INTERMEDIATES_DIR)/keep.pro
1596$(hide) java -Xmx512M -jar $(HOST_OUT_JAVA_LIBRARIES)/proguard-4.0.1.jar \
1597 -injars $< \
1598 -outjars $@ \
1599 -target 1.5 \
1600 -dontnote -dontwarn \
1601 -printmapping $(PRIVATE_INTERMEDIATES_DIR)/out.map \
1602 -forceprocessing \
1603 -renamesourcefileattribute SourceFile \
1604 -keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod \
1605 -repackageclasses \
1606 -keepclassmembers "class * { public protected *; }" \
1607 @$(PRIVATE_INTERMEDIATES_DIR)/keep.pro
1608endef
1609
1610###########################################################
1611## Commands for copying files
1612###########################################################
1613
1614# Define a rule to copy a header. Used via $(eval) by copy_headers.make.
1615# $(1): source header
1616# $(2): destination header
1617define copy-one-header
1618$(2): $(1)
1619 @echo "Header: $$@"
1620 $$(copy-file-to-new-target-with-cp)
1621endef
1622
1623# Define a rule to copy a file. For use via $(eval).
1624# $(1): source file
1625# $(2): destination file
1626define copy-one-file
1627$(2): $(1) | $(ACP)
1628 @echo "Copy: $$@"
1629 $$(copy-file-to-target)
1630endef
1631
1632# The -t option to acp and the -p option to cp is
1633# required for OSX. OSX has a ridiculous restriction
1634# where it's an error for a .a file's modification time
1635# to disagree with an internal timestamp, and this
1636# macro is used to install .a files (among other things).
1637
1638# Copy a single file from one place to another,
1639# preserving permissions and overwriting any existing
1640# file.
1641define copy-file-to-target
1642@mkdir -p $(dir $@)
1643$(hide) $(ACP) -fpt $< $@
1644endef
1645
1646# The same as copy-file-to-target, but use the local
1647# cp command instead of acp.
1648define copy-file-to-target-with-cp
1649@mkdir -p $(dir $@)
1650$(hide) cp -fp $< $@
1651endef
1652
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07001653# The same as copy-file-to-target, but use the zipalign tool to do so.
1654define copy-file-to-target-with-zipalign
1655@mkdir -p $(dir $@)
1656$(hide) $(ZIPALIGN) -f 4 $< $@
1657endef
1658
Doug Zongker1046d202009-08-06 13:02:19 -07001659# The same as copy-file-to-target, but strip out "# comment"-style
1660# comments (for config files and such).
1661define copy-file-to-target-strip-comments
1662@mkdir -p $(dir $@)
1663$(hide) sed -e 's/#.*$$//' -e 's/[ \t]*$$//' -e '/^$$/d' < $< > $@
1664endef
1665
The Android Open Source Project88b60792009-03-03 19:28:42 -08001666# The same as copy-file-to-target, but don't preserve
1667# the old modification time.
1668define copy-file-to-new-target
1669@mkdir -p $(dir $@)
1670$(hide) $(ACP) -fp $< $@
1671endef
1672
1673# The same as copy-file-to-new-target, but use the local
1674# cp command instead of acp.
1675define copy-file-to-new-target-with-cp
1676@mkdir -p $(dir $@)
1677$(hide) cp -f $< $@
1678endef
1679
1680# Copy a prebuilt file to a target location.
1681define transform-prebuilt-to-target
1682@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"
1683$(copy-file-to-target)
1684endef
1685
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07001686# Copy a prebuilt file to a target location, using zipalign on it.
1687define transform-prebuilt-to-target-with-zipalign
1688@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt APK: $(PRIVATE_MODULE) ($@)"
1689$(copy-file-to-target-with-zipalign)
1690endef
1691
Doug Zongker1046d202009-08-06 13:02:19 -07001692# Copy a prebuilt file to a target location, stripping "# comment" comments.
1693define transform-prebuilt-to-target-strip-comments
1694@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"
1695$(copy-file-to-target-strip-comments)
1696endef
1697
The Android Open Source Project88b60792009-03-03 19:28:42 -08001698###########################################################
1699## On some platforms (MacOS), after copying a static
1700## library, ranlib must be run to update an internal
1701## timestamp!?!?!
1702###########################################################
1703
1704ifeq ($(HOST_RUN_RANLIB_AFTER_COPYING),true)
1705define transform-host-ranlib-copy-hack
1706 $(hide) ranlib $@ || true
1707endef
1708else
1709define transform-host-ranlib-copy-hack
Patrick Scott0e27dff2010-05-07 08:37:11 -04001710@true
The Android Open Source Project88b60792009-03-03 19:28:42 -08001711endef
1712endif
1713
1714ifeq ($(TARGET_RUN_RANLIB_AFTER_COPYING),true)
1715define transform-ranlib-copy-hack
1716 $(hide) ranlib $@
1717endef
1718else
1719define transform-ranlib-copy-hack
Patrick Scott0e27dff2010-05-07 08:37:11 -04001720@true
The Android Open Source Project88b60792009-03-03 19:28:42 -08001721endef
1722endif
1723
1724
1725###########################################################
Ying Wang3b2bdf12010-02-01 09:51:23 -08001726## Commands to call Proguard
1727###########################################################
1728
1729# Command to copy the file with acp, if proguard is disabled.
1730define proguard-disabled-commands
1731@echo Copying: $@
1732$(hide) $(ACP) $< $@
1733endef
1734
1735# Command to call Proguard
1736# $(1): extra flags for instrumentation.
1737define proguard-enabled-commands
1738@echo Proguard: $@
1739$(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS) $(1)
1740endef
1741
1742# Figure out the proguard dictionary file of the module that is instrumentationed for.
1743define get-instrumentation-proguard-flags
1744$(if $(PRIVATE_INSTRUMENTATION_FOR),$(if $(ALL_MODULES.$(PRIVATE_INSTRUMENTATION_FOR).PROGUARD_ENABLED),-applymapping $(call intermediates-dir-for,APPS,$(PRIVATE_INSTRUMENTATION_FOR),,COMMON)/proguard_dictionary))
1745endef
1746
1747define transform-jar-to-proguard
1748$(eval _instrumentation_proguard_flags:=$(call get-instrumentation-proguard-flags))
1749$(eval _enable_proguard:=$(PRIVATE_PROGUARD_ENABLED)$(_instrumentation_proguard_flags))
1750$(if $(_enable_proguard),$(call proguard-enabled-commands,$(_instrumentation_proguard_flags)),$(call proguard-disabled-commands))
1751$(eval _instrumentation_proguard_flags:=)
1752$(eval _enable_proguard:=)
1753endef
1754
1755
1756###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001757## Stuff source generated from one-off tools
1758###########################################################
1759
1760define transform-generated-source
1761@echo "target Generated: $(PRIVATE_MODULE) <= $<"
1762@mkdir -p $(dir $@)
1763$(hide) $(PRIVATE_CUSTOM_TOOL)
1764endef
1765
1766
1767###########################################################
1768## Assertions about attributes of the target
1769###########################################################
1770
1771# $(1): The file to check
1772ifndef get-file-size
1773$(error HOST_OS must define get-file-size)
1774endif
1775
Doug Zongker4647f122009-07-02 09:00:54 -07001776# Convert a partition data size (eg, as reported in /proc/mtd) to the
1777# size of the image used to flash that partition (which includes a
1778# 64-byte spare area for each 2048-byte page).
1779# $(1): the partition data size
1780define image-size-from-data-size
1781$(shell echo $$(($(1) / 2048 * (2048+64))))
1782endef
1783
1784# $(1): The file(s) to check (often $@)
1785# $(2): The maximum total image size, in decimal bytes
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001786# $(3): the type of filesystem "yaffs" or "raw"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001787#
1788# If $(2) is empty, evaluates to "true"
1789#
1790# Reserve bad blocks. Make sure that MAX(1% of partition size, 2 blocks)
1791# is left over after the image has been flashed. Round the 1% up to the
1792# next whole flash block size.
1793define assert-max-file-size
1794$(if $(2), \
Doug Zongker742fa572009-07-08 12:09:04 -07001795 size=$$(for i in $(1); do $(call get-file-size,$$i); echo +; done; echo 0); \
1796 total=$$(( $$( echo "$$size" ) )); \
Doug Zongker4647f122009-07-02 09:00:54 -07001797 printname=$$(echo -n "$(1)" | tr " " +); \
1798 echo "$$printname total size is $$total"; \
1799 img_blocksize=$(call image-size-from-data-size,$(BOARD_FLASH_BLOCK_SIZE)); \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001800 if [ "$(3)" == "yaffs" ]; then \
Doug Zongker93d9ff42009-09-14 17:46:41 -07001801 reservedblocks=8; \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001802 else \
Doug Zongker4ac1ba62009-08-25 20:38:50 -07001803 reservedblocks=0; \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001804 fi; \
Doug Zongker4647f122009-07-02 09:00:54 -07001805 twoblocks=$$((img_blocksize * 2)); \
1806 onepct=$$((((($(2) / 100) - 1) / img_blocksize + 1) * img_blocksize)); \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001807 reserve=$$(((twoblocks > onepct ? twoblocks : onepct) + \
1808 reservedblocks * img_blocksize)); \
Doug Zongker4647f122009-07-02 09:00:54 -07001809 maxsize=$$(($(2) - reserve)); \
1810 if [ "$$total" -gt "$$maxsize" ]; then \
1811 echo "error: $$printname too large ($$total > [$(2) - $$reserve])"; \
1812 false; \
Doug Zongker742fa572009-07-08 12:09:04 -07001813 elif [ "$$total" -gt $$((maxsize - 32768)) ]; then \
Doug Zongker4647f122009-07-02 09:00:54 -07001814 echo "WARNING: $$printname approaching size limit ($$total now; limit $$maxsize)"; \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001815 fi \
1816 , \
1817 true \
1818 )
1819endef
1820
Doug Zongker8510a1e2009-08-07 16:38:08 -07001821# Like assert-max-file-size, but the second argument is a partition
1822# size, which we'll convert to a max image size before checking it
1823# against the files.
1824#
1825# $(1): The file(s) to check (often $@)
1826# $(2): The partition size.
1827define assert-max-image-size
1828$(if $(2), \
1829 $(call assert-max-file-size,$(1),$(call image-size-from-data-size,$(2))), \
1830 true)
1831endef
1832
Doug Zongkere01100c2009-06-19 17:12:18 -07001833
1834###########################################################
1835## Define device-specific radio files
1836###########################################################
1837
1838# Copy a radio image file to the output location, and add it to
1839# INSTALLED_RADIOIMAGE_TARGET.
1840# $(1): filename
1841define add-radio-file
Doug Zongker14833602010-02-02 13:12:04 -08001842 $(eval $(call add-radio-file-internal,$(1),$(notdir $(1))))
Doug Zongkere01100c2009-06-19 17:12:18 -07001843endef
1844define add-radio-file-internal
Doug Zongker14833602010-02-02 13:12:04 -08001845INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
Doug Zongker14833602010-02-02 13:12:04 -08001846$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP)
Doug Zongkere01100c2009-06-19 17:12:18 -07001847 $$(transform-prebuilt-to-target)
1848endef
1849
1850
The Android Open Source Project88b60792009-03-03 19:28:42 -08001851###########################################################
Joe Onorato899e62a2010-02-04 17:37:21 -08001852# Override the package defined in $(1), setting the
1853# variables listed below differently.
1854#
1855# $(1): The makefile to override (relative to the source
1856# tree root)
1857# $(2): Old LOCAL_PACKAGE_NAME value.
1858# $(3): New LOCAL_PACKAGE_NAME value.
Ying Wang3dae0ee2010-09-02 15:41:01 -07001859# $(4): New LOCAL_MANIFEST_PACKAGE_NAME value.
1860# $(5): New LOCAL_CERTIFICATE value.
1861# $(6): New LOCAL_INSTRUMENTATION_FOR value.
1862# $(7): New LOCAL_MANIFEST_INSTRUMENTATION_FOR value.
Joe Onorato899e62a2010-02-04 17:37:21 -08001863#
1864# Note that LOCAL_PACKAGE_OVERRIDES is NOT cleared in
1865# clear_vars.mk.
1866###########################################################
1867define inherit-package
Ying Wang3dae0ee2010-09-02 15:41:01 -07001868 $(eval $(call inherit-package-internal,$(1),$(2),$(3),$(4),$(5),$(6),$(7)))
Joe Onorato899e62a2010-02-04 17:37:21 -08001869endef
1870
1871define inherit-package-internal
1872 LOCAL_PACKAGE_OVERRIDES \
Ying Wang3dae0ee2010-09-02 15:41:01 -07001873 := $(strip $(1))||$(strip $(2))||$(strip $(3))||$(strip $(4))||&&$(strip $(5))||&&$(strip $(6))||&&$(strip $(7)) $(LOCAL_PACKAGE_OVERRIDES)
Joe Onorato899e62a2010-02-04 17:37:21 -08001874 include $(1)
1875 LOCAL_PACKAGE_OVERRIDES \
1876 := $(wordlist 1,$(words $(LOCAL_PACKAGE_OVERRIDES)), $(LOCAL_PACKAGE_OVERRIDES))
1877endef
1878
1879# To be used with inherit-package above
1880# Evalutes to true if the package was overridden
1881define set-inherited-package-variables
1882$(strip $(call set-inherited-package-variables-internal))
1883endef
1884
1885define keep-or-override
1886$(eval $(1) := $(if $(2),$(2),$($(1))))
1887endef
1888
1889define set-inherited-package-variables-internal
1890 $(eval _o := $(subst ||, ,$(lastword $(LOCAL_PACKAGE_OVERRIDES))))
1891 $(eval _n := $(subst ||, ,$(firstword $(LOCAL_PACKAGE_OVERRIDES))))
1892 $(if $(filter $(word 2,$(_n)),$(LOCAL_PACKAGE_NAME)), \
1893 $(eval LOCAL_PACKAGE_NAME := $(word 3,$(_o))) \
1894 $(eval LOCAL_MANIFEST_PACKAGE_NAME := $(word 4,$(_o))) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07001895 $(call keep-or-override,LOCAL_CERTIFICATE,$(patsubst &&%,%,$(word 5,$(_o)))) \
1896 $(call keep-or-override,LOCAL_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 6,$(_o)))) \
1897 $(call keep-or-override,LOCAL_MANIFEST_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 7,$(_o)))) \
Joe Onorato899e62a2010-02-04 17:37:21 -08001898 $(eval LOCAL_OVERRIDES_PACKAGES := $(sort $(LOCAL_OVERRIDES_PACKAGES) $(word 2,$(_o)))) \
1899 true \
1900 ,)
1901endef
1902
1903
1904###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001905## Other includes
1906###########################################################
1907
1908# -----------------------------------------------------------------
1909# Rules and functions to help copy important files to DIST_DIR
1910# when requested.
1911include $(BUILD_SYSTEM)/distdir.mk
1912
Jean-Baptiste Queru4074f232010-09-03 16:32:58 -07001913# -----------------------------------------------------------------
1914# The modules allowed to use a user tag
1915include $(BUILD_SYSTEM)/user_tags.mk
The Android Open Source Project88b60792009-03-03 19:28:42 -08001916
1917# broken:
1918# $(foreach file,$^,$(if $(findstring,.a,$(suffix $file)),-l$(file),$(file)))
1919
1920###########################################################
1921## Misc notes
1922###########################################################
1923
1924#DEPDIR = .deps
1925#df = $(DEPDIR)/$(*F)
1926
1927#SRCS = foo.c bar.c ...
1928
1929#%.o : %.c
1930# @$(MAKEDEPEND); \
1931# cp $(df).d $(df).P; \
1932# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
1933# -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \
1934# rm -f $(df).d
1935# $(COMPILE.c) -o $@ $<
1936
1937#-include $(SRCS:%.c=$(DEPDIR)/%.P)
1938
1939
1940#%.o : %.c
1941# $(COMPILE.c) -MD -o $@ $<
1942# @cp $*.d $*.P; \
1943# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
1944# -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \
1945# rm -f $*.d