blob: cb324dda99312c25e597a5b58f4d682e84a76f1d [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
Iliyan Malchevb375e712011-03-08 16:19:48 -080069# The list of dynamic binaries that haven't been stripped/compressed/etc.
The Android Open Source Project88b60792009-03-03 19:28:42 -080070ALL_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
Ying Wangfd626f22011-12-12 12:57:38 -080081# GPL module license files
82ALL_GPL_MODULE_LICENSE_FILES:=
83
Ying Wang9485a572013-02-22 14:32:30 -080084# Target and host installed module's dependencies on shared libraries.
Ying Wangd6b1d612013-04-15 17:32:21 -070085# They are list of "<module_name>:<installed_file>:lib1,lib2...".
Ying Wang9485a572013-02-22 14:32:30 -080086TARGET_DEPENDENCIES_ON_SHARED_LIBRARIES :=
Colin Cross5394bf12014-02-04 19:42:32 -0800872ND_TARGET_DEPENDENCIES_ON_SHARED_LIBRARIES :=
Ying Wang9485a572013-02-22 14:32:30 -080088HOST_DEPENDENCIES_ON_SHARED_LIBRARIES :=
89
Ying Wangae25ec12012-06-19 10:40:37 -070090# Generated class file names for Android resource.
91# They are escaped and quoted so can be passed safely to a bash command.
92ANDROID_RESOURCE_GENERATED_CLASSES := 'R.class' 'R$$*.class' 'Manifest.class' 'Manifest$$*.class'
93
The Android Open Source Project88b60792009-03-03 19:28:42 -080094###########################################################
95## Debugging; prints a variable list to stdout
96###########################################################
97
98# $(1): variable name list, not variable values
99define print-vars
100$(foreach var,$(1), \
101 $(info $(var):) \
102 $(foreach word,$($(var)), \
103 $(info $(space)$(space)$(word)) \
104 ) \
105 )
106endef
107
108###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700109## Evaluates to true if the string contains the word true,
110## and empty otherwise
111## $(1): a var to test
112###########################################################
113
114define true-or-empty
115$(filter true, $(1))
116endef
117
118
119###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800120## Retrieve the directory of the current makefile
121###########################################################
122
123# Figure out where we are.
124define my-dir
Dave Bortb3926412009-05-19 16:12:22 -0700125$(strip \
Ying Wang68f1c772012-04-23 21:29:18 -0700126 $(eval LOCAL_MODULE_MAKEFILE := $$(lastword $$(MAKEFILE_LIST))) \
127 $(if $(filter $(CLEAR_VARS),$(LOCAL_MODULE_MAKEFILE)), \
Dave Bortb3926412009-05-19 16:12:22 -0700128 $(error LOCAL_PATH must be set before including $$(CLEAR_VARS)) \
129 , \
Ying Wang68f1c772012-04-23 21:29:18 -0700130 $(patsubst %/,%,$(dir $(LOCAL_MODULE_MAKEFILE))) \
Dave Bortb3926412009-05-19 16:12:22 -0700131 ) \
132 )
The Android Open Source Project88b60792009-03-03 19:28:42 -0800133endef
134
135###########################################################
136## Retrieve a list of all makefiles immediately below some directory
137###########################################################
138
139define all-makefiles-under
140$(wildcard $(1)/*/Android.mk)
141endef
142
143###########################################################
144## Look under a directory for makefiles that don't have parent
145## makefiles.
146###########################################################
147
148# $(1): directory to search under
149# Ignores $(1)/Android.mk
150define first-makefiles-under
JP Abgrall1390cac2013-07-11 19:08:06 -0700151$(shell build/tools/findleaves.py --prune=$(OUT_DIR) --prune=.repo --prune=.git \
Joe Onoratodc1a7282009-08-04 15:58:26 -0400152 --mindepth=2 $(1) Android.mk)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800153endef
154
155###########################################################
156## Retrieve a list of all makefiles immediately below your directory
157###########################################################
158
159define all-subdir-makefiles
160$(call all-makefiles-under,$(call my-dir))
161endef
162
163###########################################################
164## Look in the named list of directories for makefiles,
165## relative to the current directory.
166###########################################################
167
168# $(1): List of directories to look for under this directory
169define all-named-subdir-makefiles
Chih-Wei Huange73c4bb2011-01-16 18:31:29 +0800170$(wildcard $(addsuffix /Android.mk, $(addprefix $(call my-dir)/,$(1))))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800171endef
172
173###########################################################
174## Find all of the java files under the named directories.
175## Meant to be used like:
176## SRC_FILES := $(call all-java-files-under,src tests)
177###########################################################
178
179define all-java-files-under
180$(patsubst ./%,%, \
181 $(shell cd $(LOCAL_PATH) ; \
Conley Owensf4357392012-10-02 10:32:00 -0700182 find -L $(1) -name "*.java" -and -not -name ".*") \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800183 )
184endef
185
186###########################################################
187## Find all of the java files from here. Meant to be used like:
188## SRC_FILES := $(call all-subdir-java-files)
189###########################################################
190
191define all-subdir-java-files
192$(call all-java-files-under,.)
193endef
194
195###########################################################
196## Find all of the c files under the named directories.
197## Meant to be used like:
198## SRC_FILES := $(call all-c-files-under,src tests)
199###########################################################
200
201define all-c-files-under
202$(patsubst ./%,%, \
203 $(shell cd $(LOCAL_PATH) ; \
Conley Owensf4357392012-10-02 10:32:00 -0700204 find -L $(1) -name "*.c" -and -not -name ".*") \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800205 )
206endef
207
208###########################################################
209## Find all of the c files from here. Meant to be used like:
210## SRC_FILES := $(call all-subdir-c-files)
211###########################################################
212
213define all-subdir-c-files
214$(call all-c-files-under,.)
215endef
216
217###########################################################
218## Find all files named "I*.aidl" under the named directories,
219## which must be relative to $(LOCAL_PATH). The returned list
220## is relative to $(LOCAL_PATH).
221###########################################################
222
223define all-Iaidl-files-under
224$(patsubst ./%,%, \
225 $(shell cd $(LOCAL_PATH) ; \
Conley Owensf4357392012-10-02 10:32:00 -0700226 find -L $(1) -name "I*.aidl" -and -not -name ".*") \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800227 )
228endef
229
230###########################################################
231## Find all of the "I*.aidl" files under $(LOCAL_PATH).
232###########################################################
233
234define all-subdir-Iaidl-files
235$(call all-Iaidl-files-under,.)
236endef
237
238###########################################################
Bjorn Bringerta89c9902010-02-02 17:36:20 +0000239## Find all of the logtags files under the named directories.
240## Meant to be used like:
241## SRC_FILES := $(call all-logtags-files-under,src)
242###########################################################
243
244define all-logtags-files-under
245$(patsubst ./%,%, \
246 $(shell cd $(LOCAL_PATH) ; \
Conley Owensf4357392012-10-02 10:32:00 -0700247 find -L $(1) -name "*.logtags" -and -not -name ".*") \
Bjorn Bringerta89c9902010-02-02 17:36:20 +0000248 )
249endef
250
251###########################################################
Ying Wanga5fc87a2010-11-02 18:43:16 -0700252## Find all of the .proto files under the named directories.
253## Meant to be used like:
254## SRC_FILES := $(call all-proto-files-under,src)
255###########################################################
256
257define all-proto-files-under
258$(patsubst ./%,%, \
259 $(shell cd $(LOCAL_PATH) ; \
Conley Owensf4357392012-10-02 10:32:00 -0700260 find -L $(1) -name "*.proto" -and -not -name ".*") \
Ying Wanga5fc87a2010-11-02 18:43:16 -0700261 )
262endef
263
264###########################################################
Ying Wang0bd59a02010-07-15 17:17:52 -0700265## Find all of the RenderScript files under the named directories.
266## Meant to be used like:
267## SRC_FILES := $(call all-renderscript-files-under,src)
268###########################################################
269
270define all-renderscript-files-under
271$(patsubst ./%,%, \
272 $(shell cd $(LOCAL_PATH) ; \
Stephen Hinesd2637572012-10-11 22:08:57 -0700273 find -L $(1) \( -name "*.rs" -or -name "*.fs" \) -and -not -name ".*") \
Ying Wang0bd59a02010-07-15 17:17:52 -0700274 )
275endef
276
277###########################################################
Elliott Hughese3b044a2014-02-11 13:48:35 -0800278## Find all of the S files under the named directories.
279## Meant to be used like:
280## SRC_FILES := $(call all-c-files-under,src tests)
281###########################################################
282
283define all-S-files-under
284$(patsubst ./%,%, \
285 $(shell cd $(LOCAL_PATH) ; \
286 find -L $(1) -name "*.S" -and -not -name ".*") \
287 )
288endef
289
290###########################################################
Jean-Baptiste Queru0a3cfdc2009-12-17 17:47:28 -0800291## Find all of the html files under the named directories.
292## Meant to be used like:
293## SRC_FILES := $(call all-html-files-under,src tests)
294###########################################################
295
296define all-html-files-under
297$(patsubst ./%,%, \
298 $(shell cd $(LOCAL_PATH) ; \
Conley Owensf4357392012-10-02 10:32:00 -0700299 find -L $(1) -name "*.html" -and -not -name ".*") \
Jean-Baptiste Queru0a3cfdc2009-12-17 17:47:28 -0800300 )
301endef
302
303###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800304## Find all of the html files from here. Meant to be used like:
305## SRC_FILES := $(call all-subdir-html-files)
306###########################################################
307
308define all-subdir-html-files
Jean-Baptiste Queru0a3cfdc2009-12-17 17:47:28 -0800309$(call all-html-files-under,.)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800310endef
311
312###########################################################
313## Find all of the files matching pattern
314## SRC_FILES := $(call find-subdir-files, <pattern>)
315###########################################################
316
317define find-subdir-files
Conley Owensf4357392012-10-02 10:32:00 -0700318$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) ; find -L $(1)))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800319endef
320
321###########################################################
322# find the files in the subdirectory $1 of LOCAL_DIR
323# matching pattern $2, filtering out files $3
324# e.g.
325# SRC_FILES += $(call find-subdir-subdir-files, \
326# css, *.cpp, DontWantThis.cpp)
327###########################################################
328
329define find-subdir-subdir-files
330$(filter-out $(patsubst %,$(1)/%,$(3)),$(patsubst ./%,%,$(shell cd \
Conley Owensf4357392012-10-02 10:32:00 -0700331 $(LOCAL_PATH) ; find -L $(1) -maxdepth 1 -name $(2))))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800332endef
333
334###########################################################
335## Find all of the files matching pattern
336## SRC_FILES := $(call all-subdir-java-files)
337###########################################################
338
339define find-subdir-assets
340$(if $(1),$(patsubst ./%,%, \
Ying Wang6ab5d6a2011-08-10 16:05:51 -0700341 $(shell if [ -d $(1) ] ; then cd $(1) ; find ./ -not -name '.*' -and -type f -and -not -type l ; fi)), \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800342 $(warning Empty argument supplied to find-subdir-assets) \
343)
344endef
345
346###########################################################
347## Find various file types in a list of directories relative to $(LOCAL_PATH)
348###########################################################
349
350define find-other-java-files
351 $(call find-subdir-files,$(1) -name "*.java" -and -not -name ".*")
352endef
353
354define find-other-html-files
355 $(call find-subdir-files,$(1) -name "*.html" -and -not -name ".*")
356endef
357
358###########################################################
Ying Wang7c8c7bd2013-12-04 16:04:49 -0800359# Use utility find to find given files in the given subdirs.
360# This function uses $(1), instead of LOCAL_PATH as the base.
361# $(1): the base dir, relative to the root of the source tree.
362# $(2): the file name pattern to be passed to find as "-name".
363# $(3): a list of subdirs of the base dir.
364# Returns: a list of paths relative to the base dir.
365###########################################################
366
367define find-files-in-subdirs
368$(patsubst ./%,%, \
369 $(shell cd $(1) ; \
370 find -L $(3) -name $(2) -and -not -name ".*") \
371 )
372endef
373
374###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800375## Scan through each directory of $(1) looking for files
376## that match $(2) using $(wildcard). Useful for seeing if
377## a given directory or one of its parents contains
378## a particular file. Returns the first match found,
379## starting furthest from the root.
380###########################################################
381
382define find-parent-file
383$(strip \
Ying Wanga67ce692011-03-03 13:29:38 -0800384 $(eval _fpf := $(wildcard $(foreach f, $(2), $(strip $(1))/$(f)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800385 $(if $(_fpf),$(_fpf), \
386 $(if $(filter-out ./ .,$(1)), \
387 $(call find-parent-file,$(patsubst %/,%,$(dir $(1))),$(2)) \
388 ) \
389 ) \
390)
391endef
392
393###########################################################
394## Function we can evaluate to introduce a dynamic dependency
395###########################################################
396
397define add-dependency
398$(1): $(2)
399endef
400
401###########################################################
402## Set up the dependencies for a prebuilt target
403## $(call add-prebuilt-file, srcfile, [targetclass])
404###########################################################
405
406define add-prebuilt-file
407 $(eval $(include-prebuilt))
408endef
409
410define include-prebuilt
411 include $$(CLEAR_VARS)
412 LOCAL_SRC_FILES := $(1)
413 LOCAL_BUILT_MODULE_STEM := $(1)
414 LOCAL_MODULE_SUFFIX := $$(suffix $(1))
415 LOCAL_MODULE := $$(basename $(1))
416 LOCAL_MODULE_CLASS := $(2)
417 include $$(BUILD_PREBUILT)
418endef
419
420###########################################################
421## do multiple prebuilts
422## $(call target class, files ...)
423###########################################################
424
425define add-prebuilt-files
426 $(foreach f,$(2),$(call add-prebuilt-file,$f,$(1)))
427endef
428
429
430
431###########################################################
432## The intermediates directory. Where object files go for
433## a given target. We could technically get away without
434## the "_intermediates" suffix on the directory, but it's
435## nice to be able to grep for that string to find out if
436## anyone's abusing the system.
437###########################################################
438
439# $(1): target class, like "APPS"
440# $(2): target name, like "NotePad"
441# $(3): if non-empty, this is a HOST target.
442# $(4): if non-empty, force the intermediates to be COMMON
Ying Wang6ef65192014-01-15 16:02:16 -0800443# $(5): if non-empty, force the intermedistes to be for the 2nd arch
The Android Open Source Project88b60792009-03-03 19:28:42 -0800444define intermediates-dir-for
445$(strip \
446 $(eval _idfClass := $(strip $(1))) \
447 $(if $(_idfClass),, \
448 $(error $(LOCAL_PATH): Class not defined in call to intermediates-dir-for)) \
449 $(eval _idfName := $(strip $(2))) \
450 $(if $(_idfName),, \
451 $(error $(LOCAL_PATH): Name not defined in call to intermediates-dir-for)) \
452 $(eval _idfPrefix := $(if $(strip $(3)),HOST,TARGET)) \
Colin Cross02e31d22014-01-24 13:38:08 -0800453 $(eval _idf2ndArchPrefix := $(if $(call directory_is_64_bit_blacklisted,$(LOCAL_PATH))$(strip $(5)),$(TARGET_2ND_ARCH_VAR_PREFIX))) \
Ying Wanga83940f2010-09-24 18:09:04 -0700454 $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800455 $(eval _idfIntBase := $($(_idfPrefix)_OUT_COMMON_INTERMEDIATES)) \
Colin Cross02e31d22014-01-24 13:38:08 -0800456 ,$(if $(filter $(_idfPrefix)-$(_idfClass),TARGET-SHARED_LIBRARIES TARGET-STATIC_LIBRARIES TARGET-EXECUTABLES),\
457 $(eval _idfIntBase := $($(_idf2ndArchPrefix)$(_idfPrefix)_OUT_INTERMEDIATES)) \
458 ,$(eval _idfIntBase := $($(_idfPrefix)_OUT_INTERMEDIATES)) \
459 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800460 ) \
461 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
462)
463endef
464
465# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE
466# to determine the intermediates directory.
467#
468# $(1): if non-empty, force the intermediates to be COMMON
Ying Wang6ef65192014-01-15 16:02:16 -0800469# $(2): if non-empty, force the intermediates to be for the 2nd arch
The Android Open Source Project88b60792009-03-03 19:28:42 -0800470define local-intermediates-dir
471$(strip \
472 $(if $(strip $(LOCAL_MODULE_CLASS)),, \
473 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-intermediates-dir)) \
474 $(if $(strip $(LOCAL_MODULE)),, \
475 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-intermediates-dir)) \
Ying Wang6ef65192014-01-15 16:02:16 -0800476 $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(LOCAL_IS_HOST_MODULE),$(1),$(2)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800477)
478endef
479
480###########################################################
Colin Crossd8262642014-01-24 23:17:21 -0800481## The generated sources directory. Placing generated
482## source files directly in the intermediates directory
483## causes problems for multiarch builds, where there are
484## two intermediates directories for a single target. Put
485## them in a separate directory, and they will be copied to
486## each intermediates directory automatically.
487###########################################################
488
489# $(1): target class, like "APPS"
490# $(2): target name, like "NotePad"
491# $(3): if non-empty, this is a HOST target.
492# $(4): if non-empty, force the generated sources to be COMMON
493define generated-sources-dir-for
494$(strip \
495 $(eval _idfClass := $(strip $(1))) \
496 $(if $(_idfClass),, \
497 $(error $(LOCAL_PATH): Class not defined in call to generated-sources-dir-for)) \
498 $(eval _idfName := $(strip $(2))) \
499 $(if $(_idfName),, \
500 $(error $(LOCAL_PATH): Name not defined in call to generated-sources-dir-for)) \
501 $(eval _idfPrefix := $(if $(strip $(3)),HOST,TARGET)) \
502 $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
503 $(eval _idfIntBase := $($(_idfPrefix)_OUT_GEN_COMMON)) \
504 , \
505 $(eval _idfIntBase := $($(_idfPrefix)_OUT_GEN)) \
506 ) \
507 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
508)
509endef
510
511# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE
512# to determine the generated sources directory.
513#
514# $(1): if non-empty, force the intermediates to be COMMON
515define local-generated-sources-dir
516$(strip \
517 $(if $(strip $(LOCAL_MODULE_CLASS)),, \
518 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-generated-sources-dir)) \
519 $(if $(strip $(LOCAL_MODULE)),, \
520 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-generated-sources-dir)) \
521 $(call generated-sources-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(LOCAL_IS_HOST_MODULE),$(1)) \
522)
523endef
524
525###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800526## Convert "path/to/libXXX.so" to "-lXXX".
527## Any "path/to/libXXX.a" elements pass through unchanged.
528###########################################################
529
530define normalize-libraries
531$(foreach so,$(filter %.so,$(1)),-l$(patsubst lib%.so,%,$(notdir $(so))))\
532$(filter-out %.so,$(1))
533endef
534
535# TODO: change users to call the common version.
536define normalize-host-libraries
537$(call normalize-libraries,$(1))
538endef
539
540define normalize-target-libraries
541$(call normalize-libraries,$(1))
542endef
543
544###########################################################
545## Convert a list of short module names (e.g., "framework", "Browser")
546## into the list of files that are built for those modules.
547## NOTE: this won't return reliable results until after all
548## sub-makefiles have been included.
549## $(1): target list
550###########################################################
551
552define module-built-files
553$(foreach module,$(1),$(ALL_MODULES.$(module).BUILT))
554endef
555
556###########################################################
557## Convert a list of short modules names (e.g., "framework", "Browser")
558## into the list of files that are installed for those modules.
559## NOTE: this won't return reliable results until after all
560## sub-makefiles have been included.
561## $(1): target list
562###########################################################
563
564define module-installed-files
565$(foreach module,$(1),$(ALL_MODULES.$(module).INSTALLED))
566endef
567
568###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700569## Convert a list of short modules names (e.g., "framework", "Browser")
570## into the list of files that should be used when linking
571## against that module as a public API.
572## TODO: Allow this for more than JAVA_LIBRARIES modules
573## NOTE: this won't return reliable results until after all
574## sub-makefiles have been included.
575## $(1): target list
576###########################################################
577
578define module-stubs-files
579$(foreach module,$(1),$(ALL_MODULES.$(module).STUBS))
580endef
581
582###########################################################
583## Evaluates to the timestamp file for a doc module, which
584## is the dependency that should be used.
585## $(1): doc module
586###########################################################
587
588define doc-timestamp-for
589$(OUT_DOCS)/$(strip $(1))-timestamp
590endef
591
592
593###########################################################
Ying Wang912f8282010-09-28 17:27:56 -0700594## Convert "core ext framework" to "out/.../javalib.jar ..."
The Android Open Source Project88b60792009-03-03 19:28:42 -0800595## $(1): library list
596## $(2): Non-empty if IS_HOST_MODULE
597###########################################################
598
599# $(1): library name
600# $(2): Non-empty if IS_HOST_MODULE
601define _java-lib-dir
602$(call intermediates-dir-for, \
Ying Wang912f8282010-09-28 17:27:56 -0700603 JAVA_LIBRARIES,$(1),$(2),COMMON)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800604endef
605
606# $(1): library name
607# $(2): Non-empty if IS_HOST_MODULE
608define _java-lib-full-classes.jar
Ying Wang912f8282010-09-28 17:27:56 -0700609$(call _java-lib-dir,$(1),$(2))/classes$(COMMON_JAVA_PACKAGE_SUFFIX)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800610endef
611
612# $(1): library name list
613# $(2): Non-empty if IS_HOST_MODULE
614define java-lib-files
615$(foreach lib,$(1),$(call _java-lib-full-classes.jar,$(lib),$(2)))
616endef
617
618# $(1): library name
The Android Open Source Project88b60792009-03-03 19:28:42 -0800619# $(2): Non-empty if IS_HOST_MODULE
620define _java-lib-full-dep
Ying Wang45150f82013-02-27 15:23:42 -0800621$(call _java-lib-dir,$(1),$(2))/$(if $(2),javalib,classes)$(COMMON_JAVA_PACKAGE_SUFFIX)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800622endef
623
624# $(1): library name list
625# $(2): Non-empty if IS_HOST_MODULE
626define java-lib-deps
627$(foreach lib,$(1),$(call _java-lib-full-dep,$(lib),$(2)))
628endef
629
630###########################################################
Joe Onorato8dc8faa2010-09-14 13:09:48 -0400631## Run rot13 on a string
632## $(1): the string. Must be one line.
633###########################################################
634define rot13
635$(shell echo $(1) | tr 'a-zA-Z' 'n-za-mN-ZA-M')
636endef
637
638
639###########################################################
640## Returns true if $(1) and $(2) are equal. Returns
641## the empty string if they are not equal.
642###########################################################
643define streq
644$(strip $(if $(strip $(1)),\
645 $(if $(strip $(2)),\
646 $(if $(filter-out __,_$(subst $(strip $(1)),,$(strip $(2)))$(subst $(strip $(2)),,$(strip $(1)))_),,true), \
647 ),\
648 $(if $(strip $(2)),\
649 ,\
650 true)\
651 ))
652endef
653
654###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800655## Convert "a b c" into "a:b:c"
656###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800657define normalize-path-list
658$(subst $(space),:,$(strip $(1)))
659endef
660
661###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700662## Read the word out of a colon-separated list of words.
663## This has the same behavior as the built-in function
664## $(word n,str).
665##
666## The individual words may not contain spaces.
667##
668## $(1): 1 based index
669## $(2): value of the form a:b:c...
670###########################################################
671
672define word-colon
673$(word $(1),$(subst :,$(space),$(2)))
674endef
675
676###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800677## Convert "a=b c= d e = f" into "a=b c=d e=f"
678##
679## $(1): list to collapse
680## $(2): if set, separator word; usually "=", ":", or ":="
681## Defaults to "=" if not set.
682###########################################################
683
684define collapse-pairs
685$(eval _cpSEP := $(strip $(if $(2),$(2),=)))\
686$(subst $(space)$(_cpSEP)$(space),$(_cpSEP),$(strip \
687 $(subst $(_cpSEP), $(_cpSEP) ,$(1))))
688endef
689
The Android Open Source Project88b60792009-03-03 19:28:42 -0800690###########################################################
Ying Wang7e8d4422011-06-17 17:05:35 -0700691## Given a list of pairs, if multiple pairs have the same
692## first components, keep only the first pair.
693##
694## $(1): list of pairs
695## $(2): the separator word, such as ":", "=", etc.
696define uniq-pairs-by-first-component
697$(eval _upbfc_fc_set :=)\
698$(strip $(foreach w,$(1), $(eval _first := $(word 1,$(subst $(2),$(space),$(w))))\
699 $(if $(filter $(_upbfc_fc_set),$(_first)),,$(w)\
700 $(eval _upbfc_fc_set += $(_first)))))\
701$(eval _upbfc_fc_set :=)\
702$(eval _first:=)
703endef
704
705###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800706## MODULE_TAG set operations
707###########################################################
708
709# Given a list of tags, return the targets that specify
710# any of those tags.
711# $(1): tag list
712define modules-for-tag-list
713$(sort $(foreach tag,$(1),$(ALL_MODULE_TAGS.$(tag))))
714endef
715
716# Same as modules-for-tag-list, but operates on
717# ALL_MODULE_NAME_TAGS.
718# $(1): tag list
719define module-names-for-tag-list
720$(sort $(foreach tag,$(1),$(ALL_MODULE_NAME_TAGS.$(tag))))
721endef
722
723# Given an accept and reject list, find the matching
724# set of targets. If a target has multiple tags and
725# any of them are rejected, the target is rejected.
726# Reject overrides accept.
727# $(1): list of tags to accept
728# $(2): list of tags to reject
729#TODO(dbort): do $(if $(strip $(1)),$(1),$(ALL_MODULE_TAGS))
Jean-Baptiste Queru75127b72010-01-07 11:44:22 -0800730#TODO(jbq): as of 20100106 nobody uses the second parameter
The Android Open Source Project88b60792009-03-03 19:28:42 -0800731define get-tagged-modules
732$(filter-out \
733 $(call modules-for-tag-list,$(2)), \
734 $(call modules-for-tag-list,$(1)))
735endef
736
Joe Onorato64d85d02009-04-09 19:31:12 -0700737###########################################################
738## Append a leaf to a base path. Properly deals with
739## base paths ending in /.
740##
741## $(1): base path
742## $(2): leaf path
743###########################################################
744
745define append-path
746$(subst //,/,$(1)/$(2))
747endef
748
The Android Open Source Project88b60792009-03-03 19:28:42 -0800749
750###########################################################
751## Package filtering
752###########################################################
753
754# Given a list of installed modules (short or long names)
755# return a list of the packages (yes, .apk packages, not
756# modules in general) that are overridden by this list and,
757# therefore, should not be installed.
758# $(1): mixed list of installed modules
759# TODO: This is fragile; find a reliable way to get this information.
760define _get-package-overrides
761 $(eval ### Discard any words containing slashes, unless they end in .apk, \
762 ### in which case trim off the directory component and the suffix. \
763 ### If there are no slashes, keep the entire word.)
764 $(eval _gpo_names := $(subst /,@@@ @@@,$(1)))
765 $(eval _gpo_names := \
766 $(filter %.apk,$(_gpo_names)) \
767 $(filter-out %@@@ @@@%,$(_gpo_names)))
768 $(eval _gpo_names := $(patsubst %.apk,%,$(_gpo_names)))
769 $(eval _gpo_names := $(patsubst @@@%,%,$(_gpo_names)))
770
771 $(eval ### Remove any remaining words that contain dots.)
772 $(eval _gpo_names := $(subst .,@@@ @@@,$(_gpo_names)))
773 $(eval _gpo_names := $(filter-out %@@@ @@@%,$(_gpo_names)))
774
775 $(eval ### Now we have a list of any words that could possibly refer to \
776 ### packages, although there may be words that do not. Only \
777 ### real packages will be present under PACKAGES.*, though.)
778 $(foreach _gpo_name,$(_gpo_names),$(PACKAGES.$(_gpo_name).OVERRIDES))
779endef
780
781define get-package-overrides
Conley Owensd7a1a9b2011-12-22 09:46:19 -0800782$(sort $(strip $(call _get-package-overrides,$(1))))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800783endef
784
785###########################################################
786## Output the command lines, or not
787###########################################################
788
789ifeq ($(strip $(SHOW_COMMANDS)),)
790define pretty
791@echo $1
792endef
793hide := @
794else
795define pretty
796endef
797hide :=
798endif
799
800###########################################################
801## Dump the variables that are associated with targets
802###########################################################
803
804define dump-module-variables
805@echo all_dependencies=$^
806@echo PRIVATE_YACCFLAGS=$(PRIVATE_YACCFLAGS);
807@echo PRIVATE_CFLAGS=$(PRIVATE_CFLAGS);
808@echo PRIVATE_CPPFLAGS=$(PRIVATE_CPPFLAGS);
809@echo PRIVATE_DEBUG_CFLAGS=$(PRIVATE_DEBUG_CFLAGS);
810@echo PRIVATE_C_INCLUDES=$(PRIVATE_C_INCLUDES);
811@echo PRIVATE_LDFLAGS=$(PRIVATE_LDFLAGS);
812@echo PRIVATE_LDLIBS=$(PRIVATE_LDLIBS);
813@echo PRIVATE_ARFLAGS=$(PRIVATE_ARFLAGS);
814@echo PRIVATE_AAPT_FLAGS=$(PRIVATE_AAPT_FLAGS);
815@echo PRIVATE_DX_FLAGS=$(PRIVATE_DX_FLAGS);
Brian Carlstromf184a0f2010-02-01 11:13:32 -0800816@echo PRIVATE_JAVACFLAGS=$(PRIVATE_JAVACFLAGS);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800817@echo PRIVATE_JAVA_LIBRARIES=$(PRIVATE_JAVA_LIBRARIES);
818@echo PRIVATE_ALL_SHARED_LIBRARIES=$(PRIVATE_ALL_SHARED_LIBRARIES);
819@echo PRIVATE_ALL_STATIC_LIBRARIES=$(PRIVATE_ALL_STATIC_LIBRARIES);
820@echo PRIVATE_ALL_WHOLE_STATIC_LIBRARIES=$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES);
821@echo PRIVATE_ALL_OBJECTS=$(PRIVATE_ALL_OBJECTS);
Jeff Brown703e7c62011-02-04 20:15:00 -0800822@echo PRIVATE_NO_CRT=$(PRIVATE_NO_CRT);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800823endef
824
825###########################################################
826## Commands for using sed to replace given variable values
827###########################################################
828
829define transform-variables
830@mkdir -p $(dir $@)
831@echo "Sed: $(if $(PRIVATE_MODULE),$(PRIVATE_MODULE),$@) <= $<"
832$(hide) sed $(foreach var,$(REPLACE_VARS),-e "s/{{$(var)}}/$(subst /,\/,$(PWD)/$($(var)))/g") $< >$@
833$(hide) if [ "$(suffix $@)" = ".sh" ]; then chmod a+rx $@; fi
834endef
835
836
837###########################################################
838## Commands for munging the dependency files GCC generates
839###########################################################
Ying Wangc23f4ef2012-09-07 17:04:06 -0700840# $(1): the input .d file
841# $(2): the output .P file
842define transform-d-to-p-args
843$(hide) cp $(1) $(2); \
844 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
845 -e '/^$$/ d' -e 's/$$/ :/' < $(1) >> $(2); \
846 rm -f $(1)
847endef
The Android Open Source Project88b60792009-03-03 19:28:42 -0800848
849define transform-d-to-p
Ying Wangc23f4ef2012-09-07 17:04:06 -0700850$(call transform-d-to-p-args,$(@:%.o=%.d),$(@:%.o=%.P))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800851endef
852
853###########################################################
854## Commands for running lex
855###########################################################
856
857define transform-l-to-cpp
858@mkdir -p $(dir $@)
859@echo "Lex: $(PRIVATE_MODULE) <= $<"
860$(hide) $(LEX) -o$@ $<
861endef
862
863###########################################################
864## Commands for running yacc
865##
866## Because the extension of c++ files can change, the
867## extension must be specified in $1.
868## E.g, "$(call transform-y-to-cpp,.cpp)"
869###########################################################
870
871define transform-y-to-cpp
872@mkdir -p $(dir $@)
873@echo "Yacc: $(PRIVATE_MODULE) <= $<"
874$(YACC) $(PRIVATE_YACCFLAGS) -o $@ $<
875touch $(@:$1=$(YACC_HEADER_SUFFIX))
876echo '#ifndef '$(@F:$1=_h) > $(@:$1=.h)
877echo '#define '$(@F:$1=_h) >> $(@:$1=.h)
878cat $(@:$1=$(YACC_HEADER_SUFFIX)) >> $(@:$1=.h)
879echo '#endif' >> $(@:$1=.h)
880rm -f $(@:$1=$(YACC_HEADER_SUFFIX))
881endef
882
Ying Wang0bd59a02010-07-15 17:17:52 -0700883###########################################################
Tim Murraya7aa8002012-10-29 16:06:00 -0700884## Commands to compile RenderScript to Java
Ying Wang0bd59a02010-07-15 17:17:52 -0700885###########################################################
Ying Wang0bd59a02010-07-15 17:17:52 -0700886
887define transform-renderscripts-to-java-and-bc
888@echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)"
889$(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR)
890$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/res/raw
891$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/src
Ying Wang7d83ef82011-05-25 17:16:22 -0700892$(hide) $(PRIVATE_RS_CC) \
Ying Wangebfddaa2010-07-30 18:37:29 -0700893 -o $(PRIVATE_RS_OUTPUT_DIR)/res/raw \
894 -p $(PRIVATE_RS_OUTPUT_DIR)/src \
Ying Wang24e1c012010-10-07 18:57:57 -0700895 -d $(PRIVATE_RS_OUTPUT_DIR) \
896 -a $@ -MD \
Stephen Hinesc963eae2011-08-10 13:53:05 -0700897 $(addprefix -target-api , $(PRIVATE_RS_TARGET_API)) \
Stephen Hines914f7a22011-12-06 18:43:24 -0800898 $(PRIVATE_RS_FLAGS) \
Ying Wang51280272010-09-01 13:28:52 -0700899 $(foreach inc,$(PRIVATE_RS_INCLUDES),$(addprefix -I , $(inc))) \
Ying Wangebfddaa2010-07-30 18:37:29 -0700900 $(PRIVATE_RS_SOURCE_FILES)
Ying Wang0bd59a02010-07-15 17:17:52 -0700901$(hide) mkdir -p $(dir $@)
902$(hide) touch $@
903endef
904
Stephen Hinese719f282012-11-28 16:52:41 -0800905define transform-bc-to-so
Stephen Hines9ac9b532013-02-27 00:51:08 -0800906@echo "Renderscript compatibility: $(notdir $@) <= $(notdir $<)"
Stephen Hinese719f282012-11-28 16:52:41 -0800907$(hide) mkdir -p $(dir $@)
Stephen Hinesf6925132012-12-17 14:23:14 -0800908$(hide) $(BCC_COMPAT) -O3 -o $(dir $@)/$(notdir $(<:.bc=.o)) -fPIC -shared \
Tim Murray1a6f09a2013-03-05 11:07:15 -0800909 -rt-path $(RS_PREBUILT_CLCORE) -mtriple $(RS_TRIPLE) $<
Stephen Hines7d6ec712012-12-13 19:24:50 -0800910$(hide) $(PRIVATE_CXX) -shared -Wl,-soname,$(notdir $@) -nostdlib \
Stephen Hinesf6925132012-12-17 14:23:14 -0800911 -Wl,-rpath,\$$ORIGIN/../lib \
Stephen Hines9541f582013-01-18 16:27:23 -0800912 $(dir $@)/$(notdir $(<:.bc=.o)) \
Tim Murray1a6f09a2013-03-05 11:07:15 -0800913 $(RS_PREBUILT_COMPILER_RT) \
Stephen Hines9541f582013-01-18 16:27:23 -0800914 -o $@ -L prebuilts/gcc/ \
Tim Murray1a6f09a2013-03-05 11:07:15 -0800915 -L $(TARGET_OUT_INTERMEDIATE_LIBRARIES) $(RS_PREBUILT_LIBPATH) \
Stephen Hines8db4cce2013-03-27 16:51:38 -0700916 -lRSSupport -lm -lc
Stephen Hinese719f282012-11-28 16:52:41 -0800917endef
918
Tim Murraya7aa8002012-10-29 16:06:00 -0700919###########################################################
920## Commands to compile RenderScript to C++
921###########################################################
922
923define transform-renderscripts-to-cpp-and-bc
924@echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)"
925$(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR)
926$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/
927$(hide) $(PRIVATE_RS_CC) \
928 -o $(PRIVATE_RS_OUTPUT_DIR)/ \
929 -d $(PRIVATE_RS_OUTPUT_DIR) \
930 -a $@ -MD \
931 -reflect-c++ \
932 $(PRIVATE_RS_FLAGS) \
933 $(foreach inc,$(PRIVATE_RS_INCLUDES),$(addprefix -I , $(inc))) \
934 $(PRIVATE_RS_SOURCE_FILES)
935$(hide) mkdir -p $(dir $@)
936$(hide) touch $@
937endef
938
The Android Open Source Project88b60792009-03-03 19:28:42 -0800939
940###########################################################
941## Commands for running aidl
942###########################################################
943
944define transform-aidl-to-java
945@mkdir -p $(dir $@)
946@echo "Aidl: $(PRIVATE_MODULE) <= $<"
947$(hide) $(AIDL) -d$(patsubst %.java,%.P,$@) $(PRIVATE_AIDL_FLAGS) $< $@
948endef
949#$(AIDL) $(PRIVATE_AIDL_FLAGS) $< - | indent -nut -br -npcs -l1000 > $@
950
951
Doug Zongker9bd49622009-11-30 14:28:59 -0800952###########################################################
953## Commands for running java-event-log-tags.py
954###########################################################
955
956define transform-logtags-to-java
957@mkdir -p $(dir $@)
958@echo "logtags: $@ <= $<"
Doug Zongkerabfbbe22010-02-16 14:32:08 -0800959$(hide) $(JAVATAGS) -o $@ $^
Doug Zongker9bd49622009-11-30 14:28:59 -0800960endef
961
The Android Open Source Project88b60792009-03-03 19:28:42 -0800962
963###########################################################
Ying Wanga5fc87a2010-11-02 18:43:16 -0700964## Commands for running protoc to compile .proto into .java
965###########################################################
966
967define transform-proto-to-java
968@mkdir -p $(dir $@)
969@echo "Protoc: $@ <= $(PRIVATE_PROTO_SRC_FILES)"
970@rm -rf $(PRIVATE_PROTO_JAVA_OUTPUT_DIR)
971@mkdir -p $(PRIVATE_PROTO_JAVA_OUTPUT_DIR)
Ben Murdochfc2bad52013-07-25 11:44:53 +0100972$(hide) for f in $(PRIVATE_PROTO_SRC_FILES); do \
973 $(PROTOC) \
Ulas Kirazci28b46fc2013-07-24 14:32:14 -0700974 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
Ulas Kirazci6e485b52013-07-25 12:28:19 -0700975 $(PRIVATE_PROTO_JAVA_OUTPUT_OPTION)="$(PRIVATE_PROTO_JAVA_OUTPUT_PARAMS):$(PRIVATE_PROTO_JAVA_OUTPUT_DIR)" \
Ben Murdochfc2bad52013-07-25 11:44:53 +0100976 $(PRIVATE_PROTOC_FLAGS) \
977 $$f || exit 33; \
978 done
Ying Wanga5fc87a2010-11-02 18:43:16 -0700979$(hide) touch $@
980endef
981
982######################################################################
983## Commands for running protoc to compile .proto into .pb.cc and .pb.h
984######################################################################
985define transform-proto-to-cc
986@mkdir -p $(dir $@)
987@echo "Protoc: $@ <= $<"
988$(hide) $(PROTOC) \
989 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
Ying Wang33c0d952010-11-05 11:30:58 -0700990 $(PRIVATE_PROTOC_FLAGS) \
Ying Wanga5fc87a2010-11-02 18:43:16 -0700991 --cpp_out=$(PRIVATE_PROTO_CC_OUTPUT_DIR) $<
992endef
993
994
995###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800996## Commands for running gcc to compile a C++ file
997###########################################################
998
999define transform-cpp-to-o
1000@mkdir -p $(dir $@)
1001@echo "target $(PRIVATE_ARM_MODE) C++: $(PRIVATE_MODULE) <= $<"
1002$(hide) $(PRIVATE_CXX) \
Ying Wangddbcad82011-04-18 11:45:44 -07001003 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Andrew Boie85f3b212012-07-11 12:14:56 -07001004 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
Ying Wang4761e562011-04-12 11:06:35 -07001005 $(addprefix -isystem ,\
1006 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1007 $(filter-out $(PRIVATE_C_INCLUDES), \
Ying Wangddbcad82011-04-18 11:45:44 -07001008 $(PRIVATE_TARGET_PROJECT_INCLUDES) \
Ying Wang4761e562011-04-12 11:06:35 -07001009 $(PRIVATE_TARGET_C_INCLUDES)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001010 -c \
1011 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -07001012 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
1013 $(PRIVATE_TARGET_GLOBAL_CPPFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001014 $(PRIVATE_ARM_CFLAGS) \
1015 ) \
Doug Kwan9a8ecf92011-05-10 21:50:58 -07001016 $(PRIVATE_RTTI_FLAG) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001017 $(PRIVATE_CFLAGS) \
1018 $(PRIVATE_CPPFLAGS) \
1019 $(PRIVATE_DEBUG_CFLAGS) \
Atte Peltomaki60fe9632011-12-21 09:24:09 -08001020 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001021$(transform-d-to-p)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001022endef
1023
1024
1025###########################################################
1026## Commands for running gcc to compile a C file
1027###########################################################
1028
1029# $(1): extra flags
1030define transform-c-or-s-to-o-no-deps
1031@mkdir -p $(dir $@)
1032$(hide) $(PRIVATE_CC) \
Ying Wangddbcad82011-04-18 11:45:44 -07001033 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Andrew Boie85f3b212012-07-11 12:14:56 -07001034 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
Ying Wang4761e562011-04-12 11:06:35 -07001035 $(addprefix -isystem ,\
1036 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1037 $(filter-out $(PRIVATE_C_INCLUDES), \
Ying Wangddbcad82011-04-18 11:45:44 -07001038 $(PRIVATE_TARGET_PROJECT_INCLUDES) \
Ying Wang4761e562011-04-12 11:06:35 -07001039 $(PRIVATE_TARGET_C_INCLUDES)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001040 -c \
1041 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -07001042 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001043 $(PRIVATE_ARM_CFLAGS) \
1044 ) \
Ying Wang65d78522012-08-10 16:30:42 -07001045 $(1) \
Atte Peltomaki60fe9632011-12-21 09:24:09 -08001046 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
The Android Open Source Project88b60792009-03-03 19:28:42 -08001047endef
1048
1049define transform-c-to-o-no-deps
1050@echo "target $(PRIVATE_ARM_MODE) C: $(PRIVATE_MODULE) <= $<"
Ying Wang7429e212012-08-15 10:59:10 -07001051$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_CONLYFLAGS) $(PRIVATE_DEBUG_CFLAGS))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001052endef
1053
1054define transform-s-to-o-no-deps
1055@echo "target asm: $(PRIVATE_MODULE) <= $<"
1056$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
1057endef
1058
1059define transform-c-to-o
1060$(transform-c-to-o-no-deps)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001061$(transform-d-to-p)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001062endef
1063
1064define transform-s-to-o
1065$(transform-s-to-o-no-deps)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001066$(transform-d-to-p)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001067endef
1068
1069###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001070## Commands for running gcc to compile an Objective-C file
1071## This should never happen for target builds but this
1072## will error at build time.
1073###########################################################
1074
1075define transform-m-to-o-no-deps
1076@echo "target ObjC: $(PRIVATE_MODULE) <= $<"
Ying Wang65d78522012-08-10 16:30:42 -07001077$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_DEBUG_CFLAGS))
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001078endef
1079
1080define transform-m-to-o
1081$(transform-m-to-o-no-deps)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001082$(transform-d-to-p)
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001083endef
1084
1085###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001086## Commands for running gcc to compile a host C++ file
1087###########################################################
1088
1089define transform-host-cpp-to-o
1090@mkdir -p $(dir $@)
1091@echo "host C++: $(PRIVATE_MODULE) <= $<"
1092$(hide) $(PRIVATE_CXX) \
Ying Wangddbcad82011-04-18 11:45:44 -07001093 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Andrew Boie85f3b212012-07-11 12:14:56 -07001094 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
Ying Wangddbcad82011-04-18 11:45:44 -07001095 $(addprefix -isystem ,\
The Android Open Source Project88b60792009-03-03 19:28:42 -08001096 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wangddbcad82011-04-18 11:45:44 -07001097 $(filter-out $(PRIVATE_C_INCLUDES), \
1098 $(HOST_PROJECT_INCLUDES) \
Logan Chiene6f65432013-12-10 19:07:41 +08001099 $(PRIVATE_HOST_C_INCLUDES)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001100 -c \
1101 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001102 $(PRIVATE_HOST_GLOBAL_CFLAGS) \
1103 $(PRIVATE_HOST_GLOBAL_CPPFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001104 ) \
1105 $(PRIVATE_CFLAGS) \
1106 $(PRIVATE_CPPFLAGS) \
1107 $(PRIVATE_DEBUG_CFLAGS) \
Atte Peltomaki60fe9632011-12-21 09:24:09 -08001108 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
The Android Open Source Project88b60792009-03-03 19:28:42 -08001109$(transform-d-to-p)
1110endef
1111
1112
1113###########################################################
1114## Commands for running gcc to compile a host C file
1115###########################################################
1116
1117# $(1): extra flags
1118define transform-host-c-or-s-to-o-no-deps
1119@mkdir -p $(dir $@)
1120$(hide) $(PRIVATE_CC) \
Ying Wangddbcad82011-04-18 11:45:44 -07001121 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Andrew Boie85f3b212012-07-11 12:14:56 -07001122 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
Ying Wangddbcad82011-04-18 11:45:44 -07001123 $(addprefix -isystem ,\
The Android Open Source Project88b60792009-03-03 19:28:42 -08001124 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wangddbcad82011-04-18 11:45:44 -07001125 $(filter-out $(PRIVATE_C_INCLUDES), \
1126 $(HOST_PROJECT_INCLUDES) \
Logan Chiene6f65432013-12-10 19:07:41 +08001127 $(PRIVATE_HOST_C_INCLUDES)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001128 -c \
1129 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001130 $(PRIVATE_HOST_GLOBAL_CFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001131 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001132 $(1) \
Atte Peltomaki60fe9632011-12-21 09:24:09 -08001133 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
The Android Open Source Project88b60792009-03-03 19:28:42 -08001134endef
1135
1136define transform-host-c-to-o-no-deps
1137@echo "host C: $(PRIVATE_MODULE) <= $<"
Ying Wang7429e212012-08-15 10:59:10 -07001138$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_CONLYFLAGS) $(PRIVATE_DEBUG_CFLAGS))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001139endef
1140
1141define transform-host-s-to-o-no-deps
1142@echo "host asm: $(PRIVATE_MODULE) <= $<"
1143$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
1144endef
1145
1146define transform-host-c-to-o
1147$(transform-host-c-to-o-no-deps)
1148$(transform-d-to-p)
1149endef
1150
1151define transform-host-s-to-o
1152$(transform-host-s-to-o-no-deps)
1153$(transform-d-to-p)
1154endef
1155
1156###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001157## Commands for running gcc to compile a host Objective-C file
1158###########################################################
1159
1160define transform-host-m-to-o-no-deps
1161@echo "host ObjC: $(PRIVATE_MODULE) <= $<"
Ying Wang65d78522012-08-10 16:30:42 -07001162$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_DEBUG_CFLAGS))
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001163endef
1164
David 'Digit' Turner5ca286d2011-02-11 16:19:31 +01001165define transform-host-m-to-o
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001166$(transform-host-m-to-o-no-deps)
1167$(transform-d-to-p)
1168endef
1169
1170###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001171## Commands for running ar
1172###########################################################
1173
Ying Wange4b24eb2010-05-27 11:55:39 -07001174define _concat-if-arg2-not-empty
1175$(if $(2),$(hide) $(1) $(2))
1176endef
1177
1178# Split long argument list into smaller groups and call the command repeatedly
Torne (Richard Coles)bffaef22012-06-15 16:03:52 +01001179# Call the command at least once even if there are no arguments, as otherwise
1180# the output file won't be created.
Ying Wange4b24eb2010-05-27 11:55:39 -07001181#
1182# $(1): the command without arguments
1183# $(2): the arguments
1184define split-long-arguments
Torne (Richard Coles)bffaef22012-06-15 16:03:52 +01001185$(hide) $(1) $(wordlist 1,500,$(2))
Ying Wange4b24eb2010-05-27 11:55:39 -07001186$(call _concat-if-arg2-not-empty,$(1),$(wordlist 501,1000,$(2)))
1187$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1001,1500,$(2)))
1188$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1501,2000,$(2)))
1189$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2001,2500,$(2)))
1190$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2501,3000,$(2)))
1191$(call _concat-if-arg2-not-empty,$(1),$(wordlist 3001,99999,$(2)))
1192endef
1193
Ying Wanga02d3d92011-01-27 18:48:00 -08001194# $(1): the full path of the source static library.
1195define _extract-and-include-single-target-whole-static-lib
1196@echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(1)]"
1197$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\
1198 rm -rf $$ldir; \
1199 mkdir -p $$ldir; \
1200 filelist=; \
1201 for f in `$(TARGET_AR) t $(1)`; do \
Ying Wang6ef65192014-01-15 16:02:16 -08001202 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) p $(1) $$f > $$ldir/$$f; \
Ying Wanga02d3d92011-01-27 18:48:00 -08001203 filelist="$$filelist $$ldir/$$f"; \
1204 done ; \
Ying Wang6ef65192014-01-15 16:02:16 -08001205 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \
1206 $(PRIVATE_ARFLAGS) $@ $$filelist
Ying Wanga02d3d92011-01-27 18:48:00 -08001207
1208endef
1209
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001210define extract-and-include-target-whole-static-libs
Dima Zavin46e9bec2009-05-27 19:41:07 -07001211$(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \
Ying Wanga02d3d92011-01-27 18:48:00 -08001212 $(call _extract-and-include-single-target-whole-static-lib, $(lib)))
Dima Zavin46e9bec2009-05-27 19:41:07 -07001213endef
1214
The Android Open Source Project88b60792009-03-03 19:28:42 -08001215# Explicitly delete the archive first so that ar doesn't
1216# try to add to an existing archive.
1217define transform-o-to-static-lib
1218@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001219@rm -f $@
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001220$(extract-and-include-target-whole-static-libs)
Dima Zavin46e9bec2009-05-27 19:41:07 -07001221@echo "target StaticLib: $(PRIVATE_MODULE) ($@)"
Ying Wang6ef65192014-01-15 16:02:16 -08001222$(call split-long-arguments,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \
1223 $(PRIVATE_ARFLAGS) $@,$(filter %.o, $^))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001224endef
1225
1226###########################################################
1227## Commands for running host ar
1228###########################################################
1229
Ying Wanga02d3d92011-01-27 18:48:00 -08001230# $(1): the full path of the source static library.
1231define _extract-and-include-single-host-whole-static-lib
1232@echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(1)]"
1233$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\
1234 rm -rf $$ldir; \
1235 mkdir -p $$ldir; \
1236 filelist=; \
Jeff Hamilton293f9392011-11-18 17:15:25 -06001237 for f in `$(HOST_AR) t $(1) | \grep '\.o$$'`; do \
Ying Wanga02d3d92011-01-27 18:48:00 -08001238 $(HOST_AR) p $(1) $$f > $$ldir/$$f; \
1239 filelist="$$filelist $$ldir/$$f"; \
1240 done ; \
1241 $(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $$filelist
1242
1243endef
1244
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001245define extract-and-include-host-whole-static-libs
1246$(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \
Ying Wanga02d3d92011-01-27 18:48:00 -08001247 $(call _extract-and-include-single-host-whole-static-lib, $(lib)))
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001248endef
1249
The Android Open Source Project88b60792009-03-03 19:28:42 -08001250# Explicitly delete the archive first so that ar doesn't
1251# try to add to an existing archive.
1252define transform-host-o-to-static-lib
1253@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001254@rm -f $@
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001255$(extract-and-include-host-whole-static-libs)
Dan Bornstein6bffc912009-10-15 13:01:36 -07001256@echo "host StaticLib: $(PRIVATE_MODULE) ($@)"
Ying Wange4b24eb2010-05-27 11:55:39 -07001257$(call split-long-arguments,$(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@,$(filter %.o, $^))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001258endef
1259
1260
1261###########################################################
1262## Commands for running gcc to link a shared library or package
1263###########################################################
1264
1265# ld just seems to be so finicky with command order that we allow
1266# it to be overriden en-masse see combo/linux-arm.make for an example.
1267ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1268define transform-host-o-to-shared-lib-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001269$(hide) $(PRIVATE_CXX) \
Ying Wang80e6cce2011-01-24 23:25:36 -08001270 -Wl,-rpath-link=$(HOST_OUT_INTERMEDIATE_LIBRARIES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001271 -Wl,-rpath,\$$ORIGIN/../lib \
1272 -shared -Wl,-soname,$(notdir $@) \
1273 $(PRIVATE_LDFLAGS) \
1274 $(HOST_GLOBAL_LD_DIRS) \
1275 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001276 $(PRIVATE_HOST_GLOBAL_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001277 ) \
1278 $(PRIVATE_ALL_OBJECTS) \
1279 -Wl,--whole-archive \
1280 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1281 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001282 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001283 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001284 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001285 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1286 -o $@ \
1287 $(PRIVATE_LDLIBS)
1288endef
1289endif
1290
1291define transform-host-o-to-shared-lib
1292@mkdir -p $(dir $@)
1293@echo "host SharedLib: $(PRIVATE_MODULE) ($@)"
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001294$(transform-host-o-to-shared-lib-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001295endef
1296
1297define transform-host-o-to-package
1298@mkdir -p $(dir $@)
1299@echo "host Package: $(PRIVATE_MODULE) ($@)"
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001300$(transform-host-o-to-shared-lib-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001301endef
1302
1303
1304###########################################################
1305## Commands for running gcc to link a shared library or package
1306###########################################################
1307
1308#echo >$@.vers "{"; \
1309#echo >>$@.vers " global:"; \
1310#$(BUILD_SYSTEM)/filter_symbols.sh $(TARGET_NM) " " ";" $(filter %.o,$^) | sort -u >>$@.vers; \
1311#echo >>$@.vers " local:"; \
1312#echo >>$@.vers " *;"; \
1313#echo >>$@.vers "};"; \
1314
1315# -Wl,--version-script=$@.vers \
1316
1317# ld just seems to be so finicky with command order that we allow
1318# it to be overriden en-masse see combo/linux-arm.make for an example.
1319ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1320define transform-o-to-shared-lib-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001321$(hide) $(PRIVATE_CXX) \
Ying Wang1a081002010-07-13 14:55:47 -07001322 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001323 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1324 -Wl,-rpath,\$$ORIGIN/../lib \
1325 -shared -Wl,-soname,$(notdir $@) \
1326 $(PRIVATE_LDFLAGS) \
Ying Wang1a081002010-07-13 14:55:47 -07001327 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001328 $(PRIVATE_ALL_OBJECTS) \
1329 -Wl,--whole-archive \
Ying Wang80e6cce2011-01-24 23:25:36 -08001330 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001331 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001332 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001333 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001334 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001335 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1336 -o $@ \
1337 $(PRIVATE_LDLIBS)
1338endef
1339endif
1340
1341define transform-o-to-shared-lib
1342@mkdir -p $(dir $@)
1343@echo "target SharedLib: $(PRIVATE_MODULE) ($@)"
Ying Wang4d2cc662014-01-16 12:36:34 -08001344$($(PRIVATE_2ND_ARCH_VAR_PREFIX)transform-o-to-shared-lib-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001345endef
1346
1347
1348###########################################################
1349## Commands for filtering a target executable or library
1350###########################################################
1351
The Android Open Source Project88b60792009-03-03 19:28:42 -08001352define transform-to-stripped
1353@mkdir -p $(dir $@)
1354@echo "target Strip: $(PRIVATE_MODULE) ($@)"
Ying Wang4d2cc662014-01-16 12:36:34 -08001355$(hide) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_STRIP_COMMAND)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001356endef
1357
The Android Open Source Project88b60792009-03-03 19:28:42 -08001358
1359###########################################################
1360## Commands for running gcc to link an executable
1361###########################################################
1362
1363ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1364define transform-o-to-executable-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001365$(hide) $(PRIVATE_CXX) \
Ying Wangc6ffc002012-09-25 17:52:10 -07001366 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
1367 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001368 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1369 -Wl,-rpath,\$$ORIGIN/../lib \
1370 $(PRIVATE_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001371 $(PRIVATE_ALL_OBJECTS) \
1372 -Wl,--whole-archive \
1373 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1374 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001375 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001376 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001377 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001378 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1379 -o $@ \
1380 $(PRIVATE_LDLIBS)
1381endef
1382endif
1383
1384define transform-o-to-executable
1385@mkdir -p $(dir $@)
1386@echo "target Executable: $(PRIVATE_MODULE) ($@)"
Ying Wangdd814bf2014-01-17 16:17:28 -08001387$($(PRIVATE_2ND_ARCH_VAR_PREFIX)transform-o-to-executable-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001388endef
1389
1390
1391###########################################################
1392## Commands for running gcc to link a statically linked
1393## executable. In practice, we only use this on arm, so
1394## the other platforms don't have the
1395## transform-o-to-static-executable defined
1396###########################################################
1397
1398ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1399define transform-o-to-static-executable-inner
1400endef
1401endif
1402
1403define transform-o-to-static-executable
1404@mkdir -p $(dir $@)
1405@echo "target StaticExecutable: $(PRIVATE_MODULE) ($@)"
Ying Wangdd814bf2014-01-17 16:17:28 -08001406$($(PRIVATE_2ND_ARCH_VAR_PREFIX)transform-o-to-static-executable-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001407endef
1408
1409
1410###########################################################
1411## Commands for running gcc to link a host executable
1412###########################################################
1413
1414ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1415define transform-host-o-to-executable-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001416$(hide) $(PRIVATE_CXX) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001417 $(PRIVATE_ALL_OBJECTS) \
1418 -Wl,--whole-archive \
1419 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1420 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001421 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001422 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001423 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001424 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
Conley Owensd9e7d252011-11-10 09:57:40 -08001425 -Wl,-rpath-link=$(HOST_OUT_INTERMEDIATE_LIBRARIES) \
1426 -Wl,-rpath,\$$ORIGIN/../lib \
1427 $(HOST_GLOBAL_LD_DIRS) \
1428 $(PRIVATE_LDFLAGS) \
1429 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001430 $(PRIVATE_HOST_GLOBAL_LDFLAGS) \
Joshua J. Drakeb0eafa22013-12-12 00:34:29 -06001431 -fPIE -pie \
Conley Owensd9e7d252011-11-10 09:57:40 -08001432 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001433 -o $@ \
1434 $(PRIVATE_LDLIBS)
1435endef
1436endif
1437
1438define transform-host-o-to-executable
1439@mkdir -p $(dir $@)
1440@echo "host Executable: $(PRIVATE_MODULE) ($@)"
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001441$(transform-host-o-to-executable-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001442endef
1443
1444
1445###########################################################
1446## Commands for running javac to make .class files
1447###########################################################
1448
1449#@echo "Source intermediates dir: $(PRIVATE_SOURCE_INTERMEDIATES_DIR)"
1450#@echo "Source intermediates: $$(find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java')"
1451
1452# TODO: Right now we generate the asset resources twice, first as part
1453# of generating the Java classes, then at the end when packaging the final
1454# assets. This should be changed to do one of two things: (1) Don't generate
1455# any resource files the first time, only create classes during that stage;
1456# or (2) Don't use the -c flag with the second stage, instead taking the
1457# resource files from the first stage as additional input. My original intent
1458# was to use approach (2), but this requires a little more work in the tool.
1459# Maybe we should just use approach (1).
1460
1461# This rule creates the R.java and Manifest.java files, both of which
Ying Wang4f1ab922011-03-15 13:19:30 -07001462# are PRODUCT-neutral. Don't pass PRIVATE_PRODUCT_AAPT_CONFIG to this invocation.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001463define create-resource-java-files
1464@mkdir -p $(PRIVATE_SOURCE_INTERMEDIATES_DIR)
1465@mkdir -p $(dir $(PRIVATE_RESOURCE_PUBLICS_OUTPUT))
Ying Wangc61d5932010-03-10 16:02:42 -08001466$(hide) $(AAPT) package $(PRIVATE_AAPT_FLAGS) -m \
Ying Wang4f1ab922011-03-15 13:19:30 -07001467 $(eval # PRIVATE_PRODUCT_AAPT_CONFIG is intentionally missing-- see comment.) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001468 $(addprefix -J , $(PRIVATE_SOURCE_INTERMEDIATES_DIR)) \
1469 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
1470 $(addprefix -P , $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) \
1471 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
1472 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001473 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
Joe Onorato2daa2b32009-08-30 13:39:24 -07001474 $(addprefix -G , $(PRIVATE_PROGUARD_OPTIONS_FILE)) \
Ying Wangbb9c2302011-04-08 17:27:35 -07001475 $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
1476 $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
Ying Wang1ae607a2010-06-23 13:34:22 -07001477 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \
Ying Wang8f5069b2010-06-29 11:08:13 -07001478 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION)-$(BUILD_NUMBER))) \
Ying Wang8c254822010-03-16 16:13:56 -07001479 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07001480 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001481endef
1482
1483ifeq ($(HOST_OS),windows)
1484xlint_unchecked :=
1485else
Jeffrey Chyan7adbf972010-07-07 13:42:19 -05001486xlint_unchecked := -Xlint:unchecked
The Android Open Source Project88b60792009-03-03 19:28:42 -08001487endif
1488
Brian Carlstrombb7c6d82011-04-01 15:45:58 -07001489ifeq (true, $(ENABLE_INCREMENTALJAVAC))
1490incremental_dex := --incremental
1491else
1492incremental_dex :=
1493endif
1494
The Android Open Source Project88b60792009-03-03 19:28:42 -08001495# emit-line, <word list>, <output file>
1496define emit-line
1497 $(if $(1),echo -n '$(strip $(1)) ' >> $(2))
1498endef
1499
1500# dump-words-to-file, <word list>, <output file>
1501define dump-words-to-file
1502 @rm -f $(2)
1503 @$(call emit-line,$(wordlist 1,200,$(1)),$(2))
1504 @$(call emit-line,$(wordlist 201,400,$(1)),$(2))
1505 @$(call emit-line,$(wordlist 401,600,$(1)),$(2))
1506 @$(call emit-line,$(wordlist 601,800,$(1)),$(2))
1507 @$(call emit-line,$(wordlist 801,1000,$(1)),$(2))
1508 @$(call emit-line,$(wordlist 1001,1200,$(1)),$(2))
1509 @$(call emit-line,$(wordlist 1201,1400,$(1)),$(2))
1510 @$(call emit-line,$(wordlist 1401,1600,$(1)),$(2))
1511 @$(call emit-line,$(wordlist 1601,1800,$(1)),$(2))
1512 @$(call emit-line,$(wordlist 1801,2000,$(1)),$(2))
1513 @$(call emit-line,$(wordlist 2001,2200,$(1)),$(2))
1514 @$(call emit-line,$(wordlist 2201,2400,$(1)),$(2))
1515 @$(call emit-line,$(wordlist 2401,2600,$(1)),$(2))
1516 @$(call emit-line,$(wordlist 2601,2800,$(1)),$(2))
1517 @$(call emit-line,$(wordlist 2801,3000,$(1)),$(2))
1518 @$(call emit-line,$(wordlist 3001,3200,$(1)),$(2))
1519 @$(call emit-line,$(wordlist 3201,3400,$(1)),$(2))
1520 @$(call emit-line,$(wordlist 3401,3600,$(1)),$(2))
1521 @$(call emit-line,$(wordlist 3601,3800,$(1)),$(2))
1522 @$(call emit-line,$(wordlist 3801,4000,$(1)),$(2))
Jesse Wilson72c941a2010-05-04 16:33:49 -07001523 @$(call emit-line,$(wordlist 4001,4200,$(1)),$(2))
1524 @$(call emit-line,$(wordlist 4201,4400,$(1)),$(2))
1525 @$(call emit-line,$(wordlist 4401,4600,$(1)),$(2))
1526 @$(call emit-line,$(wordlist 4601,4800,$(1)),$(2))
1527 @$(call emit-line,$(wordlist 4801,5000,$(1)),$(2))
1528 @$(if $(wordlist 5001,5002,$(1)),$(error Too many words ($(words $(1)))))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001529endef
1530
1531# For a list of jar files, unzip them to a specified directory,
1532# but make sure that no META-INF files come along for the ride.
1533#
1534# $(1): files to unzip
1535# $(2): destination directory
1536define unzip-jar-files
1537 $(hide) for f in $(1); \
1538 do \
1539 if [ ! -f $$f ]; then \
1540 echo Missing file $$f; \
1541 exit 1; \
1542 fi; \
Sriram Ramanf1a55f82009-06-09 15:08:29 -07001543 unzip -qo $$f -d $(2); \
Ying Wang3a6f7582012-08-30 12:59:42 -07001544 done \
1545 $(if $(PRIVATE_DONT_DELETE_JAR_META_INF),,;rm -rf $(2)/META-INF)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001546endef
1547
Brian Carlstrom78269512010-12-10 12:10:24 -08001548# Common definition to invoke javac on the host and target.
1549#
1550# Some historical notes:
1551# - below we write the list of java files to java-source-list to avoid argument
1552# list length problems with Cygwin
1553# - we filter out duplicate java file names because eclipse's compiler
1554# doesn't like them.
1555#
1556# $(1): javac
1557# $(2): bootclasspath
1558define compile-java
Joe Onorato64d85d02009-04-09 19:31:12 -07001559$(hide) rm -f $@
1560$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
Brian Carlstrom78269512010-12-10 12:10:24 -08001561$(hide) mkdir -p $(dir $@)
Joe Onorato64d85d02009-04-09 19:31:12 -07001562$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
Brian Carlstrom78269512010-12-10 12:10:24 -08001563$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES),$(PRIVATE_CLASS_INTERMEDIATES_DIR))
Ying Wang015edd22011-01-20 15:01:56 -08001564$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list)
Joe Onorato64d85d02009-04-09 19:31:12 -07001565$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
Ying Wang015edd22011-01-20 15:01:56 -08001566 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list; \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001567fi
Ying Wang015edd22011-01-20 15:01:56 -08001568$(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \
1569 | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
Ying Wange109a1d2011-12-12 17:52:03 -08001570$(hide) if [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
1571 $(1) -encoding UTF-8 \
Brian Carlstrom78269512010-12-10 12:10:24 -08001572 $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) \
Ying Wang057eba02012-10-18 10:54:49 -07001573 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
Brian Carlstrom78269512010-12-10 12:10:24 -08001574 $(2) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001575 $(addprefix -classpath ,$(strip \
1576 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \
Ying Wang057eba02012-10-18 10:54:49 -07001577 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001578 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
Brian Carlstrom78269512010-12-10 12:10:24 -08001579 $(PRIVATE_JAVACFLAGS) \
Ying Wang015edd22011-01-20 15:01:56 -08001580 \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \
Ying Wange109a1d2011-12-12 17:52:03 -08001581 || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 ) \
1582fi
Joe Onorato0eccce92011-10-30 21:37:35 -07001583$(if $(PRIVATE_JAVA_LAYERS_FILE), $(hide) build/tools/java-layers.py \
1584 $(PRIVATE_JAVA_LAYERS_FILE) \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq,)
Ying Wang015edd22011-01-20 15:01:56 -08001585$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list
1586$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
Ying Wang5758b8e2011-12-15 16:36:55 -08001587$(if $(PRIVATE_JAR_EXCLUDE_FILES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
1588 -name $(word 1, $(PRIVATE_JAR_EXCLUDE_FILES)) \
1589 $(addprefix -o -name , $(wordlist 2, 999, $(PRIVATE_JAR_EXCLUDE_FILES))) \
1590 | xargs rm -rf)
Jeff Brownae859f92013-07-17 20:29:51 -07001591$(if $(PRIVATE_JAR_PACKAGES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -mindepth 1 -type d \
1592 $(foreach pkg, $(PRIVATE_JAR_PACKAGES), \
1593 -not -path $(PRIVATE_CLASS_INTERMEDIATES_DIR)/$(subst .,/,$(pkg))) \
1594 | xargs rm -rf)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001595$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \
1596 $@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
Brian Carlstrom78269512010-12-10 12:10:24 -08001597endef
1598
1599define transform-java-to-classes.jar
1600@echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
1601$(call compile-java,$(TARGET_JAVAC),$(PRIVATE_BOOTCLASSPATH))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001602endef
1603
Ying Wang015edd22011-01-20 15:01:56 -08001604# Override the above definitions if we want to do incremetal javac
1605ifeq (true, $(ENABLE_INCREMENTALJAVAC))
1606define compile-java
1607$(hide) mkdir -p $(dir $@)
1608$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1609$(hide) touch $(PRIVATE_CLASS_INTERMEDIATES_DIR)/newstamp
1610$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES),$(PRIVATE_CLASS_INTERMEDIATES_DIR))
1611$(hide) if [ -e $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stamp ] ; then \
1612 newerFlag=$$(echo -n "-newer $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stamp") ; \
1613 fi ; \
1614 find $(PRIVATE_JAVA_SOURCES) $$newerFlag > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list ; \
1615 if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
1616 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' $$newerFlag >> $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list; \
1617 fi
1618$(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \
1619 | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
1620@echo "(Incremental) build source files:"
1621@cat $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
1622$(hide) if [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
Joe Onorato149dd912011-05-31 18:21:07 -07001623 $(1) -encoding UTF-8 \
Ying Wang015edd22011-01-20 15:01:56 -08001624 $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) \
Ying Wang057eba02012-10-18 10:54:49 -07001625 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
Ying Wang015edd22011-01-20 15:01:56 -08001626 $(2) \
1627 $(addprefix -classpath ,$(strip \
1628 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES) $(PRIVATE_CLASS_INTERMEDIATES_DIR)))) \
Ying Wang057eba02012-10-18 10:54:49 -07001629 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
Ying Wang015edd22011-01-20 15:01:56 -08001630 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
1631 $(PRIVATE_JAVACFLAGS) \
1632 \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \
1633 || ( exit 41 ) \
1634fi
1635$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list
1636$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
1637$(hide) rm -f $@
Ying Wangae25ec12012-06-19 10:40:37 -07001638$(if $(PRIVATE_JAR_EXCLUDE_FILES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
1639 -name $(word 1, $(PRIVATE_JAR_EXCLUDE_FILES)) \
1640 $(addprefix -o -name , $(wordlist 2, 999, $(PRIVATE_JAR_EXCLUDE_FILES))) \
1641 | xargs rm -rf)
Jeff Brownae859f92013-07-17 20:29:51 -07001642$(if $(PRIVATE_JAR_PACKAGES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -mindepth 1 -type d \
1643 $(foreach pkg, $(PRIVATE_JAR_PACKAGES), \
1644 -not -path $(PRIVATE_CLASS_INTERMEDIATES_DIR)/$(subst .,/,$(pkg))) \
1645 | xargs rm -rf)
Ying Wang015edd22011-01-20 15:01:56 -08001646$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \
1647 $@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
1648$(hide) mv $(PRIVATE_CLASS_INTERMEDIATES_DIR)/newstamp $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stamp
1649endef
1650
1651define transform-java-to-classes.jar
1652@echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
1653$(call compile-java,$(TARGET_JAVAC),$(PRIVATE_BOOTCLASSPATH))
1654endef
1655endif # ENABLE_INCREMENTALJAVAC
1656
The Android Open Source Project88b60792009-03-03 19:28:42 -08001657define transform-classes.jar-to-emma
1658$(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \
Guang Zhu155afe32010-03-10 15:48:03 -08001659 $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR) \
Guang Zhu9cd3d8c2010-06-15 13:31:25 -07001660 $(addprefix -ix , $(PRIVATE_EMMA_COVERAGE_FILTER))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001661endef
1662
1663#TODO: use a smaller -Xmx value for most libraries;
1664# only core.jar and framework.jar need a heap this big.
Raphaelf6ff4c52009-08-18 14:43:32 -07001665# 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 -08001666define transform-classes.jar-to-dex
1667@echo "target Dex: $(PRIVATE_MODULE)"
1668@mkdir -p $(dir $@)
Raphaelf6ff4c52009-08-18 14:43:32 -07001669$(hide) $(DX) \
Wink Saville29b3afa2012-01-30 15:30:10 -08001670 $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx2048M) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001671 --dex --output=$@ \
Brian Carlstrombb7c6d82011-04-01 15:45:58 -07001672 $(incremental_dex) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001673 $(if $(NO_OPTIMIZE_DX), \
1674 --no-optimize) \
1675 $(if $(GENERATE_DEX_DEBUG), \
1676 --debug --verbose \
1677 --dump-to=$(@:.dex=.lst) \
1678 --dump-width=1000) \
1679 $(PRIVATE_DX_FLAGS) \
1680 $<
1681endef
1682
1683# Create a mostly-empty .jar file that we'll add to later.
1684# The MacOS jar tool doesn't like creating empty jar files,
1685# so we need to give it something.
1686define create-empty-package
1687@mkdir -p $(dir $@)
1688$(hide) touch $(dir $@)/dummy
1689$(hide) (cd $(dir $@) && jar cf $(notdir $@) dummy)
1690$(hide) zip -qd $@ dummy
1691$(hide) rm $(dir $@)/dummy
1692endef
1693
1694#TODO: we kinda want to build different asset packages for
1695# different configurations, then combine them later (or something).
1696# Per-locale, etc.
1697# A list of dynamic and static parameters; build layers for
1698# dynamic params that lay over the static ones.
1699#TODO: update the manifest to point to the package file
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001700#Note that the version numbers are given to aapt as simple default
1701#values; applications can override these by explicitly stating
1702#them in their manifest.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001703define add-assets-to-package
Ying Wangc61d5932010-03-10 16:02:42 -08001704$(hide) $(AAPT) package -u $(PRIVATE_AAPT_FLAGS) \
Ying Wang4f1ab922011-03-15 13:19:30 -07001705 $(addprefix -c , $(PRIVATE_PRODUCT_AAPT_CONFIG)) \
Dianne Hackborna0f464a2011-10-14 19:37:57 -07001706 $(addprefix --preferred-configurations , $(PRIVATE_PRODUCT_AAPT_PREF_CONFIG)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001707 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
1708 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
1709 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
1710 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
Ying Wangbb9c2302011-04-08 17:27:35 -07001711 $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
1712 $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
Joe Onorato700b88e2010-10-05 17:33:58 -04001713 $(addprefix --product , $(TARGET_AAPT_CHARACTERISTICS)) \
Ying Wang1ae607a2010-06-23 13:34:22 -07001714 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \
Ying Wang8f5069b2010-06-29 11:08:13 -07001715 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION)-$(BUILD_NUMBER))) \
Jeff Hamiltonbb67d212010-02-05 22:36:42 -06001716 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07001717 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001718 -F $@
1719endef
1720
The Android Open Source Project88b60792009-03-03 19:28:42 -08001721define add-jni-shared-libs-to-package
1722$(hide) rm -rf $(dir $@)lib
Jack Palevicha0ab29b2010-06-18 15:38:07 +08001723$(hide) mkdir -p $(dir $@)lib/$(PRIVATE_JNI_SHARED_LIBRARIES_ABI)
1724$(hide) cp $(PRIVATE_JNI_SHARED_LIBRARIES) $(dir $@)lib/$(PRIVATE_JNI_SHARED_LIBRARIES_ABI)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001725$(hide) (cd $(dir $@) && zip -r $(notdir $@) lib)
1726$(hide) rm -rf $(dir $@)lib
1727endef
1728
The Android Open Source Project88b60792009-03-03 19:28:42 -08001729#TODO: update the manifest to point to the dex file
1730define add-dex-to-package
Ying Wang957fea52010-09-23 11:48:38 -07001731$(if $(filter classes.dex,$(notdir $(PRIVATE_DEX_FILE))),\
-b masterc3ccfee2013-01-23 16:54:32 -08001732$(hide) zip -qj $@ $(PRIVATE_DEX_FILE),\
Ying Wang6e7db382011-07-27 12:49:15 -07001733$(hide) _adtp_classes_dex=$(dir $(PRIVATE_DEX_FILE))classes.dex; \
1734cp $(PRIVATE_DEX_FILE) $$_adtp_classes_dex && \
-b masterc3ccfee2013-01-23 16:54:32 -08001735zip -qj $@ $$_adtp_classes_dex && rm -f $$_adtp_classes_dex)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001736endef
1737
Ying Wang85480622012-08-09 15:20:50 -07001738# Add java resources added by the current module.
1739#
The Android Open Source Project88b60792009-03-03 19:28:42 -08001740define add-java-resources-to-package
Ying Wang194a8ec2011-06-06 14:34:52 -07001741$(call dump-words-to-file, $(PRIVATE_EXTRA_JAR_ARGS), $(dir $@)jar-arg-list)
1742$(hide) jar uf $@ @$(dir $@)jar-arg-list
1743@rm -f $(dir $@)jar-arg-list
The Android Open Source Project88b60792009-03-03 19:28:42 -08001744endef
1745
Ying Wang85480622012-08-09 15:20:50 -07001746# Add java resources carried by static Java libraries.
1747#
1748define add-carried-java-resources
1749$(hide) if [ -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) ] ; then \
1750 java_res_jar_flags=$$(find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -type f -a -not -name "*.class" \
1751 | sed -e "s?^$(PRIVATE_CLASS_INTERMEDIATES_DIR)/? -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) ?"); \
1752 if [ -n "$$java_res_jar_flags" ] ; then \
1753 echo $$java_res_jar_flags >$(dir $@)java_res_jar_flags; \
1754 jar uf $@ $$java_res_jar_flags; \
1755 fi; \
1756fi
1757endef
1758
The Android Open Source Project88b60792009-03-03 19:28:42 -08001759# Sign a package using the specified key/cert.
1760#
1761define sign-package
1762$(hide) mv $@ $@.unsigned
1763$(hide) java -jar $(SIGNAPK_JAR) \
Ying Wang31df0682012-11-13 10:55:28 -08001764 $(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) \
1765 $(PRIVATE_ADDITIONAL_CERTIFICATES) $@.unsigned $@.signed
The Android Open Source Project88b60792009-03-03 19:28:42 -08001766$(hide) mv $@.signed $@
1767endef
1768
1769# Align STORED entries of a package on 4-byte boundaries
1770# to make them easier to mmap.
1771#
1772define align-package
1773$(hide) mv $@ $@.unaligned
1774$(hide) $(ZIPALIGN) -f 4 $@.unaligned $@.aligned
1775$(hide) mv $@.aligned $@
1776endef
1777
1778define install-dex-debug
1779$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.dex" ]; then \
1780 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
1781 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.dex \
1782 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).dex; \
1783 fi
1784$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.lst" ]; then \
1785 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
1786 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.lst \
1787 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).lst; \
1788 fi
1789endef
1790
1791# TODO(joeo): If we can ever upgrade to post 3.81 make and get the
1792# new prebuilt rules to work, we should change this to copy the
1793# resources to the out directory and then copy the resources.
1794
Brian Carlstrom78269512010-12-10 12:10:24 -08001795# Note: we intentionally don't clean PRIVATE_CLASS_INTERMEDIATES_DIR
1796# in transform-java-to-classes for the sake of vm-tests.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001797define transform-host-java-to-package
1798@echo "host Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
Ying Wang015edd22011-01-20 15:01:56 -08001799$(call compile-java,$(HOST_JAVAC),$(PRIVATE_BOOTCLASSPATH))
Ying Wang194a8ec2011-06-06 14:34:52 -07001800$(if $(PRIVATE_EXTRA_JAR_ARGS), $(call add-java-resources-to-package))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001801endef
1802
1803###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001804## Commands for copying files
1805###########################################################
1806
1807# Define a rule to copy a header. Used via $(eval) by copy_headers.make.
1808# $(1): source header
1809# $(2): destination header
1810define copy-one-header
1811$(2): $(1)
1812 @echo "Header: $$@"
1813 $$(copy-file-to-new-target-with-cp)
1814endef
1815
1816# Define a rule to copy a file. For use via $(eval).
1817# $(1): source file
1818# $(2): destination file
1819define copy-one-file
1820$(2): $(1) | $(ACP)
1821 @echo "Copy: $$@"
1822 $$(copy-file-to-target)
1823endef
1824
Joe Onoratoe44705a2012-05-17 17:12:04 -07001825# Copies many files.
1826# $(1): The files to copy. Each entry is a ':' separated src:dst pair
1827# Evaluates to the list of the dst files (ie suitable for a dependency list)
1828define copy-many-files
1829$(foreach f, $(1), $(strip \
1830 $(eval _cmf_tuple := $(subst :, ,$(f))) \
1831 $(eval _cmf_src := $(word 1,$(_cmf_tuple))) \
1832 $(eval _cmf_dest := $(word 2,$(_cmf_tuple))) \
1833 $(eval $(call copy-one-file,$(_cmf_src),$(_cmf_dest))) \
1834 $(_cmf_dest)))
1835endef
1836
Ying Wang3ceecfa2012-05-14 14:39:00 -07001837# Copy the file only if it's a well-formed xml file. For use via $(eval).
1838# $(1): source file
1839# $(2): destination file, must end with .xml.
1840define copy-xml-file-checked
1841$(2): $(1) | $(ACP)
1842 @echo "Copy xml: $$@"
1843 $(hide) xmllint $$< >/dev/null # Don't print the xml file to stdout.
1844 $$(copy-file-to-target)
1845endef
1846
The Android Open Source Project88b60792009-03-03 19:28:42 -08001847# The -t option to acp and the -p option to cp is
1848# required for OSX. OSX has a ridiculous restriction
1849# where it's an error for a .a file's modification time
1850# to disagree with an internal timestamp, and this
1851# macro is used to install .a files (among other things).
1852
1853# Copy a single file from one place to another,
1854# preserving permissions and overwriting any existing
1855# file.
Ian Rogers76a6dc32012-10-01 16:36:23 -07001856# We disable the "-t" option for acp cannot handle
Ying Wang84ed6fa2011-01-18 17:21:20 -08001857# high resolution timestamp correctly on file systems like ext4.
1858# Therefore copy-file-to-target is the same as copy-file-to-new-target.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001859define copy-file-to-target
1860@mkdir -p $(dir $@)
Ying Wang84ed6fa2011-01-18 17:21:20 -08001861$(hide) $(ACP) -fp $< $@
The Android Open Source Project88b60792009-03-03 19:28:42 -08001862endef
1863
1864# The same as copy-file-to-target, but use the local
1865# cp command instead of acp.
1866define copy-file-to-target-with-cp
1867@mkdir -p $(dir $@)
1868$(hide) cp -fp $< $@
1869endef
1870
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07001871# The same as copy-file-to-target, but use the zipalign tool to do so.
1872define copy-file-to-target-with-zipalign
1873@mkdir -p $(dir $@)
1874$(hide) $(ZIPALIGN) -f 4 $< $@
1875endef
1876
Doug Zongker1046d202009-08-06 13:02:19 -07001877# The same as copy-file-to-target, but strip out "# comment"-style
1878# comments (for config files and such).
1879define copy-file-to-target-strip-comments
1880@mkdir -p $(dir $@)
1881$(hide) sed -e 's/#.*$$//' -e 's/[ \t]*$$//' -e '/^$$/d' < $< > $@
1882endef
1883
The Android Open Source Project88b60792009-03-03 19:28:42 -08001884# The same as copy-file-to-target, but don't preserve
1885# the old modification time.
1886define copy-file-to-new-target
1887@mkdir -p $(dir $@)
1888$(hide) $(ACP) -fp $< $@
1889endef
1890
1891# The same as copy-file-to-new-target, but use the local
1892# cp command instead of acp.
1893define copy-file-to-new-target-with-cp
1894@mkdir -p $(dir $@)
1895$(hide) cp -f $< $@
1896endef
1897
1898# Copy a prebuilt file to a target location.
1899define transform-prebuilt-to-target
1900@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"
1901$(copy-file-to-target)
1902endef
1903
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07001904# Copy a prebuilt file to a target location, using zipalign on it.
1905define transform-prebuilt-to-target-with-zipalign
1906@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt APK: $(PRIVATE_MODULE) ($@)"
1907$(copy-file-to-target-with-zipalign)
1908endef
1909
Doug Zongker1046d202009-08-06 13:02:19 -07001910# Copy a prebuilt file to a target location, stripping "# comment" comments.
1911define transform-prebuilt-to-target-strip-comments
1912@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"
1913$(copy-file-to-target-strip-comments)
1914endef
1915
The Android Open Source Project88b60792009-03-03 19:28:42 -08001916###########################################################
1917## On some platforms (MacOS), after copying a static
1918## library, ranlib must be run to update an internal
1919## timestamp!?!?!
1920###########################################################
1921
1922ifeq ($(HOST_RUN_RANLIB_AFTER_COPYING),true)
1923define transform-host-ranlib-copy-hack
1924 $(hide) ranlib $@ || true
1925endef
1926else
1927define transform-host-ranlib-copy-hack
Patrick Scott0e27dff2010-05-07 08:37:11 -04001928@true
The Android Open Source Project88b60792009-03-03 19:28:42 -08001929endef
1930endif
1931
1932ifeq ($(TARGET_RUN_RANLIB_AFTER_COPYING),true)
1933define transform-ranlib-copy-hack
1934 $(hide) ranlib $@
1935endef
1936else
1937define transform-ranlib-copy-hack
Patrick Scott0e27dff2010-05-07 08:37:11 -04001938@true
The Android Open Source Project88b60792009-03-03 19:28:42 -08001939endef
1940endif
1941
1942
1943###########################################################
Ying Wang3b2bdf12010-02-01 09:51:23 -08001944## Commands to call Proguard
1945###########################################################
Ying Wang3b2bdf12010-02-01 09:51:23 -08001946define transform-jar-to-proguard
Ying Wang7311a342013-08-21 18:32:49 -07001947@echo Proguard: $@
1948$(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS)
Ying Wang3b2bdf12010-02-01 09:51:23 -08001949endef
1950
Ying Wang3b2bdf12010-02-01 09:51:23 -08001951###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001952## Stuff source generated from one-off tools
1953###########################################################
1954
1955define transform-generated-source
1956@echo "target Generated: $(PRIVATE_MODULE) <= $<"
1957@mkdir -p $(dir $@)
1958$(hide) $(PRIVATE_CUSTOM_TOOL)
1959endef
1960
1961
1962###########################################################
1963## Assertions about attributes of the target
1964###########################################################
1965
1966# $(1): The file to check
1967ifndef get-file-size
1968$(error HOST_OS must define get-file-size)
1969endif
1970
Doug Zongker4647f122009-07-02 09:00:54 -07001971# Convert a partition data size (eg, as reported in /proc/mtd) to the
1972# size of the image used to flash that partition (which includes a
Lars Svensson9cb8c282010-12-06 15:24:58 +01001973# spare area for each page).
Doug Zongker4647f122009-07-02 09:00:54 -07001974# $(1): the partition data size
1975define image-size-from-data-size
Ying Wang4a2ecaf2011-02-09 17:24:27 -08001976$(strip $(eval _isfds_value := $$(shell echo $$$$(($(1) / $(BOARD_NAND_PAGE_SIZE) * \
1977 ($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE))))))\
1978$(if $(filter 0, $(_isfds_value)),$(shell echo $$(($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE)))),$(_isfds_value))\
1979$(eval _isfds_value :=))
Doug Zongker4647f122009-07-02 09:00:54 -07001980endef
1981
1982# $(1): The file(s) to check (often $@)
1983# $(2): The maximum total image size, in decimal bytes
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001984# $(3): the type of filesystem "yaffs" or "raw"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001985#
1986# If $(2) is empty, evaluates to "true"
1987#
1988# Reserve bad blocks. Make sure that MAX(1% of partition size, 2 blocks)
1989# is left over after the image has been flashed. Round the 1% up to the
1990# next whole flash block size.
1991define assert-max-file-size
1992$(if $(2), \
Doug Zongker742fa572009-07-08 12:09:04 -07001993 size=$$(for i in $(1); do $(call get-file-size,$$i); echo +; done; echo 0); \
1994 total=$$(( $$( echo "$$size" ) )); \
Doug Zongker4647f122009-07-02 09:00:54 -07001995 printname=$$(echo -n "$(1)" | tr " " +); \
Doug Zongker4647f122009-07-02 09:00:54 -07001996 img_blocksize=$(call image-size-from-data-size,$(BOARD_FLASH_BLOCK_SIZE)); \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001997 if [ "$(3)" == "yaffs" ]; then \
Doug Zongker93d9ff42009-09-14 17:46:41 -07001998 reservedblocks=8; \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001999 else \
Doug Zongker4ac1ba62009-08-25 20:38:50 -07002000 reservedblocks=0; \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07002001 fi; \
Doug Zongker4647f122009-07-02 09:00:54 -07002002 twoblocks=$$((img_blocksize * 2)); \
2003 onepct=$$((((($(2) / 100) - 1) / img_blocksize + 1) * img_blocksize)); \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07002004 reserve=$$(((twoblocks > onepct ? twoblocks : onepct) + \
2005 reservedblocks * img_blocksize)); \
Doug Zongker4647f122009-07-02 09:00:54 -07002006 maxsize=$$(($(2) - reserve)); \
Ying Wang99bcbeb2011-12-02 10:34:45 -08002007 echo "$$printname maxsize=$$maxsize blocksize=$$img_blocksize total=$$total reserve=$$reserve"; \
Doug Zongker4647f122009-07-02 09:00:54 -07002008 if [ "$$total" -gt "$$maxsize" ]; then \
2009 echo "error: $$printname too large ($$total > [$(2) - $$reserve])"; \
2010 false; \
Doug Zongker742fa572009-07-08 12:09:04 -07002011 elif [ "$$total" -gt $$((maxsize - 32768)) ]; then \
Doug Zongker4647f122009-07-02 09:00:54 -07002012 echo "WARNING: $$printname approaching size limit ($$total now; limit $$maxsize)"; \
The Android Open Source Project88b60792009-03-03 19:28:42 -08002013 fi \
2014 , \
2015 true \
2016 )
2017endef
2018
Doug Zongker8510a1e2009-08-07 16:38:08 -07002019# Like assert-max-file-size, but the second argument is a partition
2020# size, which we'll convert to a max image size before checking it
2021# against the files.
2022#
2023# $(1): The file(s) to check (often $@)
2024# $(2): The partition size.
2025define assert-max-image-size
2026$(if $(2), \
2027 $(call assert-max-file-size,$(1),$(call image-size-from-data-size,$(2))), \
2028 true)
2029endef
2030
Doug Zongkere01100c2009-06-19 17:12:18 -07002031
2032###########################################################
2033## Define device-specific radio files
2034###########################################################
Ying Wang94de1eb2013-07-26 12:19:20 -07002035INSTALLED_RADIOIMAGE_TARGET :=
Doug Zongkere01100c2009-06-19 17:12:18 -07002036
2037# Copy a radio image file to the output location, and add it to
2038# INSTALLED_RADIOIMAGE_TARGET.
2039# $(1): filename
2040define add-radio-file
Doug Zongker14833602010-02-02 13:12:04 -08002041 $(eval $(call add-radio-file-internal,$(1),$(notdir $(1))))
Doug Zongkere01100c2009-06-19 17:12:18 -07002042endef
2043define add-radio-file-internal
Doug Zongker14833602010-02-02 13:12:04 -08002044INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
Doug Zongker14833602010-02-02 13:12:04 -08002045$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP)
Doug Zongkere01100c2009-06-19 17:12:18 -07002046 $$(transform-prebuilt-to-target)
2047endef
2048
Doug Zongker9296f092012-03-20 16:42:22 -07002049# Version of add-radio-file that also arranges for the version of the
2050# file to be checked against the contents of
2051# $(TARGET_BOARD_INFO_FILE).
2052# $(1): filename
2053# $(2): name of version variable in board-info (eg, "version-baseband")
2054define add-radio-file-checked
2055 $(eval $(call add-radio-file-checked-internal,$(1),$(notdir $(1)),$(2)))
2056endef
2057define add-radio-file-checked-internal
2058INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
2059BOARD_INFO_CHECK += $(3):$(LOCAL_PATH)/$(1)
2060$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP)
2061 $$(transform-prebuilt-to-target)
2062endef
2063
Doug Zongkere01100c2009-06-19 17:12:18 -07002064
The Android Open Source Project88b60792009-03-03 19:28:42 -08002065###########################################################
Joe Onorato899e62a2010-02-04 17:37:21 -08002066# Override the package defined in $(1), setting the
2067# variables listed below differently.
2068#
2069# $(1): The makefile to override (relative to the source
2070# tree root)
2071# $(2): Old LOCAL_PACKAGE_NAME value.
2072# $(3): New LOCAL_PACKAGE_NAME value.
Ying Wang3dae0ee2010-09-02 15:41:01 -07002073# $(4): New LOCAL_MANIFEST_PACKAGE_NAME value.
2074# $(5): New LOCAL_CERTIFICATE value.
2075# $(6): New LOCAL_INSTRUMENTATION_FOR value.
2076# $(7): New LOCAL_MANIFEST_INSTRUMENTATION_FOR value.
Joe Onorato899e62a2010-02-04 17:37:21 -08002077#
2078# Note that LOCAL_PACKAGE_OVERRIDES is NOT cleared in
2079# clear_vars.mk.
2080###########################################################
2081define inherit-package
Ying Wang3dae0ee2010-09-02 15:41:01 -07002082 $(eval $(call inherit-package-internal,$(1),$(2),$(3),$(4),$(5),$(6),$(7)))
Joe Onorato899e62a2010-02-04 17:37:21 -08002083endef
2084
2085define inherit-package-internal
2086 LOCAL_PACKAGE_OVERRIDES \
Ying Wang3dae0ee2010-09-02 15:41:01 -07002087 := $(strip $(1))||$(strip $(2))||$(strip $(3))||$(strip $(4))||&&$(strip $(5))||&&$(strip $(6))||&&$(strip $(7)) $(LOCAL_PACKAGE_OVERRIDES)
Joe Onorato899e62a2010-02-04 17:37:21 -08002088 include $(1)
2089 LOCAL_PACKAGE_OVERRIDES \
2090 := $(wordlist 1,$(words $(LOCAL_PACKAGE_OVERRIDES)), $(LOCAL_PACKAGE_OVERRIDES))
2091endef
2092
2093# To be used with inherit-package above
2094# Evalutes to true if the package was overridden
2095define set-inherited-package-variables
2096$(strip $(call set-inherited-package-variables-internal))
2097endef
2098
2099define keep-or-override
2100$(eval $(1) := $(if $(2),$(2),$($(1))))
2101endef
2102
2103define set-inherited-package-variables-internal
2104 $(eval _o := $(subst ||, ,$(lastword $(LOCAL_PACKAGE_OVERRIDES))))
2105 $(eval _n := $(subst ||, ,$(firstword $(LOCAL_PACKAGE_OVERRIDES))))
2106 $(if $(filter $(word 2,$(_n)),$(LOCAL_PACKAGE_NAME)), \
2107 $(eval LOCAL_PACKAGE_NAME := $(word 3,$(_o))) \
2108 $(eval LOCAL_MANIFEST_PACKAGE_NAME := $(word 4,$(_o))) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07002109 $(call keep-or-override,LOCAL_CERTIFICATE,$(patsubst &&%,%,$(word 5,$(_o)))) \
2110 $(call keep-or-override,LOCAL_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 6,$(_o)))) \
2111 $(call keep-or-override,LOCAL_MANIFEST_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 7,$(_o)))) \
Joe Onorato899e62a2010-02-04 17:37:21 -08002112 $(eval LOCAL_OVERRIDES_PACKAGES := $(sort $(LOCAL_OVERRIDES_PACKAGES) $(word 2,$(_o)))) \
2113 true \
2114 ,)
2115endef
2116
Ying Wang000e89a2012-04-30 15:48:27 -07002117###########################################################
2118## Expand a module name list with REQUIRED modules
2119###########################################################
2120# $(1): The variable name that holds the initial module name list.
2121# the variable will be modified to hold the expanded results.
2122# $(2): The initial module name list.
2123# Returns empty string (maybe with some whitespaces).
2124define expand-required-modules
2125$(eval _erm_new_modules := $(sort $(filter-out $($(1)),\
2126 $(foreach m,$(2),$(ALL_MODULES.$(m).REQUIRED)))))\
2127$(if $(_erm_new_modules),$(eval $(1) += $(_erm_new_modules))\
2128 $(call expand-required-modules,$(1),$(_erm_new_modules)))
2129endef
Joe Onorato899e62a2010-02-04 17:37:21 -08002130
2131###########################################################
Ying Wangc065da22012-11-14 15:57:07 -08002132## API Check
2133###########################################################
2134
2135# eval this to define a rule that runs apicheck.
2136#
2137# Args:
2138# $(1) target
2139# $(2) stable api file
2140# $(3) api file to be tested
2141# $(4) arguments for apicheck
2142# $(5) command to run if apicheck failed
2143# $(6) target dependent on this api check
2144# $(7) additional dependencies
2145define check-api
2146$(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(strip $(1))-timestamp: $(2) $(3) $(APICHECK) $(7)
2147 @echo "Checking API:" $(1)
2148 $(hide) ( $(APICHECK_COMMAND) $(4) $(2) $(3) || ( $(5) ; exit 38 ) )
2149 $(hide) mkdir -p $$(dir $$@)
2150 $(hide) touch $$@
2151$(6): $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(strip $(1))-timestamp
2152endef
2153
Ying Wang63d94fa2012-12-13 18:23:01 -08002154## Whether to build from source if prebuilt alternative exists
2155###########################################################
2156# $(1): module name
2157# $(2): LOCAL_PATH
2158# Expands to empty string if not from source.
2159ifeq (true,$(ANDROID_BUILD_FROM_SOURCE))
2160define if-build-from-source
2161true
2162endef
2163else
2164define if-build-from-source
2165$(if $(filter $(ANDROID_NO_PREBUILT_MODULES),$(1))$(filter \
2166 $(addsuffix %,$(ANDROID_NO_PREBUILT_PATHS)),$(2)),true)
2167endef
2168endif
2169
2170# Include makefile $(1) if build from source for module $(2)
2171# $(1): the makefile to include
2172# $(2): module name
2173# $(3): LOCAL_PATH
2174define include-if-build-from-source
2175$(if $(call if-build-from-source,$(2),$(3)),$(eval include $(1)))
2176endef
2177
Ying Wangc065da22012-11-14 15:57:07 -08002178###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08002179## Other includes
2180###########################################################
2181
2182# -----------------------------------------------------------------
2183# Rules and functions to help copy important files to DIST_DIR
2184# when requested.
2185include $(BUILD_SYSTEM)/distdir.mk
2186
Marie Lennerhagen9e5efce2010-10-20 13:41:59 +02002187# Include any vendor specific definitions.mk file
2188-include $(TOPDIR)vendor/*/build/core/definitions.mk
2189
The Android Open Source Project88b60792009-03-03 19:28:42 -08002190# broken:
2191# $(foreach file,$^,$(if $(findstring,.a,$(suffix $file)),-l$(file),$(file)))
2192
2193###########################################################
2194## Misc notes
2195###########################################################
2196
2197#DEPDIR = .deps
2198#df = $(DEPDIR)/$(*F)
2199
2200#SRCS = foo.c bar.c ...
2201
2202#%.o : %.c
2203# @$(MAKEDEPEND); \
2204# cp $(df).d $(df).P; \
2205# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
2206# -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \
2207# rm -f $(df).d
2208# $(COMPILE.c) -o $@ $<
2209
2210#-include $(SRCS:%.c=$(DEPDIR)/%.P)
2211
2212
2213#%.o : %.c
2214# $(COMPILE.c) -MD -o $@ $<
2215# @cp $*.d $*.P; \
2216# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
2217# -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \
2218# rm -f $*.d