blob: e0e960841e9c76e5b7147de0ae611f0d1ee32145 [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)) \
Ying Wang6ef65192014-01-15 16:02:16 -0800453 $(eval _idf2ndArchPrefix := $(if $(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)) \
456 , \
Ying Wang6ef65192014-01-15 16:02:16 -0800457 $(eval _idfIntBase := $($(_idf2ndArchPrefix)$(_idfPrefix)_OUT_INTERMEDIATES)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800458 ) \
459 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
460)
461endef
462
463# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE
464# to determine the intermediates directory.
465#
466# $(1): if non-empty, force the intermediates to be COMMON
Ying Wang6ef65192014-01-15 16:02:16 -0800467# $(2): if non-empty, force the intermediates to be for the 2nd arch
The Android Open Source Project88b60792009-03-03 19:28:42 -0800468define local-intermediates-dir
469$(strip \
470 $(if $(strip $(LOCAL_MODULE_CLASS)),, \
471 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-intermediates-dir)) \
472 $(if $(strip $(LOCAL_MODULE)),, \
473 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-intermediates-dir)) \
Ying Wang6ef65192014-01-15 16:02:16 -0800474 $(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 -0800475)
476endef
477
478###########################################################
Colin Crossd8262642014-01-24 23:17:21 -0800479## The generated sources directory. Placing generated
480## source files directly in the intermediates directory
481## causes problems for multiarch builds, where there are
482## two intermediates directories for a single target. Put
483## them in a separate directory, and they will be copied to
484## each intermediates directory automatically.
485###########################################################
486
487# $(1): target class, like "APPS"
488# $(2): target name, like "NotePad"
489# $(3): if non-empty, this is a HOST target.
490# $(4): if non-empty, force the generated sources to be COMMON
491define generated-sources-dir-for
492$(strip \
493 $(eval _idfClass := $(strip $(1))) \
494 $(if $(_idfClass),, \
495 $(error $(LOCAL_PATH): Class not defined in call to generated-sources-dir-for)) \
496 $(eval _idfName := $(strip $(2))) \
497 $(if $(_idfName),, \
498 $(error $(LOCAL_PATH): Name not defined in call to generated-sources-dir-for)) \
499 $(eval _idfPrefix := $(if $(strip $(3)),HOST,TARGET)) \
500 $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
501 $(eval _idfIntBase := $($(_idfPrefix)_OUT_GEN_COMMON)) \
502 , \
503 $(eval _idfIntBase := $($(_idfPrefix)_OUT_GEN)) \
504 ) \
505 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
506)
507endef
508
509# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE
510# to determine the generated sources directory.
511#
512# $(1): if non-empty, force the intermediates to be COMMON
513define local-generated-sources-dir
514$(strip \
515 $(if $(strip $(LOCAL_MODULE_CLASS)),, \
516 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-generated-sources-dir)) \
517 $(if $(strip $(LOCAL_MODULE)),, \
518 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-generated-sources-dir)) \
519 $(call generated-sources-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(LOCAL_IS_HOST_MODULE),$(1)) \
520)
521endef
522
523###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800524## Convert "path/to/libXXX.so" to "-lXXX".
525## Any "path/to/libXXX.a" elements pass through unchanged.
526###########################################################
527
528define normalize-libraries
529$(foreach so,$(filter %.so,$(1)),-l$(patsubst lib%.so,%,$(notdir $(so))))\
530$(filter-out %.so,$(1))
531endef
532
533# TODO: change users to call the common version.
534define normalize-host-libraries
535$(call normalize-libraries,$(1))
536endef
537
538define normalize-target-libraries
539$(call normalize-libraries,$(1))
540endef
541
542###########################################################
543## Convert a list of short module names (e.g., "framework", "Browser")
544## into the list of files that are built for those modules.
545## NOTE: this won't return reliable results until after all
546## sub-makefiles have been included.
547## $(1): target list
548###########################################################
549
550define module-built-files
551$(foreach module,$(1),$(ALL_MODULES.$(module).BUILT))
552endef
553
554###########################################################
555## Convert a list of short modules names (e.g., "framework", "Browser")
556## into the list of files that are installed for those modules.
557## NOTE: this won't return reliable results until after all
558## sub-makefiles have been included.
559## $(1): target list
560###########################################################
561
562define module-installed-files
563$(foreach module,$(1),$(ALL_MODULES.$(module).INSTALLED))
564endef
565
566###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700567## Convert a list of short modules names (e.g., "framework", "Browser")
568## into the list of files that should be used when linking
569## against that module as a public API.
570## TODO: Allow this for more than JAVA_LIBRARIES modules
571## NOTE: this won't return reliable results until after all
572## sub-makefiles have been included.
573## $(1): target list
574###########################################################
575
576define module-stubs-files
577$(foreach module,$(1),$(ALL_MODULES.$(module).STUBS))
578endef
579
580###########################################################
581## Evaluates to the timestamp file for a doc module, which
582## is the dependency that should be used.
583## $(1): doc module
584###########################################################
585
586define doc-timestamp-for
587$(OUT_DOCS)/$(strip $(1))-timestamp
588endef
589
590
591###########################################################
Ying Wang912f8282010-09-28 17:27:56 -0700592## Convert "core ext framework" to "out/.../javalib.jar ..."
The Android Open Source Project88b60792009-03-03 19:28:42 -0800593## $(1): library list
594## $(2): Non-empty if IS_HOST_MODULE
595###########################################################
596
597# $(1): library name
598# $(2): Non-empty if IS_HOST_MODULE
599define _java-lib-dir
600$(call intermediates-dir-for, \
Ying Wang912f8282010-09-28 17:27:56 -0700601 JAVA_LIBRARIES,$(1),$(2),COMMON)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800602endef
603
604# $(1): library name
605# $(2): Non-empty if IS_HOST_MODULE
606define _java-lib-full-classes.jar
Ying Wang912f8282010-09-28 17:27:56 -0700607$(call _java-lib-dir,$(1),$(2))/classes$(COMMON_JAVA_PACKAGE_SUFFIX)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800608endef
609
610# $(1): library name list
611# $(2): Non-empty if IS_HOST_MODULE
612define java-lib-files
613$(foreach lib,$(1),$(call _java-lib-full-classes.jar,$(lib),$(2)))
614endef
615
616# $(1): library name
The Android Open Source Project88b60792009-03-03 19:28:42 -0800617# $(2): Non-empty if IS_HOST_MODULE
618define _java-lib-full-dep
Ying Wang45150f82013-02-27 15:23:42 -0800619$(call _java-lib-dir,$(1),$(2))/$(if $(2),javalib,classes)$(COMMON_JAVA_PACKAGE_SUFFIX)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800620endef
621
622# $(1): library name list
623# $(2): Non-empty if IS_HOST_MODULE
624define java-lib-deps
625$(foreach lib,$(1),$(call _java-lib-full-dep,$(lib),$(2)))
626endef
627
628###########################################################
Joe Onorato8dc8faa2010-09-14 13:09:48 -0400629## Run rot13 on a string
630## $(1): the string. Must be one line.
631###########################################################
632define rot13
633$(shell echo $(1) | tr 'a-zA-Z' 'n-za-mN-ZA-M')
634endef
635
636
637###########################################################
638## Returns true if $(1) and $(2) are equal. Returns
639## the empty string if they are not equal.
640###########################################################
641define streq
642$(strip $(if $(strip $(1)),\
643 $(if $(strip $(2)),\
644 $(if $(filter-out __,_$(subst $(strip $(1)),,$(strip $(2)))$(subst $(strip $(2)),,$(strip $(1)))_),,true), \
645 ),\
646 $(if $(strip $(2)),\
647 ,\
648 true)\
649 ))
650endef
651
652###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800653## Convert "a b c" into "a:b:c"
654###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800655define normalize-path-list
656$(subst $(space),:,$(strip $(1)))
657endef
658
659###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700660## Read the word out of a colon-separated list of words.
661## This has the same behavior as the built-in function
662## $(word n,str).
663##
664## The individual words may not contain spaces.
665##
666## $(1): 1 based index
667## $(2): value of the form a:b:c...
668###########################################################
669
670define word-colon
671$(word $(1),$(subst :,$(space),$(2)))
672endef
673
674###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800675## Convert "a=b c= d e = f" into "a=b c=d e=f"
676##
677## $(1): list to collapse
678## $(2): if set, separator word; usually "=", ":", or ":="
679## Defaults to "=" if not set.
680###########################################################
681
682define collapse-pairs
683$(eval _cpSEP := $(strip $(if $(2),$(2),=)))\
684$(subst $(space)$(_cpSEP)$(space),$(_cpSEP),$(strip \
685 $(subst $(_cpSEP), $(_cpSEP) ,$(1))))
686endef
687
The Android Open Source Project88b60792009-03-03 19:28:42 -0800688###########################################################
Ying Wang7e8d4422011-06-17 17:05:35 -0700689## Given a list of pairs, if multiple pairs have the same
690## first components, keep only the first pair.
691##
692## $(1): list of pairs
693## $(2): the separator word, such as ":", "=", etc.
694define uniq-pairs-by-first-component
695$(eval _upbfc_fc_set :=)\
696$(strip $(foreach w,$(1), $(eval _first := $(word 1,$(subst $(2),$(space),$(w))))\
697 $(if $(filter $(_upbfc_fc_set),$(_first)),,$(w)\
698 $(eval _upbfc_fc_set += $(_first)))))\
699$(eval _upbfc_fc_set :=)\
700$(eval _first:=)
701endef
702
703###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800704## MODULE_TAG set operations
705###########################################################
706
707# Given a list of tags, return the targets that specify
708# any of those tags.
709# $(1): tag list
710define modules-for-tag-list
711$(sort $(foreach tag,$(1),$(ALL_MODULE_TAGS.$(tag))))
712endef
713
714# Same as modules-for-tag-list, but operates on
715# ALL_MODULE_NAME_TAGS.
716# $(1): tag list
717define module-names-for-tag-list
718$(sort $(foreach tag,$(1),$(ALL_MODULE_NAME_TAGS.$(tag))))
719endef
720
721# Given an accept and reject list, find the matching
722# set of targets. If a target has multiple tags and
723# any of them are rejected, the target is rejected.
724# Reject overrides accept.
725# $(1): list of tags to accept
726# $(2): list of tags to reject
727#TODO(dbort): do $(if $(strip $(1)),$(1),$(ALL_MODULE_TAGS))
Jean-Baptiste Queru75127b72010-01-07 11:44:22 -0800728#TODO(jbq): as of 20100106 nobody uses the second parameter
The Android Open Source Project88b60792009-03-03 19:28:42 -0800729define get-tagged-modules
730$(filter-out \
731 $(call modules-for-tag-list,$(2)), \
732 $(call modules-for-tag-list,$(1)))
733endef
734
Joe Onorato64d85d02009-04-09 19:31:12 -0700735###########################################################
736## Append a leaf to a base path. Properly deals with
737## base paths ending in /.
738##
739## $(1): base path
740## $(2): leaf path
741###########################################################
742
743define append-path
744$(subst //,/,$(1)/$(2))
745endef
746
The Android Open Source Project88b60792009-03-03 19:28:42 -0800747
748###########################################################
749## Package filtering
750###########################################################
751
752# Given a list of installed modules (short or long names)
753# return a list of the packages (yes, .apk packages, not
754# modules in general) that are overridden by this list and,
755# therefore, should not be installed.
756# $(1): mixed list of installed modules
757# TODO: This is fragile; find a reliable way to get this information.
758define _get-package-overrides
759 $(eval ### Discard any words containing slashes, unless they end in .apk, \
760 ### in which case trim off the directory component and the suffix. \
761 ### If there are no slashes, keep the entire word.)
762 $(eval _gpo_names := $(subst /,@@@ @@@,$(1)))
763 $(eval _gpo_names := \
764 $(filter %.apk,$(_gpo_names)) \
765 $(filter-out %@@@ @@@%,$(_gpo_names)))
766 $(eval _gpo_names := $(patsubst %.apk,%,$(_gpo_names)))
767 $(eval _gpo_names := $(patsubst @@@%,%,$(_gpo_names)))
768
769 $(eval ### Remove any remaining words that contain dots.)
770 $(eval _gpo_names := $(subst .,@@@ @@@,$(_gpo_names)))
771 $(eval _gpo_names := $(filter-out %@@@ @@@%,$(_gpo_names)))
772
773 $(eval ### Now we have a list of any words that could possibly refer to \
774 ### packages, although there may be words that do not. Only \
775 ### real packages will be present under PACKAGES.*, though.)
776 $(foreach _gpo_name,$(_gpo_names),$(PACKAGES.$(_gpo_name).OVERRIDES))
777endef
778
779define get-package-overrides
Conley Owensd7a1a9b2011-12-22 09:46:19 -0800780$(sort $(strip $(call _get-package-overrides,$(1))))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800781endef
782
783###########################################################
784## Output the command lines, or not
785###########################################################
786
787ifeq ($(strip $(SHOW_COMMANDS)),)
788define pretty
789@echo $1
790endef
791hide := @
792else
793define pretty
794endef
795hide :=
796endif
797
798###########################################################
799## Dump the variables that are associated with targets
800###########################################################
801
802define dump-module-variables
803@echo all_dependencies=$^
804@echo PRIVATE_YACCFLAGS=$(PRIVATE_YACCFLAGS);
805@echo PRIVATE_CFLAGS=$(PRIVATE_CFLAGS);
806@echo PRIVATE_CPPFLAGS=$(PRIVATE_CPPFLAGS);
807@echo PRIVATE_DEBUG_CFLAGS=$(PRIVATE_DEBUG_CFLAGS);
808@echo PRIVATE_C_INCLUDES=$(PRIVATE_C_INCLUDES);
809@echo PRIVATE_LDFLAGS=$(PRIVATE_LDFLAGS);
810@echo PRIVATE_LDLIBS=$(PRIVATE_LDLIBS);
811@echo PRIVATE_ARFLAGS=$(PRIVATE_ARFLAGS);
812@echo PRIVATE_AAPT_FLAGS=$(PRIVATE_AAPT_FLAGS);
813@echo PRIVATE_DX_FLAGS=$(PRIVATE_DX_FLAGS);
Brian Carlstromf184a0f2010-02-01 11:13:32 -0800814@echo PRIVATE_JAVACFLAGS=$(PRIVATE_JAVACFLAGS);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800815@echo PRIVATE_JAVA_LIBRARIES=$(PRIVATE_JAVA_LIBRARIES);
816@echo PRIVATE_ALL_SHARED_LIBRARIES=$(PRIVATE_ALL_SHARED_LIBRARIES);
817@echo PRIVATE_ALL_STATIC_LIBRARIES=$(PRIVATE_ALL_STATIC_LIBRARIES);
818@echo PRIVATE_ALL_WHOLE_STATIC_LIBRARIES=$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES);
819@echo PRIVATE_ALL_OBJECTS=$(PRIVATE_ALL_OBJECTS);
Jeff Brown703e7c62011-02-04 20:15:00 -0800820@echo PRIVATE_NO_CRT=$(PRIVATE_NO_CRT);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800821endef
822
823###########################################################
824## Commands for using sed to replace given variable values
825###########################################################
826
827define transform-variables
828@mkdir -p $(dir $@)
829@echo "Sed: $(if $(PRIVATE_MODULE),$(PRIVATE_MODULE),$@) <= $<"
830$(hide) sed $(foreach var,$(REPLACE_VARS),-e "s/{{$(var)}}/$(subst /,\/,$(PWD)/$($(var)))/g") $< >$@
831$(hide) if [ "$(suffix $@)" = ".sh" ]; then chmod a+rx $@; fi
832endef
833
834
835###########################################################
836## Commands for munging the dependency files GCC generates
837###########################################################
Ying Wangc23f4ef2012-09-07 17:04:06 -0700838# $(1): the input .d file
839# $(2): the output .P file
840define transform-d-to-p-args
841$(hide) cp $(1) $(2); \
842 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
843 -e '/^$$/ d' -e 's/$$/ :/' < $(1) >> $(2); \
844 rm -f $(1)
845endef
The Android Open Source Project88b60792009-03-03 19:28:42 -0800846
847define transform-d-to-p
Ying Wangc23f4ef2012-09-07 17:04:06 -0700848$(call transform-d-to-p-args,$(@:%.o=%.d),$(@:%.o=%.P))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800849endef
850
851###########################################################
852## Commands for running lex
853###########################################################
854
855define transform-l-to-cpp
856@mkdir -p $(dir $@)
857@echo "Lex: $(PRIVATE_MODULE) <= $<"
858$(hide) $(LEX) -o$@ $<
859endef
860
861###########################################################
862## Commands for running yacc
863##
864## Because the extension of c++ files can change, the
865## extension must be specified in $1.
866## E.g, "$(call transform-y-to-cpp,.cpp)"
867###########################################################
868
869define transform-y-to-cpp
870@mkdir -p $(dir $@)
871@echo "Yacc: $(PRIVATE_MODULE) <= $<"
872$(YACC) $(PRIVATE_YACCFLAGS) -o $@ $<
873touch $(@:$1=$(YACC_HEADER_SUFFIX))
874echo '#ifndef '$(@F:$1=_h) > $(@:$1=.h)
875echo '#define '$(@F:$1=_h) >> $(@:$1=.h)
876cat $(@:$1=$(YACC_HEADER_SUFFIX)) >> $(@:$1=.h)
877echo '#endif' >> $(@:$1=.h)
878rm -f $(@:$1=$(YACC_HEADER_SUFFIX))
879endef
880
Ying Wang0bd59a02010-07-15 17:17:52 -0700881###########################################################
Tim Murraya7aa8002012-10-29 16:06:00 -0700882## Commands to compile RenderScript to Java
Ying Wang0bd59a02010-07-15 17:17:52 -0700883###########################################################
Ying Wang0bd59a02010-07-15 17:17:52 -0700884
885define transform-renderscripts-to-java-and-bc
886@echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)"
887$(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR)
888$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/res/raw
889$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/src
Ying Wang7d83ef82011-05-25 17:16:22 -0700890$(hide) $(PRIVATE_RS_CC) \
Ying Wangebfddaa2010-07-30 18:37:29 -0700891 -o $(PRIVATE_RS_OUTPUT_DIR)/res/raw \
892 -p $(PRIVATE_RS_OUTPUT_DIR)/src \
Ying Wang24e1c012010-10-07 18:57:57 -0700893 -d $(PRIVATE_RS_OUTPUT_DIR) \
894 -a $@ -MD \
Stephen Hinesc963eae2011-08-10 13:53:05 -0700895 $(addprefix -target-api , $(PRIVATE_RS_TARGET_API)) \
Stephen Hines914f7a22011-12-06 18:43:24 -0800896 $(PRIVATE_RS_FLAGS) \
Ying Wang51280272010-09-01 13:28:52 -0700897 $(foreach inc,$(PRIVATE_RS_INCLUDES),$(addprefix -I , $(inc))) \
Ying Wangebfddaa2010-07-30 18:37:29 -0700898 $(PRIVATE_RS_SOURCE_FILES)
Ying Wang0bd59a02010-07-15 17:17:52 -0700899$(hide) mkdir -p $(dir $@)
900$(hide) touch $@
901endef
902
Stephen Hinese719f282012-11-28 16:52:41 -0800903define transform-bc-to-so
Stephen Hines9ac9b532013-02-27 00:51:08 -0800904@echo "Renderscript compatibility: $(notdir $@) <= $(notdir $<)"
Stephen Hinese719f282012-11-28 16:52:41 -0800905$(hide) mkdir -p $(dir $@)
Stephen Hinesf6925132012-12-17 14:23:14 -0800906$(hide) $(BCC_COMPAT) -O3 -o $(dir $@)/$(notdir $(<:.bc=.o)) -fPIC -shared \
Tim Murray1a6f09a2013-03-05 11:07:15 -0800907 -rt-path $(RS_PREBUILT_CLCORE) -mtriple $(RS_TRIPLE) $<
Stephen Hines7d6ec712012-12-13 19:24:50 -0800908$(hide) $(PRIVATE_CXX) -shared -Wl,-soname,$(notdir $@) -nostdlib \
Stephen Hinesf6925132012-12-17 14:23:14 -0800909 -Wl,-rpath,\$$ORIGIN/../lib \
Stephen Hines9541f582013-01-18 16:27:23 -0800910 $(dir $@)/$(notdir $(<:.bc=.o)) \
Tim Murray1a6f09a2013-03-05 11:07:15 -0800911 $(RS_PREBUILT_COMPILER_RT) \
Stephen Hines9541f582013-01-18 16:27:23 -0800912 -o $@ -L prebuilts/gcc/ \
Tim Murray1a6f09a2013-03-05 11:07:15 -0800913 -L $(TARGET_OUT_INTERMEDIATE_LIBRARIES) $(RS_PREBUILT_LIBPATH) \
Stephen Hines8db4cce2013-03-27 16:51:38 -0700914 -lRSSupport -lm -lc
Stephen Hinese719f282012-11-28 16:52:41 -0800915endef
916
Tim Murraya7aa8002012-10-29 16:06:00 -0700917###########################################################
918## Commands to compile RenderScript to C++
919###########################################################
920
921define transform-renderscripts-to-cpp-and-bc
922@echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)"
923$(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR)
924$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/
925$(hide) $(PRIVATE_RS_CC) \
926 -o $(PRIVATE_RS_OUTPUT_DIR)/ \
927 -d $(PRIVATE_RS_OUTPUT_DIR) \
928 -a $@ -MD \
929 -reflect-c++ \
930 $(PRIVATE_RS_FLAGS) \
931 $(foreach inc,$(PRIVATE_RS_INCLUDES),$(addprefix -I , $(inc))) \
932 $(PRIVATE_RS_SOURCE_FILES)
933$(hide) mkdir -p $(dir $@)
934$(hide) touch $@
935endef
936
The Android Open Source Project88b60792009-03-03 19:28:42 -0800937
938###########################################################
939## Commands for running aidl
940###########################################################
941
942define transform-aidl-to-java
943@mkdir -p $(dir $@)
944@echo "Aidl: $(PRIVATE_MODULE) <= $<"
945$(hide) $(AIDL) -d$(patsubst %.java,%.P,$@) $(PRIVATE_AIDL_FLAGS) $< $@
946endef
947#$(AIDL) $(PRIVATE_AIDL_FLAGS) $< - | indent -nut -br -npcs -l1000 > $@
948
949
Doug Zongker9bd49622009-11-30 14:28:59 -0800950###########################################################
951## Commands for running java-event-log-tags.py
952###########################################################
953
954define transform-logtags-to-java
955@mkdir -p $(dir $@)
956@echo "logtags: $@ <= $<"
Doug Zongkerabfbbe22010-02-16 14:32:08 -0800957$(hide) $(JAVATAGS) -o $@ $^
Doug Zongker9bd49622009-11-30 14:28:59 -0800958endef
959
The Android Open Source Project88b60792009-03-03 19:28:42 -0800960
961###########################################################
Ying Wanga5fc87a2010-11-02 18:43:16 -0700962## Commands for running protoc to compile .proto into .java
963###########################################################
964
965define transform-proto-to-java
966@mkdir -p $(dir $@)
967@echo "Protoc: $@ <= $(PRIVATE_PROTO_SRC_FILES)"
968@rm -rf $(PRIVATE_PROTO_JAVA_OUTPUT_DIR)
969@mkdir -p $(PRIVATE_PROTO_JAVA_OUTPUT_DIR)
Ben Murdochfc2bad52013-07-25 11:44:53 +0100970$(hide) for f in $(PRIVATE_PROTO_SRC_FILES); do \
971 $(PROTOC) \
Ulas Kirazci28b46fc2013-07-24 14:32:14 -0700972 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
Ulas Kirazci6e485b52013-07-25 12:28:19 -0700973 $(PRIVATE_PROTO_JAVA_OUTPUT_OPTION)="$(PRIVATE_PROTO_JAVA_OUTPUT_PARAMS):$(PRIVATE_PROTO_JAVA_OUTPUT_DIR)" \
Ben Murdochfc2bad52013-07-25 11:44:53 +0100974 $(PRIVATE_PROTOC_FLAGS) \
975 $$f || exit 33; \
976 done
Ying Wanga5fc87a2010-11-02 18:43:16 -0700977$(hide) touch $@
978endef
979
980######################################################################
981## Commands for running protoc to compile .proto into .pb.cc and .pb.h
982######################################################################
983define transform-proto-to-cc
984@mkdir -p $(dir $@)
985@echo "Protoc: $@ <= $<"
986$(hide) $(PROTOC) \
987 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
Ying Wang33c0d952010-11-05 11:30:58 -0700988 $(PRIVATE_PROTOC_FLAGS) \
Ying Wanga5fc87a2010-11-02 18:43:16 -0700989 --cpp_out=$(PRIVATE_PROTO_CC_OUTPUT_DIR) $<
990endef
991
992
993###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800994## Commands for running gcc to compile a C++ file
995###########################################################
996
997define transform-cpp-to-o
998@mkdir -p $(dir $@)
999@echo "target $(PRIVATE_ARM_MODE) C++: $(PRIVATE_MODULE) <= $<"
1000$(hide) $(PRIVATE_CXX) \
Ying Wangddbcad82011-04-18 11:45:44 -07001001 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Andrew Boie85f3b212012-07-11 12:14:56 -07001002 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
Ying Wang4761e562011-04-12 11:06:35 -07001003 $(addprefix -isystem ,\
1004 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1005 $(filter-out $(PRIVATE_C_INCLUDES), \
Ying Wangddbcad82011-04-18 11:45:44 -07001006 $(PRIVATE_TARGET_PROJECT_INCLUDES) \
Ying Wang4761e562011-04-12 11:06:35 -07001007 $(PRIVATE_TARGET_C_INCLUDES)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001008 -c \
1009 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -07001010 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
1011 $(PRIVATE_TARGET_GLOBAL_CPPFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001012 $(PRIVATE_ARM_CFLAGS) \
1013 ) \
Doug Kwan9a8ecf92011-05-10 21:50:58 -07001014 $(PRIVATE_RTTI_FLAG) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001015 $(PRIVATE_CFLAGS) \
1016 $(PRIVATE_CPPFLAGS) \
1017 $(PRIVATE_DEBUG_CFLAGS) \
Atte Peltomaki60fe9632011-12-21 09:24:09 -08001018 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001019$(transform-d-to-p)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001020endef
1021
1022
1023###########################################################
1024## Commands for running gcc to compile a C file
1025###########################################################
1026
1027# $(1): extra flags
1028define transform-c-or-s-to-o-no-deps
1029@mkdir -p $(dir $@)
1030$(hide) $(PRIVATE_CC) \
Ying Wangddbcad82011-04-18 11:45:44 -07001031 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Andrew Boie85f3b212012-07-11 12:14:56 -07001032 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
Ying Wang4761e562011-04-12 11:06:35 -07001033 $(addprefix -isystem ,\
1034 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1035 $(filter-out $(PRIVATE_C_INCLUDES), \
Ying Wangddbcad82011-04-18 11:45:44 -07001036 $(PRIVATE_TARGET_PROJECT_INCLUDES) \
Ying Wang4761e562011-04-12 11:06:35 -07001037 $(PRIVATE_TARGET_C_INCLUDES)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001038 -c \
1039 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -07001040 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001041 $(PRIVATE_ARM_CFLAGS) \
1042 ) \
Ying Wang65d78522012-08-10 16:30:42 -07001043 $(1) \
Atte Peltomaki60fe9632011-12-21 09:24:09 -08001044 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
The Android Open Source Project88b60792009-03-03 19:28:42 -08001045endef
1046
1047define transform-c-to-o-no-deps
1048@echo "target $(PRIVATE_ARM_MODE) C: $(PRIVATE_MODULE) <= $<"
Ying Wang7429e212012-08-15 10:59:10 -07001049$(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 -08001050endef
1051
1052define transform-s-to-o-no-deps
1053@echo "target asm: $(PRIVATE_MODULE) <= $<"
1054$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
1055endef
1056
1057define transform-c-to-o
1058$(transform-c-to-o-no-deps)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001059$(transform-d-to-p)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001060endef
1061
1062define transform-s-to-o
1063$(transform-s-to-o-no-deps)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001064$(transform-d-to-p)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001065endef
1066
1067###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001068## Commands for running gcc to compile an Objective-C file
1069## This should never happen for target builds but this
1070## will error at build time.
1071###########################################################
1072
1073define transform-m-to-o-no-deps
1074@echo "target ObjC: $(PRIVATE_MODULE) <= $<"
Ying Wang65d78522012-08-10 16:30:42 -07001075$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_DEBUG_CFLAGS))
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001076endef
1077
1078define transform-m-to-o
1079$(transform-m-to-o-no-deps)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001080$(transform-d-to-p)
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001081endef
1082
1083###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001084## Commands for running gcc to compile a host C++ file
1085###########################################################
1086
1087define transform-host-cpp-to-o
1088@mkdir -p $(dir $@)
1089@echo "host C++: $(PRIVATE_MODULE) <= $<"
1090$(hide) $(PRIVATE_CXX) \
Ying Wangddbcad82011-04-18 11:45:44 -07001091 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Andrew Boie85f3b212012-07-11 12:14:56 -07001092 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
Ying Wangddbcad82011-04-18 11:45:44 -07001093 $(addprefix -isystem ,\
The Android Open Source Project88b60792009-03-03 19:28:42 -08001094 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wangddbcad82011-04-18 11:45:44 -07001095 $(filter-out $(PRIVATE_C_INCLUDES), \
1096 $(HOST_PROJECT_INCLUDES) \
Logan Chiene6f65432013-12-10 19:07:41 +08001097 $(PRIVATE_HOST_C_INCLUDES)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001098 -c \
1099 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001100 $(PRIVATE_HOST_GLOBAL_CFLAGS) \
1101 $(PRIVATE_HOST_GLOBAL_CPPFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001102 ) \
1103 $(PRIVATE_CFLAGS) \
1104 $(PRIVATE_CPPFLAGS) \
1105 $(PRIVATE_DEBUG_CFLAGS) \
Atte Peltomaki60fe9632011-12-21 09:24:09 -08001106 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
The Android Open Source Project88b60792009-03-03 19:28:42 -08001107$(transform-d-to-p)
1108endef
1109
1110
1111###########################################################
1112## Commands for running gcc to compile a host C file
1113###########################################################
1114
1115# $(1): extra flags
1116define transform-host-c-or-s-to-o-no-deps
1117@mkdir -p $(dir $@)
1118$(hide) $(PRIVATE_CC) \
Ying Wangddbcad82011-04-18 11:45:44 -07001119 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Andrew Boie85f3b212012-07-11 12:14:56 -07001120 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
Ying Wangddbcad82011-04-18 11:45:44 -07001121 $(addprefix -isystem ,\
The Android Open Source Project88b60792009-03-03 19:28:42 -08001122 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wangddbcad82011-04-18 11:45:44 -07001123 $(filter-out $(PRIVATE_C_INCLUDES), \
1124 $(HOST_PROJECT_INCLUDES) \
Logan Chiene6f65432013-12-10 19:07:41 +08001125 $(PRIVATE_HOST_C_INCLUDES)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001126 -c \
1127 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001128 $(PRIVATE_HOST_GLOBAL_CFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001129 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001130 $(1) \
Atte Peltomaki60fe9632011-12-21 09:24:09 -08001131 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
The Android Open Source Project88b60792009-03-03 19:28:42 -08001132endef
1133
1134define transform-host-c-to-o-no-deps
1135@echo "host C: $(PRIVATE_MODULE) <= $<"
Ying Wang7429e212012-08-15 10:59:10 -07001136$(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 -08001137endef
1138
1139define transform-host-s-to-o-no-deps
1140@echo "host asm: $(PRIVATE_MODULE) <= $<"
1141$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
1142endef
1143
1144define transform-host-c-to-o
1145$(transform-host-c-to-o-no-deps)
1146$(transform-d-to-p)
1147endef
1148
1149define transform-host-s-to-o
1150$(transform-host-s-to-o-no-deps)
1151$(transform-d-to-p)
1152endef
1153
1154###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001155## Commands for running gcc to compile a host Objective-C file
1156###########################################################
1157
1158define transform-host-m-to-o-no-deps
1159@echo "host ObjC: $(PRIVATE_MODULE) <= $<"
Ying Wang65d78522012-08-10 16:30:42 -07001160$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_DEBUG_CFLAGS))
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001161endef
1162
David 'Digit' Turner5ca286d2011-02-11 16:19:31 +01001163define transform-host-m-to-o
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001164$(transform-host-m-to-o-no-deps)
1165$(transform-d-to-p)
1166endef
1167
1168###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001169## Commands for running ar
1170###########################################################
1171
Ying Wange4b24eb2010-05-27 11:55:39 -07001172define _concat-if-arg2-not-empty
1173$(if $(2),$(hide) $(1) $(2))
1174endef
1175
1176# Split long argument list into smaller groups and call the command repeatedly
Torne (Richard Coles)bffaef22012-06-15 16:03:52 +01001177# Call the command at least once even if there are no arguments, as otherwise
1178# the output file won't be created.
Ying Wange4b24eb2010-05-27 11:55:39 -07001179#
1180# $(1): the command without arguments
1181# $(2): the arguments
1182define split-long-arguments
Torne (Richard Coles)bffaef22012-06-15 16:03:52 +01001183$(hide) $(1) $(wordlist 1,500,$(2))
Ying Wange4b24eb2010-05-27 11:55:39 -07001184$(call _concat-if-arg2-not-empty,$(1),$(wordlist 501,1000,$(2)))
1185$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1001,1500,$(2)))
1186$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1501,2000,$(2)))
1187$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2001,2500,$(2)))
1188$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2501,3000,$(2)))
1189$(call _concat-if-arg2-not-empty,$(1),$(wordlist 3001,99999,$(2)))
1190endef
1191
Ying Wanga02d3d92011-01-27 18:48:00 -08001192# $(1): the full path of the source static library.
1193define _extract-and-include-single-target-whole-static-lib
1194@echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(1)]"
1195$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\
1196 rm -rf $$ldir; \
1197 mkdir -p $$ldir; \
1198 filelist=; \
1199 for f in `$(TARGET_AR) t $(1)`; do \
Ying Wang6ef65192014-01-15 16:02:16 -08001200 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) p $(1) $$f > $$ldir/$$f; \
Ying Wanga02d3d92011-01-27 18:48:00 -08001201 filelist="$$filelist $$ldir/$$f"; \
1202 done ; \
Ying Wang6ef65192014-01-15 16:02:16 -08001203 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \
1204 $(PRIVATE_ARFLAGS) $@ $$filelist
Ying Wanga02d3d92011-01-27 18:48:00 -08001205
1206endef
1207
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001208define extract-and-include-target-whole-static-libs
Dima Zavin46e9bec2009-05-27 19:41:07 -07001209$(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \
Ying Wanga02d3d92011-01-27 18:48:00 -08001210 $(call _extract-and-include-single-target-whole-static-lib, $(lib)))
Dima Zavin46e9bec2009-05-27 19:41:07 -07001211endef
1212
The Android Open Source Project88b60792009-03-03 19:28:42 -08001213# Explicitly delete the archive first so that ar doesn't
1214# try to add to an existing archive.
1215define transform-o-to-static-lib
1216@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001217@rm -f $@
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001218$(extract-and-include-target-whole-static-libs)
Dima Zavin46e9bec2009-05-27 19:41:07 -07001219@echo "target StaticLib: $(PRIVATE_MODULE) ($@)"
Ying Wang6ef65192014-01-15 16:02:16 -08001220$(call split-long-arguments,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \
1221 $(PRIVATE_ARFLAGS) $@,$(filter %.o, $^))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001222endef
1223
1224###########################################################
1225## Commands for running host ar
1226###########################################################
1227
Ying Wanga02d3d92011-01-27 18:48:00 -08001228# $(1): the full path of the source static library.
1229define _extract-and-include-single-host-whole-static-lib
1230@echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(1)]"
1231$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\
1232 rm -rf $$ldir; \
1233 mkdir -p $$ldir; \
1234 filelist=; \
Jeff Hamilton293f9392011-11-18 17:15:25 -06001235 for f in `$(HOST_AR) t $(1) | \grep '\.o$$'`; do \
Ying Wanga02d3d92011-01-27 18:48:00 -08001236 $(HOST_AR) p $(1) $$f > $$ldir/$$f; \
1237 filelist="$$filelist $$ldir/$$f"; \
1238 done ; \
1239 $(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@ $$filelist
1240
1241endef
1242
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001243define extract-and-include-host-whole-static-libs
1244$(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \
Ying Wanga02d3d92011-01-27 18:48:00 -08001245 $(call _extract-and-include-single-host-whole-static-lib, $(lib)))
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001246endef
1247
The Android Open Source Project88b60792009-03-03 19:28:42 -08001248# Explicitly delete the archive first so that ar doesn't
1249# try to add to an existing archive.
1250define transform-host-o-to-static-lib
1251@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001252@rm -f $@
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001253$(extract-and-include-host-whole-static-libs)
Dan Bornstein6bffc912009-10-15 13:01:36 -07001254@echo "host StaticLib: $(PRIVATE_MODULE) ($@)"
Ying Wange4b24eb2010-05-27 11:55:39 -07001255$(call split-long-arguments,$(HOST_AR) $(HOST_GLOBAL_ARFLAGS) $(PRIVATE_ARFLAGS) $@,$(filter %.o, $^))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001256endef
1257
1258
1259###########################################################
1260## Commands for running gcc to link a shared library or package
1261###########################################################
1262
1263# ld just seems to be so finicky with command order that we allow
1264# it to be overriden en-masse see combo/linux-arm.make for an example.
1265ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1266define transform-host-o-to-shared-lib-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001267$(hide) $(PRIVATE_CXX) \
Ying Wang80e6cce2011-01-24 23:25:36 -08001268 -Wl,-rpath-link=$(HOST_OUT_INTERMEDIATE_LIBRARIES) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001269 -Wl,-rpath,\$$ORIGIN/../lib \
1270 -shared -Wl,-soname,$(notdir $@) \
1271 $(PRIVATE_LDFLAGS) \
1272 $(HOST_GLOBAL_LD_DIRS) \
1273 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001274 $(PRIVATE_HOST_GLOBAL_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001275 ) \
1276 $(PRIVATE_ALL_OBJECTS) \
1277 -Wl,--whole-archive \
1278 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1279 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001280 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001281 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001282 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001283 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1284 -o $@ \
1285 $(PRIVATE_LDLIBS)
1286endef
1287endif
1288
1289define transform-host-o-to-shared-lib
1290@mkdir -p $(dir $@)
1291@echo "host SharedLib: $(PRIVATE_MODULE) ($@)"
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001292$(transform-host-o-to-shared-lib-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001293endef
1294
1295define transform-host-o-to-package
1296@mkdir -p $(dir $@)
1297@echo "host Package: $(PRIVATE_MODULE) ($@)"
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001298$(transform-host-o-to-shared-lib-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001299endef
1300
1301
1302###########################################################
1303## Commands for running gcc to link a shared library or package
1304###########################################################
1305
1306#echo >$@.vers "{"; \
1307#echo >>$@.vers " global:"; \
1308#$(BUILD_SYSTEM)/filter_symbols.sh $(TARGET_NM) " " ";" $(filter %.o,$^) | sort -u >>$@.vers; \
1309#echo >>$@.vers " local:"; \
1310#echo >>$@.vers " *;"; \
1311#echo >>$@.vers "};"; \
1312
1313# -Wl,--version-script=$@.vers \
1314
1315# ld just seems to be so finicky with command order that we allow
1316# it to be overriden en-masse see combo/linux-arm.make for an example.
1317ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1318define transform-o-to-shared-lib-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001319$(hide) $(PRIVATE_CXX) \
Ying Wang1a081002010-07-13 14:55:47 -07001320 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001321 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1322 -Wl,-rpath,\$$ORIGIN/../lib \
1323 -shared -Wl,-soname,$(notdir $@) \
1324 $(PRIVATE_LDFLAGS) \
Ying Wang1a081002010-07-13 14:55:47 -07001325 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001326 $(PRIVATE_ALL_OBJECTS) \
1327 -Wl,--whole-archive \
Ying Wang80e6cce2011-01-24 23:25:36 -08001328 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001329 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001330 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001331 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001332 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001333 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1334 -o $@ \
1335 $(PRIVATE_LDLIBS)
1336endef
1337endif
1338
1339define transform-o-to-shared-lib
1340@mkdir -p $(dir $@)
1341@echo "target SharedLib: $(PRIVATE_MODULE) ($@)"
Ying Wang4d2cc662014-01-16 12:36:34 -08001342$($(PRIVATE_2ND_ARCH_VAR_PREFIX)transform-o-to-shared-lib-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001343endef
1344
1345
1346###########################################################
1347## Commands for filtering a target executable or library
1348###########################################################
1349
The Android Open Source Project88b60792009-03-03 19:28:42 -08001350define transform-to-stripped
1351@mkdir -p $(dir $@)
1352@echo "target Strip: $(PRIVATE_MODULE) ($@)"
Ying Wang4d2cc662014-01-16 12:36:34 -08001353$(hide) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_STRIP_COMMAND)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001354endef
1355
The Android Open Source Project88b60792009-03-03 19:28:42 -08001356
1357###########################################################
1358## Commands for running gcc to link an executable
1359###########################################################
1360
1361ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1362define transform-o-to-executable-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001363$(hide) $(PRIVATE_CXX) \
Ying Wangc6ffc002012-09-25 17:52:10 -07001364 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
1365 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001366 -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
1367 -Wl,-rpath,\$$ORIGIN/../lib \
1368 $(PRIVATE_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001369 $(PRIVATE_ALL_OBJECTS) \
1370 -Wl,--whole-archive \
1371 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1372 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001373 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001374 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001375 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001376 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1377 -o $@ \
1378 $(PRIVATE_LDLIBS)
1379endef
1380endif
1381
1382define transform-o-to-executable
1383@mkdir -p $(dir $@)
1384@echo "target Executable: $(PRIVATE_MODULE) ($@)"
Ying Wangdd814bf2014-01-17 16:17:28 -08001385$($(PRIVATE_2ND_ARCH_VAR_PREFIX)transform-o-to-executable-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001386endef
1387
1388
1389###########################################################
1390## Commands for running gcc to link a statically linked
1391## executable. In practice, we only use this on arm, so
1392## the other platforms don't have the
1393## transform-o-to-static-executable defined
1394###########################################################
1395
1396ifneq ($(TARGET_CUSTOM_LD_COMMAND),true)
1397define transform-o-to-static-executable-inner
1398endef
1399endif
1400
1401define transform-o-to-static-executable
1402@mkdir -p $(dir $@)
1403@echo "target StaticExecutable: $(PRIVATE_MODULE) ($@)"
Ying Wangdd814bf2014-01-17 16:17:28 -08001404$($(PRIVATE_2ND_ARCH_VAR_PREFIX)transform-o-to-static-executable-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001405endef
1406
1407
1408###########################################################
1409## Commands for running gcc to link a host executable
1410###########################################################
1411
1412ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1413define transform-host-o-to-executable-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001414$(hide) $(PRIVATE_CXX) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001415 $(PRIVATE_ALL_OBJECTS) \
1416 -Wl,--whole-archive \
1417 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1418 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001419 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001420 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001421 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001422 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
Conley Owensd9e7d252011-11-10 09:57:40 -08001423 -Wl,-rpath-link=$(HOST_OUT_INTERMEDIATE_LIBRARIES) \
1424 -Wl,-rpath,\$$ORIGIN/../lib \
1425 $(HOST_GLOBAL_LD_DIRS) \
1426 $(PRIVATE_LDFLAGS) \
1427 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001428 $(PRIVATE_HOST_GLOBAL_LDFLAGS) \
Joshua J. Drakeb0eafa22013-12-12 00:34:29 -06001429 -fPIE -pie \
Conley Owensd9e7d252011-11-10 09:57:40 -08001430 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001431 -o $@ \
1432 $(PRIVATE_LDLIBS)
1433endef
1434endif
1435
1436define transform-host-o-to-executable
1437@mkdir -p $(dir $@)
1438@echo "host Executable: $(PRIVATE_MODULE) ($@)"
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001439$(transform-host-o-to-executable-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001440endef
1441
1442
1443###########################################################
1444## Commands for running javac to make .class files
1445###########################################################
1446
1447#@echo "Source intermediates dir: $(PRIVATE_SOURCE_INTERMEDIATES_DIR)"
1448#@echo "Source intermediates: $$(find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java')"
1449
1450# TODO: Right now we generate the asset resources twice, first as part
1451# of generating the Java classes, then at the end when packaging the final
1452# assets. This should be changed to do one of two things: (1) Don't generate
1453# any resource files the first time, only create classes during that stage;
1454# or (2) Don't use the -c flag with the second stage, instead taking the
1455# resource files from the first stage as additional input. My original intent
1456# was to use approach (2), but this requires a little more work in the tool.
1457# Maybe we should just use approach (1).
1458
1459# This rule creates the R.java and Manifest.java files, both of which
Ying Wang4f1ab922011-03-15 13:19:30 -07001460# are PRODUCT-neutral. Don't pass PRIVATE_PRODUCT_AAPT_CONFIG to this invocation.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001461define create-resource-java-files
1462@mkdir -p $(PRIVATE_SOURCE_INTERMEDIATES_DIR)
1463@mkdir -p $(dir $(PRIVATE_RESOURCE_PUBLICS_OUTPUT))
Ying Wangc61d5932010-03-10 16:02:42 -08001464$(hide) $(AAPT) package $(PRIVATE_AAPT_FLAGS) -m \
Ying Wang4f1ab922011-03-15 13:19:30 -07001465 $(eval # PRIVATE_PRODUCT_AAPT_CONFIG is intentionally missing-- see comment.) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001466 $(addprefix -J , $(PRIVATE_SOURCE_INTERMEDIATES_DIR)) \
1467 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
1468 $(addprefix -P , $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) \
1469 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
1470 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001471 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
Joe Onorato2daa2b32009-08-30 13:39:24 -07001472 $(addprefix -G , $(PRIVATE_PROGUARD_OPTIONS_FILE)) \
Ying Wangbb9c2302011-04-08 17:27:35 -07001473 $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
1474 $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
Ying Wang1ae607a2010-06-23 13:34:22 -07001475 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \
Ying Wang8f5069b2010-06-29 11:08:13 -07001476 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION)-$(BUILD_NUMBER))) \
Ying Wang8c254822010-03-16 16:13:56 -07001477 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07001478 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001479endef
1480
1481ifeq ($(HOST_OS),windows)
1482xlint_unchecked :=
1483else
Jeffrey Chyan7adbf972010-07-07 13:42:19 -05001484xlint_unchecked := -Xlint:unchecked
The Android Open Source Project88b60792009-03-03 19:28:42 -08001485endif
1486
Brian Carlstrombb7c6d82011-04-01 15:45:58 -07001487ifeq (true, $(ENABLE_INCREMENTALJAVAC))
1488incremental_dex := --incremental
1489else
1490incremental_dex :=
1491endif
1492
The Android Open Source Project88b60792009-03-03 19:28:42 -08001493# emit-line, <word list>, <output file>
1494define emit-line
1495 $(if $(1),echo -n '$(strip $(1)) ' >> $(2))
1496endef
1497
1498# dump-words-to-file, <word list>, <output file>
1499define dump-words-to-file
1500 @rm -f $(2)
1501 @$(call emit-line,$(wordlist 1,200,$(1)),$(2))
1502 @$(call emit-line,$(wordlist 201,400,$(1)),$(2))
1503 @$(call emit-line,$(wordlist 401,600,$(1)),$(2))
1504 @$(call emit-line,$(wordlist 601,800,$(1)),$(2))
1505 @$(call emit-line,$(wordlist 801,1000,$(1)),$(2))
1506 @$(call emit-line,$(wordlist 1001,1200,$(1)),$(2))
1507 @$(call emit-line,$(wordlist 1201,1400,$(1)),$(2))
1508 @$(call emit-line,$(wordlist 1401,1600,$(1)),$(2))
1509 @$(call emit-line,$(wordlist 1601,1800,$(1)),$(2))
1510 @$(call emit-line,$(wordlist 1801,2000,$(1)),$(2))
1511 @$(call emit-line,$(wordlist 2001,2200,$(1)),$(2))
1512 @$(call emit-line,$(wordlist 2201,2400,$(1)),$(2))
1513 @$(call emit-line,$(wordlist 2401,2600,$(1)),$(2))
1514 @$(call emit-line,$(wordlist 2601,2800,$(1)),$(2))
1515 @$(call emit-line,$(wordlist 2801,3000,$(1)),$(2))
1516 @$(call emit-line,$(wordlist 3001,3200,$(1)),$(2))
1517 @$(call emit-line,$(wordlist 3201,3400,$(1)),$(2))
1518 @$(call emit-line,$(wordlist 3401,3600,$(1)),$(2))
1519 @$(call emit-line,$(wordlist 3601,3800,$(1)),$(2))
1520 @$(call emit-line,$(wordlist 3801,4000,$(1)),$(2))
Jesse Wilson72c941a2010-05-04 16:33:49 -07001521 @$(call emit-line,$(wordlist 4001,4200,$(1)),$(2))
1522 @$(call emit-line,$(wordlist 4201,4400,$(1)),$(2))
1523 @$(call emit-line,$(wordlist 4401,4600,$(1)),$(2))
1524 @$(call emit-line,$(wordlist 4601,4800,$(1)),$(2))
1525 @$(call emit-line,$(wordlist 4801,5000,$(1)),$(2))
1526 @$(if $(wordlist 5001,5002,$(1)),$(error Too many words ($(words $(1)))))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001527endef
1528
1529# For a list of jar files, unzip them to a specified directory,
1530# but make sure that no META-INF files come along for the ride.
1531#
1532# $(1): files to unzip
1533# $(2): destination directory
1534define unzip-jar-files
1535 $(hide) for f in $(1); \
1536 do \
1537 if [ ! -f $$f ]; then \
1538 echo Missing file $$f; \
1539 exit 1; \
1540 fi; \
Sriram Ramanf1a55f82009-06-09 15:08:29 -07001541 unzip -qo $$f -d $(2); \
Ying Wang3a6f7582012-08-30 12:59:42 -07001542 done \
1543 $(if $(PRIVATE_DONT_DELETE_JAR_META_INF),,;rm -rf $(2)/META-INF)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001544endef
1545
Brian Carlstrom78269512010-12-10 12:10:24 -08001546# Common definition to invoke javac on the host and target.
1547#
1548# Some historical notes:
1549# - below we write the list of java files to java-source-list to avoid argument
1550# list length problems with Cygwin
1551# - we filter out duplicate java file names because eclipse's compiler
1552# doesn't like them.
1553#
1554# $(1): javac
1555# $(2): bootclasspath
1556define compile-java
Joe Onorato64d85d02009-04-09 19:31:12 -07001557$(hide) rm -f $@
1558$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
Brian Carlstrom78269512010-12-10 12:10:24 -08001559$(hide) mkdir -p $(dir $@)
Joe Onorato64d85d02009-04-09 19:31:12 -07001560$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
Brian Carlstrom78269512010-12-10 12:10:24 -08001561$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES),$(PRIVATE_CLASS_INTERMEDIATES_DIR))
Ying Wang015edd22011-01-20 15:01:56 -08001562$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list)
Joe Onorato64d85d02009-04-09 19:31:12 -07001563$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
Ying Wang015edd22011-01-20 15:01:56 -08001564 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list; \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001565fi
Ying Wang015edd22011-01-20 15:01:56 -08001566$(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \
1567 | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
Ying Wange109a1d2011-12-12 17:52:03 -08001568$(hide) if [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
1569 $(1) -encoding UTF-8 \
Brian Carlstrom78269512010-12-10 12:10:24 -08001570 $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) \
Ying Wang057eba02012-10-18 10:54:49 -07001571 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
Brian Carlstrom78269512010-12-10 12:10:24 -08001572 $(2) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001573 $(addprefix -classpath ,$(strip \
1574 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \
Ying Wang057eba02012-10-18 10:54:49 -07001575 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001576 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
Brian Carlstrom78269512010-12-10 12:10:24 -08001577 $(PRIVATE_JAVACFLAGS) \
Ying Wang015edd22011-01-20 15:01:56 -08001578 \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \
Ying Wange109a1d2011-12-12 17:52:03 -08001579 || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 ) \
1580fi
Joe Onorato0eccce92011-10-30 21:37:35 -07001581$(if $(PRIVATE_JAVA_LAYERS_FILE), $(hide) build/tools/java-layers.py \
1582 $(PRIVATE_JAVA_LAYERS_FILE) \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq,)
Ying Wang015edd22011-01-20 15:01:56 -08001583$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list
1584$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
Ying Wang5758b8e2011-12-15 16:36:55 -08001585$(if $(PRIVATE_JAR_EXCLUDE_FILES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
1586 -name $(word 1, $(PRIVATE_JAR_EXCLUDE_FILES)) \
1587 $(addprefix -o -name , $(wordlist 2, 999, $(PRIVATE_JAR_EXCLUDE_FILES))) \
1588 | xargs rm -rf)
Jeff Brownae859f92013-07-17 20:29:51 -07001589$(if $(PRIVATE_JAR_PACKAGES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -mindepth 1 -type d \
1590 $(foreach pkg, $(PRIVATE_JAR_PACKAGES), \
1591 -not -path $(PRIVATE_CLASS_INTERMEDIATES_DIR)/$(subst .,/,$(pkg))) \
1592 | xargs rm -rf)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001593$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \
1594 $@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
Brian Carlstrom78269512010-12-10 12:10:24 -08001595endef
1596
1597define transform-java-to-classes.jar
1598@echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
1599$(call compile-java,$(TARGET_JAVAC),$(PRIVATE_BOOTCLASSPATH))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001600endef
1601
Ying Wang015edd22011-01-20 15:01:56 -08001602# Override the above definitions if we want to do incremetal javac
1603ifeq (true, $(ENABLE_INCREMENTALJAVAC))
1604define compile-java
1605$(hide) mkdir -p $(dir $@)
1606$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
1607$(hide) touch $(PRIVATE_CLASS_INTERMEDIATES_DIR)/newstamp
1608$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES),$(PRIVATE_CLASS_INTERMEDIATES_DIR))
1609$(hide) if [ -e $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stamp ] ; then \
1610 newerFlag=$$(echo -n "-newer $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stamp") ; \
1611 fi ; \
1612 find $(PRIVATE_JAVA_SOURCES) $$newerFlag > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list ; \
1613 if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
1614 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' $$newerFlag >> $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list; \
1615 fi
1616$(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \
1617 | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
1618@echo "(Incremental) build source files:"
1619@cat $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
1620$(hide) if [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
Joe Onorato149dd912011-05-31 18:21:07 -07001621 $(1) -encoding UTF-8 \
Ying Wang015edd22011-01-20 15:01:56 -08001622 $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) \
Ying Wang057eba02012-10-18 10:54:49 -07001623 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
Ying Wang015edd22011-01-20 15:01:56 -08001624 $(2) \
1625 $(addprefix -classpath ,$(strip \
1626 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES) $(PRIVATE_CLASS_INTERMEDIATES_DIR)))) \
Ying Wang057eba02012-10-18 10:54:49 -07001627 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
Ying Wang015edd22011-01-20 15:01:56 -08001628 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
1629 $(PRIVATE_JAVACFLAGS) \
1630 \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \
1631 || ( exit 41 ) \
1632fi
1633$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list
1634$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
1635$(hide) rm -f $@
Ying Wangae25ec12012-06-19 10:40:37 -07001636$(if $(PRIVATE_JAR_EXCLUDE_FILES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
1637 -name $(word 1, $(PRIVATE_JAR_EXCLUDE_FILES)) \
1638 $(addprefix -o -name , $(wordlist 2, 999, $(PRIVATE_JAR_EXCLUDE_FILES))) \
1639 | xargs rm -rf)
Jeff Brownae859f92013-07-17 20:29:51 -07001640$(if $(PRIVATE_JAR_PACKAGES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -mindepth 1 -type d \
1641 $(foreach pkg, $(PRIVATE_JAR_PACKAGES), \
1642 -not -path $(PRIVATE_CLASS_INTERMEDIATES_DIR)/$(subst .,/,$(pkg))) \
1643 | xargs rm -rf)
Ying Wang015edd22011-01-20 15:01:56 -08001644$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \
1645 $@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
1646$(hide) mv $(PRIVATE_CLASS_INTERMEDIATES_DIR)/newstamp $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stamp
1647endef
1648
1649define transform-java-to-classes.jar
1650@echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
1651$(call compile-java,$(TARGET_JAVAC),$(PRIVATE_BOOTCLASSPATH))
1652endef
1653endif # ENABLE_INCREMENTALJAVAC
1654
The Android Open Source Project88b60792009-03-03 19:28:42 -08001655define transform-classes.jar-to-emma
1656$(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \
Guang Zhu155afe32010-03-10 15:48:03 -08001657 $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR) \
Guang Zhu9cd3d8c2010-06-15 13:31:25 -07001658 $(addprefix -ix , $(PRIVATE_EMMA_COVERAGE_FILTER))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001659endef
1660
1661#TODO: use a smaller -Xmx value for most libraries;
1662# only core.jar and framework.jar need a heap this big.
Raphaelf6ff4c52009-08-18 14:43:32 -07001663# 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 -08001664define transform-classes.jar-to-dex
1665@echo "target Dex: $(PRIVATE_MODULE)"
1666@mkdir -p $(dir $@)
Raphaelf6ff4c52009-08-18 14:43:32 -07001667$(hide) $(DX) \
Wink Saville29b3afa2012-01-30 15:30:10 -08001668 $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx2048M) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001669 --dex --output=$@ \
Brian Carlstrombb7c6d82011-04-01 15:45:58 -07001670 $(incremental_dex) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001671 $(if $(NO_OPTIMIZE_DX), \
1672 --no-optimize) \
1673 $(if $(GENERATE_DEX_DEBUG), \
1674 --debug --verbose \
1675 --dump-to=$(@:.dex=.lst) \
1676 --dump-width=1000) \
1677 $(PRIVATE_DX_FLAGS) \
1678 $<
1679endef
1680
1681# Create a mostly-empty .jar file that we'll add to later.
1682# The MacOS jar tool doesn't like creating empty jar files,
1683# so we need to give it something.
1684define create-empty-package
1685@mkdir -p $(dir $@)
1686$(hide) touch $(dir $@)/dummy
1687$(hide) (cd $(dir $@) && jar cf $(notdir $@) dummy)
1688$(hide) zip -qd $@ dummy
1689$(hide) rm $(dir $@)/dummy
1690endef
1691
1692#TODO: we kinda want to build different asset packages for
1693# different configurations, then combine them later (or something).
1694# Per-locale, etc.
1695# A list of dynamic and static parameters; build layers for
1696# dynamic params that lay over the static ones.
1697#TODO: update the manifest to point to the package file
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001698#Note that the version numbers are given to aapt as simple default
1699#values; applications can override these by explicitly stating
1700#them in their manifest.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001701define add-assets-to-package
Ying Wangc61d5932010-03-10 16:02:42 -08001702$(hide) $(AAPT) package -u $(PRIVATE_AAPT_FLAGS) \
Ying Wang4f1ab922011-03-15 13:19:30 -07001703 $(addprefix -c , $(PRIVATE_PRODUCT_AAPT_CONFIG)) \
Dianne Hackborna0f464a2011-10-14 19:37:57 -07001704 $(addprefix --preferred-configurations , $(PRIVATE_PRODUCT_AAPT_PREF_CONFIG)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001705 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
1706 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
1707 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
1708 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
Ying Wangbb9c2302011-04-08 17:27:35 -07001709 $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
1710 $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
Joe Onorato700b88e2010-10-05 17:33:58 -04001711 $(addprefix --product , $(TARGET_AAPT_CHARACTERISTICS)) \
Ying Wang1ae607a2010-06-23 13:34:22 -07001712 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \
Ying Wang8f5069b2010-06-29 11:08:13 -07001713 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION)-$(BUILD_NUMBER))) \
Jeff Hamiltonbb67d212010-02-05 22:36:42 -06001714 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07001715 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001716 -F $@
1717endef
1718
The Android Open Source Project88b60792009-03-03 19:28:42 -08001719define add-jni-shared-libs-to-package
1720$(hide) rm -rf $(dir $@)lib
Jack Palevicha0ab29b2010-06-18 15:38:07 +08001721$(hide) mkdir -p $(dir $@)lib/$(PRIVATE_JNI_SHARED_LIBRARIES_ABI)
1722$(hide) cp $(PRIVATE_JNI_SHARED_LIBRARIES) $(dir $@)lib/$(PRIVATE_JNI_SHARED_LIBRARIES_ABI)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001723$(hide) (cd $(dir $@) && zip -r $(notdir $@) lib)
1724$(hide) rm -rf $(dir $@)lib
1725endef
1726
The Android Open Source Project88b60792009-03-03 19:28:42 -08001727#TODO: update the manifest to point to the dex file
1728define add-dex-to-package
Ying Wang957fea52010-09-23 11:48:38 -07001729$(if $(filter classes.dex,$(notdir $(PRIVATE_DEX_FILE))),\
-b masterc3ccfee2013-01-23 16:54:32 -08001730$(hide) zip -qj $@ $(PRIVATE_DEX_FILE),\
Ying Wang6e7db382011-07-27 12:49:15 -07001731$(hide) _adtp_classes_dex=$(dir $(PRIVATE_DEX_FILE))classes.dex; \
1732cp $(PRIVATE_DEX_FILE) $$_adtp_classes_dex && \
-b masterc3ccfee2013-01-23 16:54:32 -08001733zip -qj $@ $$_adtp_classes_dex && rm -f $$_adtp_classes_dex)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001734endef
1735
Ying Wang85480622012-08-09 15:20:50 -07001736# Add java resources added by the current module.
1737#
The Android Open Source Project88b60792009-03-03 19:28:42 -08001738define add-java-resources-to-package
Ying Wang194a8ec2011-06-06 14:34:52 -07001739$(call dump-words-to-file, $(PRIVATE_EXTRA_JAR_ARGS), $(dir $@)jar-arg-list)
1740$(hide) jar uf $@ @$(dir $@)jar-arg-list
1741@rm -f $(dir $@)jar-arg-list
The Android Open Source Project88b60792009-03-03 19:28:42 -08001742endef
1743
Ying Wang85480622012-08-09 15:20:50 -07001744# Add java resources carried by static Java libraries.
1745#
1746define add-carried-java-resources
1747$(hide) if [ -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) ] ; then \
1748 java_res_jar_flags=$$(find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -type f -a -not -name "*.class" \
1749 | sed -e "s?^$(PRIVATE_CLASS_INTERMEDIATES_DIR)/? -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) ?"); \
1750 if [ -n "$$java_res_jar_flags" ] ; then \
1751 echo $$java_res_jar_flags >$(dir $@)java_res_jar_flags; \
1752 jar uf $@ $$java_res_jar_flags; \
1753 fi; \
1754fi
1755endef
1756
The Android Open Source Project88b60792009-03-03 19:28:42 -08001757# Sign a package using the specified key/cert.
1758#
1759define sign-package
1760$(hide) mv $@ $@.unsigned
1761$(hide) java -jar $(SIGNAPK_JAR) \
Ying Wang31df0682012-11-13 10:55:28 -08001762 $(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) \
1763 $(PRIVATE_ADDITIONAL_CERTIFICATES) $@.unsigned $@.signed
The Android Open Source Project88b60792009-03-03 19:28:42 -08001764$(hide) mv $@.signed $@
1765endef
1766
1767# Align STORED entries of a package on 4-byte boundaries
1768# to make them easier to mmap.
1769#
1770define align-package
1771$(hide) mv $@ $@.unaligned
1772$(hide) $(ZIPALIGN) -f 4 $@.unaligned $@.aligned
1773$(hide) mv $@.aligned $@
1774endef
1775
1776define install-dex-debug
1777$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.dex" ]; then \
1778 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
1779 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.dex \
1780 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).dex; \
1781 fi
1782$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.lst" ]; then \
1783 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
1784 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.lst \
1785 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).lst; \
1786 fi
1787endef
1788
1789# TODO(joeo): If we can ever upgrade to post 3.81 make and get the
1790# new prebuilt rules to work, we should change this to copy the
1791# resources to the out directory and then copy the resources.
1792
Brian Carlstrom78269512010-12-10 12:10:24 -08001793# Note: we intentionally don't clean PRIVATE_CLASS_INTERMEDIATES_DIR
1794# in transform-java-to-classes for the sake of vm-tests.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001795define transform-host-java-to-package
1796@echo "host Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
Ying Wang015edd22011-01-20 15:01:56 -08001797$(call compile-java,$(HOST_JAVAC),$(PRIVATE_BOOTCLASSPATH))
Ying Wang194a8ec2011-06-06 14:34:52 -07001798$(if $(PRIVATE_EXTRA_JAR_ARGS), $(call add-java-resources-to-package))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001799endef
1800
1801###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001802## Commands for copying files
1803###########################################################
1804
1805# Define a rule to copy a header. Used via $(eval) by copy_headers.make.
1806# $(1): source header
1807# $(2): destination header
1808define copy-one-header
1809$(2): $(1)
1810 @echo "Header: $$@"
1811 $$(copy-file-to-new-target-with-cp)
1812endef
1813
1814# Define a rule to copy a file. For use via $(eval).
1815# $(1): source file
1816# $(2): destination file
1817define copy-one-file
1818$(2): $(1) | $(ACP)
1819 @echo "Copy: $$@"
1820 $$(copy-file-to-target)
1821endef
1822
Joe Onoratoe44705a2012-05-17 17:12:04 -07001823# Copies many files.
1824# $(1): The files to copy. Each entry is a ':' separated src:dst pair
1825# Evaluates to the list of the dst files (ie suitable for a dependency list)
1826define copy-many-files
1827$(foreach f, $(1), $(strip \
1828 $(eval _cmf_tuple := $(subst :, ,$(f))) \
1829 $(eval _cmf_src := $(word 1,$(_cmf_tuple))) \
1830 $(eval _cmf_dest := $(word 2,$(_cmf_tuple))) \
1831 $(eval $(call copy-one-file,$(_cmf_src),$(_cmf_dest))) \
1832 $(_cmf_dest)))
1833endef
1834
Ying Wang3ceecfa2012-05-14 14:39:00 -07001835# Copy the file only if it's a well-formed xml file. For use via $(eval).
1836# $(1): source file
1837# $(2): destination file, must end with .xml.
1838define copy-xml-file-checked
1839$(2): $(1) | $(ACP)
1840 @echo "Copy xml: $$@"
1841 $(hide) xmllint $$< >/dev/null # Don't print the xml file to stdout.
1842 $$(copy-file-to-target)
1843endef
1844
The Android Open Source Project88b60792009-03-03 19:28:42 -08001845# The -t option to acp and the -p option to cp is
1846# required for OSX. OSX has a ridiculous restriction
1847# where it's an error for a .a file's modification time
1848# to disagree with an internal timestamp, and this
1849# macro is used to install .a files (among other things).
1850
1851# Copy a single file from one place to another,
1852# preserving permissions and overwriting any existing
1853# file.
Ian Rogers76a6dc32012-10-01 16:36:23 -07001854# We disable the "-t" option for acp cannot handle
Ying Wang84ed6fa2011-01-18 17:21:20 -08001855# high resolution timestamp correctly on file systems like ext4.
1856# Therefore copy-file-to-target is the same as copy-file-to-new-target.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001857define copy-file-to-target
1858@mkdir -p $(dir $@)
Ying Wang84ed6fa2011-01-18 17:21:20 -08001859$(hide) $(ACP) -fp $< $@
The Android Open Source Project88b60792009-03-03 19:28:42 -08001860endef
1861
1862# The same as copy-file-to-target, but use the local
1863# cp command instead of acp.
1864define copy-file-to-target-with-cp
1865@mkdir -p $(dir $@)
1866$(hide) cp -fp $< $@
1867endef
1868
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07001869# The same as copy-file-to-target, but use the zipalign tool to do so.
1870define copy-file-to-target-with-zipalign
1871@mkdir -p $(dir $@)
1872$(hide) $(ZIPALIGN) -f 4 $< $@
1873endef
1874
Doug Zongker1046d202009-08-06 13:02:19 -07001875# The same as copy-file-to-target, but strip out "# comment"-style
1876# comments (for config files and such).
1877define copy-file-to-target-strip-comments
1878@mkdir -p $(dir $@)
1879$(hide) sed -e 's/#.*$$//' -e 's/[ \t]*$$//' -e '/^$$/d' < $< > $@
1880endef
1881
The Android Open Source Project88b60792009-03-03 19:28:42 -08001882# The same as copy-file-to-target, but don't preserve
1883# the old modification time.
1884define copy-file-to-new-target
1885@mkdir -p $(dir $@)
1886$(hide) $(ACP) -fp $< $@
1887endef
1888
1889# The same as copy-file-to-new-target, but use the local
1890# cp command instead of acp.
1891define copy-file-to-new-target-with-cp
1892@mkdir -p $(dir $@)
1893$(hide) cp -f $< $@
1894endef
1895
1896# Copy a prebuilt file to a target location.
1897define transform-prebuilt-to-target
1898@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"
1899$(copy-file-to-target)
1900endef
1901
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07001902# Copy a prebuilt file to a target location, using zipalign on it.
1903define transform-prebuilt-to-target-with-zipalign
1904@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt APK: $(PRIVATE_MODULE) ($@)"
1905$(copy-file-to-target-with-zipalign)
1906endef
1907
Doug Zongker1046d202009-08-06 13:02:19 -07001908# Copy a prebuilt file to a target location, stripping "# comment" comments.
1909define transform-prebuilt-to-target-strip-comments
1910@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"
1911$(copy-file-to-target-strip-comments)
1912endef
1913
The Android Open Source Project88b60792009-03-03 19:28:42 -08001914###########################################################
1915## On some platforms (MacOS), after copying a static
1916## library, ranlib must be run to update an internal
1917## timestamp!?!?!
1918###########################################################
1919
1920ifeq ($(HOST_RUN_RANLIB_AFTER_COPYING),true)
1921define transform-host-ranlib-copy-hack
1922 $(hide) ranlib $@ || true
1923endef
1924else
1925define transform-host-ranlib-copy-hack
Patrick Scott0e27dff2010-05-07 08:37:11 -04001926@true
The Android Open Source Project88b60792009-03-03 19:28:42 -08001927endef
1928endif
1929
1930ifeq ($(TARGET_RUN_RANLIB_AFTER_COPYING),true)
1931define transform-ranlib-copy-hack
1932 $(hide) ranlib $@
1933endef
1934else
1935define transform-ranlib-copy-hack
Patrick Scott0e27dff2010-05-07 08:37:11 -04001936@true
The Android Open Source Project88b60792009-03-03 19:28:42 -08001937endef
1938endif
1939
1940
1941###########################################################
Ying Wang3b2bdf12010-02-01 09:51:23 -08001942## Commands to call Proguard
1943###########################################################
Ying Wang3b2bdf12010-02-01 09:51:23 -08001944define transform-jar-to-proguard
Ying Wang7311a342013-08-21 18:32:49 -07001945@echo Proguard: $@
1946$(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS)
Ying Wang3b2bdf12010-02-01 09:51:23 -08001947endef
1948
Ying Wang3b2bdf12010-02-01 09:51:23 -08001949###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001950## Stuff source generated from one-off tools
1951###########################################################
1952
1953define transform-generated-source
1954@echo "target Generated: $(PRIVATE_MODULE) <= $<"
1955@mkdir -p $(dir $@)
1956$(hide) $(PRIVATE_CUSTOM_TOOL)
1957endef
1958
1959
1960###########################################################
1961## Assertions about attributes of the target
1962###########################################################
1963
1964# $(1): The file to check
1965ifndef get-file-size
1966$(error HOST_OS must define get-file-size)
1967endif
1968
Doug Zongker4647f122009-07-02 09:00:54 -07001969# Convert a partition data size (eg, as reported in /proc/mtd) to the
1970# size of the image used to flash that partition (which includes a
Lars Svensson9cb8c282010-12-06 15:24:58 +01001971# spare area for each page).
Doug Zongker4647f122009-07-02 09:00:54 -07001972# $(1): the partition data size
1973define image-size-from-data-size
Ying Wang4a2ecaf2011-02-09 17:24:27 -08001974$(strip $(eval _isfds_value := $$(shell echo $$$$(($(1) / $(BOARD_NAND_PAGE_SIZE) * \
1975 ($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE))))))\
1976$(if $(filter 0, $(_isfds_value)),$(shell echo $$(($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE)))),$(_isfds_value))\
1977$(eval _isfds_value :=))
Doug Zongker4647f122009-07-02 09:00:54 -07001978endef
1979
1980# $(1): The file(s) to check (often $@)
1981# $(2): The maximum total image size, in decimal bytes
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001982# $(3): the type of filesystem "yaffs" or "raw"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001983#
1984# If $(2) is empty, evaluates to "true"
1985#
1986# Reserve bad blocks. Make sure that MAX(1% of partition size, 2 blocks)
1987# is left over after the image has been flashed. Round the 1% up to the
1988# next whole flash block size.
1989define assert-max-file-size
1990$(if $(2), \
Doug Zongker742fa572009-07-08 12:09:04 -07001991 size=$$(for i in $(1); do $(call get-file-size,$$i); echo +; done; echo 0); \
1992 total=$$(( $$( echo "$$size" ) )); \
Doug Zongker4647f122009-07-02 09:00:54 -07001993 printname=$$(echo -n "$(1)" | tr " " +); \
Doug Zongker4647f122009-07-02 09:00:54 -07001994 img_blocksize=$(call image-size-from-data-size,$(BOARD_FLASH_BLOCK_SIZE)); \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001995 if [ "$(3)" == "yaffs" ]; then \
Doug Zongker93d9ff42009-09-14 17:46:41 -07001996 reservedblocks=8; \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001997 else \
Doug Zongker4ac1ba62009-08-25 20:38:50 -07001998 reservedblocks=0; \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07001999 fi; \
Doug Zongker4647f122009-07-02 09:00:54 -07002000 twoblocks=$$((img_blocksize * 2)); \
2001 onepct=$$((((($(2) / 100) - 1) / img_blocksize + 1) * img_blocksize)); \
Doug Zongker6dd2ae02009-08-25 17:23:57 -07002002 reserve=$$(((twoblocks > onepct ? twoblocks : onepct) + \
2003 reservedblocks * img_blocksize)); \
Doug Zongker4647f122009-07-02 09:00:54 -07002004 maxsize=$$(($(2) - reserve)); \
Ying Wang99bcbeb2011-12-02 10:34:45 -08002005 echo "$$printname maxsize=$$maxsize blocksize=$$img_blocksize total=$$total reserve=$$reserve"; \
Doug Zongker4647f122009-07-02 09:00:54 -07002006 if [ "$$total" -gt "$$maxsize" ]; then \
2007 echo "error: $$printname too large ($$total > [$(2) - $$reserve])"; \
2008 false; \
Doug Zongker742fa572009-07-08 12:09:04 -07002009 elif [ "$$total" -gt $$((maxsize - 32768)) ]; then \
Doug Zongker4647f122009-07-02 09:00:54 -07002010 echo "WARNING: $$printname approaching size limit ($$total now; limit $$maxsize)"; \
The Android Open Source Project88b60792009-03-03 19:28:42 -08002011 fi \
2012 , \
2013 true \
2014 )
2015endef
2016
Doug Zongker8510a1e2009-08-07 16:38:08 -07002017# Like assert-max-file-size, but the second argument is a partition
2018# size, which we'll convert to a max image size before checking it
2019# against the files.
2020#
2021# $(1): The file(s) to check (often $@)
2022# $(2): The partition size.
2023define assert-max-image-size
2024$(if $(2), \
2025 $(call assert-max-file-size,$(1),$(call image-size-from-data-size,$(2))), \
2026 true)
2027endef
2028
Doug Zongkere01100c2009-06-19 17:12:18 -07002029
2030###########################################################
2031## Define device-specific radio files
2032###########################################################
Ying Wang94de1eb2013-07-26 12:19:20 -07002033INSTALLED_RADIOIMAGE_TARGET :=
Doug Zongkere01100c2009-06-19 17:12:18 -07002034
2035# Copy a radio image file to the output location, and add it to
2036# INSTALLED_RADIOIMAGE_TARGET.
2037# $(1): filename
2038define add-radio-file
Doug Zongker14833602010-02-02 13:12:04 -08002039 $(eval $(call add-radio-file-internal,$(1),$(notdir $(1))))
Doug Zongkere01100c2009-06-19 17:12:18 -07002040endef
2041define add-radio-file-internal
Doug Zongker14833602010-02-02 13:12:04 -08002042INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
Doug Zongker14833602010-02-02 13:12:04 -08002043$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP)
Doug Zongkere01100c2009-06-19 17:12:18 -07002044 $$(transform-prebuilt-to-target)
2045endef
2046
Doug Zongker9296f092012-03-20 16:42:22 -07002047# Version of add-radio-file that also arranges for the version of the
2048# file to be checked against the contents of
2049# $(TARGET_BOARD_INFO_FILE).
2050# $(1): filename
2051# $(2): name of version variable in board-info (eg, "version-baseband")
2052define add-radio-file-checked
2053 $(eval $(call add-radio-file-checked-internal,$(1),$(notdir $(1)),$(2)))
2054endef
2055define add-radio-file-checked-internal
2056INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
2057BOARD_INFO_CHECK += $(3):$(LOCAL_PATH)/$(1)
2058$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP)
2059 $$(transform-prebuilt-to-target)
2060endef
2061
Doug Zongkere01100c2009-06-19 17:12:18 -07002062
The Android Open Source Project88b60792009-03-03 19:28:42 -08002063###########################################################
Joe Onorato899e62a2010-02-04 17:37:21 -08002064# Override the package defined in $(1), setting the
2065# variables listed below differently.
2066#
2067# $(1): The makefile to override (relative to the source
2068# tree root)
2069# $(2): Old LOCAL_PACKAGE_NAME value.
2070# $(3): New LOCAL_PACKAGE_NAME value.
Ying Wang3dae0ee2010-09-02 15:41:01 -07002071# $(4): New LOCAL_MANIFEST_PACKAGE_NAME value.
2072# $(5): New LOCAL_CERTIFICATE value.
2073# $(6): New LOCAL_INSTRUMENTATION_FOR value.
2074# $(7): New LOCAL_MANIFEST_INSTRUMENTATION_FOR value.
Joe Onorato899e62a2010-02-04 17:37:21 -08002075#
2076# Note that LOCAL_PACKAGE_OVERRIDES is NOT cleared in
2077# clear_vars.mk.
2078###########################################################
2079define inherit-package
Ying Wang3dae0ee2010-09-02 15:41:01 -07002080 $(eval $(call inherit-package-internal,$(1),$(2),$(3),$(4),$(5),$(6),$(7)))
Joe Onorato899e62a2010-02-04 17:37:21 -08002081endef
2082
2083define inherit-package-internal
2084 LOCAL_PACKAGE_OVERRIDES \
Ying Wang3dae0ee2010-09-02 15:41:01 -07002085 := $(strip $(1))||$(strip $(2))||$(strip $(3))||$(strip $(4))||&&$(strip $(5))||&&$(strip $(6))||&&$(strip $(7)) $(LOCAL_PACKAGE_OVERRIDES)
Joe Onorato899e62a2010-02-04 17:37:21 -08002086 include $(1)
2087 LOCAL_PACKAGE_OVERRIDES \
2088 := $(wordlist 1,$(words $(LOCAL_PACKAGE_OVERRIDES)), $(LOCAL_PACKAGE_OVERRIDES))
2089endef
2090
2091# To be used with inherit-package above
2092# Evalutes to true if the package was overridden
2093define set-inherited-package-variables
2094$(strip $(call set-inherited-package-variables-internal))
2095endef
2096
2097define keep-or-override
2098$(eval $(1) := $(if $(2),$(2),$($(1))))
2099endef
2100
2101define set-inherited-package-variables-internal
2102 $(eval _o := $(subst ||, ,$(lastword $(LOCAL_PACKAGE_OVERRIDES))))
2103 $(eval _n := $(subst ||, ,$(firstword $(LOCAL_PACKAGE_OVERRIDES))))
2104 $(if $(filter $(word 2,$(_n)),$(LOCAL_PACKAGE_NAME)), \
2105 $(eval LOCAL_PACKAGE_NAME := $(word 3,$(_o))) \
2106 $(eval LOCAL_MANIFEST_PACKAGE_NAME := $(word 4,$(_o))) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07002107 $(call keep-or-override,LOCAL_CERTIFICATE,$(patsubst &&%,%,$(word 5,$(_o)))) \
2108 $(call keep-or-override,LOCAL_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 6,$(_o)))) \
2109 $(call keep-or-override,LOCAL_MANIFEST_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 7,$(_o)))) \
Joe Onorato899e62a2010-02-04 17:37:21 -08002110 $(eval LOCAL_OVERRIDES_PACKAGES := $(sort $(LOCAL_OVERRIDES_PACKAGES) $(word 2,$(_o)))) \
2111 true \
2112 ,)
2113endef
2114
Ying Wang000e89a2012-04-30 15:48:27 -07002115###########################################################
2116## Expand a module name list with REQUIRED modules
2117###########################################################
2118# $(1): The variable name that holds the initial module name list.
2119# the variable will be modified to hold the expanded results.
2120# $(2): The initial module name list.
2121# Returns empty string (maybe with some whitespaces).
2122define expand-required-modules
2123$(eval _erm_new_modules := $(sort $(filter-out $($(1)),\
2124 $(foreach m,$(2),$(ALL_MODULES.$(m).REQUIRED)))))\
2125$(if $(_erm_new_modules),$(eval $(1) += $(_erm_new_modules))\
2126 $(call expand-required-modules,$(1),$(_erm_new_modules)))
2127endef
Joe Onorato899e62a2010-02-04 17:37:21 -08002128
2129###########################################################
Ying Wangc065da22012-11-14 15:57:07 -08002130## API Check
2131###########################################################
2132
2133# eval this to define a rule that runs apicheck.
2134#
2135# Args:
2136# $(1) target
2137# $(2) stable api file
2138# $(3) api file to be tested
2139# $(4) arguments for apicheck
2140# $(5) command to run if apicheck failed
2141# $(6) target dependent on this api check
2142# $(7) additional dependencies
2143define check-api
2144$(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(strip $(1))-timestamp: $(2) $(3) $(APICHECK) $(7)
2145 @echo "Checking API:" $(1)
2146 $(hide) ( $(APICHECK_COMMAND) $(4) $(2) $(3) || ( $(5) ; exit 38 ) )
2147 $(hide) mkdir -p $$(dir $$@)
2148 $(hide) touch $$@
2149$(6): $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(strip $(1))-timestamp
2150endef
2151
Ying Wang63d94fa2012-12-13 18:23:01 -08002152## Whether to build from source if prebuilt alternative exists
2153###########################################################
2154# $(1): module name
2155# $(2): LOCAL_PATH
2156# Expands to empty string if not from source.
2157ifeq (true,$(ANDROID_BUILD_FROM_SOURCE))
2158define if-build-from-source
2159true
2160endef
2161else
2162define if-build-from-source
2163$(if $(filter $(ANDROID_NO_PREBUILT_MODULES),$(1))$(filter \
2164 $(addsuffix %,$(ANDROID_NO_PREBUILT_PATHS)),$(2)),true)
2165endef
2166endif
2167
2168# Include makefile $(1) if build from source for module $(2)
2169# $(1): the makefile to include
2170# $(2): module name
2171# $(3): LOCAL_PATH
2172define include-if-build-from-source
2173$(if $(call if-build-from-source,$(2),$(3)),$(eval include $(1)))
2174endef
2175
Ying Wangc065da22012-11-14 15:57:07 -08002176###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08002177## Other includes
2178###########################################################
2179
2180# -----------------------------------------------------------------
2181# Rules and functions to help copy important files to DIST_DIR
2182# when requested.
2183include $(BUILD_SYSTEM)/distdir.mk
2184
Marie Lennerhagen9e5efce2010-10-20 13:41:59 +02002185# Include any vendor specific definitions.mk file
2186-include $(TOPDIR)vendor/*/build/core/definitions.mk
2187
The Android Open Source Project88b60792009-03-03 19:28:42 -08002188# broken:
2189# $(foreach file,$^,$(if $(findstring,.a,$(suffix $file)),-l$(file),$(file)))
2190
2191###########################################################
2192## Misc notes
2193###########################################################
2194
2195#DEPDIR = .deps
2196#df = $(DEPDIR)/$(*F)
2197
2198#SRCS = foo.c bar.c ...
2199
2200#%.o : %.c
2201# @$(MAKEDEPEND); \
2202# cp $(df).d $(df).P; \
2203# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
2204# -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \
2205# rm -f $(df).d
2206# $(COMPILE.c) -o $@ $<
2207
2208#-include $(SRCS:%.c=$(DEPDIR)/%.P)
2209
2210
2211#%.o : %.c
2212# $(COMPILE.c) -MD -o $@ $<
2213# @cp $*.d $*.P; \
2214# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
2215# -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \
2216# rm -f $*.d