blob: 2db4e1b540282f495aefda5e47c0b98981ff7a38 [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001#
2# Copyright (C) 2008 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17##
18## Common build system definitions. Mostly standard
19## commands for building various types of targets, which
20## are used by others to construct the final targets.
21##
22
23# These are variables we use to collect overall lists
24# of things being processed.
25
26# Full paths to all of the documentation
27ALL_DOCS:=
28
29# The short names of all of the targets in the system.
30# For each element of ALL_MODULES, two other variables
31# are defined:
32# $(ALL_MODULES.$(target)).BUILT
33# $(ALL_MODULES.$(target)).INSTALLED
34# The BUILT variable contains LOCAL_BUILT_MODULE for that
35# target, and the INSTALLED variable contains the LOCAL_INSTALLED_MODULE.
36# Some targets may have multiple files listed in the BUILT and INSTALLED
37# sub-variables.
38ALL_MODULES:=
39
40# Full paths to targets that should be added to the "make droid"
41# set of installed targets.
42ALL_DEFAULT_INSTALLED_MODULES:=
43
The Android Open Source Project88b60792009-03-03 19:28:42 -080044# The list of tags that have been defined by
45# LOCAL_MODULE_TAGS. Each word in this variable maps
46# to a corresponding ALL_MODULE_TAGS.<tagname> variable
47# that contains all of the INSTALLED_MODULEs with that tag.
48ALL_MODULE_TAGS:=
49
50# Similar to ALL_MODULE_TAGS, but contains the short names
51# of all targets for a particular tag. The top-level variable
52# won't have the list of tags; ust ALL_MODULE_TAGS to get
53# the list of all known tags. (This means that this variable
54# will always be empty; it's just here as a placeholder for
55# its sub-variables.)
56ALL_MODULE_NAME_TAGS:=
57
58# Full paths to all prebuilt files that will be copied
59# (used to make the dependency on acp)
60ALL_PREBUILT:=
61
62# Full path to all files that are made by some tool
63ALL_GENERATED_SOURCES:=
64
65# Full path to all asm, C, C++, lex and yacc generated C files.
66# These all have an order-only dependency on the copied headers
67ALL_C_CPP_ETC_OBJECTS:=
68
Iliyan Malchevb375e712011-03-08 16:19:48 -080069# The list of dynamic binaries that haven't been stripped/compressed/etc.
The Android Open Source Project88b60792009-03-03 19:28:42 -080070ALL_ORIGINAL_DYNAMIC_BINARIES:=
71
72# These files go into the SDK
73ALL_SDK_FILES:=
74
75# Files for dalvik. This is often build without building the rest of the OS.
76INTERNAL_DALVIK_MODULES:=
77
78# All findbugs xml files
79ALL_FINDBUGS_FILES:=
80
Ying Wangfd626f22011-12-12 12:57:38 -080081# GPL module license files
82ALL_GPL_MODULE_LICENSE_FILES:=
83
Ying Wang9485a572013-02-22 14:32:30 -080084# Target and host installed module's dependencies on shared libraries.
Ying Wangd6b1d612013-04-15 17:32:21 -070085# They are list of "<module_name>:<installed_file>:lib1,lib2...".
Ying Wang9485a572013-02-22 14:32:30 -080086TARGET_DEPENDENCIES_ON_SHARED_LIBRARIES :=
Ying Wang966c1e02014-05-20 14:43:51 -070087$(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_DEPENDENCIES_ON_SHARED_LIBRARIES :=
Ying Wang9485a572013-02-22 14:32:30 -080088HOST_DEPENDENCIES_ON_SHARED_LIBRARIES :=
Ying Wang966c1e02014-05-20 14:43:51 -070089$(HOST_2ND_ARCH_VAR_PREFIX)HOST_DEPENDENCIES_ON_SHARED_LIBRARIES :=
Ying Wang9485a572013-02-22 14:32:30 -080090
Ying Wangae25ec12012-06-19 10:40:37 -070091# Generated class file names for Android resource.
92# They are escaped and quoted so can be passed safely to a bash command.
93ANDROID_RESOURCE_GENERATED_CLASSES := 'R.class' 'R$$*.class' 'Manifest.class' 'Manifest$$*.class'
94
The Android Open Source Project88b60792009-03-03 19:28:42 -080095###########################################################
96## Debugging; prints a variable list to stdout
97###########################################################
98
99# $(1): variable name list, not variable values
100define print-vars
101$(foreach var,$(1), \
102 $(info $(var):) \
103 $(foreach word,$($(var)), \
104 $(info $(space)$(space)$(word)) \
105 ) \
106 )
107endef
108
109###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700110## Evaluates to true if the string contains the word true,
111## and empty otherwise
112## $(1): a var to test
113###########################################################
114
115define true-or-empty
116$(filter true, $(1))
117endef
118
119
120###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800121## Retrieve the directory of the current makefile
Ying Wang3bbfddd2014-03-01 15:32:04 -0800122## Must be called before including any other makefile!!
The Android Open Source Project88b60792009-03-03 19:28:42 -0800123###########################################################
124
125# Figure out where we are.
126define my-dir
Dave Bortb3926412009-05-19 16:12:22 -0700127$(strip \
Ying Wang68f1c772012-04-23 21:29:18 -0700128 $(eval LOCAL_MODULE_MAKEFILE := $$(lastword $$(MAKEFILE_LIST))) \
Ying Wang3bbfddd2014-03-01 15:32:04 -0800129 $(if $(filter $(BUILD_SYSTEM)/% $(OUT_DIR)/%,$(LOCAL_MODULE_MAKEFILE)), \
130 $(error my-dir must be called before including any other makefile.) \
Dave Bortb3926412009-05-19 16:12:22 -0700131 , \
Ying Wang68f1c772012-04-23 21:29:18 -0700132 $(patsubst %/,%,$(dir $(LOCAL_MODULE_MAKEFILE))) \
Dave Bortb3926412009-05-19 16:12:22 -0700133 ) \
134 )
The Android Open Source Project88b60792009-03-03 19:28:42 -0800135endef
136
137###########################################################
138## Retrieve a list of all makefiles immediately below some directory
139###########################################################
140
141define all-makefiles-under
142$(wildcard $(1)/*/Android.mk)
143endef
144
145###########################################################
146## Look under a directory for makefiles that don't have parent
147## makefiles.
148###########################################################
149
150# $(1): directory to search under
151# Ignores $(1)/Android.mk
152define first-makefiles-under
C. Sean Youngcf469982015-06-09 12:35:45 -0500153$(shell build/tools/findleaves.py $(FIND_LEAVES_EXCLUDES) \
Joe Onoratodc1a7282009-08-04 15:58:26 -0400154 --mindepth=2 $(1) Android.mk)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800155endef
156
157###########################################################
158## Retrieve a list of all makefiles immediately below your directory
Ying Wang3bbfddd2014-03-01 15:32:04 -0800159## Must be called before including any other makefile!!
The Android Open Source Project88b60792009-03-03 19:28:42 -0800160###########################################################
161
162define all-subdir-makefiles
163$(call all-makefiles-under,$(call my-dir))
164endef
165
166###########################################################
167## Look in the named list of directories for makefiles,
168## relative to the current directory.
Ying Wang3bbfddd2014-03-01 15:32:04 -0800169## Must be called before including any other makefile!!
The Android Open Source Project88b60792009-03-03 19:28:42 -0800170###########################################################
171
172# $(1): List of directories to look for under this directory
173define all-named-subdir-makefiles
Chih-Wei Huange73c4bb2011-01-16 18:31:29 +0800174$(wildcard $(addsuffix /Android.mk, $(addprefix $(call my-dir)/,$(1))))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800175endef
176
177###########################################################
Dan Willemsen57a64e02015-10-12 15:26:52 -0700178## Find all of the directories under the named directories with
179## the specified name.
180## Meant to be used like:
181## INC_DIRS := $(call all-named-dirs-under,inc,.)
182###########################################################
183
184define all-named-dirs-under
185$(call find-subdir-files,$(2) -type d -name "$(1)")
186endef
187
188###########################################################
189## Find all the directories under the current directory that
190## haves name that match $(1)
191###########################################################
192
193define all-subdir-named-dirs
194$(call all-named-dirs-under,$(1),.)
195endef
196
197###########################################################
198## Find all of the files under the named directories with
199## the specified name.
200## Meant to be used like:
201## SRC_FILES := $(call all-named-files-under,*.h,src tests)
202###########################################################
203
204define all-named-files-under
205$(call find-files-in-subdirs,$(LOCAL_PATH),"$(1)",$(2))
206endef
207
208###########################################################
209## Find all of the files under the current directory with
210## the specified name.
211###########################################################
212
213define all-subdir-named-files
214$(call all-named-files-under,$(1),.)
215endef
216
217###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800218## Find all of the java files under the named directories.
219## Meant to be used like:
220## SRC_FILES := $(call all-java-files-under,src tests)
221###########################################################
222
223define all-java-files-under
Dan Willemsen57a64e02015-10-12 15:26:52 -0700224$(call all-named-files-under,*.java,$(1))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800225endef
226
227###########################################################
228## Find all of the java files from here. Meant to be used like:
229## SRC_FILES := $(call all-subdir-java-files)
230###########################################################
231
232define all-subdir-java-files
233$(call all-java-files-under,.)
234endef
235
236###########################################################
237## Find all of the c files under the named directories.
238## Meant to be used like:
239## SRC_FILES := $(call all-c-files-under,src tests)
240###########################################################
241
242define all-c-files-under
Dan Willemsen57a64e02015-10-12 15:26:52 -0700243$(call all-named-files-under,*.c,$(1))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800244endef
245
246###########################################################
247## Find all of the c files from here. Meant to be used like:
248## SRC_FILES := $(call all-subdir-c-files)
249###########################################################
250
251define all-subdir-c-files
252$(call all-c-files-under,.)
253endef
254
255###########################################################
Dan Willemsend7b9ac72015-09-29 16:26:28 -0700256## Find all of the cpp files under the named directories.
257## LOCAL_CPP_EXTENSION is respected if set.
258## Meant to be used like:
259## SRC_FILES := $(call all-cpp-files-under,src tests)
260###########################################################
261
262define all-cpp-files-under
263$(sort $(patsubst ./%,%, \
264 $(shell cd $(LOCAL_PATH) ; \
265 find -L $(1) -name "*$(or $(LOCAL_CPP_EXTENSION),.cpp)" -and -not -name ".*") \
266 ))
267endef
268
269###########################################################
270## Find all of the cpp files from here. Meant to be used like:
271## SRC_FILES := $(call all-subdir-cpp-files)
272###########################################################
273
274define all-subdir-cpp-files
275$(call all-cpp-files-under,.)
276endef
277
278###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800279## Find all files named "I*.aidl" under the named directories,
280## which must be relative to $(LOCAL_PATH). The returned list
281## is relative to $(LOCAL_PATH).
282###########################################################
283
284define all-Iaidl-files-under
Dan Willemsen57a64e02015-10-12 15:26:52 -0700285$(call all-named-files-under,I*.aidl,$(1))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800286endef
287
288###########################################################
289## Find all of the "I*.aidl" files under $(LOCAL_PATH).
290###########################################################
291
292define all-subdir-Iaidl-files
293$(call all-Iaidl-files-under,.)
294endef
295
296###########################################################
Bjorn Bringerta89c9902010-02-02 17:36:20 +0000297## Find all of the logtags files under the named directories.
298## Meant to be used like:
299## SRC_FILES := $(call all-logtags-files-under,src)
300###########################################################
301
302define all-logtags-files-under
Dan Willemsen57a64e02015-10-12 15:26:52 -0700303$(call all-named-files-under,*.logtags,$(1))
Bjorn Bringerta89c9902010-02-02 17:36:20 +0000304endef
305
306###########################################################
Ying Wanga5fc87a2010-11-02 18:43:16 -0700307## Find all of the .proto files under the named directories.
308## Meant to be used like:
309## SRC_FILES := $(call all-proto-files-under,src)
310###########################################################
311
312define all-proto-files-under
Dan Willemsen57a64e02015-10-12 15:26:52 -0700313$(call all-named-files-under,*.proto,$(1))
Ying Wanga5fc87a2010-11-02 18:43:16 -0700314endef
315
316###########################################################
Ying Wang0bd59a02010-07-15 17:17:52 -0700317## Find all of the RenderScript files under the named directories.
318## Meant to be used like:
319## SRC_FILES := $(call all-renderscript-files-under,src)
320###########################################################
321
322define all-renderscript-files-under
Dan Willemsen57a64e02015-10-12 15:26:52 -0700323$(call find-subdir-files,$(1) \( -name "*.rs" -or -name "*.fs" \) -and -not -name ".*")
Ying Wang0bd59a02010-07-15 17:17:52 -0700324endef
325
326###########################################################
Elliott Hughese3b044a2014-02-11 13:48:35 -0800327## Find all of the S files under the named directories.
328## Meant to be used like:
329## SRC_FILES := $(call all-c-files-under,src tests)
330###########################################################
331
332define all-S-files-under
Dan Willemsen57a64e02015-10-12 15:26:52 -0700333$(call all-named-files-under,*.S,$(1))
Elliott Hughese3b044a2014-02-11 13:48:35 -0800334endef
335
336###########################################################
Jean-Baptiste Queru0a3cfdc2009-12-17 17:47:28 -0800337## Find all of the html files under the named directories.
338## Meant to be used like:
339## SRC_FILES := $(call all-html-files-under,src tests)
340###########################################################
341
342define all-html-files-under
Dan Willemsen57a64e02015-10-12 15:26:52 -0700343$(call all-named-files-under,*.html,$(1))
Jean-Baptiste Queru0a3cfdc2009-12-17 17:47:28 -0800344endef
345
346###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800347## Find all of the html files from here. Meant to be used like:
348## SRC_FILES := $(call all-subdir-html-files)
349###########################################################
350
351define all-subdir-html-files
Jean-Baptiste Queru0a3cfdc2009-12-17 17:47:28 -0800352$(call all-html-files-under,.)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800353endef
354
355###########################################################
356## Find all of the files matching pattern
357## SRC_FILES := $(call find-subdir-files, <pattern>)
358###########################################################
359
360define find-subdir-files
Dan Willemsen76a89d32015-09-22 16:54:12 -0700361$(sort $(patsubst ./%,%,$(shell cd $(LOCAL_PATH) ; find -L $(1))))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800362endef
363
364###########################################################
365# find the files in the subdirectory $1 of LOCAL_DIR
366# matching pattern $2, filtering out files $3
367# e.g.
368# SRC_FILES += $(call find-subdir-subdir-files, \
369# css, *.cpp, DontWantThis.cpp)
370###########################################################
371
372define find-subdir-subdir-files
Dan Willemsen76a89d32015-09-22 16:54:12 -0700373$(sort $(filter-out $(patsubst %,$(1)/%,$(3)),$(patsubst ./%,%,$(shell cd \
374 $(LOCAL_PATH) ; find -L $(1) -maxdepth 1 -name $(2)))))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800375endef
376
377###########################################################
378## Find all of the files matching pattern
379## SRC_FILES := $(call all-subdir-java-files)
380###########################################################
381
382define find-subdir-assets
Dan Willemsen76a89d32015-09-22 16:54:12 -0700383$(sort $(if $(1),$(patsubst ./%,%, \
Ying Wang6ab5d6a2011-08-10 16:05:51 -0700384 $(shell if [ -d $(1) ] ; then cd $(1) ; find ./ -not -name '.*' -and -type f -and -not -type l ; fi)), \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800385 $(warning Empty argument supplied to find-subdir-assets) \
Dan Willemsen76a89d32015-09-22 16:54:12 -0700386))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800387endef
388
389###########################################################
390## Find various file types in a list of directories relative to $(LOCAL_PATH)
391###########################################################
392
393define find-other-java-files
Dan Willemsen57a64e02015-10-12 15:26:52 -0700394$(call all-java-files-under,$(1))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800395endef
396
Adnan Begovicf7964112015-04-15 12:00:43 -0700397define find-other-aidl-files
398 $(call find-subdir-files,$(1) -name "*.aidl" -and -not -name ".*")
399endef
400
The Android Open Source Project88b60792009-03-03 19:28:42 -0800401define find-other-html-files
Dan Willemsen57a64e02015-10-12 15:26:52 -0700402$(call all-html-files-under,$(1))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800403endef
404
405###########################################################
Ying Wang85898bc2013-12-04 16:04:49 -0800406# Use utility find to find given files in the given subdirs.
407# This function uses $(1), instead of LOCAL_PATH as the base.
408# $(1): the base dir, relative to the root of the source tree.
409# $(2): the file name pattern to be passed to find as "-name".
410# $(3): a list of subdirs of the base dir.
411# Returns: a list of paths relative to the base dir.
412###########################################################
413
414define find-files-in-subdirs
Dan Willemsen76a89d32015-09-22 16:54:12 -0700415$(sort $(patsubst ./%,%, \
Ying Wang85898bc2013-12-04 16:04:49 -0800416 $(shell cd $(1) ; \
417 find -L $(3) -name $(2) -and -not -name ".*") \
Dan Willemsen76a89d32015-09-22 16:54:12 -0700418 ))
Ying Wang85898bc2013-12-04 16:04:49 -0800419endef
420
421###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800422## Scan through each directory of $(1) looking for files
423## that match $(2) using $(wildcard). Useful for seeing if
424## a given directory or one of its parents contains
425## a particular file. Returns the first match found,
426## starting furthest from the root.
427###########################################################
428
429define find-parent-file
430$(strip \
Ying Wanga67ce692011-03-03 13:29:38 -0800431 $(eval _fpf := $(wildcard $(foreach f, $(2), $(strip $(1))/$(f)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800432 $(if $(_fpf),$(_fpf), \
433 $(if $(filter-out ./ .,$(1)), \
434 $(call find-parent-file,$(patsubst %/,%,$(dir $(1))),$(2)) \
435 ) \
436 ) \
437)
438endef
439
440###########################################################
441## Function we can evaluate to introduce a dynamic dependency
442###########################################################
443
444define add-dependency
445$(1): $(2)
446endef
447
448###########################################################
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200449## Reverse order of a list
450###########################################################
451
452define reverse-list
453$(if $(1),$(call reverse-list,$(wordlist 2,$(words $(1)),$(1)))) $(firstword $(1))
454endef
455
456###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800457## The intermediates directory. Where object files go for
458## a given target. We could technically get away without
459## the "_intermediates" suffix on the directory, but it's
460## nice to be able to grep for that string to find out if
461## anyone's abusing the system.
462###########################################################
463
464# $(1): target class, like "APPS"
465# $(2): target name, like "NotePad"
466# $(3): if non-empty, this is a HOST target.
467# $(4): if non-empty, force the intermediates to be COMMON
Ying Wang61d499b2014-01-15 16:02:16 -0800468# $(5): if non-empty, force the intermedistes to be for the 2nd arch
The Android Open Source Project88b60792009-03-03 19:28:42 -0800469define intermediates-dir-for
470$(strip \
471 $(eval _idfClass := $(strip $(1))) \
472 $(if $(_idfClass),, \
473 $(error $(LOCAL_PATH): Class not defined in call to intermediates-dir-for)) \
474 $(eval _idfName := $(strip $(2))) \
475 $(if $(_idfName),, \
476 $(error $(LOCAL_PATH): Name not defined in call to intermediates-dir-for)) \
477 $(eval _idfPrefix := $(if $(strip $(3)),HOST,TARGET)) \
Colin Crossae2986e2014-06-17 21:35:44 -0700478 $(eval _idf2ndArchPrefix := $(if $(strip $(5)),$(TARGET_2ND_ARCH_VAR_PREFIX))) \
Ying Wanga83940f2010-09-24 18:09:04 -0700479 $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800480 $(eval _idfIntBase := $($(_idfPrefix)_OUT_COMMON_INTERMEDIATES)) \
Ying Wang6feb6d52014-04-17 10:03:35 -0700481 ,$(if $(filter $(_idfClass),SHARED_LIBRARIES STATIC_LIBRARIES EXECUTABLES GYP),\
Colin Cross02e31d22014-01-24 13:38:08 -0800482 $(eval _idfIntBase := $($(_idf2ndArchPrefix)$(_idfPrefix)_OUT_INTERMEDIATES)) \
483 ,$(eval _idfIntBase := $($(_idfPrefix)_OUT_INTERMEDIATES)) \
484 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800485 ) \
486 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
487)
488endef
489
490# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE
491# to determine the intermediates directory.
492#
493# $(1): if non-empty, force the intermediates to be COMMON
Ying Wang61d499b2014-01-15 16:02:16 -0800494# $(2): if non-empty, force the intermediates to be for the 2nd arch
The Android Open Source Project88b60792009-03-03 19:28:42 -0800495define local-intermediates-dir
496$(strip \
497 $(if $(strip $(LOCAL_MODULE_CLASS)),, \
498 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-intermediates-dir)) \
499 $(if $(strip $(LOCAL_MODULE)),, \
500 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-intermediates-dir)) \
Ying Wang61d499b2014-01-15 16:02:16 -0800501 $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(LOCAL_IS_HOST_MODULE),$(1),$(2)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800502)
503endef
504
505###########################################################
Colin Crossd8262642014-01-24 23:17:21 -0800506## The generated sources directory. Placing generated
507## source files directly in the intermediates directory
508## causes problems for multiarch builds, where there are
509## two intermediates directories for a single target. Put
510## them in a separate directory, and they will be copied to
511## each intermediates directory automatically.
512###########################################################
513
514# $(1): target class, like "APPS"
515# $(2): target name, like "NotePad"
516# $(3): if non-empty, this is a HOST target.
517# $(4): if non-empty, force the generated sources to be COMMON
518define generated-sources-dir-for
519$(strip \
520 $(eval _idfClass := $(strip $(1))) \
521 $(if $(_idfClass),, \
522 $(error $(LOCAL_PATH): Class not defined in call to generated-sources-dir-for)) \
523 $(eval _idfName := $(strip $(2))) \
524 $(if $(_idfName),, \
525 $(error $(LOCAL_PATH): Name not defined in call to generated-sources-dir-for)) \
526 $(eval _idfPrefix := $(if $(strip $(3)),HOST,TARGET)) \
527 $(if $(filter $(_idfPrefix)-$(_idfClass),$(COMMON_MODULE_CLASSES))$(4), \
528 $(eval _idfIntBase := $($(_idfPrefix)_OUT_GEN_COMMON)) \
529 , \
530 $(eval _idfIntBase := $($(_idfPrefix)_OUT_GEN)) \
531 ) \
532 $(_idfIntBase)/$(_idfClass)/$(_idfName)_intermediates \
533)
534endef
535
536# Uses LOCAL_MODULE_CLASS, LOCAL_MODULE, and LOCAL_IS_HOST_MODULE
537# to determine the generated sources directory.
538#
539# $(1): if non-empty, force the intermediates to be COMMON
540define local-generated-sources-dir
541$(strip \
542 $(if $(strip $(LOCAL_MODULE_CLASS)),, \
543 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS not defined before call to local-generated-sources-dir)) \
544 $(if $(strip $(LOCAL_MODULE)),, \
545 $(error $(LOCAL_PATH): LOCAL_MODULE not defined before call to local-generated-sources-dir)) \
546 $(call generated-sources-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE),$(LOCAL_IS_HOST_MODULE),$(1)) \
547)
548endef
549
550###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800551## Convert "path/to/libXXX.so" to "-lXXX".
552## Any "path/to/libXXX.a" elements pass through unchanged.
553###########################################################
554
555define normalize-libraries
556$(foreach so,$(filter %.so,$(1)),-l$(patsubst lib%.so,%,$(notdir $(so))))\
557$(filter-out %.so,$(1))
558endef
559
560# TODO: change users to call the common version.
561define normalize-host-libraries
562$(call normalize-libraries,$(1))
563endef
564
565define normalize-target-libraries
566$(call normalize-libraries,$(1))
567endef
568
569###########################################################
570## Convert a list of short module names (e.g., "framework", "Browser")
571## into the list of files that are built for those modules.
572## NOTE: this won't return reliable results until after all
573## sub-makefiles have been included.
574## $(1): target list
575###########################################################
576
577define module-built-files
578$(foreach module,$(1),$(ALL_MODULES.$(module).BUILT))
579endef
580
581###########################################################
582## Convert a list of short modules names (e.g., "framework", "Browser")
583## into the list of files that are installed for those modules.
584## NOTE: this won't return reliable results until after all
585## sub-makefiles have been included.
586## $(1): target list
587###########################################################
588
589define module-installed-files
590$(foreach module,$(1),$(ALL_MODULES.$(module).INSTALLED))
591endef
592
593###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700594## Convert a list of short modules names (e.g., "framework", "Browser")
595## into the list of files that should be used when linking
596## against that module as a public API.
597## TODO: Allow this for more than JAVA_LIBRARIES modules
598## NOTE: this won't return reliable results until after all
599## sub-makefiles have been included.
600## $(1): target list
601###########################################################
602
603define module-stubs-files
604$(foreach module,$(1),$(ALL_MODULES.$(module).STUBS))
605endef
606
607###########################################################
608## Evaluates to the timestamp file for a doc module, which
609## is the dependency that should be used.
610## $(1): doc module
611###########################################################
612
613define doc-timestamp-for
614$(OUT_DOCS)/$(strip $(1))-timestamp
615endef
616
617
618###########################################################
Ying Wang912f8282010-09-28 17:27:56 -0700619## Convert "core ext framework" to "out/.../javalib.jar ..."
The Android Open Source Project88b60792009-03-03 19:28:42 -0800620## $(1): library list
621## $(2): Non-empty if IS_HOST_MODULE
622###########################################################
623
624# $(1): library name
625# $(2): Non-empty if IS_HOST_MODULE
626define _java-lib-dir
627$(call intermediates-dir-for, \
Ying Wang912f8282010-09-28 17:27:56 -0700628 JAVA_LIBRARIES,$(1),$(2),COMMON)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800629endef
630
631# $(1): library name
632# $(2): Non-empty if IS_HOST_MODULE
633define _java-lib-full-classes.jar
Ying Wang912f8282010-09-28 17:27:56 -0700634$(call _java-lib-dir,$(1),$(2))/classes$(COMMON_JAVA_PACKAGE_SUFFIX)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800635endef
636
637# $(1): library name list
638# $(2): Non-empty if IS_HOST_MODULE
639define java-lib-files
640$(foreach lib,$(1),$(call _java-lib-full-classes.jar,$(lib),$(2)))
641endef
642
643# $(1): library name
The Android Open Source Project88b60792009-03-03 19:28:42 -0800644# $(2): Non-empty if IS_HOST_MODULE
645define _java-lib-full-dep
Ying Wang833b4272015-01-21 17:30:21 -0800646$(call _java-lib-dir,$(1),$(2))/$(if $(2),javalib,classes)$(COMMON_JAVA_PACKAGE_SUFFIX)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800647endef
648
649# $(1): library name list
650# $(2): Non-empty if IS_HOST_MODULE
651define java-lib-deps
652$(foreach lib,$(1),$(call _java-lib-full-dep,$(lib),$(2)))
653endef
654
655###########################################################
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200656## Convert "core ext framework" to "out/.../classes.jack ..."
657## $(1): library list
658## $(2): Non-empty if IS_HOST_MODULE
659###########################################################
660
661# $(1): library name
662# $(2): Non-empty if IS_HOST_MODULE
663define _jack-lib-full-classes
664$(call _java-lib-dir,$(1),$(2))/classes.jack
665endef
666
667# $(1): library name list
668# $(2): Non-empty if IS_HOST_MODULE
669define jack-lib-files
670$(foreach lib,$(1),$(call _jack-lib-full-classes,$(lib),$(2)))
671endef
672
673# $(1): library name
674# $(2): Non-empty if IS_HOST_MODULE
675define _jack-lib-full-dep
676$(call _jack-lib-full-classes,$(1),$(2))
677endef
678
679# $(1): library name list
680# $(2): Non-empty if IS_HOST_MODULE
681define jack-lib-deps
682$(foreach lib,$(1),$(call _jack-lib-full-dep,$(lib),$(2)))
683endef
684
685###########################################################
Joe Onorato8dc8faa2010-09-14 13:09:48 -0400686## Run rot13 on a string
687## $(1): the string. Must be one line.
688###########################################################
689define rot13
690$(shell echo $(1) | tr 'a-zA-Z' 'n-za-mN-ZA-M')
691endef
692
693
694###########################################################
695## Returns true if $(1) and $(2) are equal. Returns
696## the empty string if they are not equal.
697###########################################################
698define streq
699$(strip $(if $(strip $(1)),\
700 $(if $(strip $(2)),\
701 $(if $(filter-out __,_$(subst $(strip $(1)),,$(strip $(2)))$(subst $(strip $(2)),,$(strip $(1)))_),,true), \
702 ),\
703 $(if $(strip $(2)),\
704 ,\
705 true)\
706 ))
707endef
708
709###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800710## Convert "a b c" into "a:b:c"
711###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800712define normalize-path-list
713$(subst $(space),:,$(strip $(1)))
714endef
715
716###########################################################
Joe Onorato64d85d02009-04-09 19:31:12 -0700717## Read the word out of a colon-separated list of words.
718## This has the same behavior as the built-in function
719## $(word n,str).
720##
721## The individual words may not contain spaces.
722##
723## $(1): 1 based index
724## $(2): value of the form a:b:c...
725###########################################################
726
727define word-colon
728$(word $(1),$(subst :,$(space),$(2)))
729endef
730
731###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800732## Convert "a=b c= d e = f" into "a=b c=d e=f"
733##
734## $(1): list to collapse
735## $(2): if set, separator word; usually "=", ":", or ":="
736## Defaults to "=" if not set.
737###########################################################
738
739define collapse-pairs
740$(eval _cpSEP := $(strip $(if $(2),$(2),=)))\
741$(subst $(space)$(_cpSEP)$(space),$(_cpSEP),$(strip \
742 $(subst $(_cpSEP), $(_cpSEP) ,$(1))))
743endef
744
The Android Open Source Project88b60792009-03-03 19:28:42 -0800745###########################################################
Ying Wang7e8d4422011-06-17 17:05:35 -0700746## Given a list of pairs, if multiple pairs have the same
747## first components, keep only the first pair.
748##
749## $(1): list of pairs
750## $(2): the separator word, such as ":", "=", etc.
751define uniq-pairs-by-first-component
752$(eval _upbfc_fc_set :=)\
753$(strip $(foreach w,$(1), $(eval _first := $(word 1,$(subst $(2),$(space),$(w))))\
754 $(if $(filter $(_upbfc_fc_set),$(_first)),,$(w)\
755 $(eval _upbfc_fc_set += $(_first)))))\
756$(eval _upbfc_fc_set :=)\
757$(eval _first:=)
758endef
759
760###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800761## MODULE_TAG set operations
762###########################################################
763
764# Given a list of tags, return the targets that specify
765# any of those tags.
766# $(1): tag list
767define modules-for-tag-list
Ying Wang634f7992014-11-18 12:41:53 -0800768$(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 -0800769endef
770
771# Same as modules-for-tag-list, but operates on
772# ALL_MODULE_NAME_TAGS.
773# $(1): tag list
774define module-names-for-tag-list
775$(sort $(foreach tag,$(1),$(ALL_MODULE_NAME_TAGS.$(tag))))
776endef
777
778# Given an accept and reject list, find the matching
779# set of targets. If a target has multiple tags and
780# any of them are rejected, the target is rejected.
781# Reject overrides accept.
782# $(1): list of tags to accept
783# $(2): list of tags to reject
784#TODO(dbort): do $(if $(strip $(1)),$(1),$(ALL_MODULE_TAGS))
Jean-Baptiste Queru75127b72010-01-07 11:44:22 -0800785#TODO(jbq): as of 20100106 nobody uses the second parameter
The Android Open Source Project88b60792009-03-03 19:28:42 -0800786define get-tagged-modules
787$(filter-out \
788 $(call modules-for-tag-list,$(2)), \
789 $(call modules-for-tag-list,$(1)))
790endef
791
Joe Onorato64d85d02009-04-09 19:31:12 -0700792###########################################################
793## Append a leaf to a base path. Properly deals with
794## base paths ending in /.
795##
796## $(1): base path
797## $(2): leaf path
798###########################################################
799
800define append-path
801$(subst //,/,$(1)/$(2))
802endef
803
The Android Open Source Project88b60792009-03-03 19:28:42 -0800804
805###########################################################
806## Package filtering
807###########################################################
808
809# Given a list of installed modules (short or long names)
810# return a list of the packages (yes, .apk packages, not
811# modules in general) that are overridden by this list and,
812# therefore, should not be installed.
813# $(1): mixed list of installed modules
814# TODO: This is fragile; find a reliable way to get this information.
815define _get-package-overrides
816 $(eval ### Discard any words containing slashes, unless they end in .apk, \
817 ### in which case trim off the directory component and the suffix. \
818 ### If there are no slashes, keep the entire word.)
819 $(eval _gpo_names := $(subst /,@@@ @@@,$(1)))
820 $(eval _gpo_names := \
821 $(filter %.apk,$(_gpo_names)) \
822 $(filter-out %@@@ @@@%,$(_gpo_names)))
823 $(eval _gpo_names := $(patsubst %.apk,%,$(_gpo_names)))
824 $(eval _gpo_names := $(patsubst @@@%,%,$(_gpo_names)))
825
826 $(eval ### Remove any remaining words that contain dots.)
827 $(eval _gpo_names := $(subst .,@@@ @@@,$(_gpo_names)))
828 $(eval _gpo_names := $(filter-out %@@@ @@@%,$(_gpo_names)))
829
830 $(eval ### Now we have a list of any words that could possibly refer to \
831 ### packages, although there may be words that do not. Only \
832 ### real packages will be present under PACKAGES.*, though.)
833 $(foreach _gpo_name,$(_gpo_names),$(PACKAGES.$(_gpo_name).OVERRIDES))
834endef
835
836define get-package-overrides
Conley Owensd7a1a9b2011-12-22 09:46:19 -0800837$(sort $(strip $(call _get-package-overrides,$(1))))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800838endef
839
840###########################################################
841## Output the command lines, or not
842###########################################################
843
844ifeq ($(strip $(SHOW_COMMANDS)),)
845define pretty
846@echo $1
847endef
848hide := @
849else
850define pretty
851endef
852hide :=
853endif
854
855###########################################################
856## Dump the variables that are associated with targets
857###########################################################
858
859define dump-module-variables
860@echo all_dependencies=$^
861@echo PRIVATE_YACCFLAGS=$(PRIVATE_YACCFLAGS);
862@echo PRIVATE_CFLAGS=$(PRIVATE_CFLAGS);
863@echo PRIVATE_CPPFLAGS=$(PRIVATE_CPPFLAGS);
864@echo PRIVATE_DEBUG_CFLAGS=$(PRIVATE_DEBUG_CFLAGS);
865@echo PRIVATE_C_INCLUDES=$(PRIVATE_C_INCLUDES);
866@echo PRIVATE_LDFLAGS=$(PRIVATE_LDFLAGS);
867@echo PRIVATE_LDLIBS=$(PRIVATE_LDLIBS);
868@echo PRIVATE_ARFLAGS=$(PRIVATE_ARFLAGS);
869@echo PRIVATE_AAPT_FLAGS=$(PRIVATE_AAPT_FLAGS);
870@echo PRIVATE_DX_FLAGS=$(PRIVATE_DX_FLAGS);
Brian Carlstromf184a0f2010-02-01 11:13:32 -0800871@echo PRIVATE_JAVACFLAGS=$(PRIVATE_JAVACFLAGS);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800872@echo PRIVATE_JAVA_LIBRARIES=$(PRIVATE_JAVA_LIBRARIES);
873@echo PRIVATE_ALL_SHARED_LIBRARIES=$(PRIVATE_ALL_SHARED_LIBRARIES);
874@echo PRIVATE_ALL_STATIC_LIBRARIES=$(PRIVATE_ALL_STATIC_LIBRARIES);
875@echo PRIVATE_ALL_WHOLE_STATIC_LIBRARIES=$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES);
876@echo PRIVATE_ALL_OBJECTS=$(PRIVATE_ALL_OBJECTS);
Jeff Brown703e7c62011-02-04 20:15:00 -0800877@echo PRIVATE_NO_CRT=$(PRIVATE_NO_CRT);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800878endef
879
880###########################################################
881## Commands for using sed to replace given variable values
882###########################################################
883
884define transform-variables
885@mkdir -p $(dir $@)
886@echo "Sed: $(if $(PRIVATE_MODULE),$(PRIVATE_MODULE),$@) <= $<"
887$(hide) sed $(foreach var,$(REPLACE_VARS),-e "s/{{$(var)}}/$(subst /,\/,$(PWD)/$($(var)))/g") $< >$@
888$(hide) if [ "$(suffix $@)" = ".sh" ]; then chmod a+rx $@; fi
889endef
890
891
892###########################################################
893## Commands for munging the dependency files GCC generates
894###########################################################
Ying Wangc23f4ef2012-09-07 17:04:06 -0700895# $(1): the input .d file
896# $(2): the output .P file
897define transform-d-to-p-args
898$(hide) cp $(1) $(2); \
899 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
900 -e '/^$$/ d' -e 's/$$/ :/' < $(1) >> $(2); \
901 rm -f $(1)
902endef
The Android Open Source Project88b60792009-03-03 19:28:42 -0800903
904define transform-d-to-p
Ying Wangc23f4ef2012-09-07 17:04:06 -0700905$(call transform-d-to-p-args,$(@:%.o=%.d),$(@:%.o=%.P))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800906endef
907
908###########################################################
909## Commands for running lex
910###########################################################
911
912define transform-l-to-cpp
913@mkdir -p $(dir $@)
914@echo "Lex: $(PRIVATE_MODULE) <= $<"
915$(hide) $(LEX) -o$@ $<
916endef
917
918###########################################################
919## Commands for running yacc
920##
921## Because the extension of c++ files can change, the
922## extension must be specified in $1.
923## E.g, "$(call transform-y-to-cpp,.cpp)"
924###########################################################
925
926define transform-y-to-cpp
927@mkdir -p $(dir $@)
928@echo "Yacc: $(PRIVATE_MODULE) <= $<"
929$(YACC) $(PRIVATE_YACCFLAGS) -o $@ $<
930touch $(@:$1=$(YACC_HEADER_SUFFIX))
931echo '#ifndef '$(@F:$1=_h) > $(@:$1=.h)
932echo '#define '$(@F:$1=_h) >> $(@:$1=.h)
933cat $(@:$1=$(YACC_HEADER_SUFFIX)) >> $(@:$1=.h)
934echo '#endif' >> $(@:$1=.h)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800935endef
936
Ying Wang0bd59a02010-07-15 17:17:52 -0700937###########################################################
Tim Murraya7aa8002012-10-29 16:06:00 -0700938## Commands to compile RenderScript to Java
Ying Wang0bd59a02010-07-15 17:17:52 -0700939###########################################################
Ying Wang0bd59a02010-07-15 17:17:52 -0700940
941define transform-renderscripts-to-java-and-bc
942@echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)"
943$(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR)
944$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/res/raw
945$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/src
Ying Wang7d83ef82011-05-25 17:16:22 -0700946$(hide) $(PRIVATE_RS_CC) \
Ying Wangebfddaa2010-07-30 18:37:29 -0700947 -o $(PRIVATE_RS_OUTPUT_DIR)/res/raw \
948 -p $(PRIVATE_RS_OUTPUT_DIR)/src \
Ying Wang24e1c012010-10-07 18:57:57 -0700949 -d $(PRIVATE_RS_OUTPUT_DIR) \
950 -a $@ -MD \
Stephen Hinesc963eae2011-08-10 13:53:05 -0700951 $(addprefix -target-api , $(PRIVATE_RS_TARGET_API)) \
Stephen Hines914f7a22011-12-06 18:43:24 -0800952 $(PRIVATE_RS_FLAGS) \
Ying Wang51280272010-09-01 13:28:52 -0700953 $(foreach inc,$(PRIVATE_RS_INCLUDES),$(addprefix -I , $(inc))) \
Ying Wangebfddaa2010-07-30 18:37:29 -0700954 $(PRIVATE_RS_SOURCE_FILES)
Ying Wangb9319562015-04-03 16:15:28 -0700955 $(foreach d,$(PRIVATE_DEP_FILES),\
956 $(call transform-d-to-p-args,$(d),$(d:%.d=%.P))$(newline))
Ying Wang0bd59a02010-07-15 17:17:52 -0700957$(hide) mkdir -p $(dir $@)
958$(hide) touch $@
959endef
960
Stephen Hinese719f282012-11-28 16:52:41 -0800961define transform-bc-to-so
Stephen Hines9ac9b532013-02-27 00:51:08 -0800962@echo "Renderscript compatibility: $(notdir $@) <= $(notdir $<)"
Stephen Hinese719f282012-11-28 16:52:41 -0800963$(hide) mkdir -p $(dir $@)
Stephen Hinesf6925132012-12-17 14:23:14 -0800964$(hide) $(BCC_COMPAT) -O3 -o $(dir $@)/$(notdir $(<:.bc=.o)) -fPIC -shared \
Stephen Hines52626d22014-09-02 19:09:35 -0700965 -rt-path $(RS_PREBUILT_CLCORE) -mtriple $(RS_COMPAT_TRIPLE) $<
Stephen Hines7d6ec712012-12-13 19:24:50 -0800966$(hide) $(PRIVATE_CXX) -shared -Wl,-soname,$(notdir $@) -nostdlib \
Stephen Hinesf6925132012-12-17 14:23:14 -0800967 -Wl,-rpath,\$$ORIGIN/../lib \
Stephen Hines9541f582013-01-18 16:27:23 -0800968 $(dir $@)/$(notdir $(<:.bc=.o)) \
Tim Murray1a6f09a2013-03-05 11:07:15 -0800969 $(RS_PREBUILT_COMPILER_RT) \
Miao Wange23e8082014-11-15 14:25:33 -0800970 -o $@ $(TARGET_GLOBAL_LDFLAGS) -Wl,--hash-style=sysv -L prebuilts/gcc/ \
Ying Wangbfc43692015-03-05 11:29:30 -0800971 $(RS_PREBUILT_LIBPATH) -L $(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
Stephen Hines8db4cce2013-03-27 16:51:38 -0700972 -lRSSupport -lm -lc
Stephen Hinese719f282012-11-28 16:52:41 -0800973endef
974
Tim Murraya7aa8002012-10-29 16:06:00 -0700975###########################################################
976## Commands to compile RenderScript to C++
977###########################################################
978
979define transform-renderscripts-to-cpp-and-bc
980@echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)"
981$(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR)
982$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/
983$(hide) $(PRIVATE_RS_CC) \
984 -o $(PRIVATE_RS_OUTPUT_DIR)/ \
985 -d $(PRIVATE_RS_OUTPUT_DIR) \
986 -a $@ -MD \
987 -reflect-c++ \
988 $(PRIVATE_RS_FLAGS) \
Ying Wang81ab8332014-05-28 16:17:09 -0700989 $(addprefix -I , $(PRIVATE_RS_INCLUDES)) \
Tim Murraya7aa8002012-10-29 16:06:00 -0700990 $(PRIVATE_RS_SOURCE_FILES)
Ying Wangb9319562015-04-03 16:15:28 -0700991 $(foreach d,$(PRIVATE_DEP_FILES),\
992 $(call transform-d-to-p-args,$(d),$(d:%.d=%.P))$(newline))
Tim Murraya7aa8002012-10-29 16:06:00 -0700993$(hide) mkdir -p $(dir $@)
994$(hide) touch $@
995endef
996
The Android Open Source Project88b60792009-03-03 19:28:42 -0800997
998###########################################################
999## Commands for running aidl
1000###########################################################
1001
1002define transform-aidl-to-java
1003@mkdir -p $(dir $@)
1004@echo "Aidl: $(PRIVATE_MODULE) <= $<"
1005$(hide) $(AIDL) -d$(patsubst %.java,%.P,$@) $(PRIVATE_AIDL_FLAGS) $< $@
1006endef
1007#$(AIDL) $(PRIVATE_AIDL_FLAGS) $< - | indent -nut -br -npcs -l1000 > $@
1008
1009
Doug Zongker9bd49622009-11-30 14:28:59 -08001010###########################################################
1011## Commands for running java-event-log-tags.py
1012###########################################################
1013
1014define transform-logtags-to-java
1015@mkdir -p $(dir $@)
1016@echo "logtags: $@ <= $<"
Doug Zongkerabfbbe22010-02-16 14:32:08 -08001017$(hide) $(JAVATAGS) -o $@ $^
Doug Zongker9bd49622009-11-30 14:28:59 -08001018endef
1019
The Android Open Source Project88b60792009-03-03 19:28:42 -08001020
1021###########################################################
Ying Wanga5fc87a2010-11-02 18:43:16 -07001022## Commands for running protoc to compile .proto into .java
1023###########################################################
1024
1025define transform-proto-to-java
1026@mkdir -p $(dir $@)
1027@echo "Protoc: $@ <= $(PRIVATE_PROTO_SRC_FILES)"
1028@rm -rf $(PRIVATE_PROTO_JAVA_OUTPUT_DIR)
1029@mkdir -p $(PRIVATE_PROTO_JAVA_OUTPUT_DIR)
Ben Murdochfc2bad52013-07-25 11:44:53 +01001030$(hide) for f in $(PRIVATE_PROTO_SRC_FILES); do \
1031 $(PROTOC) \
Ulas Kirazci28b46fc2013-07-24 14:32:14 -07001032 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
Ulas Kirazci6e485b52013-07-25 12:28:19 -07001033 $(PRIVATE_PROTO_JAVA_OUTPUT_OPTION)="$(PRIVATE_PROTO_JAVA_OUTPUT_PARAMS):$(PRIVATE_PROTO_JAVA_OUTPUT_DIR)" \
Ben Murdochfc2bad52013-07-25 11:44:53 +01001034 $(PRIVATE_PROTOC_FLAGS) \
1035 $$f || exit 33; \
1036 done
Ying Wanga5fc87a2010-11-02 18:43:16 -07001037$(hide) touch $@
1038endef
1039
1040######################################################################
Ying Wangfaeb6932015-04-07 11:59:34 -07001041## Commands for running protoc to compile .proto into .pb.cc (or.pb.c) and .pb.h
Ying Wanga5fc87a2010-11-02 18:43:16 -07001042######################################################################
1043define transform-proto-to-cc
1044@mkdir -p $(dir $@)
1045@echo "Protoc: $@ <= $<"
1046$(hide) $(PROTOC) \
1047 $(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
Ying Wang33c0d952010-11-05 11:30:58 -07001048 $(PRIVATE_PROTOC_FLAGS) \
Ying Wangfaeb6932015-04-07 11:59:34 -07001049 $<
Wink Saville042d4dc2014-05-06 15:45:57 -07001050endef
Ying Wanga5fc87a2010-11-02 18:43:16 -07001051
1052###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001053## Commands for running gcc to compile a C++ file
1054###########################################################
1055
1056define transform-cpp-to-o
1057@mkdir -p $(dir $@)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301058@echo -e ${CL_GRN}"target $(PRIVATE_ARM_MODE) C++:"${CL_RST}" $(PRIVATE_MODULE) <= $<"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001059$(hide) $(PRIVATE_CXX) \
Ying Wangddbcad82011-04-18 11:45:44 -07001060 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Andrew Boie85f3b212012-07-11 12:14:56 -07001061 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
Ying Wang4761e562011-04-12 11:06:35 -07001062 $(addprefix -isystem ,\
1063 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1064 $(filter-out $(PRIVATE_C_INCLUDES), \
Ying Wangddbcad82011-04-18 11:45:44 -07001065 $(PRIVATE_TARGET_PROJECT_INCLUDES) \
Ying Wang4761e562011-04-12 11:06:35 -07001066 $(PRIVATE_TARGET_C_INCLUDES)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001067 -c \
1068 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -07001069 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
1070 $(PRIVATE_TARGET_GLOBAL_CPPFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001071 $(PRIVATE_ARM_CFLAGS) \
1072 ) \
Doug Kwan9a8ecf92011-05-10 21:50:58 -07001073 $(PRIVATE_RTTI_FLAG) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001074 $(PRIVATE_CFLAGS) \
1075 $(PRIVATE_CPPFLAGS) \
1076 $(PRIVATE_DEBUG_CFLAGS) \
Dan Albert0c91fa82015-02-21 12:45:26 -08001077 $(GLOBAL_CFLAGS_NO_OVERRIDE) \
1078 $(GLOBAL_CPPFLAGS_NO_OVERRIDE) \
Atte Peltomaki60fe9632011-12-21 09:24:09 -08001079 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001080$(transform-d-to-p)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001081endef
1082
1083
1084###########################################################
1085## Commands for running gcc to compile a C file
1086###########################################################
1087
1088# $(1): extra flags
1089define transform-c-or-s-to-o-no-deps
1090@mkdir -p $(dir $@)
1091$(hide) $(PRIVATE_CC) \
Ying Wangddbcad82011-04-18 11:45:44 -07001092 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Andrew Boie85f3b212012-07-11 12:14:56 -07001093 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
Ying Wang4761e562011-04-12 11:06:35 -07001094 $(addprefix -isystem ,\
1095 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
1096 $(filter-out $(PRIVATE_C_INCLUDES), \
Ying Wangddbcad82011-04-18 11:45:44 -07001097 $(PRIVATE_TARGET_PROJECT_INCLUDES) \
Ying Wang4761e562011-04-12 11:06:35 -07001098 $(PRIVATE_TARGET_C_INCLUDES)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001099 -c \
1100 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wang1a081002010-07-13 14:55:47 -07001101 $(PRIVATE_TARGET_GLOBAL_CFLAGS) \
Stephen Hines15680292014-11-26 00:53:46 -08001102 $(PRIVATE_TARGET_GLOBAL_CONLYFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001103 $(PRIVATE_ARM_CFLAGS) \
1104 ) \
Ying Wang65d78522012-08-10 16:30:42 -07001105 $(1) \
Atte Peltomaki60fe9632011-12-21 09:24:09 -08001106 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
The Android Open Source Project88b60792009-03-03 19:28:42 -08001107endef
1108
1109define transform-c-to-o-no-deps
Chirayu Desaiad48df42012-10-13 13:05:29 +05301110@echo -e ${CL_GRN}"target $(PRIVATE_ARM_MODE) C:"${CL_RST}" $(PRIVATE_MODULE) <= $<"
Dan Albert0c91fa82015-02-21 12:45:26 -08001111$(call transform-c-or-s-to-o-no-deps, \
1112 $(PRIVATE_CFLAGS) \
1113 $(PRIVATE_CONLYFLAGS) \
1114 $(PRIVATE_DEBUG_CFLAGS) \
1115 $(GLOBAL_CFLAGS_NO_OVERRIDE))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001116endef
1117
1118define transform-s-to-o-no-deps
Chirayu Desaiad48df42012-10-13 13:05:29 +05301119@echo -e ${CL_GRN}"target asm:"${CL_RST}" $(PRIVATE_MODULE) <= $<"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001120$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
1121endef
1122
1123define transform-c-to-o
1124$(transform-c-to-o-no-deps)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001125$(transform-d-to-p)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001126endef
1127
1128define transform-s-to-o
1129$(transform-s-to-o-no-deps)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001130$(transform-d-to-p)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001131endef
1132
Ying Wang7b913ce2014-06-05 19:05:47 -07001133# YASM compilation
1134define transform-asm-to-o
1135@mkdir -p $(dir $@)
1136$(hide) $(YASM) \
1137 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Ying Wangfe1e5c32015-03-09 18:57:40 -07001138 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_YASM_FLAGS) \
Ying Wang7b913ce2014-06-05 19:05:47 -07001139 $(PRIVATE_ASFLAGS) \
1140 -o $@ $<
1141endef
1142
The Android Open Source Project88b60792009-03-03 19:28:42 -08001143###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001144## Commands for running gcc to compile an Objective-C file
1145## This should never happen for target builds but this
1146## will error at build time.
1147###########################################################
1148
1149define transform-m-to-o-no-deps
Chirayu Desaiad48df42012-10-13 13:05:29 +05301150@echo -e ${CL_GRN}"target ObjC:"${CL_RST}" $(PRIVATE_MODULE) <= $<"
Ying Wang65d78522012-08-10 16:30:42 -07001151$(call transform-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_DEBUG_CFLAGS))
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001152endef
1153
1154define transform-m-to-o
1155$(transform-m-to-o-no-deps)
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001156$(transform-d-to-p)
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001157endef
1158
1159###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001160## Commands for running gcc to compile a host C++ file
1161###########################################################
1162
1163define transform-host-cpp-to-o
1164@mkdir -p $(dir $@)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301165@echo -e ${CL_YLW}"host C++:"${CL_RST}" $(PRIVATE_MODULE) <= $<"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001166$(hide) $(PRIVATE_CXX) \
Ying Wangddbcad82011-04-18 11:45:44 -07001167 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Andrew Boie85f3b212012-07-11 12:14:56 -07001168 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
Ying Wangddbcad82011-04-18 11:45:44 -07001169 $(addprefix -isystem ,\
The Android Open Source Project88b60792009-03-03 19:28:42 -08001170 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wangddbcad82011-04-18 11:45:44 -07001171 $(filter-out $(PRIVATE_C_INCLUDES), \
1172 $(HOST_PROJECT_INCLUDES) \
Logan Chiene6f65432013-12-10 19:07:41 +08001173 $(PRIVATE_HOST_C_INCLUDES)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001174 -c \
1175 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001176 $(PRIVATE_HOST_GLOBAL_CFLAGS) \
1177 $(PRIVATE_HOST_GLOBAL_CPPFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001178 ) \
1179 $(PRIVATE_CFLAGS) \
1180 $(PRIVATE_CPPFLAGS) \
1181 $(PRIVATE_DEBUG_CFLAGS) \
Atte Peltomaki60fe9632011-12-21 09:24:09 -08001182 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
The Android Open Source Project88b60792009-03-03 19:28:42 -08001183$(transform-d-to-p)
1184endef
1185
1186
1187###########################################################
1188## Commands for running gcc to compile a host C file
1189###########################################################
1190
1191# $(1): extra flags
1192define transform-host-c-or-s-to-o-no-deps
1193@mkdir -p $(dir $@)
1194$(hide) $(PRIVATE_CC) \
Ying Wangddbcad82011-04-18 11:45:44 -07001195 $(addprefix -I , $(PRIVATE_C_INCLUDES)) \
Andrew Boie85f3b212012-07-11 12:14:56 -07001196 $(shell cat $(PRIVATE_IMPORT_INCLUDES)) \
Ying Wangddbcad82011-04-18 11:45:44 -07001197 $(addprefix -isystem ,\
The Android Open Source Project88b60792009-03-03 19:28:42 -08001198 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Ying Wangddbcad82011-04-18 11:45:44 -07001199 $(filter-out $(PRIVATE_C_INCLUDES), \
1200 $(HOST_PROJECT_INCLUDES) \
Logan Chiene6f65432013-12-10 19:07:41 +08001201 $(PRIVATE_HOST_C_INCLUDES)))) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001202 -c \
1203 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001204 $(PRIVATE_HOST_GLOBAL_CFLAGS) \
Stephen Hines15680292014-11-26 00:53:46 -08001205 $(PRIVATE_HOST_GLOBAL_CONLYFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001206 ) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001207 $(1) \
Atte Peltomaki60fe9632011-12-21 09:24:09 -08001208 -MD -MF $(patsubst %.o,%.d,$@) -o $@ $<
The Android Open Source Project88b60792009-03-03 19:28:42 -08001209endef
1210
1211define transform-host-c-to-o-no-deps
Chirayu Desaiad48df42012-10-13 13:05:29 +05301212@echo -e ${CL_YLW}"host C:"${CL_RST}" $(PRIVATE_MODULE) <= $<"
Ying Wang7429e212012-08-15 10:59:10 -07001213$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_CONLYFLAGS) $(PRIVATE_DEBUG_CFLAGS))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001214endef
1215
1216define transform-host-s-to-o-no-deps
Chirayu Desaiad48df42012-10-13 13:05:29 +05301217@echo -e ${CL_YLW}"host asm:"${CL_RST}" $(PRIVATE_MODULE) <= $<"
The Android Open Source Project88b60792009-03-03 19:28:42 -08001218$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_ASFLAGS))
1219endef
1220
1221define transform-host-c-to-o
1222$(transform-host-c-to-o-no-deps)
1223$(transform-d-to-p)
1224endef
1225
1226define transform-host-s-to-o
1227$(transform-host-s-to-o-no-deps)
1228$(transform-d-to-p)
1229endef
1230
1231###########################################################
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001232## Commands for running gcc to compile a host Objective-C file
1233###########################################################
1234
1235define transform-host-m-to-o-no-deps
Chirayu Desaiad48df42012-10-13 13:05:29 +05301236@echo -e ${CL_YLW}"host ObjC:"${CL_RST}" $(PRIVATE_MODULE) <= $<"
Ying Wang65d78522012-08-10 16:30:42 -07001237$(call transform-host-c-or-s-to-o-no-deps, $(PRIVATE_CFLAGS) $(PRIVATE_DEBUG_CFLAGS))
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001238endef
1239
David 'Digit' Turner5ca286d2011-02-11 16:19:31 +01001240define transform-host-m-to-o
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001241$(transform-host-m-to-o-no-deps)
1242$(transform-d-to-p)
1243endef
1244
Ying Wangfb22a422015-03-10 18:03:11 -07001245
1246###########################################################
1247## Rules to compile a single C/C++ source with ../ in the path
1248###########################################################
1249# Replace "../" in object paths with $(DOTDOT_REPLACEMENT).
1250DOTDOT_REPLACEMENT := dotdot/
1251
1252## Rule to compile a C++ source file with ../ in the path.
1253## Must be called with $(eval).
1254# $(1): the C++ source file in LOCAL_SRC_FILES.
1255# $(2): the additional dependencies.
1256# $(3): the variable name to collect the output object file.
1257define compile-dotdot-cpp-file
1258o := $(intermediates)/$(patsubst %$(LOCAL_CPP_EXTENSION),%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
1259$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2)
1260 $$(transform-$$(PRIVATE_HOST)cpp-to-o)
1261-include $$(o:%.o=%.P)
1262$(3) += $$(o)
1263endef
1264
1265## Rule to compile a C source file with ../ in the path.
1266## Must be called with $(eval).
1267# $(1): the C source file in LOCAL_SRC_FILES.
1268# $(2): the additional dependencies.
1269# $(3): the variable name to collect the output object file.
1270define compile-dotdot-c-file
1271o := $(intermediates)/$(patsubst %.c,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
1272$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2)
1273 $$(transform-$$(PRIVATE_HOST)c-to-o)
1274-include $$(o:%.o=%.P)
1275$(3) += $$(o)
1276endef
1277
1278## Rule to compile a .S source file with ../ in the path.
1279## Must be called with $(eval).
1280# $(1): the .S source file in LOCAL_SRC_FILES.
1281# $(2): the additional dependencies.
1282# $(3): the variable name to collect the output object file.
1283define compile-dotdot-s-file
1284o := $(intermediates)/$(patsubst %.S,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
1285$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2)
1286 $$(transform-$$(PRIVATE_HOST)s-to-o)
1287-include $$(o:%.o=%.P)
1288$(3) += $$(o)
1289endef
1290
1291## Rule to compile a .s source file with ../ in the path.
1292## Must be called with $(eval).
1293# $(1): the .s source file in LOCAL_SRC_FILES.
1294# $(2): the additional dependencies.
1295# $(3): the variable name to collect the output object file.
1296define compile-dotdot-s-file-no-deps
1297o := $(intermediates)/$(patsubst %.s,%.o,$(subst ../,$(DOTDOT_REPLACEMENT),$(1)))
1298$$(o) : $(TOPDIR)$(LOCAL_PATH)/$(1) $(2)
1299 $$(transform-$$(PRIVATE_HOST)s-to-o-no-deps)
1300$(3) += $$(o)
1301endef
1302
David 'Digit' Turner5dbb5292009-05-14 16:00:09 +02001303###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08001304## Commands for running ar
1305###########################################################
1306
Ying Wange4b24eb2010-05-27 11:55:39 -07001307define _concat-if-arg2-not-empty
1308$(if $(2),$(hide) $(1) $(2))
1309endef
1310
1311# Split long argument list into smaller groups and call the command repeatedly
Torne (Richard Coles)bffaef22012-06-15 16:03:52 +01001312# Call the command at least once even if there are no arguments, as otherwise
1313# the output file won't be created.
Ying Wange4b24eb2010-05-27 11:55:39 -07001314#
1315# $(1): the command without arguments
1316# $(2): the arguments
1317define split-long-arguments
Torne (Richard Coles)bffaef22012-06-15 16:03:52 +01001318$(hide) $(1) $(wordlist 1,500,$(2))
Ying Wange4b24eb2010-05-27 11:55:39 -07001319$(call _concat-if-arg2-not-empty,$(1),$(wordlist 501,1000,$(2)))
1320$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1001,1500,$(2)))
1321$(call _concat-if-arg2-not-empty,$(1),$(wordlist 1501,2000,$(2)))
1322$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2001,2500,$(2)))
1323$(call _concat-if-arg2-not-empty,$(1),$(wordlist 2501,3000,$(2)))
1324$(call _concat-if-arg2-not-empty,$(1),$(wordlist 3001,99999,$(2)))
1325endef
1326
Ying Wanga02d3d92011-01-27 18:48:00 -08001327# $(1): the full path of the source static library.
1328define _extract-and-include-single-target-whole-static-lib
Chirayu Desaiad48df42012-10-13 13:05:29 +05301329@echo -e ${CL_YLW}"preparing StaticLib:"${CL_RST}" $(PRIVATE_MODULE) [including $(1)]"
Ying Wanga02d3d92011-01-27 18:48:00 -08001330$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\
1331 rm -rf $$ldir; \
1332 mkdir -p $$ldir; \
Christopher Ferris44203f32015-01-07 17:14:03 -08001333 cp $(1) $$ldir; \
1334 lib_to_include=$$ldir/$(notdir $(1)); \
Ying Wanga02d3d92011-01-27 18:48:00 -08001335 filelist=; \
Christopher Ferris44203f32015-01-07 17:14:03 -08001336 subdir=0; \
Ying Wang6feb6d52014-04-17 10:03:35 -07001337 for f in `$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) t $(1)`; do \
Christopher Ferris44203f32015-01-07 17:14:03 -08001338 if [ -e $$ldir/$$f ]; then \
1339 mkdir $$ldir/$$subdir; \
1340 ext=$$subdir/; \
1341 subdir=$$((subdir+1)); \
1342 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) m $$lib_to_include $$f; \
1343 else \
1344 ext=; \
1345 fi; \
1346 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) p $$lib_to_include $$f > $$ldir/$$ext$$f; \
1347 filelist="$$filelist $$ldir/$$ext$$f"; \
Ying Wanga02d3d92011-01-27 18:48:00 -08001348 done ; \
Ying Wang61d499b2014-01-15 16:02:16 -08001349 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \
1350 $(PRIVATE_ARFLAGS) $@ $$filelist
Ying Wanga02d3d92011-01-27 18:48:00 -08001351
1352endef
1353
Dan Alberte0f44ac2014-05-23 12:26:51 -07001354# $(1): the full path of the source static library.
1355define extract-and-include-whole-static-libs-first
1356$(if $(strip $(1)),
1357@echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(strip $(1))]"
1358$(hide) cp $(1) $@)
1359endef
1360
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001361define extract-and-include-target-whole-static-libs
Dan Alberte0f44ac2014-05-23 12:26:51 -07001362$(call extract-and-include-whole-static-libs-first, $(firstword $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)))
1363$(foreach lib,$(wordlist 2,999,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)), \
Ying Wanga02d3d92011-01-27 18:48:00 -08001364 $(call _extract-and-include-single-target-whole-static-lib, $(lib)))
Dima Zavin46e9bec2009-05-27 19:41:07 -07001365endef
1366
The Android Open Source Project88b60792009-03-03 19:28:42 -08001367# Explicitly delete the archive first so that ar doesn't
1368# try to add to an existing archive.
1369define transform-o-to-static-lib
1370@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001371@rm -f $@
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001372$(extract-and-include-target-whole-static-libs)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301373@echo -e ${CL_GRN}"target StaticLib:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Ying Wang6feb6d52014-04-17 10:03:35 -07001374$(call split-long-arguments,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) \
1375 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \
Ying Wang854607e2015-04-02 18:02:33 -07001376 $(PRIVATE_ARFLAGS) $@,$(PRIVATE_ALL_OBJECTS))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001377endef
1378
1379###########################################################
1380## Commands for running host ar
1381###########################################################
1382
Ying Wanga02d3d92011-01-27 18:48:00 -08001383# $(1): the full path of the source static library.
1384define _extract-and-include-single-host-whole-static-lib
Chirayu Desaiad48df42012-10-13 13:05:29 +05301385@echo -e ${CL_YLW}"preparing StaticLib:"${CL_RST}" $(PRIVATE_MODULE) [including $(1)]"
Ying Wanga02d3d92011-01-27 18:48:00 -08001386$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\
1387 rm -rf $$ldir; \
1388 mkdir -p $$ldir; \
Christopher Ferris44203f32015-01-07 17:14:03 -08001389 cp $(1) $$ldir; \
1390 lib_to_include=$$ldir/$(notdir $(1)); \
Ying Wanga02d3d92011-01-27 18:48:00 -08001391 filelist=; \
Christopher Ferris44203f32015-01-07 17:14:03 -08001392 subdir=0; \
Ying Wang6feb6d52014-04-17 10:03:35 -07001393 for f in `$($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_AR) t $(1) | \grep '\.o$$'`; do \
Christopher Ferris44203f32015-01-07 17:14:03 -08001394 if [ -e $$ldir/$$f ]; then \
1395 mkdir $$ldir/$$subdir; \
1396 ext=$$subdir/; \
1397 subdir=$$((subdir+1)); \
1398 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_AR) m $$lib_to_include $$f; \
1399 else \
1400 ext=; \
1401 fi; \
1402 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_AR) p $$lib_to_include $$f > $$ldir/$$ext$$f; \
1403 filelist="$$filelist $$ldir/$$ext$$f"; \
Ying Wanga02d3d92011-01-27 18:48:00 -08001404 done ; \
Ying Wang6feb6d52014-04-17 10:03:35 -07001405 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_AR) $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_ARFLAGS) \
1406 $(PRIVATE_ARFLAGS) $@ $$filelist
Ying Wanga02d3d92011-01-27 18:48:00 -08001407
1408endef
1409
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001410define extract-and-include-host-whole-static-libs
Dan Alberte0f44ac2014-05-23 12:26:51 -07001411$(call extract-and-include-whole-static-libs-first, $(firstword $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)))
1412$(foreach lib,$(wordlist 2,999,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)), \
Ying Wanga02d3d92011-01-27 18:48:00 -08001413 $(call _extract-and-include-single-host-whole-static-lib, $(lib)))
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001414endef
1415
The Android Open Source Project88b60792009-03-03 19:28:42 -08001416# Explicitly delete the archive first so that ar doesn't
1417# try to add to an existing archive.
1418define transform-host-o-to-static-lib
1419@mkdir -p $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001420@rm -f $@
Dan Bornstein3d02eac2009-10-21 11:12:56 -07001421$(extract-and-include-host-whole-static-libs)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301422@echo -e ${CL_YLW}"host StaticLib:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Ying Wang6feb6d52014-04-17 10:03:35 -07001423$(call split-long-arguments,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_AR) \
1424 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_ARFLAGS) \
Ying Wang854607e2015-04-02 18:02:33 -07001425 $(PRIVATE_ARFLAGS) $@,$(PRIVATE_ALL_OBJECTS))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001426endef
1427
1428
1429###########################################################
1430## Commands for running gcc to link a shared library or package
1431###########################################################
1432
1433# ld just seems to be so finicky with command order that we allow
1434# it to be overriden en-masse see combo/linux-arm.make for an example.
1435ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1436define transform-host-o-to-shared-lib-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001437$(hide) $(PRIVATE_CXX) \
Ying Wang6feb6d52014-04-17 10:03:35 -07001438 -Wl,-rpath-link=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_OUT_INTERMEDIATE_LIBRARIES) \
1439 -Wl,-rpath,\$$ORIGIN/../$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_OUT_SHARED_LIBRARIES)) \
Ying Wang4fe7bfd2015-06-01 10:43:29 -07001440 -Wl,-rpath,\$$ORIGIN/$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_OUT_SHARED_LIBRARIES)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001441 -shared -Wl,-soname,$(notdir $@) \
Ying Wang6feb6d52014-04-17 10:03:35 -07001442 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_LD_DIRS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001443 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001444 $(PRIVATE_HOST_GLOBAL_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001445 ) \
Torne (Richard Coles)a424bf72014-02-12 14:24:41 +00001446 $(PRIVATE_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001447 $(PRIVATE_ALL_OBJECTS) \
1448 -Wl,--whole-archive \
1449 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1450 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001451 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001452 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001453 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
Dan Albert43e128a2015-01-23 16:12:57 -08001454 $(if $(filter true,$(NATIVE_COVERAGE)),-lgcov) \
Dan Albert343ed672015-01-25 16:20:57 -08001455 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_HOST_LIBPROFILE_RT)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001456 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1457 -o $@ \
1458 $(PRIVATE_LDLIBS)
1459endef
1460endif
1461
1462define transform-host-o-to-shared-lib
1463@mkdir -p $(dir $@)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301464@echo -e ${CL_YLW}"host SharedLib:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001465$(transform-host-o-to-shared-lib-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001466endef
1467
1468define transform-host-o-to-package
1469@mkdir -p $(dir $@)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301470@echo -e ${CL_YLW}"host Package:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001471$(transform-host-o-to-shared-lib-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001472endef
1473
1474
1475###########################################################
1476## Commands for running gcc to link a shared library or package
1477###########################################################
1478
The Android Open Source Project88b60792009-03-03 19:28:42 -08001479define transform-o-to-shared-lib-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001480$(hide) $(PRIVATE_CXX) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001481 -nostdlib -Wl,-soname,$(notdir $@) \
1482 -Wl,--gc-sections \
Logan Chiene481e7d2015-01-25 21:15:12 +08001483 $(if $(filter true,$(PRIVATE_CLANG)),-shared,-Wl$(comma)-shared) \
Ying Wang1a081002010-07-13 14:55:47 -07001484 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001485 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_SO_O)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001486 $(PRIVATE_ALL_OBJECTS) \
1487 -Wl,--whole-archive \
Ying Wang80e6cce2011-01-24 23:25:36 -08001488 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001489 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001490 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001491 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001492 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
Dan Albert91f713a2015-03-31 15:21:30 -07001493 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBGCOV)) \
Dan Albert343ed672015-01-25 16:20:57 -08001494 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBPROFILE_RT)) \
Dan Albert91f713a2015-03-31 15:21:30 -07001495 $(PRIVATE_TARGET_LIBATOMIC) \
1496 $(PRIVATE_TARGET_LIBGCC) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001497 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1498 -o $@ \
Dan Alberte088c0d2014-11-13 10:15:46 -08001499 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
1500 $(PRIVATE_LDFLAGS) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001501 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_SO_O)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001502 $(PRIVATE_LDLIBS)
1503endef
The Android Open Source Project88b60792009-03-03 19:28:42 -08001504
1505define transform-o-to-shared-lib
1506@mkdir -p $(dir $@)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301507@echo -e ${CL_GRN}"target SharedLib:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Dan Alberte088c0d2014-11-13 10:15:46 -08001508$(transform-o-to-shared-lib-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001509endef
1510
1511
1512###########################################################
1513## Commands for filtering a target executable or library
1514###########################################################
1515
Ying Wangce1c5962014-03-28 17:24:39 -07001516ifneq ($(TARGET_BUILD_VARIANT),user)
1517 TARGET_STRIP_EXTRA = && $(PRIVATE_OBJCOPY) --add-gnu-debuglink=$< $@
1518 TARGET_STRIP_KEEP_SYMBOLS_EXTRA = --add-gnu-debuglink=$<
1519endif
1520
The Android Open Source Project88b60792009-03-03 19:28:42 -08001521define transform-to-stripped
1522@mkdir -p $(dir $@)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301523@echo -e ${CL_GRN}"target Strip:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Ying Wangbfb52a22014-08-20 17:12:32 -07001524$(hide) $(PRIVATE_STRIP) --strip-all $< -o $@ \
1525 $(if $(PRIVATE_NO_DEBUGLINK),,$(TARGET_STRIP_EXTRA))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001526endef
1527
Christopher Ferrisa6e2f932014-03-18 14:50:09 -07001528define transform-to-stripped-keep-symbols
1529@mkdir -p $(dir $@)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301530@echo -e ${CL_GRN}"target Strip (keep symbols):"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Ying Wangce1c5962014-03-28 17:24:39 -07001531$(hide) $(PRIVATE_OBJCOPY) \
1532 `$(PRIVATE_READELF) -S $< | awk '/.debug_/ {print "-R " $$2}' | xargs` \
1533 $(TARGET_STRIP_KEEP_SYMBOLS_EXTRA) $< $@
Christopher Ferrisa6e2f932014-03-18 14:50:09 -07001534endef
1535
Dmitriy Ivanov4c2d1a62015-04-20 16:59:05 -07001536###########################################################
1537## Commands for packing a target executable or library
1538###########################################################
1539
1540define pack-elf-relocations
1541$(copy-file-to-target)
1542@echo "target Pack Relocations: $(PRIVATE_MODULE) ($@)"
1543$(hide) $(RELOCATION_PACKER) $@
1544endef
The Android Open Source Project88b60792009-03-03 19:28:42 -08001545
1546###########################################################
1547## Commands for running gcc to link an executable
1548###########################################################
1549
The Android Open Source Project88b60792009-03-03 19:28:42 -08001550define transform-o-to-executable-inner
Dan Alberte088c0d2014-11-13 10:15:46 -08001551$(hide) $(PRIVATE_CXX) -pie \
1552 -nostdlib -Bdynamic \
1553 -Wl,-dynamic-linker,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_LINKER) \
1554 -Wl,--gc-sections \
1555 -Wl,-z,nocopyreloc \
Ying Wangc6ffc002012-09-25 17:52:10 -07001556 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
Ying Wang9fb35262014-02-21 16:17:05 -08001557 -Wl,-rpath-link=$(PRIVATE_TARGET_OUT_INTERMEDIATE_LIBRARIES) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001558 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001559 $(PRIVATE_ALL_OBJECTS) \
1560 -Wl,--whole-archive \
1561 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1562 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001563 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001564 $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001565 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
Dan Albert91f713a2015-03-31 15:21:30 -07001566 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBGCOV)) \
Dan Albert343ed672015-01-25 16:20:57 -08001567 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBPROFILE_RT)) \
Dan Albert91f713a2015-03-31 15:21:30 -07001568 $(PRIVATE_TARGET_LIBATOMIC) \
1569 $(PRIVATE_TARGET_LIBGCC) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001570 $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
1571 -o $@ \
Dan Alberte088c0d2014-11-13 10:15:46 -08001572 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
1573 $(PRIVATE_LDFLAGS) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001574 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001575 $(PRIVATE_LDLIBS)
1576endef
The Android Open Source Project88b60792009-03-03 19:28:42 -08001577
1578define transform-o-to-executable
1579@mkdir -p $(dir $@)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301580@echo -e ${CL_GRN}"target Executable:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Dan Alberte088c0d2014-11-13 10:15:46 -08001581$(transform-o-to-executable-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001582endef
1583
1584
1585###########################################################
Dan Alberte088c0d2014-11-13 10:15:46 -08001586## Commands for linking a static executable. In practice,
1587## we only use this on arm, so the other platforms don't
1588## have transform-o-to-static-executable defined.
Chih-Hung Hsieh69b1fe62015-01-20 11:00:20 -08001589## Clang driver needs -static to create static executable.
1590## However, bionic/linker uses -shared to overwrite.
1591## Linker for x86 targets does not allow coexistance of -static and -shared,
1592## so we add -static only if -shared is not used.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001593###########################################################
1594
The Android Open Source Project88b60792009-03-03 19:28:42 -08001595define transform-o-to-static-executable-inner
Dan Alberte088c0d2014-11-13 10:15:46 -08001596$(hide) $(PRIVATE_CXX) \
1597 -nostdlib -Bstatic \
Chih-Hung Hsieh69b1fe62015-01-20 11:00:20 -08001598 $(if $(filter $(PRIVATE_LDFLAGS),-shared),,-static) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001599 -Wl,--gc-sections \
1600 -o $@ \
1601 $(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
1602 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_STATIC_O)) \
1603 $(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
1604 $(PRIVATE_LDFLAGS) \
1605 $(PRIVATE_ALL_OBJECTS) \
1606 -Wl,--whole-archive \
1607 $(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1608 -Wl,--no-whole-archive \
1609 $(call normalize-target-libraries,$(filter-out %libcompiler_rt.a,$(filter-out %libc_nomalloc.a,$(filter-out %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))))) \
1610 -Wl,--start-group \
1611 $(call normalize-target-libraries,$(filter %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
1612 $(call normalize-target-libraries,$(filter %libc_nomalloc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001613 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBGCOV)) \
Dan Albert343ed672015-01-25 16:20:57 -08001614 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBPROFILE_RT)) \
1615 $(PRIVATE_TARGET_LIBATOMIC) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001616 $(call normalize-target-libraries,$(filter %libcompiler_rt.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
Dan Albert741b36e2014-11-13 21:24:04 -08001617 $(PRIVATE_TARGET_LIBGCC) \
Dan Alberte088c0d2014-11-13 10:15:46 -08001618 -Wl,--end-group \
1619 $(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001620endef
The Android Open Source Project88b60792009-03-03 19:28:42 -08001621
1622define transform-o-to-static-executable
1623@mkdir -p $(dir $@)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301624@echo -e ${CL_GRN}"target StaticExecutable:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Dan Alberte088c0d2014-11-13 10:15:46 -08001625$(transform-o-to-static-executable-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001626endef
1627
1628
1629###########################################################
1630## Commands for running gcc to link a host executable
1631###########################################################
Ying Wangfaf3d5e2014-04-04 14:37:33 -07001632ifdef BUILD_HOST_static
1633HOST_FPIE_FLAGS :=
1634else
Dan Albert4803ce22014-08-06 12:36:46 -07001635HOST_FPIE_FLAGS := -pie
Stephen Hinesa503fb32014-10-02 00:51:11 -07001636# Force the correct entry point to workaround a bug in binutils that manifests with -pie
1637ifeq ($(HOST_OS),windows)
1638HOST_FPIE_FLAGS += -Wl,-e_mainCRTStartup
1639endif
Ying Wangfaf3d5e2014-04-04 14:37:33 -07001640endif
The Android Open Source Project88b60792009-03-03 19:28:42 -08001641
1642ifneq ($(HOST_CUSTOM_LD_COMMAND),true)
1643define transform-host-o-to-executable-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001644$(hide) $(PRIVATE_CXX) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001645 $(PRIVATE_ALL_OBJECTS) \
1646 -Wl,--whole-archive \
1647 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
1648 -Wl,--no-whole-archive \
Ying Wangfcdabd42011-04-25 14:22:41 -07001649 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001650 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -07001651 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
Dan Albert43e128a2015-01-23 16:12:57 -08001652 $(if $(filter true,$(NATIVE_COVERAGE)),-lgcov) \
Dan Albert343ed672015-01-25 16:20:57 -08001653 $(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_HOST_LIBPROFILE_RT)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001654 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
Ying Wang6feb6d52014-04-17 10:03:35 -07001655 -Wl,-rpath-link=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_OUT_INTERMEDIATE_LIBRARIES) \
1656 -Wl,-rpath,\$$ORIGIN/../$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_OUT_SHARED_LIBRARIES)) \
Ying Wang4fe7bfd2015-06-01 10:43:29 -07001657 -Wl,-rpath,\$$ORIGIN/$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_OUT_SHARED_LIBRARIES)) \
Ying Wang6feb6d52014-04-17 10:03:35 -07001658 $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_LD_DIRS) \
Conley Owensd9e7d252011-11-10 09:57:40 -08001659 $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
Logan Chiene6f65432013-12-10 19:07:41 +08001660 $(PRIVATE_HOST_GLOBAL_LDFLAGS) \
Conley Owensd9e7d252011-11-10 09:57:40 -08001661 ) \
Torne (Richard Coles)a424bf72014-02-12 14:24:41 +00001662 $(PRIVATE_LDFLAGS) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001663 -o $@ \
1664 $(PRIVATE_LDLIBS)
1665endef
1666endif
1667
1668define transform-host-o-to-executable
1669@mkdir -p $(dir $@)
Chirayu Desaiad48df42012-10-13 13:05:29 +05301670@echo -e ${CL_YLW}"host Executable:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Ying Wang3a7e4cc2011-01-28 14:14:47 -08001671$(transform-host-o-to-executable-inner)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001672endef
1673
1674
1675###########################################################
1676## Commands for running javac to make .class files
1677###########################################################
1678
Ying Wangb79e8772015-09-19 10:56:35 -07001679# Add BUILD_NUMBER to apps default version name if it's unbundled build.
1680ifdef TARGET_BUILD_APPS
1681APPS_DEFAULT_VERSION_NAME := $(PLATFORM_VERSION)-$(BUILD_NUMBER)
1682else
1683APPS_DEFAULT_VERSION_NAME := $(PLATFORM_VERSION)
1684endif
The Android Open Source Project88b60792009-03-03 19:28:42 -08001685
1686# TODO: Right now we generate the asset resources twice, first as part
1687# of generating the Java classes, then at the end when packaging the final
1688# assets. This should be changed to do one of two things: (1) Don't generate
1689# any resource files the first time, only create classes during that stage;
1690# or (2) Don't use the -c flag with the second stage, instead taking the
1691# resource files from the first stage as additional input. My original intent
1692# was to use approach (2), but this requires a little more work in the tool.
1693# Maybe we should just use approach (1).
1694
1695# This rule creates the R.java and Manifest.java files, both of which
Ying Wang4f1ab922011-03-15 13:19:30 -07001696# are PRODUCT-neutral. Don't pass PRIVATE_PRODUCT_AAPT_CONFIG to this invocation.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001697define create-resource-java-files
1698@mkdir -p $(PRIVATE_SOURCE_INTERMEDIATES_DIR)
1699@mkdir -p $(dir $(PRIVATE_RESOURCE_PUBLICS_OUTPUT))
Ying Wangc61d5932010-03-10 16:02:42 -08001700$(hide) $(AAPT) package $(PRIVATE_AAPT_FLAGS) -m \
Ying Wang4f1ab922011-03-15 13:19:30 -07001701 $(eval # PRIVATE_PRODUCT_AAPT_CONFIG is intentionally missing-- see comment.) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001702 $(addprefix -J , $(PRIVATE_SOURCE_INTERMEDIATES_DIR)) \
1703 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
1704 $(addprefix -P , $(PRIVATE_RESOURCE_PUBLICS_OUTPUT)) \
1705 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
1706 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
Dianne Hackborn9bd54042009-05-15 18:01:20 -07001707 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
Joe Onorato2daa2b32009-08-30 13:39:24 -07001708 $(addprefix -G , $(PRIVATE_PROGUARD_OPTIONS_FILE)) \
Ying Wangbb9c2302011-04-08 17:27:35 -07001709 $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
1710 $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
Ying Wangb79e8772015-09-19 10:56:35 -07001711 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,--version-code $(PLATFORM_SDK_VERSION)) \
1712 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,--version-name $(APPS_DEFAULT_VERSION_NAME)) \
Ying Wang8c254822010-03-16 16:13:56 -07001713 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Adrian Roos6784cae2015-06-01 18:24:41 -07001714 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \
1715 --skip-symbols-without-default-localization
The Android Open Source Project88b60792009-03-03 19:28:42 -08001716endef
1717
1718ifeq ($(HOST_OS),windows)
1719xlint_unchecked :=
1720else
Jeffrey Chyan7adbf972010-07-07 13:42:19 -05001721xlint_unchecked := -Xlint:unchecked
The Android Open Source Project88b60792009-03-03 19:28:42 -08001722endif
1723
1724# emit-line, <word list>, <output file>
1725define emit-line
1726 $(if $(1),echo -n '$(strip $(1)) ' >> $(2))
1727endef
1728
1729# dump-words-to-file, <word list>, <output file>
1730define dump-words-to-file
1731 @rm -f $(2)
1732 @$(call emit-line,$(wordlist 1,200,$(1)),$(2))
1733 @$(call emit-line,$(wordlist 201,400,$(1)),$(2))
1734 @$(call emit-line,$(wordlist 401,600,$(1)),$(2))
1735 @$(call emit-line,$(wordlist 601,800,$(1)),$(2))
1736 @$(call emit-line,$(wordlist 801,1000,$(1)),$(2))
1737 @$(call emit-line,$(wordlist 1001,1200,$(1)),$(2))
1738 @$(call emit-line,$(wordlist 1201,1400,$(1)),$(2))
1739 @$(call emit-line,$(wordlist 1401,1600,$(1)),$(2))
1740 @$(call emit-line,$(wordlist 1601,1800,$(1)),$(2))
1741 @$(call emit-line,$(wordlist 1801,2000,$(1)),$(2))
1742 @$(call emit-line,$(wordlist 2001,2200,$(1)),$(2))
1743 @$(call emit-line,$(wordlist 2201,2400,$(1)),$(2))
1744 @$(call emit-line,$(wordlist 2401,2600,$(1)),$(2))
1745 @$(call emit-line,$(wordlist 2601,2800,$(1)),$(2))
1746 @$(call emit-line,$(wordlist 2801,3000,$(1)),$(2))
1747 @$(call emit-line,$(wordlist 3001,3200,$(1)),$(2))
1748 @$(call emit-line,$(wordlist 3201,3400,$(1)),$(2))
1749 @$(call emit-line,$(wordlist 3401,3600,$(1)),$(2))
1750 @$(call emit-line,$(wordlist 3601,3800,$(1)),$(2))
1751 @$(call emit-line,$(wordlist 3801,4000,$(1)),$(2))
Jesse Wilson72c941a2010-05-04 16:33:49 -07001752 @$(call emit-line,$(wordlist 4001,4200,$(1)),$(2))
1753 @$(call emit-line,$(wordlist 4201,4400,$(1)),$(2))
1754 @$(call emit-line,$(wordlist 4401,4600,$(1)),$(2))
1755 @$(call emit-line,$(wordlist 4601,4800,$(1)),$(2))
1756 @$(call emit-line,$(wordlist 4801,5000,$(1)),$(2))
1757 @$(if $(wordlist 5001,5002,$(1)),$(error Too many words ($(words $(1)))))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001758endef
1759
1760# For a list of jar files, unzip them to a specified directory,
1761# but make sure that no META-INF files come along for the ride.
1762#
1763# $(1): files to unzip
1764# $(2): destination directory
1765define unzip-jar-files
1766 $(hide) for f in $(1); \
1767 do \
1768 if [ ! -f $$f ]; then \
1769 echo Missing file $$f; \
1770 exit 1; \
1771 fi; \
Sriram Ramanf1a55f82009-06-09 15:08:29 -07001772 unzip -qo $$f -d $(2); \
Ying Wang3a6f7582012-08-30 12:59:42 -07001773 done \
1774 $(if $(PRIVATE_DONT_DELETE_JAR_META_INF),,;rm -rf $(2)/META-INF)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001775endef
1776
Brian Carlstrom78269512010-12-10 12:10:24 -08001777# Common definition to invoke javac on the host and target.
1778#
1779# Some historical notes:
1780# - below we write the list of java files to java-source-list to avoid argument
1781# list length problems with Cygwin
1782# - we filter out duplicate java file names because eclipse's compiler
1783# doesn't like them.
1784#
1785# $(1): javac
1786# $(2): bootclasspath
1787define compile-java
Joe Onorato64d85d02009-04-09 19:31:12 -07001788$(hide) rm -f $@
1789$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
Brian Carlstrom78269512010-12-10 12:10:24 -08001790$(hide) mkdir -p $(dir $@)
Joe Onorato64d85d02009-04-09 19:31:12 -07001791$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
Brian Carlstrom78269512010-12-10 12:10:24 -08001792$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES),$(PRIVATE_CLASS_INTERMEDIATES_DIR))
Ying Wang015edd22011-01-20 15:01:56 -08001793$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list)
Joe Onorato64d85d02009-04-09 19:31:12 -07001794$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
Ying Wanga3b75932013-08-14 16:59:00 -07001795 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list; \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001796fi
Ying Wang884738e2015-05-08 18:51:00 +00001797$(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \
1798 | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
1799$(hide) if [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
Ying Wange109a1d2011-12-12 17:52:03 -08001800 $(1) -encoding UTF-8 \
Brian Carlstrom78269512010-12-10 12:10:24 -08001801 $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) \
Ying Wang057eba02012-10-18 10:54:49 -07001802 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
Brian Carlstrom78269512010-12-10 12:10:24 -08001803 $(2) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001804 $(addprefix -classpath ,$(strip \
1805 $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \
Ying Wang057eba02012-10-18 10:54:49 -07001806 $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08001807 -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
Brian Carlstrom78269512010-12-10 12:10:24 -08001808 $(PRIVATE_JAVACFLAGS) \
Ying Wang015edd22011-01-20 15:01:56 -08001809 \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \
nuclearmistake451a31b2014-04-27 21:59:42 -04001810 2>$(PRIVATE_CLASS_INTERMEDIATES_DIR)/stderr \
nuclearmistake73c9e722014-05-15 10:30:26 -04001811 && ( [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stderr ] && \
1812 echo -e ${CL_YLW}"`cat $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stderr`"${CL_RST} 1>&2; \
1813 rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stderr ) \
1814 || ( [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stderr ] && \
nuclearmistake451a31b2014-04-27 21:59:42 -04001815 echo -e ${CL_RED}"`cat $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stderr`"${CL_RST} 1>&2; \
nuclearmistake73c9e722014-05-15 10:30:26 -04001816 rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR); exit 41 ) \
Ying Wange109a1d2011-12-12 17:52:03 -08001817fi
Joe Onorato0eccce92011-10-30 21:37:35 -07001818$(if $(PRIVATE_JAVA_LAYERS_FILE), $(hide) build/tools/java-layers.py \
1819 $(PRIVATE_JAVA_LAYERS_FILE) \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq,)
Ying Wang015edd22011-01-20 15:01:56 -08001820$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list
1821$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
Ying Wang5758b8e2011-12-15 16:36:55 -08001822$(if $(PRIVATE_JAR_EXCLUDE_FILES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
1823 -name $(word 1, $(PRIVATE_JAR_EXCLUDE_FILES)) \
1824 $(addprefix -o -name , $(wordlist 2, 999, $(PRIVATE_JAR_EXCLUDE_FILES))) \
1825 | xargs rm -rf)
Jeff Brown4c4aa992014-05-23 18:41:19 -07001826$(if $(PRIVATE_JAR_PACKAGES), \
1827 $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -mindepth 1 -type f \
1828 $(foreach pkg, $(PRIVATE_JAR_PACKAGES), \
1829 -not -path $(PRIVATE_CLASS_INTERMEDIATES_DIR)/$(subst .,/,$(pkg))/\*) -delete ; \
1830 find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -empty -delete)
1831$(if $(PRIVATE_JAR_EXCLUDE_PACKAGES), $(hide) rm -rf \
1832 $(foreach pkg, $(PRIVATE_JAR_EXCLUDE_PACKAGES), \
1833 $(PRIVATE_CLASS_INTERMEDIATES_DIR)/$(subst .,/,$(pkg))))
Ying Wanga3b75932013-08-14 16:59:00 -07001834$(if $(PRIVATE_RMTYPEDEFS), $(hide) $(RMTYPEDEFS) -v $(PRIVATE_CLASS_INTERMEDIATES_DIR))
Guang Zhu5c9a1a42013-09-24 19:05:52 -07001835$(if $(PRIVATE_JAR_MANIFEST), \
1836 $(hide) sed -e 's/%BUILD_NUMBER%/$(BUILD_NUMBER)/' \
1837 $(PRIVATE_JAR_MANIFEST) > $(dir $@)/manifest.mf && \
1838 jar -cfm $@ $(dir $@)/manifest.mf \
1839 -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) ., \
1840 $(hide) jar -cf $@ -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .)
Ying Wang33360dd2015-01-14 14:23:56 -08001841$(if $(PRIVATE_EXTRA_JAR_ARGS),$(call add-java-resources-to,$@))
Brian Carlstrom78269512010-12-10 12:10:24 -08001842endef
1843
1844define transform-java-to-classes.jar
Chirayu Desaiad48df42012-10-13 13:05:29 +05301845@echo -e ${CL_GRN}"target Java:"${CL_RST}" $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
Brian Carlstrom78269512010-12-10 12:10:24 -08001846$(call compile-java,$(TARGET_JAVAC),$(PRIVATE_BOOTCLASSPATH))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001847endef
1848
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001849# Invoke Jack to compile java from source to dex and jack files.
1850#
1851# Some historical notes:
1852# - below we write the list of java files to java-source-list to avoid argument
1853# list length problems with Cygwin
1854# - we filter out duplicate java file names because Jack doesn't like them.
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001855define jack-java-to-dex
1856$(hide) rm -f $@
1857$(hide) rm -f $(PRIVATE_CLASSES_JACK)
1858$(hide) rm -rf $(PRIVATE_JACK_INTERMEDIATES_DIR)
1859$(hide) mkdir -p $(dir $@)
1860$(hide) mkdir -p $(dir $(PRIVATE_CLASSES_JACK))
1861$(hide) mkdir -p $(PRIVATE_JACK_INTERMEDIATES_DIR)
Yohann Roussel37822c42015-01-09 10:36:40 +01001862$(if $(PRIVATE_JACK_INCREMENTAL_DIR),$(hide) mkdir -p $(PRIVATE_JACK_INCREMENTAL_DIR))
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001863$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list)
1864$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
1865 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list; \
1866fi
Ying Wang884738e2015-05-08 18:51:00 +00001867$(hide) tr ' ' '\n' < $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list \
1868 | sort -u > $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001869$(if $(PRIVATE_JACK_PROGUARD_FLAGS), \
1870 $(hide) echo -basedirectory $(CURDIR) > $@.flags; \
1871 echo $(PRIVATE_JACK_PROGUARD_FLAGS) >> $@.flags; \
1872)
Ying Wang33360dd2015-01-14 14:23:56 -08001873$(if $(PRIVATE_EXTRA_JAR_ARGS),
1874 $(hide) mkdir -p $@.res.tmp
1875 $(hide) $(call create-empty-package-at,$@.res.tmp.zip)
1876 $(hide) $(call add-java-resources-to,$@.res.tmp.zip)
1877 $(hide) $(call unzip-jar-files,$@.res.tmp.zip,$@.res.tmp)
1878 $(hide) rm $@.res.tmp.zip)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001879$(hide) if [ -s $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
1880 export tmpEcjArg="@$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq"; \
1881else \
1882 export tmpEcjArg=""; \
1883fi; \
Yohann Roussel28096662015-02-02 12:18:20 +01001884$(call call-jack,$(PRIVATE_JACK_VM_ARGS),$(PRIVATE_JACK_EXTRA_ARGS)) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001885 $(strip $(PRIVATE_JACK_FLAGS)) \
1886 $(strip $(PRIVATE_JACK_DEBUG_FLAGS)) \
1887 $(if $(NO_OPTIMIZE_DX), \
1888 -D jack.dex.optimize="false") \
Yohann Roussel5b2c6e22015-05-20 17:52:15 +02001889 $(if $(PRIVATE_RMTYPEDEFS), \
1890 -D jack.android.remove-typedef="true") \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001891 $(addprefix --classpath ,$(strip \
1892 $(call normalize-path-list,$(PRIVATE_BOOTCLASSPATH_JAVA_LIBRARIES) $(PRIVATE_ALL_JACK_LIBRARIES)))) \
1893 $(addprefix --import ,$(call reverse-list,$(PRIVATE_STATIC_JACK_LIBRARIES))) \
Ying Wang33360dd2015-01-14 14:23:56 -08001894 $(if $(PRIVATE_EXTRA_JAR_ARGS),--import-resource $@.res.tmp) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001895 -D jack.import.resource.policy=keep-first \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001896 -D jack.import.type.policy=keep-first \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001897 --output-jack $(PRIVATE_CLASSES_JACK) \
1898 -D jack.java.source.version=1.7 \
Yohann Roussel37822c42015-01-09 10:36:40 +01001899 $(if $(PRIVATE_JACK_INCREMENTAL_DIR),--incremental-folder $(PRIVATE_JACK_INCREMENTAL_DIR)) \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001900 --output-dex $(PRIVATE_JACK_INTERMEDIATES_DIR) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001901 $(addprefix --config-jarjar ,$(strip $(PRIVATE_JARJAR_RULES))) \
1902 $(if $(PRIVATE_JACK_PROGUARD_FLAGS),--config-proguard $@.flags) \
1903 $$tmpEcjArg \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001904 || ( rm -rf $(PRIVATE_CLASSES_JACK); rm -rf $(PRIVATE_JACK_INTERMEDIATES_DIR); exit 41 )
1905$(hide) mv $(PRIVATE_JACK_INTERMEDIATES_DIR)/classes*.dex $(dir $@)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001906$(hide) rm -f $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list
Ying Wang33360dd2015-01-14 14:23:56 -08001907$(if $(PRIVATE_EXTRA_JAR_ARGS),$(hide) rm -rf $@.res.tmp)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001908$(hide) mv $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq $(PRIVATE_JACK_INTERMEDIATES_DIR).java-source-list
1909$(if $(PRIVATE_JAR_PACKAGES), $(hide) echo unsupported options PRIVATE_JAR_PACKAGES in $@; exit 53)
1910$(if $(PRIVATE_JAR_EXCLUDE_PACKAGES), $(hide) echo unsupported options JAR_EXCLUDE_PACKAGES in $@; exit 53)
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001911$(if $(PRIVATE_JAR_MANIFEST), $(hide) echo unsupported options JAR_MANIFEST in $@; exit 53)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001912endef
1913
1914define transform-jar-to-jack
1915 $(hide) mkdir -p $(dir $@)
Yohann Roussel801f2c42015-03-03 17:14:09 +01001916 $(JILL) $(PRIVATE_JILL_FLAGS) --output $@.tmpjill.jack $<
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001917 $(hide) mkdir -p $@.tmpjill.res
1918 $(hide) $(call unzip-jar-files,$<,$@.tmpjill.res)
1919 $(hide) find $@.tmpjill.res -iname "*.class" -delete
Yohann Roussel28096662015-02-02 12:18:20 +01001920 $(hide) $(call call-jack,$(PRIVATE_JACK_VM_ARGS),$(PRIVATE_JACK_EXTRA_ARGS)) \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001921 -D jack.import.resource.policy=keep-first \
1922 -D jack.import.type.policy=keep-first \
1923 --import $@.tmpjill.jack \
1924 --import-resource $@.tmpjill.res \
1925 --output-jack $@
1926 $(hide) rm -rf $@.tmpjill.res
1927 $(hide) rm $@.tmpjill.jack
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001928endef
1929
1930
1931# Invoke Jack to compile java from source to jack files without shrink or obfuscation.
1932#
1933# Some historical notes:
1934# - below we write the list of java files to java-source-list to avoid argument
1935# list length problems with Cygwin
1936# - we filter out duplicate java file names because Jack doesn't like them.
1937define java-to-jack
1938$(hide) rm -f $@
1939$(hide) rm -rf $(PRIVATE_JACK_INTERMEDIATES_DIR)
1940$(hide) mkdir -p $(dir $@)
1941$(hide) mkdir -p $(PRIVATE_JACK_INTERMEDIATES_DIR)
Yohann Roussel37822c42015-01-09 10:36:40 +01001942$(if $(PRIVATE_JACK_INCREMENTAL_DIR),$(hide) mkdir -p $(PRIVATE_JACK_INCREMENTAL_DIR))
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001943$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list)
1944$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
1945 find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list; \
1946fi
Ying Wang884738e2015-05-08 18:51:00 +00001947$(hide) tr ' ' '\n' < $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list \
1948 | sort -u > $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001949$(if $(PRIVATE_JACK_PROGUARD_FLAGS), \
1950 $(hide) echo -basedirectory $(CURDIR) > $@.flags; \
1951 echo $(PRIVATE_JACK_PROGUARD_FLAGS) >> $@.flags; \
1952)
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001953$(if $(PRIVATE_EXTRA_JAR_ARGS),
1954 $(hide) mkdir -p $@.res.tmp
1955 $(hide) $(call create-empty-package-at,$@.res.tmp.zip)
1956 $(hide) $(call add-java-resources-to,$@.res.tmp.zip)
Yohann Roussel5dd3e1d2015-01-14 16:21:39 +01001957 $(hide) unzip -qo $@.res.tmp.zip -d $@.res.tmp
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001958 $(hide) rm $@.res.tmp.zip)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001959$(hide) if [ -s $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
1960 export tmpEcjArg="@$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq"; \
1961else \
1962 export tmpEcjArg=""; \
1963fi; \
Yohann Roussel28096662015-02-02 12:18:20 +01001964$(call call-jack,$(PRIVATE_JACK_VM_ARGS),$(PRIVATE_JACK_EXTRA_ARGS)) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001965 $(strip $(PRIVATE_JACK_FLAGS)) \
1966 $(strip $(PRIVATE_JACK_DEBUG_FLAGS)) \
1967 $(if $(NO_OPTIMIZE_DX), \
1968 -D jack.dex.optimize="false") \
1969 $(addprefix --classpath ,$(strip \
1970 $(call normalize-path-list,$(PRIVATE_BOOTCLASSPATH_JAVA_LIBRARIES) $(PRIVATE_ALL_JACK_LIBRARIES)))) \
1971 $(addprefix --import ,$(call reverse-list,$(PRIVATE_STATIC_JACK_LIBRARIES))) \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001972 $(if $(PRIVATE_EXTRA_JAR_ARGS),--import-resource $@.res.tmp) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001973 -D jack.import.resource.policy=keep-first \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001974 -D jack.import.type.policy=keep-first \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001975 -D jack.java.source.version=1.7 \
Yohann Roussel37822c42015-01-09 10:36:40 +01001976 $(if $(PRIVATE_JACK_INCREMENTAL_DIR),--incremental-folder $(PRIVATE_JACK_INCREMENTAL_DIR)) \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001977 --output-jack $@ \
1978 $(addprefix --config-jarjar ,$(strip $(PRIVATE_JARJAR_RULES))) \
1979 $(if $(PRIVATE_JACK_PROGUARD_FLAGS),--config-proguard $@.flags) \
1980 $$tmpEcjArg \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001981 || ( rm -f $@ ; exit 41 )
1982$(hide) rm -f $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list
1983$(if $(PRIVATE_EXTRA_JAR_ARGS),$(hide) rm -rf $@.res.tmp)
1984$(hide) mv $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq $(PRIVATE_JACK_INTERMEDIATES_DIR).java-source-list
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001985$(if $(PRIVATE_JAR_PACKAGES), $(hide) echo unsupported options PRIVATE_JAR_PACKAGES in $@; exit 53)
1986$(if $(PRIVATE_JAR_EXCLUDE_PACKAGES), $(hide) echo unsupported options JAR_EXCLUDE_PACKAGES in $@; exit 53)
Yohann Roussel22c3fa62014-11-19 14:01:06 +01001987$(if $(PRIVATE_JAR_MANIFEST), $(hide) echo unsupported options JAR_MANIFEST in $@; exit 53)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02001988endef
1989
The Android Open Source Project88b60792009-03-03 19:28:42 -08001990define transform-classes.jar-to-emma
1991$(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \
Guang Zhu155afe32010-03-10 15:48:03 -08001992 $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR) \
Guang Zhu9cd3d8c2010-06-15 13:31:25 -07001993 $(addprefix -ix , $(PRIVATE_EMMA_COVERAGE_FILTER))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001994endef
1995
1996#TODO: use a smaller -Xmx value for most libraries;
1997# only core.jar and framework.jar need a heap this big.
Raphaelf6ff4c52009-08-18 14:43:32 -07001998# Avoid the memory arguments on Windows, dx fails to load for some reason with them.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001999define transform-classes.jar-to-dex
Chirayu Desaiad48df42012-10-13 13:05:29 +05302000@echo -e ${CL_GRN}"target Dex:"${CL_RST}" $(PRIVATE_MODULE)"
The Android Open Source Project88b60792009-03-03 19:28:42 -08002001@mkdir -p $(dir $@)
Ying Wangaf9757e2014-07-17 21:24:42 -07002002$(hide) rm -f $(dir $@)classes*.dex
Raphaelf6ff4c52009-08-18 14:43:32 -07002003$(hide) $(DX) \
Sebastian Schmidtd36495b2012-07-15 15:25:49 +02002004 $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx$(if $(call streq,$(HOST_BITS),32),1024,2048)M) \
Yohann Roussel8ffe9c32013-08-20 17:05:27 +02002005 --dex --output=$(dir $@) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08002006 $(if $(NO_OPTIMIZE_DX), \
2007 --no-optimize) \
2008 $(if $(GENERATE_DEX_DEBUG), \
2009 --debug --verbose \
2010 --dump-to=$(@:.dex=.lst) \
2011 --dump-width=1000) \
2012 $(PRIVATE_DX_FLAGS) \
2013 $<
2014endef
2015
2016# Create a mostly-empty .jar file that we'll add to later.
2017# The MacOS jar tool doesn't like creating empty jar files,
2018# so we need to give it something.
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002019# $(1) package to create
2020define create-empty-package-at
2021@mkdir -p $(dir $(1))
Ying Wangc894e092015-02-26 10:34:33 -08002022$(hide) touch $(dir $(1))zipdummy
2023$(hide) (cd $(dir $(1)) && jar cf $(notdir $(1)) zipdummy)
2024$(hide) zip -qd $(1) zipdummy
2025$(hide) rm $(dir $(1))zipdummy
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002026endef
2027
2028# Create a mostly-empty .jar file that we'll add to later.
2029# The MacOS jar tool doesn't like creating empty jar files,
2030# so we need to give it something.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002031define create-empty-package
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002032$(call create-empty-package-at,$@)
The Android Open Source Project88b60792009-03-03 19:28:42 -08002033endef
2034
Ying Wang33360dd2015-01-14 14:23:56 -08002035# Copy an arhchive file and delete any class files and empty folders inside.
2036# $(1): the source archive file.
2037# $(2): the destination archive file.
2038define initialize-package-file
2039@mkdir -p $(dir $(2))
2040$(hide) cp -f $(1) $(2)
Fredrik Roubertcc93f0c2015-01-28 21:29:38 +01002041$(hide) zip -qd $(2) "*.class" \
2042 $(if $(strip $(PRIVATE_DONT_DELETE_JAR_DIRS)),,"*/") \
2043 || true # Ignore the error when nothing to delete.
Ying Wang33360dd2015-01-14 14:23:56 -08002044endef
2045
The Android Open Source Project88b60792009-03-03 19:28:42 -08002046#TODO: we kinda want to build different asset packages for
2047# different configurations, then combine them later (or something).
2048# Per-locale, etc.
2049# A list of dynamic and static parameters; build layers for
2050# dynamic params that lay over the static ones.
2051#TODO: update the manifest to point to the package file
Dianne Hackborn9bd54042009-05-15 18:01:20 -07002052#Note that the version numbers are given to aapt as simple default
2053#values; applications can override these by explicitly stating
2054#them in their manifest.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002055define add-assets-to-package
Ying Wangc61d5932010-03-10 16:02:42 -08002056$(hide) $(AAPT) package -u $(PRIVATE_AAPT_FLAGS) \
Ying Wang4f1ab922011-03-15 13:19:30 -07002057 $(addprefix -c , $(PRIVATE_PRODUCT_AAPT_CONFIG)) \
Adam Lesinski2d1718a2014-05-09 10:57:48 -07002058 $(addprefix --preferred-density , $(PRIVATE_PRODUCT_AAPT_PREF_CONFIG)) \
The Android Open Source Project88b60792009-03-03 19:28:42 -08002059 $(addprefix -M , $(PRIVATE_ANDROID_MANIFEST)) \
2060 $(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
2061 $(addprefix -A , $(PRIVATE_ASSET_DIR)) \
2062 $(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
Ying Wangbb9c2302011-04-08 17:27:35 -07002063 $(addprefix --min-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
2064 $(addprefix --target-sdk-version , $(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
Ying Wangf39752e2014-03-20 17:28:57 -07002065 $(if $(filter --product,$(PRIVATE_AAPT_FLAGS)),,$(addprefix --product , $(TARGET_AAPT_CHARACTERISTICS))) \
Ying Wangb79e8772015-09-19 10:56:35 -07002066 $(if $(filter --version-code,$(PRIVATE_AAPT_FLAGS)),,--version-code $(PLATFORM_SDK_VERSION)) \
2067 $(if $(filter --version-name,$(PRIVATE_AAPT_FLAGS)),,--version-name $(APPS_DEFAULT_VERSION_NAME)) \
Jeff Hamiltonbb67d212010-02-05 22:36:42 -06002068 $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07002069 $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \
Adrian Roos6784cae2015-06-01 18:24:41 -07002070 --skip-symbols-without-default-localization \
The Android Open Source Project88b60792009-03-03 19:28:42 -08002071 -F $@
2072endef
2073
Ying Wang8e20ef62014-06-24 20:01:52 -07002074# We need the extra blank line, so that the command will be on a separate line.
2075# $(1): the ABI name
2076# $(2): the list of shared libraies
2077define _add-jni-shared-libs-to-package-per-abi
2078$(hide) cp $(2) $(dir $@)lib/$(1)
2079
2080endef
2081
Ying Wang1f8964d2015-07-15 18:33:24 -07002082# For apps_only build, don't uncompress/page-align the jni libraries,
2083# because the apk may be run on older platforms that don't support loading jni directly from apk.
2084ifdef TARGET_BUILD_APPS
2085JNI_COMPRESS_FLAGS :=
2086ZIPALIGN_PAGE_ALIGN_FLAGS :=
2087else
2088JNI_COMPRESS_FLAGS := -0
2089ZIPALIGN_PAGE_ALIGN_FLAGS := -p
2090endif
2091
The Android Open Source Project88b60792009-03-03 19:28:42 -08002092define add-jni-shared-libs-to-package
2093$(hide) rm -rf $(dir $@)lib
Ying Wang8e20ef62014-06-24 20:01:52 -07002094$(hide) mkdir -p $(addprefix $(dir $@)lib/,$(PRIVATE_JNI_SHARED_LIBRARIES_ABI))
2095$(foreach abi,$(PRIVATE_JNI_SHARED_LIBRARIES_ABI),\
2096 $(call _add-jni-shared-libs-to-package-per-abi,$(abi),\
2097 $(patsubst $(abi):%,%,$(filter $(abi):%,$(PRIVATE_JNI_SHARED_LIBRARIES)))))
Ying Wang1f8964d2015-07-15 18:33:24 -07002098$(hide) (cd $(dir $@) && zip -r $(JNI_COMPRESS_FLAGS) $(notdir $@) lib)
The Android Open Source Project88b60792009-03-03 19:28:42 -08002099$(hide) rm -rf $(dir $@)lib
2100endef
2101
The Android Open Source Project88b60792009-03-03 19:28:42 -08002102#TODO: update the manifest to point to the dex file
2103define add-dex-to-package
Ying Wangaf9757e2014-07-17 21:24:42 -07002104$(hide) zip -qj $@ $(dir $(PRIVATE_DEX_FILE))classes*.dex
The Android Open Source Project88b60792009-03-03 19:28:42 -08002105endef
2106
Ying Wang85480622012-08-09 15:20:50 -07002107# Add java resources added by the current module.
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002108# $(1) destination package
2109#
2110define add-java-resources-to
2111$(call dump-words-to-file, $(PRIVATE_EXTRA_JAR_ARGS), $(1).jar-arg-list)
2112$(hide) jar uf $(1) @$(1).jar-arg-list
2113@rm -f $(1).jar-arg-list
2114endef
2115
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002116# Add resources carried by static Jack libraries.
2117#
2118define add-carried-jack-resources
2119 $(hide) if [ -d $(PRIVATE_JACK_INTERMEDIATES_DIR) ] ; then \
Yohann Roussel22c3fa62014-11-19 14:01:06 +01002120 jack_res_jar_flags=$$(find $(PRIVATE_JACK_INTERMEDIATES_DIR) -type f \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +02002121 | sed -e "s?^$(PRIVATE_JACK_INTERMEDIATES_DIR)/? -C $(PRIVATE_JACK_INTERMEDIATES_DIR) ?"); \
2122 if [ -n "$$jack_res_jar_flags" ] ; then \
2123 echo $$jack_res_jar_flags >$(dir $@)jack_res_jar_flags; \
2124 jar uf $@ $$jack_res_jar_flags; \
2125 fi; \
2126fi
2127endef
2128
The Android Open Source Project88b60792009-03-03 19:28:42 -08002129# Sign a package using the specified key/cert.
2130#
2131define sign-package
2132$(hide) mv $@ $@.unsigned
2133$(hide) java -jar $(SIGNAPK_JAR) \
Ying Wang31df0682012-11-13 10:55:28 -08002134 $(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) \
2135 $(PRIVATE_ADDITIONAL_CERTIFICATES) $@.unsigned $@.signed
The Android Open Source Project88b60792009-03-03 19:28:42 -08002136$(hide) mv $@.signed $@
2137endef
2138
Dmitriy Ivanov13e59652014-07-23 15:27:21 -07002139# 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 -08002140#
2141define align-package
2142$(hide) mv $@ $@.unaligned
Dmitriy Ivanov13e59652014-07-23 15:27:21 -07002143$(hide) $(ZIPALIGN) \
Ying Wang1f8964d2015-07-15 18:33:24 -07002144 -f \
2145 $(ZIPALIGN_PAGE_ALIGN_FLAGS) \
Dmitriy Ivanov13e59652014-07-23 15:27:21 -07002146 4 \
2147 $@.unaligned $@.aligned
The Android Open Source Project88b60792009-03-03 19:28:42 -08002148$(hide) mv $@.aligned $@
2149endef
2150
Ying Wang1fb01522015-05-01 14:02:26 -07002151# Uncompress shared libraries embedded in an apk.
2152#
Nick Kralevich5aa02232015-04-17 16:53:15 -07002153define uncompress-shared-libs
Ying Wang1fb01522015-05-01 14:02:26 -07002154$(hide) if unzip -l $@ $(PRIVATE_EMBEDDED_JNI_LIBS) >/dev/null ; then \
2155 rm -rf $(dir $@)uncompressedlibs && mkdir $(dir $@)uncompressedlibs; \
2156 unzip $@ $(PRIVATE_EMBEDDED_JNI_LIBS) -d $(dir $@)uncompressedlibs && \
2157 zip -d $@ 'lib/*.so' && \
2158 ( cd $(dir $@)uncompressedlibs && zip -D -r -0 ../$(notdir $@) lib ) && \
2159 rm -rf $(dir $@)uncompressedlibs; \
2160 fi
Nick Kralevich5aa02232015-04-17 16:53:15 -07002161endef
2162
The Android Open Source Project88b60792009-03-03 19:28:42 -08002163define install-dex-debug
2164$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.dex" ]; then \
2165 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
2166 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.dex \
2167 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).dex; \
2168 fi
2169$(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.lst" ]; then \
2170 mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
2171 $(ACP) $(PRIVATE_INTERMEDIATES_DIR)/classes.lst \
2172 $(TOP)/dalvik/DEBUG-FILES/$(PRIVATE_MODULE).lst; \
2173 fi
2174endef
2175
2176# TODO(joeo): If we can ever upgrade to post 3.81 make and get the
2177# new prebuilt rules to work, we should change this to copy the
2178# resources to the out directory and then copy the resources.
2179
Brian Carlstrom78269512010-12-10 12:10:24 -08002180# Note: we intentionally don't clean PRIVATE_CLASS_INTERMEDIATES_DIR
2181# in transform-java-to-classes for the sake of vm-tests.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002182define transform-host-java-to-package
Chirayu Desaiad48df42012-10-13 13:05:29 +05302183@echo -e ${CL_YLW}"host Java:"${CL_RST}" $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
Ying Wang015edd22011-01-20 15:01:56 -08002184$(call compile-java,$(HOST_JAVAC),$(PRIVATE_BOOTCLASSPATH))
The Android Open Source Project88b60792009-03-03 19:28:42 -08002185endef
2186
2187###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08002188## Commands for copying files
2189###########################################################
2190
2191# Define a rule to copy a header. Used via $(eval) by copy_headers.make.
2192# $(1): source header
2193# $(2): destination header
2194define copy-one-header
2195$(2): $(1)
Chirayu Desaiad48df42012-10-13 13:05:29 +05302196 @echo -e ${CL_YLW}"Header:"${CL_RST}" $$@"
The Android Open Source Project88b60792009-03-03 19:28:42 -08002197 $$(copy-file-to-new-target-with-cp)
2198endef
2199
2200# Define a rule to copy a file. For use via $(eval).
2201# $(1): source file
2202# $(2): destination file
2203define copy-one-file
2204$(2): $(1) | $(ACP)
Chirayu Desaiad48df42012-10-13 13:05:29 +05302205 @echo -e ${CL_YLW}"Copy:"${CL_RST}" $$@"
The Android Open Source Project88b60792009-03-03 19:28:42 -08002206 $$(copy-file-to-target)
2207endef
2208
Joe Onoratoe44705a2012-05-17 17:12:04 -07002209# Copies many files.
2210# $(1): The files to copy. Each entry is a ':' separated src:dst pair
2211# Evaluates to the list of the dst files (ie suitable for a dependency list)
2212define copy-many-files
2213$(foreach f, $(1), $(strip \
2214 $(eval _cmf_tuple := $(subst :, ,$(f))) \
2215 $(eval _cmf_src := $(word 1,$(_cmf_tuple))) \
2216 $(eval _cmf_dest := $(word 2,$(_cmf_tuple))) \
2217 $(eval $(call copy-one-file,$(_cmf_src),$(_cmf_dest))) \
2218 $(_cmf_dest)))
2219endef
2220
Ying Wang3ceecfa2012-05-14 14:39:00 -07002221# Copy the file only if it's a well-formed xml file. For use via $(eval).
2222# $(1): source file
2223# $(2): destination file, must end with .xml.
2224define copy-xml-file-checked
2225$(2): $(1) | $(ACP)
Chirayu Desaiad48df42012-10-13 13:05:29 +05302226 @echo -e ${CL_YLW}"Copy xml:"${CL_RST}" $$@"
Ying Wang3ceecfa2012-05-14 14:39:00 -07002227 $(hide) xmllint $$< >/dev/null # Don't print the xml file to stdout.
2228 $$(copy-file-to-target)
2229endef
2230
The Android Open Source Project88b60792009-03-03 19:28:42 -08002231# The -t option to acp and the -p option to cp is
2232# required for OSX. OSX has a ridiculous restriction
2233# where it's an error for a .a file's modification time
2234# to disagree with an internal timestamp, and this
2235# macro is used to install .a files (among other things).
2236
2237# Copy a single file from one place to another,
2238# preserving permissions and overwriting any existing
2239# file.
Ian Rogers76a6dc32012-10-01 16:36:23 -07002240# We disable the "-t" option for acp cannot handle
Ying Wang84ed6fa2011-01-18 17:21:20 -08002241# high resolution timestamp correctly on file systems like ext4.
2242# Therefore copy-file-to-target is the same as copy-file-to-new-target.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002243define copy-file-to-target
2244@mkdir -p $(dir $@)
Ying Wang84ed6fa2011-01-18 17:21:20 -08002245$(hide) $(ACP) -fp $< $@
The Android Open Source Project88b60792009-03-03 19:28:42 -08002246endef
2247
2248# The same as copy-file-to-target, but use the local
2249# cp command instead of acp.
2250define copy-file-to-target-with-cp
2251@mkdir -p $(dir $@)
2252$(hide) cp -fp $< $@
2253endef
2254
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07002255# The same as copy-file-to-target, but use the zipalign tool to do so.
2256define copy-file-to-target-with-zipalign
2257@mkdir -p $(dir $@)
2258$(hide) $(ZIPALIGN) -f 4 $< $@
2259endef
2260
Doug Zongker1046d202009-08-06 13:02:19 -07002261# The same as copy-file-to-target, but strip out "# comment"-style
2262# comments (for config files and such).
2263define copy-file-to-target-strip-comments
2264@mkdir -p $(dir $@)
2265$(hide) sed -e 's/#.*$$//' -e 's/[ \t]*$$//' -e '/^$$/d' < $< > $@
2266endef
2267
The Android Open Source Project88b60792009-03-03 19:28:42 -08002268# The same as copy-file-to-target, but don't preserve
2269# the old modification time.
2270define copy-file-to-new-target
2271@mkdir -p $(dir $@)
2272$(hide) $(ACP) -fp $< $@
2273endef
2274
2275# The same as copy-file-to-new-target, but use the local
2276# cp command instead of acp.
2277define copy-file-to-new-target-with-cp
2278@mkdir -p $(dir $@)
2279$(hide) cp -f $< $@
2280endef
2281
2282# Copy a prebuilt file to a target location.
2283define transform-prebuilt-to-target
Oliver Middletond01d6b82014-10-12 22:11:26 +01002284@echo -e ${CL_CYN}"$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
The Android Open Source Project88b60792009-03-03 19:28:42 -08002285$(copy-file-to-target)
2286endef
2287
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07002288# Copy a prebuilt file to a target location, using zipalign on it.
2289define transform-prebuilt-to-target-with-zipalign
Oliver Middletond01d6b82014-10-12 22:11:26 +01002290@echo -e ${CL_CYN}"$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt APK:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Dianne Hackborn9c0c4b72009-08-11 19:16:46 -07002291$(copy-file-to-target-with-zipalign)
2292endef
2293
Doug Zongker1046d202009-08-06 13:02:19 -07002294# Copy a prebuilt file to a target location, stripping "# comment" comments.
2295define transform-prebuilt-to-target-strip-comments
Oliver Middletond01d6b82014-10-12 22:11:26 +01002296@echo -e ${CL_CYN}"$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt:"${CL_RST}" $(PRIVATE_MODULE) ($@)"
Doug Zongker1046d202009-08-06 13:02:19 -07002297$(copy-file-to-target-strip-comments)
2298endef
2299
Ying Wangc45a47b2015-04-08 12:24:37 -07002300# Copy a list of files/directories to target location, with sub dir structure preserved.
2301# For example $(HOST_OUT_EXECUTABLES)/aapt -> $(staging)/bin/aapt .
2302# $(1): the source list of files/directories.
2303# $(2): the path prefix to strip. In the above example it would be $(HOST_OUT).
2304# $(3): the target location.
2305define copy-files-with-structure
2306$(foreach t,$(1),\
2307 $(eval s := $(patsubst $(2)%,%,$(t)))\
2308 $(hide) mkdir -p $(dir $(3)/$(s)); cp -Rf $(t) $(3)/$(s)$(newline))
2309endef
2310
The Android Open Source Project88b60792009-03-03 19:28:42 -08002311
2312###########################################################
Ying Wang3b2bdf12010-02-01 09:51:23 -08002313## Commands to call Proguard
2314###########################################################
nuclearmistake451a31b2014-04-27 21:59:42 -04002315@echo -e ${CL_CYN}"Copying:"${CL_RST}" $@"
2316@echo -e ${CL_GRN}"Proguard:"${CL_RST}" $@"
Ying Wang3b2bdf12010-02-01 09:51:23 -08002317define transform-jar-to-proguard
Mihail Dumitrescu4df82b32014-02-07 15:18:59 +00002318$(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS) \
2319 $(addprefix -injars , $(PRIVATE_EXTRA_INPUT_JAR))
Ying Wang3b2bdf12010-02-01 09:51:23 -08002320endef
2321
Ying Wang3b2bdf12010-02-01 09:51:23 -08002322###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08002323## Stuff source generated from one-off tools
2324###########################################################
2325
2326define transform-generated-source
Chirayu Desaiad48df42012-10-13 13:05:29 +05302327@echo -e ${CL_GRN}"target Generated:"${CL_RST}" $(PRIVATE_MODULE) <= $<"
The Android Open Source Project88b60792009-03-03 19:28:42 -08002328@mkdir -p $(dir $@)
2329$(hide) $(PRIVATE_CUSTOM_TOOL)
2330endef
2331
2332
2333###########################################################
2334## Assertions about attributes of the target
2335###########################################################
2336
2337# $(1): The file to check
2338ifndef get-file-size
2339$(error HOST_OS must define get-file-size)
2340endif
2341
Doug Zongker4647f122009-07-02 09:00:54 -07002342# Convert a partition data size (eg, as reported in /proc/mtd) to the
2343# size of the image used to flash that partition (which includes a
Lars Svensson9cb8c282010-12-06 15:24:58 +01002344# spare area for each page).
Doug Zongker4647f122009-07-02 09:00:54 -07002345# $(1): the partition data size
2346define image-size-from-data-size
Ying Wang4a2ecaf2011-02-09 17:24:27 -08002347$(strip $(eval _isfds_value := $$(shell echo $$$$(($(1) / $(BOARD_NAND_PAGE_SIZE) * \
2348 ($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE))))))\
2349$(if $(filter 0, $(_isfds_value)),$(shell echo $$(($(BOARD_NAND_PAGE_SIZE)+$(BOARD_NAND_SPARE_SIZE)))),$(_isfds_value))\
2350$(eval _isfds_value :=))
Doug Zongker4647f122009-07-02 09:00:54 -07002351endef
2352
2353# $(1): The file(s) to check (often $@)
JP Abgrall0ed7cec2014-06-16 14:19:36 -07002354# $(2): The maximum total image size, in decimal bytes.
2355# Make sure to take into account any reserved space needed for the FS.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002356#
2357# If $(2) is empty, evaluates to "true"
2358#
2359# Reserve bad blocks. Make sure that MAX(1% of partition size, 2 blocks)
2360# is left over after the image has been flashed. Round the 1% up to the
2361# next whole flash block size.
2362define assert-max-file-size
2363$(if $(2), \
Doug Zongker742fa572009-07-08 12:09:04 -07002364 size=$$(for i in $(1); do $(call get-file-size,$$i); echo +; done; echo 0); \
2365 total=$$(( $$( echo "$$size" ) )); \
Doug Zongker4647f122009-07-02 09:00:54 -07002366 printname=$$(echo -n "$(1)" | tr " " +); \
Doug Zongker4647f122009-07-02 09:00:54 -07002367 img_blocksize=$(call image-size-from-data-size,$(BOARD_FLASH_BLOCK_SIZE)); \
2368 twoblocks=$$((img_blocksize * 2)); \
2369 onepct=$$((((($(2) / 100) - 1) / img_blocksize + 1) * img_blocksize)); \
JP Abgrall0ed7cec2014-06-16 14:19:36 -07002370 reserve=$$((twoblocks > onepct ? twoblocks : onepct)); \
Doug Zongker4647f122009-07-02 09:00:54 -07002371 maxsize=$$(($(2) - reserve)); \
Ying Wang99bcbeb2011-12-02 10:34:45 -08002372 echo "$$printname maxsize=$$maxsize blocksize=$$img_blocksize total=$$total reserve=$$reserve"; \
Doug Zongker4647f122009-07-02 09:00:54 -07002373 if [ "$$total" -gt "$$maxsize" ]; then \
2374 echo "error: $$printname too large ($$total > [$(2) - $$reserve])"; \
2375 false; \
Doug Zongker742fa572009-07-08 12:09:04 -07002376 elif [ "$$total" -gt $$((maxsize - 32768)) ]; then \
Doug Zongker4647f122009-07-02 09:00:54 -07002377 echo "WARNING: $$printname approaching size limit ($$total now; limit $$maxsize)"; \
The Android Open Source Project88b60792009-03-03 19:28:42 -08002378 fi \
2379 , \
2380 true \
2381 )
2382endef
2383
Doug Zongker8510a1e2009-08-07 16:38:08 -07002384# Like assert-max-file-size, but the second argument is a partition
2385# size, which we'll convert to a max image size before checking it
2386# against the files.
2387#
2388# $(1): The file(s) to check (often $@)
2389# $(2): The partition size.
2390define assert-max-image-size
2391$(if $(2), \
JP Abgrall0ed7cec2014-06-16 14:19:36 -07002392 $(call assert-max-file-size,$(1),$(call image-size-from-data-size,$(2))))
Doug Zongker8510a1e2009-08-07 16:38:08 -07002393endef
2394
Doug Zongkere01100c2009-06-19 17:12:18 -07002395
2396###########################################################
2397## Define device-specific radio files
2398###########################################################
Ying Wang94de1eb2013-07-26 12:19:20 -07002399INSTALLED_RADIOIMAGE_TARGET :=
Doug Zongkere01100c2009-06-19 17:12:18 -07002400
2401# Copy a radio image file to the output location, and add it to
2402# INSTALLED_RADIOIMAGE_TARGET.
2403# $(1): filename
2404define add-radio-file
Doug Zongker14833602010-02-02 13:12:04 -08002405 $(eval $(call add-radio-file-internal,$(1),$(notdir $(1))))
Doug Zongkere01100c2009-06-19 17:12:18 -07002406endef
2407define add-radio-file-internal
Doug Zongker14833602010-02-02 13:12:04 -08002408INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
Doug Zongker14833602010-02-02 13:12:04 -08002409$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP)
Doug Zongkere01100c2009-06-19 17:12:18 -07002410 $$(transform-prebuilt-to-target)
2411endef
2412
Doug Zongker9296f092012-03-20 16:42:22 -07002413# Version of add-radio-file that also arranges for the version of the
2414# file to be checked against the contents of
2415# $(TARGET_BOARD_INFO_FILE).
2416# $(1): filename
2417# $(2): name of version variable in board-info (eg, "version-baseband")
2418define add-radio-file-checked
2419 $(eval $(call add-radio-file-checked-internal,$(1),$(notdir $(1)),$(2)))
2420endef
2421define add-radio-file-checked-internal
2422INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(2)
2423BOARD_INFO_CHECK += $(3):$(LOCAL_PATH)/$(1)
2424$$(PRODUCT_OUT)/$(2) : $$(LOCAL_PATH)/$(1) | $$(ACP)
2425 $$(transform-prebuilt-to-target)
2426endef
2427
Doug Zongkere01100c2009-06-19 17:12:18 -07002428
The Android Open Source Project88b60792009-03-03 19:28:42 -08002429###########################################################
Joe Onorato899e62a2010-02-04 17:37:21 -08002430# Override the package defined in $(1), setting the
2431# variables listed below differently.
2432#
2433# $(1): The makefile to override (relative to the source
2434# tree root)
2435# $(2): Old LOCAL_PACKAGE_NAME value.
2436# $(3): New LOCAL_PACKAGE_NAME value.
Ying Wang3dae0ee2010-09-02 15:41:01 -07002437# $(4): New LOCAL_MANIFEST_PACKAGE_NAME value.
2438# $(5): New LOCAL_CERTIFICATE value.
2439# $(6): New LOCAL_INSTRUMENTATION_FOR value.
2440# $(7): New LOCAL_MANIFEST_INSTRUMENTATION_FOR value.
Joe Onorato899e62a2010-02-04 17:37:21 -08002441#
2442# Note that LOCAL_PACKAGE_OVERRIDES is NOT cleared in
2443# clear_vars.mk.
2444###########################################################
2445define inherit-package
Ying Wang3dae0ee2010-09-02 15:41:01 -07002446 $(eval $(call inherit-package-internal,$(1),$(2),$(3),$(4),$(5),$(6),$(7)))
Joe Onorato899e62a2010-02-04 17:37:21 -08002447endef
2448
2449define inherit-package-internal
2450 LOCAL_PACKAGE_OVERRIDES \
Ying Wang3dae0ee2010-09-02 15:41:01 -07002451 := $(strip $(1))||$(strip $(2))||$(strip $(3))||$(strip $(4))||&&$(strip $(5))||&&$(strip $(6))||&&$(strip $(7)) $(LOCAL_PACKAGE_OVERRIDES)
Joe Onorato899e62a2010-02-04 17:37:21 -08002452 include $(1)
2453 LOCAL_PACKAGE_OVERRIDES \
2454 := $(wordlist 1,$(words $(LOCAL_PACKAGE_OVERRIDES)), $(LOCAL_PACKAGE_OVERRIDES))
2455endef
2456
2457# To be used with inherit-package above
2458# Evalutes to true if the package was overridden
2459define set-inherited-package-variables
2460$(strip $(call set-inherited-package-variables-internal))
2461endef
2462
2463define keep-or-override
2464$(eval $(1) := $(if $(2),$(2),$($(1))))
2465endef
2466
2467define set-inherited-package-variables-internal
2468 $(eval _o := $(subst ||, ,$(lastword $(LOCAL_PACKAGE_OVERRIDES))))
2469 $(eval _n := $(subst ||, ,$(firstword $(LOCAL_PACKAGE_OVERRIDES))))
2470 $(if $(filter $(word 2,$(_n)),$(LOCAL_PACKAGE_NAME)), \
2471 $(eval LOCAL_PACKAGE_NAME := $(word 3,$(_o))) \
2472 $(eval LOCAL_MANIFEST_PACKAGE_NAME := $(word 4,$(_o))) \
Ying Wang3dae0ee2010-09-02 15:41:01 -07002473 $(call keep-or-override,LOCAL_CERTIFICATE,$(patsubst &&%,%,$(word 5,$(_o)))) \
2474 $(call keep-or-override,LOCAL_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 6,$(_o)))) \
2475 $(call keep-or-override,LOCAL_MANIFEST_INSTRUMENTATION_FOR,$(patsubst &&%,%,$(word 7,$(_o)))) \
Joe Onorato899e62a2010-02-04 17:37:21 -08002476 $(eval LOCAL_OVERRIDES_PACKAGES := $(sort $(LOCAL_OVERRIDES_PACKAGES) $(word 2,$(_o)))) \
2477 true \
2478 ,)
2479endef
2480
Ying Wang000e89a2012-04-30 15:48:27 -07002481###########################################################
Ying Wangc065da22012-11-14 15:57:07 -08002482## API Check
2483###########################################################
2484
2485# eval this to define a rule that runs apicheck.
2486#
2487# Args:
2488# $(1) target
2489# $(2) stable api file
2490# $(3) api file to be tested
Hui Shuec21c582014-03-13 16:21:08 -07002491# $(4) stable removed api file
Hui Shue8af17e2014-02-21 14:18:19 -08002492# $(5) removed api file to be tested
2493# $(6) arguments for apicheck
2494# $(7) command to run if apicheck failed
2495# $(8) target dependent on this api check
2496# $(9) additional dependencies
Ying Wangc065da22012-11-14 15:57:07 -08002497define check-api
Hui Shuec21c582014-03-13 16:21:08 -07002498$(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(strip $(1))-timestamp: $(2) $(3) $(4) $(APICHECK) $(9)
Ying Wangc065da22012-11-14 15:57:07 -08002499 @echo "Checking API:" $(1)
Hui Shue8af17e2014-02-21 14:18:19 -08002500 $(hide) ( $(APICHECK_COMMAND) $(6) $(2) $(3) $(4) $(5) || ( $(7) ; exit 38 ) )
Ying Wangc065da22012-11-14 15:57:07 -08002501 $(hide) mkdir -p $$(dir $$@)
2502 $(hide) touch $$@
Hui Shue8af17e2014-02-21 14:18:19 -08002503$(8): $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(strip $(1))-timestamp
Ying Wangc065da22012-11-14 15:57:07 -08002504endef
2505
Ying Wang63d94fa2012-12-13 18:23:01 -08002506## Whether to build from source if prebuilt alternative exists
2507###########################################################
2508# $(1): module name
2509# $(2): LOCAL_PATH
2510# Expands to empty string if not from source.
2511ifeq (true,$(ANDROID_BUILD_FROM_SOURCE))
2512define if-build-from-source
2513true
2514endef
2515else
2516define if-build-from-source
2517$(if $(filter $(ANDROID_NO_PREBUILT_MODULES),$(1))$(filter \
2518 $(addsuffix %,$(ANDROID_NO_PREBUILT_PATHS)),$(2)),true)
2519endef
2520endif
2521
2522# Include makefile $(1) if build from source for module $(2)
2523# $(1): the makefile to include
2524# $(2): module name
2525# $(3): LOCAL_PATH
2526define include-if-build-from-source
2527$(if $(call if-build-from-source,$(2),$(3)),$(eval include $(1)))
2528endef
2529
Ying Wanga6a6c352014-09-26 10:41:27 -07002530# Return the arch for the source file of a prebuilt
2531# Return "none" if no matching arch found, so the result can be passed to
2532# LOCAL_MODULE_TARGET_ARCH.
Ying Wangc0adfb72014-02-27 14:10:53 -08002533# $(1) the list of archs supported by the prebuilt
2534define get-prebuilt-src-arch
2535$(strip $(if $(filter $(TARGET_ARCH),$(1)),$(TARGET_ARCH),\
Ying Wanga6a6c352014-09-26 10:41:27 -07002536 $(if $(filter $(TARGET_2ND_ARCH),$(1)),$(TARGET_2ND_ARCH),none)))
Ying Wangc0adfb72014-02-27 14:10:53 -08002537endef
2538
Ying Wangc065da22012-11-14 15:57:07 -08002539###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -08002540## Other includes
2541###########################################################
2542
2543# -----------------------------------------------------------------
2544# Rules and functions to help copy important files to DIST_DIR
2545# when requested.
2546include $(BUILD_SYSTEM)/distdir.mk
2547
Marie Lennerhagen9e5efce2010-10-20 13:41:59 +02002548# Include any vendor specific definitions.mk file
2549-include $(TOPDIR)vendor/*/build/core/definitions.mk
Andrew Boie388c04d2014-10-28 08:32:11 -07002550-include $(TOPDIR)device/*/build/core/definitions.mk
Marie Lennerhagen9e5efce2010-10-20 13:41:59 +02002551
The Android Open Source Project88b60792009-03-03 19:28:42 -08002552# broken:
2553# $(foreach file,$^,$(if $(findstring,.a,$(suffix $file)),-l$(file),$(file)))
2554
2555###########################################################
2556## Misc notes
2557###########################################################
2558
2559#DEPDIR = .deps
2560#df = $(DEPDIR)/$(*F)
2561
2562#SRCS = foo.c bar.c ...
2563
2564#%.o : %.c
2565# @$(MAKEDEPEND); \
2566# cp $(df).d $(df).P; \
2567# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
2568# -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \
2569# rm -f $(df).d
2570# $(COMPILE.c) -o $@ $<
2571
2572#-include $(SRCS:%.c=$(DEPDIR)/%.P)
2573
2574
2575#%.o : %.c
2576# $(COMPILE.c) -MD -o $@ $<
2577# @cp $*.d $*.P; \
2578# sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
2579# -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \
2580# rm -f $*.d