blob: a07c7b11f353e6635481d081e8d4475975ff1c41 [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 :=
Ying Wang966c1e02014-05-20 14:43:51 -070087$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_DEPENDENCIES_ON_SHARED_LIBRARIES :=
Ying Wang9485a572013-02-22 14:32:30 -080088HOST_DEPENDENCIES_ON_SHARED_LIBRARIES :=
Ying Wang966c1e02014-05-20 14:43:51 -070089$(HOST_2ND_ARCH_VAR_PREFIX)HOST_DEPENDENCIES_ON_SHARED_LIBRARIES :=
Ying Wang9485a572013-02-22 14:32:30 -080090
Ying Wangae25ec12012-06-19 10:40:37 -070091# Generated class file names for Android resource.
92# They are escaped and quoted so can be passed safely to a bash command.
93ANDROID_RESOURCE_GENERATED_CLASSES := 'R.class' 'R$$*.class' 'Manifest.class' 'Manifest$$*.class'
94
The Android Open Source Project88b60792009-03-03 19:28:42 -080095###########################################################
96## Debugging; prints a variable list to stdout
97###########################################################
98
99# $(1): variable name list, not variable values
100define print-vars
101$(foreach var,$(1), \
102 $(info $(var):) \
103 $(foreach word,$($(var)), \
104 $(info $(space)$(space)$(word)) \
105 ) \
106 )
107endef
108
109###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700110## Evaluates to true if the string contains the word true,
111## and empty otherwise
112## $(1): a var to test
113###########################################################
114
115define true-or-empty
116$(filter true, $(1))
117endef
118
119
120###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800121## Retrieve the directory of the current makefile
Ying Wang3bbfddd2014-03-01 15:32:04 -0800122## Must be called before including any other makefile!!
The Android Open Source Project88b60792009-03-03 19:28:42 -0800123###########################################################
124
125# Figure out where we are.
126define my-dir
Dave Bortb3926412009-05-19 16:12:22 -0700127$(strip \
Ying Wang68f1c772012-04-23 21:29:18 -0700128 $(eval LOCAL_MODULE_MAKEFILE := $$(lastword $$(MAKEFILE_LIST))) \
Ying Wang3bbfddd2014-03-01 15:32:04 -0800129 $(if $(filter $(BUILD_SYSTEM)/% $(OUT_DIR)/%,$(LOCAL_MODULE_MAKEFILE)), \
130 $(error my-dir must be called before including any other makefile.) \
Dave Bortb3926412009-05-19 16:12:22 -0700131 , \
Ying Wang68f1c772012-04-23 21:29:18 -0700132 $(patsubst %/,%,$(dir $(LOCAL_MODULE_MAKEFILE))) \
Dave Bortb3926412009-05-19 16:12:22 -0700133 ) \
134 )
The Android Open Source Project88b60792009-03-03 19:28:42 -0800135endef
136
137###########################################################
138## Retrieve a list of all makefiles immediately below some directory
139###########################################################
140
141define all-makefiles-under
142$(wildcard $(1)/*/Android.mk)
143endef
144
145###########################################################
146## Look under a directory for makefiles that don't have parent
147## makefiles.
148###########################################################
149
150# $(1): directory to search under
151# Ignores $(1)/Android.mk
152define first-makefiles-under
C. Sean Youngcf469982015-06-09 12:35:45 -0500153$(shell build/tools/findleaves.py $(FIND_LEAVES_EXCLUDES) \
Joe Onoratodc1a7282009-08-04 15:58:26 -0400154 --mindepth=2 $(1) Android.mk)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800155endef
156
157###########################################################
158## Retrieve a list of all makefiles immediately below your directory
Ying Wang3bbfddd2014-03-01 15:32:04 -0800159## Must be called before including any other makefile!!
The Android Open Source Project88b60792009-03-03 19:28:42 -0800160###########################################################
161
162define all-subdir-makefiles
163$(call all-makefiles-under,$(call my-dir))
164endef
165
166###########################################################
167## Look in the named list of directories for makefiles,
168## relative to the current directory.
Ying Wang3bbfddd2014-03-01 15:32:04 -0800169## Must be called before including any other makefile!!
The Android Open Source Project88b60792009-03-03 19:28:42 -0800170###########################################################
171
172# $(1): List of directories to look for under this directory
173define all-named-subdir-makefiles
Chih-Wei Huange73c4bb2011-01-16 18:31:29 +0800174$(wildcard $(addsuffix /Android.mk, $(addprefix $(call my-dir)/,$(1))))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800175endef
176
177###########################################################
178## Find all of the java files under the named directories.
179## Meant to be used like:
180## SRC_FILES := $(call all-java-files-under,src tests)
181###########################################################
182
183define all-java-files-under
184$(patsubst ./%,%, \
185 $(shell cd $(LOCAL_PATH) ; \
Conley Owensf4357392012-10-02 10:32:00 -0700186 find -L $(1) -name "*.java" -and -not -name ".*") \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800187 )
188endef
189
190###########################################################
191## Find all of the java files from here. Meant to be used like:
192## SRC_FILES := $(call all-subdir-java-files)
193###########################################################
194
195define all-subdir-java-files
196$(call all-java-files-under,.)
197endef
198
199###########################################################
200## Find all of the c files under the named directories.
201## Meant to be used like:
202## SRC_FILES := $(call all-c-files-under,src tests)
203###########################################################
204
205define all-c-files-under
206$(patsubst ./%,%, \
207 $(shell cd $(LOCAL_PATH) ; \
Conley Owensf4357392012-10-02 10:32:00 -0700208 find -L $(1) -name "*.c" -and -not -name ".*") \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800209 )
210endef
211
212###########################################################
213## Find all of the c files from here. Meant to be used like:
214## SRC_FILES := $(call all-subdir-c-files)
215###########################################################
216
217define all-subdir-c-files
218$(call all-c-files-under,.)
219endef
220
221###########################################################
Dan Willemsend7b9ac72015-09-29 16:26:28 -0700222## Find all of the cpp files under the named directories.
223## LOCAL_CPP_EXTENSION is respected if set.
224## Meant to be used like:
225## SRC_FILES := $(call all-cpp-files-under,src tests)
226###########################################################
227
228define all-cpp-files-under
229$(sort $(patsubst ./%,%, \
230 $(shell cd $(LOCAL_PATH) ; \
231 find -L $(1) -name "*$(or $(LOCAL_CPP_EXTENSION),.cpp)" -and -not -name ".*") \
232 ))
233endef
234
235###########################################################
236## Find all of the cpp files from here. Meant to be used like:
237## SRC_FILES := $(call all-subdir-cpp-files)
238###########################################################
239
240define all-subdir-cpp-files
241$(call all-cpp-files-under,.)
242endef
243
244###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800245## Find all files named "I*.aidl" under the named directories,
246## which must be relative to $(LOCAL_PATH). The returned list
247## is relative to $(LOCAL_PATH).
248###########################################################
249
250define all-Iaidl-files-under
251$(patsubst ./%,%, \
252 $(shell cd $(LOCAL_PATH) ; \
Conley Owensf4357392012-10-02 10:32:00 -0700253 find -L $(1) -name "I*.aidl" -and -not -name ".*") \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800254 )
255endef
256
257###########################################################
258## Find all of the "I*.aidl" files under $(LOCAL_PATH).
259###########################################################
260
261define all-subdir-Iaidl-files
262$(call all-Iaidl-files-under,.)
263endef
264
265###########################################################
Bjorn Bringerta89c9902010-02-02 17:36:20 +0000266## Find all of the logtags files under the named directories.
267## Meant to be used like:
268## SRC_FILES := $(call all-logtags-files-under,src)
269###########################################################
270
271define all-logtags-files-under
272$(patsubst ./%,%, \
273 $(shell cd $(LOCAL_PATH) ; \
Conley Owensf4357392012-10-02 10:32:00 -0700274 find -L $(1) -name "*.logtags" -and -not -name ".*") \
Bjorn Bringerta89c9902010-02-02 17:36:20 +0000275 )
276endef
277
278###########################################################
Ying Wanga5fc87a2010-11-02 18:43:16 -0700279## Find all of the .proto files under the named directories.
280## Meant to be used like:
281## SRC_FILES := $(call all-proto-files-under,src)
282###########################################################
283
284define all-proto-files-under
285$(patsubst ./%,%, \
286 $(shell cd $(LOCAL_PATH) ; \
Conley Owensf4357392012-10-02 10:32:00 -0700287 find -L $(1) -name "*.proto" -and -not -name ".*") \
Ying Wanga5fc87a2010-11-02 18:43:16 -0700288 )
289endef
290
291###########################################################
Ying Wang0bd59a02010-07-15 17:17:52 -0700292## Find all of the RenderScript files under the named directories.
293## Meant to be used like:
294## SRC_FILES := $(call all-renderscript-files-under,src)
295###########################################################
296
297define all-renderscript-files-under
298$(patsubst ./%,%, \
299 $(shell cd $(LOCAL_PATH) ; \
Stephen Hinesd2637572012-10-11 22:08:57 -0700300 find -L $(1) \( -name "*.rs" -or -name "*.fs" \) -and -not -name ".*") \
Ying Wang0bd59a02010-07-15 17:17:52 -0700301 )
302endef
303
304###########################################################
Elliott Hughese3b044a2014-02-11 13:48:35 -0800305## Find all of the S files under the named directories.
306## Meant to be used like:
307## SRC_FILES := $(call all-c-files-under,src tests)
308###########################################################
309
310define all-S-files-under
311$(patsubst ./%,%, \
312 $(shell cd $(LOCAL_PATH) ; \
313 find -L $(1) -name "*.S" -and -not -name ".*") \
314 )
315endef
316
317###########################################################
Jean-Baptiste Queru0a3cfdc2009-12-17 17:47:28 -0800318## Find all of the html files under the named directories.
319## Meant to be used like:
320## SRC_FILES := $(call all-html-files-under,src tests)
321###########################################################
322
323define all-html-files-under
324$(patsubst ./%,%, \
325 $(shell cd $(LOCAL_PATH) ; \
Conley Owensf4357392012-10-02 10:32:00 -0700326 find -L $(1) -name "*.html" -and -not -name ".*") \
Jean-Baptiste Queru0a3cfdc2009-12-17 17:47:28 -0800327 )
328endef
329
330###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800331## Find all of the html files from here. Meant to be used like:
332## SRC_FILES := $(call all-subdir-html-files)
333###########################################################
334
335define all-subdir-html-files
Jean-Baptiste Queru0a3cfdc2009-12-17 17:47:28 -0800336$(call all-html-files-under,.)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800337endef
338
339###########################################################
340## Find all of the files matching pattern
341## SRC_FILES := $(call find-subdir-files, <pattern>)
342###########################################################
343
344define find-subdir-files
Conley Owensf4357392012-10-02 10:32:00 -0700345$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) ; find -L $(1)))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800346endef
347
348###########################################################
349# find the files in the subdirectory $1 of LOCAL_DIR
350# matching pattern $2, filtering out files $3
351# e.g.
352# SRC_FILES += $(call find-subdir-subdir-files, \
353# css, *.cpp, DontWantThis.cpp)
354###########################################################
355
356define find-subdir-subdir-files
357$(filter-out $(patsubst %,$(1)/%,$(3)),$(patsubst ./%,%,$(shell cd \
Conley Owensf4357392012-10-02 10:32:00 -0700358 $(LOCAL_PATH) ; find -L $(1) -maxdepth 1 -name $(2))))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800359endef
360
361###########################################################
362## Find all of the files matching pattern
363## SRC_FILES := $(call all-subdir-java-files)
364###########################################################
365
366define find-subdir-assets
367$(if $(1),$(patsubst ./%,%, \
Ying Wang6ab5d6a2011-08-10 16:05:51 -0700368 $(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 -0800369 $(warning Empty argument supplied to find-subdir-assets) \
370)
371endef
372
373###########################################################
374## Find various file types in a list of directories relative to $(LOCAL_PATH)
375###########################################################
376
377define find-other-java-files
378 $(call find-subdir-files,$(1) -name "*.java" -and -not -name ".*")
379endef
380
381define find-other-html-files
382 $(call find-subdir-files,$(1) -name "*.html" -and -not -name ".*")
383endef
384
385###########################################################
Ying Wang85898bc2013-12-04 16:04:49 -0800386# Use utility find to find given files in the given subdirs.
387# This function uses $(1), instead of LOCAL_PATH as the base.
388# $(1): the base dir, relative to the root of the source tree.
389# $(2): the file name pattern to be passed to find as "-name".
390# $(3): a list of subdirs of the base dir.
391# Returns: a list of paths relative to the base dir.
392###########################################################
393
394define find-files-in-subdirs
395$(patsubst ./%,%, \
396 $(shell cd $(1) ; \
397 find -L $(3) -name $(2) -and -not -name ".*") \
398 )
399endef
400
401###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800402## Scan through each directory of $(1) looking for files
403## that match $(2) using $(wildcard). Useful for seeing if
404## a given directory or one of its parents contains
405## a particular file. Returns the first match found,
406## starting furthest from the root.
407###########################################################
408
409define find-parent-file
410$(strip \
Ying Wanga67ce692011-03-03 13:29:38 -0800411 $(eval _fpf := $(wildcard $(foreach f, $(2), $(strip $(1))/$(f)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800412 $(if $(_fpf),$(_fpf), \
413 $(if $(filter-out ./ .,$(1)), \
414 $(call find-parent-file,$(patsubst %/,%,$(dir $(1))),$(2)) \
415 ) \
416 ) \
417)
418endef
419
420###########################################################
421## Function we can evaluate to introduce a dynamic dependency
422###########################################################
423
424define add-dependency
425$(1): $(2)
426endef
427
428###########################################################
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200429## Reverse order of a list
430###########################################################
431
432define reverse-list
433$(if $(1),$(call reverse-list,$(wordlist 2,$(words $(1)),$(1)))) $(firstword $(1))
434endef
435
436###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800437## The intermediates directory. Where object files go for
438## a given target. We could technically get away without
439## the "_intermediates" suffix on the directory, but it's
440## nice to be able to grep for that string to find out if
441## anyone's abusing the system.
442###########################################################
443
444# $(1): target class, like "APPS"
445# $(2): target name, like "NotePad"
446# $(3): if non-empty, this is a HOST target.
447# $(4): if non-empty, force the intermediates to be COMMON
Ying Wang61d499b2014-01-15 16:02:16 -0800448# $(5): if non-empty, force the intermedistes to be for the 2nd arch
The Android Open Source Project88b60792009-03-03 19:28:42 -0800449define intermediates-dir-for
450$(strip \
451 $(eval _idfClass := $(strip $(1))) \
452 $(if $(_idfClass),, \
453 $(error $(LOCAL_PATH): Class not defined in call to intermediates-dir-for)) \
454 $(eval _idfName := $(strip $(2))) \
455 $(if $(_idfName),, \
456 $(error $(LOCAL_PATH): Name not defined in call to intermediates-dir-for)) \
457 $(eval _idfPrefix := $(if $(strip $(3)),HOST,TARGET)) \
Colin Crossae2986e2014-06-17 21:35:44 -0700458 $(eval _idf2ndArchPrefix := $(if $(strip $(5)),$(TARGET_2ND_ARCH_VAR_PREFIX))) \
Ying Wanga83940f2010-09-24 18:09:04 -0700459 $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800460 $(eval _idfIntBase := $($(_idfPrefix)_OUT_COMMON_INTERMEDIATES)) \
Ying Wang6feb6d52014-04-17 10:03:35 -0700461 ,$(if $(filter $(_idfClass),SHARED_LIBRARIES STATIC_LIBRARIES EXECUTABLES GYP),\
Colin Cross02e31d22014-01-24 13:38:08 -0800462 $(eval _idfIntBase := $($(_idf2ndArchPrefix)$(_idfPrefix)_OUT_INTERMEDIATES)) \
463 ,$(eval _idfIntBase := $($(_idfPrefix)_OUT_INTERMEDIATES)) \
464 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800465 ) \
466 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
467)
468endef
469
470# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE
471# to determine the intermediates directory.
472#
473# $(1): if non-empty, force the intermediates to be COMMON
Ying Wang61d499b2014-01-15 16:02:16 -0800474# $(2): if non-empty, force the intermediates to be for the 2nd arch
The Android Open Source Project88b60792009-03-03 19:28:42 -0800475define local-intermediates-dir
476$(strip \
477 $(if $(strip $(LOCAL_MODULE_CLASS)),, \
478 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-intermediates-dir)) \
479 $(if $(strip $(LOCAL_MODULE)),, \
480 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-intermediates-dir)) \
Ying Wang61d499b2014-01-15 16:02:16 -0800481 $(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 -0800482)
483endef
484
485###########################################################
Colin Crossd8262642014-01-24 23:17:21 -0800486## The generated sources directory. Placing generated
487## source files directly in the intermediates directory
488## causes problems for multiarch builds, where there are
489## two intermediates directories for a single target. Put
490## them in a separate directory, and they will be copied to
491## each intermediates directory automatically.
492###########################################################
493
494# $(1): target class, like "APPS"
495# $(2): target name, like "NotePad"
496# $(3): if non-empty, this is a HOST target.
497# $(4): if non-empty, force the generated sources to be COMMON
498define generated-sources-dir-for
499$(strip \
500 $(eval _idfClass := $(strip $(1))) \
501 $(if $(_idfClass),, \
502 $(error $(LOCAL_PATH): Class not defined in call to generated-sources-dir-for)) \
503 $(eval _idfName := $(strip $(2))) \
504 $(if $(_idfName),, \
505 $(error $(LOCAL_PATH): Name not defined in call to generated-sources-dir-for)) \
506 $(eval _idfPrefix := $(if $(strip $(3)),HOST,TARGET)) \
507 $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
508 $(eval _idfIntBase := $($(_idfPrefix)_OUT_GEN_COMMON)) \
509 , \
510 $(eval _idfIntBase := $($(_idfPrefix)_OUT_GEN)) \
511 ) \
512 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
513)
514endef
515
516# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE
517# to determine the generated sources directory.
518#
519# $(1): if non-empty, force the intermediates to be COMMON
520define local-generated-sources-dir
521$(strip \
522 $(if $(strip $(LOCAL_MODULE_CLASS)),, \
523 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-generated-sources-dir)) \
524 $(if $(strip $(LOCAL_MODULE)),, \
525 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-generated-sources-dir)) \
526 $(call generated-sources-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(LOCAL_IS_HOST_MODULE),$(1)) \
527)
528endef
529
530###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800531## Convert "path/to/libXXX.so" to "-lXXX".
532## Any "path/to/libXXX.a" elements pass through unchanged.
533###########################################################
534
535define normalize-libraries
536$(foreach so,$(filter %.so,$(1)),-l$(patsubst lib%.so,%,$(notdir $(so))))\
537$(filter-out %.so,$(1))
538endef
539
540# TODO: change users to call the common version.
541define normalize-host-libraries
542$(call normalize-libraries,$(1))
543endef
544
545define normalize-target-libraries
546$(call normalize-libraries,$(1))
547endef
548
549###########################################################
550## Convert a list of short module names (e.g., "framework", "Browser")
551## into the list of files that are built for those modules.
552## NOTE: this won't return reliable results until after all
553## sub-makefiles have been included.
554## $(1): target list
555###########################################################
556
557define module-built-files
558$(foreach module,$(1),$(ALL_MODULES.$(module).BUILT))
559endef
560
561###########################################################
562## Convert a list of short modules names (e.g., "framework", "Browser")
563## into the list of files that are installed for those modules.
564## NOTE: this won't return reliable results until after all
565## sub-makefiles have been included.
566## $(1): target list
567###########################################################
568
569define module-installed-files
570$(foreach module,$(1),$(ALL_MODULES.$(module).INSTALLED))
571endef
572
573###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700574## Convert a list of short modules names (e.g., "framework", "Browser")
575## into the list of files that should be used when linking
576## against that module as a public API.
577## TODO: Allow this for more than JAVA_LIBRARIES modules
578## NOTE: this won't return reliable results until after all
579## sub-makefiles have been included.
580## $(1): target list
581###########################################################
582
583define module-stubs-files
584$(foreach module,$(1),$(ALL_MODULES.$(module).STUBS))
585endef
586
587###########################################################
588## Evaluates to the timestamp file for a doc module, which
589## is the dependency that should be used.
590## $(1): doc module
591###########################################################
592
593define doc-timestamp-for
594$(OUT_DOCS)/$(strip $(1))-timestamp
595endef
596
597
598###########################################################
Ying Wang912f8282010-09-28 17:27:56 -0700599## Convert "core ext framework" to "out/.../javalib.jar ..."
The Android Open Source Project88b60792009-03-03 19:28:42 -0800600## $(1): library list
601## $(2): Non-empty if IS_HOST_MODULE
602###########################################################
603
604# $(1): library name
605# $(2): Non-empty if IS_HOST_MODULE
606define _java-lib-dir
607$(call intermediates-dir-for, \
Ying Wang912f8282010-09-28 17:27:56 -0700608 JAVA_LIBRARIES,$(1),$(2),COMMON)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800609endef
610
611# $(1): library name
612# $(2): Non-empty if IS_HOST_MODULE
613define _java-lib-full-classes.jar
Ying Wang912f8282010-09-28 17:27:56 -0700614$(call _java-lib-dir,$(1),$(2))/classes$(COMMON_JAVA_PACKAGE_SUFFIX)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800615endef
616
617# $(1): library name list
618# $(2): Non-empty if IS_HOST_MODULE
619define java-lib-files
620$(foreach lib,$(1),$(call _java-lib-full-classes.jar,$(lib),$(2)))
621endef
622
623# $(1): library name
The Android Open Source Project88b60792009-03-03 19:28:42 -0800624# $(2): Non-empty if IS_HOST_MODULE
625define _java-lib-full-dep
Ying Wang833b4272015-01-21 17:30:21 -0800626$(call _java-lib-dir,$(1),$(2))/$(if $(2),javalib,classes)$(COMMON_JAVA_PACKAGE_SUFFIX)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800627endef
628
629# $(1): library name list
630# $(2): Non-empty if IS_HOST_MODULE
631define java-lib-deps
632$(foreach lib,$(1),$(call _java-lib-full-dep,$(lib),$(2)))
633endef
634
635###########################################################
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200636## Convert "core ext framework" to "out/.../classes.jack ..."
637## $(1): library list
638## $(2): Non-empty if IS_HOST_MODULE
639###########################################################
640
641# $(1): library name
642# $(2): Non-empty if IS_HOST_MODULE
643define _jack-lib-full-classes
644$(call _java-lib-dir,$(1),$(2))/classes.jack
645endef
646
647# $(1): library name list
648# $(2): Non-empty if IS_HOST_MODULE
649define jack-lib-files
650$(foreach lib,$(1),$(call _jack-lib-full-classes,$(lib),$(2)))
651endef
652
653# $(1): library name
654# $(2): Non-empty if IS_HOST_MODULE
655define _jack-lib-full-dep
656$(call _jack-lib-full-classes,$(1),$(2))
657endef
658
659# $(1): library name list
660# $(2): Non-empty if IS_HOST_MODULE
661define jack-lib-deps
662$(foreach lib,$(1),$(call _jack-lib-full-dep,$(lib),$(2)))
663endef
664
665###########################################################
Joe Onorato8dc8faa2010-09-14 13:09:48 -0400666## Run rot13 on a string
667## $(1): the string. Must be one line.
668###########################################################
669define rot13
670$(shell echo $(1) | tr 'a-zA-Z' 'n-za-mN-ZA-M')
671endef
672
673
674###########################################################
675## Returns true if $(1) and $(2) are equal. Returns
676## the empty string if they are not equal.
677###########################################################
678define streq
679$(strip $(if $(strip $(1)),\
680 $(if $(strip $(2)),\
681 $(if $(filter-out __,_$(subst $(strip $(1)),,$(strip $(2)))$(subst $(strip $(2)),,$(strip $(1)))_),,true), \
682 ),\
683 $(if $(strip $(2)),\
684 ,\
685 true)\
686 ))
687endef
688
689###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800690## Convert "a b c" into "a:b:c"
691###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800692define normalize-path-list
693$(subst $(space),:,$(strip $(1)))
694endef
695
696###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700697## Read the word out of a colon-separated list of words.
698## This has the same behavior as the built-in function
699## $(word n,str).
700##
701## The individual words may not contain spaces.
702##
703## $(1): 1 based index
704## $(2): value of the form a:b:c...
705###########################################################
706
707define word-colon
708$(word $(1),$(subst :,$(space),$(2)))
709endef
710
711###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800712## Convert "a=b c= d e = f" into "a=b c=d e=f"
713##
714## $(1): list to collapse
715## $(2): if set, separator word; usually "=", ":", or ":="
716## Defaults to "=" if not set.
717###########################################################
718
719define collapse-pairs
720$(eval _cpSEP := $(strip $(if $(2),$(2),=)))\
721$(subst $(space)$(_cpSEP)$(space),$(_cpSEP),$(strip \
722 $(subst $(_cpSEP), $(_cpSEP) ,$(1))))
723endef
724
The Android Open Source Project88b60792009-03-03 19:28:42 -0800725###########################################################
Ying Wang7e8d4422011-06-17 17:05:35 -0700726## Given a list of pairs, if multiple pairs have the same
727## first components, keep only the first pair.
728##
729## $(1): list of pairs
730## $(2): the separator word, such as ":", "=", etc.
731define uniq-pairs-by-first-component
732$(eval _upbfc_fc_set :=)\
733$(strip $(foreach w,$(1), $(eval _first := $(word 1,$(subst $(2),$(space),$(w))))\
734 $(if $(filter $(_upbfc_fc_set),$(_first)),,$(w)\
735 $(eval _upbfc_fc_set += $(_first)))))\
736$(eval _upbfc_fc_set :=)\
737$(eval _first:=)
738endef
739
740###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800741## MODULE_TAG set operations
742###########################################################
743
744# Given a list of tags, return the targets that specify
745# any of those tags.
746# $(1): tag list
747define modules-for-tag-list
Ying Wang634f7992014-11-18 12:41:53 -0800748$(sort $(foreach tag,$(1),$(foreach m,$(ALL_MODULE_NAME_TAGS.$(tag)),$(ALL_MODULES.$(m).INSTALLED))))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800749endef
750
751# Same as modules-for-tag-list, but operates on
752# ALL_MODULE_NAME_TAGS.
753# $(1): tag list
754define module-names-for-tag-list
755$(sort $(foreach tag,$(1),$(ALL_MODULE_NAME_TAGS.$(tag))))
756endef
757
758# Given an accept and reject list, find the matching
759# set of targets. If a target has multiple tags and
760# any of them are rejected, the target is rejected.
761# Reject overrides accept.
762# $(1): list of tags to accept
763# $(2): list of tags to reject
764#TODO(dbort): do $(if $(strip $(1)),$(1),$(ALL_MODULE_TAGS))
Jean-Baptiste Queru75127b72010-01-07 11:44:22 -0800765#TODO(jbq): as of 20100106 nobody uses the second parameter
The Android Open Source Project88b60792009-03-03 19:28:42 -0800766define get-tagged-modules
767$(filter-out \
768 $(call modules-for-tag-list,$(2)), \
769 $(call modules-for-tag-list,$(1)))
770endef
771
Joe Onorato64d85d02009-04-09 19:31:12 -0700772###########################################################
773## Append a leaf to a base path. Properly deals with
774## base paths ending in /.
775##
776## $(1): base path
777## $(2): leaf path
778###########################################################
779
780define append-path
781$(subst //,/,$(1)/$(2))
782endef
783
The Android Open Source Project88b60792009-03-03 19:28:42 -0800784
785###########################################################
786## Package filtering
787###########################################################
788
789# Given a list of installed modules (short or long names)
790# return a list of the packages (yes, .apk packages, not
791# modules in general) that are overridden by this list and,
792# therefore, should not be installed.
793# $(1): mixed list of installed modules
794# TODO: This is fragile; find a reliable way to get this information.
795define _get-package-overrides
796 $(eval ### Discard any words containing slashes, unless they end in .apk, \
797 ### in which case trim off the directory component and the suffix. \
798 ### If there are no slashes, keep the entire word.)
799 $(eval _gpo_names := $(subst /,@@@ @@@,$(1)))
800 $(eval _gpo_names := \
801 $(filter %.apk,$(_gpo_names)) \
802 $(filter-out %@@@ @@@%,$(_gpo_names)))
803 $(eval _gpo_names := $(patsubst %.apk,%,$(_gpo_names)))
804 $(eval _gpo_names := $(patsubst @@@%,%,$(_gpo_names)))
805
806 $(eval ### Remove any remaining words that contain dots.)
807 $(eval _gpo_names := $(subst .,@@@ @@@,$(_gpo_names)))
808 $(eval _gpo_names := $(filter-out %@@@ @@@%,$(_gpo_names)))
809
810 $(eval ### Now we have a list of any words that could possibly refer to \
811 ### packages, although there may be words that do not. Only \
812 ### real packages will be present under PACKAGES.*, though.)
813 $(foreach _gpo_name,$(_gpo_names),$(PACKAGES.$(_gpo_name).OVERRIDES))
814endef
815
816define get-package-overrides
Conley Owensd7a1a9b2011-12-22 09:46:19 -0800817$(sort $(strip $(call _get-package-overrides,$(1))))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800818endef
819
820###########################################################
821## Output the command lines, or not
822###########################################################
823
824ifeq ($(strip $(SHOW_COMMANDS)),)
825define pretty
826@echo $1
827endef
828hide := @
829else
830define pretty
831endef
832hide :=
833endif
834
835###########################################################
836## Dump the variables that are associated with targets
837###########################################################
838
839define dump-module-variables
840@echo all_dependencies=$^
841@echo PRIVATE_YACCFLAGS=$(PRIVATE_YACCFLAGS);
842@echo PRIVATE_CFLAGS=$(PRIVATE_CFLAGS);
843@echo PRIVATE_CPPFLAGS=$(PRIVATE_CPPFLAGS);
844@echo PRIVATE_DEBUG_CFLAGS=$(PRIVATE_DEBUG_CFLAGS);
845@echo PRIVATE_C_INCLUDES=$(PRIVATE_C_INCLUDES);
846@echo PRIVATE_LDFLAGS=$(PRIVATE_LDFLAGS);
847@echo PRIVATE_LDLIBS=$(PRIVATE_LDLIBS);
848@echo PRIVATE_ARFLAGS=$(PRIVATE_ARFLAGS);
849@echo PRIVATE_AAPT_FLAGS=$(PRIVATE_AAPT_FLAGS);
850@echo PRIVATE_DX_FLAGS=$(PRIVATE_DX_FLAGS);
Brian Carlstromf184a0f2010-02-01 11:13:32 -0800851@echo PRIVATE_JAVACFLAGS=$(PRIVATE_JAVACFLAGS);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800852@echo PRIVATE_JAVA_LIBRARIES=$(PRIVATE_JAVA_LIBRARIES);
853@echo PRIVATE_ALL_SHARED_LIBRARIES=$(PRIVATE_ALL_SHARED_LIBRARIES);
854@echo PRIVATE_ALL_STATIC_LIBRARIES=$(PRIVATE_ALL_STATIC_LIBRARIES);
855@echo PRIVATE_ALL_WHOLE_STATIC_LIBRARIES=$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES);
856@echo PRIVATE_ALL_OBJECTS=$(PRIVATE_ALL_OBJECTS);
Jeff Brown703e7c62011-02-04 20:15:00 -0800857@echo PRIVATE_NO_CRT=$(PRIVATE_NO_CRT);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800858endef
859
860###########################################################
861## Commands for using sed to replace given variable values
862###########################################################
863
864define transform-variables
865@mkdir -p $(dir $@)
866@echo "Sed: $(if $(PRIVATE_MODULE),$(PRIVATE_MODULE),$@) <= $<"
867$(hide) sed $(foreach var,$(REPLACE_VARS),-e "s/{{$(var)}}/$(subst /,\/,$(PWD)/$($(var)))/g") $< >$@
868$(hide) if [ "$(suffix $@)" = ".sh" ]; then chmod a+rx $@; fi
869endef
870
871
872###########################################################
873## Commands for munging the dependency files GCC generates
874###########################################################
Ying Wangc23f4ef2012-09-07 17:04:06 -0700875# $(1): the input .d file
876# $(2): the output .P file
877define transform-d-to-p-args
878$(hide) cp $(1) $(2); \
879 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
880 -e '/^$$/ d' -e 's/$$/ :/' < $(1) >> $(2); \
881 rm -f $(1)
882endef
The Android Open Source Project88b60792009-03-03 19:28:42 -0800883
884define transform-d-to-p
Ying Wangc23f4ef2012-09-07 17:04:06 -0700885$(call transform-d-to-p-args,$(@:%.o=%.d),$(@:%.o=%.P))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800886endef
887
888###########################################################
889## Commands for running lex
890###########################################################
891
892define transform-l-to-cpp
893@mkdir -p $(dir $@)
894@echo "Lex: $(PRIVATE_MODULE) <= $<"
895$(hide) $(LEX) -o$@ $<
896endef
897
898###########################################################
899## Commands for running yacc
900##
901## Because the extension of c++ files can change, the
902## extension must be specified in $1.
903## E.g, "$(call transform-y-to-cpp,.cpp)"
904###########################################################
905
906define transform-y-to-cpp
907@mkdir -p $(dir $@)
908@echo "Yacc: $(PRIVATE_MODULE) <= $<"
909$(YACC) $(PRIVATE_YACCFLAGS) -o $@ $<
910touch $(@:$1=$(YACC_HEADER_SUFFIX))
911echo '#ifndef '$(@F:$1=_h) > $(@:$1=.h)
912echo '#define '$(@F:$1=_h) >> $(@:$1=.h)
913cat $(@:$1=$(YACC_HEADER_SUFFIX)) >> $(@:$1=.h)
914echo '#endif' >> $(@:$1=.h)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800915endef
916
Ying Wang0bd59a02010-07-15 17:17:52 -0700917###########################################################
Tim Murraya7aa8002012-10-29 16:06:00 -0700918## Commands to compile RenderScript to Java
Ying Wang0bd59a02010-07-15 17:17:52 -0700919###########################################################
Ying Wang0bd59a02010-07-15 17:17:52 -0700920
921define transform-renderscripts-to-java-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)/res/raw
925$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/src
Ying Wang7d83ef82011-05-25 17:16:22 -0700926$(hide) $(PRIVATE_RS_CC) \
Ying Wangebfddaa2010-07-30 18:37:29 -0700927 -o $(PRIVATE_RS_OUTPUT_DIR)/res/raw \
928 -p $(PRIVATE_RS_OUTPUT_DIR)/src \
Ying Wang24e1c012010-10-07 18:57:57 -0700929 -d $(PRIVATE_RS_OUTPUT_DIR) \
930 -a $@ -MD \
Stephen Hinesc963eae2011-08-10 13:53:05 -0700931 $(addprefix -target-api , $(PRIVATE_RS_TARGET_API)) \
Stephen Hines914f7a22011-12-06 18:43:24 -0800932 $(PRIVATE_RS_FLAGS) \
Ying Wang51280272010-09-01 13:28:52 -0700933 $(foreach inc,$(PRIVATE_RS_INCLUDES),$(addprefix -I , $(inc))) \
Ying Wangebfddaa2010-07-30 18:37:29 -0700934 $(PRIVATE_RS_SOURCE_FILES)
Ying Wangb9319562015-04-03 16:15:28 -0700935 $(foreach d,$(PRIVATE_DEP_FILES),\
936 $(call transform-d-to-p-args,$(d),$(d:%.d=%.P))$(newline))
Ying Wang0bd59a02010-07-15 17:17:52 -0700937$(hide) mkdir -p $(dir $@)
938$(hide) touch $@
939endef
940
Stephen Hinese719f282012-11-28 16:52:41 -0800941define transform-bc-to-so
Stephen Hines9ac9b532013-02-27 00:51:08 -0800942@echo "Renderscript compatibility: $(notdir $@) <= $(notdir $<)"
Stephen Hinese719f282012-11-28 16:52:41 -0800943$(hide) mkdir -p $(dir $@)
Stephen Hinesf6925132012-12-17 14:23:14 -0800944$(hide) $(BCC_COMPAT) -O3 -o $(dir $@)/$(notdir $(<:.bc=.o)) -fPIC -shared \
Stephen Hines52626d22014-09-02 19:09:35 -0700945 -rt-path $(RS_PREBUILT_CLCORE) -mtriple $(RS_COMPAT_TRIPLE) $<
Stephen Hines7d6ec712012-12-13 19:24:50 -0800946$(hide) $(PRIVATE_CXX) -shared -Wl,-soname,$(notdir $@) -nostdlib \
Stephen Hinesf6925132012-12-17 14:23:14 -0800947 -Wl,-rpath,\$$ORIGIN/../lib \
Stephen Hines9541f582013-01-18 16:27:23 -0800948 $(dir $@)/$(notdir $(<:.bc=.o)) \
Tim Murray1a6f09a2013-03-05 11:07:15 -0800949 $(RS_PREBUILT_COMPILER_RT) \
Miao Wange23e8082014-11-15 14:25:33 -0800950 -o $@ $(TARGET_GLOBAL_LDFLAGS) -Wl,--hash-style=sysv -L prebuilts/gcc/ \
Ying Wangbfc43692015-03-05 11:29:30 -0800951 $(RS_PREBUILT_LIBPATH) -L $(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
Stephen Hines8db4cce2013-03-27 16:51:38 -0700952 -lRSSupport -lm -lc
Stephen Hinese719f282012-11-28 16:52:41 -0800953endef
954
Tim Murraya7aa8002012-10-29 16:06:00 -0700955###########################################################
956## Commands to compile RenderScript to C++
957###########################################################
958
959define transform-renderscripts-to-cpp-and-bc
960@echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)"
961$(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR)
962$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/
963$(hide) $(PRIVATE_RS_CC) \
964 -o $(PRIVATE_RS_OUTPUT_DIR)/ \
965 -d $(PRIVATE_RS_OUTPUT_DIR) \
966 -a $@ -MD \
967 -reflect-c++ \
968 $(PRIVATE_RS_FLAGS) \
Ying Wang81ab8332014-05-28 16:17:09 -0700969 $(addprefix -I , $(PRIVATE_RS_INCLUDES)) \
Tim Murraya7aa8002012-10-29 16:06:00 -0700970 $(PRIVATE_RS_SOURCE_FILES)
Ying Wangb9319562015-04-03 16:15:28 -0700971 $(foreach d,$(PRIVATE_DEP_FILES),\
972 $(call transform-d-to-p-args,$(d),$(d:%.d=%.P))$(newline))
Tim Murraya7aa8002012-10-29 16:06:00 -0700973$(hide) mkdir -p $(dir $@)
974$(hide) touch $@
975endef
976
The Android Open Source Project88b60792009-03-03 19:28:42 -0800977
978###########################################################
979## Commands for running aidl
980###########################################################
981
982define transform-aidl-to-java
983@mkdir -p $(dir $@)
984@echo "Aidl: $(PRIVATE_MODULE) <= $<"
985$(hide) $(AIDL) -d$(patsubst %.java,%.P,$@) $(PRIVATE_AIDL_FLAGS) $< $@
986endef
987#$(AIDL) $(PRIVATE_AIDL_FLAGS) $< - | indent -nut -br -npcs -l1000 > $@
988
989
Doug Zongker9bd49622009-11-30 14:28:59 -0800990###########################################################
991## Commands for running java-event-log-tags.py
992###########################################################
993
994define transform-logtags-to-java
995@mkdir -p $(dir $@)
996@echo "logtags: $@ <= $<"
Doug Zongkerabfbbe22010-02-16 14:32:08 -0800997$(hide) $(JAVATAGS) -o $@ $^
Doug Zongker9bd49622009-11-30 14:28:59 -0800998endef
999
The Android Open Source Project88b60792009-03-03 19:28:42 -08001000
1001###########################################################
Ying Wanga5fc87a2010-11-02 18:43:16 -07001002## Commands for running protoc to compile .proto into .java
1003###########################################################
1004
1005define transform-proto-to-java
1006@mkdir -p $(dir $@)
1007@echo "Protoc: $@ <= $(PRIVATE_PROTO_SRC_FILES)"
1008@rm -rf $(PRIVATE_PROTO_JAVA_OUTPUT_DIR)
1009@mkdir -p $(PRIVATE_PROTO_JAVA_OUTPUT_DIR)
Ben Murdochfc2bad52013-07-25 11:44:53 +01001010$(hide) for f in $(PRIVATE_PROTO_SRC_FILES); do \
1011 $(PROTOC) \
Ulas Kirazci28b46fc2013-07-24 14:32:14 -07001012 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
Ulas Kirazci6e485b52013-07-25 12:28:19 -07001013 $(PRIVATE_PROTO_JAVA_OUTPUT_OPTION)="$(PRIVATE_PROTO_JAVA_OUTPUT_PARAMS):$(PRIVATE_PROTO_JAVA_OUTPUT_DIR)" \
Ben Murdochfc2bad52013-07-25 11:44:53 +01001014 $(PRIVATE_PROTOC_FLAGS) \
1015 $$f || exit 33; \
1016 done
Ying Wanga5fc87a2010-11-02 18:43:16 -07001017$(hide) touch $@
1018endef
1019
1020######################################################################
Ying Wangfaeb6932015-04-07 11:59:34 -07001021## Commands for running protoc to compile .proto into .pb.cc (or.pb.c) and .pb.h
Ying Wanga5fc87a2010-11-02 18:43:16 -07001022######################################################################
1023define transform-proto-to-cc
1024@mkdir -p $(dir $@)
1025@echo "Protoc: $@ <= $<"
1026$(hide) $(PROTOC) \
1027 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
Ying Wang33c0d952010-11-05 11:30:58 -07001028 $(PRIVATE_PROTOC_FLAGS) \
Ying Wangfaeb6932015-04-07 11:59:34 -07001029 $<
Wink Saville042d4dc2014-05-06 15:45:57 -07001030endef
Ying Wanga5fc87a2010-11-02 18:43:16 -07001031
1032###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001033## Commands for running gcc to compile a C++ file
1034###########################################################
1035
1036define transform-cpp-to-o
1037@mkdir -p $(dir $@)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301038@echo -e ${CL_GRN}"target $(PRIVATE_ARM_MODE) C++:"${CL_RST}" $(PRIVATE_MODULE) <= $<"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001039$(hide) $(PRIVATE_CXX) \
Ying Wangddbcad82011-04-18 11:45:44 -07001040 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Andrew Boie85f3b212012-07-11 12:14:56 -07001041 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
Ying Wang4761e562011-04-12 11:06:35 -07001042 $(addprefix -isystem ,\
1043 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1044 $(filter-out $(PRIVATE_C_INCLUDES), \
Ying Wangddbcad82011-04-18 11:45:44 -07001045 $(PRIVATE_TARGET_PROJECT_INCLUDES) \
Ying Wang4761e562011-04-12 11:06:35 -07001046 $(PRIVATE_TARGET_C_INCLUDES)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001047 -c \
1048 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -07001049 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
1050 $(PRIVATE_TARGET_GLOBAL_CPPFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001051 $(PRIVATE_ARM_CFLAGS) \
1052 ) \
Doug Kwan9a8ecf92011-05-10 21:50:58 -07001053 $(PRIVATE_RTTI_FLAG) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001054 $(PRIVATE_CFLAGS) \
1055 $(PRIVATE_CPPFLAGS) \
1056 $(PRIVATE_DEBUG_CFLAGS) \
Dan Albert0c91fa82015-02-21 12:45:26 -08001057 $(GLOBAL_CFLAGS_NO_OVERRIDE) \
1058 $(GLOBAL_CPPFLAGS_NO_OVERRIDE) \
Atte Peltomaki60fe9632011-12-21 09:24:09 -08001059 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001060$(transform-d-to-p)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001061endef
1062
1063
1064###########################################################
1065## Commands for running gcc to compile a C file
1066###########################################################
1067
1068# $(1): extra flags
1069define transform-c-or-s-to-o-no-deps
1070@mkdir -p $(dir $@)
1071$(hide) $(PRIVATE_CC) \
Ying Wangddbcad82011-04-18 11:45:44 -07001072 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Andrew Boie85f3b212012-07-11 12:14:56 -07001073 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
Ying Wang4761e562011-04-12 11:06:35 -07001074 $(addprefix -isystem ,\
1075 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1076 $(filter-out $(PRIVATE_C_INCLUDES), \
Ying Wangddbcad82011-04-18 11:45:44 -07001077 $(PRIVATE_TARGET_PROJECT_INCLUDES) \
Ying Wang4761e562011-04-12 11:06:35 -07001078 $(PRIVATE_TARGET_C_INCLUDES)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001079 -c \
1080 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -07001081 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
Stephen Hines15680292014-11-26 00:53:46 -08001082 $(PRIVATE_TARGET_GLOBAL_CONLYFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001083 $(PRIVATE_ARM_CFLAGS) \
1084 ) \
Ying Wang65d78522012-08-10 16:30:42 -07001085 $(1) \
Atte Peltomaki60fe9632011-12-21 09:24:09 -08001086 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
The Android Open Source Project88b60792009-03-03 19:28:42 -08001087endef
1088
1089define transform-c-to-o-no-deps
Chirayu Desaiad48df42012-10-13 13:05:29 +05301090@echo -e ${CL_GRN}"target $(PRIVATE_ARM_MODE) C:"${CL_RST}" $(PRIVATE_MODULE) <= $<"
Dan Albert0c91fa82015-02-21 12:45:26 -08001091$(call transform-c-or-s-to-o-no-deps, \
1092 $(PRIVATE_CFLAGS) \
1093 $(PRIVATE_CONLYFLAGS) \
1094 $(PRIVATE_DEBUG_CFLAGS) \
1095 $(GLOBAL_CFLAGS_NO_OVERRIDE))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001096endef
1097
1098define transform-s-to-o-no-deps
Chirayu Desaiad48df42012-10-13 13:05:29 +05301099@echo -e ${CL_GRN}"target asm:"${CL_RST}" $(PRIVATE_MODULE) <= $<"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001100$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
1101endef
1102
1103define transform-c-to-o
1104$(transform-c-to-o-no-deps)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001105$(transform-d-to-p)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001106endef
1107
1108define transform-s-to-o
1109$(transform-s-to-o-no-deps)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001110$(transform-d-to-p)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001111endef
1112
Ying Wang7b913ce2014-06-05 19:05:47 -07001113# YASM compilation
1114define transform-asm-to-o
1115@mkdir -p $(dir $@)
1116$(hide) $(YASM) \
1117 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Ying Wangfe1e5c32015-03-09 18:57:40 -07001118 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_YASM_FLAGS) \
Ying Wang7b913ce2014-06-05 19:05:47 -07001119 $(PRIVATE_ASFLAGS) \
1120 -o $@ $<
1121endef
1122
The Android Open Source Project88b60792009-03-03 19:28:42 -08001123###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001124## Commands for running gcc to compile an Objective-C file
1125## This should never happen for target builds but this
1126## will error at build time.
1127###########################################################
1128
1129define transform-m-to-o-no-deps
Chirayu Desaiad48df42012-10-13 13:05:29 +05301130@echo -e ${CL_GRN}"target ObjC:"${CL_RST}" $(PRIVATE_MODULE) <= $<"
Ying Wang65d78522012-08-10 16:30:42 -07001131$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_DEBUG_CFLAGS))
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001132endef
1133
1134define transform-m-to-o
1135$(transform-m-to-o-no-deps)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001136$(transform-d-to-p)
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001137endef
1138
1139###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001140## Commands for running gcc to compile a host C++ file
1141###########################################################
1142
1143define transform-host-cpp-to-o
1144@mkdir -p $(dir $@)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301145@echo -e ${CL_YLW}"host C++:"${CL_RST}" $(PRIVATE_MODULE) <= $<"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001146$(hide) $(PRIVATE_CXX) \
Ying Wangddbcad82011-04-18 11:45:44 -07001147 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Andrew Boie85f3b212012-07-11 12:14:56 -07001148 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
Ying Wangddbcad82011-04-18 11:45:44 -07001149 $(addprefix -isystem ,\
The Android Open Source Project88b60792009-03-03 19:28:42 -08001150 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wangddbcad82011-04-18 11:45:44 -07001151 $(filter-out $(PRIVATE_C_INCLUDES), \
1152 $(HOST_PROJECT_INCLUDES) \
Logan Chiene6f65432013-12-10 19:07:41 +08001153 $(PRIVATE_HOST_C_INCLUDES)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001154 -c \
1155 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001156 $(PRIVATE_HOST_GLOBAL_CFLAGS) \
1157 $(PRIVATE_HOST_GLOBAL_CPPFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001158 ) \
1159 $(PRIVATE_CFLAGS) \
1160 $(PRIVATE_CPPFLAGS) \
1161 $(PRIVATE_DEBUG_CFLAGS) \
Atte Peltomaki60fe9632011-12-21 09:24:09 -08001162 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
The Android Open Source Project88b60792009-03-03 19:28:42 -08001163$(transform-d-to-p)
1164endef
1165
1166
1167###########################################################
1168## Commands for running gcc to compile a host C file
1169###########################################################
1170
1171# $(1): extra flags
1172define transform-host-c-or-s-to-o-no-deps
1173@mkdir -p $(dir $@)
1174$(hide) $(PRIVATE_CC) \
Ying Wangddbcad82011-04-18 11:45:44 -07001175 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Andrew Boie85f3b212012-07-11 12:14:56 -07001176 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
Ying Wangddbcad82011-04-18 11:45:44 -07001177 $(addprefix -isystem ,\
The Android Open Source Project88b60792009-03-03 19:28:42 -08001178 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wangddbcad82011-04-18 11:45:44 -07001179 $(filter-out $(PRIVATE_C_INCLUDES), \
1180 $(HOST_PROJECT_INCLUDES) \
Logan Chiene6f65432013-12-10 19:07:41 +08001181 $(PRIVATE_HOST_C_INCLUDES)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001182 -c \
1183 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001184 $(PRIVATE_HOST_GLOBAL_CFLAGS) \
Stephen Hines15680292014-11-26 00:53:46 -08001185 $(PRIVATE_HOST_GLOBAL_CONLYFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001186 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001187 $(1) \
Atte Peltomaki60fe9632011-12-21 09:24:09 -08001188 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
The Android Open Source Project88b60792009-03-03 19:28:42 -08001189endef
1190
1191define transform-host-c-to-o-no-deps
Chirayu Desaiad48df42012-10-13 13:05:29 +05301192@echo -e ${CL_YLW}"host C:"${CL_RST}" $(PRIVATE_MODULE) <= $<"
Ying Wang7429e212012-08-15 10:59:10 -07001193$(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 -08001194endef
1195
1196define transform-host-s-to-o-no-deps
Chirayu Desaiad48df42012-10-13 13:05:29 +05301197@echo -e ${CL_YLW}"host asm:"${CL_RST}" $(PRIVATE_MODULE) <= $<"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001198$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
1199endef
1200
1201define transform-host-c-to-o
1202$(transform-host-c-to-o-no-deps)
1203$(transform-d-to-p)
1204endef
1205
1206define transform-host-s-to-o
1207$(transform-host-s-to-o-no-deps)
1208$(transform-d-to-p)
1209endef
1210
1211###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001212## Commands for running gcc to compile a host Objective-C file
1213###########################################################
1214
1215define transform-host-m-to-o-no-deps
Chirayu Desaiad48df42012-10-13 13:05:29 +05301216@echo -e ${CL_YLW}"host ObjC:"${CL_RST}" $(PRIVATE_MODULE) <= $<"
Ying Wang65d78522012-08-10 16:30:42 -07001217$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_DEBUG_CFLAGS))
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001218endef
1219
David 'Digit' Turner5ca286d2011-02-11 16:19:31 +01001220define transform-host-m-to-o
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001221$(transform-host-m-to-o-no-deps)
1222$(transform-d-to-p)
1223endef
1224
Ying Wangfb22a422015-03-10 18:03:11 -07001225
1226###########################################################
1227## Rules to compile a single C/C++ source with ../ in the path
1228###########################################################
1229# Replace "../" in object paths with $(DOTDOT_REPLACEMENT).
1230DOTDOT_REPLACEMENT := dotdot/
1231
1232## Rule to compile a C++ source file with ../ in the path.
1233## Must be called with $(eval).
1234# $(1): the C++ source file in LOCAL_SRC_FILES.
1235# $(2): the additional dependencies.
1236# $(3): the variable name to collect the output object file.
1237define compile-dotdot-cpp-file
1238o := $(intermediates)/$(patsubst %$(LOCAL_CPP_EXTENSION),%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
1239$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2)
1240 $$(transform-$$(PRIVATE_HOST)cpp-to-o)
1241-include $$(o:%.o=%.P)
1242$(3) += $$(o)
1243endef
1244
1245## Rule to compile a C source file with ../ in the path.
1246## Must be called with $(eval).
1247# $(1): the C source file in LOCAL_SRC_FILES.
1248# $(2): the additional dependencies.
1249# $(3): the variable name to collect the output object file.
1250define compile-dotdot-c-file
1251o := $(intermediates)/$(patsubst %.c,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
1252$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2)
1253 $$(transform-$$(PRIVATE_HOST)c-to-o)
1254-include $$(o:%.o=%.P)
1255$(3) += $$(o)
1256endef
1257
1258## Rule to compile a .S source file with ../ in the path.
1259## Must be called with $(eval).
1260# $(1): the .S source file in LOCAL_SRC_FILES.
1261# $(2): the additional dependencies.
1262# $(3): the variable name to collect the output object file.
1263define compile-dotdot-s-file
1264o := $(intermediates)/$(patsubst %.S,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
1265$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2)
1266 $$(transform-$$(PRIVATE_HOST)s-to-o)
1267-include $$(o:%.o=%.P)
1268$(3) += $$(o)
1269endef
1270
1271## Rule to compile a .s source file with ../ in the path.
1272## Must be called with $(eval).
1273# $(1): the .s source file in LOCAL_SRC_FILES.
1274# $(2): the additional dependencies.
1275# $(3): the variable name to collect the output object file.
1276define compile-dotdot-s-file-no-deps
1277o := $(intermediates)/$(patsubst %.s,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
1278$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2)
1279 $$(transform-$$(PRIVATE_HOST)s-to-o-no-deps)
1280$(3) += $$(o)
1281endef
1282
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001283###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001284## Commands for running ar
1285###########################################################
1286
Ying Wange4b24eb2010-05-27 11:55:39 -07001287define _concat-if-arg2-not-empty
1288$(if $(2),$(hide) $(1) $(2))
1289endef
1290
1291# Split long argument list into smaller groups and call the command repeatedly
Torne (Richard Coles)bffaef22012-06-15 16:03:52 +01001292# Call the command at least once even if there are no arguments, as otherwise
1293# the output file won't be created.
Ying Wange4b24eb2010-05-27 11:55:39 -07001294#
1295# $(1): the command without arguments
1296# $(2): the arguments
1297define split-long-arguments
Torne (Richard Coles)bffaef22012-06-15 16:03:52 +01001298$(hide) $(1) $(wordlist 1,500,$(2))
Ying Wange4b24eb2010-05-27 11:55:39 -07001299$(call _concat-if-arg2-not-empty,$(1),$(wordlist 501,1000,$(2)))
1300$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1001,1500,$(2)))
1301$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1501,2000,$(2)))
1302$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2001,2500,$(2)))
1303$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2501,3000,$(2)))
1304$(call _concat-if-arg2-not-empty,$(1),$(wordlist 3001,99999,$(2)))
1305endef
1306
Ying Wanga02d3d92011-01-27 18:48:00 -08001307# $(1): the full path of the source static library.
1308define _extract-and-include-single-target-whole-static-lib
Chirayu Desaiad48df42012-10-13 13:05:29 +05301309@echo -e ${CL_YLW}"preparing StaticLib:"${CL_RST}" $(PRIVATE_MODULE) [including $(1)]"
Ying Wanga02d3d92011-01-27 18:48:00 -08001310$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\
1311 rm -rf $$ldir; \
1312 mkdir -p $$ldir; \
Christopher Ferris44203f32015-01-07 17:14:03 -08001313 cp $(1) $$ldir; \
1314 lib_to_include=$$ldir/$(notdir $(1)); \
Ying Wanga02d3d92011-01-27 18:48:00 -08001315 filelist=; \
Christopher Ferris44203f32015-01-07 17:14:03 -08001316 subdir=0; \
Ying Wang6feb6d52014-04-17 10:03:35 -07001317 for f in `$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) t $(1)`; do \
Christopher Ferris44203f32015-01-07 17:14:03 -08001318 if [ -e $$ldir/$$f ]; then \
1319 mkdir $$ldir/$$subdir; \
1320 ext=$$subdir/; \
1321 subdir=$$((subdir+1)); \
1322 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) m $$lib_to_include $$f; \
1323 else \
1324 ext=; \
1325 fi; \
1326 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) p $$lib_to_include $$f > $$ldir/$$ext$$f; \
1327 filelist="$$filelist $$ldir/$$ext$$f"; \
Ying Wanga02d3d92011-01-27 18:48:00 -08001328 done ; \
Ying Wang61d499b2014-01-15 16:02:16 -08001329 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \
1330 $(PRIVATE_ARFLAGS) $@ $$filelist
Ying Wanga02d3d92011-01-27 18:48:00 -08001331
1332endef
1333
Dan Alberte0f44ac2014-05-23 12:26:51 -07001334# $(1): the full path of the source static library.
1335define extract-and-include-whole-static-libs-first
1336$(if $(strip $(1)),
1337@echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(strip $(1))]"
1338$(hide) cp $(1) $@)
1339endef
1340
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001341define extract-and-include-target-whole-static-libs
Dan Alberte0f44ac2014-05-23 12:26:51 -07001342$(call extract-and-include-whole-static-libs-first, $(firstword $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)))
1343$(foreach lib,$(wordlist 2,999,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)), \
Ying Wanga02d3d92011-01-27 18:48:00 -08001344 $(call _extract-and-include-single-target-whole-static-lib, $(lib)))
Dima Zavin46e9bec2009-05-27 19:41:07 -07001345endef
1346
The Android Open Source Project88b60792009-03-03 19:28:42 -08001347# Explicitly delete the archive first so that ar doesn't
1348# try to add to an existing archive.
1349define transform-o-to-static-lib
1350@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001351@rm -f $@
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001352$(extract-and-include-target-whole-static-libs)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301353@echo -e ${CL_GRN}"target StaticLib:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Ying Wang6feb6d52014-04-17 10:03:35 -07001354$(call split-long-arguments,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) \
1355 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \
Ying Wang854607e2015-04-02 18:02:33 -07001356 $(PRIVATE_ARFLAGS) $@,$(PRIVATE_ALL_OBJECTS))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001357endef
1358
1359###########################################################
1360## Commands for running host ar
1361###########################################################
1362
Ying Wanga02d3d92011-01-27 18:48:00 -08001363# $(1): the full path of the source static library.
1364define _extract-and-include-single-host-whole-static-lib
Chirayu Desaiad48df42012-10-13 13:05:29 +05301365@echo -e ${CL_YLW}"preparing StaticLib:"${CL_RST}" $(PRIVATE_MODULE) [including $(1)]"
Ying Wanga02d3d92011-01-27 18:48:00 -08001366$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\
1367 rm -rf $$ldir; \
1368 mkdir -p $$ldir; \
Christopher Ferris44203f32015-01-07 17:14:03 -08001369 cp $(1) $$ldir; \
1370 lib_to_include=$$ldir/$(notdir $(1)); \
Ying Wanga02d3d92011-01-27 18:48:00 -08001371 filelist=; \
Christopher Ferris44203f32015-01-07 17:14:03 -08001372 subdir=0; \
Ying Wang6feb6d52014-04-17 10:03:35 -07001373 for f in `$($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_AR) t $(1) | \grep '\.o$$'`; do \
Christopher Ferris44203f32015-01-07 17:14:03 -08001374 if [ -e $$ldir/$$f ]; then \
1375 mkdir $$ldir/$$subdir; \
1376 ext=$$subdir/; \
1377 subdir=$$((subdir+1)); \
1378 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_AR) m $$lib_to_include $$f; \
1379 else \
1380 ext=; \
1381 fi; \
1382 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_AR) p $$lib_to_include $$f > $$ldir/$$ext$$f; \
1383 filelist="$$filelist $$ldir/$$ext$$f"; \
Ying Wanga02d3d92011-01-27 18:48:00 -08001384 done ; \
Ying Wang6feb6d52014-04-17 10:03:35 -07001385 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_ARFLAGS) \
1386 $(PRIVATE_ARFLAGS) $@ $$filelist
Ying Wanga02d3d92011-01-27 18:48:00 -08001387
1388endef
1389
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001390define extract-and-include-host-whole-static-libs
Dan Alberte0f44ac2014-05-23 12:26:51 -07001391$(call extract-and-include-whole-static-libs-first, $(firstword $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)))
1392$(foreach lib,$(wordlist 2,999,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)), \
Ying Wanga02d3d92011-01-27 18:48:00 -08001393 $(call _extract-and-include-single-host-whole-static-lib, $(lib)))
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001394endef
1395
The Android Open Source Project88b60792009-03-03 19:28:42 -08001396# Explicitly delete the archive first so that ar doesn't
1397# try to add to an existing archive.
1398define transform-host-o-to-static-lib
1399@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001400@rm -f $@
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001401$(extract-and-include-host-whole-static-libs)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301402@echo -e ${CL_YLW}"host StaticLib:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Ying Wang6feb6d52014-04-17 10:03:35 -07001403$(call split-long-arguments,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_AR) \
1404 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_ARFLAGS) \
Ying Wang854607e2015-04-02 18:02:33 -07001405 $(PRIVATE_ARFLAGS) $@,$(PRIVATE_ALL_OBJECTS))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001406endef
1407
1408
1409###########################################################
1410## Commands for running gcc to link a shared library or package
1411###########################################################
1412
1413# ld just seems to be so finicky with command order that we allow
1414# it to be overriden en-masse see combo/linux-arm.make for an example.
1415ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1416define transform-host-o-to-shared-lib-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001417$(hide) $(PRIVATE_CXX) \
Ying Wang6feb6d52014-04-17 10:03:35 -07001418 -Wl,-rpath-link=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_OUT_INTERMEDIATE_LIBRARIES) \
1419 -Wl,-rpath,\$$ORIGIN/../$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_OUT_SHARED_LIBRARIES)) \
Ying Wang4fe7bfd2015-06-01 10:43:29 -07001420 -Wl,-rpath,\$$ORIGIN/$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_OUT_SHARED_LIBRARIES)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001421 -shared -Wl,-soname,$(notdir $@) \
Ying Wang6feb6d52014-04-17 10:03:35 -07001422 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_LD_DIRS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001423 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001424 $(PRIVATE_HOST_GLOBAL_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001425 ) \
Torne (Richard Coles)a424bf72014-02-12 14:24:41 +00001426 $(PRIVATE_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001427 $(PRIVATE_ALL_OBJECTS) \
1428 -Wl,--whole-archive \
1429 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1430 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001431 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001432 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001433 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
Dan Albert43e128a2015-01-23 16:12:57 -08001434 $(if $(filter true,$(NATIVE_COVERAGE)),-lgcov) \
Dan Albert343ed672015-01-25 16:20:57 -08001435 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_HOST_LIBPROFILE_RT)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001436 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1437 -o $@ \
1438 $(PRIVATE_LDLIBS)
1439endef
1440endif
1441
1442define transform-host-o-to-shared-lib
1443@mkdir -p $(dir $@)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301444@echo -e ${CL_YLW}"host SharedLib:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001445$(transform-host-o-to-shared-lib-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001446endef
1447
1448define transform-host-o-to-package
1449@mkdir -p $(dir $@)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301450@echo -e ${CL_YLW}"host Package:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001451$(transform-host-o-to-shared-lib-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001452endef
1453
1454
1455###########################################################
1456## Commands for running gcc to link a shared library or package
1457###########################################################
1458
The Android Open Source Project88b60792009-03-03 19:28:42 -08001459define transform-o-to-shared-lib-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001460$(hide) $(PRIVATE_CXX) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001461 -nostdlib -Wl,-soname,$(notdir $@) \
1462 -Wl,--gc-sections \
Logan Chiene481e7d2015-01-25 21:15:12 +08001463 $(if $(filter true,$(PRIVATE_CLANG)),-shared,-Wl$(comma)-shared) \
Ying Wang1a081002010-07-13 14:55:47 -07001464 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001465 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_SO_O)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001466 $(PRIVATE_ALL_OBJECTS) \
1467 -Wl,--whole-archive \
Ying Wang80e6cce2011-01-24 23:25:36 -08001468 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001469 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001470 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001471 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001472 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
Dan Albert91f713a2015-03-31 15:21:30 -07001473 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBGCOV)) \
Dan Albert343ed672015-01-25 16:20:57 -08001474 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBPROFILE_RT)) \
Dan Albert91f713a2015-03-31 15:21:30 -07001475 $(PRIVATE_TARGET_LIBATOMIC) \
1476 $(PRIVATE_TARGET_LIBGCC) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001477 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1478 -o $@ \
Dan Alberte088c0d2014-11-13 10:15:46 -08001479 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
1480 $(PRIVATE_LDFLAGS) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001481 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_SO_O)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001482 $(PRIVATE_LDLIBS)
1483endef
The Android Open Source Project88b60792009-03-03 19:28:42 -08001484
1485define transform-o-to-shared-lib
1486@mkdir -p $(dir $@)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301487@echo -e ${CL_GRN}"target SharedLib:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Dan Alberte088c0d2014-11-13 10:15:46 -08001488$(transform-o-to-shared-lib-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001489endef
1490
1491
1492###########################################################
1493## Commands for filtering a target executable or library
1494###########################################################
1495
Ying Wangce1c5962014-03-28 17:24:39 -07001496ifneq ($(TARGET_BUILD_VARIANT),user)
1497 TARGET_STRIP_EXTRA = && $(PRIVATE_OBJCOPY) --add-gnu-debuglink=$< $@
1498 TARGET_STRIP_KEEP_SYMBOLS_EXTRA = --add-gnu-debuglink=$<
1499endif
1500
The Android Open Source Project88b60792009-03-03 19:28:42 -08001501define transform-to-stripped
1502@mkdir -p $(dir $@)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301503@echo -e ${CL_GRN}"target Strip:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Ying Wangbfb52a22014-08-20 17:12:32 -07001504$(hide) $(PRIVATE_STRIP) --strip-all $< -o $@ \
1505 $(if $(PRIVATE_NO_DEBUGLINK),,$(TARGET_STRIP_EXTRA))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001506endef
1507
Christopher Ferrisa6e2f932014-03-18 14:50:09 -07001508define transform-to-stripped-keep-symbols
1509@mkdir -p $(dir $@)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301510@echo -e ${CL_GRN}"target Strip (keep symbols):"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Ying Wangce1c5962014-03-28 17:24:39 -07001511$(hide) $(PRIVATE_OBJCOPY) \
1512 `$(PRIVATE_READELF) -S $< | awk '/.debug_/ {print "-R " $$2}' | xargs` \
1513 $(TARGET_STRIP_KEEP_SYMBOLS_EXTRA) $< $@
Christopher Ferrisa6e2f932014-03-18 14:50:09 -07001514endef
1515
Dmitriy Ivanov4c2d1a62015-04-20 16:59:05 -07001516###########################################################
1517## Commands for packing a target executable or library
1518###########################################################
1519
1520define pack-elf-relocations
1521$(copy-file-to-target)
1522@echo "target Pack Relocations: $(PRIVATE_MODULE) ($@)"
1523$(hide) $(RELOCATION_PACKER) $@
1524endef
The Android Open Source Project88b60792009-03-03 19:28:42 -08001525
1526###########################################################
1527## Commands for running gcc to link an executable
1528###########################################################
1529
The Android Open Source Project88b60792009-03-03 19:28:42 -08001530define transform-o-to-executable-inner
Dan Alberte088c0d2014-11-13 10:15:46 -08001531$(hide) $(PRIVATE_CXX) -pie \
1532 -nostdlib -Bdynamic \
1533 -Wl,-dynamic-linker,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_LINKER) \
1534 -Wl,--gc-sections \
1535 -Wl,-z,nocopyreloc \
Ying Wangc6ffc002012-09-25 17:52:10 -07001536 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
Ying Wang9fb35262014-02-21 16:17:05 -08001537 -Wl,-rpath-link=$(PRIVATE_TARGET_OUT_INTERMEDIATE_LIBRARIES) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001538 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001539 $(PRIVATE_ALL_OBJECTS) \
1540 -Wl,--whole-archive \
1541 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1542 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001543 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001544 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001545 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
Dan Albert91f713a2015-03-31 15:21:30 -07001546 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBGCOV)) \
Dan Albert343ed672015-01-25 16:20:57 -08001547 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBPROFILE_RT)) \
Dan Albert91f713a2015-03-31 15:21:30 -07001548 $(PRIVATE_TARGET_LIBATOMIC) \
1549 $(PRIVATE_TARGET_LIBGCC) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001550 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1551 -o $@ \
Dan Alberte088c0d2014-11-13 10:15:46 -08001552 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
1553 $(PRIVATE_LDFLAGS) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001554 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001555 $(PRIVATE_LDLIBS)
1556endef
The Android Open Source Project88b60792009-03-03 19:28:42 -08001557
1558define transform-o-to-executable
1559@mkdir -p $(dir $@)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301560@echo -e ${CL_GRN}"target Executable:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Dan Alberte088c0d2014-11-13 10:15:46 -08001561$(transform-o-to-executable-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001562endef
1563
1564
1565###########################################################
Dan Alberte088c0d2014-11-13 10:15:46 -08001566## Commands for linking a static executable. In practice,
1567## we only use this on arm, so the other platforms don't
1568## have transform-o-to-static-executable defined.
Chih-Hung Hsieh69b1fe62015-01-20 11:00:20 -08001569## Clang driver needs -static to create static executable.
1570## However, bionic/linker uses -shared to overwrite.
1571## Linker for x86 targets does not allow coexistance of -static and -shared,
1572## so we add -static only if -shared is not used.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001573###########################################################
1574
The Android Open Source Project88b60792009-03-03 19:28:42 -08001575define transform-o-to-static-executable-inner
Dan Alberte088c0d2014-11-13 10:15:46 -08001576$(hide) $(PRIVATE_CXX) \
1577 -nostdlib -Bstatic \
Chih-Hung Hsieh69b1fe62015-01-20 11:00:20 -08001578 $(if $(filter $(PRIVATE_LDFLAGS),-shared),,-static) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001579 -Wl,--gc-sections \
1580 -o $@ \
1581 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
1582 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_STATIC_O)) \
1583 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
1584 $(PRIVATE_LDFLAGS) \
1585 $(PRIVATE_ALL_OBJECTS) \
1586 -Wl,--whole-archive \
1587 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1588 -Wl,--no-whole-archive \
1589 $(call normalize-target-libraries,$(filter-out %libcompiler_rt.a,$(filter-out %libc_nomalloc.a,$(filter-out %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))))) \
1590 -Wl,--start-group \
1591 $(call normalize-target-libraries,$(filter %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
1592 $(call normalize-target-libraries,$(filter %libc_nomalloc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001593 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBGCOV)) \
Dan Albert343ed672015-01-25 16:20:57 -08001594 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBPROFILE_RT)) \
1595 $(PRIVATE_TARGET_LIBATOMIC) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001596 $(call normalize-target-libraries,$(filter %libcompiler_rt.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
Dan Albert741b36e2014-11-13 21:24:04 -08001597 $(PRIVATE_TARGET_LIBGCC) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001598 -Wl,--end-group \
1599 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001600endef
The Android Open Source Project88b60792009-03-03 19:28:42 -08001601
1602define transform-o-to-static-executable
1603@mkdir -p $(dir $@)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301604@echo -e ${CL_GRN}"target StaticExecutable:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Dan Alberte088c0d2014-11-13 10:15:46 -08001605$(transform-o-to-static-executable-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001606endef
1607
1608
1609###########################################################
1610## Commands for running gcc to link a host executable
1611###########################################################
Ying Wangfaf3d5e2014-04-04 14:37:33 -07001612ifdef BUILD_HOST_static
1613HOST_FPIE_FLAGS :=
1614else
Dan Albert4803ce22014-08-06 12:36:46 -07001615HOST_FPIE_FLAGS := -pie
Stephen Hinesa503fb32014-10-02 00:51:11 -07001616# Force the correct entry point to workaround a bug in binutils that manifests with -pie
1617ifeq ($(HOST_OS),windows)
1618HOST_FPIE_FLAGS += -Wl,-e_mainCRTStartup
1619endif
Ying Wangfaf3d5e2014-04-04 14:37:33 -07001620endif
The Android Open Source Project88b60792009-03-03 19:28:42 -08001621
1622ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1623define transform-host-o-to-executable-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001624$(hide) $(PRIVATE_CXX) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001625 $(PRIVATE_ALL_OBJECTS) \
1626 -Wl,--whole-archive \
1627 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1628 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001629 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001630 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001631 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
Dan Albert43e128a2015-01-23 16:12:57 -08001632 $(if $(filter true,$(NATIVE_COVERAGE)),-lgcov) \
Dan Albert343ed672015-01-25 16:20:57 -08001633 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_HOST_LIBPROFILE_RT)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001634 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
Ying Wang6feb6d52014-04-17 10:03:35 -07001635 -Wl,-rpath-link=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_OUT_INTERMEDIATE_LIBRARIES) \
1636 -Wl,-rpath,\$$ORIGIN/../$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_OUT_SHARED_LIBRARIES)) \
Ying Wang4fe7bfd2015-06-01 10:43:29 -07001637 -Wl,-rpath,\$$ORIGIN/$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_OUT_SHARED_LIBRARIES)) \
Ying Wang6feb6d52014-04-17 10:03:35 -07001638 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_LD_DIRS) \
Conley Owensd9e7d252011-11-10 09:57:40 -08001639 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001640 $(PRIVATE_HOST_GLOBAL_LDFLAGS) \
Conley Owensd9e7d252011-11-10 09:57:40 -08001641 ) \
Torne (Richard Coles)a424bf72014-02-12 14:24:41 +00001642 $(PRIVATE_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001643 -o $@ \
1644 $(PRIVATE_LDLIBS)
1645endef
1646endif
1647
1648define transform-host-o-to-executable
1649@mkdir -p $(dir $@)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301650@echo -e ${CL_YLW}"host Executable:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001651$(transform-host-o-to-executable-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001652endef
1653
1654
1655###########################################################
1656## Commands for running javac to make .class files
1657###########################################################
1658
1659#@echo "Source intermediates dir: $(PRIVATE_SOURCE_INTERMEDIATES_DIR)"
1660#@echo "Source intermediates: $$(find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java')"
1661
1662# TODO: Right now we generate the asset resources twice, first as part
1663# of generating the Java classes, then at the end when packaging the final
1664# assets. This should be changed to do one of two things: (1) Don't generate
1665# any resource files the first time, only create classes during that stage;
1666# or (2) Don't use the -c flag with the second stage, instead taking the
1667# resource files from the first stage as additional input. My original intent
1668# was to use approach (2), but this requires a little more work in the tool.
1669# Maybe we should just use approach (1).
1670
1671# This rule creates the R.java and Manifest.java files, both of which
Ying Wang4f1ab922011-03-15 13:19:30 -07001672# are PRODUCT-neutral. Don't pass PRIVATE_PRODUCT_AAPT_CONFIG to this invocation.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001673define create-resource-java-files
1674@mkdir -p $(PRIVATE_SOURCE_INTERMEDIATES_DIR)
1675@mkdir -p $(dir $(PRIVATE_RESOURCE_PUBLICS_OUTPUT))
Ying Wangc61d5932010-03-10 16:02:42 -08001676$(hide) $(AAPT) package $(PRIVATE_AAPT_FLAGS) -m \
Ying Wang4f1ab922011-03-15 13:19:30 -07001677 $(eval # PRIVATE_PRODUCT_AAPT_CONFIG is intentionally missing-- see comment.) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001678 $(addprefix -J , $(PRIVATE_SOURCE_INTERMEDIATES_DIR)) \
1679 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
1680 $(addprefix -P , $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) \
1681 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
1682 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001683 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
Joe Onorato2daa2b32009-08-30 13:39:24 -07001684 $(addprefix -G , $(PRIVATE_PROGUARD_OPTIONS_FILE)) \
Ying Wangbb9c2302011-04-08 17:27:35 -07001685 $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
1686 $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
Ying Wang1ae607a2010-06-23 13:34:22 -07001687 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \
Ying Wang8f5069b2010-06-29 11:08:13 -07001688 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION)-$(BUILD_NUMBER))) \
Ying Wang8c254822010-03-16 16:13:56 -07001689 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Adrian Roos6784cae2015-06-01 18:24:41 -07001690 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \
1691 --skip-symbols-without-default-localization
The Android Open Source Project88b60792009-03-03 19:28:42 -08001692endef
1693
1694ifeq ($(HOST_OS),windows)
1695xlint_unchecked :=
1696else
Jeffrey Chyan7adbf972010-07-07 13:42:19 -05001697xlint_unchecked := -Xlint:unchecked
The Android Open Source Project88b60792009-03-03 19:28:42 -08001698endif
1699
1700# emit-line, <word list>, <output file>
1701define emit-line
1702 $(if $(1),echo -n '$(strip $(1)) ' >> $(2))
1703endef
1704
1705# dump-words-to-file, <word list>, <output file>
1706define dump-words-to-file
1707 @rm -f $(2)
1708 @$(call emit-line,$(wordlist 1,200,$(1)),$(2))
1709 @$(call emit-line,$(wordlist 201,400,$(1)),$(2))
1710 @$(call emit-line,$(wordlist 401,600,$(1)),$(2))
1711 @$(call emit-line,$(wordlist 601,800,$(1)),$(2))
1712 @$(call emit-line,$(wordlist 801,1000,$(1)),$(2))
1713 @$(call emit-line,$(wordlist 1001,1200,$(1)),$(2))
1714 @$(call emit-line,$(wordlist 1201,1400,$(1)),$(2))
1715 @$(call emit-line,$(wordlist 1401,1600,$(1)),$(2))
1716 @$(call emit-line,$(wordlist 1601,1800,$(1)),$(2))
1717 @$(call emit-line,$(wordlist 1801,2000,$(1)),$(2))
1718 @$(call emit-line,$(wordlist 2001,2200,$(1)),$(2))
1719 @$(call emit-line,$(wordlist 2201,2400,$(1)),$(2))
1720 @$(call emit-line,$(wordlist 2401,2600,$(1)),$(2))
1721 @$(call emit-line,$(wordlist 2601,2800,$(1)),$(2))
1722 @$(call emit-line,$(wordlist 2801,3000,$(1)),$(2))
1723 @$(call emit-line,$(wordlist 3001,3200,$(1)),$(2))
1724 @$(call emit-line,$(wordlist 3201,3400,$(1)),$(2))
1725 @$(call emit-line,$(wordlist 3401,3600,$(1)),$(2))
1726 @$(call emit-line,$(wordlist 3601,3800,$(1)),$(2))
1727 @$(call emit-line,$(wordlist 3801,4000,$(1)),$(2))
Jesse Wilson72c941a2010-05-04 16:33:49 -07001728 @$(call emit-line,$(wordlist 4001,4200,$(1)),$(2))
1729 @$(call emit-line,$(wordlist 4201,4400,$(1)),$(2))
1730 @$(call emit-line,$(wordlist 4401,4600,$(1)),$(2))
1731 @$(call emit-line,$(wordlist 4601,4800,$(1)),$(2))
1732 @$(call emit-line,$(wordlist 4801,5000,$(1)),$(2))
1733 @$(if $(wordlist 5001,5002,$(1)),$(error Too many words ($(words $(1)))))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001734endef
1735
1736# For a list of jar files, unzip them to a specified directory,
1737# but make sure that no META-INF files come along for the ride.
1738#
1739# $(1): files to unzip
1740# $(2): destination directory
1741define unzip-jar-files
1742 $(hide) for f in $(1); \
1743 do \
1744 if [ ! -f $$f ]; then \
1745 echo Missing file $$f; \
1746 exit 1; \
1747 fi; \
Sriram Ramanf1a55f82009-06-09 15:08:29 -07001748 unzip -qo $$f -d $(2); \
Ying Wang3a6f7582012-08-30 12:59:42 -07001749 done \
1750 $(if $(PRIVATE_DONT_DELETE_JAR_META_INF),,;rm -rf $(2)/META-INF)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001751endef
1752
Brian Carlstrom78269512010-12-10 12:10:24 -08001753# Common definition to invoke javac on the host and target.
1754#
1755# Some historical notes:
1756# - below we write the list of java files to java-source-list to avoid argument
1757# list length problems with Cygwin
1758# - we filter out duplicate java file names because eclipse's compiler
1759# doesn't like them.
1760#
1761# $(1): javac
1762# $(2): bootclasspath
1763define compile-java
Joe Onorato64d85d02009-04-09 19:31:12 -07001764$(hide) rm -f $@
1765$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
Brian Carlstrom78269512010-12-10 12:10:24 -08001766$(hide) mkdir -p $(dir $@)
Joe Onorato64d85d02009-04-09 19:31:12 -07001767$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
Brian Carlstrom78269512010-12-10 12:10:24 -08001768$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES),$(PRIVATE_CLASS_INTERMEDIATES_DIR))
Ying Wang015edd22011-01-20 15:01:56 -08001769$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list)
Joe Onorato64d85d02009-04-09 19:31:12 -07001770$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
Ying Wanga3b75932013-08-14 16:59:00 -07001771 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list; \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001772fi
Ying Wang884738e2015-05-08 18:51:00 +00001773$(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \
1774 | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
1775$(hide) if [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
Ying Wange109a1d2011-12-12 17:52:03 -08001776 $(1) -encoding UTF-8 \
Brian Carlstrom78269512010-12-10 12:10:24 -08001777 $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) \
Ying Wang057eba02012-10-18 10:54:49 -07001778 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
Brian Carlstrom78269512010-12-10 12:10:24 -08001779 $(2) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001780 $(addprefix -classpath ,$(strip \
1781 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \
Ying Wang057eba02012-10-18 10:54:49 -07001782 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001783 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
Brian Carlstrom78269512010-12-10 12:10:24 -08001784 $(PRIVATE_JAVACFLAGS) \
Ying Wang015edd22011-01-20 15:01:56 -08001785 \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \
nuclearmistake451a31b2014-04-27 21:59:42 -04001786 2>$(PRIVATE_CLASS_INTERMEDIATES_DIR)/stderr \
nuclearmistake73c9e722014-05-15 10:30:26 -04001787 && ( [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stderr ] && \
1788 echo -e ${CL_YLW}"`cat $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stderr`"${CL_RST} 1>&2; \
1789 rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stderr ) \
1790 || ( [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stderr ] && \
nuclearmistake451a31b2014-04-27 21:59:42 -04001791 echo -e ${CL_RED}"`cat $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stderr`"${CL_RST} 1>&2; \
nuclearmistake73c9e722014-05-15 10:30:26 -04001792 rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR); exit 41 ) \
Ying Wange109a1d2011-12-12 17:52:03 -08001793fi
Joe Onorato0eccce92011-10-30 21:37:35 -07001794$(if $(PRIVATE_JAVA_LAYERS_FILE), $(hide) build/tools/java-layers.py \
1795 $(PRIVATE_JAVA_LAYERS_FILE) \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq,)
Ying Wang015edd22011-01-20 15:01:56 -08001796$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list
1797$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
Ying Wang5758b8e2011-12-15 16:36:55 -08001798$(if $(PRIVATE_JAR_EXCLUDE_FILES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
1799 -name $(word 1, $(PRIVATE_JAR_EXCLUDE_FILES)) \
1800 $(addprefix -o -name , $(wordlist 2, 999, $(PRIVATE_JAR_EXCLUDE_FILES))) \
1801 | xargs rm -rf)
Jeff Brown4c4aa992014-05-23 18:41:19 -07001802$(if $(PRIVATE_JAR_PACKAGES), \
1803 $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -mindepth 1 -type f \
1804 $(foreach pkg, $(PRIVATE_JAR_PACKAGES), \
1805 -not -path $(PRIVATE_CLASS_INTERMEDIATES_DIR)/$(subst .,/,$(pkg))/\*) -delete ; \
1806 find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -empty -delete)
1807$(if $(PRIVATE_JAR_EXCLUDE_PACKAGES), $(hide) rm -rf \
1808 $(foreach pkg, $(PRIVATE_JAR_EXCLUDE_PACKAGES), \
1809 $(PRIVATE_CLASS_INTERMEDIATES_DIR)/$(subst .,/,$(pkg))))
Ying Wanga3b75932013-08-14 16:59:00 -07001810$(if $(PRIVATE_RMTYPEDEFS), $(hide) $(RMTYPEDEFS) -v $(PRIVATE_CLASS_INTERMEDIATES_DIR))
Guang Zhu5c9a1a42013-09-24 19:05:52 -07001811$(if $(PRIVATE_JAR_MANIFEST), \
1812 $(hide) sed -e 's/%BUILD_NUMBER%/$(BUILD_NUMBER)/' \
1813 $(PRIVATE_JAR_MANIFEST) > $(dir $@)/manifest.mf && \
1814 jar -cfm $@ $(dir $@)/manifest.mf \
1815 -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) ., \
1816 $(hide) jar -cf $@ -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .)
Ying Wang33360dd2015-01-14 14:23:56 -08001817$(if $(PRIVATE_EXTRA_JAR_ARGS),$(call add-java-resources-to,$@))
Brian Carlstrom78269512010-12-10 12:10:24 -08001818endef
1819
1820define transform-java-to-classes.jar
Chirayu Desaiad48df42012-10-13 13:05:29 +05301821@echo -e ${CL_GRN}"target Java:"${CL_RST}" $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
Brian Carlstrom78269512010-12-10 12:10:24 -08001822$(call compile-java,$(TARGET_JAVAC),$(PRIVATE_BOOTCLASSPATH))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001823endef
1824
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001825# Invoke Jack to compile java from source to dex and jack files.
1826#
1827# Some historical notes:
1828# - below we write the list of java files to java-source-list to avoid argument
1829# list length problems with Cygwin
1830# - we filter out duplicate java file names because Jack doesn't like them.
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001831define jack-java-to-dex
1832$(hide) rm -f $@
1833$(hide) rm -f $(PRIVATE_CLASSES_JACK)
1834$(hide) rm -rf $(PRIVATE_JACK_INTERMEDIATES_DIR)
1835$(hide) mkdir -p $(dir $@)
1836$(hide) mkdir -p $(dir $(PRIVATE_CLASSES_JACK))
1837$(hide) mkdir -p $(PRIVATE_JACK_INTERMEDIATES_DIR)
Yohann Roussel37822c42015-01-09 10:36:40 +01001838$(if $(PRIVATE_JACK_INCREMENTAL_DIR),$(hide) mkdir -p $(PRIVATE_JACK_INCREMENTAL_DIR))
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001839$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list)
1840$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
1841 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list; \
1842fi
Ying Wang884738e2015-05-08 18:51:00 +00001843$(hide) tr ' ' '\n' < $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list \
1844 | sort -u > $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001845$(if $(PRIVATE_JACK_PROGUARD_FLAGS), \
1846 $(hide) echo -basedirectory $(CURDIR) > $@.flags; \
1847 echo $(PRIVATE_JACK_PROGUARD_FLAGS) >> $@.flags; \
1848)
Ying Wang33360dd2015-01-14 14:23:56 -08001849$(if $(PRIVATE_EXTRA_JAR_ARGS),
1850 $(hide) mkdir -p $@.res.tmp
1851 $(hide) $(call create-empty-package-at,$@.res.tmp.zip)
1852 $(hide) $(call add-java-resources-to,$@.res.tmp.zip)
1853 $(hide) $(call unzip-jar-files,$@.res.tmp.zip,$@.res.tmp)
1854 $(hide) rm $@.res.tmp.zip)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001855$(hide) if [ -s $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
1856 export tmpEcjArg="@$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq"; \
1857else \
1858 export tmpEcjArg=""; \
1859fi; \
Yohann Roussel28096662015-02-02 12:18:20 +01001860$(call call-jack,$(PRIVATE_JACK_VM_ARGS),$(PRIVATE_JACK_EXTRA_ARGS)) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001861 $(strip $(PRIVATE_JACK_FLAGS)) \
1862 $(strip $(PRIVATE_JACK_DEBUG_FLAGS)) \
1863 $(if $(NO_OPTIMIZE_DX), \
1864 -D jack.dex.optimize="false") \
Yohann Roussel5b2c6e22015-05-20 17:52:15 +02001865 $(if $(PRIVATE_RMTYPEDEFS), \
1866 -D jack.android.remove-typedef="true") \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001867 $(addprefix --classpath ,$(strip \
1868 $(call normalize-path-list,$(PRIVATE_BOOTCLASSPATH_JAVA_LIBRARIES) $(PRIVATE_ALL_JACK_LIBRARIES)))) \
1869 $(addprefix --import ,$(call reverse-list,$(PRIVATE_STATIC_JACK_LIBRARIES))) \
Ying Wang33360dd2015-01-14 14:23:56 -08001870 $(if $(PRIVATE_EXTRA_JAR_ARGS),--import-resource $@.res.tmp) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001871 -D jack.import.resource.policy=keep-first \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001872 -D jack.import.type.policy=keep-first \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001873 --output-jack $(PRIVATE_CLASSES_JACK) \
1874 -D jack.java.source.version=1.7 \
Yohann Roussel37822c42015-01-09 10:36:40 +01001875 $(if $(PRIVATE_JACK_INCREMENTAL_DIR),--incremental-folder $(PRIVATE_JACK_INCREMENTAL_DIR)) \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001876 --output-dex $(PRIVATE_JACK_INTERMEDIATES_DIR) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001877 $(addprefix --config-jarjar ,$(strip $(PRIVATE_JARJAR_RULES))) \
1878 $(if $(PRIVATE_JACK_PROGUARD_FLAGS),--config-proguard $@.flags) \
1879 $$tmpEcjArg \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001880 || ( rm -rf $(PRIVATE_CLASSES_JACK); rm -rf $(PRIVATE_JACK_INTERMEDIATES_DIR); exit 41 )
1881$(hide) mv $(PRIVATE_JACK_INTERMEDIATES_DIR)/classes*.dex $(dir $@)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001882$(hide) rm -f $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list
Ying Wang33360dd2015-01-14 14:23:56 -08001883$(if $(PRIVATE_EXTRA_JAR_ARGS),$(hide) rm -rf $@.res.tmp)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001884$(hide) mv $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq $(PRIVATE_JACK_INTERMEDIATES_DIR).java-source-list
1885$(if $(PRIVATE_JAR_PACKAGES), $(hide) echo unsupported options PRIVATE_JAR_PACKAGES in $@; exit 53)
1886$(if $(PRIVATE_JAR_EXCLUDE_PACKAGES), $(hide) echo unsupported options JAR_EXCLUDE_PACKAGES in $@; exit 53)
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001887$(if $(PRIVATE_JAR_MANIFEST), $(hide) echo unsupported options JAR_MANIFEST in $@; exit 53)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001888endef
1889
1890define transform-jar-to-jack
1891 $(hide) mkdir -p $(dir $@)
Yohann Roussel801f2c42015-03-03 17:14:09 +01001892 $(JILL) $(PRIVATE_JILL_FLAGS) --output $@.tmpjill.jack $<
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001893 $(hide) mkdir -p $@.tmpjill.res
1894 $(hide) $(call unzip-jar-files,$<,$@.tmpjill.res)
1895 $(hide) find $@.tmpjill.res -iname "*.class" -delete
Yohann Roussel28096662015-02-02 12:18:20 +01001896 $(hide) $(call call-jack,$(PRIVATE_JACK_VM_ARGS),$(PRIVATE_JACK_EXTRA_ARGS)) \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001897 -D jack.import.resource.policy=keep-first \
1898 -D jack.import.type.policy=keep-first \
1899 --import $@.tmpjill.jack \
1900 --import-resource $@.tmpjill.res \
1901 --output-jack $@
1902 $(hide) rm -rf $@.tmpjill.res
1903 $(hide) rm $@.tmpjill.jack
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001904endef
1905
1906
1907# Invoke Jack to compile java from source to jack files without shrink or obfuscation.
1908#
1909# Some historical notes:
1910# - below we write the list of java files to java-source-list to avoid argument
1911# list length problems with Cygwin
1912# - we filter out duplicate java file names because Jack doesn't like them.
1913define java-to-jack
1914$(hide) rm -f $@
1915$(hide) rm -rf $(PRIVATE_JACK_INTERMEDIATES_DIR)
1916$(hide) mkdir -p $(dir $@)
1917$(hide) mkdir -p $(PRIVATE_JACK_INTERMEDIATES_DIR)
Yohann Roussel37822c42015-01-09 10:36:40 +01001918$(if $(PRIVATE_JACK_INCREMENTAL_DIR),$(hide) mkdir -p $(PRIVATE_JACK_INCREMENTAL_DIR))
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001919$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list)
1920$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
1921 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list; \
1922fi
Ying Wang884738e2015-05-08 18:51:00 +00001923$(hide) tr ' ' '\n' < $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list \
1924 | sort -u > $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001925$(if $(PRIVATE_JACK_PROGUARD_FLAGS), \
1926 $(hide) echo -basedirectory $(CURDIR) > $@.flags; \
1927 echo $(PRIVATE_JACK_PROGUARD_FLAGS) >> $@.flags; \
1928)
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001929$(if $(PRIVATE_EXTRA_JAR_ARGS),
1930 $(hide) mkdir -p $@.res.tmp
1931 $(hide) $(call create-empty-package-at,$@.res.tmp.zip)
1932 $(hide) $(call add-java-resources-to,$@.res.tmp.zip)
Yohann Roussel5dd3e1d2015-01-14 16:21:39 +01001933 $(hide) unzip -qo $@.res.tmp.zip -d $@.res.tmp
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001934 $(hide) rm $@.res.tmp.zip)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001935$(hide) if [ -s $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
1936 export tmpEcjArg="@$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq"; \
1937else \
1938 export tmpEcjArg=""; \
1939fi; \
Yohann Roussel28096662015-02-02 12:18:20 +01001940$(call call-jack,$(PRIVATE_JACK_VM_ARGS),$(PRIVATE_JACK_EXTRA_ARGS)) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001941 $(strip $(PRIVATE_JACK_FLAGS)) \
1942 $(strip $(PRIVATE_JACK_DEBUG_FLAGS)) \
1943 $(if $(NO_OPTIMIZE_DX), \
1944 -D jack.dex.optimize="false") \
1945 $(addprefix --classpath ,$(strip \
1946 $(call normalize-path-list,$(PRIVATE_BOOTCLASSPATH_JAVA_LIBRARIES) $(PRIVATE_ALL_JACK_LIBRARIES)))) \
1947 $(addprefix --import ,$(call reverse-list,$(PRIVATE_STATIC_JACK_LIBRARIES))) \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001948 $(if $(PRIVATE_EXTRA_JAR_ARGS),--import-resource $@.res.tmp) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001949 -D jack.import.resource.policy=keep-first \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001950 -D jack.import.type.policy=keep-first \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001951 -D jack.java.source.version=1.7 \
Yohann Roussel37822c42015-01-09 10:36:40 +01001952 $(if $(PRIVATE_JACK_INCREMENTAL_DIR),--incremental-folder $(PRIVATE_JACK_INCREMENTAL_DIR)) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001953 --output-jack $@ \
1954 $(addprefix --config-jarjar ,$(strip $(PRIVATE_JARJAR_RULES))) \
1955 $(if $(PRIVATE_JACK_PROGUARD_FLAGS),--config-proguard $@.flags) \
1956 $$tmpEcjArg \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001957 || ( rm -f $@ ; exit 41 )
1958$(hide) rm -f $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list
1959$(if $(PRIVATE_EXTRA_JAR_ARGS),$(hide) rm -rf $@.res.tmp)
1960$(hide) mv $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq $(PRIVATE_JACK_INTERMEDIATES_DIR).java-source-list
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001961$(if $(PRIVATE_JAR_PACKAGES), $(hide) echo unsupported options PRIVATE_JAR_PACKAGES in $@; exit 53)
1962$(if $(PRIVATE_JAR_EXCLUDE_PACKAGES), $(hide) echo unsupported options JAR_EXCLUDE_PACKAGES in $@; exit 53)
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001963$(if $(PRIVATE_JAR_MANIFEST), $(hide) echo unsupported options JAR_MANIFEST in $@; exit 53)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001964endef
1965
The Android Open Source Project88b60792009-03-03 19:28:42 -08001966define transform-classes.jar-to-emma
1967$(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \
Guang Zhu155afe32010-03-10 15:48:03 -08001968 $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR) \
Guang Zhu9cd3d8c2010-06-15 13:31:25 -07001969 $(addprefix -ix , $(PRIVATE_EMMA_COVERAGE_FILTER))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001970endef
1971
1972#TODO: use a smaller -Xmx value for most libraries;
1973# only core.jar and framework.jar need a heap this big.
Raphaelf6ff4c52009-08-18 14:43:32 -07001974# 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 -08001975define transform-classes.jar-to-dex
Chirayu Desaiad48df42012-10-13 13:05:29 +05301976@echo -e ${CL_GRN}"target Dex:"${CL_RST}" $(PRIVATE_MODULE)"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001977@mkdir -p $(dir $@)
Ying Wangaf9757e2014-07-17 21:24:42 -07001978$(hide) rm -f $(dir $@)classes*.dex
Raphaelf6ff4c52009-08-18 14:43:32 -07001979$(hide) $(DX) \
Sebastian Schmidtd36495b2012-07-15 15:25:49 +02001980 $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx$(if $(call streq,$(HOST_BITS),32),1024,2048)M) \
Yohann Roussel8ffe9c32013-08-20 17:05:27 +02001981 --dex --output=$(dir $@) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001982 $(if $(NO_OPTIMIZE_DX), \
1983 --no-optimize) \
1984 $(if $(GENERATE_DEX_DEBUG), \
1985 --debug --verbose \
1986 --dump-to=$(@:.dex=.lst) \
1987 --dump-width=1000) \
1988 $(PRIVATE_DX_FLAGS) \
1989 $<
1990endef
1991
1992# Create a mostly-empty .jar file that we'll add to later.
1993# The MacOS jar tool doesn't like creating empty jar files,
1994# so we need to give it something.
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001995# $(1) package to create
1996define create-empty-package-at
1997@mkdir -p $(dir $(1))
Ying Wangc894e092015-02-26 10:34:33 -08001998$(hide) touch $(dir $(1))zipdummy
1999$(hide) (cd $(dir $(1)) && jar cf $(notdir $(1)) zipdummy)
2000$(hide) zip -qd $(1) zipdummy
2001$(hide) rm $(dir $(1))zipdummy
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002002endef
2003
2004# Create a mostly-empty .jar file that we'll add to later.
2005# The MacOS jar tool doesn't like creating empty jar files,
2006# so we need to give it something.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002007define create-empty-package
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002008$(call create-empty-package-at,$@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08002009endef
2010
Ying Wang33360dd2015-01-14 14:23:56 -08002011# Copy an arhchive file and delete any class files and empty folders inside.
2012# $(1): the source archive file.
2013# $(2): the destination archive file.
2014define initialize-package-file
2015@mkdir -p $(dir $(2))
2016$(hide) cp -f $(1) $(2)
Fredrik Roubertcc93f0c2015-01-28 21:29:38 +01002017$(hide) zip -qd $(2) "*.class" \
2018 $(if $(strip $(PRIVATE_DONT_DELETE_JAR_DIRS)),,"*/") \
2019 || true # Ignore the error when nothing to delete.
Ying Wang33360dd2015-01-14 14:23:56 -08002020endef
2021
The Android Open Source Project88b60792009-03-03 19:28:42 -08002022#TODO: we kinda want to build different asset packages for
2023# different configurations, then combine them later (or something).
2024# Per-locale, etc.
2025# A list of dynamic and static parameters; build layers for
2026# dynamic params that lay over the static ones.
2027#TODO: update the manifest to point to the package file
Dianne Hackborn9bd54042009-05-15 18:01:20 -07002028#Note that the version numbers are given to aapt as simple default
2029#values; applications can override these by explicitly stating
2030#them in their manifest.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002031define add-assets-to-package
Ying Wangc61d5932010-03-10 16:02:42 -08002032$(hide) $(AAPT) package -u $(PRIVATE_AAPT_FLAGS) \
Ying Wang4f1ab922011-03-15 13:19:30 -07002033 $(addprefix -c , $(PRIVATE_PRODUCT_AAPT_CONFIG)) \
Adam Lesinski2d1718a2014-05-09 10:57:48 -07002034 $(addprefix --preferred-density , $(PRIVATE_PRODUCT_AAPT_PREF_CONFIG)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08002035 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
2036 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
2037 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
2038 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
Ying Wangbb9c2302011-04-08 17:27:35 -07002039 $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
2040 $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
Ying Wangf39752e2014-03-20 17:28:57 -07002041 $(if $(filter --product,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --product , $(TARGET_AAPT_CHARACTERISTICS))) \
Ying Wang1ae607a2010-06-23 13:34:22 -07002042 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-code , $(PLATFORM_SDK_VERSION))) \
Ying Wang8f5069b2010-06-29 11:08:13 -07002043 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --version-name , $(PLATFORM_VERSION)-$(BUILD_NUMBER))) \
Jeff Hamiltonbb67d212010-02-05 22:36:42 -06002044 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07002045 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \
Adrian Roos6784cae2015-06-01 18:24:41 -07002046 --skip-symbols-without-default-localization \
The Android Open Source Project88b60792009-03-03 19:28:42 -08002047 -F $@
2048endef
2049
Ying Wang8e20ef62014-06-24 20:01:52 -07002050# We need the extra blank line, so that the command will be on a separate line.
2051# $(1): the ABI name
2052# $(2): the list of shared libraies
2053define _add-jni-shared-libs-to-package-per-abi
2054$(hide) cp $(2) $(dir $@)lib/$(1)
2055
2056endef
2057
Ying Wang1f8964d2015-07-15 18:33:24 -07002058# For apps_only build, don't uncompress/page-align the jni libraries,
2059# because the apk may be run on older platforms that don't support loading jni directly from apk.
2060ifdef TARGET_BUILD_APPS
2061JNI_COMPRESS_FLAGS :=
2062ZIPALIGN_PAGE_ALIGN_FLAGS :=
2063else
2064JNI_COMPRESS_FLAGS := -0
2065ZIPALIGN_PAGE_ALIGN_FLAGS := -p
2066endif
2067
The Android Open Source Project88b60792009-03-03 19:28:42 -08002068define add-jni-shared-libs-to-package
2069$(hide) rm -rf $(dir $@)lib
Ying Wang8e20ef62014-06-24 20:01:52 -07002070$(hide) mkdir -p $(addprefix $(dir $@)lib/,$(PRIVATE_JNI_SHARED_LIBRARIES_ABI))
2071$(foreach abi,$(PRIVATE_JNI_SHARED_LIBRARIES_ABI),\
2072 $(call _add-jni-shared-libs-to-package-per-abi,$(abi),\
2073 $(patsubst $(abi):%,%,$(filter $(abi):%,$(PRIVATE_JNI_SHARED_LIBRARIES)))))
Ying Wang1f8964d2015-07-15 18:33:24 -07002074$(hide) (cd $(dir $@) && zip -r $(JNI_COMPRESS_FLAGS) $(notdir $@) lib)
The Android Open Source Project88b60792009-03-03 19:28:42 -08002075$(hide) rm -rf $(dir $@)lib
2076endef
2077
The Android Open Source Project88b60792009-03-03 19:28:42 -08002078#TODO: update the manifest to point to the dex file
2079define add-dex-to-package
Ying Wangaf9757e2014-07-17 21:24:42 -07002080$(hide) zip -qj $@ $(dir $(PRIVATE_DEX_FILE))classes*.dex
The Android Open Source Project88b60792009-03-03 19:28:42 -08002081endef
2082
Ying Wang85480622012-08-09 15:20:50 -07002083# Add java resources added by the current module.
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002084# $(1) destination package
2085#
2086define add-java-resources-to
2087$(call dump-words-to-file, $(PRIVATE_EXTRA_JAR_ARGS), $(1).jar-arg-list)
2088$(hide) jar uf $(1) @$(1).jar-arg-list
2089@rm -f $(1).jar-arg-list
2090endef
2091
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002092# Add resources carried by static Jack libraries.
2093#
2094define add-carried-jack-resources
2095 $(hide) if [ -d $(PRIVATE_JACK_INTERMEDIATES_DIR) ] ; then \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002096 jack_res_jar_flags=$$(find $(PRIVATE_JACK_INTERMEDIATES_DIR) -type f \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002097 | sed -e "s?^$(PRIVATE_JACK_INTERMEDIATES_DIR)/? -C $(PRIVATE_JACK_INTERMEDIATES_DIR) ?"); \
2098 if [ -n "$$jack_res_jar_flags" ] ; then \
2099 echo $$jack_res_jar_flags >$(dir $@)jack_res_jar_flags; \
2100 jar uf $@ $$jack_res_jar_flags; \
2101 fi; \
2102fi
2103endef
2104
The Android Open Source Project88b60792009-03-03 19:28:42 -08002105# Sign a package using the specified key/cert.
2106#
2107define sign-package
2108$(hide) mv $@ $@.unsigned
2109$(hide) java -jar $(SIGNAPK_JAR) \
Ying Wang31df0682012-11-13 10:55:28 -08002110 $(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) \
2111 $(PRIVATE_ADDITIONAL_CERTIFICATES) $@.unsigned $@.signed
The Android Open Source Project88b60792009-03-03 19:28:42 -08002112$(hide) mv $@.signed $@
2113endef
2114
Dmitriy Ivanov13e59652014-07-23 15:27:21 -07002115# Align STORED entries of a package on 4-byte boundaries to make them easier to mmap.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002116#
2117define align-package
2118$(hide) mv $@ $@.unaligned
Dmitriy Ivanov13e59652014-07-23 15:27:21 -07002119$(hide) $(ZIPALIGN) \
Ying Wang1f8964d2015-07-15 18:33:24 -07002120 -f \
2121 $(ZIPALIGN_PAGE_ALIGN_FLAGS) \
Dmitriy Ivanov13e59652014-07-23 15:27:21 -07002122 4 \
2123 $@.unaligned $@.aligned
The Android Open Source Project88b60792009-03-03 19:28:42 -08002124$(hide) mv $@.aligned $@
2125endef
2126
Ying Wang1fb01522015-05-01 14:02:26 -07002127# Uncompress shared libraries embedded in an apk.
2128#
Nick Kralevich5aa02232015-04-17 16:53:15 -07002129define uncompress-shared-libs
Ying Wang1fb01522015-05-01 14:02:26 -07002130$(hide) if unzip -l $@ $(PRIVATE_EMBEDDED_JNI_LIBS) >/dev/null ; then \
2131 rm -rf $(dir $@)uncompressedlibs && mkdir $(dir $@)uncompressedlibs; \
2132 unzip $@ $(PRIVATE_EMBEDDED_JNI_LIBS) -d $(dir $@)uncompressedlibs && \
2133 zip -d $@ 'lib/*.so' && \
2134 ( cd $(dir $@)uncompressedlibs && zip -D -r -0 ../$(notdir $@) lib ) && \
2135 rm -rf $(dir $@)uncompressedlibs; \
2136 fi
Nick Kralevich5aa02232015-04-17 16:53:15 -07002137endef
2138
The Android Open Source Project88b60792009-03-03 19:28:42 -08002139define install-dex-debug
2140$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.dex" ]; then \
2141 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
2142 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.dex \
2143 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).dex; \
2144 fi
2145$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.lst" ]; then \
2146 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
2147 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.lst \
2148 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).lst; \
2149 fi
2150endef
2151
2152# TODO(joeo): If we can ever upgrade to post 3.81 make and get the
2153# new prebuilt rules to work, we should change this to copy the
2154# resources to the out directory and then copy the resources.
2155
Brian Carlstrom78269512010-12-10 12:10:24 -08002156# Note: we intentionally don't clean PRIVATE_CLASS_INTERMEDIATES_DIR
2157# in transform-java-to-classes for the sake of vm-tests.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002158define transform-host-java-to-package
Chirayu Desaiad48df42012-10-13 13:05:29 +05302159@echo -e ${CL_YLW}"host Java:"${CL_RST}" $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
Ying Wang015edd22011-01-20 15:01:56 -08002160$(call compile-java,$(HOST_JAVAC),$(PRIVATE_BOOTCLASSPATH))
The Android Open Source Project88b60792009-03-03 19:28:42 -08002161endef
2162
2163###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08002164## Commands for copying files
2165###########################################################
2166
2167# Define a rule to copy a header. Used via $(eval) by copy_headers.make.
2168# $(1): source header
2169# $(2): destination header
2170define copy-one-header
2171$(2): $(1)
Chirayu Desaiad48df42012-10-13 13:05:29 +05302172 @echo -e ${CL_YLW}"Header:"${CL_RST}" $$@"
The Android Open Source Project88b60792009-03-03 19:28:42 -08002173 $$(copy-file-to-new-target-with-cp)
2174endef
2175
2176# Define a rule to copy a file. For use via $(eval).
2177# $(1): source file
2178# $(2): destination file
2179define copy-one-file
2180$(2): $(1) | $(ACP)
Chirayu Desaiad48df42012-10-13 13:05:29 +05302181 @echo -e ${CL_YLW}"Copy:"${CL_RST}" $$@"
The Android Open Source Project88b60792009-03-03 19:28:42 -08002182 $$(copy-file-to-target)
2183endef
2184
Joe Onoratoe44705a2012-05-17 17:12:04 -07002185# Copies many files.
2186# $(1): The files to copy. Each entry is a ':' separated src:dst pair
2187# Evaluates to the list of the dst files (ie suitable for a dependency list)
2188define copy-many-files
2189$(foreach f, $(1), $(strip \
2190 $(eval _cmf_tuple := $(subst :, ,$(f))) \
2191 $(eval _cmf_src := $(word 1,$(_cmf_tuple))) \
2192 $(eval _cmf_dest := $(word 2,$(_cmf_tuple))) \
2193 $(eval $(call copy-one-file,$(_cmf_src),$(_cmf_dest))) \
2194 $(_cmf_dest)))
2195endef
2196
Ying Wang3ceecfa2012-05-14 14:39:00 -07002197# Copy the file only if it's a well-formed xml file. For use via $(eval).
2198# $(1): source file
2199# $(2): destination file, must end with .xml.
2200define copy-xml-file-checked
2201$(2): $(1) | $(ACP)
Chirayu Desaiad48df42012-10-13 13:05:29 +05302202 @echo -e ${CL_YLW}"Copy xml:"${CL_RST}" $$@"
Ying Wang3ceecfa2012-05-14 14:39:00 -07002203 $(hide) xmllint $$< >/dev/null # Don't print the xml file to stdout.
2204 $$(copy-file-to-target)
2205endef
2206
The Android Open Source Project88b60792009-03-03 19:28:42 -08002207# The -t option to acp and the -p option to cp is
2208# required for OSX. OSX has a ridiculous restriction
2209# where it's an error for a .a file's modification time
2210# to disagree with an internal timestamp, and this
2211# macro is used to install .a files (among other things).
2212
2213# Copy a single file from one place to another,
2214# preserving permissions and overwriting any existing
2215# file.
Ian Rogers76a6dc32012-10-01 16:36:23 -07002216# We disable the "-t" option for acp cannot handle
Ying Wang84ed6fa2011-01-18 17:21:20 -08002217# high resolution timestamp correctly on file systems like ext4.
2218# Therefore copy-file-to-target is the same as copy-file-to-new-target.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002219define copy-file-to-target
2220@mkdir -p $(dir $@)
Ying Wang84ed6fa2011-01-18 17:21:20 -08002221$(hide) $(ACP) -fp $< $@
The Android Open Source Project88b60792009-03-03 19:28:42 -08002222endef
2223
2224# The same as copy-file-to-target, but use the local
2225# cp command instead of acp.
2226define copy-file-to-target-with-cp
2227@mkdir -p $(dir $@)
2228$(hide) cp -fp $< $@
2229endef
2230
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07002231# The same as copy-file-to-target, but use the zipalign tool to do so.
2232define copy-file-to-target-with-zipalign
2233@mkdir -p $(dir $@)
2234$(hide) $(ZIPALIGN) -f 4 $< $@
2235endef
2236
Doug Zongker1046d202009-08-06 13:02:19 -07002237# The same as copy-file-to-target, but strip out "# comment"-style
2238# comments (for config files and such).
2239define copy-file-to-target-strip-comments
2240@mkdir -p $(dir $@)
2241$(hide) sed -e 's/#.*$$//' -e 's/[ \t]*$$//' -e '/^$$/d' < $< > $@
2242endef
2243
The Android Open Source Project88b60792009-03-03 19:28:42 -08002244# The same as copy-file-to-target, but don't preserve
2245# the old modification time.
2246define copy-file-to-new-target
2247@mkdir -p $(dir $@)
2248$(hide) $(ACP) -fp $< $@
2249endef
2250
2251# The same as copy-file-to-new-target, but use the local
2252# cp command instead of acp.
2253define copy-file-to-new-target-with-cp
2254@mkdir -p $(dir $@)
2255$(hide) cp -f $< $@
2256endef
2257
2258# Copy a prebuilt file to a target location.
2259define transform-prebuilt-to-target
Oliver Middletond01d6b82014-10-12 22:11:26 +01002260@echo -e ${CL_CYN}"$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
The Android Open Source Project88b60792009-03-03 19:28:42 -08002261$(copy-file-to-target)
2262endef
2263
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07002264# Copy a prebuilt file to a target location, using zipalign on it.
2265define transform-prebuilt-to-target-with-zipalign
Oliver Middletond01d6b82014-10-12 22:11:26 +01002266@echo -e ${CL_CYN}"$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt APK:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07002267$(copy-file-to-target-with-zipalign)
2268endef
2269
Doug Zongker1046d202009-08-06 13:02:19 -07002270# Copy a prebuilt file to a target location, stripping "# comment" comments.
2271define transform-prebuilt-to-target-strip-comments
Oliver Middletond01d6b82014-10-12 22:11:26 +01002272@echo -e ${CL_CYN}"$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Doug Zongker1046d202009-08-06 13:02:19 -07002273$(copy-file-to-target-strip-comments)
2274endef
2275
Ying Wangc45a47b2015-04-08 12:24:37 -07002276# Copy a list of files/directories to target location, with sub dir structure preserved.
2277# For example $(HOST_OUT_EXECUTABLES)/aapt -> $(staging)/bin/aapt .
2278# $(1): the source list of files/directories.
2279# $(2): the path prefix to strip. In the above example it would be $(HOST_OUT).
2280# $(3): the target location.
2281define copy-files-with-structure
2282$(foreach t,$(1),\
2283 $(eval s := $(patsubst $(2)%,%,$(t)))\
2284 $(hide) mkdir -p $(dir $(3)/$(s)); cp -Rf $(t) $(3)/$(s)$(newline))
2285endef
2286
The Android Open Source Project88b60792009-03-03 19:28:42 -08002287
2288###########################################################
Ying Wang3b2bdf12010-02-01 09:51:23 -08002289## Commands to call Proguard
2290###########################################################
nuclearmistake451a31b2014-04-27 21:59:42 -04002291@echo -e ${CL_CYN}"Copying:"${CL_RST}" $@"
2292@echo -e ${CL_GRN}"Proguard:"${CL_RST}" $@"
Ying Wang3b2bdf12010-02-01 09:51:23 -08002293define transform-jar-to-proguard
Mihail Dumitrescu4df82b32014-02-07 15:18:59 +00002294$(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS) \
2295 $(addprefix -injars , $(PRIVATE_EXTRA_INPUT_JAR))
Ying Wang3b2bdf12010-02-01 09:51:23 -08002296endef
2297
Ying Wang3b2bdf12010-02-01 09:51:23 -08002298###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08002299## Stuff source generated from one-off tools
2300###########################################################
2301
2302define transform-generated-source
Chirayu Desaiad48df42012-10-13 13:05:29 +05302303@echo -e ${CL_GRN}"target Generated:"${CL_RST}" $(PRIVATE_MODULE) <= $<"
The Android Open Source Project88b60792009-03-03 19:28:42 -08002304@mkdir -p $(dir $@)
2305$(hide) $(PRIVATE_CUSTOM_TOOL)
2306endef
2307
2308
2309###########################################################
2310## Assertions about attributes of the target
2311###########################################################
2312
2313# $(1): The file to check
2314ifndef get-file-size
2315$(error HOST_OS must define get-file-size)
2316endif
2317
Doug Zongker4647f122009-07-02 09:00:54 -07002318# Convert a partition data size (eg, as reported in /proc/mtd) to the
2319# size of the image used to flash that partition (which includes a
Lars Svensson9cb8c282010-12-06 15:24:58 +01002320# spare area for each page).
Doug Zongker4647f122009-07-02 09:00:54 -07002321# $(1): the partition data size
2322define image-size-from-data-size
Ying Wang4a2ecaf2011-02-09 17:24:27 -08002323$(strip $(eval _isfds_value := $$(shell echo $$$$(($(1) / $(BOARD_NAND_PAGE_SIZE) * \
2324 ($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE))))))\
2325$(if $(filter 0, $(_isfds_value)),$(shell echo $$(($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE)))),$(_isfds_value))\
2326$(eval _isfds_value :=))
Doug Zongker4647f122009-07-02 09:00:54 -07002327endef
2328
2329# $(1): The file(s) to check (often $@)
JP Abgrall0ed7cec2014-06-16 14:19:36 -07002330# $(2): The maximum total image size, in decimal bytes.
2331# Make sure to take into account any reserved space needed for the FS.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002332#
2333# If $(2) is empty, evaluates to "true"
2334#
2335# Reserve bad blocks. Make sure that MAX(1% of partition size, 2 blocks)
2336# is left over after the image has been flashed. Round the 1% up to the
2337# next whole flash block size.
2338define assert-max-file-size
2339$(if $(2), \
Doug Zongker742fa572009-07-08 12:09:04 -07002340 size=$$(for i in $(1); do $(call get-file-size,$$i); echo +; done; echo 0); \
2341 total=$$(( $$( echo "$$size" ) )); \
Doug Zongker4647f122009-07-02 09:00:54 -07002342 printname=$$(echo -n "$(1)" | tr " " +); \
Doug Zongker4647f122009-07-02 09:00:54 -07002343 img_blocksize=$(call image-size-from-data-size,$(BOARD_FLASH_BLOCK_SIZE)); \
2344 twoblocks=$$((img_blocksize * 2)); \
2345 onepct=$$((((($(2) / 100) - 1) / img_blocksize + 1) * img_blocksize)); \
JP Abgrall0ed7cec2014-06-16 14:19:36 -07002346 reserve=$$((twoblocks > onepct ? twoblocks : onepct)); \
Doug Zongker4647f122009-07-02 09:00:54 -07002347 maxsize=$$(($(2) - reserve)); \
Ying Wang99bcbeb2011-12-02 10:34:45 -08002348 echo "$$printname maxsize=$$maxsize blocksize=$$img_blocksize total=$$total reserve=$$reserve"; \
Doug Zongker4647f122009-07-02 09:00:54 -07002349 if [ "$$total" -gt "$$maxsize" ]; then \
2350 echo "error: $$printname too large ($$total > [$(2) - $$reserve])"; \
2351 false; \
Doug Zongker742fa572009-07-08 12:09:04 -07002352 elif [ "$$total" -gt $$((maxsize - 32768)) ]; then \
Doug Zongker4647f122009-07-02 09:00:54 -07002353 echo "WARNING: $$printname approaching size limit ($$total now; limit $$maxsize)"; \
The Android Open Source Project88b60792009-03-03 19:28:42 -08002354 fi \
2355 , \
2356 true \
2357 )
2358endef
2359
Doug Zongker8510a1e2009-08-07 16:38:08 -07002360# Like assert-max-file-size, but the second argument is a partition
2361# size, which we'll convert to a max image size before checking it
2362# against the files.
2363#
2364# $(1): The file(s) to check (often $@)
2365# $(2): The partition size.
2366define assert-max-image-size
2367$(if $(2), \
JP Abgrall0ed7cec2014-06-16 14:19:36 -07002368 $(call assert-max-file-size,$(1),$(call image-size-from-data-size,$(2))))
Doug Zongker8510a1e2009-08-07 16:38:08 -07002369endef
2370
Doug Zongkere01100c2009-06-19 17:12:18 -07002371
2372###########################################################
2373## Define device-specific radio files
2374###########################################################
Ying Wang94de1eb2013-07-26 12:19:20 -07002375INSTALLED_RADIOIMAGE_TARGET :=
Doug Zongkere01100c2009-06-19 17:12:18 -07002376
2377# Copy a radio image file to the output location, and add it to
2378# INSTALLED_RADIOIMAGE_TARGET.
2379# $(1): filename
2380define add-radio-file
Doug Zongker14833602010-02-02 13:12:04 -08002381 $(eval $(call add-radio-file-internal,$(1),$(notdir $(1))))
Doug Zongkere01100c2009-06-19 17:12:18 -07002382endef
2383define add-radio-file-internal
Doug Zongker14833602010-02-02 13:12:04 -08002384INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
Doug Zongker14833602010-02-02 13:12:04 -08002385$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP)
Doug Zongkere01100c2009-06-19 17:12:18 -07002386 $$(transform-prebuilt-to-target)
2387endef
2388
Doug Zongker9296f092012-03-20 16:42:22 -07002389# Version of add-radio-file that also arranges for the version of the
2390# file to be checked against the contents of
2391# $(TARGET_BOARD_INFO_FILE).
2392# $(1): filename
2393# $(2): name of version variable in board-info (eg, "version-baseband")
2394define add-radio-file-checked
2395 $(eval $(call add-radio-file-checked-internal,$(1),$(notdir $(1)),$(2)))
2396endef
2397define add-radio-file-checked-internal
2398INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
2399BOARD_INFO_CHECK += $(3):$(LOCAL_PATH)/$(1)
2400$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP)
2401 $$(transform-prebuilt-to-target)
2402endef
2403
Doug Zongkere01100c2009-06-19 17:12:18 -07002404
The Android Open Source Project88b60792009-03-03 19:28:42 -08002405###########################################################
Joe Onorato899e62a2010-02-04 17:37:21 -08002406# Override the package defined in $(1), setting the
2407# variables listed below differently.
2408#
2409# $(1): The makefile to override (relative to the source
2410# tree root)
2411# $(2): Old LOCAL_PACKAGE_NAME value.
2412# $(3): New LOCAL_PACKAGE_NAME value.
Ying Wang3dae0ee2010-09-02 15:41:01 -07002413# $(4): New LOCAL_MANIFEST_PACKAGE_NAME value.
2414# $(5): New LOCAL_CERTIFICATE value.
2415# $(6): New LOCAL_INSTRUMENTATION_FOR value.
2416# $(7): New LOCAL_MANIFEST_INSTRUMENTATION_FOR value.
Joe Onorato899e62a2010-02-04 17:37:21 -08002417#
2418# Note that LOCAL_PACKAGE_OVERRIDES is NOT cleared in
2419# clear_vars.mk.
2420###########################################################
2421define inherit-package
Ying Wang3dae0ee2010-09-02 15:41:01 -07002422 $(eval $(call inherit-package-internal,$(1),$(2),$(3),$(4),$(5),$(6),$(7)))
Joe Onorato899e62a2010-02-04 17:37:21 -08002423endef
2424
2425define inherit-package-internal
2426 LOCAL_PACKAGE_OVERRIDES \
Ying Wang3dae0ee2010-09-02 15:41:01 -07002427 := $(strip $(1))||$(strip $(2))||$(strip $(3))||$(strip $(4))||&&$(strip $(5))||&&$(strip $(6))||&&$(strip $(7)) $(LOCAL_PACKAGE_OVERRIDES)
Joe Onorato899e62a2010-02-04 17:37:21 -08002428 include $(1)
2429 LOCAL_PACKAGE_OVERRIDES \
2430 := $(wordlist 1,$(words $(LOCAL_PACKAGE_OVERRIDES)), $(LOCAL_PACKAGE_OVERRIDES))
2431endef
2432
2433# To be used with inherit-package above
2434# Evalutes to true if the package was overridden
2435define set-inherited-package-variables
2436$(strip $(call set-inherited-package-variables-internal))
2437endef
2438
2439define keep-or-override
2440$(eval $(1) := $(if $(2),$(2),$($(1))))
2441endef
2442
2443define set-inherited-package-variables-internal
2444 $(eval _o := $(subst ||, ,$(lastword $(LOCAL_PACKAGE_OVERRIDES))))
2445 $(eval _n := $(subst ||, ,$(firstword $(LOCAL_PACKAGE_OVERRIDES))))
2446 $(if $(filter $(word 2,$(_n)),$(LOCAL_PACKAGE_NAME)), \
2447 $(eval LOCAL_PACKAGE_NAME := $(word 3,$(_o))) \
2448 $(eval LOCAL_MANIFEST_PACKAGE_NAME := $(word 4,$(_o))) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07002449 $(call keep-or-override,LOCAL_CERTIFICATE,$(patsubst &&%,%,$(word 5,$(_o)))) \
2450 $(call keep-or-override,LOCAL_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 6,$(_o)))) \
2451 $(call keep-or-override,LOCAL_MANIFEST_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 7,$(_o)))) \
Joe Onorato899e62a2010-02-04 17:37:21 -08002452 $(eval LOCAL_OVERRIDES_PACKAGES := $(sort $(LOCAL_OVERRIDES_PACKAGES) $(word 2,$(_o)))) \
2453 true \
2454 ,)
2455endef
2456
Ying Wang000e89a2012-04-30 15:48:27 -07002457###########################################################
Ying Wangc065da22012-11-14 15:57:07 -08002458## API Check
2459###########################################################
2460
2461# eval this to define a rule that runs apicheck.
2462#
2463# Args:
2464# $(1) target
2465# $(2) stable api file
2466# $(3) api file to be tested
Hui Shuec21c582014-03-13 16:21:08 -07002467# $(4) stable removed api file
Hui Shue8af17e2014-02-21 14:18:19 -08002468# $(5) removed api file to be tested
2469# $(6) arguments for apicheck
2470# $(7) command to run if apicheck failed
2471# $(8) target dependent on this api check
2472# $(9) additional dependencies
Ying Wangc065da22012-11-14 15:57:07 -08002473define check-api
Hui Shuec21c582014-03-13 16:21:08 -07002474$(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(strip $(1))-timestamp: $(2) $(3) $(4) $(APICHECK) $(9)
Ying Wangc065da22012-11-14 15:57:07 -08002475 @echo "Checking API:" $(1)
Hui Shue8af17e2014-02-21 14:18:19 -08002476 $(hide) ( $(APICHECK_COMMAND) $(6) $(2) $(3) $(4) $(5) || ( $(7) ; exit 38 ) )
Ying Wangc065da22012-11-14 15:57:07 -08002477 $(hide) mkdir -p $$(dir $$@)
2478 $(hide) touch $$@
Hui Shue8af17e2014-02-21 14:18:19 -08002479$(8): $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(strip $(1))-timestamp
Ying Wangc065da22012-11-14 15:57:07 -08002480endef
2481
Ying Wang63d94fa2012-12-13 18:23:01 -08002482## Whether to build from source if prebuilt alternative exists
2483###########################################################
2484# $(1): module name
2485# $(2): LOCAL_PATH
2486# Expands to empty string if not from source.
2487ifeq (true,$(ANDROID_BUILD_FROM_SOURCE))
2488define if-build-from-source
2489true
2490endef
2491else
2492define if-build-from-source
2493$(if $(filter $(ANDROID_NO_PREBUILT_MODULES),$(1))$(filter \
2494 $(addsuffix %,$(ANDROID_NO_PREBUILT_PATHS)),$(2)),true)
2495endef
2496endif
2497
2498# Include makefile $(1) if build from source for module $(2)
2499# $(1): the makefile to include
2500# $(2): module name
2501# $(3): LOCAL_PATH
2502define include-if-build-from-source
2503$(if $(call if-build-from-source,$(2),$(3)),$(eval include $(1)))
2504endef
2505
Ying Wanga6a6c352014-09-26 10:41:27 -07002506# Return the arch for the source file of a prebuilt
2507# Return "none" if no matching arch found, so the result can be passed to
2508# LOCAL_MODULE_TARGET_ARCH.
Ying Wangc0adfb72014-02-27 14:10:53 -08002509# $(1) the list of archs supported by the prebuilt
2510define get-prebuilt-src-arch
2511$(strip $(if $(filter $(TARGET_ARCH),$(1)),$(TARGET_ARCH),\
Ying Wanga6a6c352014-09-26 10:41:27 -07002512 $(if $(filter $(TARGET_2ND_ARCH),$(1)),$(TARGET_2ND_ARCH),none)))
Ying Wangc0adfb72014-02-27 14:10:53 -08002513endef
2514
Ying Wangc065da22012-11-14 15:57:07 -08002515###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08002516## Other includes
2517###########################################################
2518
2519# -----------------------------------------------------------------
2520# Rules and functions to help copy important files to DIST_DIR
2521# when requested.
2522include $(BUILD_SYSTEM)/distdir.mk
2523
Marie Lennerhagen9e5efce2010-10-20 13:41:59 +02002524# Include any vendor specific definitions.mk file
2525-include $(TOPDIR)vendor/*/build/core/definitions.mk
Andrew Boie388c04d2014-10-28 08:32:11 -07002526-include $(TOPDIR)device/*/build/core/definitions.mk
Marie Lennerhagen9e5efce2010-10-20 13:41:59 +02002527
The Android Open Source Project88b60792009-03-03 19:28:42 -08002528# broken:
2529# $(foreach file,$^,$(if $(findstring,.a,$(suffix $file)),-l$(file),$(file)))
2530
2531###########################################################
2532## Misc notes
2533###########################################################
2534
2535#DEPDIR = .deps
2536#df = $(DEPDIR)/$(*F)
2537
2538#SRCS = foo.c bar.c ...
2539
2540#%.o : %.c
2541# @$(MAKEDEPEND); \
2542# cp $(df).d $(df).P; \
2543# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
2544# -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \
2545# rm -f $(df).d
2546# $(COMPILE.c) -o $@ $<
2547
2548#-include $(SRCS:%.c=$(DEPDIR)/%.P)
2549
2550
2551#%.o : %.c
2552# $(COMPILE.c) -MD -o $@ $<
2553# @cp $*.d $*.P; \
2554# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
2555# -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \
2556# rm -f $*.d