blob: 5a8fc8d8929e8a28396638a71f59bebf58e2ece1 [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 :=
Dan Willemsen057aaea2015-08-14 12:59:50 -070090HOST_CROSS_DEPENDENCIES_ON_SHARED_LIBRARIES :=
Ying Wang9485a572013-02-22 14:32:30 -080091
Ying Wangae25ec12012-06-19 10:40:37 -070092# Generated class file names for Android resource.
93# They are escaped and quoted so can be passed safely to a bash command.
94ANDROID_RESOURCE_GENERATED_CLASSES := 'R.class' 'R$$*.class' 'Manifest.class' 'Manifest$$*.class'
95
Dan Willemsen057aaea2015-08-14 12:59:50 -070096# Display names for various build targets
97TARGET_DISPLAY := target
98HOST_DISPLAY := host
99HOST_CROSS_DISPLAY := host cross
100
The Android Open Source Project88b60792009-03-03 19:28:42 -0800101###########################################################
102## Debugging; prints a variable list to stdout
103###########################################################
104
105# $(1): variable name list, not variable values
106define print-vars
107$(foreach var,$(1), \
108 $(info $(var):) \
109 $(foreach word,$($(var)), \
110 $(info $(space)$(space)$(word)) \
111 ) \
112 )
113endef
114
115###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700116## Evaluates to true if the string contains the word true,
117## and empty otherwise
118## $(1): a var to test
119###########################################################
120
121define true-or-empty
122$(filter true, $(1))
123endef
124
125
126###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800127## Retrieve the directory of the current makefile
Ying Wang3bbfddd2014-03-01 15:32:04 -0800128## Must be called before including any other makefile!!
The Android Open Source Project88b60792009-03-03 19:28:42 -0800129###########################################################
130
131# Figure out where we are.
132define my-dir
Dave Bortb3926412009-05-19 16:12:22 -0700133$(strip \
Ying Wang68f1c772012-04-23 21:29:18 -0700134 $(eval LOCAL_MODULE_MAKEFILE := $$(lastword $$(MAKEFILE_LIST))) \
Colin Crossa4447e82015-09-28 16:26:00 -0700135 $(eval LOCAL_MODULE_MAKEFILE_DEP := $(if $(BUILDING_WITH_NINJA),,$$(LOCAL_MODULE_MAKEFILE))) \
Ying Wang3bbfddd2014-03-01 15:32:04 -0800136 $(if $(filter $(BUILD_SYSTEM)/% $(OUT_DIR)/%,$(LOCAL_MODULE_MAKEFILE)), \
137 $(error my-dir must be called before including any other makefile.) \
Dave Bortb3926412009-05-19 16:12:22 -0700138 , \
Ying Wang68f1c772012-04-23 21:29:18 -0700139 $(patsubst %/,%,$(dir $(LOCAL_MODULE_MAKEFILE))) \
Dave Bortb3926412009-05-19 16:12:22 -0700140 ) \
141 )
The Android Open Source Project88b60792009-03-03 19:28:42 -0800142endef
143
144###########################################################
145## Retrieve a list of all makefiles immediately below some directory
146###########################################################
147
148define all-makefiles-under
Dan Willemsenec224d52015-08-06 15:01:24 -0700149$(sort $(wildcard $(1)/*/Android.mk))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800150endef
151
152###########################################################
153## Look under a directory for makefiles that don't have parent
154## makefiles.
155###########################################################
156
157# $(1): directory to search under
158# Ignores $(1)/Android.mk
159define first-makefiles-under
JP Abgrall1390cac2013-07-11 19:08:06 -0700160$(shell build/tools/findleaves.py --prune=$(OUT_DIR) --prune=.repo --prune=.git \
Joe Onoratodc1a7282009-08-04 15:58:26 -0400161 --mindepth=2 $(1) Android.mk)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800162endef
163
164###########################################################
165## Retrieve a list of all makefiles immediately below your directory
Ying Wang3bbfddd2014-03-01 15:32:04 -0800166## Must be called before including any other makefile!!
The Android Open Source Project88b60792009-03-03 19:28:42 -0800167###########################################################
168
169define all-subdir-makefiles
170$(call all-makefiles-under,$(call my-dir))
171endef
172
173###########################################################
174## Look in the named list of directories for makefiles,
175## relative to the current directory.
Ying Wang3bbfddd2014-03-01 15:32:04 -0800176## Must be called before including any other makefile!!
The Android Open Source Project88b60792009-03-03 19:28:42 -0800177###########################################################
178
179# $(1): List of directories to look for under this directory
180define all-named-subdir-makefiles
Dan Willemsenec224d52015-08-06 15:01:24 -0700181$(sort $(wildcard $(addsuffix /Android.mk, $(addprefix $(call my-dir)/,$(1)))))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800182endef
183
184###########################################################
185## Find all of the java files under the named directories.
186## Meant to be used like:
187## SRC_FILES := $(call all-java-files-under,src tests)
188###########################################################
189
190define all-java-files-under
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700191$(sort $(patsubst ./%,%, \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800192 $(shell cd $(LOCAL_PATH) ; \
Conley Owensf4357392012-10-02 10:32:00 -0700193 find -L $(1) -name "*.java" -and -not -name ".*") \
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700194 ))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800195endef
196
197###########################################################
198## Find all of the java files from here. Meant to be used like:
199## SRC_FILES := $(call all-subdir-java-files)
200###########################################################
201
202define all-subdir-java-files
203$(call all-java-files-under,.)
204endef
205
206###########################################################
207## Find all of the c files under the named directories.
208## Meant to be used like:
209## SRC_FILES := $(call all-c-files-under,src tests)
210###########################################################
211
212define all-c-files-under
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700213$(sort $(patsubst ./%,%, \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800214 $(shell cd $(LOCAL_PATH) ; \
Conley Owensf4357392012-10-02 10:32:00 -0700215 find -L $(1) -name "*.c" -and -not -name ".*") \
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700216 ))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800217endef
218
219###########################################################
220## Find all of the c files from here. Meant to be used like:
221## SRC_FILES := $(call all-subdir-c-files)
222###########################################################
223
224define all-subdir-c-files
225$(call all-c-files-under,.)
226endef
227
228###########################################################
229## Find all files named "I*.aidl" under the named directories,
230## which must be relative to $(LOCAL_PATH). The returned list
231## is relative to $(LOCAL_PATH).
232###########################################################
233
234define all-Iaidl-files-under
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700235$(sort $(patsubst ./%,%, \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800236 $(shell cd $(LOCAL_PATH) ; \
Conley Owensf4357392012-10-02 10:32:00 -0700237 find -L $(1) -name "I*.aidl" -and -not -name ".*") \
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700238 ))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800239endef
240
241###########################################################
242## Find all of the "I*.aidl" files under $(LOCAL_PATH).
243###########################################################
244
245define all-subdir-Iaidl-files
246$(call all-Iaidl-files-under,.)
247endef
248
249###########################################################
Bjorn Bringerta89c9902010-02-02 17:36:20 +0000250## Find all of the logtags files under the named directories.
251## Meant to be used like:
252## SRC_FILES := $(call all-logtags-files-under,src)
253###########################################################
254
255define all-logtags-files-under
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700256$(sort $(patsubst ./%,%, \
Bjorn Bringerta89c9902010-02-02 17:36:20 +0000257 $(shell cd $(LOCAL_PATH) ; \
Conley Owensf4357392012-10-02 10:32:00 -0700258 find -L $(1) -name "*.logtags" -and -not -name ".*") \
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700259 ))
Bjorn Bringerta89c9902010-02-02 17:36:20 +0000260endef
261
262###########################################################
Ying Wanga5fc87a2010-11-02 18:43:16 -0700263## Find all of the .proto files under the named directories.
264## Meant to be used like:
265## SRC_FILES := $(call all-proto-files-under,src)
266###########################################################
267
268define all-proto-files-under
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700269$(sort $(patsubst ./%,%, \
Ying Wanga5fc87a2010-11-02 18:43:16 -0700270 $(shell cd $(LOCAL_PATH) ; \
Conley Owensf4357392012-10-02 10:32:00 -0700271 find -L $(1) -name "*.proto" -and -not -name ".*") \
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700272 ))
Ying Wanga5fc87a2010-11-02 18:43:16 -0700273endef
274
275###########################################################
Ying Wang0bd59a02010-07-15 17:17:52 -0700276## Find all of the RenderScript files under the named directories.
277## Meant to be used like:
278## SRC_FILES := $(call all-renderscript-files-under,src)
279###########################################################
280
281define all-renderscript-files-under
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700282$(sort $(patsubst ./%,%, \
Ying Wang0bd59a02010-07-15 17:17:52 -0700283 $(shell cd $(LOCAL_PATH) ; \
Stephen Hinesd2637572012-10-11 22:08:57 -0700284 find -L $(1) \( -name "*.rs" -or -name "*.fs" \) -and -not -name ".*") \
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700285 ))
Ying Wang0bd59a02010-07-15 17:17:52 -0700286endef
287
288###########################################################
Elliott Hughese3b044a2014-02-11 13:48:35 -0800289## Find all of the S files under the named directories.
290## Meant to be used like:
291## SRC_FILES := $(call all-c-files-under,src tests)
292###########################################################
293
294define all-S-files-under
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700295$(sort $(patsubst ./%,%, \
Elliott Hughese3b044a2014-02-11 13:48:35 -0800296 $(shell cd $(LOCAL_PATH) ; \
297 find -L $(1) -name "*.S" -and -not -name ".*") \
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700298 ))
Elliott Hughese3b044a2014-02-11 13:48:35 -0800299endef
300
301###########################################################
Jean-Baptiste Queru0a3cfdc2009-12-17 17:47:28 -0800302## Find all of the html files under the named directories.
303## Meant to be used like:
304## SRC_FILES := $(call all-html-files-under,src tests)
305###########################################################
306
307define all-html-files-under
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700308$(sort $(patsubst ./%,%, \
Jean-Baptiste Queru0a3cfdc2009-12-17 17:47:28 -0800309 $(shell cd $(LOCAL_PATH) ; \
Conley Owensf4357392012-10-02 10:32:00 -0700310 find -L $(1) -name "*.html" -and -not -name ".*") \
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700311 ))
Jean-Baptiste Queru0a3cfdc2009-12-17 17:47:28 -0800312endef
313
314###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800315## Find all of the html files from here. Meant to be used like:
316## SRC_FILES := $(call all-subdir-html-files)
317###########################################################
318
319define all-subdir-html-files
Jean-Baptiste Queru0a3cfdc2009-12-17 17:47:28 -0800320$(call all-html-files-under,.)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800321endef
322
323###########################################################
324## Find all of the files matching pattern
325## SRC_FILES := $(call find-subdir-files, <pattern>)
326###########################################################
327
328define find-subdir-files
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700329$(sort $(patsubst ./%,%,$(shell cd $(LOCAL_PATH) ; find -L $(1))))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800330endef
331
332###########################################################
333# find the files in the subdirectory $1 of LOCAL_DIR
334# matching pattern $2, filtering out files $3
335# e.g.
336# SRC_FILES += $(call find-subdir-subdir-files, \
337# css, *.cpp, DontWantThis.cpp)
338###########################################################
339
340define find-subdir-subdir-files
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700341$(sort $(filter-out $(patsubst %,$(1)/%,$(3)),$(patsubst ./%,%,$(shell cd \
342 $(LOCAL_PATH) ; find -L $(1) -maxdepth 1 -name $(2)))))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800343endef
344
345###########################################################
346## Find all of the files matching pattern
347## SRC_FILES := $(call all-subdir-java-files)
348###########################################################
349
350define find-subdir-assets
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700351$(sort $(if $(1),$(patsubst ./%,%, \
Ying Wang6ab5d6a2011-08-10 16:05:51 -0700352 $(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 -0800353 $(warning Empty argument supplied to find-subdir-assets) \
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700354))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800355endef
356
357###########################################################
358## Find various file types in a list of directories relative to $(LOCAL_PATH)
359###########################################################
360
361define find-other-java-files
362 $(call find-subdir-files,$(1) -name "*.java" -and -not -name ".*")
363endef
364
365define find-other-html-files
366 $(call find-subdir-files,$(1) -name "*.html" -and -not -name ".*")
367endef
368
369###########################################################
Ying Wang85898bc2013-12-04 16:04:49 -0800370# Use utility find to find given files in the given subdirs.
371# This function uses $(1), instead of LOCAL_PATH as the base.
372# $(1): the base dir, relative to the root of the source tree.
373# $(2): the file name pattern to be passed to find as "-name".
374# $(3): a list of subdirs of the base dir.
375# Returns: a list of paths relative to the base dir.
376###########################################################
377
378define find-files-in-subdirs
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700379$(sort $(patsubst ./%,%, \
Ying Wang85898bc2013-12-04 16:04:49 -0800380 $(shell cd $(1) ; \
381 find -L $(3) -name $(2) -and -not -name ".*") \
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700382 ))
Ying Wang85898bc2013-12-04 16:04:49 -0800383endef
384
385###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800386## Scan through each directory of $(1) looking for files
387## that match $(2) using $(wildcard). Useful for seeing if
388## a given directory or one of its parents contains
389## a particular file. Returns the first match found,
390## starting furthest from the root.
391###########################################################
392
393define find-parent-file
394$(strip \
Ying Wanga67ce692011-03-03 13:29:38 -0800395 $(eval _fpf := $(wildcard $(foreach f, $(2), $(strip $(1))/$(f)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800396 $(if $(_fpf),$(_fpf), \
397 $(if $(filter-out ./ .,$(1)), \
398 $(call find-parent-file,$(patsubst %/,%,$(dir $(1))),$(2)) \
399 ) \
400 ) \
401)
402endef
403
404###########################################################
405## Function we can evaluate to introduce a dynamic dependency
406###########################################################
407
408define add-dependency
409$(1): $(2)
410endef
411
412###########################################################
Yohann Rousself09e59e2014-09-08 14:45:14 +0200413## Reverse order of a list
414###########################################################
415
416define reverse-list
417$(if $(1),$(call reverse-list,$(wordlist 2,$(words $(1)),$(1)))) $(firstword $(1))
418endef
419
420###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800421## The intermediates directory. Where object files go for
422## a given target. We could technically get away without
423## the "_intermediates" suffix on the directory, but it's
424## nice to be able to grep for that string to find out if
425## anyone's abusing the system.
426###########################################################
427
428# $(1): target class, like "APPS"
429# $(2): target name, like "NotePad"
430# $(3): if non-empty, this is a HOST target.
431# $(4): if non-empty, force the intermediates to be COMMON
Dan Willemsen057aaea2015-08-14 12:59:50 -0700432# $(5): if non-empty, force the intermediates to be for the 2nd arch
433# $(6): if non-empty, force the intermediates to be for the host cross os
The Android Open Source Project88b60792009-03-03 19:28:42 -0800434define intermediates-dir-for
435$(strip \
436 $(eval _idfClass := $(strip $(1))) \
437 $(if $(_idfClass),, \
438 $(error $(LOCAL_PATH): Class not defined in call to intermediates-dir-for)) \
439 $(eval _idfName := $(strip $(2))) \
440 $(if $(_idfName),, \
441 $(error $(LOCAL_PATH): Name not defined in call to intermediates-dir-for)) \
Dan Willemsen057aaea2015-08-14 12:59:50 -0700442 $(eval _idfPrefix := $(if $(strip $(3)),$(if $(strip $(6)),HOST_CROSS,HOST),TARGET)) \
Colin Crossae2986e2014-06-17 21:35:44 -0700443 $(eval _idf2ndArchPrefix := $(if $(strip $(5)),$(TARGET_2ND_ARCH_VAR_PREFIX))) \
Ying Wanga83940f2010-09-24 18:09:04 -0700444 $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800445 $(eval _idfIntBase := $($(_idfPrefix)_OUT_COMMON_INTERMEDIATES)) \
Ying Wang6feb6d52014-04-17 10:03:35 -0700446 ,$(if $(filter $(_idfClass),SHARED_LIBRARIES STATIC_LIBRARIES EXECUTABLES GYP),\
Colin Cross02e31d22014-01-24 13:38:08 -0800447 $(eval _idfIntBase := $($(_idf2ndArchPrefix)$(_idfPrefix)_OUT_INTERMEDIATES)) \
448 ,$(eval _idfIntBase := $($(_idfPrefix)_OUT_INTERMEDIATES)) \
449 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800450 ) \
451 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
452)
453endef
454
455# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE
456# to determine the intermediates directory.
457#
458# $(1): if non-empty, force the intermediates to be COMMON
Ying Wang61d499b2014-01-15 16:02:16 -0800459# $(2): if non-empty, force the intermediates to be for the 2nd arch
Dan Willemsen057aaea2015-08-14 12:59:50 -0700460# $(3): if non-empty, force the intermediates to be for the host cross os
The Android Open Source Project88b60792009-03-03 19:28:42 -0800461define local-intermediates-dir
462$(strip \
463 $(if $(strip $(LOCAL_MODULE_CLASS)),, \
464 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-intermediates-dir)) \
465 $(if $(strip $(LOCAL_MODULE)),, \
466 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-intermediates-dir)) \
Dan Willemsen057aaea2015-08-14 12:59:50 -0700467 $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(LOCAL_IS_HOST_MODULE),$(1),$(2),$(3)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800468)
469endef
470
471###########################################################
Colin Crossd8262642014-01-24 23:17:21 -0800472## The generated sources directory. Placing generated
473## source files directly in the intermediates directory
474## causes problems for multiarch builds, where there are
475## two intermediates directories for a single target. Put
476## them in a separate directory, and they will be copied to
477## each intermediates directory automatically.
478###########################################################
479
480# $(1): target class, like "APPS"
481# $(2): target name, like "NotePad"
482# $(3): if non-empty, this is a HOST target.
483# $(4): if non-empty, force the generated sources to be COMMON
484define generated-sources-dir-for
485$(strip \
486 $(eval _idfClass := $(strip $(1))) \
487 $(if $(_idfClass),, \
488 $(error $(LOCAL_PATH): Class not defined in call to generated-sources-dir-for)) \
489 $(eval _idfName := $(strip $(2))) \
490 $(if $(_idfName),, \
491 $(error $(LOCAL_PATH): Name not defined in call to generated-sources-dir-for)) \
492 $(eval _idfPrefix := $(if $(strip $(3)),HOST,TARGET)) \
493 $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
494 $(eval _idfIntBase := $($(_idfPrefix)_OUT_GEN_COMMON)) \
495 , \
496 $(eval _idfIntBase := $($(_idfPrefix)_OUT_GEN)) \
497 ) \
498 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
499)
500endef
501
502# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE
503# to determine the generated sources directory.
504#
505# $(1): if non-empty, force the intermediates to be COMMON
506define local-generated-sources-dir
507$(strip \
508 $(if $(strip $(LOCAL_MODULE_CLASS)),, \
509 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-generated-sources-dir)) \
510 $(if $(strip $(LOCAL_MODULE)),, \
511 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-generated-sources-dir)) \
512 $(call generated-sources-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(LOCAL_IS_HOST_MODULE),$(1)) \
513)
514endef
515
516###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800517## Convert "path/to/libXXX.so" to "-lXXX".
518## Any "path/to/libXXX.a" elements pass through unchanged.
519###########################################################
520
521define normalize-libraries
522$(foreach so,$(filter %.so,$(1)),-l$(patsubst lib%.so,%,$(notdir $(so))))\
523$(filter-out %.so,$(1))
524endef
525
526# TODO: change users to call the common version.
527define normalize-host-libraries
528$(call normalize-libraries,$(1))
529endef
530
531define normalize-target-libraries
532$(call normalize-libraries,$(1))
533endef
534
535###########################################################
536## Convert a list of short module names (e.g., "framework", "Browser")
537## into the list of files that are built for those modules.
538## NOTE: this won't return reliable results until after all
539## sub-makefiles have been included.
540## $(1): target list
541###########################################################
542
543define module-built-files
544$(foreach module,$(1),$(ALL_MODULES.$(module).BUILT))
545endef
546
547###########################################################
548## Convert a list of short modules names (e.g., "framework", "Browser")
549## into the list of files that are installed for those modules.
550## NOTE: this won't return reliable results until after all
551## sub-makefiles have been included.
552## $(1): target list
553###########################################################
554
555define module-installed-files
556$(foreach module,$(1),$(ALL_MODULES.$(module).INSTALLED))
557endef
558
559###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700560## Convert a list of short modules names (e.g., "framework", "Browser")
561## into the list of files that should be used when linking
562## against that module as a public API.
563## TODO: Allow this for more than JAVA_LIBRARIES 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-stubs-files
570$(foreach module,$(1),$(ALL_MODULES.$(module).STUBS))
571endef
572
573###########################################################
574## Evaluates to the timestamp file for a doc module, which
575## is the dependency that should be used.
576## $(1): doc module
577###########################################################
578
579define doc-timestamp-for
580$(OUT_DOCS)/$(strip $(1))-timestamp
581endef
582
583
584###########################################################
Ying Wang912f8282010-09-28 17:27:56 -0700585## Convert "core ext framework" to "out/.../javalib.jar ..."
The Android Open Source Project88b60792009-03-03 19:28:42 -0800586## $(1): library list
587## $(2): Non-empty if IS_HOST_MODULE
588###########################################################
589
590# $(1): library name
591# $(2): Non-empty if IS_HOST_MODULE
592define _java-lib-dir
593$(call intermediates-dir-for, \
Ying Wang912f8282010-09-28 17:27:56 -0700594 JAVA_LIBRARIES,$(1),$(2),COMMON)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800595endef
596
597# $(1): library name
598# $(2): Non-empty if IS_HOST_MODULE
599define _java-lib-full-classes.jar
Ying Wang912f8282010-09-28 17:27:56 -0700600$(call _java-lib-dir,$(1),$(2))/classes$(COMMON_JAVA_PACKAGE_SUFFIX)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800601endef
602
603# $(1): library name list
604# $(2): Non-empty if IS_HOST_MODULE
605define java-lib-files
606$(foreach lib,$(1),$(call _java-lib-full-classes.jar,$(lib),$(2)))
607endef
608
609# $(1): library name
The Android Open Source Project88b60792009-03-03 19:28:42 -0800610# $(2): Non-empty if IS_HOST_MODULE
611define _java-lib-full-dep
Ying Wang45150f82013-02-27 15:23:42 -0800612$(call _java-lib-dir,$(1),$(2))/$(if $(2),javalib,classes)$(COMMON_JAVA_PACKAGE_SUFFIX)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800613endef
614
615# $(1): library name list
616# $(2): Non-empty if IS_HOST_MODULE
617define java-lib-deps
618$(foreach lib,$(1),$(call _java-lib-full-dep,$(lib),$(2)))
619endef
620
621###########################################################
Yohann Rousself09e59e2014-09-08 14:45:14 +0200622## Convert "core ext framework" to "out/.../classes.jack ..."
623## $(1): library list
624## $(2): Non-empty if IS_HOST_MODULE
625###########################################################
626
627# $(1): library name
628# $(2): Non-empty if IS_HOST_MODULE
629define _jack-lib-full-classes
630$(call _java-lib-dir,$(1),$(2))/classes.jack
631endef
632
633# $(1): library name list
634# $(2): Non-empty if IS_HOST_MODULE
635define jack-lib-files
636$(foreach lib,$(1),$(call _jack-lib-full-classes,$(lib),$(2)))
637endef
638
639# $(1): library name
640# $(2): Non-empty if IS_HOST_MODULE
641define _jack-lib-full-dep
642$(call _jack-lib-full-classes,$(1),$(2))
643endef
644
645# $(1): library name list
646# $(2): Non-empty if IS_HOST_MODULE
647define jack-lib-deps
648$(foreach lib,$(1),$(call _jack-lib-full-dep,$(lib),$(2)))
649endef
650
651###########################################################
Joe Onorato8dc8faa2010-09-14 13:09:48 -0400652## Run rot13 on a string
653## $(1): the string. Must be one line.
654###########################################################
655define rot13
656$(shell echo $(1) | tr 'a-zA-Z' 'n-za-mN-ZA-M')
657endef
658
659
660###########################################################
661## Returns true if $(1) and $(2) are equal. Returns
662## the empty string if they are not equal.
663###########################################################
664define streq
665$(strip $(if $(strip $(1)),\
666 $(if $(strip $(2)),\
667 $(if $(filter-out __,_$(subst $(strip $(1)),,$(strip $(2)))$(subst $(strip $(2)),,$(strip $(1)))_),,true), \
668 ),\
669 $(if $(strip $(2)),\
670 ,\
671 true)\
672 ))
673endef
674
675###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800676## Convert "a b c" into "a:b:c"
677###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800678define normalize-path-list
679$(subst $(space),:,$(strip $(1)))
680endef
681
682###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700683## Read the word out of a colon-separated list of words.
684## This has the same behavior as the built-in function
685## $(word n,str).
686##
687## The individual words may not contain spaces.
688##
689## $(1): 1 based index
690## $(2): value of the form a:b:c...
691###########################################################
692
693define word-colon
694$(word $(1),$(subst :,$(space),$(2)))
695endef
696
697###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800698## Convert "a=b c= d e = f" into "a=b c=d e=f"
699##
700## $(1): list to collapse
701## $(2): if set, separator word; usually "=", ":", or ":="
702## Defaults to "=" if not set.
703###########################################################
704
705define collapse-pairs
706$(eval _cpSEP := $(strip $(if $(2),$(2),=)))\
707$(subst $(space)$(_cpSEP)$(space),$(_cpSEP),$(strip \
708 $(subst $(_cpSEP), $(_cpSEP) ,$(1))))
709endef
710
The Android Open Source Project88b60792009-03-03 19:28:42 -0800711###########################################################
Ying Wang7e8d4422011-06-17 17:05:35 -0700712## Given a list of pairs, if multiple pairs have the same
713## first components, keep only the first pair.
714##
715## $(1): list of pairs
716## $(2): the separator word, such as ":", "=", etc.
717define uniq-pairs-by-first-component
718$(eval _upbfc_fc_set :=)\
719$(strip $(foreach w,$(1), $(eval _first := $(word 1,$(subst $(2),$(space),$(w))))\
720 $(if $(filter $(_upbfc_fc_set),$(_first)),,$(w)\
721 $(eval _upbfc_fc_set += $(_first)))))\
722$(eval _upbfc_fc_set :=)\
723$(eval _first:=)
724endef
725
726###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800727## MODULE_TAG set operations
728###########################################################
729
730# Given a list of tags, return the targets that specify
731# any of those tags.
732# $(1): tag list
733define modules-for-tag-list
Ying Wang634f7992014-11-18 12:41:53 -0800734$(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 -0800735endef
736
737# Same as modules-for-tag-list, but operates on
738# ALL_MODULE_NAME_TAGS.
739# $(1): tag list
740define module-names-for-tag-list
741$(sort $(foreach tag,$(1),$(ALL_MODULE_NAME_TAGS.$(tag))))
742endef
743
744# Given an accept and reject list, find the matching
745# set of targets. If a target has multiple tags and
746# any of them are rejected, the target is rejected.
747# Reject overrides accept.
748# $(1): list of tags to accept
749# $(2): list of tags to reject
750#TODO(dbort): do $(if $(strip $(1)),$(1),$(ALL_MODULE_TAGS))
Jean-Baptiste Queru75127b72010-01-07 11:44:22 -0800751#TODO(jbq): as of 20100106 nobody uses the second parameter
The Android Open Source Project88b60792009-03-03 19:28:42 -0800752define get-tagged-modules
753$(filter-out \
754 $(call modules-for-tag-list,$(2)), \
755 $(call modules-for-tag-list,$(1)))
756endef
757
Joe Onorato64d85d02009-04-09 19:31:12 -0700758###########################################################
759## Append a leaf to a base path. Properly deals with
760## base paths ending in /.
761##
762## $(1): base path
763## $(2): leaf path
764###########################################################
765
766define append-path
767$(subst //,/,$(1)/$(2))
768endef
769
The Android Open Source Project88b60792009-03-03 19:28:42 -0800770
771###########################################################
772## Package filtering
773###########################################################
774
775# Given a list of installed modules (short or long names)
776# return a list of the packages (yes, .apk packages, not
777# modules in general) that are overridden by this list and,
778# therefore, should not be installed.
779# $(1): mixed list of installed modules
780# TODO: This is fragile; find a reliable way to get this information.
781define _get-package-overrides
782 $(eval ### Discard any words containing slashes, unless they end in .apk, \
783 ### in which case trim off the directory component and the suffix. \
784 ### If there are no slashes, keep the entire word.)
785 $(eval _gpo_names := $(subst /,@@@ @@@,$(1)))
786 $(eval _gpo_names := \
787 $(filter %.apk,$(_gpo_names)) \
788 $(filter-out %@@@ @@@%,$(_gpo_names)))
789 $(eval _gpo_names := $(patsubst %.apk,%,$(_gpo_names)))
790 $(eval _gpo_names := $(patsubst @@@%,%,$(_gpo_names)))
791
792 $(eval ### Remove any remaining words that contain dots.)
793 $(eval _gpo_names := $(subst .,@@@ @@@,$(_gpo_names)))
794 $(eval _gpo_names := $(filter-out %@@@ @@@%,$(_gpo_names)))
795
796 $(eval ### Now we have a list of any words that could possibly refer to \
797 ### packages, although there may be words that do not. Only \
798 ### real packages will be present under PACKAGES.*, though.)
799 $(foreach _gpo_name,$(_gpo_names),$(PACKAGES.$(_gpo_name).OVERRIDES))
800endef
801
802define get-package-overrides
Conley Owensd7a1a9b2011-12-22 09:46:19 -0800803$(sort $(strip $(call _get-package-overrides,$(1))))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800804endef
805
806###########################################################
807## Output the command lines, or not
808###########################################################
809
810ifeq ($(strip $(SHOW_COMMANDS)),)
811define pretty
812@echo $1
813endef
The Android Open Source Project88b60792009-03-03 19:28:42 -0800814else
815define pretty
816endef
The Android Open Source Project88b60792009-03-03 19:28:42 -0800817endif
818
819###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800820## Commands for munging the dependency files GCC generates
821###########################################################
Ying Wangc23f4ef2012-09-07 17:04:06 -0700822# $(1): the input .d file
823# $(2): the output .P file
824define transform-d-to-p-args
825$(hide) cp $(1) $(2); \
826 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
827 -e '/^$$/ d' -e 's/$$/ :/' < $(1) >> $(2); \
828 rm -f $(1)
829endef
The Android Open Source Project88b60792009-03-03 19:28:42 -0800830
831define transform-d-to-p
Ying Wangc23f4ef2012-09-07 17:04:06 -0700832$(call transform-d-to-p-args,$(@:%.o=%.d),$(@:%.o=%.P))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800833endef
834
835###########################################################
836## Commands for running lex
837###########################################################
838
839define transform-l-to-cpp
The Android Open Source Project88b60792009-03-03 19:28:42 -0800840@echo "Lex: $(PRIVATE_MODULE) <= $<"
Colin Crossb6da5892015-07-16 17:14:27 -0700841@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800842$(hide) $(LEX) -o$@ $<
843endef
844
845###########################################################
846## Commands for running yacc
847##
848## Because the extension of c++ files can change, the
849## extension must be specified in $1.
850## E.g, "$(call transform-y-to-cpp,.cpp)"
851###########################################################
852
853define transform-y-to-cpp
The Android Open Source Project88b60792009-03-03 19:28:42 -0800854@echo "Yacc: $(PRIVATE_MODULE) <= $<"
Colin Crossb6da5892015-07-16 17:14:27 -0700855@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800856$(YACC) $(PRIVATE_YACCFLAGS) -o $@ $<
857touch $(@:$1=$(YACC_HEADER_SUFFIX))
858echo '#ifndef '$(@F:$1=_h) > $(@:$1=.h)
859echo '#define '$(@F:$1=_h) >> $(@:$1=.h)
860cat $(@:$1=$(YACC_HEADER_SUFFIX)) >> $(@:$1=.h)
861echo '#endif' >> $(@:$1=.h)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800862endef
863
Ying Wang0bd59a02010-07-15 17:17:52 -0700864###########################################################
Tim Murraya7aa8002012-10-29 16:06:00 -0700865## Commands to compile RenderScript to Java
Ying Wang0bd59a02010-07-15 17:17:52 -0700866###########################################################
Ying Wang0bd59a02010-07-15 17:17:52 -0700867
868define transform-renderscripts-to-java-and-bc
869@echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)"
870$(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR)
871$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/res/raw
872$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/src
Ying Wang7d83ef82011-05-25 17:16:22 -0700873$(hide) $(PRIVATE_RS_CC) \
Ying Wangebfddaa2010-07-30 18:37:29 -0700874 -o $(PRIVATE_RS_OUTPUT_DIR)/res/raw \
875 -p $(PRIVATE_RS_OUTPUT_DIR)/src \
Ying Wang24e1c012010-10-07 18:57:57 -0700876 -d $(PRIVATE_RS_OUTPUT_DIR) \
877 -a $@ -MD \
Stephen Hinesc963eae2011-08-10 13:53:05 -0700878 $(addprefix -target-api , $(PRIVATE_RS_TARGET_API)) \
Stephen Hines914f7a22011-12-06 18:43:24 -0800879 $(PRIVATE_RS_FLAGS) \
Ying Wang51280272010-09-01 13:28:52 -0700880 $(foreach inc,$(PRIVATE_RS_INCLUDES),$(addprefix -I , $(inc))) \
Ying Wangebfddaa2010-07-30 18:37:29 -0700881 $(PRIVATE_RS_SOURCE_FILES)
Ying Wangb9319562015-04-03 16:15:28 -0700882 $(foreach d,$(PRIVATE_DEP_FILES),\
883 $(call transform-d-to-p-args,$(d),$(d:%.d=%.P))$(newline))
Ying Wang0bd59a02010-07-15 17:17:52 -0700884$(hide) mkdir -p $(dir $@)
885$(hide) touch $@
886endef
887
Stephen Hinese719f282012-11-28 16:52:41 -0800888define transform-bc-to-so
Stephen Hines9ac9b532013-02-27 00:51:08 -0800889@echo "Renderscript compatibility: $(notdir $@) <= $(notdir $<)"
Stephen Hinese719f282012-11-28 16:52:41 -0800890$(hide) mkdir -p $(dir $@)
Stephen Hinesf6925132012-12-17 14:23:14 -0800891$(hide) $(BCC_COMPAT) -O3 -o $(dir $@)/$(notdir $(<:.bc=.o)) -fPIC -shared \
Stephen Hines52626d22014-09-02 19:09:35 -0700892 -rt-path $(RS_PREBUILT_CLCORE) -mtriple $(RS_COMPAT_TRIPLE) $<
Stephen Hines7d6ec712012-12-13 19:24:50 -0800893$(hide) $(PRIVATE_CXX) -shared -Wl,-soname,$(notdir $@) -nostdlib \
Stephen Hinesf6925132012-12-17 14:23:14 -0800894 -Wl,-rpath,\$$ORIGIN/../lib \
Stephen Hines9541f582013-01-18 16:27:23 -0800895 $(dir $@)/$(notdir $(<:.bc=.o)) \
Tim Murray1a6f09a2013-03-05 11:07:15 -0800896 $(RS_PREBUILT_COMPILER_RT) \
Miao Wange23e8082014-11-15 14:25:33 -0800897 -o $@ $(TARGET_GLOBAL_LDFLAGS) -Wl,--hash-style=sysv -L prebuilts/gcc/ \
Ying Wangbfc43692015-03-05 11:29:30 -0800898 $(RS_PREBUILT_LIBPATH) -L $(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
Stephen Hines8db4cce2013-03-27 16:51:38 -0700899 -lRSSupport -lm -lc
Stephen Hinese719f282012-11-28 16:52:41 -0800900endef
901
Tim Murraya7aa8002012-10-29 16:06:00 -0700902###########################################################
903## Commands to compile RenderScript to C++
904###########################################################
905
906define transform-renderscripts-to-cpp-and-bc
907@echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)"
908$(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR)
909$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/
910$(hide) $(PRIVATE_RS_CC) \
911 -o $(PRIVATE_RS_OUTPUT_DIR)/ \
912 -d $(PRIVATE_RS_OUTPUT_DIR) \
913 -a $@ -MD \
914 -reflect-c++ \
Noah Presler4796a8c2015-08-13 17:04:10 -0700915 $(addprefix -target-api , $(PRIVATE_RS_TARGET_API)) \
Tim Murraya7aa8002012-10-29 16:06:00 -0700916 $(PRIVATE_RS_FLAGS) \
Ying Wang81ab8332014-05-28 16:17:09 -0700917 $(addprefix -I , $(PRIVATE_RS_INCLUDES)) \
Tim Murraya7aa8002012-10-29 16:06:00 -0700918 $(PRIVATE_RS_SOURCE_FILES)
Ying Wangb9319562015-04-03 16:15:28 -0700919 $(foreach d,$(PRIVATE_DEP_FILES),\
920 $(call transform-d-to-p-args,$(d),$(d:%.d=%.P))$(newline))
Tim Murraya7aa8002012-10-29 16:06:00 -0700921$(hide) mkdir -p $(dir $@)
922$(hide) touch $@
923endef
924
The Android Open Source Project88b60792009-03-03 19:28:42 -0800925
926###########################################################
927## Commands for running aidl
928###########################################################
929
930define transform-aidl-to-java
931@mkdir -p $(dir $@)
932@echo "Aidl: $(PRIVATE_MODULE) <= $<"
933$(hide) $(AIDL) -d$(patsubst %.java,%.P,$@) $(PRIVATE_AIDL_FLAGS) $< $@
934endef
935#$(AIDL) $(PRIVATE_AIDL_FLAGS) $< - | indent -nut -br -npcs -l1000 > $@
936
937
Doug Zongker9bd49622009-11-30 14:28:59 -0800938###########################################################
939## Commands for running java-event-log-tags.py
940###########################################################
941
942define transform-logtags-to-java
943@mkdir -p $(dir $@)
944@echo "logtags: $@ <= $<"
Doug Zongkerabfbbe22010-02-16 14:32:08 -0800945$(hide) $(JAVATAGS) -o $@ $^
Doug Zongker9bd49622009-11-30 14:28:59 -0800946endef
947
The Android Open Source Project88b60792009-03-03 19:28:42 -0800948
949###########################################################
Ying Wanga5fc87a2010-11-02 18:43:16 -0700950## Commands for running protoc to compile .proto into .java
951###########################################################
952
953define transform-proto-to-java
954@mkdir -p $(dir $@)
955@echo "Protoc: $@ <= $(PRIVATE_PROTO_SRC_FILES)"
956@rm -rf $(PRIVATE_PROTO_JAVA_OUTPUT_DIR)
957@mkdir -p $(PRIVATE_PROTO_JAVA_OUTPUT_DIR)
Ben Murdochfc2bad52013-07-25 11:44:53 +0100958$(hide) for f in $(PRIVATE_PROTO_SRC_FILES); do \
959 $(PROTOC) \
Ulas Kirazci28b46fc2013-07-24 14:32:14 -0700960 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
Ulas Kirazci6e485b52013-07-25 12:28:19 -0700961 $(PRIVATE_PROTO_JAVA_OUTPUT_OPTION)="$(PRIVATE_PROTO_JAVA_OUTPUT_PARAMS):$(PRIVATE_PROTO_JAVA_OUTPUT_DIR)" \
Ben Murdochfc2bad52013-07-25 11:44:53 +0100962 $(PRIVATE_PROTOC_FLAGS) \
963 $$f || exit 33; \
964 done
Ying Wanga5fc87a2010-11-02 18:43:16 -0700965$(hide) touch $@
966endef
967
968######################################################################
Ying Wangb28ed232015-04-07 11:59:34 -0700969## Commands for running protoc to compile .proto into .pb.cc (or.pb.c) and .pb.h
Ying Wanga5fc87a2010-11-02 18:43:16 -0700970######################################################################
971define transform-proto-to-cc
Ying Wanga5fc87a2010-11-02 18:43:16 -0700972@echo "Protoc: $@ <= $<"
Colin Crossb6da5892015-07-16 17:14:27 -0700973@mkdir -p $(dir $@)
Ying Wanga5fc87a2010-11-02 18:43:16 -0700974$(hide) $(PROTOC) \
975 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
Ying Wang33c0d952010-11-05 11:30:58 -0700976 $(PRIVATE_PROTOC_FLAGS) \
Ying Wangb28ed232015-04-07 11:59:34 -0700977 $<
Ying Wanga5fc87a2010-11-02 18:43:16 -0700978endef
979
980
Christopher Wileybc2be462015-07-29 17:14:24 -0700981######################################################################
Christopher Wiley9b17dea2015-08-20 09:08:17 -0700982## Commands for generating DBus adaptors from .dbus-xml files.
Christopher Wileybc2be462015-07-29 17:14:24 -0700983######################################################################
Christopher Wiley529f1762015-08-14 14:55:32 -0700984define generate-dbus-adaptors
985@echo "Generating DBus adaptors for $(PRIVATE_MODULE)"
986@mkdir -p $(dir $@)
Christopher Wileybc2be462015-07-29 17:14:24 -0700987$(hide) $(DBUS_GENERATOR) \
988 --service-config=$(PRIVATE_DBUS_SERVICE_CONFIG) \
Christopher Wiley529f1762015-08-14 14:55:32 -0700989 --adaptor=$@ \
990 $<
991endef
992
993######################################################################
Christopher Wiley9b17dea2015-08-20 09:08:17 -0700994## Commands for generating DBus proxies from .dbus-xml files.
Christopher Wiley529f1762015-08-14 14:55:32 -0700995######################################################################
996define generate-dbus-proxies
997@echo "Generating DBus proxies for $(PRIVATE_MODULE)"
998@mkdir -p $(dir $@)
999$(hide) $(DBUS_GENERATOR) \
1000 --service-config=$(PRIVATE_DBUS_SERVICE_CONFIG) \
1001 --proxy=$@ \
Christopher Wiley9b17dea2015-08-20 09:08:17 -07001002 $(filter %.dbus-xml,$^)
Christopher Wileybc2be462015-07-29 17:14:24 -07001003endef
1004
1005
Ying Wanga5fc87a2010-11-02 18:43:16 -07001006###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001007## Commands for running gcc to compile a C++ file
1008###########################################################
1009
1010define transform-cpp-to-o
The Android Open Source Project88b60792009-03-03 19:28:42 -08001011@echo "target $(PRIVATE_ARM_MODE) C++: $(PRIVATE_MODULE) <= $<"
Colin Crossb6da5892015-07-16 17:14:27 -07001012@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001013$(hide) $(PRIVATE_CXX) \
Ying Wangddbcad82011-04-18 11:45:44 -07001014 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Andrew Boie85f3b212012-07-11 12:14:56 -07001015 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
Ying Wang4761e562011-04-12 11:06:35 -07001016 $(addprefix -isystem ,\
1017 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1018 $(filter-out $(PRIVATE_C_INCLUDES), \
Ying Wangddbcad82011-04-18 11:45:44 -07001019 $(PRIVATE_TARGET_PROJECT_INCLUDES) \
Ying Wang4761e562011-04-12 11:06:35 -07001020 $(PRIVATE_TARGET_C_INCLUDES)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001021 -c \
1022 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -07001023 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
1024 $(PRIVATE_TARGET_GLOBAL_CPPFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001025 $(PRIVATE_ARM_CFLAGS) \
1026 ) \
Doug Kwan9a8ecf92011-05-10 21:50:58 -07001027 $(PRIVATE_RTTI_FLAG) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001028 $(PRIVATE_CFLAGS) \
1029 $(PRIVATE_CPPFLAGS) \
1030 $(PRIVATE_DEBUG_CFLAGS) \
Dan Albertd1600412015-06-10 16:33:43 -07001031 $(PRIVATE_CFLAGS_NO_OVERRIDE) \
1032 $(PRIVATE_CPPFLAGS_NO_OVERRIDE) \
Atte Peltomaki60fe9632011-12-21 09:24:09 -08001033 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001034$(transform-d-to-p)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001035endef
1036
1037
1038###########################################################
1039## Commands for running gcc to compile a C file
1040###########################################################
1041
1042# $(1): extra flags
1043define transform-c-or-s-to-o-no-deps
1044@mkdir -p $(dir $@)
1045$(hide) $(PRIVATE_CC) \
Ying Wangddbcad82011-04-18 11:45:44 -07001046 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Andrew Boie85f3b212012-07-11 12:14:56 -07001047 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
Ying Wang4761e562011-04-12 11:06:35 -07001048 $(addprefix -isystem ,\
1049 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1050 $(filter-out $(PRIVATE_C_INCLUDES), \
Ying Wangddbcad82011-04-18 11:45:44 -07001051 $(PRIVATE_TARGET_PROJECT_INCLUDES) \
Ying Wang4761e562011-04-12 11:06:35 -07001052 $(PRIVATE_TARGET_C_INCLUDES)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001053 -c \
1054 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -07001055 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
Stephen Hines15680292014-11-26 00:53:46 -08001056 $(PRIVATE_TARGET_GLOBAL_CONLYFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001057 $(PRIVATE_ARM_CFLAGS) \
1058 ) \
Ying Wang65d78522012-08-10 16:30:42 -07001059 $(1) \
Atte Peltomaki60fe9632011-12-21 09:24:09 -08001060 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
The Android Open Source Project88b60792009-03-03 19:28:42 -08001061endef
1062
1063define transform-c-to-o-no-deps
1064@echo "target $(PRIVATE_ARM_MODE) C: $(PRIVATE_MODULE) <= $<"
Dan Albert0c91fa82015-02-21 12:45:26 -08001065$(call transform-c-or-s-to-o-no-deps, \
1066 $(PRIVATE_CFLAGS) \
1067 $(PRIVATE_CONLYFLAGS) \
1068 $(PRIVATE_DEBUG_CFLAGS) \
Dan Albertd1600412015-06-10 16:33:43 -07001069 $(PRIVATE_CFLAGS_NO_OVERRIDE))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001070endef
1071
1072define transform-s-to-o-no-deps
1073@echo "target asm: $(PRIVATE_MODULE) <= $<"
1074$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
1075endef
1076
1077define transform-c-to-o
1078$(transform-c-to-o-no-deps)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001079$(transform-d-to-p)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001080endef
1081
1082define transform-s-to-o
1083$(transform-s-to-o-no-deps)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001084$(transform-d-to-p)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001085endef
1086
Ying Wang7b913ce2014-06-05 19:05:47 -07001087# YASM compilation
1088define transform-asm-to-o
1089@mkdir -p $(dir $@)
1090$(hide) $(YASM) \
1091 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Ying Wangfe1e5c32015-03-09 18:57:40 -07001092 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_YASM_FLAGS) \
Ying Wang7b913ce2014-06-05 19:05:47 -07001093 $(PRIVATE_ASFLAGS) \
1094 -o $@ $<
1095endef
1096
The Android Open Source Project88b60792009-03-03 19:28:42 -08001097###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001098## Commands for running gcc to compile an Objective-C file
1099## This should never happen for target builds but this
1100## will error at build time.
1101###########################################################
1102
1103define transform-m-to-o-no-deps
1104@echo "target ObjC: $(PRIVATE_MODULE) <= $<"
Ying Wang65d78522012-08-10 16:30:42 -07001105$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_DEBUG_CFLAGS))
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001106endef
1107
1108define transform-m-to-o
1109$(transform-m-to-o-no-deps)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001110$(transform-d-to-p)
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001111endef
1112
1113###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001114## Commands for running gcc to compile a host C++ file
1115###########################################################
1116
1117define transform-host-cpp-to-o
Dan Willemsen057aaea2015-08-14 12:59:50 -07001118@echo "$($(PRIVATE_PREFIX)DISPLAY) C++: $(PRIVATE_MODULE) <= $<"
Colin Crossb6da5892015-07-16 17:14:27 -07001119@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001120$(hide) $(PRIVATE_CXX) \
Ying Wangddbcad82011-04-18 11:45:44 -07001121 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Andrew Boie85f3b212012-07-11 12:14:56 -07001122 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
Ying Wangddbcad82011-04-18 11:45:44 -07001123 $(addprefix -isystem ,\
The Android Open Source Project88b60792009-03-03 19:28:42 -08001124 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wangddbcad82011-04-18 11:45:44 -07001125 $(filter-out $(PRIVATE_C_INCLUDES), \
Dan Willemsen057aaea2015-08-14 12:59:50 -07001126 $($(PRIVATE_PREFIX)PROJECT_INCLUDES) \
Logan Chiene6f65432013-12-10 19:07:41 +08001127 $(PRIVATE_HOST_C_INCLUDES)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001128 -c \
1129 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001130 $(PRIVATE_HOST_GLOBAL_CFLAGS) \
1131 $(PRIVATE_HOST_GLOBAL_CPPFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001132 ) \
1133 $(PRIVATE_CFLAGS) \
1134 $(PRIVATE_CPPFLAGS) \
1135 $(PRIVATE_DEBUG_CFLAGS) \
Dan Albertd1600412015-06-10 16:33:43 -07001136 $(PRIVATE_CFLAGS_NO_OVERRIDE) \
1137 $(PRIVATE_CPPFLAGS_NO_OVERRIDE) \
Atte Peltomaki60fe9632011-12-21 09:24:09 -08001138 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
The Android Open Source Project88b60792009-03-03 19:28:42 -08001139$(transform-d-to-p)
1140endef
1141
1142
1143###########################################################
1144## Commands for running gcc to compile a host C file
1145###########################################################
1146
1147# $(1): extra flags
1148define transform-host-c-or-s-to-o-no-deps
1149@mkdir -p $(dir $@)
1150$(hide) $(PRIVATE_CC) \
Ying Wangddbcad82011-04-18 11:45:44 -07001151 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Andrew Boie85f3b212012-07-11 12:14:56 -07001152 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
Ying Wangddbcad82011-04-18 11:45:44 -07001153 $(addprefix -isystem ,\
The Android Open Source Project88b60792009-03-03 19:28:42 -08001154 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wangddbcad82011-04-18 11:45:44 -07001155 $(filter-out $(PRIVATE_C_INCLUDES), \
Dan Willemsen057aaea2015-08-14 12:59:50 -07001156 $($(PRIVATE_PREFIX)PROJECT_INCLUDES) \
Logan Chiene6f65432013-12-10 19:07:41 +08001157 $(PRIVATE_HOST_C_INCLUDES)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001158 -c \
1159 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001160 $(PRIVATE_HOST_GLOBAL_CFLAGS) \
Stephen Hines15680292014-11-26 00:53:46 -08001161 $(PRIVATE_HOST_GLOBAL_CONLYFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001162 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001163 $(1) \
Dan Albertd1600412015-06-10 16:33:43 -07001164 $(PRIVATE_CFLAGS_NO_OVERRIDE) \
Atte Peltomaki60fe9632011-12-21 09:24:09 -08001165 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
The Android Open Source Project88b60792009-03-03 19:28:42 -08001166endef
1167
1168define transform-host-c-to-o-no-deps
Dan Willemsen057aaea2015-08-14 12:59:50 -07001169@echo "$($(PRIVATE_PREFIX)DISPLAY) C: $(PRIVATE_MODULE) <= $<"
Ying Wang7429e212012-08-15 10:59:10 -07001170$(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 -08001171endef
1172
1173define transform-host-s-to-o-no-deps
Dan Willemsen057aaea2015-08-14 12:59:50 -07001174@echo "$($(PRIVATE_PREFIX)DISPLAY) asm: $(PRIVATE_MODULE) <= $<"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001175$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
1176endef
1177
1178define transform-host-c-to-o
1179$(transform-host-c-to-o-no-deps)
1180$(transform-d-to-p)
1181endef
1182
1183define transform-host-s-to-o
1184$(transform-host-s-to-o-no-deps)
1185$(transform-d-to-p)
1186endef
1187
1188###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001189## Commands for running gcc to compile a host Objective-C file
1190###########################################################
1191
1192define transform-host-m-to-o-no-deps
Dan Willemsen057aaea2015-08-14 12:59:50 -07001193@echo "$($(PRIVATE_PREFIX)DISPLAY) ObjC: $(PRIVATE_MODULE) <= $<"
Ying Wang65d78522012-08-10 16:30:42 -07001194$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_DEBUG_CFLAGS))
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001195endef
1196
David 'Digit' Turner5ca286d2011-02-11 16:19:31 +01001197define transform-host-m-to-o
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001198$(transform-host-m-to-o-no-deps)
1199$(transform-d-to-p)
1200endef
1201
Scott James Remnantdd86e5a2015-09-17 15:40:49 -07001202###########################################################
1203## Commands for running gcc to compile a host Objective-C++ file
1204###########################################################
1205
1206define transform-host-mm-to-o
1207$(transform-host-cpp-to-o)
1208endef
1209
Ying Wangfb22a422015-03-10 18:03:11 -07001210
1211###########################################################
1212## Rules to compile a single C/C++ source with ../ in the path
1213###########################################################
1214# Replace "../" in object paths with $(DOTDOT_REPLACEMENT).
1215DOTDOT_REPLACEMENT := dotdot/
1216
1217## Rule to compile a C++ source file with ../ in the path.
1218## Must be called with $(eval).
1219# $(1): the C++ source file in LOCAL_SRC_FILES.
1220# $(2): the additional dependencies.
1221# $(3): the variable name to collect the output object file.
1222define compile-dotdot-cpp-file
1223o := $(intermediates)/$(patsubst %$(LOCAL_CPP_EXTENSION),%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
1224$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2)
1225 $$(transform-$$(PRIVATE_HOST)cpp-to-o)
1226-include $$(o:%.o=%.P)
1227$(3) += $$(o)
1228endef
1229
1230## Rule to compile a C source file with ../ in the path.
1231## Must be called with $(eval).
1232# $(1): the C source file in LOCAL_SRC_FILES.
1233# $(2): the additional dependencies.
1234# $(3): the variable name to collect the output object file.
1235define compile-dotdot-c-file
1236o := $(intermediates)/$(patsubst %.c,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
1237$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2)
1238 $$(transform-$$(PRIVATE_HOST)c-to-o)
1239-include $$(o:%.o=%.P)
1240$(3) += $$(o)
1241endef
1242
1243## Rule to compile a .S source file with ../ in the path.
1244## Must be called with $(eval).
1245# $(1): the .S source file in LOCAL_SRC_FILES.
1246# $(2): the additional dependencies.
1247# $(3): the variable name to collect the output object file.
1248define compile-dotdot-s-file
1249o := $(intermediates)/$(patsubst %.S,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
1250$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2)
1251 $$(transform-$$(PRIVATE_HOST)s-to-o)
1252-include $$(o:%.o=%.P)
1253$(3) += $$(o)
1254endef
1255
1256## Rule to compile a .s source file with ../ in the path.
1257## Must be called with $(eval).
1258# $(1): the .s source file in LOCAL_SRC_FILES.
1259# $(2): the additional dependencies.
1260# $(3): the variable name to collect the output object file.
1261define compile-dotdot-s-file-no-deps
1262o := $(intermediates)/$(patsubst %.s,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
1263$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2)
1264 $$(transform-$$(PRIVATE_HOST)s-to-o-no-deps)
1265$(3) += $$(o)
1266endef
1267
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001268###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001269## Commands for running ar
1270###########################################################
1271
Ying Wange4b24eb2010-05-27 11:55:39 -07001272define _concat-if-arg2-not-empty
1273$(if $(2),$(hide) $(1) $(2))
1274endef
1275
1276# Split long argument list into smaller groups and call the command repeatedly
Torne (Richard Coles)bffaef22012-06-15 16:03:52 +01001277# Call the command at least once even if there are no arguments, as otherwise
1278# the output file won't be created.
Ying Wange4b24eb2010-05-27 11:55:39 -07001279#
1280# $(1): the command without arguments
1281# $(2): the arguments
1282define split-long-arguments
Torne (Richard Coles)bffaef22012-06-15 16:03:52 +01001283$(hide) $(1) $(wordlist 1,500,$(2))
Ying Wange4b24eb2010-05-27 11:55:39 -07001284$(call _concat-if-arg2-not-empty,$(1),$(wordlist 501,1000,$(2)))
1285$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1001,1500,$(2)))
1286$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1501,2000,$(2)))
1287$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2001,2500,$(2)))
1288$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2501,3000,$(2)))
1289$(call _concat-if-arg2-not-empty,$(1),$(wordlist 3001,99999,$(2)))
1290endef
1291
Ying Wanga02d3d92011-01-27 18:48:00 -08001292# $(1): the full path of the source static library.
1293define _extract-and-include-single-target-whole-static-lib
Ying Wanga02d3d92011-01-27 18:48:00 -08001294$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\
1295 rm -rf $$ldir; \
1296 mkdir -p $$ldir; \
Christopher Ferris44203f32015-01-07 17:14:03 -08001297 cp $(1) $$ldir; \
1298 lib_to_include=$$ldir/$(notdir $(1)); \
Ying Wanga02d3d92011-01-27 18:48:00 -08001299 filelist=; \
Christopher Ferris44203f32015-01-07 17:14:03 -08001300 subdir=0; \
Ying Wang6feb6d52014-04-17 10:03:35 -07001301 for f in `$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) t $(1)`; do \
Christopher Ferris44203f32015-01-07 17:14:03 -08001302 if [ -e $$ldir/$$f ]; then \
1303 mkdir $$ldir/$$subdir; \
1304 ext=$$subdir/; \
1305 subdir=$$((subdir+1)); \
1306 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) m $$lib_to_include $$f; \
1307 else \
1308 ext=; \
1309 fi; \
1310 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) p $$lib_to_include $$f > $$ldir/$$ext$$f; \
1311 filelist="$$filelist $$ldir/$$ext$$f"; \
Ying Wanga02d3d92011-01-27 18:48:00 -08001312 done ; \
Ying Wang61d499b2014-01-15 16:02:16 -08001313 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \
1314 $(PRIVATE_ARFLAGS) $@ $$filelist
Ying Wanga02d3d92011-01-27 18:48:00 -08001315
1316endef
1317
Dan Alberte0f44ac2014-05-23 12:26:51 -07001318# $(1): the full path of the source static library.
1319define extract-and-include-whole-static-libs-first
1320$(if $(strip $(1)),
Dan Alberte0f44ac2014-05-23 12:26:51 -07001321$(hide) cp $(1) $@)
1322endef
1323
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001324define extract-and-include-target-whole-static-libs
Dan Alberte0f44ac2014-05-23 12:26:51 -07001325$(call extract-and-include-whole-static-libs-first, $(firstword $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)))
1326$(foreach lib,$(wordlist 2,999,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)), \
Ying Wanga02d3d92011-01-27 18:48:00 -08001327 $(call _extract-and-include-single-target-whole-static-lib, $(lib)))
Dima Zavin46e9bec2009-05-27 19:41:07 -07001328endef
1329
The Android Open Source Project88b60792009-03-03 19:28:42 -08001330# Explicitly delete the archive first so that ar doesn't
1331# try to add to an existing archive.
1332define transform-o-to-static-lib
Colin Crossb6da5892015-07-16 17:14:27 -07001333@echo "target StaticLib: $(PRIVATE_MODULE) ($@)"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001334@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001335@rm -f $@
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001336$(extract-and-include-target-whole-static-libs)
Ying Wang6feb6d52014-04-17 10:03:35 -07001337$(call split-long-arguments,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) \
1338 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \
Ying Wang854607e2015-04-02 18:02:33 -07001339 $(PRIVATE_ARFLAGS) $@,$(PRIVATE_ALL_OBJECTS))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001340endef
1341
1342###########################################################
1343## Commands for running host ar
1344###########################################################
1345
Ying Wanga02d3d92011-01-27 18:48:00 -08001346# $(1): the full path of the source static library.
1347define _extract-and-include-single-host-whole-static-lib
Ying Wanga02d3d92011-01-27 18:48:00 -08001348$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\
1349 rm -rf $$ldir; \
1350 mkdir -p $$ldir; \
Christopher Ferris44203f32015-01-07 17:14:03 -08001351 cp $(1) $$ldir; \
1352 lib_to_include=$$ldir/$(notdir $(1)); \
Ying Wanga02d3d92011-01-27 18:48:00 -08001353 filelist=; \
Christopher Ferris44203f32015-01-07 17:14:03 -08001354 subdir=0; \
Dan Willemsen057aaea2015-08-14 12:59:50 -07001355 for f in `$($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) t $(1) | \grep '\.o$$'`; do \
Christopher Ferris44203f32015-01-07 17:14:03 -08001356 if [ -e $$ldir/$$f ]; then \
1357 mkdir $$ldir/$$subdir; \
1358 ext=$$subdir/; \
1359 subdir=$$((subdir+1)); \
Dan Willemsen057aaea2015-08-14 12:59:50 -07001360 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) m $$lib_to_include $$f; \
Christopher Ferris44203f32015-01-07 17:14:03 -08001361 else \
1362 ext=; \
1363 fi; \
Dan Willemsen057aaea2015-08-14 12:59:50 -07001364 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) p $$lib_to_include $$f > $$ldir/$$ext$$f; \
Christopher Ferris44203f32015-01-07 17:14:03 -08001365 filelist="$$filelist $$ldir/$$ext$$f"; \
Ying Wanga02d3d92011-01-27 18:48:00 -08001366 done ; \
Dan Willemsen057aaea2015-08-14 12:59:50 -07001367 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)GLOBAL_ARFLAGS) \
Ying Wang6feb6d52014-04-17 10:03:35 -07001368 $(PRIVATE_ARFLAGS) $@ $$filelist
Ying Wanga02d3d92011-01-27 18:48:00 -08001369
1370endef
1371
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001372define extract-and-include-host-whole-static-libs
Dan Alberte0f44ac2014-05-23 12:26:51 -07001373$(call extract-and-include-whole-static-libs-first, $(firstword $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)))
1374$(foreach lib,$(wordlist 2,999,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)), \
Ying Wanga02d3d92011-01-27 18:48:00 -08001375 $(call _extract-and-include-single-host-whole-static-lib, $(lib)))
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001376endef
1377
The Android Open Source Project88b60792009-03-03 19:28:42 -08001378# Explicitly delete the archive first so that ar doesn't
1379# try to add to an existing archive.
1380define transform-host-o-to-static-lib
Dan Willemsen057aaea2015-08-14 12:59:50 -07001381@echo "$($(PRIVATE_PREFIX)DISPLAY) StaticLib: $(PRIVATE_MODULE) ($@)"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001382@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001383@rm -f $@
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001384$(extract-and-include-host-whole-static-libs)
Dan Willemsen057aaea2015-08-14 12:59:50 -07001385$(call split-long-arguments,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) \
1386 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)GLOBAL_ARFLAGS) \
Ying Wang854607e2015-04-02 18:02:33 -07001387 $(PRIVATE_ARFLAGS) $@,$(PRIVATE_ALL_OBJECTS))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001388endef
1389
1390
1391###########################################################
1392## Commands for running gcc to link a shared library or package
1393###########################################################
1394
1395# ld just seems to be so finicky with command order that we allow
1396# it to be overriden en-masse see combo/linux-arm.make for an example.
1397ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1398define transform-host-o-to-shared-lib-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001399$(hide) $(PRIVATE_CXX) \
Dan Willemsen057aaea2015-08-14 12:59:50 -07001400 -Wl,-rpath-link=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)OUT_INTERMEDIATE_LIBRARIES) \
1401 -Wl,-rpath,\$$ORIGIN/../$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)OUT_SHARED_LIBRARIES)) \
1402 -Wl,-rpath,\$$ORIGIN/$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)OUT_SHARED_LIBRARIES)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001403 -shared -Wl,-soname,$(notdir $@) \
Dan Willemsen057aaea2015-08-14 12:59:50 -07001404 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)GLOBAL_LD_DIRS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001405 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001406 $(PRIVATE_HOST_GLOBAL_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001407 ) \
Torne (Richard Coles)a424bf72014-02-12 14:24:41 +00001408 $(PRIVATE_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001409 $(PRIVATE_ALL_OBJECTS) \
1410 -Wl,--whole-archive \
1411 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1412 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001413 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001414 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001415 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
Dan Albert43e128a2015-01-23 16:12:57 -08001416 $(if $(filter true,$(NATIVE_COVERAGE)),-lgcov) \
Dan Albert343ed672015-01-25 16:20:57 -08001417 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_HOST_LIBPROFILE_RT)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001418 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1419 -o $@ \
1420 $(PRIVATE_LDLIBS)
1421endef
1422endif
1423
1424define transform-host-o-to-shared-lib
Dan Willemsen057aaea2015-08-14 12:59:50 -07001425@echo "$($(PRIVATE_PREFIX)DISPLAY) SharedLib: $(PRIVATE_MODULE) ($@)"
Colin Crossb6da5892015-07-16 17:14:27 -07001426@mkdir -p $(dir $@)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001427$(transform-host-o-to-shared-lib-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001428endef
1429
1430define transform-host-o-to-package
Dan Willemsen057aaea2015-08-14 12:59:50 -07001431@echo "$($(PRIVATE_PREFIX)DISPLAY) Package: $(PRIVATE_MODULE) ($@)"
Colin Crossb6da5892015-07-16 17:14:27 -07001432@mkdir -p $(dir $@)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001433$(transform-host-o-to-shared-lib-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001434endef
1435
1436
1437###########################################################
1438## Commands for running gcc to link a shared library or package
1439###########################################################
1440
The Android Open Source Project88b60792009-03-03 19:28:42 -08001441define transform-o-to-shared-lib-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001442$(hide) $(PRIVATE_CXX) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001443 -nostdlib -Wl,-soname,$(notdir $@) \
1444 -Wl,--gc-sections \
Logan Chiene481e7d2015-01-25 21:15:12 +08001445 $(if $(filter true,$(PRIVATE_CLANG)),-shared,-Wl$(comma)-shared) \
Ying Wang1a081002010-07-13 14:55:47 -07001446 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
Ying Wang491fca92015-07-02 15:57:45 -07001447 $(PRIVATE_TARGET_CRTBEGIN_SO_O) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001448 $(PRIVATE_ALL_OBJECTS) \
1449 -Wl,--whole-archive \
Ying Wang80e6cce2011-01-24 23:25:36 -08001450 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001451 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001452 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001453 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001454 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
Dan Albert91f713a2015-03-31 15:21:30 -07001455 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBGCOV)) \
Dan Albert343ed672015-01-25 16:20:57 -08001456 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBPROFILE_RT)) \
Dan Albert91f713a2015-03-31 15:21:30 -07001457 $(PRIVATE_TARGET_LIBATOMIC) \
1458 $(PRIVATE_TARGET_LIBGCC) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001459 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1460 -o $@ \
Dan Alberte088c0d2014-11-13 10:15:46 -08001461 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
1462 $(PRIVATE_LDFLAGS) \
Ying Wang491fca92015-07-02 15:57:45 -07001463 $(PRIVATE_TARGET_CRTEND_SO_O) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001464 $(PRIVATE_LDLIBS)
1465endef
The Android Open Source Project88b60792009-03-03 19:28:42 -08001466
1467define transform-o-to-shared-lib
The Android Open Source Project88b60792009-03-03 19:28:42 -08001468@echo "target SharedLib: $(PRIVATE_MODULE) ($@)"
Colin Crossb6da5892015-07-16 17:14:27 -07001469@mkdir -p $(dir $@)
Dan Alberte088c0d2014-11-13 10:15:46 -08001470$(transform-o-to-shared-lib-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001471endef
1472
1473
1474###########################################################
1475## Commands for filtering a target executable or library
1476###########################################################
1477
Ying Wangce1c5962014-03-28 17:24:39 -07001478ifneq ($(TARGET_BUILD_VARIANT),user)
1479 TARGET_STRIP_EXTRA = && $(PRIVATE_OBJCOPY) --add-gnu-debuglink=$< $@
1480 TARGET_STRIP_KEEP_SYMBOLS_EXTRA = --add-gnu-debuglink=$<
1481endif
1482
The Android Open Source Project88b60792009-03-03 19:28:42 -08001483define transform-to-stripped
The Android Open Source Project88b60792009-03-03 19:28:42 -08001484@echo "target Strip: $(PRIVATE_MODULE) ($@)"
Colin Crossb6da5892015-07-16 17:14:27 -07001485@mkdir -p $(dir $@)
Ying Wangc1729f32014-08-20 17:12:32 -07001486$(hide) $(PRIVATE_STRIP) --strip-all $< -o $@ \
1487 $(if $(PRIVATE_NO_DEBUGLINK),,$(TARGET_STRIP_EXTRA))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001488endef
1489
Christopher Ferrisa6e2f932014-03-18 14:50:09 -07001490define transform-to-stripped-keep-symbols
Christopher Ferrisa6e2f932014-03-18 14:50:09 -07001491@echo "target Strip (keep symbols): $(PRIVATE_MODULE) ($@)"
Colin Crossb6da5892015-07-16 17:14:27 -07001492@mkdir -p $(dir $@)
Ying Wangce1c5962014-03-28 17:24:39 -07001493$(hide) $(PRIVATE_OBJCOPY) \
1494 `$(PRIVATE_READELF) -S $< | awk '/.debug_/ {print "-R " $$2}' | xargs` \
1495 $(TARGET_STRIP_KEEP_SYMBOLS_EXTRA) $< $@
Christopher Ferrisa6e2f932014-03-18 14:50:09 -07001496endef
1497
Dmitriy Ivanov4c2d1a62015-04-20 16:59:05 -07001498###########################################################
1499## Commands for packing a target executable or library
1500###########################################################
1501
1502define pack-elf-relocations
Dmitriy Ivanov4c2d1a62015-04-20 16:59:05 -07001503@echo "target Pack Relocations: $(PRIVATE_MODULE) ($@)"
Colin Crossb6da5892015-07-16 17:14:27 -07001504$(copy-file-to-target)
Dmitriy Ivanov4c2d1a62015-04-20 16:59:05 -07001505$(hide) $(RELOCATION_PACKER) $@
1506endef
The Android Open Source Project88b60792009-03-03 19:28:42 -08001507
1508###########################################################
1509## Commands for running gcc to link an executable
1510###########################################################
1511
The Android Open Source Project88b60792009-03-03 19:28:42 -08001512define transform-o-to-executable-inner
Dan Alberte088c0d2014-11-13 10:15:46 -08001513$(hide) $(PRIVATE_CXX) -pie \
1514 -nostdlib -Bdynamic \
Evgenii Stepanov8f5e67a2015-07-10 18:06:51 -07001515 -Wl,-dynamic-linker,$(PRIVATE_LINKER) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001516 -Wl,--gc-sections \
1517 -Wl,-z,nocopyreloc \
Ying Wangc6ffc002012-09-25 17:52:10 -07001518 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
Ying Wang9fb35262014-02-21 16:17:05 -08001519 -Wl,-rpath-link=$(PRIVATE_TARGET_OUT_INTERMEDIATE_LIBRARIES) \
Ying Wang491fca92015-07-02 15:57:45 -07001520 $(PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001521 $(PRIVATE_ALL_OBJECTS) \
1522 -Wl,--whole-archive \
1523 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1524 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001525 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001526 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001527 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
Dan Albert91f713a2015-03-31 15:21:30 -07001528 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBGCOV)) \
Dan Albert343ed672015-01-25 16:20:57 -08001529 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBPROFILE_RT)) \
Dan Albert91f713a2015-03-31 15:21:30 -07001530 $(PRIVATE_TARGET_LIBATOMIC) \
1531 $(PRIVATE_TARGET_LIBGCC) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001532 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1533 -o $@ \
Dan Alberte088c0d2014-11-13 10:15:46 -08001534 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
1535 $(PRIVATE_LDFLAGS) \
Ying Wang491fca92015-07-02 15:57:45 -07001536 $(PRIVATE_TARGET_CRTEND_O) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001537 $(PRIVATE_LDLIBS)
1538endef
The Android Open Source Project88b60792009-03-03 19:28:42 -08001539
1540define transform-o-to-executable
The Android Open Source Project88b60792009-03-03 19:28:42 -08001541@echo "target Executable: $(PRIVATE_MODULE) ($@)"
Colin Crossb6da5892015-07-16 17:14:27 -07001542@mkdir -p $(dir $@)
Dan Alberte088c0d2014-11-13 10:15:46 -08001543$(transform-o-to-executable-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001544endef
1545
1546
1547###########################################################
Dan Alberte088c0d2014-11-13 10:15:46 -08001548## Commands for linking a static executable. In practice,
1549## we only use this on arm, so the other platforms don't
1550## have transform-o-to-static-executable defined.
Chih-Hung Hsieh69b1fe62015-01-20 11:00:20 -08001551## Clang driver needs -static to create static executable.
1552## However, bionic/linker uses -shared to overwrite.
1553## Linker for x86 targets does not allow coexistance of -static and -shared,
1554## so we add -static only if -shared is not used.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001555###########################################################
1556
The Android Open Source Project88b60792009-03-03 19:28:42 -08001557define transform-o-to-static-executable-inner
Dan Alberte088c0d2014-11-13 10:15:46 -08001558$(hide) $(PRIVATE_CXX) \
1559 -nostdlib -Bstatic \
Chih-Hung Hsieh69b1fe62015-01-20 11:00:20 -08001560 $(if $(filter $(PRIVATE_LDFLAGS),-shared),,-static) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001561 -Wl,--gc-sections \
1562 -o $@ \
1563 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
Ying Wang491fca92015-07-02 15:57:45 -07001564 $(PRIVATE_TARGET_CRTBEGIN_STATIC_O) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001565 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
1566 $(PRIVATE_LDFLAGS) \
1567 $(PRIVATE_ALL_OBJECTS) \
1568 -Wl,--whole-archive \
1569 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1570 -Wl,--no-whole-archive \
1571 $(call normalize-target-libraries,$(filter-out %libcompiler_rt.a,$(filter-out %libc_nomalloc.a,$(filter-out %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))))) \
1572 -Wl,--start-group \
1573 $(call normalize-target-libraries,$(filter %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
1574 $(call normalize-target-libraries,$(filter %libc_nomalloc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001575 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBGCOV)) \
Dan Albert343ed672015-01-25 16:20:57 -08001576 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBPROFILE_RT)) \
1577 $(PRIVATE_TARGET_LIBATOMIC) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001578 $(call normalize-target-libraries,$(filter %libcompiler_rt.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
Dan Albert741b36e2014-11-13 21:24:04 -08001579 $(PRIVATE_TARGET_LIBGCC) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001580 -Wl,--end-group \
Ying Wang491fca92015-07-02 15:57:45 -07001581 $(PRIVATE_TARGET_CRTEND_O)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001582endef
The Android Open Source Project88b60792009-03-03 19:28:42 -08001583
1584define transform-o-to-static-executable
The Android Open Source Project88b60792009-03-03 19:28:42 -08001585@echo "target StaticExecutable: $(PRIVATE_MODULE) ($@)"
Colin Crossb6da5892015-07-16 17:14:27 -07001586@mkdir -p $(dir $@)
Dan Alberte088c0d2014-11-13 10:15:46 -08001587$(transform-o-to-static-executable-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001588endef
1589
1590
1591###########################################################
1592## Commands for running gcc to link a host executable
1593###########################################################
Ying Wangfaf3d5e2014-04-04 14:37:33 -07001594ifdef BUILD_HOST_static
1595HOST_FPIE_FLAGS :=
1596else
Dan Albert4803ce22014-08-06 12:36:46 -07001597HOST_FPIE_FLAGS := -pie
Stephen Hinesa503fb32014-10-02 00:51:11 -07001598# Force the correct entry point to workaround a bug in binutils that manifests with -pie
Dan Willemsen057aaea2015-08-14 12:59:50 -07001599ifeq ($(HOST_CROSS_OS),windows)
1600HOST_CROSS_FPIE_FLAGS += -Wl,-e_mainCRTStartup
Stephen Hinesa503fb32014-10-02 00:51:11 -07001601endif
Ying Wangfaf3d5e2014-04-04 14:37:33 -07001602endif
The Android Open Source Project88b60792009-03-03 19:28:42 -08001603
1604ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1605define transform-host-o-to-executable-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001606$(hide) $(PRIVATE_CXX) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001607 $(PRIVATE_ALL_OBJECTS) \
1608 -Wl,--whole-archive \
1609 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1610 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001611 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001612 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001613 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
Dan Albert43e128a2015-01-23 16:12:57 -08001614 $(if $(filter true,$(NATIVE_COVERAGE)),-lgcov) \
Dan Albert343ed672015-01-25 16:20:57 -08001615 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_HOST_LIBPROFILE_RT)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001616 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
Dan Willemsen057aaea2015-08-14 12:59:50 -07001617 -Wl,-rpath-link=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)OUT_INTERMEDIATE_LIBRARIES) \
1618 -Wl,-rpath,\$$ORIGIN/../$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)OUT_SHARED_LIBRARIES)) \
1619 -Wl,-rpath,\$$ORIGIN/$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)OUT_SHARED_LIBRARIES)) \
1620 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)GLOBAL_LD_DIRS) \
Conley Owensd9e7d252011-11-10 09:57:40 -08001621 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001622 $(PRIVATE_HOST_GLOBAL_LDFLAGS) \
Conley Owensd9e7d252011-11-10 09:57:40 -08001623 ) \
Torne (Richard Coles)a424bf72014-02-12 14:24:41 +00001624 $(PRIVATE_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001625 -o $@ \
1626 $(PRIVATE_LDLIBS)
1627endef
1628endif
1629
1630define transform-host-o-to-executable
Dan Willemsen057aaea2015-08-14 12:59:50 -07001631@echo "$($(PRIVATE_PREFIX)DISPLAY) Executable: $(PRIVATE_MODULE) ($@)"
Colin Crossb6da5892015-07-16 17:14:27 -07001632@mkdir -p $(dir $@)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001633$(transform-host-o-to-executable-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001634endef
1635
1636
1637###########################################################
1638## Commands for running javac to make .class files
1639###########################################################
1640
Ying Wangd75d8932015-09-19 10:56:35 -07001641# Add BUILD_NUMBER to apps default version name if it's unbundled build.
1642ifdef TARGET_BUILD_APPS
1643APPS_DEFAULT_VERSION_NAME := $(PLATFORM_VERSION)-$(BUILD_NUMBER_FROM_FILE)
1644else
1645APPS_DEFAULT_VERSION_NAME := $(PLATFORM_VERSION)
1646endif
1647
The Android Open Source Project88b60792009-03-03 19:28:42 -08001648# TODO: Right now we generate the asset resources twice, first as part
1649# of generating the Java classes, then at the end when packaging the final
1650# assets. This should be changed to do one of two things: (1) Don't generate
1651# any resource files the first time, only create classes during that stage;
1652# or (2) Don't use the -c flag with the second stage, instead taking the
1653# resource files from the first stage as additional input. My original intent
1654# was to use approach (2), but this requires a little more work in the tool.
1655# Maybe we should just use approach (1).
1656
1657# This rule creates the R.java and Manifest.java files, both of which
Ying Wang4f1ab922011-03-15 13:19:30 -07001658# are PRODUCT-neutral. Don't pass PRIVATE_PRODUCT_AAPT_CONFIG to this invocation.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001659define create-resource-java-files
1660@mkdir -p $(PRIVATE_SOURCE_INTERMEDIATES_DIR)
1661@mkdir -p $(dir $(PRIVATE_RESOURCE_PUBLICS_OUTPUT))
Ying Wangc61d5932010-03-10 16:02:42 -08001662$(hide) $(AAPT) package $(PRIVATE_AAPT_FLAGS) -m \
Ying Wang4f1ab922011-03-15 13:19:30 -07001663 $(eval # PRIVATE_PRODUCT_AAPT_CONFIG is intentionally missing-- see comment.) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001664 $(addprefix -J , $(PRIVATE_SOURCE_INTERMEDIATES_DIR)) \
1665 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
1666 $(addprefix -P , $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) \
1667 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
1668 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001669 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
Joe Onorato2daa2b32009-08-30 13:39:24 -07001670 $(addprefix -G , $(PRIVATE_PROGUARD_OPTIONS_FILE)) \
Ying Wangbb9c2302011-04-08 17:27:35 -07001671 $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
1672 $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
Colin Crossf37b4552015-07-16 17:15:19 -07001673 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,--version-code $(PLATFORM_SDK_VERSION)) \
Ying Wangd75d8932015-09-19 10:56:35 -07001674 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,--version-name $(APPS_DEFAULT_VERSION_NAME)) \
Ying Wang8c254822010-03-16 16:13:56 -07001675 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07001676 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001677endef
1678
Jeffrey Chyan7adbf972010-07-07 13:42:19 -05001679xlint_unchecked := -Xlint:unchecked
The Android Open Source Project88b60792009-03-03 19:28:42 -08001680
1681# emit-line, <word list>, <output file>
1682define emit-line
1683 $(if $(1),echo -n '$(strip $(1)) ' >> $(2))
1684endef
1685
1686# dump-words-to-file, <word list>, <output file>
1687define dump-words-to-file
1688 @rm -f $(2)
1689 @$(call emit-line,$(wordlist 1,200,$(1)),$(2))
1690 @$(call emit-line,$(wordlist 201,400,$(1)),$(2))
1691 @$(call emit-line,$(wordlist 401,600,$(1)),$(2))
1692 @$(call emit-line,$(wordlist 601,800,$(1)),$(2))
1693 @$(call emit-line,$(wordlist 801,1000,$(1)),$(2))
1694 @$(call emit-line,$(wordlist 1001,1200,$(1)),$(2))
1695 @$(call emit-line,$(wordlist 1201,1400,$(1)),$(2))
1696 @$(call emit-line,$(wordlist 1401,1600,$(1)),$(2))
1697 @$(call emit-line,$(wordlist 1601,1800,$(1)),$(2))
1698 @$(call emit-line,$(wordlist 1801,2000,$(1)),$(2))
1699 @$(call emit-line,$(wordlist 2001,2200,$(1)),$(2))
1700 @$(call emit-line,$(wordlist 2201,2400,$(1)),$(2))
1701 @$(call emit-line,$(wordlist 2401,2600,$(1)),$(2))
1702 @$(call emit-line,$(wordlist 2601,2800,$(1)),$(2))
1703 @$(call emit-line,$(wordlist 2801,3000,$(1)),$(2))
1704 @$(call emit-line,$(wordlist 3001,3200,$(1)),$(2))
1705 @$(call emit-line,$(wordlist 3201,3400,$(1)),$(2))
1706 @$(call emit-line,$(wordlist 3401,3600,$(1)),$(2))
1707 @$(call emit-line,$(wordlist 3601,3800,$(1)),$(2))
1708 @$(call emit-line,$(wordlist 3801,4000,$(1)),$(2))
Jesse Wilson72c941a2010-05-04 16:33:49 -07001709 @$(call emit-line,$(wordlist 4001,4200,$(1)),$(2))
1710 @$(call emit-line,$(wordlist 4201,4400,$(1)),$(2))
1711 @$(call emit-line,$(wordlist 4401,4600,$(1)),$(2))
1712 @$(call emit-line,$(wordlist 4601,4800,$(1)),$(2))
1713 @$(call emit-line,$(wordlist 4801,5000,$(1)),$(2))
1714 @$(if $(wordlist 5001,5002,$(1)),$(error Too many words ($(words $(1)))))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001715endef
1716
1717# For a list of jar files, unzip them to a specified directory,
1718# but make sure that no META-INF files come along for the ride.
1719#
1720# $(1): files to unzip
1721# $(2): destination directory
1722define unzip-jar-files
1723 $(hide) for f in $(1); \
1724 do \
1725 if [ ! -f $$f ]; then \
1726 echo Missing file $$f; \
1727 exit 1; \
1728 fi; \
Sriram Ramanf1a55f82009-06-09 15:08:29 -07001729 unzip -qo $$f -d $(2); \
Ying Wang3a6f7582012-08-30 12:59:42 -07001730 done \
1731 $(if $(PRIVATE_DONT_DELETE_JAR_META_INF),,;rm -rf $(2)/META-INF)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001732endef
1733
Brian Carlstrom78269512010-12-10 12:10:24 -08001734# Common definition to invoke javac on the host and target.
1735#
1736# Some historical notes:
1737# - below we write the list of java files to java-source-list to avoid argument
1738# list length problems with Cygwin
1739# - we filter out duplicate java file names because eclipse's compiler
1740# doesn't like them.
1741#
1742# $(1): javac
1743# $(2): bootclasspath
1744define compile-java
Joe Onorato64d85d02009-04-09 19:31:12 -07001745$(hide) rm -f $@
1746$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
Brian Carlstrom78269512010-12-10 12:10:24 -08001747$(hide) mkdir -p $(dir $@)
Joe Onorato64d85d02009-04-09 19:31:12 -07001748$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
Brian Carlstrom78269512010-12-10 12:10:24 -08001749$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES),$(PRIVATE_CLASS_INTERMEDIATES_DIR))
Ying Wang015edd22011-01-20 15:01:56 -08001750$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list)
Joe Onorato64d85d02009-04-09 19:31:12 -07001751$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
Ying Wang4aedea92015-08-04 12:44:38 -07001752 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' -and -not -name '.*' >> $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list; \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001753fi
Ying Wang015edd22011-01-20 15:01:56 -08001754$(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \
1755 | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
Ying Wange109a1d2011-12-12 17:52:03 -08001756$(hide) if [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
1757 $(1) -encoding UTF-8 \
Ying Wang057eba02012-10-18 10:54:49 -07001758 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
Brian Carlstrom78269512010-12-10 12:10:24 -08001759 $(2) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001760 $(addprefix -classpath ,$(strip \
1761 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \
Ying Wang057eba02012-10-18 10:54:49 -07001762 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001763 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
Brian Carlstrom78269512010-12-10 12:10:24 -08001764 $(PRIVATE_JAVACFLAGS) \
Ying Wang015edd22011-01-20 15:01:56 -08001765 \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \
Ying Wange109a1d2011-12-12 17:52:03 -08001766 || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 ) \
1767fi
Joe Onorato0eccce92011-10-30 21:37:35 -07001768$(if $(PRIVATE_JAVA_LAYERS_FILE), $(hide) build/tools/java-layers.py \
1769 $(PRIVATE_JAVA_LAYERS_FILE) \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq,)
Ying Wang015edd22011-01-20 15:01:56 -08001770$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list
1771$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
Ying Wang5758b8e2011-12-15 16:36:55 -08001772$(if $(PRIVATE_JAR_EXCLUDE_FILES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
1773 -name $(word 1, $(PRIVATE_JAR_EXCLUDE_FILES)) \
1774 $(addprefix -o -name , $(wordlist 2, 999, $(PRIVATE_JAR_EXCLUDE_FILES))) \
1775 | xargs rm -rf)
Jeff Brown4c4aa992014-05-23 18:41:19 -07001776$(if $(PRIVATE_JAR_PACKAGES), \
1777 $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -mindepth 1 -type f \
1778 $(foreach pkg, $(PRIVATE_JAR_PACKAGES), \
1779 -not -path $(PRIVATE_CLASS_INTERMEDIATES_DIR)/$(subst .,/,$(pkg))/\*) -delete ; \
1780 find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -empty -delete)
1781$(if $(PRIVATE_JAR_EXCLUDE_PACKAGES), $(hide) rm -rf \
1782 $(foreach pkg, $(PRIVATE_JAR_EXCLUDE_PACKAGES), \
1783 $(PRIVATE_CLASS_INTERMEDIATES_DIR)/$(subst .,/,$(pkg))))
Ying Wanga3b75932013-08-14 16:59:00 -07001784$(if $(PRIVATE_RMTYPEDEFS), $(hide) $(RMTYPEDEFS) -v $(PRIVATE_CLASS_INTERMEDIATES_DIR))
Guang Zhu5c9a1a42013-09-24 19:05:52 -07001785$(if $(PRIVATE_JAR_MANIFEST), \
Colin Crossf37b4552015-07-16 17:15:19 -07001786 $(hide) sed -e "s/%BUILD_NUMBER%/$(BUILD_NUMBER_FROM_FILE)/" \
Guang Zhu5c9a1a42013-09-24 19:05:52 -07001787 $(PRIVATE_JAR_MANIFEST) > $(dir $@)/manifest.mf && \
1788 jar -cfm $@ $(dir $@)/manifest.mf \
1789 -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) ., \
1790 $(hide) jar -cf $@ -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .)
Ying Wang07acdbf2015-01-14 14:23:56 -08001791$(if $(PRIVATE_EXTRA_JAR_ARGS),$(call add-java-resources-to,$@))
Brian Carlstrom78269512010-12-10 12:10:24 -08001792endef
1793
1794define transform-java-to-classes.jar
1795@echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
1796$(call compile-java,$(TARGET_JAVAC),$(PRIVATE_BOOTCLASSPATH))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001797endef
1798
Yohann Rousself09e59e2014-09-08 14:45:14 +02001799# Invoke Jack to compile java from source to dex and jack files.
1800#
1801# Some historical notes:
1802# - below we write the list of java files to java-source-list to avoid argument
1803# list length problems with Cygwin
1804# - we filter out duplicate java file names because Jack doesn't like them.
Yohann Rousself09e59e2014-09-08 14:45:14 +02001805define jack-java-to-dex
1806$(hide) rm -f $@
1807$(hide) rm -f $(PRIVATE_CLASSES_JACK)
1808$(hide) rm -rf $(PRIVATE_JACK_INTERMEDIATES_DIR)
1809$(hide) mkdir -p $(dir $@)
1810$(hide) mkdir -p $(dir $(PRIVATE_CLASSES_JACK))
1811$(hide) mkdir -p $(PRIVATE_JACK_INTERMEDIATES_DIR)
1812$(if $(PRIVATE_JACK_INCREMENTAL_DIR),$(hide) mkdir -p $(PRIVATE_JACK_INCREMENTAL_DIR))
1813$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list)
1814$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
Ying Wang4aedea92015-08-04 12:44:38 -07001815 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' -and -not -name '.*' >> $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list; \
Yohann Rousself09e59e2014-09-08 14:45:14 +02001816fi
1817$(hide) tr ' ' '\n' < $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list \
1818 | sort -u > $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq
1819$(if $(PRIVATE_JACK_PROGUARD_FLAGS), \
1820 $(hide) echo -basedirectory $(CURDIR) > $@.flags; \
1821 echo $(PRIVATE_JACK_PROGUARD_FLAGS) >> $@.flags; \
1822)
1823$(if $(PRIVATE_EXTRA_JAR_ARGS),
1824 $(hide) mkdir -p $@.res.tmp
1825 $(hide) $(call create-empty-package-at,$@.res.tmp.zip)
1826 $(hide) $(call add-java-resources-to,$@.res.tmp.zip)
1827 $(hide) $(call unzip-jar-files,$@.res.tmp.zip,$@.res.tmp)
1828 $(hide) rm $@.res.tmp.zip)
1829$(hide) if [ -s $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
1830 export tmpEcjArg="@$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq"; \
1831else \
1832 export tmpEcjArg=""; \
1833fi; \
1834$(call call-jack,$(PRIVATE_JACK_VM_ARGS),$(PRIVATE_JACK_EXTRA_ARGS)) \
1835 $(strip $(PRIVATE_JACK_FLAGS)) \
Yohann Rousself09e59e2014-09-08 14:45:14 +02001836 $(if $(NO_OPTIMIZE_DX), \
1837 -D jack.dex.optimize="false") \
Yohann Rousselb518c3e2015-05-20 17:52:15 +02001838 $(if $(PRIVATE_RMTYPEDEFS), \
1839 -D jack.android.remove-typedef="true") \
Yohann Rousself09e59e2014-09-08 14:45:14 +02001840 $(addprefix --classpath ,$(strip \
1841 $(call normalize-path-list,$(PRIVATE_BOOTCLASSPATH_JAVA_LIBRARIES) $(PRIVATE_ALL_JACK_LIBRARIES)))) \
1842 $(addprefix --import ,$(call reverse-list,$(PRIVATE_STATIC_JACK_LIBRARIES))) \
1843 $(if $(PRIVATE_EXTRA_JAR_ARGS),--import-resource $@.res.tmp) \
1844 -D jack.import.resource.policy=keep-first \
1845 -D jack.import.type.policy=keep-first \
1846 --output-jack $(PRIVATE_CLASSES_JACK) \
1847 -D jack.java.source.version=1.7 \
1848 $(if $(PRIVATE_JACK_INCREMENTAL_DIR),--incremental-folder $(PRIVATE_JACK_INCREMENTAL_DIR)) \
1849 --output-dex $(PRIVATE_JACK_INTERMEDIATES_DIR) \
1850 $(addprefix --config-jarjar ,$(strip $(PRIVATE_JARJAR_RULES))) \
1851 $(if $(PRIVATE_JACK_PROGUARD_FLAGS),--config-proguard $@.flags) \
1852 $$tmpEcjArg \
1853 || ( rm -rf $(PRIVATE_CLASSES_JACK); rm -rf $(PRIVATE_JACK_INTERMEDIATES_DIR); exit 41 )
1854$(hide) mv $(PRIVATE_JACK_INTERMEDIATES_DIR)/classes*.dex $(dir $@)
1855$(hide) rm -f $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list
1856$(if $(PRIVATE_EXTRA_JAR_ARGS),$(hide) rm -rf $@.res.tmp)
1857$(hide) mv $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq $(PRIVATE_JACK_INTERMEDIATES_DIR).java-source-list
1858$(if $(PRIVATE_JAR_PACKAGES), $(hide) echo unsupported options PRIVATE_JAR_PACKAGES in $@; exit 53)
1859$(if $(PRIVATE_JAR_EXCLUDE_PACKAGES), $(hide) echo unsupported options JAR_EXCLUDE_PACKAGES in $@; exit 53)
1860$(if $(PRIVATE_JAR_MANIFEST), $(hide) echo unsupported options JAR_MANIFEST in $@; exit 53)
1861endef
1862
1863define transform-jar-to-jack
1864 $(hide) mkdir -p $(dir $@)
1865 $(JILL) $(PRIVATE_JILL_FLAGS) --output $@.tmpjill.jack $<
1866 $(hide) mkdir -p $@.tmpjill.res
1867 $(hide) $(call unzip-jar-files,$<,$@.tmpjill.res)
1868 $(hide) find $@.tmpjill.res -iname "*.class" -delete
1869 $(hide) $(call call-jack,$(PRIVATE_JACK_VM_ARGS),$(PRIVATE_JACK_EXTRA_ARGS)) \
1870 -D jack.import.resource.policy=keep-first \
1871 -D jack.import.type.policy=keep-first \
1872 --import $@.tmpjill.jack \
1873 --import-resource $@.tmpjill.res \
1874 --output-jack $@
1875 $(hide) rm -rf $@.tmpjill.res
1876 $(hide) rm $@.tmpjill.jack
1877endef
1878
1879
1880# Invoke Jack to compile java from source to jack files without shrink or obfuscation.
1881#
1882# Some historical notes:
1883# - below we write the list of java files to java-source-list to avoid argument
1884# list length problems with Cygwin
1885# - we filter out duplicate java file names because Jack doesn't like them.
1886define java-to-jack
1887$(hide) rm -f $@
1888$(hide) rm -rf $(PRIVATE_JACK_INTERMEDIATES_DIR)
1889$(hide) mkdir -p $(dir $@)
1890$(hide) mkdir -p $(PRIVATE_JACK_INTERMEDIATES_DIR)
1891$(if $(PRIVATE_JACK_INCREMENTAL_DIR),$(hide) mkdir -p $(PRIVATE_JACK_INCREMENTAL_DIR))
1892$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list)
1893$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
Ying Wang4aedea92015-08-04 12:44:38 -07001894 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' -and -not -name '.*' >> $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list; \
Yohann Rousself09e59e2014-09-08 14:45:14 +02001895fi
1896$(hide) tr ' ' '\n' < $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list \
1897 | sort -u > $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq
1898$(if $(PRIVATE_JACK_PROGUARD_FLAGS), \
1899 $(hide) echo -basedirectory $(CURDIR) > $@.flags; \
1900 echo $(PRIVATE_JACK_PROGUARD_FLAGS) >> $@.flags; \
1901)
1902$(if $(PRIVATE_EXTRA_JAR_ARGS),
1903 $(hide) mkdir -p $@.res.tmp
1904 $(hide) $(call create-empty-package-at,$@.res.tmp.zip)
1905 $(hide) $(call add-java-resources-to,$@.res.tmp.zip)
1906 $(hide) unzip -qo $@.res.tmp.zip -d $@.res.tmp
1907 $(hide) rm $@.res.tmp.zip)
1908$(hide) if [ -s $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
1909 export tmpEcjArg="@$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq"; \
1910else \
1911 export tmpEcjArg=""; \
1912fi; \
1913$(call call-jack,$(PRIVATE_JACK_VM_ARGS),$(PRIVATE_JACK_EXTRA_ARGS)) \
1914 $(strip $(PRIVATE_JACK_FLAGS)) \
Yohann Rousself09e59e2014-09-08 14:45:14 +02001915 $(if $(NO_OPTIMIZE_DX), \
1916 -D jack.dex.optimize="false") \
1917 $(addprefix --classpath ,$(strip \
1918 $(call normalize-path-list,$(PRIVATE_BOOTCLASSPATH_JAVA_LIBRARIES) $(PRIVATE_ALL_JACK_LIBRARIES)))) \
1919 $(addprefix --import ,$(call reverse-list,$(PRIVATE_STATIC_JACK_LIBRARIES))) \
1920 $(if $(PRIVATE_EXTRA_JAR_ARGS),--import-resource $@.res.tmp) \
1921 -D jack.import.resource.policy=keep-first \
1922 -D jack.import.type.policy=keep-first \
1923 -D jack.java.source.version=1.7 \
1924 $(if $(PRIVATE_JACK_INCREMENTAL_DIR),--incremental-folder $(PRIVATE_JACK_INCREMENTAL_DIR)) \
1925 --output-jack $@ \
1926 $(addprefix --config-jarjar ,$(strip $(PRIVATE_JARJAR_RULES))) \
1927 $(if $(PRIVATE_JACK_PROGUARD_FLAGS),--config-proguard $@.flags) \
1928 $$tmpEcjArg \
1929 || ( rm -f $@ ; exit 41 )
1930$(hide) rm -f $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list
1931$(if $(PRIVATE_EXTRA_JAR_ARGS),$(hide) rm -rf $@.res.tmp)
1932$(hide) mv $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq $(PRIVATE_JACK_INTERMEDIATES_DIR).java-source-list
1933$(if $(PRIVATE_JAR_PACKAGES), $(hide) echo unsupported options PRIVATE_JAR_PACKAGES in $@; exit 53)
1934$(if $(PRIVATE_JAR_EXCLUDE_PACKAGES), $(hide) echo unsupported options JAR_EXCLUDE_PACKAGES in $@; exit 53)
1935$(if $(PRIVATE_JAR_MANIFEST), $(hide) echo unsupported options JAR_MANIFEST in $@; exit 53)
1936endef
1937
The Android Open Source Project88b60792009-03-03 19:28:42 -08001938define transform-classes.jar-to-emma
1939$(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \
Guang Zhu155afe32010-03-10 15:48:03 -08001940 $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR) \
Guang Zhu9cd3d8c2010-06-15 13:31:25 -07001941 $(addprefix -ix , $(PRIVATE_EMMA_COVERAGE_FILTER))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001942endef
1943
1944#TODO: use a smaller -Xmx value for most libraries;
1945# only core.jar and framework.jar need a heap this big.
1946define transform-classes.jar-to-dex
1947@echo "target Dex: $(PRIVATE_MODULE)"
1948@mkdir -p $(dir $@)
Ying Wangaf9757e2014-07-17 21:24:42 -07001949$(hide) rm -f $(dir $@)classes*.dex
Raphaelf6ff4c52009-08-18 14:43:32 -07001950$(hide) $(DX) \
Dan Willemsen145ae322015-08-13 14:31:36 -07001951 -JXms16M -JXmx2048M \
Yohann Roussel8ffe9c32013-08-20 17:05:27 +02001952 --dex --output=$(dir $@) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001953 $(if $(NO_OPTIMIZE_DX), \
1954 --no-optimize) \
1955 $(if $(GENERATE_DEX_DEBUG), \
1956 --debug --verbose \
1957 --dump-to=$(@:.dex=.lst) \
1958 --dump-width=1000) \
1959 $(PRIVATE_DX_FLAGS) \
1960 $<
1961endef
1962
1963# Create a mostly-empty .jar file that we'll add to later.
1964# The MacOS jar tool doesn't like creating empty jar files,
1965# so we need to give it something.
Yohann Rousself09e59e2014-09-08 14:45:14 +02001966# $(1) package to create
1967define create-empty-package-at
1968@mkdir -p $(dir $(1))
1969$(hide) touch $(dir $(1))dummy
1970$(hide) (cd $(dir $(1)) && jar cf $(notdir $(1)) dummy)
1971$(hide) zip -qd $(1) dummy
1972$(hide) rm $(dir $(1))dummy
1973endef
1974
1975# Create a mostly-empty .jar file that we'll add to later.
1976# The MacOS jar tool doesn't like creating empty jar files,
1977# so we need to give it something.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001978define create-empty-package
Yohann Rousself09e59e2014-09-08 14:45:14 +02001979@mkdir -p $(dir $(1))
1980$(hide) touch $(dir $(1))zipdummy
1981$(hide) (cd $(dir $(1)) && jar cf $(notdir $(1)) zipdummy)
1982$(hide) zip -qd $(1) zipdummy
1983$(hide) rm $(dir $(1))zipdummy
1984endef
1985
1986# Create a mostly-empty .jar file that we'll add to later.
1987# The MacOS jar tool doesn't like creating empty jar files,
1988# so we need to give it something.
1989define create-empty-package
1990$(call create-empty-package-at,$@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001991endef
1992
Ying Wang07acdbf2015-01-14 14:23:56 -08001993# Copy an arhchive file and delete any class files and empty folders inside.
1994# $(1): the source archive file.
1995# $(2): the destination archive file.
1996define initialize-package-file
1997@mkdir -p $(dir $(2))
1998$(hide) cp -f $(1) $(2)
Fredrik Roubertcc93f0c2015-01-28 21:29:38 +01001999$(hide) zip -qd $(2) "*.class" \
2000 $(if $(strip $(PRIVATE_DONT_DELETE_JAR_DIRS)),,"*/") \
2001 || true # Ignore the error when nothing to delete.
Ying Wang07acdbf2015-01-14 14:23:56 -08002002endef
2003
The Android Open Source Project88b60792009-03-03 19:28:42 -08002004#TODO: we kinda want to build different asset packages for
2005# different configurations, then combine them later (or something).
2006# Per-locale, etc.
2007# A list of dynamic and static parameters; build layers for
2008# dynamic params that lay over the static ones.
2009#TODO: update the manifest to point to the package file
Dianne Hackborn9bd54042009-05-15 18:01:20 -07002010#Note that the version numbers are given to aapt as simple default
2011#values; applications can override these by explicitly stating
2012#them in their manifest.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002013define add-assets-to-package
Ying Wangc61d5932010-03-10 16:02:42 -08002014$(hide) $(AAPT) package -u $(PRIVATE_AAPT_FLAGS) \
Ying Wang4f1ab922011-03-15 13:19:30 -07002015 $(addprefix -c , $(PRIVATE_PRODUCT_AAPT_CONFIG)) \
Adam Lesinski2d1718a2014-05-09 10:57:48 -07002016 $(addprefix --preferred-density , $(PRIVATE_PRODUCT_AAPT_PREF_CONFIG)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08002017 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
2018 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
2019 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
2020 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
Ying Wangbb9c2302011-04-08 17:27:35 -07002021 $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
2022 $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
Ying Wangf39752e2014-03-20 17:28:57 -07002023 $(if $(filter --product,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --product , $(TARGET_AAPT_CHARACTERISTICS))) \
Colin Crossf37b4552015-07-16 17:15:19 -07002024 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,--version-code $(PLATFORM_SDK_VERSION)) \
Ying Wangd75d8932015-09-19 10:56:35 -07002025 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,--version-name $(APPS_DEFAULT_VERSION_NAME)) \
Jeff Hamiltonbb67d212010-02-05 22:36:42 -06002026 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07002027 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08002028 -F $@
2029endef
2030
Ying Wang8e20ef62014-06-24 20:01:52 -07002031# We need the extra blank line, so that the command will be on a separate line.
2032# $(1): the ABI name
2033# $(2): the list of shared libraies
2034define _add-jni-shared-libs-to-package-per-abi
2035$(hide) cp $(2) $(dir $@)lib/$(1)
2036
2037endef
2038
The Android Open Source Project88b60792009-03-03 19:28:42 -08002039define add-jni-shared-libs-to-package
2040$(hide) rm -rf $(dir $@)lib
Ying Wang8e20ef62014-06-24 20:01:52 -07002041$(hide) mkdir -p $(addprefix $(dir $@)lib/,$(PRIVATE_JNI_SHARED_LIBRARIES_ABI))
2042$(foreach abi,$(PRIVATE_JNI_SHARED_LIBRARIES_ABI),\
2043 $(call _add-jni-shared-libs-to-package-per-abi,$(abi),\
2044 $(patsubst $(abi):%,%,$(filter $(abi):%,$(PRIVATE_JNI_SHARED_LIBRARIES)))))
Colin Cross92f83482015-09-28 16:15:09 -07002045$(hide) (cd $(dir $@) && zip -qr \
Dmitriy Ivanov8f948742015-04-17 11:00:15 -07002046 $(if $(filter true, $(PRIVATE_PAGE_ALIGN_JNI_SHARED_LIBRARIES)),-0,) $(notdir $@) lib)
The Android Open Source Project88b60792009-03-03 19:28:42 -08002047$(hide) rm -rf $(dir $@)lib
2048endef
2049
The Android Open Source Project88b60792009-03-03 19:28:42 -08002050#TODO: update the manifest to point to the dex file
2051define add-dex-to-package
Ying Wangaf9757e2014-07-17 21:24:42 -07002052$(hide) zip -qj $@ $(dir $(PRIVATE_DEX_FILE))classes*.dex
The Android Open Source Project88b60792009-03-03 19:28:42 -08002053endef
2054
Ying Wang85480622012-08-09 15:20:50 -07002055# Add java resources added by the current module.
Ying Wang07acdbf2015-01-14 14:23:56 -08002056# $(1) destination package
Ying Wang85480622012-08-09 15:20:50 -07002057#
Ying Wang07acdbf2015-01-14 14:23:56 -08002058define add-java-resources-to
2059$(call dump-words-to-file, $(PRIVATE_EXTRA_JAR_ARGS), $(1).jar-arg-list)
2060$(hide) jar uf $(1) @$(1).jar-arg-list
2061@rm -f $(1).jar-arg-list
Ying Wang85480622012-08-09 15:20:50 -07002062endef
2063
Yohann Rousself09e59e2014-09-08 14:45:14 +02002064# Add resources carried by static Jack libraries.
2065#
2066define add-carried-jack-resources
2067 $(hide) if [ -d $(PRIVATE_JACK_INTERMEDIATES_DIR) ] ; then \
2068 jack_res_jar_flags=$$(find $(PRIVATE_JACK_INTERMEDIATES_DIR) -type f \
2069 | sed -e "s?^$(PRIVATE_JACK_INTERMEDIATES_DIR)/? -C $(PRIVATE_JACK_INTERMEDIATES_DIR) ?"); \
2070 if [ -n "$$jack_res_jar_flags" ] ; then \
2071 echo $$jack_res_jar_flags >$(dir $@)jack_res_jar_flags; \
2072 jar uf $@ $$jack_res_jar_flags; \
2073 fi; \
2074fi
2075endef
2076
The Android Open Source Project88b60792009-03-03 19:28:42 -08002077# Sign a package using the specified key/cert.
2078#
2079define sign-package
2080$(hide) mv $@ $@.unsigned
2081$(hide) java -jar $(SIGNAPK_JAR) \
Ying Wang31df0682012-11-13 10:55:28 -08002082 $(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) \
2083 $(PRIVATE_ADDITIONAL_CERTIFICATES) $@.unsigned $@.signed
The Android Open Source Project88b60792009-03-03 19:28:42 -08002084$(hide) mv $@.signed $@
2085endef
2086
Dmitriy Ivanov13e59652014-07-23 15:27:21 -07002087# 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 -08002088#
2089define align-package
2090$(hide) mv $@ $@.unaligned
Dmitriy Ivanov13e59652014-07-23 15:27:21 -07002091$(hide) $(ZIPALIGN) \
2092 -f \
Dmitriy Ivanov8f948742015-04-17 11:00:15 -07002093 $(if $(filter true, $(PRIVATE_PAGE_ALIGN_JNI_SHARED_LIBRARIES)),-p,) \
Dmitriy Ivanov13e59652014-07-23 15:27:21 -07002094 4 \
2095 $@.unaligned $@.aligned
The Android Open Source Project88b60792009-03-03 19:28:42 -08002096$(hide) mv $@.aligned $@
2097endef
2098
Nick Kralevich5aa02232015-04-17 16:53:15 -07002099define uncompress-shared-libs
2100$(hide) rm -rf $(dir $@)/tmpworkdir
2101$(hide) mv $@ $@.compressed
2102$(hide) mkdir $(dir $@)/tmpworkdir
2103$(hide) unzip $@.compressed 'lib/*.so' -d $(dir $@)/tmpworkdir
2104$(hide) ( cd $(dir $@)/tmpworkdir && zip -D -r -0 ../$(notdir $@).compressed lib )
2105$(hide) mv $@.compressed $@
2106$(hide) rm -rf $(dir $@)/tmpworkdir
2107endef
2108
The Android Open Source Project88b60792009-03-03 19:28:42 -08002109define install-dex-debug
2110$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.dex" ]; then \
2111 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
2112 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.dex \
2113 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).dex; \
2114 fi
2115$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.lst" ]; then \
2116 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
2117 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.lst \
2118 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).lst; \
2119 fi
2120endef
2121
2122# TODO(joeo): If we can ever upgrade to post 3.81 make and get the
2123# new prebuilt rules to work, we should change this to copy the
2124# resources to the out directory and then copy the resources.
2125
Brian Carlstrom78269512010-12-10 12:10:24 -08002126# Note: we intentionally don't clean PRIVATE_CLASS_INTERMEDIATES_DIR
2127# in transform-java-to-classes for the sake of vm-tests.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002128define transform-host-java-to-package
Dan Willemsen057aaea2015-08-14 12:59:50 -07002129@echo "$($(PRIVATE_PREFIX)DISPLAY) Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
Ying Wang015edd22011-01-20 15:01:56 -08002130$(call compile-java,$(HOST_JAVAC),$(PRIVATE_BOOTCLASSPATH))
The Android Open Source Project88b60792009-03-03 19:28:42 -08002131endef
2132
2133###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08002134## Commands for copying files
2135###########################################################
2136
2137# Define a rule to copy a header. Used via $(eval) by copy_headers.make.
2138# $(1): source header
2139# $(2): destination header
2140define copy-one-header
2141$(2): $(1)
2142 @echo "Header: $$@"
2143 $$(copy-file-to-new-target-with-cp)
2144endef
2145
2146# Define a rule to copy a file. For use via $(eval).
2147# $(1): source file
2148# $(2): destination file
2149define copy-one-file
2150$(2): $(1) | $(ACP)
2151 @echo "Copy: $$@"
2152 $$(copy-file-to-target)
2153endef
2154
Joe Onoratoe44705a2012-05-17 17:12:04 -07002155# Copies many files.
2156# $(1): The files to copy. Each entry is a ':' separated src:dst pair
2157# Evaluates to the list of the dst files (ie suitable for a dependency list)
2158define copy-many-files
2159$(foreach f, $(1), $(strip \
2160 $(eval _cmf_tuple := $(subst :, ,$(f))) \
2161 $(eval _cmf_src := $(word 1,$(_cmf_tuple))) \
2162 $(eval _cmf_dest := $(word 2,$(_cmf_tuple))) \
2163 $(eval $(call copy-one-file,$(_cmf_src),$(_cmf_dest))) \
2164 $(_cmf_dest)))
2165endef
2166
Ying Wang3ceecfa2012-05-14 14:39:00 -07002167# Copy the file only if it's a well-formed xml file. For use via $(eval).
2168# $(1): source file
2169# $(2): destination file, must end with .xml.
2170define copy-xml-file-checked
2171$(2): $(1) | $(ACP)
2172 @echo "Copy xml: $$@"
2173 $(hide) xmllint $$< >/dev/null # Don't print the xml file to stdout.
2174 $$(copy-file-to-target)
2175endef
2176
The Android Open Source Project88b60792009-03-03 19:28:42 -08002177# The -t option to acp and the -p option to cp is
2178# required for OSX. OSX has a ridiculous restriction
2179# where it's an error for a .a file's modification time
2180# to disagree with an internal timestamp, and this
2181# macro is used to install .a files (among other things).
2182
2183# Copy a single file from one place to another,
2184# preserving permissions and overwriting any existing
2185# file.
Ian Rogers76a6dc32012-10-01 16:36:23 -07002186# We disable the "-t" option for acp cannot handle
Ying Wang84ed6fa2011-01-18 17:21:20 -08002187# high resolution timestamp correctly on file systems like ext4.
2188# Therefore copy-file-to-target is the same as copy-file-to-new-target.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002189define copy-file-to-target
2190@mkdir -p $(dir $@)
Ying Wang84ed6fa2011-01-18 17:21:20 -08002191$(hide) $(ACP) -fp $< $@
The Android Open Source Project88b60792009-03-03 19:28:42 -08002192endef
2193
2194# The same as copy-file-to-target, but use the local
2195# cp command instead of acp.
2196define copy-file-to-target-with-cp
2197@mkdir -p $(dir $@)
2198$(hide) cp -fp $< $@
2199endef
2200
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07002201# The same as copy-file-to-target, but use the zipalign tool to do so.
2202define copy-file-to-target-with-zipalign
2203@mkdir -p $(dir $@)
2204$(hide) $(ZIPALIGN) -f 4 $< $@
2205endef
2206
Doug Zongker1046d202009-08-06 13:02:19 -07002207# The same as copy-file-to-target, but strip out "# comment"-style
2208# comments (for config files and such).
2209define copy-file-to-target-strip-comments
2210@mkdir -p $(dir $@)
2211$(hide) sed -e 's/#.*$$//' -e 's/[ \t]*$$//' -e '/^$$/d' < $< > $@
2212endef
2213
The Android Open Source Project88b60792009-03-03 19:28:42 -08002214# The same as copy-file-to-target, but don't preserve
2215# the old modification time.
2216define copy-file-to-new-target
2217@mkdir -p $(dir $@)
2218$(hide) $(ACP) -fp $< $@
2219endef
2220
2221# The same as copy-file-to-new-target, but use the local
2222# cp command instead of acp.
2223define copy-file-to-new-target-with-cp
2224@mkdir -p $(dir $@)
2225$(hide) cp -f $< $@
2226endef
2227
2228# Copy a prebuilt file to a target location.
2229define transform-prebuilt-to-target
2230@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"
2231$(copy-file-to-target)
2232endef
2233
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07002234# Copy a prebuilt file to a target location, using zipalign on it.
2235define transform-prebuilt-to-target-with-zipalign
2236@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt APK: $(PRIVATE_MODULE) ($@)"
2237$(copy-file-to-target-with-zipalign)
2238endef
2239
Doug Zongker1046d202009-08-06 13:02:19 -07002240# Copy a prebuilt file to a target location, stripping "# comment" comments.
2241define transform-prebuilt-to-target-strip-comments
2242@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"
2243$(copy-file-to-target-strip-comments)
2244endef
2245
Ying Wangc45a47b2015-04-08 12:24:37 -07002246# Copy a list of files/directories to target location, with sub dir structure preserved.
2247# For example $(HOST_OUT_EXECUTABLES)/aapt -> $(staging)/bin/aapt .
2248# $(1): the source list of files/directories.
2249# $(2): the path prefix to strip. In the above example it would be $(HOST_OUT).
2250# $(3): the target location.
2251define copy-files-with-structure
2252$(foreach t,$(1),\
2253 $(eval s := $(patsubst $(2)%,%,$(t)))\
2254 $(hide) mkdir -p $(dir $(3)/$(s)); cp -Rf $(t) $(3)/$(s)$(newline))
2255endef
2256
The Android Open Source Project88b60792009-03-03 19:28:42 -08002257
2258###########################################################
Ying Wang3b2bdf12010-02-01 09:51:23 -08002259## Commands to call Proguard
2260###########################################################
Ying Wang3b2bdf12010-02-01 09:51:23 -08002261define transform-jar-to-proguard
Ying Wang7311a342013-08-21 18:32:49 -07002262@echo Proguard: $@
Mihail Dumitrescu4df82b32014-02-07 15:18:59 +00002263$(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS) \
2264 $(addprefix -injars , $(PRIVATE_EXTRA_INPUT_JAR))
Ying Wang3b2bdf12010-02-01 09:51:23 -08002265endef
2266
Ying Wang3b2bdf12010-02-01 09:51:23 -08002267###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08002268## Stuff source generated from one-off tools
2269###########################################################
2270
2271define transform-generated-source
2272@echo "target Generated: $(PRIVATE_MODULE) <= $<"
2273@mkdir -p $(dir $@)
2274$(hide) $(PRIVATE_CUSTOM_TOOL)
2275endef
2276
2277
2278###########################################################
2279## Assertions about attributes of the target
2280###########################################################
2281
2282# $(1): The file to check
2283ifndef get-file-size
2284$(error HOST_OS must define get-file-size)
2285endif
2286
Doug Zongker4647f122009-07-02 09:00:54 -07002287# Convert a partition data size (eg, as reported in /proc/mtd) to the
2288# size of the image used to flash that partition (which includes a
Lars Svensson9cb8c282010-12-06 15:24:58 +01002289# spare area for each page).
Doug Zongker4647f122009-07-02 09:00:54 -07002290# $(1): the partition data size
2291define image-size-from-data-size
Ying Wang4a2ecaf2011-02-09 17:24:27 -08002292$(strip $(eval _isfds_value := $$(shell echo $$$$(($(1) / $(BOARD_NAND_PAGE_SIZE) * \
2293 ($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE))))))\
2294$(if $(filter 0, $(_isfds_value)),$(shell echo $$(($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE)))),$(_isfds_value))\
2295$(eval _isfds_value :=))
Doug Zongker4647f122009-07-02 09:00:54 -07002296endef
2297
2298# $(1): The file(s) to check (often $@)
JP Abgrall0ed7cec2014-06-16 14:19:36 -07002299# $(2): The maximum total image size, in decimal bytes.
2300# Make sure to take into account any reserved space needed for the FS.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002301#
2302# If $(2) is empty, evaluates to "true"
2303#
2304# Reserve bad blocks. Make sure that MAX(1% of partition size, 2 blocks)
2305# is left over after the image has been flashed. Round the 1% up to the
2306# next whole flash block size.
2307define assert-max-file-size
2308$(if $(2), \
Doug Zongker742fa572009-07-08 12:09:04 -07002309 size=$$(for i in $(1); do $(call get-file-size,$$i); echo +; done; echo 0); \
2310 total=$$(( $$( echo "$$size" ) )); \
Doug Zongker4647f122009-07-02 09:00:54 -07002311 printname=$$(echo -n "$(1)" | tr " " +); \
Doug Zongker4647f122009-07-02 09:00:54 -07002312 img_blocksize=$(call image-size-from-data-size,$(BOARD_FLASH_BLOCK_SIZE)); \
2313 twoblocks=$$((img_blocksize * 2)); \
2314 onepct=$$((((($(2) / 100) - 1) / img_blocksize + 1) * img_blocksize)); \
JP Abgrall0ed7cec2014-06-16 14:19:36 -07002315 reserve=$$((twoblocks > onepct ? twoblocks : onepct)); \
Doug Zongker4647f122009-07-02 09:00:54 -07002316 maxsize=$$(($(2) - reserve)); \
Ying Wang99bcbeb2011-12-02 10:34:45 -08002317 echo "$$printname maxsize=$$maxsize blocksize=$$img_blocksize total=$$total reserve=$$reserve"; \
Doug Zongker4647f122009-07-02 09:00:54 -07002318 if [ "$$total" -gt "$$maxsize" ]; then \
2319 echo "error: $$printname too large ($$total > [$(2) - $$reserve])"; \
2320 false; \
Doug Zongker742fa572009-07-08 12:09:04 -07002321 elif [ "$$total" -gt $$((maxsize - 32768)) ]; then \
Doug Zongker4647f122009-07-02 09:00:54 -07002322 echo "WARNING: $$printname approaching size limit ($$total now; limit $$maxsize)"; \
The Android Open Source Project88b60792009-03-03 19:28:42 -08002323 fi \
2324 , \
2325 true \
2326 )
2327endef
2328
Doug Zongker8510a1e2009-08-07 16:38:08 -07002329# Like assert-max-file-size, but the second argument is a partition
2330# size, which we'll convert to a max image size before checking it
2331# against the files.
2332#
2333# $(1): The file(s) to check (often $@)
2334# $(2): The partition size.
2335define assert-max-image-size
2336$(if $(2), \
JP Abgrall0ed7cec2014-06-16 14:19:36 -07002337 $(call assert-max-file-size,$(1),$(call image-size-from-data-size,$(2))))
Doug Zongker8510a1e2009-08-07 16:38:08 -07002338endef
2339
Doug Zongkere01100c2009-06-19 17:12:18 -07002340
2341###########################################################
2342## Define device-specific radio files
2343###########################################################
Ying Wang94de1eb2013-07-26 12:19:20 -07002344INSTALLED_RADIOIMAGE_TARGET :=
Doug Zongkere01100c2009-06-19 17:12:18 -07002345
2346# Copy a radio image file to the output location, and add it to
2347# INSTALLED_RADIOIMAGE_TARGET.
2348# $(1): filename
2349define add-radio-file
Doug Zongker14833602010-02-02 13:12:04 -08002350 $(eval $(call add-radio-file-internal,$(1),$(notdir $(1))))
Doug Zongkere01100c2009-06-19 17:12:18 -07002351endef
2352define add-radio-file-internal
Doug Zongker14833602010-02-02 13:12:04 -08002353INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
Doug Zongker14833602010-02-02 13:12:04 -08002354$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP)
Doug Zongkere01100c2009-06-19 17:12:18 -07002355 $$(transform-prebuilt-to-target)
2356endef
2357
Doug Zongker9296f092012-03-20 16:42:22 -07002358# Version of add-radio-file that also arranges for the version of the
2359# file to be checked against the contents of
2360# $(TARGET_BOARD_INFO_FILE).
2361# $(1): filename
2362# $(2): name of version variable in board-info (eg, "version-baseband")
2363define add-radio-file-checked
2364 $(eval $(call add-radio-file-checked-internal,$(1),$(notdir $(1)),$(2)))
2365endef
2366define add-radio-file-checked-internal
2367INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
2368BOARD_INFO_CHECK += $(3):$(LOCAL_PATH)/$(1)
2369$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP)
2370 $$(transform-prebuilt-to-target)
2371endef
2372
Doug Zongkere01100c2009-06-19 17:12:18 -07002373
The Android Open Source Project88b60792009-03-03 19:28:42 -08002374###########################################################
Joe Onorato899e62a2010-02-04 17:37:21 -08002375# Override the package defined in $(1), setting the
2376# variables listed below differently.
2377#
2378# $(1): The makefile to override (relative to the source
2379# tree root)
2380# $(2): Old LOCAL_PACKAGE_NAME value.
2381# $(3): New LOCAL_PACKAGE_NAME value.
Ying Wang3dae0ee2010-09-02 15:41:01 -07002382# $(4): New LOCAL_MANIFEST_PACKAGE_NAME value.
2383# $(5): New LOCAL_CERTIFICATE value.
2384# $(6): New LOCAL_INSTRUMENTATION_FOR value.
2385# $(7): New LOCAL_MANIFEST_INSTRUMENTATION_FOR value.
Joe Onorato899e62a2010-02-04 17:37:21 -08002386#
2387# Note that LOCAL_PACKAGE_OVERRIDES is NOT cleared in
2388# clear_vars.mk.
2389###########################################################
2390define inherit-package
Ying Wang3dae0ee2010-09-02 15:41:01 -07002391 $(eval $(call inherit-package-internal,$(1),$(2),$(3),$(4),$(5),$(6),$(7)))
Joe Onorato899e62a2010-02-04 17:37:21 -08002392endef
2393
2394define inherit-package-internal
2395 LOCAL_PACKAGE_OVERRIDES \
Ying Wang3dae0ee2010-09-02 15:41:01 -07002396 := $(strip $(1))||$(strip $(2))||$(strip $(3))||$(strip $(4))||&&$(strip $(5))||&&$(strip $(6))||&&$(strip $(7)) $(LOCAL_PACKAGE_OVERRIDES)
Joe Onorato899e62a2010-02-04 17:37:21 -08002397 include $(1)
2398 LOCAL_PACKAGE_OVERRIDES \
2399 := $(wordlist 1,$(words $(LOCAL_PACKAGE_OVERRIDES)), $(LOCAL_PACKAGE_OVERRIDES))
2400endef
2401
2402# To be used with inherit-package above
2403# Evalutes to true if the package was overridden
2404define set-inherited-package-variables
2405$(strip $(call set-inherited-package-variables-internal))
2406endef
2407
2408define keep-or-override
2409$(eval $(1) := $(if $(2),$(2),$($(1))))
2410endef
2411
2412define set-inherited-package-variables-internal
2413 $(eval _o := $(subst ||, ,$(lastword $(LOCAL_PACKAGE_OVERRIDES))))
2414 $(eval _n := $(subst ||, ,$(firstword $(LOCAL_PACKAGE_OVERRIDES))))
2415 $(if $(filter $(word 2,$(_n)),$(LOCAL_PACKAGE_NAME)), \
2416 $(eval LOCAL_PACKAGE_NAME := $(word 3,$(_o))) \
2417 $(eval LOCAL_MANIFEST_PACKAGE_NAME := $(word 4,$(_o))) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07002418 $(call keep-or-override,LOCAL_CERTIFICATE,$(patsubst &&%,%,$(word 5,$(_o)))) \
2419 $(call keep-or-override,LOCAL_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 6,$(_o)))) \
2420 $(call keep-or-override,LOCAL_MANIFEST_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 7,$(_o)))) \
Joe Onorato899e62a2010-02-04 17:37:21 -08002421 $(eval LOCAL_OVERRIDES_PACKAGES := $(sort $(LOCAL_OVERRIDES_PACKAGES) $(word 2,$(_o)))) \
2422 true \
2423 ,)
2424endef
2425
Ying Wang000e89a2012-04-30 15:48:27 -07002426###########################################################
Ying Wangc065da22012-11-14 15:57:07 -08002427## API Check
2428###########################################################
2429
2430# eval this to define a rule that runs apicheck.
2431#
2432# Args:
2433# $(1) target
2434# $(2) stable api file
2435# $(3) api file to be tested
Hui Shuec21c582014-03-13 16:21:08 -07002436# $(4) stable removed api file
Hui Shue8af17e2014-02-21 14:18:19 -08002437# $(5) removed api file to be tested
2438# $(6) arguments for apicheck
2439# $(7) command to run if apicheck failed
2440# $(8) target dependent on this api check
2441# $(9) additional dependencies
Ying Wangc065da22012-11-14 15:57:07 -08002442define check-api
Hui Shuec21c582014-03-13 16:21:08 -07002443$(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(strip $(1))-timestamp: $(2) $(3) $(4) $(APICHECK) $(9)
Ying Wangc065da22012-11-14 15:57:07 -08002444 @echo "Checking API:" $(1)
Hui Shue8af17e2014-02-21 14:18:19 -08002445 $(hide) ( $(APICHECK_COMMAND) $(6) $(2) $(3) $(4) $(5) || ( $(7) ; exit 38 ) )
Ying Wangc065da22012-11-14 15:57:07 -08002446 $(hide) mkdir -p $$(dir $$@)
2447 $(hide) touch $$@
Hui Shue8af17e2014-02-21 14:18:19 -08002448$(8): $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(strip $(1))-timestamp
Ying Wangc065da22012-11-14 15:57:07 -08002449endef
2450
Ying Wang63d94fa2012-12-13 18:23:01 -08002451## Whether to build from source if prebuilt alternative exists
2452###########################################################
2453# $(1): module name
2454# $(2): LOCAL_PATH
2455# Expands to empty string if not from source.
2456ifeq (true,$(ANDROID_BUILD_FROM_SOURCE))
2457define if-build-from-source
2458true
2459endef
2460else
2461define if-build-from-source
2462$(if $(filter $(ANDROID_NO_PREBUILT_MODULES),$(1))$(filter \
2463 $(addsuffix %,$(ANDROID_NO_PREBUILT_PATHS)),$(2)),true)
2464endef
2465endif
2466
2467# Include makefile $(1) if build from source for module $(2)
2468# $(1): the makefile to include
2469# $(2): module name
2470# $(3): LOCAL_PATH
2471define include-if-build-from-source
2472$(if $(call if-build-from-source,$(2),$(3)),$(eval include $(1)))
2473endef
2474
Ying Wanga6a6c352014-09-26 10:41:27 -07002475# Return the arch for the source file of a prebuilt
2476# Return "none" if no matching arch found, so the result can be passed to
2477# LOCAL_MODULE_TARGET_ARCH.
Ying Wangc0adfb72014-02-27 14:10:53 -08002478# $(1) the list of archs supported by the prebuilt
2479define get-prebuilt-src-arch
2480$(strip $(if $(filter $(TARGET_ARCH),$(1)),$(TARGET_ARCH),\
Ying Wanga6a6c352014-09-26 10:41:27 -07002481 $(if $(filter $(TARGET_2ND_ARCH),$(1)),$(TARGET_2ND_ARCH),none)))
Ying Wangc0adfb72014-02-27 14:10:53 -08002482endef
2483
Ying Wangc065da22012-11-14 15:57:07 -08002484###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08002485## Other includes
2486###########################################################
2487
2488# -----------------------------------------------------------------
2489# Rules and functions to help copy important files to DIST_DIR
2490# when requested.
2491include $(BUILD_SYSTEM)/distdir.mk
2492
Marie Lennerhagen9e5efce2010-10-20 13:41:59 +02002493# Include any vendor specific definitions.mk file
2494-include $(TOPDIR)vendor/*/build/core/definitions.mk
Andrew Boie388c04d2014-10-28 08:32:11 -07002495-include $(TOPDIR)device/*/build/core/definitions.mk
Marie Lennerhagen9e5efce2010-10-20 13:41:59 +02002496
The Android Open Source Project88b60792009-03-03 19:28:42 -08002497# broken:
2498# $(foreach file,$^,$(if $(findstring,.a,$(suffix $file)),-l$(file),$(file)))
2499
2500###########################################################
2501## Misc notes
2502###########################################################
2503
2504#DEPDIR = .deps
2505#df = $(DEPDIR)/$(*F)
2506
2507#SRCS = foo.c bar.c ...
2508
2509#%.o : %.c
2510# @$(MAKEDEPEND); \
2511# cp $(df).d $(df).P; \
2512# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
2513# -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \
2514# rm -f $(df).d
2515# $(COMPILE.c) -o $@ $<
2516
2517#-include $(SRCS:%.c=$(DEPDIR)/%.P)
2518
2519
2520#%.o : %.c
2521# $(COMPILE.c) -MD -o $@ $<
2522# @cp $*.d $*.P; \
2523# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
2524# -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \
2525# rm -f $*.d