blob: d1284e61ec432330bbc0c921d7427f2c0016ed1e [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
The Android Open Source Project88b60792009-03-03 19:28:42 -080058# Full path to all files that are made by some tool
59ALL_GENERATED_SOURCES:=
60
61# Full path to all asm, C, C++, lex and yacc generated C files.
62# These all have an order-only dependency on the copied headers
63ALL_C_CPP_ETC_OBJECTS:=
64
Iliyan Malchevb375e712011-03-08 16:19:48 -080065# The list of dynamic binaries that haven't been stripped/compressed/etc.
The Android Open Source Project88b60792009-03-03 19:28:42 -080066ALL_ORIGINAL_DYNAMIC_BINARIES:=
67
68# These files go into the SDK
69ALL_SDK_FILES:=
70
71# Files for dalvik. This is often build without building the rest of the OS.
72INTERNAL_DALVIK_MODULES:=
73
74# All findbugs xml files
75ALL_FINDBUGS_FILES:=
76
Ying Wangfd626f22011-12-12 12:57:38 -080077# GPL module license files
78ALL_GPL_MODULE_LICENSE_FILES:=
79
Ying Wang9485a572013-02-22 14:32:30 -080080# Target and host installed module's dependencies on shared libraries.
Ying Wangd6b1d612013-04-15 17:32:21 -070081# They are list of "<module_name>:<installed_file>:lib1,lib2...".
Ying Wang9485a572013-02-22 14:32:30 -080082TARGET_DEPENDENCIES_ON_SHARED_LIBRARIES :=
Ying Wang966c1e02014-05-20 14:43:51 -070083$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_DEPENDENCIES_ON_SHARED_LIBRARIES :=
Ying Wang9485a572013-02-22 14:32:30 -080084HOST_DEPENDENCIES_ON_SHARED_LIBRARIES :=
Ying Wang966c1e02014-05-20 14:43:51 -070085$(HOST_2ND_ARCH_VAR_PREFIX)HOST_DEPENDENCIES_ON_SHARED_LIBRARIES :=
Dan Willemsen057aaea2015-08-14 12:59:50 -070086HOST_CROSS_DEPENDENCIES_ON_SHARED_LIBRARIES :=
Dan Willemsen9ecbf832016-02-05 16:20:19 -080087$(HOST_CROSS_2ND_ARCH_VAR_PREFIX)HOST_CROSS_DEPENDENCIES_ON_SHARED_LIBRARIES :=
Ying Wang9485a572013-02-22 14:32:30 -080088
Ying Wangae25ec12012-06-19 10:40:37 -070089# Generated class file names for Android resource.
90# They are escaped and quoted so can be passed safely to a bash command.
91ANDROID_RESOURCE_GENERATED_CLASSES := 'R.class' 'R$$*.class' 'Manifest.class' 'Manifest$$*.class'
92
Dan Willemsen057aaea2015-08-14 12:59:50 -070093# Display names for various build targets
94TARGET_DISPLAY := target
Alexey Polyudovccdc3112016-08-01 17:41:49 -070095AUX_DISPLAY := aux
Dan Willemsen057aaea2015-08-14 12:59:50 -070096HOST_DISPLAY := host
97HOST_CROSS_DISPLAY := host cross
98
Dan Willemsen435360a2016-07-27 22:52:42 -070099# All installed initrc files
100ALL_INIT_RC_INSTALLED_PAIRS :=
101
The Android Open Source Project88b60792009-03-03 19:28:42 -0800102###########################################################
103## Debugging; prints a variable list to stdout
104###########################################################
105
106# $(1): variable name list, not variable values
107define print-vars
108$(foreach var,$(1), \
109 $(info $(var):) \
110 $(foreach word,$($(var)), \
111 $(info $(space)$(space)$(word)) \
112 ) \
113 )
114endef
115
116###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700117## Evaluates to true if the string contains the word true,
118## and empty otherwise
119## $(1): a var to test
120###########################################################
121
122define true-or-empty
123$(filter true, $(1))
124endef
125
126
127###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800128## Retrieve the directory of the current makefile
Ying Wang3bbfddd2014-03-01 15:32:04 -0800129## Must be called before including any other makefile!!
The Android Open Source Project88b60792009-03-03 19:28:42 -0800130###########################################################
131
132# Figure out where we are.
133define my-dir
Dave Bortb3926412009-05-19 16:12:22 -0700134$(strip \
Ying Wang68f1c772012-04-23 21:29:18 -0700135 $(eval LOCAL_MODULE_MAKEFILE := $$(lastword $$(MAKEFILE_LIST))) \
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
Colin Cross4cbf8eb2016-05-27 15:23:13 -0700144
Colin Cross861ab992016-01-11 12:33:23 -0800145###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800146## Retrieve a list of all makefiles immediately below some directory
147###########################################################
148
149define all-makefiles-under
Colin Cross65543c72016-07-11 16:57:33 -0700150$(wildcard $(1)/*/Android.mk)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800151endef
152
153###########################################################
154## Look under a directory for makefiles that don't have parent
155## makefiles.
156###########################################################
157
158# $(1): directory to search under
159# Ignores $(1)/Android.mk
160define first-makefiles-under
Colin Cross65543c72016-07-11 16:57:33 -0700161$(shell build/tools/findleaves.py $(FIND_LEAVES_EXCLUDES) \
162 --mindepth=2 $(addprefix --dir=,$(1)) Android.mk)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800163endef
164
165###########################################################
166## Retrieve a list of all makefiles immediately below your directory
Ying Wang3bbfddd2014-03-01 15:32:04 -0800167## Must be called before including any other makefile!!
The Android Open Source Project88b60792009-03-03 19:28:42 -0800168###########################################################
169
170define all-subdir-makefiles
171$(call all-makefiles-under,$(call my-dir))
172endef
173
174###########################################################
175## Look in the named list of directories for makefiles,
176## relative to the current directory.
Ying Wang3bbfddd2014-03-01 15:32:04 -0800177## Must be called before including any other makefile!!
The Android Open Source Project88b60792009-03-03 19:28:42 -0800178###########################################################
179
180# $(1): List of directories to look for under this directory
181define all-named-subdir-makefiles
Colin Cross65543c72016-07-11 16:57:33 -0700182$(wildcard $(addsuffix /Android.mk, $(addprefix $(call my-dir)/,$(1))))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800183endef
184
185###########################################################
Dan Willemsen92f5fcc2015-10-12 15:26:52 -0700186## Find all of the directories under the named directories with
187## the specified name.
188## Meant to be used like:
189## INC_DIRS := $(call all-named-dirs-under,inc,.)
190###########################################################
191
192define all-named-dirs-under
193$(call find-subdir-files,$(2) -type d -name "$(1)")
194endef
195
196###########################################################
197## Find all the directories under the current directory that
198## haves name that match $(1)
199###########################################################
200
201define all-subdir-named-dirs
202$(call all-named-dirs-under,$(1),.)
203endef
204
205###########################################################
206## Find all of the files under the named directories with
207## the specified name.
208## Meant to be used like:
209## SRC_FILES := $(call all-named-files-under,*.h,src tests)
210###########################################################
211
212define all-named-files-under
213$(call find-files-in-subdirs,$(LOCAL_PATH),"$(1)",$(2))
214endef
215
216###########################################################
217## Find all of the files under the current directory with
218## the specified name.
219###########################################################
220
221define all-subdir-named-files
222$(call all-named-files-under,$(1),.)
223endef
224
225###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800226## Find all of the java files under the named directories.
227## Meant to be used like:
228## SRC_FILES := $(call all-java-files-under,src tests)
229###########################################################
230
231define all-java-files-under
Dan Willemsen92f5fcc2015-10-12 15:26:52 -0700232$(call all-named-files-under,*.java,$(1))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800233endef
234
235###########################################################
236## Find all of the java files from here. Meant to be used like:
237## SRC_FILES := $(call all-subdir-java-files)
238###########################################################
239
240define all-subdir-java-files
241$(call all-java-files-under,.)
242endef
243
244###########################################################
245## Find all of the c files under the named directories.
246## Meant to be used like:
247## SRC_FILES := $(call all-c-files-under,src tests)
248###########################################################
249
250define all-c-files-under
Dan Willemsen92f5fcc2015-10-12 15:26:52 -0700251$(call all-named-files-under,*.c,$(1))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800252endef
253
254###########################################################
255## Find all of the c files from here. Meant to be used like:
256## SRC_FILES := $(call all-subdir-c-files)
257###########################################################
258
259define all-subdir-c-files
260$(call all-c-files-under,.)
261endef
262
263###########################################################
Dan Willemsen379f9f92015-09-29 16:26:28 -0700264## Find all of the cpp files under the named directories.
265## LOCAL_CPP_EXTENSION is respected if set.
266## Meant to be used like:
267## SRC_FILES := $(call all-cpp-files-under,src tests)
268###########################################################
269
270define all-cpp-files-under
271$(sort $(patsubst ./%,%, \
272 $(shell cd $(LOCAL_PATH) ; \
273 find -L $(1) -name "*$(or $(LOCAL_CPP_EXTENSION),.cpp)" -and -not -name ".*") \
274 ))
275endef
276
277###########################################################
278## Find all of the cpp files from here. Meant to be used like:
279## SRC_FILES := $(call all-subdir-cpp-files)
280###########################################################
281
282define all-subdir-cpp-files
283$(call all-cpp-files-under,.)
284endef
285
286###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800287## Find all files named "I*.aidl" under the named directories,
288## which must be relative to $(LOCAL_PATH). The returned list
289## is relative to $(LOCAL_PATH).
290###########################################################
291
292define all-Iaidl-files-under
Dan Willemsen92f5fcc2015-10-12 15:26:52 -0700293$(call all-named-files-under,I*.aidl,$(1))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800294endef
295
296###########################################################
297## Find all of the "I*.aidl" files under $(LOCAL_PATH).
298###########################################################
299
300define all-subdir-Iaidl-files
301$(call all-Iaidl-files-under,.)
302endef
303
304###########################################################
Bjorn Bringerta89c9902010-02-02 17:36:20 +0000305## Find all of the logtags files under the named directories.
306## Meant to be used like:
307## SRC_FILES := $(call all-logtags-files-under,src)
308###########################################################
309
310define all-logtags-files-under
Dan Willemsen92f5fcc2015-10-12 15:26:52 -0700311$(call all-named-files-under,*.logtags,$(1))
Bjorn Bringerta89c9902010-02-02 17:36:20 +0000312endef
313
314###########################################################
Ying Wanga5fc87a2010-11-02 18:43:16 -0700315## Find all of the .proto files under the named directories.
316## Meant to be used like:
317## SRC_FILES := $(call all-proto-files-under,src)
318###########################################################
319
320define all-proto-files-under
Dan Willemsen92f5fcc2015-10-12 15:26:52 -0700321$(call all-named-files-under,*.proto,$(1))
Ying Wanga5fc87a2010-11-02 18:43:16 -0700322endef
323
324###########################################################
Ying Wang0bd59a02010-07-15 17:17:52 -0700325## Find all of the RenderScript files under the named directories.
326## Meant to be used like:
327## SRC_FILES := $(call all-renderscript-files-under,src)
328###########################################################
329
330define all-renderscript-files-under
Dan Willemsen92f5fcc2015-10-12 15:26:52 -0700331$(call find-subdir-files,$(1) \( -name "*.rs" -or -name "*.fs" \) -and -not -name ".*")
Ying Wang0bd59a02010-07-15 17:17:52 -0700332endef
333
334###########################################################
Elliott Hughese3b044a2014-02-11 13:48:35 -0800335## Find all of the S files under the named directories.
336## Meant to be used like:
337## SRC_FILES := $(call all-c-files-under,src tests)
338###########################################################
339
340define all-S-files-under
Dan Willemsen92f5fcc2015-10-12 15:26:52 -0700341$(call all-named-files-under,*.S,$(1))
Elliott Hughese3b044a2014-02-11 13:48:35 -0800342endef
343
344###########################################################
Jean-Baptiste Queru0a3cfdc2009-12-17 17:47:28 -0800345## Find all of the html files under the named directories.
346## Meant to be used like:
347## SRC_FILES := $(call all-html-files-under,src tests)
348###########################################################
349
350define all-html-files-under
Dan Willemsen92f5fcc2015-10-12 15:26:52 -0700351$(call all-named-files-under,*.html,$(1))
Jean-Baptiste Queru0a3cfdc2009-12-17 17:47:28 -0800352endef
353
354###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800355## Find all of the html files from here. Meant to be used like:
356## SRC_FILES := $(call all-subdir-html-files)
357###########################################################
358
359define all-subdir-html-files
Jean-Baptiste Queru0a3cfdc2009-12-17 17:47:28 -0800360$(call all-html-files-under,.)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800361endef
362
363###########################################################
364## Find all of the files matching pattern
365## SRC_FILES := $(call find-subdir-files, <pattern>)
366###########################################################
367
368define find-subdir-files
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700369$(sort $(patsubst ./%,%,$(shell cd $(LOCAL_PATH) ; find -L $(1))))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800370endef
371
372###########################################################
373# find the files in the subdirectory $1 of LOCAL_DIR
374# matching pattern $2, filtering out files $3
375# e.g.
376# SRC_FILES += $(call find-subdir-subdir-files, \
377# css, *.cpp, DontWantThis.cpp)
378###########################################################
379
380define find-subdir-subdir-files
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700381$(sort $(filter-out $(patsubst %,$(1)/%,$(3)),$(patsubst ./%,%,$(shell cd \
382 $(LOCAL_PATH) ; find -L $(1) -maxdepth 1 -name $(2)))))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800383endef
384
385###########################################################
386## Find all of the files matching pattern
387## SRC_FILES := $(call all-subdir-java-files)
388###########################################################
389
390define find-subdir-assets
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700391$(sort $(if $(1),$(patsubst ./%,%, \
Shinichiro Hamajid8f9f7d2016-05-12 18:15:28 +0900392 $(shell if [ -d $(1) ] ; then cd $(1) ; find -L ./ -not -name '.*' -and -type f ; fi)), \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800393 $(warning Empty argument supplied to find-subdir-assets) \
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700394))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800395endef
396
397###########################################################
398## Find various file types in a list of directories relative to $(LOCAL_PATH)
399###########################################################
400
401define find-other-java-files
Dan Willemsen92f5fcc2015-10-12 15:26:52 -0700402$(call all-java-files-under,$(1))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800403endef
404
405define find-other-html-files
Dan Willemsen92f5fcc2015-10-12 15:26:52 -0700406$(call all-html-files-under,$(1))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800407endef
408
409###########################################################
Ying Wang85898bc2013-12-04 16:04:49 -0800410# Use utility find to find given files in the given subdirs.
411# This function uses $(1), instead of LOCAL_PATH as the base.
412# $(1): the base dir, relative to the root of the source tree.
413# $(2): the file name pattern to be passed to find as "-name".
414# $(3): a list of subdirs of the base dir.
415# Returns: a list of paths relative to the base dir.
416###########################################################
417
418define find-files-in-subdirs
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700419$(sort $(patsubst ./%,%, \
Ying Wang85898bc2013-12-04 16:04:49 -0800420 $(shell cd $(1) ; \
421 find -L $(3) -name $(2) -and -not -name ".*") \
Dan Willemsen4d66adf2015-09-22 16:54:12 -0700422 ))
Ying Wang85898bc2013-12-04 16:04:49 -0800423endef
424
425###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800426## Scan through each directory of $(1) looking for files
427## that match $(2) using $(wildcard). Useful for seeing if
428## a given directory or one of its parents contains
429## a particular file. Returns the first match found,
430## starting furthest from the root.
431###########################################################
432
433define find-parent-file
434$(strip \
Dan Willemsen7c3e3f82015-09-29 16:30:21 -0700435 $(eval _fpf := $(sort $(wildcard $(foreach f, $(2), $(strip $(1))/$(f))))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800436 $(if $(_fpf),$(_fpf), \
437 $(if $(filter-out ./ .,$(1)), \
438 $(call find-parent-file,$(patsubst %/,%,$(dir $(1))),$(2)) \
439 ) \
440 ) \
441)
442endef
443
444###########################################################
445## Function we can evaluate to introduce a dynamic dependency
446###########################################################
447
448define add-dependency
449$(1): $(2)
450endef
451
452###########################################################
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200453## Reverse order of a list
454###########################################################
455
456define reverse-list
457$(if $(1),$(call reverse-list,$(wordlist 2,$(words $(1)),$(1)))) $(firstword $(1))
458endef
459
Alexey Polyudovccdc3112016-08-01 17:41:49 -0700460define def-host-aux-target
461$(eval _idf_val_:=$(if $(strip $(LOCAL_IS_HOST_MODULE)),HOST,$(if $(strip $(LOCAL_IS_AUX_MODULE)),AUX,))) \
462$(_idf_val_)
463endef
464
465###########################################################
466## Returns correct _idfPrefix from the list:
467## { HOST, HOST_CROSS, AUX, TARGET }
468###########################################################
469# the following rules checked in order:
470# ($1 is in {AUX, HOST_CROSS} => $1;
471# ($1 is empty) => TARGET;
472# ($2 is not empty) => HOST_CROSS;
473# => HOST;
474define find-idf-prefix
475$(strip \
476 $(eval _idf_pfx_:=$(strip $(filter AUX HOST_CROSS,$(1)))) \
477 $(eval _idf_pfx_:=$(if $(strip $(1)),$(if $(_idf_pfx_),$(_idf_pfx_),$(if $(strip $(2)),HOST_CROSS,HOST)),TARGET)) \
478 $(_idf_pfx_)
479)
480endef
481
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200482###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800483## The intermediates directory. Where object files go for
484## a given target. We could technically get away without
485## the "_intermediates" suffix on the directory, but it's
486## nice to be able to grep for that string to find out if
487## anyone's abusing the system.
488###########################################################
489
490# $(1): target class, like "APPS"
491# $(2): target name, like "NotePad"
Alexey Polyudovccdc3112016-08-01 17:41:49 -0700492# $(3): { HOST, HOST_CROSS, AUX, <empty (TARGET)>, <other non-empty (HOST)> }
The Android Open Source Project88b60792009-03-03 19:28:42 -0800493# $(4): if non-empty, force the intermediates to be COMMON
Dan Willemsen057aaea2015-08-14 12:59:50 -0700494# $(5): if non-empty, force the intermediates to be for the 2nd arch
495# $(6): if non-empty, force the intermediates to be for the host cross os
The Android Open Source Project88b60792009-03-03 19:28:42 -0800496define intermediates-dir-for
497$(strip \
498 $(eval _idfClass := $(strip $(1))) \
499 $(if $(_idfClass),, \
500 $(error $(LOCAL_PATH): Class not defined in call to intermediates-dir-for)) \
501 $(eval _idfName := $(strip $(2))) \
502 $(if $(_idfName),, \
503 $(error $(LOCAL_PATH): Name not defined in call to intermediates-dir-for)) \
Alexey Polyudovccdc3112016-08-01 17:41:49 -0700504 $(eval _idfPrefix := $(call find-idf-prefix,$(3),$(6))) \
Colin Crossae2986e2014-06-17 21:35:44 -0700505 $(eval _idf2ndArchPrefix := $(if $(strip $(5)),$(TARGET_2ND_ARCH_VAR_PREFIX))) \
Ying Wanga83940f2010-09-24 18:09:04 -0700506 $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800507 $(eval _idfIntBase := $($(_idfPrefix)_OUT_COMMON_INTERMEDIATES)) \
Dan Willemsenc6e194f2016-02-13 00:19:40 -0800508 ,$(if $(filter $(_idfClass),$(PER_ARCH_MODULE_CLASSES)),\
Colin Cross02e31d22014-01-24 13:38:08 -0800509 $(eval _idfIntBase := $($(_idf2ndArchPrefix)$(_idfPrefix)_OUT_INTERMEDIATES)) \
510 ,$(eval _idfIntBase := $($(_idfPrefix)_OUT_INTERMEDIATES)) \
511 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800512 ) \
513 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
514)
515endef
516
517# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE
518# to determine the intermediates directory.
519#
520# $(1): if non-empty, force the intermediates to be COMMON
Ying Wang61d499b2014-01-15 16:02:16 -0800521# $(2): if non-empty, force the intermediates to be for the 2nd arch
Dan Willemsen057aaea2015-08-14 12:59:50 -0700522# $(3): if non-empty, force the intermediates to be for the host cross os
The Android Open Source Project88b60792009-03-03 19:28:42 -0800523define local-intermediates-dir
524$(strip \
525 $(if $(strip $(LOCAL_MODULE_CLASS)),, \
526 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-intermediates-dir)) \
527 $(if $(strip $(LOCAL_MODULE)),, \
528 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-intermediates-dir)) \
Alexey Polyudovccdc3112016-08-01 17:41:49 -0700529 $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(call def-host-aux-target),$(1),$(2),$(3)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800530)
531endef
532
533###########################################################
Colin Crossd8262642014-01-24 23:17:21 -0800534## The generated sources directory. Placing generated
535## source files directly in the intermediates directory
536## causes problems for multiarch builds, where there are
537## two intermediates directories for a single target. Put
538## them in a separate directory, and they will be copied to
539## each intermediates directory automatically.
540###########################################################
541
542# $(1): target class, like "APPS"
543# $(2): target name, like "NotePad"
Alexey Polyudovccdc3112016-08-01 17:41:49 -0700544# $(3): { HOST, HOST_CROSS, AUX, <empty (TARGET)>, <other non-empty (HOST)> }
Colin Crossd8262642014-01-24 23:17:21 -0800545# $(4): if non-empty, force the generated sources to be COMMON
546define generated-sources-dir-for
547$(strip \
548 $(eval _idfClass := $(strip $(1))) \
549 $(if $(_idfClass),, \
550 $(error $(LOCAL_PATH): Class not defined in call to generated-sources-dir-for)) \
551 $(eval _idfName := $(strip $(2))) \
552 $(if $(_idfName),, \
553 $(error $(LOCAL_PATH): Name not defined in call to generated-sources-dir-for)) \
Alexey Polyudovccdc3112016-08-01 17:41:49 -0700554 $(eval _idfPrefix := $(call find-idf-prefix,$(3),)) \
Colin Crossd8262642014-01-24 23:17:21 -0800555 $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
Paul Duffin699a3222015-11-25 13:14:23 +0000556 $(eval _idfIntBase := $($(_idfPrefix)_OUT_COMMON_GEN)) \
Colin Crossd8262642014-01-24 23:17:21 -0800557 , \
558 $(eval _idfIntBase := $($(_idfPrefix)_OUT_GEN)) \
559 ) \
560 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
561)
562endef
563
564# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE
565# to determine the generated sources directory.
566#
567# $(1): if non-empty, force the intermediates to be COMMON
568define local-generated-sources-dir
569$(strip \
570 $(if $(strip $(LOCAL_MODULE_CLASS)),, \
571 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-generated-sources-dir)) \
572 $(if $(strip $(LOCAL_MODULE)),, \
573 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-generated-sources-dir)) \
Alexey Polyudovccdc3112016-08-01 17:41:49 -0700574 $(call generated-sources-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(call def-host-aux-target),$(1)) \
Colin Crossd8262642014-01-24 23:17:21 -0800575)
576endef
577
578###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800579## Convert "path/to/libXXX.so" to "-lXXX".
580## Any "path/to/libXXX.a" elements pass through unchanged.
581###########################################################
582
583define normalize-libraries
584$(foreach so,$(filter %.so,$(1)),-l$(patsubst lib%.so,%,$(notdir $(so))))\
585$(filter-out %.so,$(1))
586endef
587
588# TODO: change users to call the common version.
589define normalize-host-libraries
590$(call normalize-libraries,$(1))
591endef
592
593define normalize-target-libraries
594$(call normalize-libraries,$(1))
595endef
596
597###########################################################
598## Convert a list of short module names (e.g., "framework", "Browser")
599## into the list of files that are built for those modules.
600## NOTE: this won't return reliable results until after all
601## sub-makefiles have been included.
602## $(1): target list
603###########################################################
604
605define module-built-files
606$(foreach module,$(1),$(ALL_MODULES.$(module).BUILT))
607endef
608
609###########################################################
610## Convert a list of short modules names (e.g., "framework", "Browser")
611## into the list of files that are installed for those modules.
612## NOTE: this won't return reliable results until after all
613## sub-makefiles have been included.
614## $(1): target list
615###########################################################
616
617define module-installed-files
618$(foreach module,$(1),$(ALL_MODULES.$(module).INSTALLED))
619endef
620
621###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700622## Convert a list of short modules names (e.g., "framework", "Browser")
623## into the list of files that should be used when linking
624## against that module as a public API.
625## TODO: Allow this for more than JAVA_LIBRARIES modules
626## NOTE: this won't return reliable results until after all
627## sub-makefiles have been included.
628## $(1): target list
629###########################################################
630
631define module-stubs-files
632$(foreach module,$(1),$(ALL_MODULES.$(module).STUBS))
633endef
634
635###########################################################
636## Evaluates to the timestamp file for a doc module, which
637## is the dependency that should be used.
638## $(1): doc module
639###########################################################
640
641define doc-timestamp-for
642$(OUT_DOCS)/$(strip $(1))-timestamp
643endef
644
645
646###########################################################
Ying Wang912f8282010-09-28 17:27:56 -0700647## Convert "core ext framework" to "out/.../javalib.jar ..."
The Android Open Source Project88b60792009-03-03 19:28:42 -0800648## $(1): library list
649## $(2): Non-empty if IS_HOST_MODULE
650###########################################################
651
652# $(1): library name
653# $(2): Non-empty if IS_HOST_MODULE
654define _java-lib-dir
655$(call intermediates-dir-for, \
Ying Wang912f8282010-09-28 17:27:56 -0700656 JAVA_LIBRARIES,$(1),$(2),COMMON)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800657endef
658
659# $(1): library name
660# $(2): Non-empty if IS_HOST_MODULE
661define _java-lib-full-classes.jar
Ying Wangea04f822016-03-02 17:25:01 -0800662$(call _java-lib-dir,$(1),$(2))/$(if $(2),javalib,classes)$(COMMON_JAVA_PACKAGE_SUFFIX)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800663endef
664
Ying Wangea04f822016-03-02 17:25:01 -0800665# Get the jar files (you can pass to "javac -classpath") of static or shared
666# Java libraries that you want to link against.
The Android Open Source Project88b60792009-03-03 19:28:42 -0800667# $(1): library name list
668# $(2): Non-empty if IS_HOST_MODULE
669define java-lib-files
670$(foreach lib,$(1),$(call _java-lib-full-classes.jar,$(lib),$(2)))
671endef
672
Ying Wangea04f822016-03-02 17:25:01 -0800673# Get the dependency files (you can put on the right side of "|" of a build rule)
674# of the Java libraries.
The Android Open Source Project88b60792009-03-03 19:28:42 -0800675# $(1): library name list
676# $(2): Non-empty if IS_HOST_MODULE
Ying Wangea04f822016-03-02 17:25:01 -0800677# Historically for target Java libraries we used a different file (javalib.jar)
678# as the dependency.
679# Now we can use classes.jar as dependency, so java-lib-deps is the same
680# as java-lib-files.
The Android Open Source Project88b60792009-03-03 19:28:42 -0800681define java-lib-deps
Ying Wangea04f822016-03-02 17:25:01 -0800682$(call java-lib-files,$(1),$(2))
683endef
684
685# Get the jar files (you can pass to "javac -classpath") of host dalvik Java libraries.
686# You can also use them as dependency files.
687# A host dalvik Java library is different from a host Java library in that
688# the java lib file is classes.jar, not javalib.jar.
689# $(1): library name list
690define host-dex-java-lib-files
691$(foreach lib,$(1),$(call _java-lib-dir,$(lib),true)/classes.jar)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800692endef
693
694###########################################################
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200695## Convert "core ext framework" to "out/.../classes.jack ..."
696## $(1): library list
697## $(2): Non-empty if IS_HOST_MODULE
698###########################################################
699
700# $(1): library name
701# $(2): Non-empty if IS_HOST_MODULE
702define _jack-lib-full-classes
703$(call _java-lib-dir,$(1),$(2))/classes.jack
704endef
705
706# $(1): library name list
707# $(2): Non-empty if IS_HOST_MODULE
708define jack-lib-files
709$(foreach lib,$(1),$(call _jack-lib-full-classes,$(lib),$(2)))
710endef
711
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200712###########################################################
Joe Onorato8dc8faa2010-09-14 13:09:48 -0400713## Run rot13 on a string
714## $(1): the string. Must be one line.
715###########################################################
716define rot13
717$(shell echo $(1) | tr 'a-zA-Z' 'n-za-mN-ZA-M')
718endef
719
720
721###########################################################
722## Returns true if $(1) and $(2) are equal. Returns
723## the empty string if they are not equal.
724###########################################################
725define streq
726$(strip $(if $(strip $(1)),\
727 $(if $(strip $(2)),\
728 $(if $(filter-out __,_$(subst $(strip $(1)),,$(strip $(2)))$(subst $(strip $(2)),,$(strip $(1)))_),,true), \
729 ),\
730 $(if $(strip $(2)),\
731 ,\
732 true)\
733 ))
734endef
735
736###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800737## Convert "a b c" into "a:b:c"
738###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800739define normalize-path-list
740$(subst $(space),:,$(strip $(1)))
741endef
742
743###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700744## Read the word out of a colon-separated list of words.
745## This has the same behavior as the built-in function
746## $(word n,str).
747##
748## The individual words may not contain spaces.
749##
750## $(1): 1 based index
751## $(2): value of the form a:b:c...
752###########################################################
753
754define word-colon
755$(word $(1),$(subst :,$(space),$(2)))
756endef
757
758###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800759## Convert "a=b c= d e = f" into "a=b c=d e=f"
760##
761## $(1): list to collapse
762## $(2): if set, separator word; usually "=", ":", or ":="
763## Defaults to "=" if not set.
764###########################################################
765
766define collapse-pairs
767$(eval _cpSEP := $(strip $(if $(2),$(2),=)))\
768$(subst $(space)$(_cpSEP)$(space),$(_cpSEP),$(strip \
769 $(subst $(_cpSEP), $(_cpSEP) ,$(1))))
770endef
771
The Android Open Source Project88b60792009-03-03 19:28:42 -0800772###########################################################
Ying Wang7e8d4422011-06-17 17:05:35 -0700773## Given a list of pairs, if multiple pairs have the same
774## first components, keep only the first pair.
775##
776## $(1): list of pairs
777## $(2): the separator word, such as ":", "=", etc.
778define uniq-pairs-by-first-component
779$(eval _upbfc_fc_set :=)\
780$(strip $(foreach w,$(1), $(eval _first := $(word 1,$(subst $(2),$(space),$(w))))\
781 $(if $(filter $(_upbfc_fc_set),$(_first)),,$(w)\
782 $(eval _upbfc_fc_set += $(_first)))))\
783$(eval _upbfc_fc_set :=)\
784$(eval _first:=)
785endef
786
787###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800788## MODULE_TAG set operations
789###########################################################
790
791# Given a list of tags, return the targets that specify
792# any of those tags.
793# $(1): tag list
794define modules-for-tag-list
Ying Wang634f7992014-11-18 12:41:53 -0800795$(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 -0800796endef
797
798# Same as modules-for-tag-list, but operates on
799# ALL_MODULE_NAME_TAGS.
800# $(1): tag list
801define module-names-for-tag-list
802$(sort $(foreach tag,$(1),$(ALL_MODULE_NAME_TAGS.$(tag))))
803endef
804
805# Given an accept and reject list, find the matching
806# set of targets. If a target has multiple tags and
807# any of them are rejected, the target is rejected.
808# Reject overrides accept.
809# $(1): list of tags to accept
810# $(2): list of tags to reject
811#TODO(dbort): do $(if $(strip $(1)),$(1),$(ALL_MODULE_TAGS))
Jean-Baptiste Queru75127b72010-01-07 11:44:22 -0800812#TODO(jbq): as of 20100106 nobody uses the second parameter
The Android Open Source Project88b60792009-03-03 19:28:42 -0800813define get-tagged-modules
814$(filter-out \
815 $(call modules-for-tag-list,$(2)), \
816 $(call modules-for-tag-list,$(1)))
817endef
818
Joe Onorato64d85d02009-04-09 19:31:12 -0700819###########################################################
820## Append a leaf to a base path. Properly deals with
821## base paths ending in /.
822##
823## $(1): base path
824## $(2): leaf path
825###########################################################
826
827define append-path
828$(subst //,/,$(1)/$(2))
829endef
830
The Android Open Source Project88b60792009-03-03 19:28:42 -0800831
832###########################################################
Dan Willemsendd5a5d32016-06-15 19:20:57 -0700833## Color-coded warnings and errors in build rules
834##
835## $(1): message to print
836###########################################################
837define echo-warning
838echo -e "\e[1;35mwarning:\e[0m \e[1m" $(1) "\e[0m\n"
839endef
840
841define echo-error
842echo -e "\e[1;31merror:\e[0m \e[1m" $(1) "\e[0m\n"
843endef
844
845
846###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800847## Package filtering
848###########################################################
849
850# Given a list of installed modules (short or long names)
851# return a list of the packages (yes, .apk packages, not
852# modules in general) that are overridden by this list and,
853# therefore, should not be installed.
854# $(1): mixed list of installed modules
855# TODO: This is fragile; find a reliable way to get this information.
856define _get-package-overrides
857 $(eval ### Discard any words containing slashes, unless they end in .apk, \
858 ### in which case trim off the directory component and the suffix. \
859 ### If there are no slashes, keep the entire word.)
860 $(eval _gpo_names := $(subst /,@@@ @@@,$(1)))
861 $(eval _gpo_names := \
862 $(filter %.apk,$(_gpo_names)) \
863 $(filter-out %@@@ @@@%,$(_gpo_names)))
864 $(eval _gpo_names := $(patsubst %.apk,%,$(_gpo_names)))
865 $(eval _gpo_names := $(patsubst @@@%,%,$(_gpo_names)))
866
867 $(eval ### Remove any remaining words that contain dots.)
868 $(eval _gpo_names := $(subst .,@@@ @@@,$(_gpo_names)))
869 $(eval _gpo_names := $(filter-out %@@@ @@@%,$(_gpo_names)))
870
871 $(eval ### Now we have a list of any words that could possibly refer to \
872 ### packages, although there may be words that do not. Only \
873 ### real packages will be present under PACKAGES.*, though.)
874 $(foreach _gpo_name,$(_gpo_names),$(PACKAGES.$(_gpo_name).OVERRIDES))
875endef
876
877define get-package-overrides
Conley Owensd7a1a9b2011-12-22 09:46:19 -0800878$(sort $(strip $(call _get-package-overrides,$(1))))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800879endef
880
881###########################################################
882## Output the command lines, or not
883###########################################################
884
885ifeq ($(strip $(SHOW_COMMANDS)),)
886define pretty
887@echo $1
888endef
The Android Open Source Project88b60792009-03-03 19:28:42 -0800889else
890define pretty
891endef
The Android Open Source Project88b60792009-03-03 19:28:42 -0800892endif
893
894###########################################################
Shinichiro Hamaji2e45fd02016-01-25 18:59:43 +0900895## Commands for munging the dependency files the compiler generates
The Android Open Source Project88b60792009-03-03 19:28:42 -0800896###########################################################
Ying Wangc23f4ef2012-09-07 17:04:06 -0700897# $(1): the input .d file
898# $(2): the output .P file
899define transform-d-to-p-args
900$(hide) cp $(1) $(2); \
901 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
902 -e '/^$$/ d' -e 's/$$/ :/' < $(1) >> $(2); \
903 rm -f $(1)
904endef
The Android Open Source Project88b60792009-03-03 19:28:42 -0800905
906define transform-d-to-p
Ying Wangc23f4ef2012-09-07 17:04:06 -0700907$(call transform-d-to-p-args,$(@:%.o=%.d),$(@:%.o=%.P))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800908endef
909
910###########################################################
Shinichiro Hamaji2e45fd02016-01-25 18:59:43 +0900911## Commands for including the dependency files the compiler generates
912###########################################################
913# $(1): the .P file
914# $(2): the main build target
Shinichiro Hamaji2e45fd02016-01-25 18:59:43 +0900915define include-depfile
916$(eval $(2) : .KATI_DEPFILE := $1)
917endef
Shinichiro Hamaji2e45fd02016-01-25 18:59:43 +0900918
Shinichiro Hamaji4037c422016-03-03 18:12:52 +0900919# $(1): object files
920define include-depfiles-for-objs
921$(foreach obj, $(1), $(call include-depfile, $(obj:%.o=%.P), $(obj)))
922endef
923
Shinichiro Hamaji2e45fd02016-01-25 18:59:43 +0900924###########################################################
Dan Willemsen3bb168f2016-01-19 20:07:08 -0800925## Track source files compiled to objects
926###########################################################
927# $(1): list of sources
928# $(2): list of matching objects
929define track-src-file-obj
930$(eval $(call _track-src-file-obj,$(1)))
931endef
932define _track-src-file-obj
933i := w
934$(foreach s,$(1),
935my_tracked_src_files += $(s)
936my_src_file_obj_$(s) := $$(word $$(words $$(i)),$$(2))
937i += w)
938endef
939
940# $(1): list of sources
941# $(2): list of matching generated sources
942define track-src-file-gen
943$(eval $(call _track-src-file-gen,$(2)))
944endef
945define _track-src-file-gen
946i := w
947$(foreach s,$(1),
948my_tracked_gen_files += $(s)
949my_src_file_gen_$(s) := $$(word $$(words $$(i)),$$(1))
950i += w)
951endef
952
953# $(1): list of generated sources
954# $(2): list of matching objects
955define track-gen-file-obj
956$(call track-src-file-obj,$(foreach f,$(1),\
957 $(or $(my_src_file_gen_$(f)),$(f))),$(2))
958endef
959
960###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800961## Commands for running lex
962###########################################################
963
Ying Wang64088f22016-01-11 16:28:45 -0800964define transform-l-to-c-or-cpp
The Android Open Source Project88b60792009-03-03 19:28:42 -0800965@echo "Lex: $(PRIVATE_MODULE) <= $<"
Colin Crossb6da5892015-07-16 17:14:27 -0700966@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800967$(hide) $(LEX) -o$@ $<
968endef
969
970###########################################################
971## Commands for running yacc
972##
The Android Open Source Project88b60792009-03-03 19:28:42 -0800973###########################################################
974
Ying Wang64088f22016-01-11 16:28:45 -0800975define transform-y-to-c-or-cpp
The Android Open Source Project88b60792009-03-03 19:28:42 -0800976@echo "Yacc: $(PRIVATE_MODULE) <= $<"
Colin Crossb6da5892015-07-16 17:14:27 -0700977@mkdir -p $(dir $@)
Ying Wang64088f22016-01-11 16:28:45 -0800978$(YACC) $(PRIVATE_YACCFLAGS) \
979 --defines=$(basename $@).h \
980 -o $@ $<
The Android Open Source Project88b60792009-03-03 19:28:42 -0800981endef
982
Ying Wang0bd59a02010-07-15 17:17:52 -0700983###########################################################
Tim Murraya7aa8002012-10-29 16:06:00 -0700984## Commands to compile RenderScript to Java
Ying Wang0bd59a02010-07-15 17:17:52 -0700985###########################################################
Ying Wang0bd59a02010-07-15 17:17:52 -0700986
Shinichiro Hamaji52a1d6c2016-02-01 17:59:01 +0900987## Merge multiple .d files generated by llvm-rs-cc. This is necessary
988## because ninja can handle only a single depfile per build target.
989## .d files generated by llvm-rs-cc define .stamp, .bc, and optionally
990## .java as build targets. However, there's no way to let ninja know
991## dependencies to .bc files and .java files, so we give up build
992## targets for them. As we write the .stamp file as the target by
993## ourselves, the awk script removes the first lines before the colon
994## and append a backslash to the last line to concatenate contents of
995## multiple files.
996# $(1): .d files to be merged
997# $(2): merged .d file
998define _merge-renderscript-d
999$(hide) echo '$@: $(backslash)' > $2
1000$(foreach d,$1, \
1001 $(hide) awk 'start { sub(/( \\)?$$/, " \\"); print } /:/ { start=1 }' < $d >> $2$(newline))
1002$(hide) echo >> $2
1003endef
1004
Ying Wang0bd59a02010-07-15 17:17:52 -07001005define transform-renderscripts-to-java-and-bc
1006@echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)"
1007$(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR)
1008$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/res/raw
1009$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/src
Ying Wang7d83ef82011-05-25 17:16:22 -07001010$(hide) $(PRIVATE_RS_CC) \
Ying Wangebfddaa2010-07-30 18:37:29 -07001011 -o $(PRIVATE_RS_OUTPUT_DIR)/res/raw \
1012 -p $(PRIVATE_RS_OUTPUT_DIR)/src \
Ying Wang24e1c012010-10-07 18:57:57 -07001013 -d $(PRIVATE_RS_OUTPUT_DIR) \
1014 -a $@ -MD \
Stephen Hinesc963eae2011-08-10 13:53:05 -07001015 $(addprefix -target-api , $(PRIVATE_RS_TARGET_API)) \
Stephen Hines914f7a22011-12-06 18:43:24 -08001016 $(PRIVATE_RS_FLAGS) \
Ying Wang51280272010-09-01 13:28:52 -07001017 $(foreach inc,$(PRIVATE_RS_INCLUDES),$(addprefix -I , $(inc))) \
Ying Wangebfddaa2010-07-30 18:37:29 -07001018 $(PRIVATE_RS_SOURCE_FILES)
Shinichiro Hamaji52a1d6c2016-02-01 17:59:01 +09001019$(call _merge-renderscript-d,$(PRIVATE_DEP_FILES),$@.d)
1020$(call transform-d-to-p-args,$@.d,$@.P)
Ying Wang0bd59a02010-07-15 17:17:52 -07001021$(hide) mkdir -p $(dir $@)
1022$(hide) touch $@
1023endef
1024
Stephen Hinese719f282012-11-28 16:52:41 -08001025define transform-bc-to-so
Stephen Hines9ac9b532013-02-27 00:51:08 -08001026@echo "Renderscript compatibility: $(notdir $@) <= $(notdir $<)"
Stephen Hinese719f282012-11-28 16:52:41 -08001027$(hide) mkdir -p $(dir $@)
Stephen Hinesf6925132012-12-17 14:23:14 -08001028$(hide) $(BCC_COMPAT) -O3 -o $(dir $@)/$(notdir $(<:.bc=.o)) -fPIC -shared \
Stephen Hines52626d22014-09-02 19:09:35 -07001029 -rt-path $(RS_PREBUILT_CLCORE) -mtriple $(RS_COMPAT_TRIPLE) $<
Stephen Hines7d6ec712012-12-13 19:24:50 -08001030$(hide) $(PRIVATE_CXX) -shared -Wl,-soname,$(notdir $@) -nostdlib \
Stephen Hinesf6925132012-12-17 14:23:14 -08001031 -Wl,-rpath,\$$ORIGIN/../lib \
Stephen Hines9541f582013-01-18 16:27:23 -08001032 $(dir $@)/$(notdir $(<:.bc=.o)) \
Tim Murray1a6f09a2013-03-05 11:07:15 -08001033 $(RS_PREBUILT_COMPILER_RT) \
Miao Wange23e8082014-11-15 14:25:33 -08001034 -o $@ $(TARGET_GLOBAL_LDFLAGS) -Wl,--hash-style=sysv -L prebuilts/gcc/ \
Ying Wangbfc43692015-03-05 11:29:30 -08001035 $(RS_PREBUILT_LIBPATH) -L $(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
Stephen Hines8db4cce2013-03-27 16:51:38 -07001036 -lRSSupport -lm -lc
Stephen Hinese719f282012-11-28 16:52:41 -08001037endef
1038
Tim Murraya7aa8002012-10-29 16:06:00 -07001039###########################################################
1040## Commands to compile RenderScript to C++
1041###########################################################
1042
1043define transform-renderscripts-to-cpp-and-bc
1044@echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)"
1045$(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR)
1046$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/
1047$(hide) $(PRIVATE_RS_CC) \
1048 -o $(PRIVATE_RS_OUTPUT_DIR)/ \
1049 -d $(PRIVATE_RS_OUTPUT_DIR) \
1050 -a $@ -MD \
1051 -reflect-c++ \
Noah Presler4796a8c2015-08-13 17:04:10 -07001052 $(addprefix -target-api , $(PRIVATE_RS_TARGET_API)) \
Tim Murraya7aa8002012-10-29 16:06:00 -07001053 $(PRIVATE_RS_FLAGS) \
Ying Wang81ab8332014-05-28 16:17:09 -07001054 $(addprefix -I , $(PRIVATE_RS_INCLUDES)) \
Tim Murraya7aa8002012-10-29 16:06:00 -07001055 $(PRIVATE_RS_SOURCE_FILES)
Shinichiro Hamaji2e45fd02016-01-25 18:59:43 +09001056$(call _merge-renderscript-d,$(PRIVATE_DEP_FILES),$@.d)
1057$(call transform-d-to-p-args,$@.d,$@.P)
Tim Murraya7aa8002012-10-29 16:06:00 -07001058$(hide) mkdir -p $(dir $@)
1059$(hide) touch $@
1060endef
1061
The Android Open Source Project88b60792009-03-03 19:28:42 -08001062
1063###########################################################
1064## Commands for running aidl
1065###########################################################
1066
1067define transform-aidl-to-java
1068@mkdir -p $(dir $@)
1069@echo "Aidl: $(PRIVATE_MODULE) <= $<"
1070$(hide) $(AIDL) -d$(patsubst %.java,%.P,$@) $(PRIVATE_AIDL_FLAGS) $< $@
1071endef
1072#$(AIDL) $(PRIVATE_AIDL_FLAGS) $< - | indent -nut -br -npcs -l1000 > $@
1073
Christopher Wiley2df75d12015-10-14 17:27:24 -07001074define transform-aidl-to-cpp
1075@mkdir -p $(dir $@)
1076@mkdir -p $(PRIVATE_HEADER_OUTPUT_DIR)
1077@echo "Generating C++ from AIDL: $(PRIVATE_MODULE) <= $<"
Christopher Wiley087f3272016-01-19 09:26:10 -08001078$(hide) $(AIDL_CPP) -d$(basename $@).aidl.P $(PRIVATE_AIDL_FLAGS) \
Christopher Wiley2df75d12015-10-14 17:27:24 -07001079 $< $(PRIVATE_HEADER_OUTPUT_DIR) $@
1080endef
1081
Christopher Wileyd9205ba2016-06-23 16:44:47 -07001082## Given a .aidl file path, generate the rule to compile it a .java file
1083# $(1): a .aidl source file
1084# $(2): a directory to place the generated .java files in
1085# $(3): name of a variable to add the path to the generated source file to
1086#
1087# You must call this with $(eval).
1088define define-aidl-java-rule
1089define-aidl-java-rule-src := $(patsubst %.aidl,%.java,$(subst ../,dotdot/,$(addprefix $(2)/,$(1))))
1090$$(define-aidl-java-rule-src) : $(LOCAL_PATH)/$(1) $(AIDL)
1091 $$(transform-aidl-to-java)
1092$(3) += $$(define-aidl-java-rule-src)
1093endef
1094
Christopher Wiley257796c2016-01-19 08:58:35 -08001095## Given a .aidl file path generate the rule to compile it a .cpp file.
1096# $(1): a .aidl source file
1097# $(2): a directory to place the generated .cpp files in
1098# $(3): name of a variable to add the path to the generated source file to
1099#
1100# You must call this with $(eval).
1101define define-aidl-cpp-rule
1102define-aidl-cpp-rule-src := $(patsubst %.aidl,%$(LOCAL_CPP_EXTENSION),$(subst ../,dotdot/,$(addprefix $(2)/,$(1))))
1103$$(define-aidl-cpp-rule-src) : $(LOCAL_PATH)/$(1) $(AIDL_CPP)
1104 $$(transform-aidl-to-cpp)
1105$(3) += $$(define-aidl-cpp-rule-src)
1106endef
The Android Open Source Project88b60792009-03-03 19:28:42 -08001107
Doug Zongker9bd49622009-11-30 14:28:59 -08001108###########################################################
1109## Commands for running java-event-log-tags.py
1110###########################################################
1111
1112define transform-logtags-to-java
1113@mkdir -p $(dir $@)
1114@echo "logtags: $@ <= $<"
Shinichiro Hamajid3ce14c2016-03-29 03:29:21 +09001115$(hide) $(JAVATAGS) -o $@ $< $(PRIVATE_MERGED_TAG)
Doug Zongker9bd49622009-11-30 14:28:59 -08001116endef
1117
The Android Open Source Project88b60792009-03-03 19:28:42 -08001118
1119###########################################################
Ying Wanga5fc87a2010-11-02 18:43:16 -07001120## Commands for running protoc to compile .proto into .java
1121###########################################################
1122
1123define transform-proto-to-java
1124@mkdir -p $(dir $@)
1125@echo "Protoc: $@ <= $(PRIVATE_PROTO_SRC_FILES)"
1126@rm -rf $(PRIVATE_PROTO_JAVA_OUTPUT_DIR)
1127@mkdir -p $(PRIVATE_PROTO_JAVA_OUTPUT_DIR)
Ben Murdochfc2bad52013-07-25 11:44:53 +01001128$(hide) for f in $(PRIVATE_PROTO_SRC_FILES); do \
1129 $(PROTOC) \
Ulas Kirazci28b46fc2013-07-24 14:32:14 -07001130 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
Ulas Kirazci6e485b52013-07-25 12:28:19 -07001131 $(PRIVATE_PROTO_JAVA_OUTPUT_OPTION)="$(PRIVATE_PROTO_JAVA_OUTPUT_PARAMS):$(PRIVATE_PROTO_JAVA_OUTPUT_DIR)" \
Ben Murdochfc2bad52013-07-25 11:44:53 +01001132 $(PRIVATE_PROTOC_FLAGS) \
1133 $$f || exit 33; \
1134 done
Ying Wanga5fc87a2010-11-02 18:43:16 -07001135$(hide) touch $@
1136endef
1137
1138######################################################################
Ying Wangfaeb6932015-04-07 11:59:34 -07001139## Commands for running protoc to compile .proto into .pb.cc (or.pb.c) and .pb.h
Ying Wanga5fc87a2010-11-02 18:43:16 -07001140######################################################################
1141define transform-proto-to-cc
Ying Wanga5fc87a2010-11-02 18:43:16 -07001142@echo "Protoc: $@ <= $<"
Colin Crossb6da5892015-07-16 17:14:27 -07001143@mkdir -p $(dir $@)
Ying Wanga5fc87a2010-11-02 18:43:16 -07001144$(hide) $(PROTOC) \
1145 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
Ying Wang33c0d952010-11-05 11:30:58 -07001146 $(PRIVATE_PROTOC_FLAGS) \
Ying Wangfaeb6932015-04-07 11:59:34 -07001147 $<
Ying Wang05f9f352016-05-05 20:02:08 -07001148@# aprotoc outputs only .cc. Rename it to .cpp if necessary.
1149$(if $(PRIVATE_RENAME_CPP_EXT),\
1150 $(hide) mv $(basename $@).cc $@)
Wink Saville042d4dc2014-05-06 15:45:57 -07001151endef
Ying Wanga5fc87a2010-11-02 18:43:16 -07001152
Ying Wanga5fc87a2010-11-02 18:43:16 -07001153
Christopher Wileybc2be462015-07-29 17:14:24 -07001154######################################################################
Christopher Wiley9b17dea2015-08-20 09:08:17 -07001155## Commands for generating DBus adaptors from .dbus-xml files.
Christopher Wileybc2be462015-07-29 17:14:24 -07001156######################################################################
Christopher Wiley529f1762015-08-14 14:55:32 -07001157define generate-dbus-adaptors
1158@echo "Generating DBus adaptors for $(PRIVATE_MODULE)"
1159@mkdir -p $(dir $@)
Christopher Wileybc2be462015-07-29 17:14:24 -07001160$(hide) $(DBUS_GENERATOR) \
1161 --service-config=$(PRIVATE_DBUS_SERVICE_CONFIG) \
Christopher Wiley529f1762015-08-14 14:55:32 -07001162 --adaptor=$@ \
1163 $<
1164endef
1165
1166######################################################################
Christopher Wiley9b17dea2015-08-20 09:08:17 -07001167## Commands for generating DBus proxies from .dbus-xml files.
Christopher Wiley529f1762015-08-14 14:55:32 -07001168######################################################################
1169define generate-dbus-proxies
1170@echo "Generating DBus proxies for $(PRIVATE_MODULE)"
1171@mkdir -p $(dir $@)
1172$(hide) $(DBUS_GENERATOR) \
1173 --service-config=$(PRIVATE_DBUS_SERVICE_CONFIG) \
1174 --proxy=$@ \
Christopher Wiley9b17dea2015-08-20 09:08:17 -07001175 $(filter %.dbus-xml,$^)
Christopher Wileybc2be462015-07-29 17:14:24 -07001176endef
1177
Colin Crosse25fd792016-07-19 13:19:21 -07001178###########################################################
1179## Helper to set include paths form transform-*-to-o
1180###########################################################
1181define c-includes
1182$(addprefix -I , $(PRIVATE_C_INCLUDES)) \
1183$$(cat $(PRIVATE_IMPORT_INCLUDES))\
1184$(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),,\
Colin Cross23ba6122016-07-20 12:22:57 -07001185 $(addprefix -I ,\
1186 $(filter-out $(PRIVATE_C_INCLUDES), \
1187 $(PRIVATE_GLOBAL_C_INCLUDES))) \
Colin Crosse25fd792016-07-19 13:19:21 -07001188 $(addprefix -isystem ,\
1189 $(filter-out $(PRIVATE_C_INCLUDES), \
Colin Cross23ba6122016-07-20 12:22:57 -07001190 $(PRIVATE_GLOBAL_C_SYSTEM_INCLUDES))))
Colin Crosse25fd792016-07-19 13:19:21 -07001191endef
Christopher Wileybc2be462015-07-29 17:14:24 -07001192
Ying Wanga5fc87a2010-11-02 18:43:16 -07001193###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001194## Commands for running gcc to compile a C++ file
1195###########################################################
1196
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001197define transform-cpp-to-o-compiler-args
Colin Crosse25fd792016-07-19 13:19:21 -07001198 $(c-includes) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001199 -c \
1200 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -07001201 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
1202 $(PRIVATE_TARGET_GLOBAL_CPPFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001203 $(PRIVATE_ARM_CFLAGS) \
1204 ) \
Doug Kwan9a8ecf92011-05-10 21:50:58 -07001205 $(PRIVATE_RTTI_FLAG) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001206 $(PRIVATE_CFLAGS) \
1207 $(PRIVATE_CPPFLAGS) \
1208 $(PRIVATE_DEBUG_CFLAGS) \
Dan Albertd1600412015-06-10 16:33:43 -07001209 $(PRIVATE_CFLAGS_NO_OVERRIDE) \
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001210 $(PRIVATE_CPPFLAGS_NO_OVERRIDE)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001211endef
1212
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001213define clang-tidy-cpp
1214$(hide) $(PATH_TO_CLANG_TIDY) $(PRIVATE_TIDY_FLAGS) \
1215 -checks=$(PRIVATE_TIDY_CHECKS) \
1216 $< -- $(transform-cpp-to-o-compiler-args)
1217endef
1218
1219ifneq (,$(filter 1 true,$(WITH_TIDY_ONLY)))
1220define transform-cpp-to-o
1221$(if $(PRIVATE_TIDY_CHECKS),
Alexey Polyudov8b540fd2016-06-24 11:13:34 -07001222 @echo "$($(PRIVATE_PREFIX)DISPLAY) tidy $(PRIVATE_ARM_MODE) C++: $<"
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001223 $(clang-tidy-cpp))
1224endef
1225else
1226define transform-cpp-to-o
Alexey Polyudov8b540fd2016-06-24 11:13:34 -07001227@echo "$($(PRIVATE_PREFIX)DISPLAY) $(PRIVATE_ARM_MODE) C++: $(PRIVATE_MODULE) <= $<"
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001228@mkdir -p $(dir $@)
1229$(if $(PRIVATE_TIDY_CHECKS),$(clang-tidy-cpp))
1230$(hide) $(RELATIVE_PWD) $(PRIVATE_CXX) \
1231 $(transform-cpp-to-o-compiler-args) \
1232 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
1233$(hide) $(transform-d-to-p)
1234endef
1235endif
1236
The Android Open Source Project88b60792009-03-03 19:28:42 -08001237
1238###########################################################
1239## Commands for running gcc to compile a C file
1240###########################################################
1241
1242# $(1): extra flags
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001243define transform-c-or-s-to-o-compiler-args
Colin Crosse25fd792016-07-19 13:19:21 -07001244 $(c-includes) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001245 -c \
1246 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -07001247 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
Stephen Hines15680292014-11-26 00:53:46 -08001248 $(PRIVATE_TARGET_GLOBAL_CONLYFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001249 $(PRIVATE_ARM_CFLAGS) \
1250 ) \
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001251 $(1)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001252endef
1253
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001254define transform-c-to-o-compiler-args
1255$(call transform-c-or-s-to-o-compiler-args, \
1256 $(PRIVATE_CFLAGS) \
1257 $(PRIVATE_CONLYFLAGS) \
1258 $(PRIVATE_DEBUG_CFLAGS) \
1259 $(PRIVATE_CFLAGS_NO_OVERRIDE))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001260endef
1261
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001262define clang-tidy-c
1263$(hide) $(PATH_TO_CLANG_TIDY) $(PRIVATE_TIDY_FLAGS) \
1264 -checks=$(PRIVATE_TIDY_CHECKS) \
1265 $< -- $(transform-c-to-o-compiler-args)
1266endef
1267
1268ifneq (,$(filter 1 true,$(WITH_TIDY_ONLY)))
1269define transform-c-to-o
1270$(if $(PRIVATE_TIDY_CHECKS),
Alexey Polyudov8b540fd2016-06-24 11:13:34 -07001271 @echo "$($(PRIVATE_PREFIX)DISPLAY) tidy $(PRIVATE_ARM_MODE) C: $<"
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001272 $(clang-tidy-c))
1273endef
1274else
1275define transform-c-to-o
Alexey Polyudov8b540fd2016-06-24 11:13:34 -07001276@echo "$($(PRIVATE_PREFIX)DISPLAY) $(PRIVATE_ARM_MODE) C: $(PRIVATE_MODULE) <= $<"
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001277@mkdir -p $(dir $@)
1278$(if $(PRIVATE_TIDY_CHECKS),$(clang-tidy-c))
1279$(hide) $(RELATIVE_PWD) $(PRIVATE_CC) \
1280 $(transform-c-to-o-compiler-args) \
1281 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
1282$(hide) $(transform-d-to-p)
1283endef
1284endif
1285
The Android Open Source Project88b60792009-03-03 19:28:42 -08001286define transform-s-to-o-no-deps
Alexey Polyudov8b540fd2016-06-24 11:13:34 -07001287@echo "$($(PRIVATE_PREFIX)DISPLAY) asm: $(PRIVATE_MODULE) <= $<"
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001288@mkdir -p $(dir $@)
1289$(RELATIVE_PWD) $(PRIVATE_CC) \
1290 $(call transform-c-or-s-to-o-compiler-args, $(PRIVATE_ASFLAGS)) \
1291 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
The Android Open Source Project88b60792009-03-03 19:28:42 -08001292endef
1293
1294define transform-s-to-o
1295$(transform-s-to-o-no-deps)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001296$(transform-d-to-p)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001297endef
1298
Ying Wang7b913ce2014-06-05 19:05:47 -07001299# YASM compilation
1300define transform-asm-to-o
1301@mkdir -p $(dir $@)
1302$(hide) $(YASM) \
1303 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Ying Wangfe1e5c32015-03-09 18:57:40 -07001304 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_YASM_FLAGS) \
Ying Wang7b913ce2014-06-05 19:05:47 -07001305 $(PRIVATE_ASFLAGS) \
1306 -o $@ $<
1307endef
1308
The Android Open Source Project88b60792009-03-03 19:28:42 -08001309###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001310## Commands for running gcc to compile an Objective-C file
1311## This should never happen for target builds but this
1312## will error at build time.
1313###########################################################
1314
1315define transform-m-to-o-no-deps
Alexey Polyudov8b540fd2016-06-24 11:13:34 -07001316@echo "$($(PRIVATE_PREFIX)DISPLAY) ObjC: $(PRIVATE_MODULE) <= $<"
Ying Wang65d78522012-08-10 16:30:42 -07001317$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_DEBUG_CFLAGS))
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001318endef
1319
1320define transform-m-to-o
1321$(transform-m-to-o-no-deps)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001322$(transform-d-to-p)
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001323endef
1324
1325###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001326## Commands for running gcc to compile a host C++ file
1327###########################################################
1328
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001329define transform-host-cpp-to-o-compiler-args
Colin Crosse25fd792016-07-19 13:19:21 -07001330 $(c-includes) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001331 -c \
1332 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001333 $(PRIVATE_HOST_GLOBAL_CFLAGS) \
1334 $(PRIVATE_HOST_GLOBAL_CPPFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001335 ) \
1336 $(PRIVATE_CFLAGS) \
1337 $(PRIVATE_CPPFLAGS) \
1338 $(PRIVATE_DEBUG_CFLAGS) \
Dan Albertd1600412015-06-10 16:33:43 -07001339 $(PRIVATE_CFLAGS_NO_OVERRIDE) \
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001340 $(PRIVATE_CPPFLAGS_NO_OVERRIDE)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001341endef
1342
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001343define clang-tidy-host-cpp
1344$(hide) $(PATH_TO_CLANG_TIDY) $(PRIVATE_TIDY_FLAGS) \
1345 -checks=$(PRIVATE_TIDY_CHECKS) \
1346 $< -- $(transform-host-cpp-to-o-compiler-args)
1347endef
1348
1349ifneq (,$(filter 1 true,$(WITH_TIDY_ONLY)))
1350define transform-host-cpp-to-o
1351$(if $(PRIVATE_TIDY_CHECKS),
1352 @echo "tidy $($(PRIVATE_PREFIX)DISPLAY) C++: $<"
1353 $(clang-tidy-host-cpp))
1354endef
1355else
1356define transform-host-cpp-to-o
1357@echo "$($(PRIVATE_PREFIX)DISPLAY) C++: $(PRIVATE_MODULE) <= $<"
1358@mkdir -p $(dir $@)
1359$(if $(PRIVATE_TIDY_CHECKS),$(clang-tidy-host-cpp))
1360$(hide) $(RELATIVE_PWD) $(PRIVATE_CXX) \
1361 $(transform-host-cpp-to-o-compiler-args) \
1362 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
1363$(hide) $(transform-d-to-p)
1364endef
1365endif
1366
The Android Open Source Project88b60792009-03-03 19:28:42 -08001367
1368###########################################################
1369## Commands for running gcc to compile a host C file
1370###########################################################
1371
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001372define transform-host-c-or-s-to-o-common-args
Colin Crosse25fd792016-07-19 13:19:21 -07001373 $(c-includes) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001374 -c \
1375 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001376 $(PRIVATE_HOST_GLOBAL_CFLAGS) \
Stephen Hines15680292014-11-26 00:53:46 -08001377 $(PRIVATE_HOST_GLOBAL_CONLYFLAGS) \
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001378 )
The Android Open Source Project88b60792009-03-03 19:28:42 -08001379endef
1380
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001381# $(1): extra flags
1382define transform-host-c-or-s-to-o-no-deps
1383@mkdir -p $(dir $@)
1384$(hide) $(RELATIVE_PWD) $(PRIVATE_CC) \
1385 $(transform-host-c-or-s-to-o-common-args) \
1386 $(1) \
1387 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
The Android Open Source Project88b60792009-03-03 19:28:42 -08001388endef
1389
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -07001390define transform-host-c-to-o-compiler-args
1391 $(transform-host-c-or-s-to-o-common-args) \
1392 $(PRIVATE_CFLAGS) $(PRIVATE_CONLYFLAGS) \
1393 $(PRIVATE_DEBUG_CFLAGS) $(PRIVATE_CFLAGS_NO_OVERRIDE)
1394endef
1395
1396define clang-tidy-host-c
1397$(hide) $(PATH_TO_CLANG_TIDY) $(PRIVATE_TIDY_FLAGS) \
1398 -checks=$(PRIVATE_TIDY_CHECKS) \
1399 $< -- $(transform-host-c-to-o-compiler-args)
1400endef
1401
1402ifneq (,$(filter 1 true,$(WITH_TIDY_ONLY)))
1403define transform-host-c-to-o
1404$(if $(PRIVATE_TIDY_CHECKS),
1405 @echo "tidy $($(PRIVATE_PREFIX)DISPLAY) C: $<"
1406 $(clang-tidy-host-c))
1407endef
1408else
1409define transform-host-c-to-o
1410@echo "$($(PRIVATE_PREFIX)DISPLAY) C: $(PRIVATE_MODULE) <= $<"
1411@mkdir -p $(dir $@)
1412$(if $(PRIVATE_TIDY_CHECKS), $(clang-tidy-host-c))
1413$(hide) $(RELATIVE_PWD) $(PRIVATE_CC) \
1414 $(transform-host-c-to-o-compiler-args) \
1415 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
1416$(hide) $(transform-d-to-p)
1417endef
1418endif
1419
The Android Open Source Project88b60792009-03-03 19:28:42 -08001420define transform-host-s-to-o-no-deps
Dan Willemsen057aaea2015-08-14 12:59:50 -07001421@echo "$($(PRIVATE_PREFIX)DISPLAY) asm: $(PRIVATE_MODULE) <= $<"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001422$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
1423endef
1424
The Android Open Source Project88b60792009-03-03 19:28:42 -08001425define transform-host-s-to-o
1426$(transform-host-s-to-o-no-deps)
1427$(transform-d-to-p)
1428endef
1429
1430###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001431## Commands for running gcc to compile a host Objective-C file
1432###########################################################
1433
1434define transform-host-m-to-o-no-deps
Dan Willemsen057aaea2015-08-14 12:59:50 -07001435@echo "$($(PRIVATE_PREFIX)DISPLAY) ObjC: $(PRIVATE_MODULE) <= $<"
Dan Willemsendf9acac2016-03-03 17:37:50 -08001436$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_DEBUG_CFLAGS) $(PRIVATE_CFLAGS_NO_OVERRIDE))
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001437endef
1438
David 'Digit' Turner5ca286d2011-02-11 16:19:31 +01001439define transform-host-m-to-o
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001440$(transform-host-m-to-o-no-deps)
1441$(transform-d-to-p)
1442endef
1443
Scott James Remnantdd86e5a2015-09-17 15:40:49 -07001444###########################################################
1445## Commands for running gcc to compile a host Objective-C++ file
1446###########################################################
1447
1448define transform-host-mm-to-o
1449$(transform-host-cpp-to-o)
1450endef
1451
Ying Wangfb22a422015-03-10 18:03:11 -07001452
1453###########################################################
1454## Rules to compile a single C/C++ source with ../ in the path
1455###########################################################
1456# Replace "../" in object paths with $(DOTDOT_REPLACEMENT).
1457DOTDOT_REPLACEMENT := dotdot/
1458
1459## Rule to compile a C++ source file with ../ in the path.
1460## Must be called with $(eval).
1461# $(1): the C++ source file in LOCAL_SRC_FILES.
1462# $(2): the additional dependencies.
1463# $(3): the variable name to collect the output object file.
1464define compile-dotdot-cpp-file
1465o := $(intermediates)/$(patsubst %$(LOCAL_CPP_EXTENSION),%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
1466$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2)
1467 $$(transform-$$(PRIVATE_HOST)cpp-to-o)
Shinichiro Hamaji72904772016-03-16 06:40:04 +09001468$$(call include-depfiles-for-objs, $$(o))
Ying Wangfb22a422015-03-10 18:03:11 -07001469$(3) += $$(o)
1470endef
1471
1472## Rule to compile a C source file with ../ in the path.
1473## Must be called with $(eval).
1474# $(1): the C source file in LOCAL_SRC_FILES.
1475# $(2): the additional dependencies.
1476# $(3): the variable name to collect the output object file.
1477define compile-dotdot-c-file
1478o := $(intermediates)/$(patsubst %.c,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
1479$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2)
1480 $$(transform-$$(PRIVATE_HOST)c-to-o)
Shinichiro Hamaji72904772016-03-16 06:40:04 +09001481$$(call include-depfiles-for-objs, $$(o))
Ying Wangfb22a422015-03-10 18:03:11 -07001482$(3) += $$(o)
1483endef
1484
1485## Rule to compile a .S source file with ../ in the path.
1486## Must be called with $(eval).
1487# $(1): the .S source file in LOCAL_SRC_FILES.
1488# $(2): the additional dependencies.
1489# $(3): the variable name to collect the output object file.
1490define compile-dotdot-s-file
1491o := $(intermediates)/$(patsubst %.S,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
1492$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2)
1493 $$(transform-$$(PRIVATE_HOST)s-to-o)
Shinichiro Hamaji72904772016-03-16 06:40:04 +09001494$$(call include-depfiles-for-objs, $$(o))
Ying Wangfb22a422015-03-10 18:03:11 -07001495$(3) += $$(o)
1496endef
1497
1498## Rule to compile a .s source file with ../ in the path.
1499## Must be called with $(eval).
1500# $(1): the .s source file in LOCAL_SRC_FILES.
1501# $(2): the additional dependencies.
1502# $(3): the variable name to collect the output object file.
1503define compile-dotdot-s-file-no-deps
1504o := $(intermediates)/$(patsubst %.s,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
1505$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2)
1506 $$(transform-$$(PRIVATE_HOST)s-to-o-no-deps)
1507$(3) += $$(o)
1508endef
1509
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001510###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001511## Commands for running ar
1512###########################################################
1513
Ying Wange4b24eb2010-05-27 11:55:39 -07001514define _concat-if-arg2-not-empty
1515$(if $(2),$(hide) $(1) $(2))
1516endef
1517
1518# Split long argument list into smaller groups and call the command repeatedly
Torne (Richard Coles)bffaef22012-06-15 16:03:52 +01001519# Call the command at least once even if there are no arguments, as otherwise
1520# the output file won't be created.
Ying Wange4b24eb2010-05-27 11:55:39 -07001521#
1522# $(1): the command without arguments
1523# $(2): the arguments
1524define split-long-arguments
Torne (Richard Coles)bffaef22012-06-15 16:03:52 +01001525$(hide) $(1) $(wordlist 1,500,$(2))
Ying Wange4b24eb2010-05-27 11:55:39 -07001526$(call _concat-if-arg2-not-empty,$(1),$(wordlist 501,1000,$(2)))
1527$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1001,1500,$(2)))
1528$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1501,2000,$(2)))
1529$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2001,2500,$(2)))
1530$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2501,3000,$(2)))
1531$(call _concat-if-arg2-not-empty,$(1),$(wordlist 3001,99999,$(2)))
1532endef
1533
Ying Wanga02d3d92011-01-27 18:48:00 -08001534# $(1): the full path of the source static library.
1535define _extract-and-include-single-target-whole-static-lib
Ying Wanga02d3d92011-01-27 18:48:00 -08001536$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\
1537 rm -rf $$ldir; \
1538 mkdir -p $$ldir; \
Christopher Ferris44203f32015-01-07 17:14:03 -08001539 cp $(1) $$ldir; \
1540 lib_to_include=$$ldir/$(notdir $(1)); \
Ying Wanga02d3d92011-01-27 18:48:00 -08001541 filelist=; \
Christopher Ferris44203f32015-01-07 17:14:03 -08001542 subdir=0; \
Ying Wang6feb6d52014-04-17 10:03:35 -07001543 for f in `$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) t $(1)`; do \
Christopher Ferris44203f32015-01-07 17:14:03 -08001544 if [ -e $$ldir/$$f ]; then \
1545 mkdir $$ldir/$$subdir; \
1546 ext=$$subdir/; \
1547 subdir=$$((subdir+1)); \
1548 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) m $$lib_to_include $$f; \
1549 else \
1550 ext=; \
1551 fi; \
1552 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) p $$lib_to_include $$f > $$ldir/$$ext$$f; \
1553 filelist="$$filelist $$ldir/$$ext$$f"; \
Ying Wanga02d3d92011-01-27 18:48:00 -08001554 done ; \
Ying Wang61d499b2014-01-15 16:02:16 -08001555 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \
1556 $(PRIVATE_ARFLAGS) $@ $$filelist
Ying Wanga02d3d92011-01-27 18:48:00 -08001557
1558endef
1559
Dan Alberte0f44ac2014-05-23 12:26:51 -07001560# $(1): the full path of the source static library.
1561define extract-and-include-whole-static-libs-first
1562$(if $(strip $(1)),
Dan Alberte0f44ac2014-05-23 12:26:51 -07001563$(hide) cp $(1) $@)
1564endef
1565
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001566define extract-and-include-target-whole-static-libs
Dan Alberte0f44ac2014-05-23 12:26:51 -07001567$(call extract-and-include-whole-static-libs-first, $(firstword $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)))
1568$(foreach lib,$(wordlist 2,999,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)), \
Ying Wanga02d3d92011-01-27 18:48:00 -08001569 $(call _extract-and-include-single-target-whole-static-lib, $(lib)))
Dima Zavin46e9bec2009-05-27 19:41:07 -07001570endef
1571
The Android Open Source Project88b60792009-03-03 19:28:42 -08001572# Explicitly delete the archive first so that ar doesn't
1573# try to add to an existing archive.
1574define transform-o-to-static-lib
Alexey Polyudov8b540fd2016-06-24 11:13:34 -07001575@echo "$($(PRIVATE_PREFIX)DISPLAY) StaticLib: $(PRIVATE_MODULE) ($@)"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001576@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001577@rm -f $@
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001578$(extract-and-include-target-whole-static-libs)
Ying Wang6feb6d52014-04-17 10:03:35 -07001579$(call split-long-arguments,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) \
1580 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \
Ying Wang854607e2015-04-02 18:02:33 -07001581 $(PRIVATE_ARFLAGS) $@,$(PRIVATE_ALL_OBJECTS))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001582endef
1583
Alexey Polyudovccdc3112016-08-01 17:41:49 -07001584# $(1): the full path of the source static library.
1585define _extract-and-include-single-aux-whole-static-lib
1586$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\
1587 rm -rf $$ldir; \
1588 mkdir -p $$ldir; \
1589 cp $(1) $$ldir; \
1590 lib_to_include=$$ldir/$(notdir $(1)); \
1591 filelist=; \
1592 subdir=0; \
1593 for f in `$(PRIVATE_AR) t $(1)`; do \
1594 if [ -e $$ldir/$$f ]; then \
1595 mkdir $$ldir/$$subdir; \
1596 ext=$$subdir/; \
1597 subdir=$$((subdir+1)); \
1598 $(PRIVATE_AR) m $$lib_to_include $$f; \
1599 else \
1600 ext=; \
1601 fi; \
1602 $(PRIVATE_AR) p $$lib_to_include $$f > $$ldir/$$ext$$f; \
1603 filelist="$$filelist $$ldir/$$ext$$f"; \
1604 done ; \
1605 $(PRIVATE_AR) $(AUX_GLOBAL_ARFLAGS) \
1606 $(PRIVATE_ARFLAGS) $@ $$filelist
1607
1608endef
1609
1610define extract-and-include-aux-whole-static-libs
1611$(call extract-and-include-whole-static-libs-first, $(firstword $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)))
1612$(foreach lib,$(wordlist 2,999,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)), \
1613 $(call _extract-and-include-single-aux-whole-static-lib, $(lib)))
1614endef
1615
1616# Explicitly delete the archive first so that ar doesn't
1617# try to add to an existing archive.
1618define transform-o-to-aux-static-lib
1619@echo "$($(PRIVATE_PREFIX)DISPLAY) StaticLib: $(PRIVATE_MODULE) ($@)"
1620@mkdir -p $(dir $@)
1621@rm -f $@
1622$(extract-and-include-aux-whole-static-libs)
1623$(call split-long-arguments,$(PRIVATE_AR) \
1624 $(AUX_GLOBAL_ARFLAGS) \
1625 $(PRIVATE_ARFLAGS) $@,$(PRIVATE_ALL_OBJECTS))
1626endef
1627
1628define transform-o-to-aux-executable-inner
1629$(hide) $(PRIVATE_CXX) -pie \
1630 -Bdynamic \
1631 -Wl,--gc-sections \
1632 $(PRIVATE_ALL_OBJECTS) \
1633 -Wl,--whole-archive \
1634 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1635 -Wl,--no-whole-archive \
1636 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1637 $(PRIVATE_LDFLAGS) \
1638 -o $@
1639endef
1640
1641define transform-o-to-aux-executable
1642@echo "$(AUX_DISPLAY) Executable: $(PRIVATE_MODULE) ($@)"
1643@mkdir -p $(dir $@)
1644$(transform-o-to-aux-executable-inner)
1645endef
1646
1647define transform-o-to-aux-static-executable-inner
1648$(hide) $(PRIVATE_CXX) \
1649 -Bstatic \
1650 -Wl,--gc-sections \
1651 $(PRIVATE_ALL_OBJECTS) \
1652 -Wl,--whole-archive \
1653 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1654 -Wl,--no-whole-archive \
1655 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
1656 $(PRIVATE_LDFLAGS) \
1657 -Wl,-Map=$(@).map \
1658 -o $@
1659endef
1660
1661define transform-o-to-aux-static-executable
1662@echo "$(AUX_DISPLAY) StaticExecutable: $(PRIVATE_MODULE) ($@)"
1663@mkdir -p $(dir $@)
1664$(transform-o-to-aux-static-executable-inner)
1665endef
1666
The Android Open Source Project88b60792009-03-03 19:28:42 -08001667###########################################################
1668## Commands for running host ar
1669###########################################################
1670
Ying Wanga02d3d92011-01-27 18:48:00 -08001671# $(1): the full path of the source static library.
1672define _extract-and-include-single-host-whole-static-lib
Ying Wanga02d3d92011-01-27 18:48:00 -08001673$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\
1674 rm -rf $$ldir; \
1675 mkdir -p $$ldir; \
Christopher Ferris44203f32015-01-07 17:14:03 -08001676 cp $(1) $$ldir; \
1677 lib_to_include=$$ldir/$(notdir $(1)); \
Ying Wanga02d3d92011-01-27 18:48:00 -08001678 filelist=; \
Christopher Ferris44203f32015-01-07 17:14:03 -08001679 subdir=0; \
Dan Willemsen057aaea2015-08-14 12:59:50 -07001680 for f in `$($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) t $(1) | \grep '\.o$$'`; do \
Christopher Ferris44203f32015-01-07 17:14:03 -08001681 if [ -e $$ldir/$$f ]; then \
1682 mkdir $$ldir/$$subdir; \
1683 ext=$$subdir/; \
1684 subdir=$$((subdir+1)); \
Dan Willemsen057aaea2015-08-14 12:59:50 -07001685 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) m $$lib_to_include $$f; \
Christopher Ferris44203f32015-01-07 17:14:03 -08001686 else \
1687 ext=; \
1688 fi; \
Dan Willemsen057aaea2015-08-14 12:59:50 -07001689 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) p $$lib_to_include $$f > $$ldir/$$ext$$f; \
Christopher Ferris44203f32015-01-07 17:14:03 -08001690 filelist="$$filelist $$ldir/$$ext$$f"; \
Ying Wanga02d3d92011-01-27 18:48:00 -08001691 done ; \
Dan Willemsen057aaea2015-08-14 12:59:50 -07001692 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)GLOBAL_ARFLAGS) \
Ying Wang6feb6d52014-04-17 10:03:35 -07001693 $(PRIVATE_ARFLAGS) $@ $$filelist
Ying Wanga02d3d92011-01-27 18:48:00 -08001694
1695endef
1696
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001697define extract-and-include-host-whole-static-libs
Dan Alberte0f44ac2014-05-23 12:26:51 -07001698$(call extract-and-include-whole-static-libs-first, $(firstword $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)))
1699$(foreach lib,$(wordlist 2,999,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)), \
Ying Wanga02d3d92011-01-27 18:48:00 -08001700 $(call _extract-and-include-single-host-whole-static-lib, $(lib)))
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001701endef
1702
Ying Wang4aaa1a12016-03-22 18:23:13 -07001703ifeq ($(HOST_OS),darwin)
1704# On Darwin the host ar fails if there is nothing to add to .a at all.
1705# We work around by adding a dummy.o and then deleting it.
1706define create-dummy.o-if-no-objs
1707$(if $(PRIVATE_ALL_OBJECTS),,$(hide) touch $(dir $@)dummy.o)
1708endef
1709
1710define get-dummy.o-if-no-objs
1711$(if $(PRIVATE_ALL_OBJECTS),,$(dir $@)dummy.o)
1712endef
1713
1714define delete-dummy.o-if-no-objs
1715$(if $(PRIVATE_ALL_OBJECTS),,$(hide) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) d $@ $(dir $@)dummy.o \
1716 && rm -f $(dir $@)dummy.o)
1717endef
1718endif # HOST_OS is darwin
1719
The Android Open Source Project88b60792009-03-03 19:28:42 -08001720# Explicitly delete the archive first so that ar doesn't
1721# try to add to an existing archive.
1722define transform-host-o-to-static-lib
Dan Willemsen057aaea2015-08-14 12:59:50 -07001723@echo "$($(PRIVATE_PREFIX)DISPLAY) StaticLib: $(PRIVATE_MODULE) ($@)"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001724@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001725@rm -f $@
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001726$(extract-and-include-host-whole-static-libs)
Ying Wang4aaa1a12016-03-22 18:23:13 -07001727$(create-dummy.o-if-no-objs)
Dan Willemsen057aaea2015-08-14 12:59:50 -07001728$(call split-long-arguments,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)AR) \
1729 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)GLOBAL_ARFLAGS) \
Ying Wang4aaa1a12016-03-22 18:23:13 -07001730 $(PRIVATE_ARFLAGS) $@,$(PRIVATE_ALL_OBJECTS) $(get-dummy.o-if-no-objs))
1731$(delete-dummy.o-if-no-objs)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001732endef
1733
1734
1735###########################################################
1736## Commands for running gcc to link a shared library or package
1737###########################################################
1738
1739# ld just seems to be so finicky with command order that we allow
1740# it to be overriden en-masse see combo/linux-arm.make for an example.
1741ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1742define transform-host-o-to-shared-lib-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001743$(hide) $(PRIVATE_CXX) \
Dan Willemsen057aaea2015-08-14 12:59:50 -07001744 -Wl,-rpath-link=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)OUT_INTERMEDIATE_LIBRARIES) \
1745 -Wl,-rpath,\$$ORIGIN/../$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)OUT_SHARED_LIBRARIES)) \
1746 -Wl,-rpath,\$$ORIGIN/$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)OUT_SHARED_LIBRARIES)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001747 -shared -Wl,-soname,$(notdir $@) \
Dan Willemsen057aaea2015-08-14 12:59:50 -07001748 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)GLOBAL_LD_DIRS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001749 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001750 $(PRIVATE_HOST_GLOBAL_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001751 ) \
Torne (Richard Coles)a424bf72014-02-12 14:24:41 +00001752 $(PRIVATE_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001753 $(PRIVATE_ALL_OBJECTS) \
1754 -Wl,--whole-archive \
1755 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1756 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001757 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001758 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001759 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
Dan Albert43e128a2015-01-23 16:12:57 -08001760 $(if $(filter true,$(NATIVE_COVERAGE)),-lgcov) \
Dan Albert343ed672015-01-25 16:20:57 -08001761 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_HOST_LIBPROFILE_RT)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001762 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1763 -o $@ \
1764 $(PRIVATE_LDLIBS)
1765endef
1766endif
1767
1768define transform-host-o-to-shared-lib
Dan Willemsen057aaea2015-08-14 12:59:50 -07001769@echo "$($(PRIVATE_PREFIX)DISPLAY) SharedLib: $(PRIVATE_MODULE) ($@)"
Colin Crossb6da5892015-07-16 17:14:27 -07001770@mkdir -p $(dir $@)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001771$(transform-host-o-to-shared-lib-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001772endef
1773
1774define transform-host-o-to-package
Dan Willemsen057aaea2015-08-14 12:59:50 -07001775@echo "$($(PRIVATE_PREFIX)DISPLAY) Package: $(PRIVATE_MODULE) ($@)"
Colin Crossb6da5892015-07-16 17:14:27 -07001776@mkdir -p $(dir $@)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001777$(transform-host-o-to-shared-lib-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001778endef
1779
1780
1781###########################################################
1782## Commands for running gcc to link a shared library or package
1783###########################################################
1784
The Android Open Source Project88b60792009-03-03 19:28:42 -08001785define transform-o-to-shared-lib-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001786$(hide) $(PRIVATE_CXX) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001787 -nostdlib -Wl,-soname,$(notdir $@) \
1788 -Wl,--gc-sections \
Logan Chiene481e7d2015-01-25 21:15:12 +08001789 $(if $(filter true,$(PRIVATE_CLANG)),-shared,-Wl$(comma)-shared) \
Ying Wang1a081002010-07-13 14:55:47 -07001790 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
Ying Wang491fca92015-07-02 15:57:45 -07001791 $(PRIVATE_TARGET_CRTBEGIN_SO_O) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001792 $(PRIVATE_ALL_OBJECTS) \
1793 -Wl,--whole-archive \
Ying Wang80e6cce2011-01-24 23:25:36 -08001794 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001795 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001796 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001797 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001798 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
Dan Albert7fbbc5d2015-10-08 14:16:39 -07001799 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_COVERAGE_LIB)) \
Dan Albert91f713a2015-03-31 15:21:30 -07001800 $(PRIVATE_TARGET_LIBATOMIC) \
1801 $(PRIVATE_TARGET_LIBGCC) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001802 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
1803 $(PRIVATE_LDFLAGS) \
Dan Albert121aa602016-07-26 11:54:47 -07001804 $(PRIVATE_ALL_SHARED_LIBRARIES) \
Chih-Hung Hsiehad741e62016-03-09 14:54:55 -08001805 -o $@ \
Ying Wang491fca92015-07-02 15:57:45 -07001806 $(PRIVATE_TARGET_CRTEND_SO_O) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001807 $(PRIVATE_LDLIBS)
1808endef
The Android Open Source Project88b60792009-03-03 19:28:42 -08001809
1810define transform-o-to-shared-lib
Alexey Polyudov8b540fd2016-06-24 11:13:34 -07001811@echo "$($(PRIVATE_PREFIX)DISPLAY) SharedLib: $(PRIVATE_MODULE) ($@)"
Colin Crossb6da5892015-07-16 17:14:27 -07001812@mkdir -p $(dir $@)
Dan Alberte088c0d2014-11-13 10:15:46 -08001813$(transform-o-to-shared-lib-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001814endef
1815
The Android Open Source Project88b60792009-03-03 19:28:42 -08001816###########################################################
1817## Commands for filtering a target executable or library
1818###########################################################
1819
Ying Wangce1c5962014-03-28 17:24:39 -07001820ifneq ($(TARGET_BUILD_VARIANT),user)
1821 TARGET_STRIP_EXTRA = && $(PRIVATE_OBJCOPY) --add-gnu-debuglink=$< $@
1822 TARGET_STRIP_KEEP_SYMBOLS_EXTRA = --add-gnu-debuglink=$<
1823endif
1824
The Android Open Source Project88b60792009-03-03 19:28:42 -08001825define transform-to-stripped
Alexey Polyudov8b540fd2016-06-24 11:13:34 -07001826@echo "$($(PRIVATE_PREFIX)DISPLAY) Strip: $(PRIVATE_MODULE) ($@)"
Colin Crossb6da5892015-07-16 17:14:27 -07001827@mkdir -p $(dir $@)
Ying Wangbfb52a22014-08-20 17:12:32 -07001828$(hide) $(PRIVATE_STRIP) --strip-all $< -o $@ \
1829 $(if $(PRIVATE_NO_DEBUGLINK),,$(TARGET_STRIP_EXTRA))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001830endef
1831
Yabin Cuifab79952016-03-29 12:22:20 -07001832define transform-to-stripped-keep-mini-debug-info
Alexey Polyudov8b540fd2016-06-24 11:13:34 -07001833@echo "$($(PRIVATE_PREFIX)DISPLAY) Strip (mini debug info): $(PRIVATE_MODULE) ($@)"
Yabin Cuifab79952016-03-29 12:22:20 -07001834@mkdir -p $(dir $@)
1835$(hide) $(PRIVATE_NM) -D $< --format=posix --defined-only | awk '{ print $$1 }' | sort >$@.dynsyms
1836$(hide) $(PRIVATE_NM) $< --format=posix --defined-only | awk '{ if ($$2 == "T" || $$2 == "t" || $$2 == "D") print $$1 }' | sort >$@.funcsyms
1837$(hide) comm -13 $@.dynsyms $@.funcsyms >$@.keep_symbols
1838$(hide) $(PRIVATE_OBJCOPY) --only-keep-debug $< $@.debug
1839$(hide) $(PRIVATE_OBJCOPY) --rename-section .debug_frame=saved_debug_frame $@.debug $@.mini_debuginfo
1840$(hide) $(PRIVATE_OBJCOPY) -S --remove-section .gdb_index --remove-section .comment --keep-symbols=$@.keep_symbols $@.mini_debuginfo
1841$(hide) $(PRIVATE_OBJCOPY) --rename-section saved_debug_frame=.debug_frame $@.mini_debuginfo
1842$(hide) $(PRIVATE_STRIP) --strip-all -R .comment $< -o $@
1843$(hide) rm -f $@.mini_debuginfo.xz
1844$(hide) xz $@.mini_debuginfo
1845$(hide) $(PRIVATE_OBJCOPY) --add-section .gnu_debugdata=$@.mini_debuginfo.xz $@
1846$(hide) rm -f $@.dynsyms $@.funcsyms $@.keep_symbols $@.debug $@.mini_debuginfo.xz
1847endef
1848
Christopher Ferrisa6e2f932014-03-18 14:50:09 -07001849define transform-to-stripped-keep-symbols
Alexey Polyudov8b540fd2016-06-24 11:13:34 -07001850@echo "$($(PRIVATE_PREFIX)DISPLAY) Strip (keep symbols): $(PRIVATE_MODULE) ($@)"
Colin Crossb6da5892015-07-16 17:14:27 -07001851@mkdir -p $(dir $@)
Ying Wangce1c5962014-03-28 17:24:39 -07001852$(hide) $(PRIVATE_OBJCOPY) \
1853 `$(PRIVATE_READELF) -S $< | awk '/.debug_/ {print "-R " $$2}' | xargs` \
1854 $(TARGET_STRIP_KEEP_SYMBOLS_EXTRA) $< $@
Christopher Ferrisa6e2f932014-03-18 14:50:09 -07001855endef
1856
Dmitriy Ivanov4c2d1a62015-04-20 16:59:05 -07001857###########################################################
1858## Commands for packing a target executable or library
1859###########################################################
1860
1861define pack-elf-relocations
Alexey Polyudov8b540fd2016-06-24 11:13:34 -07001862@echo "$($(PRIVATE_PREFIX)DISPLAY) Pack Relocations: $(PRIVATE_MODULE) ($@)"
Colin Crossb6da5892015-07-16 17:14:27 -07001863$(copy-file-to-target)
Dmitriy Ivanov4c2d1a62015-04-20 16:59:05 -07001864$(hide) $(RELOCATION_PACKER) $@
1865endef
The Android Open Source Project88b60792009-03-03 19:28:42 -08001866
1867###########################################################
1868## Commands for running gcc to link an executable
1869###########################################################
1870
The Android Open Source Project88b60792009-03-03 19:28:42 -08001871define transform-o-to-executable-inner
Dan Alberte088c0d2014-11-13 10:15:46 -08001872$(hide) $(PRIVATE_CXX) -pie \
1873 -nostdlib -Bdynamic \
Evgenii Stepanov8f5e67a2015-07-10 18:06:51 -07001874 -Wl,-dynamic-linker,$(PRIVATE_LINKER) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001875 -Wl,--gc-sections \
1876 -Wl,-z,nocopyreloc \
Ying Wangc6ffc002012-09-25 17:52:10 -07001877 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
Ying Wang9fb35262014-02-21 16:17:05 -08001878 -Wl,-rpath-link=$(PRIVATE_TARGET_OUT_INTERMEDIATE_LIBRARIES) \
Ying Wang491fca92015-07-02 15:57:45 -07001879 $(PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001880 $(PRIVATE_ALL_OBJECTS) \
1881 -Wl,--whole-archive \
1882 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1883 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001884 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001885 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001886 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
Dan Albert7fbbc5d2015-10-08 14:16:39 -07001887 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_COVERAGE_LIB)) \
Dan Albert91f713a2015-03-31 15:21:30 -07001888 $(PRIVATE_TARGET_LIBATOMIC) \
1889 $(PRIVATE_TARGET_LIBGCC) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001890 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
1891 $(PRIVATE_LDFLAGS) \
Dan Albert121aa602016-07-26 11:54:47 -07001892 $(PRIVATE_ALL_SHARED_LIBRARIES) \
Chih-Hung Hsiehad741e62016-03-09 14:54:55 -08001893 -o $@ \
Ying Wang491fca92015-07-02 15:57:45 -07001894 $(PRIVATE_TARGET_CRTEND_O) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001895 $(PRIVATE_LDLIBS)
1896endef
The Android Open Source Project88b60792009-03-03 19:28:42 -08001897
1898define transform-o-to-executable
Alexey Polyudov8b540fd2016-06-24 11:13:34 -07001899@echo "$($(PRIVATE_PREFIX)DISPLAY) Executable: $(PRIVATE_MODULE) ($@)"
Colin Crossb6da5892015-07-16 17:14:27 -07001900@mkdir -p $(dir $@)
Dan Alberte088c0d2014-11-13 10:15:46 -08001901$(transform-o-to-executable-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001902endef
1903
1904
1905###########################################################
Dan Alberte088c0d2014-11-13 10:15:46 -08001906## Commands for linking a static executable. In practice,
1907## we only use this on arm, so the other platforms don't
1908## have transform-o-to-static-executable defined.
Chih-Hung Hsieh69b1fe62015-01-20 11:00:20 -08001909## Clang driver needs -static to create static executable.
1910## However, bionic/linker uses -shared to overwrite.
1911## Linker for x86 targets does not allow coexistance of -static and -shared,
1912## so we add -static only if -shared is not used.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001913###########################################################
1914
The Android Open Source Project88b60792009-03-03 19:28:42 -08001915define transform-o-to-static-executable-inner
Dan Alberte088c0d2014-11-13 10:15:46 -08001916$(hide) $(PRIVATE_CXX) \
1917 -nostdlib -Bstatic \
Chih-Hung Hsieh69b1fe62015-01-20 11:00:20 -08001918 $(if $(filter $(PRIVATE_LDFLAGS),-shared),,-static) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001919 -Wl,--gc-sections \
1920 -o $@ \
1921 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
Ying Wang491fca92015-07-02 15:57:45 -07001922 $(PRIVATE_TARGET_CRTBEGIN_STATIC_O) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001923 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
1924 $(PRIVATE_LDFLAGS) \
1925 $(PRIVATE_ALL_OBJECTS) \
1926 -Wl,--whole-archive \
1927 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1928 -Wl,--no-whole-archive \
1929 $(call normalize-target-libraries,$(filter-out %libcompiler_rt.a,$(filter-out %libc_nomalloc.a,$(filter-out %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))))) \
1930 -Wl,--start-group \
1931 $(call normalize-target-libraries,$(filter %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
1932 $(call normalize-target-libraries,$(filter %libc_nomalloc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
Dan Albert7fbbc5d2015-10-08 14:16:39 -07001933 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_COVERAGE_LIB)) \
Dan Albert343ed672015-01-25 16:20:57 -08001934 $(PRIVATE_TARGET_LIBATOMIC) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001935 $(call normalize-target-libraries,$(filter %libcompiler_rt.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
Dan Albert741b36e2014-11-13 21:24:04 -08001936 $(PRIVATE_TARGET_LIBGCC) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001937 -Wl,--end-group \
Ying Wang491fca92015-07-02 15:57:45 -07001938 $(PRIVATE_TARGET_CRTEND_O)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001939endef
The Android Open Source Project88b60792009-03-03 19:28:42 -08001940
1941define transform-o-to-static-executable
Alexey Polyudov8b540fd2016-06-24 11:13:34 -07001942@echo "$($(PRIVATE_PREFIX)DISPLAY) StaticExecutable: $(PRIVATE_MODULE) ($@)"
Colin Crossb6da5892015-07-16 17:14:27 -07001943@mkdir -p $(dir $@)
Dan Alberte088c0d2014-11-13 10:15:46 -08001944$(transform-o-to-static-executable-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001945endef
1946
1947
1948###########################################################
1949## Commands for running gcc to link a host executable
1950###########################################################
Ying Wangfaf3d5e2014-04-04 14:37:33 -07001951ifdef BUILD_HOST_static
1952HOST_FPIE_FLAGS :=
1953else
Dan Albert4803ce22014-08-06 12:36:46 -07001954HOST_FPIE_FLAGS := -pie
Stephen Hinesa503fb32014-10-02 00:51:11 -07001955# Force the correct entry point to workaround a bug in binutils that manifests with -pie
Dan Willemsen057aaea2015-08-14 12:59:50 -07001956ifeq ($(HOST_CROSS_OS),windows)
1957HOST_CROSS_FPIE_FLAGS += -Wl,-e_mainCRTStartup
Stephen Hinesa503fb32014-10-02 00:51:11 -07001958endif
Ying Wangfaf3d5e2014-04-04 14:37:33 -07001959endif
The Android Open Source Project88b60792009-03-03 19:28:42 -08001960
1961ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1962define transform-host-o-to-executable-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001963$(hide) $(PRIVATE_CXX) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001964 $(PRIVATE_ALL_OBJECTS) \
1965 -Wl,--whole-archive \
1966 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1967 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001968 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001969 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001970 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
Dan Albert43e128a2015-01-23 16:12:57 -08001971 $(if $(filter true,$(NATIVE_COVERAGE)),-lgcov) \
Dan Albert343ed672015-01-25 16:20:57 -08001972 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_HOST_LIBPROFILE_RT)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001973 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
Dan Willemsen057aaea2015-08-14 12:59:50 -07001974 -Wl,-rpath-link=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)OUT_INTERMEDIATE_LIBRARIES) \
Dan Willemsen7fe992c2016-03-02 13:54:51 -08001975 $(foreach path,$(PRIVATE_RPATHS), \
1976 -Wl,-rpath,\$$ORIGIN/$(path)) \
Dan Willemsen057aaea2015-08-14 12:59:50 -07001977 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)GLOBAL_LD_DIRS) \
Conley Owensd9e7d252011-11-10 09:57:40 -08001978 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001979 $(PRIVATE_HOST_GLOBAL_LDFLAGS) \
Conley Owensd9e7d252011-11-10 09:57:40 -08001980 ) \
Torne (Richard Coles)a424bf72014-02-12 14:24:41 +00001981 $(PRIVATE_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001982 -o $@ \
1983 $(PRIVATE_LDLIBS)
1984endef
1985endif
1986
1987define transform-host-o-to-executable
Dan Willemsen057aaea2015-08-14 12:59:50 -07001988@echo "$($(PRIVATE_PREFIX)DISPLAY) Executable: $(PRIVATE_MODULE) ($@)"
Colin Crossb6da5892015-07-16 17:14:27 -07001989@mkdir -p $(dir $@)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001990$(transform-host-o-to-executable-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001991endef
1992
1993
1994###########################################################
1995## Commands for running javac to make .class files
1996###########################################################
1997
Ying Wangd75d8932015-09-19 10:56:35 -07001998# Add BUILD_NUMBER to apps default version name if it's unbundled build.
1999ifdef TARGET_BUILD_APPS
2000APPS_DEFAULT_VERSION_NAME := $(PLATFORM_VERSION)-$(BUILD_NUMBER_FROM_FILE)
2001else
2002APPS_DEFAULT_VERSION_NAME := $(PLATFORM_VERSION)
2003endif
2004
The Android Open Source Project88b60792009-03-03 19:28:42 -08002005# TODO: Right now we generate the asset resources twice, first as part
2006# of generating the Java classes, then at the end when packaging the final
2007# assets. This should be changed to do one of two things: (1) Don't generate
2008# any resource files the first time, only create classes during that stage;
2009# or (2) Don't use the -c flag with the second stage, instead taking the
2010# resource files from the first stage as additional input. My original intent
2011# was to use approach (2), but this requires a little more work in the tool.
2012# Maybe we should just use approach (1).
2013
2014# This rule creates the R.java and Manifest.java files, both of which
Ying Wang4f1ab922011-03-15 13:19:30 -07002015# are PRODUCT-neutral. Don't pass PRIVATE_PRODUCT_AAPT_CONFIG to this invocation.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002016define create-resource-java-files
2017@mkdir -p $(PRIVATE_SOURCE_INTERMEDIATES_DIR)
2018@mkdir -p $(dir $(PRIVATE_RESOURCE_PUBLICS_OUTPUT))
Ying Wangc61d5932010-03-10 16:02:42 -08002019$(hide) $(AAPT) package $(PRIVATE_AAPT_FLAGS) -m \
Ying Wang4f1ab922011-03-15 13:19:30 -07002020 $(eval # PRIVATE_PRODUCT_AAPT_CONFIG is intentionally missing-- see comment.) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08002021 $(addprefix -J , $(PRIVATE_SOURCE_INTERMEDIATES_DIR)) \
2022 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
2023 $(addprefix -P , $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) \
2024 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
2025 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
Dianne Hackborn9bd54042009-05-15 18:01:20 -07002026 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
Joe Onorato2daa2b32009-08-30 13:39:24 -07002027 $(addprefix -G , $(PRIVATE_PROGUARD_OPTIONS_FILE)) \
Ying Wangbb9c2302011-04-08 17:27:35 -07002028 $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
2029 $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
Colin Crossf37b4552015-07-16 17:15:19 -07002030 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,--version-code $(PLATFORM_SDK_VERSION)) \
Ying Wangd75d8932015-09-19 10:56:35 -07002031 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,--version-name $(APPS_DEFAULT_VERSION_NAME)) \
Ying Wang8c254822010-03-16 16:13:56 -07002032 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Adrian Roos6784cae2015-06-01 18:24:41 -07002033 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \
2034 --skip-symbols-without-default-localization
The Android Open Source Project88b60792009-03-03 19:28:42 -08002035endef
2036
Jeffrey Chyan7adbf972010-07-07 13:42:19 -05002037xlint_unchecked := -Xlint:unchecked
The Android Open Source Project88b60792009-03-03 19:28:42 -08002038
2039# emit-line, <word list>, <output file>
2040define emit-line
2041 $(if $(1),echo -n '$(strip $(1)) ' >> $(2))
2042endef
2043
2044# dump-words-to-file, <word list>, <output file>
2045define dump-words-to-file
2046 @rm -f $(2)
Yohann Rousself8c63cb2015-10-06 15:28:38 +02002047 @touch $(2)
The Android Open Source Project88b60792009-03-03 19:28:42 -08002048 @$(call emit-line,$(wordlist 1,200,$(1)),$(2))
2049 @$(call emit-line,$(wordlist 201,400,$(1)),$(2))
2050 @$(call emit-line,$(wordlist 401,600,$(1)),$(2))
2051 @$(call emit-line,$(wordlist 601,800,$(1)),$(2))
2052 @$(call emit-line,$(wordlist 801,1000,$(1)),$(2))
2053 @$(call emit-line,$(wordlist 1001,1200,$(1)),$(2))
2054 @$(call emit-line,$(wordlist 1201,1400,$(1)),$(2))
2055 @$(call emit-line,$(wordlist 1401,1600,$(1)),$(2))
2056 @$(call emit-line,$(wordlist 1601,1800,$(1)),$(2))
2057 @$(call emit-line,$(wordlist 1801,2000,$(1)),$(2))
2058 @$(call emit-line,$(wordlist 2001,2200,$(1)),$(2))
2059 @$(call emit-line,$(wordlist 2201,2400,$(1)),$(2))
2060 @$(call emit-line,$(wordlist 2401,2600,$(1)),$(2))
2061 @$(call emit-line,$(wordlist 2601,2800,$(1)),$(2))
2062 @$(call emit-line,$(wordlist 2801,3000,$(1)),$(2))
2063 @$(call emit-line,$(wordlist 3001,3200,$(1)),$(2))
2064 @$(call emit-line,$(wordlist 3201,3400,$(1)),$(2))
2065 @$(call emit-line,$(wordlist 3401,3600,$(1)),$(2))
2066 @$(call emit-line,$(wordlist 3601,3800,$(1)),$(2))
2067 @$(call emit-line,$(wordlist 3801,4000,$(1)),$(2))
Jesse Wilson72c941a2010-05-04 16:33:49 -07002068 @$(call emit-line,$(wordlist 4001,4200,$(1)),$(2))
2069 @$(call emit-line,$(wordlist 4201,4400,$(1)),$(2))
2070 @$(call emit-line,$(wordlist 4401,4600,$(1)),$(2))
2071 @$(call emit-line,$(wordlist 4601,4800,$(1)),$(2))
2072 @$(call emit-line,$(wordlist 4801,5000,$(1)),$(2))
Przemyslaw Szczepaniak20de4fa2015-11-20 15:05:03 +00002073 @$(call emit-line,$(wordlist 5001,5200,$(1)),$(2))
2074 @$(if $(wordlist 5201,5202,$(1)),$(error Too many words ($(words $(1)))))
The Android Open Source Project88b60792009-03-03 19:28:42 -08002075endef
2076
2077# For a list of jar files, unzip them to a specified directory,
Ying Wang3be52e62015-11-24 11:44:20 -08002078# but make sure that no META-INF files come along for the ride,
2079# unless PRIVATE_DONT_DELETE_JAR_META_INF is set.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002080#
2081# $(1): files to unzip
2082# $(2): destination directory
2083define unzip-jar-files
2084 $(hide) for f in $(1); \
2085 do \
2086 if [ ! -f $$f ]; then \
2087 echo Missing file $$f; \
2088 exit 1; \
2089 fi; \
Sriram Ramanf1a55f82009-06-09 15:08:29 -07002090 unzip -qo $$f -d $(2); \
Ying Wang3be52e62015-11-24 11:44:20 -08002091 done
2092 $(if $(PRIVATE_DONT_DELETE_JAR_META_INF),,$(hide) rm -rf $(2)/META-INF)
The Android Open Source Project88b60792009-03-03 19:28:42 -08002093endef
2094
Yohann Roussel8998d572015-07-03 15:46:51 +02002095# Call jack
2096#
Yohann Roussel8998d572015-07-03 15:46:51 +02002097define call-jack
Yohann Roussel6528ea32015-10-12 18:02:51 +02002098 JACK_VERSION=$(PRIVATE_JACK_VERSION) $(JACK) $(DEFAULT_JACK_EXTRA_ARGS)
Yohann Roussel8998d572015-07-03 15:46:51 +02002099endef
2100
Brian Carlstrom78269512010-12-10 12:10:24 -08002101# Common definition to invoke javac on the host and target.
2102#
2103# Some historical notes:
2104# - below we write the list of java files to java-source-list to avoid argument
2105# list length problems with Cygwin
2106# - we filter out duplicate java file names because eclipse's compiler
2107# doesn't like them.
2108#
2109# $(1): javac
2110# $(2): bootclasspath
2111define compile-java
Joe Onorato64d85d02009-04-09 19:31:12 -07002112$(hide) rm -f $@
2113$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
Brian Carlstrom78269512010-12-10 12:10:24 -08002114$(hide) mkdir -p $(dir $@)
Joe Onorato64d85d02009-04-09 19:31:12 -07002115$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
Brian Carlstrom78269512010-12-10 12:10:24 -08002116$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES),$(PRIVATE_CLASS_INTERMEDIATES_DIR))
Ying Wang015edd22011-01-20 15:01:56 -08002117$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list)
Joe Onorato64d85d02009-04-09 19:31:12 -07002118$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
Ying Wang4aedea92015-08-04 12:44:38 -07002119 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 -08002120fi
Ying Wang884738e2015-05-08 18:51:00 +00002121$(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \
Ying Wang4d688792015-10-22 16:30:00 -07002122 | $(NORMALIZE_PATH) | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
Ying Wang884738e2015-05-08 18:51:00 +00002123$(hide) if [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
Ying Wange109a1d2011-12-12 17:52:03 -08002124 $(1) -encoding UTF-8 \
Ying Wang057eba02012-10-18 10:54:49 -07002125 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
Brian Carlstrom78269512010-12-10 12:10:24 -08002126 $(2) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08002127 $(addprefix -classpath ,$(strip \
2128 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \
Ying Wang057eba02012-10-18 10:54:49 -07002129 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08002130 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
Brian Carlstrom78269512010-12-10 12:10:24 -08002131 $(PRIVATE_JAVACFLAGS) \
Ying Wang015edd22011-01-20 15:01:56 -08002132 \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \
Ying Wange109a1d2011-12-12 17:52:03 -08002133 || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 ) \
2134fi
Joe Onorato0eccce92011-10-30 21:37:35 -07002135$(if $(PRIVATE_JAVA_LAYERS_FILE), $(hide) build/tools/java-layers.py \
2136 $(PRIVATE_JAVA_LAYERS_FILE) \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq,)
Ying Wang015edd22011-01-20 15:01:56 -08002137$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list
2138$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
Ying Wang5758b8e2011-12-15 16:36:55 -08002139$(if $(PRIVATE_JAR_EXCLUDE_FILES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
2140 -name $(word 1, $(PRIVATE_JAR_EXCLUDE_FILES)) \
2141 $(addprefix -o -name , $(wordlist 2, 999, $(PRIVATE_JAR_EXCLUDE_FILES))) \
2142 | xargs rm -rf)
Jeff Brown4c4aa992014-05-23 18:41:19 -07002143$(if $(PRIVATE_JAR_PACKAGES), \
2144 $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -mindepth 1 -type f \
2145 $(foreach pkg, $(PRIVATE_JAR_PACKAGES), \
2146 -not -path $(PRIVATE_CLASS_INTERMEDIATES_DIR)/$(subst .,/,$(pkg))/\*) -delete ; \
2147 find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -empty -delete)
2148$(if $(PRIVATE_JAR_EXCLUDE_PACKAGES), $(hide) rm -rf \
2149 $(foreach pkg, $(PRIVATE_JAR_EXCLUDE_PACKAGES), \
2150 $(PRIVATE_CLASS_INTERMEDIATES_DIR)/$(subst .,/,$(pkg))))
Guang Zhu5c9a1a42013-09-24 19:05:52 -07002151$(if $(PRIVATE_JAR_MANIFEST), \
Colin Crossf37b4552015-07-16 17:15:19 -07002152 $(hide) sed -e "s/%BUILD_NUMBER%/$(BUILD_NUMBER_FROM_FILE)/" \
Guang Zhu5c9a1a42013-09-24 19:05:52 -07002153 $(PRIVATE_JAR_MANIFEST) > $(dir $@)/manifest.mf && \
2154 jar -cfm $@ $(dir $@)/manifest.mf \
2155 -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) ., \
2156 $(hide) jar -cf $@ -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .)
Ying Wang33360dd2015-01-14 14:23:56 -08002157$(if $(PRIVATE_EXTRA_JAR_ARGS),$(call add-java-resources-to,$@))
Brian Carlstrom78269512010-12-10 12:10:24 -08002158endef
2159
2160define transform-java-to-classes.jar
Alexey Polyudov8b540fd2016-06-24 11:13:34 -07002161@echo "$($(PRIVATE_PREFIX)DISPLAY) Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
Brian Carlstrom78269512010-12-10 12:10:24 -08002162$(call compile-java,$(TARGET_JAVAC),$(PRIVATE_BOOTCLASSPATH))
The Android Open Source Project88b60792009-03-03 19:28:42 -08002163endef
2164
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002165# Invoke Jack to compile java from source to dex and jack files.
2166#
2167# Some historical notes:
2168# - below we write the list of java files to java-source-list to avoid argument
2169# list length problems with Cygwin
2170# - we filter out duplicate java file names because Jack doesn't like them.
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002171define jack-java-to-dex
2172$(hide) rm -f $@
2173$(hide) rm -f $(PRIVATE_CLASSES_JACK)
2174$(hide) rm -rf $(PRIVATE_JACK_INTERMEDIATES_DIR)
2175$(hide) mkdir -p $(dir $@)
2176$(hide) mkdir -p $(dir $(PRIVATE_CLASSES_JACK))
2177$(hide) mkdir -p $(PRIVATE_JACK_INTERMEDIATES_DIR)
Yohann Roussel37822c42015-01-09 10:36:40 +01002178$(if $(PRIVATE_JACK_INCREMENTAL_DIR),$(hide) mkdir -p $(PRIVATE_JACK_INCREMENTAL_DIR))
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002179$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list)
2180$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
2181 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list; \
2182fi
Ying Wang884738e2015-05-08 18:51:00 +00002183$(hide) tr ' ' '\n' < $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list \
Ying Wang4d688792015-10-22 16:30:00 -07002184 | $(NORMALIZE_PATH) | sort -u > $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002185$(if $(PRIVATE_JACK_PROGUARD_FLAGS), \
2186 $(hide) echo -basedirectory $(CURDIR) > $@.flags; \
2187 echo $(PRIVATE_JACK_PROGUARD_FLAGS) >> $@.flags; \
2188)
Ying Wang33360dd2015-01-14 14:23:56 -08002189$(if $(PRIVATE_EXTRA_JAR_ARGS),
2190 $(hide) mkdir -p $@.res.tmp
2191 $(hide) $(call create-empty-package-at,$@.res.tmp.zip)
2192 $(hide) $(call add-java-resources-to,$@.res.tmp.zip)
Ying Wang3be52e62015-11-24 11:44:20 -08002193 $(hide) unzip -qo $@.res.tmp.zip -d $@.res.tmp
Ying Wang33360dd2015-01-14 14:23:56 -08002194 $(hide) rm $@.res.tmp.zip)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002195$(hide) if [ -s $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
2196 export tmpEcjArg="@$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq"; \
2197else \
2198 export tmpEcjArg=""; \
2199fi; \
Yohann Roussel6528ea32015-10-12 18:02:51 +02002200$(call call-jack) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002201 $(strip $(PRIVATE_JACK_FLAGS)) \
Sebastien Hertzdfce8ad2015-11-19 17:53:00 +01002202 $(strip $(PRIVATE_JACK_COVERAGE_OPTIONS)) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002203 $(if $(NO_OPTIMIZE_DX), \
2204 -D jack.dex.optimize="false") \
Yohann Roussel5b2c6e22015-05-20 17:52:15 +02002205 $(if $(PRIVATE_RMTYPEDEFS), \
2206 -D jack.android.remove-typedef="true") \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002207 $(addprefix --classpath ,$(strip \
Yohann Rousselae2fc812016-04-21 16:49:10 +02002208 $(call normalize-path-list,$(PRIVATE_JACK_SHARED_LIBRARIES)))) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002209 $(addprefix --import ,$(call reverse-list,$(PRIVATE_STATIC_JACK_LIBRARIES))) \
Ying Wang33360dd2015-01-14 14:23:56 -08002210 $(if $(PRIVATE_EXTRA_JAR_ARGS),--import-resource $@.res.tmp) \
Yohann Rousselc6383d62016-03-09 17:19:58 +01002211 -D jack.android.min-api-level=$(PRIVATE_JACK_MIN_SDK_VERSION) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002212 -D jack.import.resource.policy=keep-first \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002213 -D jack.import.type.policy=keep-first \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002214 --output-jack $(PRIVATE_CLASSES_JACK) \
Yohann Roussel37822c42015-01-09 10:36:40 +01002215 $(if $(PRIVATE_JACK_INCREMENTAL_DIR),--incremental-folder $(PRIVATE_JACK_INCREMENTAL_DIR)) \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002216 --output-dex $(PRIVATE_JACK_INTERMEDIATES_DIR) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002217 $(addprefix --config-jarjar ,$(strip $(PRIVATE_JARJAR_RULES))) \
2218 $(if $(PRIVATE_JACK_PROGUARD_FLAGS),--config-proguard $@.flags) \
2219 $$tmpEcjArg \
Yohann Rousselb2c55582015-07-02 12:10:17 +02002220 || ( rm -rf $(PRIVATE_CLASSES_JACK); exit 41 )
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002221$(hide) mv $(PRIVATE_JACK_INTERMEDIATES_DIR)/classes*.dex $(dir $@)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002222$(hide) rm -f $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list
Ying Wang33360dd2015-01-14 14:23:56 -08002223$(if $(PRIVATE_EXTRA_JAR_ARGS),$(hide) rm -rf $@.res.tmp)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002224$(hide) mv $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq $(PRIVATE_JACK_INTERMEDIATES_DIR).java-source-list
2225$(if $(PRIVATE_JAR_PACKAGES), $(hide) echo unsupported options PRIVATE_JAR_PACKAGES in $@; exit 53)
2226$(if $(PRIVATE_JAR_EXCLUDE_PACKAGES), $(hide) echo unsupported options JAR_EXCLUDE_PACKAGES in $@; exit 53)
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002227$(if $(PRIVATE_JAR_MANIFEST), $(hide) echo unsupported options JAR_MANIFEST in $@; exit 53)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002228endef
2229
Yohann Rousselee572682015-08-18 19:18:18 +02002230# Invoke Jack to compile java source just to check it compiles correctly.
2231#
2232# Some historical notes:
2233# - below we write the list of java files to java-source-list to avoid argument
2234# list length problems with Cygwin
2235# - we filter out duplicate java file names because Jack doesn't like them.
2236define jack-check-java
2237$(hide) rm -f $@
2238$(hide) rm -f $@.java-source-list
2239$(hide) rm -f $@.java-source-list-uniq
2240$(hide) mkdir -p $(dir $@)
2241$(if $(PRIVATE_JACK_INCREMENTAL_DIR),$(hide) mkdir -p $(PRIVATE_JACK_INCREMENTAL_DIR))
2242$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$@.java-source-list)
2243$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
2244 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $@.java-source-list; \
2245fi
2246$(hide) tr ' ' '\n' < $@.java-source-list \
2247 | sort -u > $@.java-source-list-uniq
2248$(hide) if [ -s $@.java-source-list-uniq ] ; then \
Ying Wang85865732016-03-28 18:39:42 -07002249 $(call call-jack) \
Yohann Rousselee572682015-08-18 19:18:18 +02002250 $(strip $(PRIVATE_JACK_FLAGS)) \
Yohann Rousselee572682015-08-18 19:18:18 +02002251 $(addprefix --classpath ,$(strip \
Yohann Rousselae2fc812016-04-21 16:49:10 +02002252 $(call normalize-path-list,$(call reverse-list,$(PRIVATE_STATIC_JACK_LIBRARIES)) $(PRIVATE_JACK_SHARED_LIBRARIES)))) \
Yohann Rousselee572682015-08-18 19:18:18 +02002253 -D jack.import.resource.policy=keep-first \
Yohann Rousselc6383d62016-03-09 17:19:58 +01002254 -D jack.android.min-api-level=$(PRIVATE_JACK_MIN_SDK_VERSION) \
Yohann Rousselee572682015-08-18 19:18:18 +02002255 -D jack.import.type.policy=keep-first \
2256 $(if $(PRIVATE_JACK_INCREMENTAL_DIR),--incremental-folder $(PRIVATE_JACK_INCREMENTAL_DIR)) \
2257 @$@.java-source-list-uniq; \
2258fi
2259touch $@
2260endef
2261
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002262define transform-jar-to-jack
2263 $(hide) mkdir -p $(dir $@)
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002264 $(hide) mkdir -p $@.tmpjill.res
Ying Wang6cce4022015-11-24 14:09:11 -08002265 $(hide) unzip -qo $< -d $@.tmpjill.res
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002266 $(hide) find $@.tmpjill.res -iname "*.class" -delete
Yohann Roussel6528ea32015-10-12 18:02:51 +02002267 $(hide) $(call call-jack) \
Yohann Rousselccfa5c62016-01-19 16:08:34 +01002268 $(PRIVATE_JACK_FLAGS) \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002269 -D jack.import.resource.policy=keep-first \
2270 -D jack.import.type.policy=keep-first \
Yohann Rousselc6383d62016-03-09 17:19:58 +01002271 -D jack.android.min-api-level=$(PRIVATE_JACK_MIN_SDK_VERSION) \
Yohann Rousselccfa5c62016-01-19 16:08:34 +01002272 --import $< \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002273 --import-resource $@.tmpjill.res \
2274 --output-jack $@
2275 $(hide) rm -rf $@.tmpjill.res
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002276endef
2277
Shinichiro Hamaji89b255a2015-11-09 16:47:42 +09002278# Moves $1.tmp to $1 if necessary. This is designed to be used with
2279# .KATI_RESTAT. For kati, this function doesn't update the timestamp
2280# of $1 when $1.tmp is identical to $1 so that ninja won't rebuild
Dan Willemsen1c6dc5b2016-01-06 14:28:36 -08002281# targets which depend on $1.
Shinichiro Hamaji89b255a2015-11-09 16:47:42 +09002282define commit-change-for-toc
2283$(hide) if cmp -s $1.tmp $1 ; then \
2284 rm $1.tmp ; \
2285else \
2286 mv $1.tmp $1 ; \
2287fi
2288endef
Shinichiro Hamaji89b255a2015-11-09 16:47:42 +09002289
Shinichiro Hamajif972a4a2015-12-09 18:06:20 +09002290## Rule to create a table of contents from a .jar file.
Shinichiro Hamaji89b255a2015-11-09 16:47:42 +09002291## Must be called with $(eval).
Shinichiro Hamajif972a4a2015-12-09 18:06:20 +09002292# $(1): A .jar file
Shinichiro Hamaji89b255a2015-11-09 16:47:42 +09002293define _transform-jar-to-toc
2294$1.toc: $1 | $(IJAR)
2295 @echo Generating TOC: $$@
2296 $(hide) $(IJAR) $$< $$@.tmp
2297 $$(call commit-change-for-toc,$$@)
2298endef
2299
2300## Define a rule which generates .jar.toc and mark it as .KATI_RESTAT.
Shinichiro Hamajif972a4a2015-12-09 18:06:20 +09002301# $(1): A .jar file
Shinichiro Hamaji89b255a2015-11-09 16:47:42 +09002302define define-jar-to-toc-rule
Ying Wang427f8c42015-12-04 16:44:03 -08002303$(eval $(call _transform-jar-to-toc,$1))\
Shinichiro Hamaji89b255a2015-11-09 16:47:42 +09002304$(eval .KATI_RESTAT: $1.toc)
2305endef
2306
Shinichiro Hamajif972a4a2015-12-09 18:06:20 +09002307ifeq (,$(TARGET_BUILD_APPS))
2308
2309## Rule to create a table of contents from a .dex file.
2310## Must be called with $(eval).
2311# $(1): The directory which contains classes*.dex files
2312define _transform-dex-to-toc
2313$1/classes.dex.toc: PRIVATE_INPUT_DEX_FILES := $1/classes*.dex
2314$1/classes.dex.toc: $1/classes.dex $(DEXDUMP)
2315 @echo Generating TOC: $$@
David Sehr49fbdd12016-06-24 09:17:04 -07002316 $(hide) ANDROID_LOG_TAGS="*:e" $(DEXDUMP) -l xml $$(PRIVATE_INPUT_DEX_FILES) > $$@.tmp
Shinichiro Hamajif972a4a2015-12-09 18:06:20 +09002317 $$(call commit-change-for-toc,$$@)
2318endef
2319
2320## Define a rule which generates .dex.toc and mark it as .KATI_RESTAT.
2321# $(1): The directory which contains classes*.dex files
2322define define-dex-to-toc-rule
2323$(eval $(call _transform-dex-to-toc,$1))\
2324$(eval .KATI_RESTAT: $1/classes.dex.toc)
2325endef
2326
2327else
2328
2329# Turn off .toc optimization for apps build as we cannot build dexdump.
2330define define-dex-to-toc-rule
2331endef
2332
2333endif # TARGET_BUILD_APPS
2334
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002335
2336# Invoke Jack to compile java from source to jack files without shrink or obfuscation.
2337#
2338# Some historical notes:
2339# - below we write the list of java files to java-source-list to avoid argument
2340# list length problems with Cygwin
2341# - we filter out duplicate java file names because Jack doesn't like them.
2342define java-to-jack
2343$(hide) rm -f $@
2344$(hide) rm -rf $(PRIVATE_JACK_INTERMEDIATES_DIR)
2345$(hide) mkdir -p $(dir $@)
2346$(hide) mkdir -p $(PRIVATE_JACK_INTERMEDIATES_DIR)
Yohann Roussel37822c42015-01-09 10:36:40 +01002347$(if $(PRIVATE_JACK_INCREMENTAL_DIR),$(hide) mkdir -p $(PRIVATE_JACK_INCREMENTAL_DIR))
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002348$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list)
2349$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
2350 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list; \
2351fi
Ying Wang884738e2015-05-08 18:51:00 +00002352$(hide) tr ' ' '\n' < $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list \
Ying Wang4d688792015-10-22 16:30:00 -07002353 | $(NORMALIZE_PATH) | sort -u > $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002354$(if $(PRIVATE_JACK_PROGUARD_FLAGS), \
2355 $(hide) echo -basedirectory $(CURDIR) > $@.flags; \
2356 echo $(PRIVATE_JACK_PROGUARD_FLAGS) >> $@.flags; \
2357)
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002358$(if $(PRIVATE_EXTRA_JAR_ARGS),
2359 $(hide) mkdir -p $@.res.tmp
2360 $(hide) $(call create-empty-package-at,$@.res.tmp.zip)
2361 $(hide) $(call add-java-resources-to,$@.res.tmp.zip)
Yohann Roussel5dd3e1d2015-01-14 16:21:39 +01002362 $(hide) unzip -qo $@.res.tmp.zip -d $@.res.tmp
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002363 $(hide) rm $@.res.tmp.zip)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002364$(hide) if [ -s $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
2365 export tmpEcjArg="@$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq"; \
2366else \
2367 export tmpEcjArg=""; \
2368fi; \
Yohann Roussel6528ea32015-10-12 18:02:51 +02002369$(call call-jack) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002370 $(strip $(PRIVATE_JACK_FLAGS)) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002371 $(if $(NO_OPTIMIZE_DX), \
2372 -D jack.dex.optimize="false") \
2373 $(addprefix --classpath ,$(strip \
Yohann Rousselae2fc812016-04-21 16:49:10 +02002374 $(call normalize-path-list,$(PRIVATE_JACK_SHARED_LIBRARIES)))) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002375 $(addprefix --import ,$(call reverse-list,$(PRIVATE_STATIC_JACK_LIBRARIES))) \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002376 $(if $(PRIVATE_EXTRA_JAR_ARGS),--import-resource $@.res.tmp) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002377 -D jack.import.resource.policy=keep-first \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002378 -D jack.import.type.policy=keep-first \
Yohann Rousselc6383d62016-03-09 17:19:58 +01002379 -D jack.android.min-api-level=$(PRIVATE_JACK_MIN_SDK_VERSION) \
Yohann Roussel37822c42015-01-09 10:36:40 +01002380 $(if $(PRIVATE_JACK_INCREMENTAL_DIR),--incremental-folder $(PRIVATE_JACK_INCREMENTAL_DIR)) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002381 --output-jack $@ \
2382 $(addprefix --config-jarjar ,$(strip $(PRIVATE_JARJAR_RULES))) \
2383 $(if $(PRIVATE_JACK_PROGUARD_FLAGS),--config-proguard $@.flags) \
2384 $$tmpEcjArg \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002385 || ( rm -f $@ ; exit 41 )
2386$(hide) rm -f $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list
2387$(if $(PRIVATE_EXTRA_JAR_ARGS),$(hide) rm -rf $@.res.tmp)
2388$(hide) mv $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq $(PRIVATE_JACK_INTERMEDIATES_DIR).java-source-list
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002389$(if $(PRIVATE_JAR_PACKAGES), $(hide) echo unsupported options PRIVATE_JAR_PACKAGES in $@; exit 53)
2390$(if $(PRIVATE_JAR_EXCLUDE_PACKAGES), $(hide) echo unsupported options JAR_EXCLUDE_PACKAGES in $@; exit 53)
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002391$(if $(PRIVATE_JAR_MANIFEST), $(hide) echo unsupported options JAR_MANIFEST in $@; exit 53)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002392endef
2393
The Android Open Source Project88b60792009-03-03 19:28:42 -08002394define transform-classes.jar-to-emma
2395$(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \
Guang Zhu155afe32010-03-10 15:48:03 -08002396 $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR) \
Guang Zhu9cd3d8c2010-06-15 13:31:25 -07002397 $(addprefix -ix , $(PRIVATE_EMMA_COVERAGE_FILTER))
The Android Open Source Project88b60792009-03-03 19:28:42 -08002398endef
2399
The Android Open Source Project88b60792009-03-03 19:28:42 -08002400# Create a mostly-empty .jar file that we'll add to later.
2401# The MacOS jar tool doesn't like creating empty jar files,
2402# so we need to give it something.
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002403# $(1) package to create
2404define create-empty-package-at
2405@mkdir -p $(dir $(1))
Ying Wangc894e092015-02-26 10:34:33 -08002406$(hide) touch $(dir $(1))zipdummy
2407$(hide) (cd $(dir $(1)) && jar cf $(notdir $(1)) zipdummy)
2408$(hide) zip -qd $(1) zipdummy
2409$(hide) rm $(dir $(1))zipdummy
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002410endef
2411
2412# Create a mostly-empty .jar file that we'll add to later.
2413# The MacOS jar tool doesn't like creating empty jar files,
2414# so we need to give it something.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002415define create-empty-package
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002416$(call create-empty-package-at,$@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08002417endef
2418
2419#TODO: we kinda want to build different asset packages for
2420# different configurations, then combine them later (or something).
2421# Per-locale, etc.
2422# A list of dynamic and static parameters; build layers for
2423# dynamic params that lay over the static ones.
2424#TODO: update the manifest to point to the package file
Dianne Hackborn9bd54042009-05-15 18:01:20 -07002425#Note that the version numbers are given to aapt as simple default
2426#values; applications can override these by explicitly stating
2427#them in their manifest.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002428define add-assets-to-package
Ying Wangc61d5932010-03-10 16:02:42 -08002429$(hide) $(AAPT) package -u $(PRIVATE_AAPT_FLAGS) \
Ying Wang4f1ab922011-03-15 13:19:30 -07002430 $(addprefix -c , $(PRIVATE_PRODUCT_AAPT_CONFIG)) \
Adam Lesinski2d1718a2014-05-09 10:57:48 -07002431 $(addprefix --preferred-density , $(PRIVATE_PRODUCT_AAPT_PREF_CONFIG)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08002432 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
2433 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
2434 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
2435 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
Ying Wangbb9c2302011-04-08 17:27:35 -07002436 $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
2437 $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
Ying Wangf39752e2014-03-20 17:28:57 -07002438 $(if $(filter --product,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --product , $(TARGET_AAPT_CHARACTERISTICS))) \
Colin Crossf37b4552015-07-16 17:15:19 -07002439 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,--version-code $(PLATFORM_SDK_VERSION)) \
Ying Wangd75d8932015-09-19 10:56:35 -07002440 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,--version-name $(APPS_DEFAULT_VERSION_NAME)) \
Jeff Hamiltonbb67d212010-02-05 22:36:42 -06002441 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07002442 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \
Adrian Roos6784cae2015-06-01 18:24:41 -07002443 --skip-symbols-without-default-localization \
The Android Open Source Project88b60792009-03-03 19:28:42 -08002444 -F $@
2445endef
2446
Ying Wang8e20ef62014-06-24 20:01:52 -07002447# We need the extra blank line, so that the command will be on a separate line.
2448# $(1): the ABI name
2449# $(2): the list of shared libraies
2450define _add-jni-shared-libs-to-package-per-abi
2451$(hide) cp $(2) $(dir $@)lib/$(1)
2452
2453endef
2454
Ying Wang1f8964d2015-07-15 18:33:24 -07002455# For apps_only build, don't uncompress/page-align the jni libraries,
2456# because the apk may be run on older platforms that don't support loading jni directly from apk.
2457ifdef TARGET_BUILD_APPS
2458JNI_COMPRESS_FLAGS :=
2459ZIPALIGN_PAGE_ALIGN_FLAGS :=
2460else
2461JNI_COMPRESS_FLAGS := -0
2462ZIPALIGN_PAGE_ALIGN_FLAGS := -p
2463endif
2464
The Android Open Source Project88b60792009-03-03 19:28:42 -08002465define add-jni-shared-libs-to-package
2466$(hide) rm -rf $(dir $@)lib
Ying Wang8e20ef62014-06-24 20:01:52 -07002467$(hide) mkdir -p $(addprefix $(dir $@)lib/,$(PRIVATE_JNI_SHARED_LIBRARIES_ABI))
2468$(foreach abi,$(PRIVATE_JNI_SHARED_LIBRARIES_ABI),\
2469 $(call _add-jni-shared-libs-to-package-per-abi,$(abi),\
2470 $(patsubst $(abi):%,%,$(filter $(abi):%,$(PRIVATE_JNI_SHARED_LIBRARIES)))))
Dan Willemsen48a621c2015-10-29 16:33:05 -07002471$(hide) (cd $(dir $@) && zip -qrX $(JNI_COMPRESS_FLAGS) $(notdir $@) lib)
The Android Open Source Project88b60792009-03-03 19:28:42 -08002472$(hide) rm -rf $(dir $@)lib
2473endef
2474
The Android Open Source Project88b60792009-03-03 19:28:42 -08002475#TODO: update the manifest to point to the dex file
2476define add-dex-to-package
Ying Wangfbc5b9f2016-03-11 10:32:01 -08002477$(call add-dex-to-package-arg,$@)
2478endef
2479
2480# $(1): the package file.
2481define add-dex-to-package-arg
2482$(hide) find $(dir $(PRIVATE_DEX_FILE)) -maxdepth 1 -name "classes*.dex" | sort | xargs zip -qjX $(1)
The Android Open Source Project88b60792009-03-03 19:28:42 -08002483endef
2484
Ying Wang85480622012-08-09 15:20:50 -07002485# Add java resources added by the current module.
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002486# $(1) destination package
2487#
2488define add-java-resources-to
2489$(call dump-words-to-file, $(PRIVATE_EXTRA_JAR_ARGS), $(1).jar-arg-list)
2490$(hide) jar uf $(1) @$(1).jar-arg-list
2491@rm -f $(1).jar-arg-list
2492endef
2493
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002494# Add resources carried by static Jack libraries.
2495#
2496define add-carried-jack-resources
2497 $(hide) if [ -d $(PRIVATE_JACK_INTERMEDIATES_DIR) ] ; then \
Yohann Roussel94f86f82015-11-12 12:21:42 +01002498 find $(PRIVATE_JACK_INTERMEDIATES_DIR) -type f | sort \
Ying Wang3a562a92015-10-13 18:40:37 -07002499 | sed -e "s?^$(PRIVATE_JACK_INTERMEDIATES_DIR)/? -C \"$(PRIVATE_JACK_INTERMEDIATES_DIR)\" \"?" -e "s/$$/\"/" \
2500 > $(dir $@)jack_res_jar_flags; \
2501 if [ -s $(dir $@)jack_res_jar_flags ] ; then \
2502 jar uf $@ @$(dir $@)jack_res_jar_flags; \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002503 fi; \
2504fi
2505endef
2506
Alex Klyubin2cfd1d12016-01-13 10:32:47 -08002507# Returns the minSdkVersion of the specified APK as a decimal number. If the
2508# version is a codename, returns the current platform SDK version (always a
2509# decimal number) instead. If the APK does not specify a minSdkVersion, returns
2510# 0 to match how the Android platform interprets this situation at runtime.
2511#
2512define get-package-min-sdk-version-int
2513$$(($(AAPT) dump badging $(1) 2>&1 | grep '^sdkVersion' || echo "sdkVersion:'0'") \
2514 | cut -d"'" -f2 | \
2515 sed -e s/^$(PLATFORM_VERSION_CODENAME)$$/$(PLATFORM_SDK_VERSION)/)
2516endef
2517
The Android Open Source Project88b60792009-03-03 19:28:42 -08002518# Sign a package using the specified key/cert.
2519#
2520define sign-package
Ying Wangfbc5b9f2016-03-11 10:32:01 -08002521$(call sign-package-arg,$@)
2522endef
2523
2524# $(1): the package file we are signing.
2525define sign-package-arg
2526$(hide) mv $(1) $(1).unsigned
Alex Klyubin9667b182015-12-10 13:38:50 -08002527$(hide) java -Djava.library.path=$(SIGNAPK_JNI_LIBRARY_PATH) -jar $(SIGNAPK_JAR) \
Alex Klyubin2cfd1d12016-01-13 10:32:47 -08002528 --min-sdk-version $(call get-package-min-sdk-version-int,$@.unsigned) \
Ying Wang31df0682012-11-13 10:55:28 -08002529 $(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) \
Ying Wangfbc5b9f2016-03-11 10:32:01 -08002530 $(PRIVATE_ADDITIONAL_CERTIFICATES) $(1).unsigned $(1).signed
2531$(hide) mv $(1).signed $(1)
The Android Open Source Project88b60792009-03-03 19:28:42 -08002532endef
2533
Dmitriy Ivanov13e59652014-07-23 15:27:21 -07002534# 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 -08002535#
2536define align-package
2537$(hide) mv $@ $@.unaligned
Dmitriy Ivanov13e59652014-07-23 15:27:21 -07002538$(hide) $(ZIPALIGN) \
Ying Wang1f8964d2015-07-15 18:33:24 -07002539 -f \
2540 $(ZIPALIGN_PAGE_ALIGN_FLAGS) \
Dmitriy Ivanov13e59652014-07-23 15:27:21 -07002541 4 \
2542 $@.unaligned $@.aligned
The Android Open Source Project88b60792009-03-03 19:28:42 -08002543$(hide) mv $@.aligned $@
2544endef
2545
Dan Willemsen48a621c2015-10-29 16:33:05 -07002546# Remove dynamic timestamps from packages
2547#
2548define remove-timestamps-from-package
2549$(hide) $(ZIPTIME) $@
2550endef
2551
Ying Wang1fb01522015-05-01 14:02:26 -07002552# Uncompress shared libraries embedded in an apk.
2553#
Nick Kralevich5aa02232015-04-17 16:53:15 -07002554define uncompress-shared-libs
Ying Wang1fb01522015-05-01 14:02:26 -07002555$(hide) if unzip -l $@ $(PRIVATE_EMBEDDED_JNI_LIBS) >/dev/null ; then \
2556 rm -rf $(dir $@)uncompressedlibs && mkdir $(dir $@)uncompressedlibs; \
2557 unzip $@ $(PRIVATE_EMBEDDED_JNI_LIBS) -d $(dir $@)uncompressedlibs && \
2558 zip -d $@ 'lib/*.so' && \
Dan Willemsen5c64b4e2015-11-11 18:20:37 -08002559 ( cd $(dir $@)uncompressedlibs && find lib -type f | sort | zip -D -X -0 ../$(notdir $@) -@ ) && \
Ying Wang1fb01522015-05-01 14:02:26 -07002560 rm -rf $(dir $@)uncompressedlibs; \
2561 fi
Nick Kralevich5aa02232015-04-17 16:53:15 -07002562endef
2563
The Android Open Source Project88b60792009-03-03 19:28:42 -08002564# TODO(joeo): If we can ever upgrade to post 3.81 make and get the
2565# new prebuilt rules to work, we should change this to copy the
2566# resources to the out directory and then copy the resources.
2567
Brian Carlstrom78269512010-12-10 12:10:24 -08002568# Note: we intentionally don't clean PRIVATE_CLASS_INTERMEDIATES_DIR
2569# in transform-java-to-classes for the sake of vm-tests.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002570define transform-host-java-to-package
Dan Willemsen057aaea2015-08-14 12:59:50 -07002571@echo "$($(PRIVATE_PREFIX)DISPLAY) Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
Ying Wang015edd22011-01-20 15:01:56 -08002572$(call compile-java,$(HOST_JAVAC),$(PRIVATE_BOOTCLASSPATH))
The Android Open Source Project88b60792009-03-03 19:28:42 -08002573endef
2574
2575###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08002576## Commands for copying files
2577###########################################################
2578
2579# Define a rule to copy a header. Used via $(eval) by copy_headers.make.
2580# $(1): source header
2581# $(2): destination header
2582define copy-one-header
2583$(2): $(1)
2584 @echo "Header: $$@"
2585 $$(copy-file-to-new-target-with-cp)
2586endef
2587
2588# Define a rule to copy a file. For use via $(eval).
2589# $(1): source file
2590# $(2): destination file
2591define copy-one-file
Dan Willemsenf1a98af2016-02-29 12:45:18 -08002592$(2): $(1)
The Android Open Source Project88b60792009-03-03 19:28:42 -08002593 @echo "Copy: $$@"
2594 $$(copy-file-to-target)
2595endef
2596
Joe Onoratoe44705a2012-05-17 17:12:04 -07002597# Copies many files.
2598# $(1): The files to copy. Each entry is a ':' separated src:dst pair
2599# Evaluates to the list of the dst files (ie suitable for a dependency list)
2600define copy-many-files
2601$(foreach f, $(1), $(strip \
2602 $(eval _cmf_tuple := $(subst :, ,$(f))) \
2603 $(eval _cmf_src := $(word 1,$(_cmf_tuple))) \
2604 $(eval _cmf_dest := $(word 2,$(_cmf_tuple))) \
2605 $(eval $(call copy-one-file,$(_cmf_src),$(_cmf_dest))) \
2606 $(_cmf_dest)))
2607endef
2608
Ying Wang3ceecfa2012-05-14 14:39:00 -07002609# Copy the file only if it's a well-formed xml file. For use via $(eval).
2610# $(1): source file
2611# $(2): destination file, must end with .xml.
2612define copy-xml-file-checked
Dan Willemsen7f016152016-02-29 17:52:39 -08002613$(2): $(1)
Ying Wang3ceecfa2012-05-14 14:39:00 -07002614 @echo "Copy xml: $$@"
2615 $(hide) xmllint $$< >/dev/null # Don't print the xml file to stdout.
2616 $$(copy-file-to-target)
2617endef
2618
The Android Open Source Project88b60792009-03-03 19:28:42 -08002619# The -t option to acp and the -p option to cp is
2620# required for OSX. OSX has a ridiculous restriction
2621# where it's an error for a .a file's modification time
2622# to disagree with an internal timestamp, and this
2623# macro is used to install .a files (among other things).
2624
2625# Copy a single file from one place to another,
2626# preserving permissions and overwriting any existing
2627# file.
Dan Willemsenf1a98af2016-02-29 12:45:18 -08002628# When we used acp, it could not handle high resolution timestamps
2629# on file systems like ext4. Because of that, '-t' option was disabled
2630# and copy-file-to-target was identical to copy-file-to-new-target.
2631# Keep the behavior until we audit and ensure that switching this back
2632# won't break anything.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002633define copy-file-to-target
2634@mkdir -p $(dir $@)
Dan Willemsen3545eeb2016-02-29 12:45:18 -08002635$(hide) rm -f $@
Dan Willemsenf1a98af2016-02-29 12:45:18 -08002636$(hide) cp $< $@
The Android Open Source Project88b60792009-03-03 19:28:42 -08002637endef
2638
2639# The same as copy-file-to-target, but use the local
2640# cp command instead of acp.
2641define copy-file-to-target-with-cp
2642@mkdir -p $(dir $@)
Dan Willemsen3545eeb2016-02-29 12:45:18 -08002643$(hide) rm -f $@
2644$(hide) cp -p $< $@
The Android Open Source Project88b60792009-03-03 19:28:42 -08002645endef
2646
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07002647# The same as copy-file-to-target, but use the zipalign tool to do so.
2648define copy-file-to-target-with-zipalign
2649@mkdir -p $(dir $@)
Dan Willemsen3545eeb2016-02-29 12:45:18 -08002650$(hide) rm -f $@
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07002651$(hide) $(ZIPALIGN) -f 4 $< $@
2652endef
2653
Doug Zongker1046d202009-08-06 13:02:19 -07002654# The same as copy-file-to-target, but strip out "# comment"-style
2655# comments (for config files and such).
2656define copy-file-to-target-strip-comments
2657@mkdir -p $(dir $@)
Dan Willemsen3545eeb2016-02-29 12:45:18 -08002658$(hide) rm -f $@
Doug Zongker1046d202009-08-06 13:02:19 -07002659$(hide) sed -e 's/#.*$$//' -e 's/[ \t]*$$//' -e '/^$$/d' < $< > $@
2660endef
2661
The Android Open Source Project88b60792009-03-03 19:28:42 -08002662# The same as copy-file-to-target, but don't preserve
2663# the old modification time.
2664define copy-file-to-new-target
2665@mkdir -p $(dir $@)
Dan Willemsen3545eeb2016-02-29 12:45:18 -08002666$(hide) rm -f $@
Dan Willemsenf1a98af2016-02-29 12:45:18 -08002667$(hide) cp $< $@
The Android Open Source Project88b60792009-03-03 19:28:42 -08002668endef
2669
2670# The same as copy-file-to-new-target, but use the local
2671# cp command instead of acp.
2672define copy-file-to-new-target-with-cp
2673@mkdir -p $(dir $@)
Dan Willemsen3545eeb2016-02-29 12:45:18 -08002674$(hide) rm -f $@
2675$(hide) cp $< $@
The Android Open Source Project88b60792009-03-03 19:28:42 -08002676endef
2677
2678# Copy a prebuilt file to a target location.
2679define transform-prebuilt-to-target
Alexey Polyudov8b540fd2016-06-24 11:13:34 -07002680@echo "$($(PRIVATE_PREFIX)DISPLAY) Prebuilt: $(PRIVATE_MODULE) ($@)"
The Android Open Source Project88b60792009-03-03 19:28:42 -08002681$(copy-file-to-target)
2682endef
2683
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07002684# Copy a prebuilt file to a target location, using zipalign on it.
2685define transform-prebuilt-to-target-with-zipalign
Alexey Polyudov8b540fd2016-06-24 11:13:34 -07002686@echo "$($(PRIVATE_PREFIX)DISPLAY) Prebuilt APK: $(PRIVATE_MODULE) ($@)"
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07002687$(copy-file-to-target-with-zipalign)
2688endef
2689
Doug Zongker1046d202009-08-06 13:02:19 -07002690# Copy a prebuilt file to a target location, stripping "# comment" comments.
2691define transform-prebuilt-to-target-strip-comments
Alexey Polyudov8b540fd2016-06-24 11:13:34 -07002692@echo "$($(PRIVATE_PREFIX)DISPLAY) Prebuilt: $(PRIVATE_MODULE) ($@)"
Doug Zongker1046d202009-08-06 13:02:19 -07002693$(copy-file-to-target-strip-comments)
2694endef
2695
Ying Wangc45a47b2015-04-08 12:24:37 -07002696# Copy a list of files/directories to target location, with sub dir structure preserved.
2697# For example $(HOST_OUT_EXECUTABLES)/aapt -> $(staging)/bin/aapt .
2698# $(1): the source list of files/directories.
2699# $(2): the path prefix to strip. In the above example it would be $(HOST_OUT).
2700# $(3): the target location.
2701define copy-files-with-structure
2702$(foreach t,$(1),\
2703 $(eval s := $(patsubst $(2)%,%,$(t)))\
2704 $(hide) mkdir -p $(dir $(3)/$(s)); cp -Rf $(t) $(3)/$(s)$(newline))
2705endef
2706
Colin Cross744d33b2016-07-14 16:02:57 -07002707# Define a rule to create a symlink to a file.
2708# $(1): full path to source
2709# $(2): source (may be relative)
2710# $(3): full path to destination
2711define symlink-file
2712$(eval $(_symlink-file))
2713endef
2714
2715# Order-only dependency because make/ninja will follow the link when checking
2716# the timestamp, so the file must exist
2717define _symlink-file
2718$(3): | $(1)
2719 @echo "Symlink: $$@ -> $(2)"
2720 @mkdir -p $(dir $$@)
2721 @rm -rf $$@
2722 $(hide) ln -sf $(2) $$@
2723endef
2724
Dan Willemsendb16dd22016-05-16 14:41:49 -07002725###########################################################
Ying Wang3b2bdf12010-02-01 09:51:23 -08002726## Commands to call Proguard
2727###########################################################
Ying Wang3b2bdf12010-02-01 09:51:23 -08002728define transform-jar-to-proguard
Ying Wang7311a342013-08-21 18:32:49 -07002729@echo Proguard: $@
Mihail Dumitrescu4df82b32014-02-07 15:18:59 +00002730$(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS) \
2731 $(addprefix -injars , $(PRIVATE_EXTRA_INPUT_JAR))
Ying Wang3b2bdf12010-02-01 09:51:23 -08002732endef
2733
Ying Wang3b2bdf12010-02-01 09:51:23 -08002734###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08002735## Stuff source generated from one-off tools
2736###########################################################
2737
2738define transform-generated-source
Alexey Polyudov8b540fd2016-06-24 11:13:34 -07002739@echo "$($(PRIVATE_PREFIX)DISPLAY) Generated: $(PRIVATE_MODULE) <= $<"
The Android Open Source Project88b60792009-03-03 19:28:42 -08002740@mkdir -p $(dir $@)
2741$(hide) $(PRIVATE_CUSTOM_TOOL)
2742endef
2743
2744
2745###########################################################
2746## Assertions about attributes of the target
2747###########################################################
2748
2749# $(1): The file to check
2750ifndef get-file-size
2751$(error HOST_OS must define get-file-size)
2752endif
2753
Doug Zongker4647f122009-07-02 09:00:54 -07002754# Convert a partition data size (eg, as reported in /proc/mtd) to the
2755# size of the image used to flash that partition (which includes a
Lars Svensson9cb8c282010-12-06 15:24:58 +01002756# spare area for each page).
Doug Zongker4647f122009-07-02 09:00:54 -07002757# $(1): the partition data size
2758define image-size-from-data-size
Ying Wang4a2ecaf2011-02-09 17:24:27 -08002759$(strip $(eval _isfds_value := $$(shell echo $$$$(($(1) / $(BOARD_NAND_PAGE_SIZE) * \
2760 ($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE))))))\
2761$(if $(filter 0, $(_isfds_value)),$(shell echo $$(($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE)))),$(_isfds_value))\
2762$(eval _isfds_value :=))
Doug Zongker4647f122009-07-02 09:00:54 -07002763endef
2764
2765# $(1): The file(s) to check (often $@)
JP Abgrall0ed7cec2014-06-16 14:19:36 -07002766# $(2): The maximum total image size, in decimal bytes.
2767# Make sure to take into account any reserved space needed for the FS.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002768#
2769# If $(2) is empty, evaluates to "true"
2770#
2771# Reserve bad blocks. Make sure that MAX(1% of partition size, 2 blocks)
2772# is left over after the image has been flashed. Round the 1% up to the
2773# next whole flash block size.
2774define assert-max-file-size
2775$(if $(2), \
Doug Zongker742fa572009-07-08 12:09:04 -07002776 size=$$(for i in $(1); do $(call get-file-size,$$i); echo +; done; echo 0); \
2777 total=$$(( $$( echo "$$size" ) )); \
Doug Zongker4647f122009-07-02 09:00:54 -07002778 printname=$$(echo -n "$(1)" | tr " " +); \
Doug Zongker4647f122009-07-02 09:00:54 -07002779 img_blocksize=$(call image-size-from-data-size,$(BOARD_FLASH_BLOCK_SIZE)); \
2780 twoblocks=$$((img_blocksize * 2)); \
2781 onepct=$$((((($(2) / 100) - 1) / img_blocksize + 1) * img_blocksize)); \
JP Abgrall0ed7cec2014-06-16 14:19:36 -07002782 reserve=$$((twoblocks > onepct ? twoblocks : onepct)); \
Doug Zongker4647f122009-07-02 09:00:54 -07002783 maxsize=$$(($(2) - reserve)); \
Ying Wang99bcbeb2011-12-02 10:34:45 -08002784 echo "$$printname maxsize=$$maxsize blocksize=$$img_blocksize total=$$total reserve=$$reserve"; \
Doug Zongker4647f122009-07-02 09:00:54 -07002785 if [ "$$total" -gt "$$maxsize" ]; then \
2786 echo "error: $$printname too large ($$total > [$(2) - $$reserve])"; \
2787 false; \
Doug Zongker742fa572009-07-08 12:09:04 -07002788 elif [ "$$total" -gt $$((maxsize - 32768)) ]; then \
Doug Zongker4647f122009-07-02 09:00:54 -07002789 echo "WARNING: $$printname approaching size limit ($$total now; limit $$maxsize)"; \
The Android Open Source Project88b60792009-03-03 19:28:42 -08002790 fi \
2791 , \
2792 true \
2793 )
2794endef
2795
Doug Zongker8510a1e2009-08-07 16:38:08 -07002796# Like assert-max-file-size, but the second argument is a partition
2797# size, which we'll convert to a max image size before checking it
2798# against the files.
2799#
2800# $(1): The file(s) to check (often $@)
2801# $(2): The partition size.
2802define assert-max-image-size
2803$(if $(2), \
JP Abgrall0ed7cec2014-06-16 14:19:36 -07002804 $(call assert-max-file-size,$(1),$(call image-size-from-data-size,$(2))))
Doug Zongker8510a1e2009-08-07 16:38:08 -07002805endef
2806
Doug Zongkere01100c2009-06-19 17:12:18 -07002807
2808###########################################################
2809## Define device-specific radio files
2810###########################################################
Ying Wang94de1eb2013-07-26 12:19:20 -07002811INSTALLED_RADIOIMAGE_TARGET :=
Doug Zongkere01100c2009-06-19 17:12:18 -07002812
2813# Copy a radio image file to the output location, and add it to
2814# INSTALLED_RADIOIMAGE_TARGET.
2815# $(1): filename
2816define add-radio-file
Doug Zongker14833602010-02-02 13:12:04 -08002817 $(eval $(call add-radio-file-internal,$(1),$(notdir $(1))))
Doug Zongkere01100c2009-06-19 17:12:18 -07002818endef
2819define add-radio-file-internal
Doug Zongker14833602010-02-02 13:12:04 -08002820INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
Dan Willemsen7f016152016-02-29 17:52:39 -08002821$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1)
Doug Zongkere01100c2009-06-19 17:12:18 -07002822 $$(transform-prebuilt-to-target)
2823endef
2824
Doug Zongker9296f092012-03-20 16:42:22 -07002825# Version of add-radio-file that also arranges for the version of the
2826# file to be checked against the contents of
2827# $(TARGET_BOARD_INFO_FILE).
2828# $(1): filename
2829# $(2): name of version variable in board-info (eg, "version-baseband")
2830define add-radio-file-checked
2831 $(eval $(call add-radio-file-checked-internal,$(1),$(notdir $(1)),$(2)))
2832endef
2833define add-radio-file-checked-internal
2834INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
2835BOARD_INFO_CHECK += $(3):$(LOCAL_PATH)/$(1)
Dan Willemsen7f016152016-02-29 17:52:39 -08002836$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1)
Doug Zongker9296f092012-03-20 16:42:22 -07002837 $$(transform-prebuilt-to-target)
2838endef
2839
Doug Zongkere01100c2009-06-19 17:12:18 -07002840
The Android Open Source Project88b60792009-03-03 19:28:42 -08002841###########################################################
Joe Onorato899e62a2010-02-04 17:37:21 -08002842# Override the package defined in $(1), setting the
2843# variables listed below differently.
2844#
2845# $(1): The makefile to override (relative to the source
2846# tree root)
2847# $(2): Old LOCAL_PACKAGE_NAME value.
2848# $(3): New LOCAL_PACKAGE_NAME value.
Ying Wang3dae0ee2010-09-02 15:41:01 -07002849# $(4): New LOCAL_MANIFEST_PACKAGE_NAME value.
2850# $(5): New LOCAL_CERTIFICATE value.
2851# $(6): New LOCAL_INSTRUMENTATION_FOR value.
2852# $(7): New LOCAL_MANIFEST_INSTRUMENTATION_FOR value.
Joe Onorato899e62a2010-02-04 17:37:21 -08002853#
2854# Note that LOCAL_PACKAGE_OVERRIDES is NOT cleared in
2855# clear_vars.mk.
2856###########################################################
2857define inherit-package
Ying Wang3dae0ee2010-09-02 15:41:01 -07002858 $(eval $(call inherit-package-internal,$(1),$(2),$(3),$(4),$(5),$(6),$(7)))
Joe Onorato899e62a2010-02-04 17:37:21 -08002859endef
2860
2861define inherit-package-internal
2862 LOCAL_PACKAGE_OVERRIDES \
Ying Wang3dae0ee2010-09-02 15:41:01 -07002863 := $(strip $(1))||$(strip $(2))||$(strip $(3))||$(strip $(4))||&&$(strip $(5))||&&$(strip $(6))||&&$(strip $(7)) $(LOCAL_PACKAGE_OVERRIDES)
Joe Onorato899e62a2010-02-04 17:37:21 -08002864 include $(1)
2865 LOCAL_PACKAGE_OVERRIDES \
2866 := $(wordlist 1,$(words $(LOCAL_PACKAGE_OVERRIDES)), $(LOCAL_PACKAGE_OVERRIDES))
2867endef
2868
2869# To be used with inherit-package above
2870# Evalutes to true if the package was overridden
2871define set-inherited-package-variables
2872$(strip $(call set-inherited-package-variables-internal))
2873endef
2874
2875define keep-or-override
2876$(eval $(1) := $(if $(2),$(2),$($(1))))
2877endef
2878
2879define set-inherited-package-variables-internal
2880 $(eval _o := $(subst ||, ,$(lastword $(LOCAL_PACKAGE_OVERRIDES))))
2881 $(eval _n := $(subst ||, ,$(firstword $(LOCAL_PACKAGE_OVERRIDES))))
2882 $(if $(filter $(word 2,$(_n)),$(LOCAL_PACKAGE_NAME)), \
2883 $(eval LOCAL_PACKAGE_NAME := $(word 3,$(_o))) \
2884 $(eval LOCAL_MANIFEST_PACKAGE_NAME := $(word 4,$(_o))) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07002885 $(call keep-or-override,LOCAL_CERTIFICATE,$(patsubst &&%,%,$(word 5,$(_o)))) \
2886 $(call keep-or-override,LOCAL_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 6,$(_o)))) \
2887 $(call keep-or-override,LOCAL_MANIFEST_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 7,$(_o)))) \
Joe Onorato899e62a2010-02-04 17:37:21 -08002888 $(eval LOCAL_OVERRIDES_PACKAGES := $(sort $(LOCAL_OVERRIDES_PACKAGES) $(word 2,$(_o)))) \
2889 true \
2890 ,)
2891endef
2892
Ying Wang000e89a2012-04-30 15:48:27 -07002893###########################################################
Ying Wangc065da22012-11-14 15:57:07 -08002894## API Check
2895###########################################################
2896
2897# eval this to define a rule that runs apicheck.
2898#
2899# Args:
2900# $(1) target
2901# $(2) stable api file
2902# $(3) api file to be tested
Hui Shuec21c582014-03-13 16:21:08 -07002903# $(4) stable removed api file
Hui Shue8af17e2014-02-21 14:18:19 -08002904# $(5) removed api file to be tested
2905# $(6) arguments for apicheck
2906# $(7) command to run if apicheck failed
2907# $(8) target dependent on this api check
2908# $(9) additional dependencies
Ying Wangc065da22012-11-14 15:57:07 -08002909define check-api
Hui Shuec21c582014-03-13 16:21:08 -07002910$(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(strip $(1))-timestamp: $(2) $(3) $(4) $(APICHECK) $(9)
Ying Wangc065da22012-11-14 15:57:07 -08002911 @echo "Checking API:" $(1)
Hui Shue8af17e2014-02-21 14:18:19 -08002912 $(hide) ( $(APICHECK_COMMAND) $(6) $(2) $(3) $(4) $(5) || ( $(7) ; exit 38 ) )
Ying Wangc065da22012-11-14 15:57:07 -08002913 $(hide) mkdir -p $$(dir $$@)
2914 $(hide) touch $$@
Hui Shue8af17e2014-02-21 14:18:19 -08002915$(8): $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(strip $(1))-timestamp
Ying Wangc065da22012-11-14 15:57:07 -08002916endef
2917
Ying Wang63d94fa2012-12-13 18:23:01 -08002918## Whether to build from source if prebuilt alternative exists
2919###########################################################
2920# $(1): module name
2921# $(2): LOCAL_PATH
2922# Expands to empty string if not from source.
2923ifeq (true,$(ANDROID_BUILD_FROM_SOURCE))
2924define if-build-from-source
2925true
2926endef
2927else
2928define if-build-from-source
2929$(if $(filter $(ANDROID_NO_PREBUILT_MODULES),$(1))$(filter \
2930 $(addsuffix %,$(ANDROID_NO_PREBUILT_PATHS)),$(2)),true)
2931endef
2932endif
2933
2934# Include makefile $(1) if build from source for module $(2)
2935# $(1): the makefile to include
2936# $(2): module name
2937# $(3): LOCAL_PATH
2938define include-if-build-from-source
2939$(if $(call if-build-from-source,$(2),$(3)),$(eval include $(1)))
2940endef
2941
Ying Wanga6a6c352014-09-26 10:41:27 -07002942# Return the arch for the source file of a prebuilt
Chih-Wei Huang74ccefb2015-10-05 00:28:47 +08002943# Return "none" if no matching arch found and return empty
2944# if the input is empty, so the result can be passed to
Ying Wanga6a6c352014-09-26 10:41:27 -07002945# LOCAL_MODULE_TARGET_ARCH.
Ying Wangc0adfb72014-02-27 14:10:53 -08002946# $(1) the list of archs supported by the prebuilt
2947define get-prebuilt-src-arch
2948$(strip $(if $(filter $(TARGET_ARCH),$(1)),$(TARGET_ARCH),\
Chih-Wei Huang74ccefb2015-10-05 00:28:47 +08002949 $(if $(filter $(TARGET_2ND_ARCH),$(1)),$(TARGET_2ND_ARCH),$(if $(1),none))))
Ying Wangc0adfb72014-02-27 14:10:53 -08002950endef
2951
Dan Willemsen3bf15e72016-07-25 16:03:53 -07002952# ###############################################################
2953# Set up statistics gathering
2954# ###############################################################
2955STATS.MODULE_TYPE := \
2956 HOST_STATIC_LIBRARY \
2957 HOST_SHARED_LIBRARY \
2958 STATIC_LIBRARY \
2959 SHARED_LIBRARY \
2960 EXECUTABLE \
2961 HOST_EXECUTABLE \
2962 PACKAGE \
2963 PHONY_PACKAGE \
2964 HOST_PREBUILT \
2965 PREBUILT \
2966 MULTI_PREBUILT \
2967 JAVA_LIBRARY \
2968 STATIC_JAVA_LIBRARY \
2969 HOST_JAVA_LIBRARY \
2970 DROIDDOC \
2971 COPY_HEADERS \
2972 NATIVE_TEST \
2973 NATIVE_BENCHMARK \
2974 HOST_NATIVE_TEST \
2975 FUZZ_TEST \
2976 HOST_FUZZ_TEST \
2977 STATIC_TEST_LIBRARY \
2978 HOST_STATIC_TEST_LIBRARY \
2979 NOTICE_FILE \
2980 HOST_DALVIK_JAVA_LIBRARY \
2981 HOST_DALVIK_STATIC_JAVA_LIBRARY \
2982 base_rules
2983
2984$(foreach $(s),$(STATS.MODULE_TYPE),$(eval STATS.MODULE_TYPE.$(s) :=))
2985define record-module-type
2986$(strip $(if $(LOCAL_RECORDED_MODULE_TYPE),,
2987 $(if $(filter-out $(SOONG_ANDROID_MK),$(LOCAL_MODULE_MAKEFILE)),
2988 $(if $(filter $(1),$(STATS.MODULE_TYPE)),
2989 $(eval LOCAL_RECORDED_MODULE_TYPE := true)
2990 $(eval STATS.MODULE_TYPE.$(1) += 1),
2991 $(error Invalid module type: $(1))))))
2992endef
2993
Ying Wangc065da22012-11-14 15:57:07 -08002994###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08002995## Other includes
2996###########################################################
2997
2998# -----------------------------------------------------------------
2999# Rules and functions to help copy important files to DIST_DIR
3000# when requested.
3001include $(BUILD_SYSTEM)/distdir.mk
3002
Marie Lennerhagen9e5efce2010-10-20 13:41:59 +02003003# Include any vendor specific definitions.mk file
3004-include $(TOPDIR)vendor/*/build/core/definitions.mk
Andrew Boie388c04d2014-10-28 08:32:11 -07003005-include $(TOPDIR)device/*/build/core/definitions.mk
Lee Campbell04ba3122015-08-20 15:39:56 -07003006-include $(TOPDIR)product/*/build/core/definitions.mk
Marie Lennerhagen9e5efce2010-10-20 13:41:59 +02003007
The Android Open Source Project88b60792009-03-03 19:28:42 -08003008# broken:
3009# $(foreach file,$^,$(if $(findstring,.a,$(suffix $file)),-l$(file),$(file)))
3010
3011###########################################################
3012## Misc notes
3013###########################################################
3014
3015#DEPDIR = .deps
3016#df = $(DEPDIR)/$(*F)
3017
3018#SRCS = foo.c bar.c ...
3019
3020#%.o : %.c
3021# @$(MAKEDEPEND); \
3022# cp $(df).d $(df).P; \
3023# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
3024# -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \
3025# rm -f $(df).d
3026# $(COMPILE.c) -o $@ $<
3027
3028#-include $(SRCS:%.c=$(DEPDIR)/%.P)
3029
3030
3031#%.o : %.c
3032# $(COMPILE.c) -MD -o $@ $<
3033# @cp $*.d $*.P; \
3034# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
3035# -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \
3036# rm -f $*.d