• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2009 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15# Common definitions for the Android NDK build system
16#
17
18# We use the GNU Make Standard Library
19include $(NDK_ROOT)/build/gmsl/gmsl
20
21# If NDK_TRACE is enabled then calls to the library functions are
22# traced to stdout using warning messages with their arguments
23
24ifdef NDK_TRACE
25__ndk_tr1 = $(warning $0('$1'))
26__ndk_tr2 = $(warning $0('$1','$2'))
27__ndk_tr3 = $(warning $0('$1','$2','$3'))
28else
29__ndk_tr1 :=
30__ndk_tr2 :=
31__ndk_tr3 :=
32endif
33
34# -----------------------------------------------------------------------------
35# Macro    : empty
36# Returns  : an empty macro
37# Usage    : $(empty)
38# -----------------------------------------------------------------------------
39empty :=
40
41# -----------------------------------------------------------------------------
42# Macro    : space
43# Returns  : a single space
44# Usage    : $(space)
45# -----------------------------------------------------------------------------
46space  := $(empty) $(empty)
47
48space4 := $(space)$(space)$(space)$(space)
49
50# -----------------------------------------------------------------------------
51# Function : last2
52# Arguments: a list
53# Returns  : the penultimate (next-to-last) element of a list
54# Usage    : $(call last2, <LIST>)
55# -----------------------------------------------------------------------------
56last2 = $(word $(words $1), x $1)
57
58# -----------------------------------------------------------------------------
59# Function : last3
60# Arguments: a list
61# Returns  : the antepenultimate (second-next-to-last) element of a list
62# Usage    : $(call last3, <LIST>)
63# -----------------------------------------------------------------------------
64last3 = $(word $(words $1), x x $1)
65
66# -----------------------------------------------------------------------------
67# Function : remove-duplicates
68# Arguments: a list
69# Returns  : the list with duplicate items removed, order is preserved.
70# Usage    : $(call remove-duplicates, <LIST>)
71# Note     : This is equivalent to the 'uniq' function provided by GMSL,
72#            however this implementation is non-recursive and *much*
73#            faster. It will also not explode the stack with a lot of
74#            items like 'uniq' does.
75# -----------------------------------------------------------------------------
76remove-duplicates = $(strip \
77  $(eval __uniq_ret :=) \
78  $(foreach __uniq_item,$1,\
79    $(if $(findstring $(__uniq_item),$(__uniq_ret)),,\
80      $(eval __uniq_ret += $(__uniq_item))\
81    )\
82  )\
83  $(__uniq_ret))
84
85# -----------------------------------------------------------------------------
86# Macro    : this-makefile
87# Returns  : the name of the current Makefile in the inclusion stack
88# Usage    : $(this-makefile)
89# -----------------------------------------------------------------------------
90this-makefile = $(lastword $(MAKEFILE_LIST))
91
92# -----------------------------------------------------------------------------
93# Macro    : local-makefile
94# Returns  : the name of the last parsed Android.mk file
95# Usage    : $(local-makefile)
96# -----------------------------------------------------------------------------
97local-makefile = $(lastword $(filter %Android.mk,$(MAKEFILE_LIST)))
98
99# -----------------------------------------------------------------------------
100# Function : assert-defined
101# Arguments: 1: list of variable names
102# Returns  : None
103# Usage    : $(call assert-defined, VAR1 VAR2 VAR3...)
104# Rationale: Checks that all variables listed in $1 are defined, or abort the
105#            build
106# -----------------------------------------------------------------------------
107assert-defined = $(foreach __varname,$(strip $1),\
108  $(if $(strip $($(__varname))),,\
109    $(call __ndk_error, Assertion failure: $(__varname) is not defined)\
110  )\
111)
112
113# -----------------------------------------------------------------------------
114# Function : clear-vars
115# Arguments: 1: list of variable names
116#            2: file where the variable should be defined
117# Returns  : None
118# Usage    : $(call clear-vars, VAR1 VAR2 VAR3...)
119# Rationale: Clears/undefines all variables in argument list
120# -----------------------------------------------------------------------------
121clear-vars = $(foreach __varname,$1,$(eval $(__varname) := $(empty)))
122
123# -----------------------------------------------------------------------------
124# Function : check-required-vars
125# Arguments: 1: list of variable names
126#            2: file where the variable(s) should be defined
127# Returns  : None
128# Usage    : $(call check-required-vars, VAR1 VAR2 VAR3..., <file>)
129# Rationale: Checks that all required vars listed in $1 were defined by $2
130#            or abort the build with an error
131# -----------------------------------------------------------------------------
132check-required-vars = $(foreach __varname,$1,\
133  $(if $(strip $($(__varname))),,\
134    $(call __ndk_info, Required variable $(__varname) is not defined by $2)\
135    $(call __ndk_error,Aborting)\
136  )\
137)
138
139# -----------------------------------------------------------------------------
140# Function : host-path
141# Arguments: 1: file path
142# Returns  : file path, as understood by the host file system
143# Usage    : $(call host-path,<path>)
144# Rationale: This function is used to translate Cygwin paths into
145#            Cygwin-specific ones. On other platforms, it will just
146#            return its argument.
147# -----------------------------------------------------------------------------
148ifeq ($(HOST_OS),cygwin)
149host-path = $(if $(strip $1),$(call cygwin-to-host-path,$1))
150else
151host-path = $1
152endif
153
154# -----------------------------------------------------------------------------
155# Function : host-rm
156# Arguments: 1: list of files
157# Usage    : $(call host-rm,<files>)
158# Rationale: This function expands to the host-specific shell command used
159#            to remove some files.
160# -----------------------------------------------------------------------------
161ifeq ($(HOST_OS),windows)
162host-rm = \
163    $(eval __host_rm_files := $(foreach __host_rm_file,$1,$(subst /,\,$(wildcard $(__host_rm_file)))))\
164    $(if $(__host_rm_files),del /f/q $(__host_rm_files) >NUL 2>NUL)
165else
166host-rm = rm -f $1
167endif
168
169# -----------------------------------------------------------------------------
170# Function : host-rmdir
171# Arguments: 1: list of files or directories
172# Usage    : $(call host-rm,<files>)
173# Rationale: This function expands to the host-specific shell command used
174#            to remove some files _and_ directories.
175# -----------------------------------------------------------------------------
176ifeq ($(HOST_OS),windows)
177host-rmdir = \
178    $(eval __host_rmdir_files := $(foreach __host_rmdir_file,$1,$(subst /,\,$(wildcard $(__host_rmdir_file)))))\
179    $(if $(__host_rmdir_files),del /f/s/q $(__host_rmdir_files) >NUL 2>NUL)
180else
181host-rmdir = rm -rf $1
182endif
183
184# -----------------------------------------------------------------------------
185# Function : host-mkdir
186# Arguments: 1: directory path
187# Usage    : $(call host-mkdir,<path>
188# Rationale: This function expands to the host-specific shell command used
189#            to create a path if it doesn't exist.
190# -----------------------------------------------------------------------------
191ifeq ($(HOST_OS),windows)
192host-mkdir = md $(subst /,\,"$1") >NUL 2>NUL || rem
193else
194host-mkdir = mkdir -p $1
195endif
196
197# -----------------------------------------------------------------------------
198# Function : host-cp
199# Arguments: 1: source file
200#            2: target file
201# Usage    : $(call host-cp,<src-file>,<dst-file>)
202# Rationale: This function expands to the host-specific shell command used
203#            to copy a single file
204# -----------------------------------------------------------------------------
205ifeq ($(HOST_OS),windows)
206host-cp = copy /b/y $(subst /,\,"$1" "$2") > NUL
207else
208host-cp = cp -f $1 $2
209endif
210
211# -----------------------------------------------------------------------------
212# Function : host-install
213# Arguments: 1: source file
214#            2: target file
215# Usage    : $(call host-install,<src-file>,<dst-file>)
216# Rationale: This function expands to the host-specific shell command used
217#            to install a file or directory, while preserving its timestamps
218#            (if possible).
219# -----------------------------------------------------------------------------
220ifeq ($(HOST_OS),windows)
221host-install = copy /b/y $(subst /,\,"$1" "$2") > NUL
222else
223host-install = install -p $1 $2
224endif
225
226# -----------------------------------------------------------------------------
227# Function : host-c-includes
228# Arguments: 1: list of file paths (e.g. "foo bar")
229# Returns  : list of include compiler options (e.g. "-Ifoo -Ibar")
230# Usage    : $(call host-c-includes,<paths>)
231# Rationale: This function is used to translate Cygwin paths into
232#            Cygwin-specific ones. On other platforms, it will just
233#            return its argument.
234# -----------------------------------------------------------------------------
235ifeq ($(HOST_OS),cygwin)
236host-c-includes = $(patsubst %,-I%,$(call host-path,$1))
237else
238host-c-includes = $(1:%=-I%)
239endif
240
241# -----------------------------------------------------------------------------
242# Function : copy-if-differ
243# Arguments: 1: source file
244#            2: destination file
245# Usage    : $(call copy-if-differ,<src-file>,<dst-file>)
246# Rationale: This function copy source file to destination file if contents are
247#            different.
248# -----------------------------------------------------------------------------
249ifeq ($(HOST_OS),windows)
250copy-if-differ = $(HOST_CMP) -s $1 $2 > NUL || copy /b/y $(subst /,\,"$1" "$2") > NUL
251else
252copy-if-differ = $(HOST_CMP) -s $1 $2 > /dev/null 2>&1 || cp -f $1 $2
253endif
254
255# -----------------------------------------------------------------------------
256# Function : generate-dir
257# Arguments: 1: directory path
258# Returns  : Generate a rule, but not dependency, to create a directory with
259#            host-mkdir.
260# Usage    : $(call generate-dir,<path>)
261# -----------------------------------------------------------------------------
262define ev-generate-dir
263__ndk_dir := $1
264ifeq (,$$(__ndk_dir_flag__$1))
265__ndk_dir_flag__$1 := true
266$1:
267	@$$(call host-mkdir,$$@)
268endif
269endef
270
271generate-dir = $(eval $(call ev-generate-dir,$1))
272
273# -----------------------------------------------------------------------------
274# Function : generate-file-dir
275# Arguments: 1: file path
276# Returns  : Generate a dependency and a rule to ensure that the parent
277#            directory of the input file path will be created before it.
278#            This is used to enforce a call to host-mkdir.
279# Usage    : $(call generate-file-dir,<file>)
280# Rationale: Many object files will be stored in the same output directory.
281#            Introducing a dependency on the latter avoids calling mkdir -p
282#            for every one of them.
283#
284# -----------------------------------------------------------------------------
285
286define ev-generate-file-dir
287__ndk_file_dir := $(call parent-dir,$1)
288$$(call generate-dir,$$(__ndk_file_dir))
289$1: $$(__ndk_file_dir)
290endef
291
292generate-file-dir = $(eval $(call ev-generate-file-dir,$1))
293
294# -----------------------------------------------------------------------------
295# Function : generate-list-file
296# Arguments: 1: list of strings (possibly very long)
297#            2: file name
298# Returns  : write the content of a possibly very long string list to a file.
299#            this shall be used in commands and will work around limitations
300#            of host command-line lengths.
301# Usage    : $(call host-echo-to-file,<string-list>,<file>)
302# Rationale: When there is a very large number of objects and/or libraries at
303#            link time, the size of the command becomes too large for the
304#            host system's maximum. Various tools however support the
305#            @<listfile> syntax, where <listfile> is the path of a file
306#            which content will be parsed as if they were options.
307#
308#            This function is used to generate such a list file from a long
309#            list of strings in input.
310#
311# -----------------------------------------------------------------------------
312
313# Helper functions because the GNU Make $(word ...) function does
314# not accept a 0 index, so we need to bump any of these to 1 when
315# we find them.
316#
317index-is-zero = $(filter 0 00 000 0000 00000 000000 0000000,$1)
318bump-0-to-1 = $(if $(call index-is-zero,$1),1,$1)
319
320# Same as $(wordlist ...) except the start index, if 0, is bumped to 1
321index-word-list = $(wordlist $(call bump-0-to-1,$1),$2,$3)
322
323# NOTE: With GNU Make $1 and $(1) are equivalent, which means
324#       that $10 is equivalent to $(1)0, and *not* $(10).
325
326# Used to generate a slice of up to 10 items starting from index $1,
327# If $1 is 0, it will be bumped to 1 (and only 9 items will be printed)
328# $1: start (tenth) index. Can be 0
329# $2: word list
330#
331define list-file-start-gen-10
332	$$(hide) $$(HOST_ECHO_N) "$(call index-word-list,$10,$19,$2) " >> $$@
333endef
334
335# Used to generate a slice of always 10 items starting from index $1
336# $1: start (tenth) index. CANNOT BE 0
337# $2: word list
338define list-file-always-gen-10
339	$$(hide) $$(HOST_ECHO_N) "$(wordlist $10,$19,$2) " >> $$@
340endef
341
342# Same as list-file-always-gen-10, except that the word list might be
343# empty at position $10 (i.e. $(1)0)
344define list-file-maybe-gen-10
345ifneq ($(word $10,$2),)
346	$$(hide) $$(HOST_ECHO_N) "$(wordlist $10,$19,$2) " >> $$@
347endif
348endef
349
350define list-file-start-gen-100
351$(call list-file-start-gen-10,$10,$2)
352$(call list-file-always-gen-10,$11,$2)
353$(call list-file-always-gen-10,$12,$2)
354$(call list-file-always-gen-10,$13,$2)
355$(call list-file-always-gen-10,$14,$2)
356$(call list-file-always-gen-10,$15,$2)
357$(call list-file-always-gen-10,$16,$2)
358$(call list-file-always-gen-10,$17,$2)
359$(call list-file-always-gen-10,$18,$2)
360$(call list-file-always-gen-10,$19,$2)
361endef
362
363define list-file-always-gen-100
364$(call list-file-always-gen-10,$10,$2)
365$(call list-file-always-gen-10,$11,$2)
366$(call list-file-always-gen-10,$12,$2)
367$(call list-file-always-gen-10,$13,$2)
368$(call list-file-always-gen-10,$14,$2)
369$(call list-file-always-gen-10,$15,$2)
370$(call list-file-always-gen-10,$16,$2)
371$(call list-file-always-gen-10,$17,$2)
372$(call list-file-always-gen-10,$18,$2)
373$(call list-file-always-gen-10,$19,$2)
374endef
375
376define list-file-maybe-gen-100
377ifneq ($(word $(call bump-0-to-1,$100),$2),)
378ifneq ($(word $199,$2),)
379$(call list-file-start-gen-10,$10,$2)
380$(call list-file-always-gen-10,$11,$2)
381$(call list-file-always-gen-10,$12,$2)
382$(call list-file-always-gen-10,$13,$2)
383$(call list-file-always-gen-10,$14,$2)
384$(call list-file-always-gen-10,$15,$2)
385$(call list-file-always-gen-10,$16,$2)
386$(call list-file-always-gen-10,$17,$2)
387$(call list-file-always-gen-10,$18,$2)
388$(call list-file-always-gen-10,$19,$2)
389else
390ifneq ($(word $150,$2),)
391$(call list-file-start-gen-10,$10,$2)
392$(call list-file-always-gen-10,$11,$2)
393$(call list-file-always-gen-10,$12,$2)
394$(call list-file-always-gen-10,$13,$2)
395$(call list-file-always-gen-10,$14,$2)
396$(call list-file-maybe-gen-10,$15,$2)
397$(call list-file-maybe-gen-10,$16,$2)
398$(call list-file-maybe-gen-10,$17,$2)
399$(call list-file-maybe-gen-10,$18,$2)
400$(call list-file-maybe-gen-10,$19,$2)
401else
402$(call list-file-start-gen-10,$10,$2)
403$(call list-file-maybe-gen-10,$11,$2)
404$(call list-file-maybe-gen-10,$12,$2)
405$(call list-file-maybe-gen-10,$13,$2)
406$(call list-file-maybe-gen-10,$14,$2)
407endif
408endif
409endif
410endef
411
412define list-file-maybe-gen-1000
413ifneq ($(word $(call bump-0-to-1,$1000),$2),)
414ifneq ($(word $1999,$2),)
415$(call list-file-start-gen-100,$10,$2)
416$(call list-file-always-gen-100,$11,$2)
417$(call list-file-always-gen-100,$12,$2)
418$(call list-file-always-gen-100,$13,$2)
419$(call list-file-always-gen-100,$14,$2)
420$(call list-file-always-gen-100,$15,$2)
421$(call list-file-always-gen-100,$16,$2)
422$(call list-file-always-gen-100,$17,$2)
423$(call list-file-always-gen-100,$18,$2)
424$(call list-file-always-gen-100,$19,$2)
425else
426ifneq ($(word $1500,$2),)
427$(call list-file-start-gen-100,$10,$2)
428$(call list-file-always-gen-100,$11,$2)
429$(call list-file-always-gen-100,$12,$2)
430$(call list-file-always-gen-100,$13,$2)
431$(call list-file-always-gen-100,$14,$2)
432$(call list-file-maybe-gen-100,$15,$2)
433$(call list-file-maybe-gen-100,$16,$2)
434$(call list-file-maybe-gen-100,$17,$2)
435$(call list-file-maybe-gen-100,$18,$2)
436$(call list-file-maybe-gen-100,$19,$2)
437else
438$(call list-file-start-gen-100,$10,$2)
439$(call list-file-maybe-gen-100,$11,$2)
440$(call list-file-maybe-gen-100,$12,$2)
441$(call list-file-maybe-gen-100,$13,$2)
442$(call list-file-maybe-gen-100,$14,$2)
443endif
444endif
445endif
446endef
447
448
449define generate-list-file-ev
450__list_file := $2
451
452.PHONY: $$(__list_file).tmp
453
454$$(call generate-file-dir,$$(__list_file).tmp)
455
456$$(__list_file).tmp:
457	$$(hide) $$(HOST_ECHO_N) "" > $$@
458$(call list-file-maybe-gen-1000,0,$1)
459$(call list-file-maybe-gen-1000,1,$1)
460$(call list-file-maybe-gen-1000,2,$1)
461$(call list-file-maybe-gen-1000,3,$1)
462$(call list-file-maybe-gen-1000,4,$1)
463$(call list-file-maybe-gen-1000,5,$1)
464
465$$(__list_file): $$(__list_file).tmp
466	$$(hide) $$(call copy-if-differ,$$@.tmp,$$@)
467	$$(hide) $$(call host-rm,$$@.tmp)
468
469endef
470
471generate-list-file = $(eval $(call generate-list-file-ev,$1,$2))
472
473# -----------------------------------------------------------------------------
474# Function : link-whole-archives
475# Arguments: 1: list of whole static libraries
476# Returns  : linker flags to use the whole static libraries
477# Usage    : $(call link-whole-archives,<libraries>)
478# Rationale: This function is used to put the list of whole static libraries
479#            inside a -Wl,--whole-archive ... -Wl,--no-whole-archive block.
480#            If the list is empty, it returns an empty string.
481#            This function also calls host-path to translate the library
482#            paths.
483# -----------------------------------------------------------------------------
484link-whole-archives = $(if $(strip $1),$(call link-whole-archive-flags,$1))
485link-whole-archive-flags = -Wl,--whole-archive $(call host-path,$1) -Wl,--no-whole-archive
486
487# =============================================================================
488#
489# Modules database
490#
491# The following declarations are used to manage the list of modules
492# defined in application's Android.mk files.
493#
494# Technical note:
495#    We use __ndk_modules to hold the list of all modules corresponding
496#    to a given application.
497#
498#    For each module 'foo', __ndk_modules.foo.<field> is used
499#    to store module-specific information.
500#
501#        type         -> type of module (e.g. 'static', 'shared', ...)
502#        depends      -> list of other modules this module depends on
503#
504#    Also, LOCAL_XXXX values defined for a module are recorded in XXXX, e.g.:
505#
506#        PATH   -> recorded LOCAL_PATH for the module
507#        CFLAGS -> recorded LOCAL_CFLAGS for the module
508#        ...
509#
510#    Some of these are created by build scripts like BUILD_STATIC_LIBRARY:
511#
512#        MAKEFILE -> The Android.mk where the module is defined.
513#        LDFLAGS  -> Final linker flags
514#        OBJECTS  -> List of module objects
515#        BUILT_MODULE -> location of module built file (e.g. obj/<app>/<abi>/libfoo.so)
516#
517#    Note that some modules are never installed (e.g. static libraries).
518#
519# =============================================================================
520
521# The list of LOCAL_XXXX variables that are recorded for each module definition
522# These are documented by docs/ANDROID-MK.TXT. Exception is LOCAL_MODULE
523#
524modules-LOCALS := \
525    MODULE \
526    MODULE_FILENAME \
527    PATH \
528    SRC_FILES \
529    CPP_EXTENSION \
530    C_INCLUDES \
531    CFLAGS \
532    CXXFLAGS \
533    CPPFLAGS \
534    STATIC_LIBRARIES \
535    WHOLE_STATIC_LIBRARIES \
536    SHARED_LIBRARIES \
537    LDLIBS \
538    ALLOW_UNDEFINED_SYMBOLS \
539    ARM_MODE \
540    ARM_NEON \
541    DISABLE_NO_EXECUTE \
542    DISABLE_RELRO \
543    EXPORT_CFLAGS \
544    EXPORT_CPPFLAGS \
545    EXPORT_LDLIBS \
546    EXPORT_C_INCLUDES \
547    FILTER_ASM \
548    CPP_FEATURES \
549    SHORT_COMMANDS \
550
551# The following are generated by the build scripts themselves
552
553# LOCAL_MAKEFILE will contain the path to the Android.mk defining the module
554modules-LOCALS += MAKEFILE
555
556# LOCAL_LDFLAGS will contain the set of final linker flags for the module
557modules-LOCALS += LDFLAGS
558
559# LOCAL_OBJECTS will contain the list of object files generated from the
560# module's sources, if any.
561modules-LOCALS += OBJECTS
562
563# LOCAL_BUILT_MODULE will contain the location of the symbolic version of
564# the generated module (i.e. the one containing all symbols used during
565# native debugging). It is generally under $PROJECT/obj/local/
566modules-LOCALS += BUILT_MODULE
567
568# LOCAL_OBJS_DIR will contain the location where the object files for
569# this module will be stored. Usually $PROJECT/obj/local/<module>/obj
570modules-LOCALS += OBJS_DIR
571
572# LOCAL_INSTALLED will contain the location of the installed version
573# of the module. Usually $PROJECT/libs/<abi>/<prefix><module><suffix>
574# where <prefix> and <suffix> depend on the module class.
575modules-LOCALS += INSTALLED
576
577# LOCAL_MODULE_CLASS will contain the type of the module
578# (e.g. STATIC_LIBRARY, SHARED_LIBRARY, etc...)
579modules-LOCALS += MODULE_CLASS
580
581# the list of managed fields per module
582modules-fields = depends \
583                 $(modules-LOCALS)
584
585# -----------------------------------------------------------------------------
586# Function : modules-clear
587# Arguments: None
588# Returns  : None
589# Usage    : $(call modules-clear)
590# Rationale: clears the list of defined modules known by the build system
591# -----------------------------------------------------------------------------
592modules-clear = \
593    $(foreach __mod,$(__ndk_modules),\
594        $(foreach __field,$(modules-fields),\
595            $(eval __ndk_modules.$(__mod).$(__field) := $(empty))\
596        )\
597    )\
598    $(eval __ndk_modules := $(empty_set)) \
599    $(eval __ndk_top_modules := $(empty)) \
600    $(eval __ndk_import_list := $(empty)) \
601    $(eval __ndk_import_depth := $(empty))
602
603# -----------------------------------------------------------------------------
604# Function : modules-get-list
605# Arguments: None
606# Returns  : The list of all recorded modules
607# Usage    : $(call modules-get-list)
608# -----------------------------------------------------------------------------
609modules-get-list = $(__ndk_modules)
610
611# -----------------------------------------------------------------------------
612# Function : modules-get-top-list
613# Arguments: None
614# Returns  : The list of all recorded non-imported modules
615# Usage    : $(call modules-get-top-list)
616# -----------------------------------------------------------------------------
617modules-get-top-list = $(__ndk_top_modules)
618
619# -----------------------------------------------------------------------------
620# Function : module-add
621# Arguments: 1: module name
622# Returns  : None
623# Usage    : $(call module-add,<modulename>)
624# Rationale: add a new module. If it is already defined, print an error message
625#            and abort. This will record all LOCAL_XXX variables for the module.
626# -----------------------------------------------------------------------------
627module-add = \
628  $(call assert-defined,LOCAL_MAKEFILE LOCAL_BUILT_MODULE LOCAL_OBJS_DIR LOCAL_MODULE_CLASS)\
629  $(if $(call set_is_member,$(__ndk_modules),$1),\
630    $(call __ndk_info,Trying to define local module '$1' in $(LOCAL_MAKEFILE).)\
631    $(call __ndk_info,But this module was already defined by $(__ndk_modules.$1.MAKEFILE).)\
632    $(call __ndk_error,Aborting.)\
633  )\
634  $(eval __ndk_modules := $(call set_insert,$(__ndk_modules),$1))\
635  $(if $(strip $(__ndk_import_depth)),,\
636    $(eval __ndk_top_modules := $(call set_insert,$(__ndk_top_modules),$1))\
637  )\
638  $(if $(call module-class-is-installable,$(LOCAL_MODULE_CLASS)),\
639    $(eval LOCAL_INSTALLED := $(NDK_APP_DST_DIR)/$(notdir $(LOCAL_BUILT_MODULE)))\
640  )\
641  $(foreach __local,$(modules-LOCALS),\
642    $(eval __ndk_modules.$1.$(__local) := $(LOCAL_$(__local)))\
643  )\
644  $(call module-handle-c++-features,$1)
645
646
647# Retrieve the class of module $1
648module-get-class = $(__ndk_modules.$1.MODULE_CLASS)
649
650# Retrieve built location of module $1
651module-get-built = $(__ndk_modules.$1.BUILT_MODULE)
652
653# Returns $(true) is module $1 is installable
654# An installable module is one that will be copied to $PROJECT/libs/<abi>/
655# (e.g. shared libraries).
656#
657module-is-installable = $(call module-class-is-installable,$(call module-get-class,$1))
658
659# Returns $(true) if module $1 is prebuilt
660# A prebuilt module is one declared with BUILD_PREBUILT_SHARED_LIBRARY or
661# BUILD_PREBUILT_STATIC_LIBRARY
662#
663module-is-prebuilt = $(call module-class-is-prebuilt,$(call module-get-class,$1))
664
665# -----------------------------------------------------------------------------
666# Function : module-get-export
667# Arguments: 1: module name
668#            2: export variable name without LOCAL_EXPORT_ prefix (e.g. 'CFLAGS')
669# Returns  : Exported value
670# Usage    : $(call module-get-export,<modulename>,<varname>)
671# Rationale: Return the recorded value of LOCAL_EXPORT_$2, if any, for module $1
672# -----------------------------------------------------------------------------
673module-get-export = $(__ndk_modules.$1.EXPORT_$2)
674
675# -----------------------------------------------------------------------------
676# Function : module-get-listed-export
677# Arguments: 1: list of module names
678#            2: export variable name without LOCAL_EXPORT_ prefix (e.g. 'CFLAGS')
679# Returns  : Exported values
680# Usage    : $(call module-get-listed-export,<module-list>,<varname>)
681# Rationale: Return the recorded value of LOCAL_EXPORT_$2, if any, for modules
682#            listed in $1.
683# -----------------------------------------------------------------------------
684module-get-listed-export = $(strip \
685    $(foreach __listed_module,$1,\
686        $(call module-get-export,$(__listed_module),$2)\
687    ))
688
689# -----------------------------------------------------------------------------
690# Function : modules-restore-locals
691# Arguments: 1: module name
692# Returns  : None
693# Usage    : $(call module-restore-locals,<modulename>)
694# Rationale: Restore the recorded LOCAL_XXX definitions for a given module.
695# -----------------------------------------------------------------------------
696module-restore-locals = \
697    $(foreach __local,$(modules-LOCALS),\
698        $(eval LOCAL_$(__local) := $(__ndk_modules.$1.$(__local)))\
699    )
700
701# Dump all module information. Only use this for debugging
702modules-dump-database = \
703    $(info Modules: $(__ndk_modules)) \
704    $(foreach __mod,$(__ndk_modules),\
705        $(info $(space4)$(__mod):)\
706        $(foreach __field,$(modules-fields),\
707            $(eval __fieldval := $(strip $(__ndk_modules.$(__mod).$(__field))))\
708            $(if $(__fieldval),\
709                $(if $(filter 1,$(words $(__fieldval))),\
710                    $(info $(space4)$(space4)$(__field): $(__fieldval)),\
711                    $(info $(space4)$(space4)$(__field): )\
712                    $(foreach __fielditem,$(__fieldval),\
713                        $(info $(space4)$(space4)$(space4)$(__fielditem))\
714                    )\
715                )\
716            )\
717        )\
718    )\
719    $(info --- end of modules list)
720
721
722# -----------------------------------------------------------------------------
723# Function : module-add-static-depends
724# Arguments: 1: module name
725#            2: list/set of static library modules this module depends on.
726# Returns  : None
727# Usage    : $(call module-add-static-depends,<modulename>,<list of module names>)
728# Rationale: Record that a module depends on a set of static libraries.
729#            Use module-get-static-dependencies to retrieve final list.
730# -----------------------------------------------------------------------------
731module-add-static-depends = \
732    $(call module-add-depends-any,$1,$2,depends) \
733
734# -----------------------------------------------------------------------------
735# Function : module-add-shared-depends
736# Arguments: 1: module name
737#            2: list/set of shared library modules this module depends on.
738# Returns  : None
739# Usage    : $(call module-add-shared-depends,<modulename>,<list of module names>)
740# Rationale: Record that a module depends on a set of shared libraries.
741#            Use modulge-get-shared-dependencies to retrieve final list.
742# -----------------------------------------------------------------------------
743module-add-shared-depends = \
744    $(call module-add-depends-any,$1,$2,depends) \
745
746# Used internally by module-add-static-depends and module-add-shared-depends
747# NOTE: this function must not modify the existing dependency order when new depends are added.
748#
749module-add-depends-any = \
750    $(eval __ndk_modules.$1.$3 += $(filter-out $(__ndk_modules.$1.$3),$(call strip-lib-prefix,$2)))
751
752# Used to recompute all dependencies once all module information has been recorded.
753#
754modules-compute-dependencies = \
755    $(foreach __module,$(__ndk_modules),\
756        $(call module-compute-depends,$(__module))\
757    )
758
759module-compute-depends = \
760    $(call module-add-static-depends,$1,$(__ndk_modules.$1.STATIC_LIBRARIES))\
761    $(call module-add-static-depends,$1,$(__ndk_modules.$1.WHOLE_STATIC_LIBRARIES))\
762    $(call module-add-shared-depends,$1,$(__ndk_modules.$1.SHARED_LIBRARIES))\
763
764module-get-installed = $(__ndk_modules.$1.INSTALLED)
765
766# -----------------------------------------------------------------------------
767# Function : modules-get-all-dependencies
768# Arguments: 1: list of module names
769# Returns  : List of all the modules $1 depends on transitively.
770# Usage    : $(call modules-all-get-dependencies,<list of module names>)
771# Rationale: This computes the closure of all module dependencies starting from $1
772# -----------------------------------------------------------------------------
773module-get-all-dependencies = $(strip \
774    $(call modules-get-closure,$1,depends))
775
776modules-get-closure = \
777    $(eval __closure_deps  := $(strip $(call strip-lib-prefix,$1))) \
778    $(eval __closure_wq    := $(__closure_deps)) \
779    $(eval __closure_field := $(strip $2)) \
780    $(call modules-closure)\
781    $(__closure_deps)
782
783# Used internally by modules-get-all-dependencies
784# Note the tricky use of conditional recursion to work around the fact that
785# the GNU Make language does not have any conditional looping construct
786# like 'while'.
787#
788modules-closure = \
789    $(eval __closure_mod := $(call first,$(__closure_wq))) \
790    $(eval __closure_wq  := $(call rest,$(__closure_wq))) \
791    $(eval __closure_val := $(call strip-lib-prefix,$(__ndk_modules.$(__closure_mod).$(__closure_field)))) \
792    $(eval __closure_new := $(filter-out $(__closure_deps),$(__closure_val)))\
793    $(eval __closure_deps += $(__closure_new)) \
794    $(eval __closure_wq   := $(strip $(__closure_wq) $(__closure_new)))\
795    $(if $(__closure_wq),$(call modules-closure)) \
796
797# -----------------------------------------------------------------------------
798# Function : module-get-depends
799# Arguments: 1: list of module names
800#            2: local module type (e.g. SHARED_LIBRARIES)
801# Returns  : List all the <local-type> modules $1 depends on transitively.
802# Usage    : $(call module-get-depends,<list of module names>,<local-type>)
803# Rationale: This computes the closure of all local module dependencies starting from $1
804# -----------------------------------------------------------------------------
805module-get-depends = $(strip $(call modules-get-closure,$1,$2))
806
807
808# -----------------------------------------------------------------------------
809# Function : modules-get-all-installable
810# Arguments: 1: list of module names
811# Returns  : List of all the installable modules $1 depends on transitively.
812# Usage    : $(call modules-all-get-installable,<list of module names>)
813# Rationale: This computes the closure of all installable module dependencies starting from $1
814# -----------------------------------------------------------------------------
815# For now, only the closure of LOCAL_SHARED_LIBRARIES is enough
816modules-get-all-installable = $(strip \
817    $(foreach __alldep,$(call module-get-depends,$1,depends),\
818        $(if $(call module-is-installable,$(__alldep)),$(__alldep))\
819    ))
820
821# Return the C++ extension of a given module
822# $1: module name
823module-get-cpp-extension = $(strip \
824    $(if $(__ndk_modules.$1.CPP_EXTENSION),\
825        $(__ndk_modules.$1.CPP_EXTENSION),\
826        .cpp\
827    ))
828
829# Return the list of C++ sources of a given module
830#
831module-get-c++-sources = \
832    $(eval __files := $(__ndk_modules.$1.SRC_FILES:%.neon=%)) \
833    $(eval __files := $(__files:%.arm=%)) \
834    $(filter %$(call module-get-cpp-extension,$1),$(__files))
835
836# Returns true if a module has C++ sources
837#
838module-has-c++-sources = $(strip $(call module-get-c++-sources,$1))
839
840
841# Add C++ dependencies to any module that has C++ sources.
842# $1: list of C++ runtime static libraries (if any)
843# $2: list of C++ runtime shared libraries (if any)
844#
845modules-add-c++-dependencies = \
846    $(foreach __module,$(__ndk_modules),\
847        $(if $(call module-has-c++-sources,$(__module)),\
848            $(call ndk_log,Module '$(__module)' has C++ sources)\
849            $(call module-add-c++-deps,$(__module),$1,$2),\
850        )\
851    )
852
853
854# Return the compiler flags used to compile a C++ module
855# Order matters and should match the one used by the build command
856module-get-c++-flags = $(strip \
857    $(__ndk_modules.$1.CFLAGS) \
858    $(__ndk_modules.$1.CPPFLAGS) \
859    $(__ndk_modules.$1.CXXFLAGS))
860
861# This function is used to remove certain flags from a module compiler flags
862# $1: Module name
863# $2: List of flags to remove
864#
865module-filter-out-compiler-flags = \
866    $(eval __ndk_modules.$1.CFLAGS   := $(filter-out $2,$(__ndk_modules.$1.CFLAGS)))\
867    $(eval __ndk_modules.$1.CPPFLAGS := $(filter-out $2,$(__ndk_modules.$1.CPPFLAGS)))\
868    $(eval __ndk_modules.$1.CXXFLAGS := $(filter-out $2,$(__ndk_modules.$1.CXXFLAGS)))
869
870# Return true if a module's compiler flags enable rtti
871# We just look at -frtti and -fno-rtti on the command-line
872# and keep the last one of these flags.
873module-flags-have-rtti = $(strip \
874        $(filter -frtti,\
875            $(lastword $(filter -frtti -fno-rtti,$(call module-get-c++-flags,$1)))\
876        )\
877    )
878
879# Same with C++ exception support (i.e. -fexceptions and -fno-exceptions)
880#
881module-flags-have-exceptions = $(strip \
882        $(filter -fexceptions,\
883            $(lastword $(filter -fexceptions -fno-execeptions,$(call module-get-c++-flags,$1)))\
884        )\
885    )
886
887# Handle the definition of LOCAL_CPP_FEATURES, i.e.:
888#
889#  - If it is defined, check that it only contains valid values
890#  - If it is undefined, try to compute its value automatically by
891#    looking at the C++ compiler flags used to build the module
892#
893# After this, we remove all features flags from the module's command-line
894# And add only the correct ones back in LOCAL_CPP_FLAGS
895#
896module-handle-c++-features = \
897    $(if $(strip $(__ndk_modules.$1.CPP_FEATURES)),\
898        $(eval __cxxbad := $(filter-out rtti exceptions,$(__ndk_modules.$1.CPP_FEATURES)))\
899        $(if $(__cxxbad),\
900            $(call __ndk_info,WARNING: Ignoring invalid values in LOCAL_CPP_FEATURES definition in $(__ndk_modules.$1.MAKEFILE): $(__cxxbad))\
901            $(eval __ndk_modules.$1.CPP_FEATURES := $(strip $(filter-out $(__cxxbad),$(__ndk_modules.$1.CPP_FEATURES))))\
902        )\
903    ,\
904        $(eval __ndk_modules.$1.CPP_FEATURES := $(strip \
905            $(if $(call module-flags-have-rtti,$1),rtti) \
906            $(if $(call module-flags-have-exceptions,$1),exceptions) \
907        )) \
908    )\
909    $(call module-filter-out-compiler-flags,$1,-frtti -fno-rtti -fexceptions -fno-exceptions)\
910
911# Returns true if a module or its dependencies have specific C++ features
912# (i.e. RTTI or Exceptions)
913#
914# $1: module name
915# $2: list of features (e.g. 'rtti' or 'exceptions')
916#
917module-has-c++-features = $(strip \
918    $(eval __cxxdeps  := $(call module-get-all-dependencies,$1))\
919    $(eval __cxxflags := $(foreach __cxxdep,$(__cxxdeps),$(__ndk_modules.$(__cxxdep).CPP_FEATURES)))\
920    $(if $(filter $2,$(__cxxflags)),true,)\
921    )
922
923# Add standard C++ dependencies to a given module
924#
925# $1: module name
926# $2: list of C++ runtime static libraries (if any)
927# $3: list of C++ runtime shared libraries (if any)
928#
929module-add-c++-deps = \
930    $(eval __ndk_modules.$1.STATIC_LIBRARIES += $(2))\
931    $(eval __ndk_modules.$1.SHARED_LIBRARIES += $(3))
932
933
934# =============================================================================
935#
936# Utility functions
937#
938# =============================================================================
939
940# -----------------------------------------------------------------------------
941# Function : parent-dir
942# Arguments: 1: path
943# Returns  : Parent dir or path of $1, with final separator removed.
944# -----------------------------------------------------------------------------
945parent-dir = $(patsubst %/,%,$(dir $1))
946
947
948# -----------------------------------------------------------------------------
949# Function : pretty-dir
950# Arguments: 1: path
951# Returns  : Remove NDK_PROJECT_PATH prefix from a given path. This can be
952#            used to perform pretty-printing for logs.
953# -----------------------------------------------------------------------------
954pretty-dir = $(patsubst $(NDK_ROOT)/%,<NDK>/%,\
955                 $(patsubst $(NDK_PROJECT_PATH)/%,%,$1))
956
957# -----------------------------------------------------------------------------
958# Function : check-user-define
959# Arguments: 1: name of variable that must be defined by the user
960#            2: name of Makefile where the variable should be defined
961#            3: name/description of the Makefile where the check is done, which
962#               must be included by $2
963# Returns  : None
964# -----------------------------------------------------------------------------
965check-user-define = $(if $(strip $($1)),,\
966  $(call __ndk_error,Missing $1 before including $3 in $2))
967
968# -----------------------------------------------------------------------------
969# This is used to check that LOCAL_MODULE is properly defined by an Android.mk
970# file before including one of the $(BUILD_SHARED_LIBRARY), etc... files.
971#
972# Function : check-user-LOCAL_MODULE
973# Arguments: 1: name/description of the included build Makefile where the
974#               check is done
975# Returns  : None
976# Usage    : $(call check-user-LOCAL_MODULE, BUILD_SHARED_LIBRARY)
977# -----------------------------------------------------------------------------
978check-defined-LOCAL_MODULE = \
979  $(call check-user-define,LOCAL_MODULE,$(local-makefile),$(1)) \
980  $(if $(call seq,$(words $(LOCAL_MODULE)),1),,\
981    $(call __ndk_info,LOCAL_MODULE definition in $(local-makefile) must not contain space)\
982    $(call __ndk_error,Please correct error. Aborting)\
983  )
984
985# -----------------------------------------------------------------------------
986# This is used to check that LOCAL_MODULE_FILENAME, if defined, is correct.
987#
988# Function : check-user-LOCAL_MODULE_FILENAME
989# Returns  : None
990# Usage    : $(call check-user-LOCAL_MODULE_FILENAME)
991# -----------------------------------------------------------------------------
992check-LOCAL_MODULE_FILENAME = \
993  $(if $(strip $(LOCAL_MODULE_FILENAME)),\
994    $(if $(call seq,$(words $(LOCAL_MODULE_FILENAME)),1),,\
995        $(call __ndk_info,$(LOCAL_MAKEFILE):$(LOCAL_MODULE): LOCAL_MODULE_FILENAME must not contain spaces)\
996        $(call __ndk_error,Plase correct error. Aborting)\
997    )\
998    $(if $(filter %.a %.so,$(LOCAL_MODULE_FILENAME)),\
999        $(call __ndk_info,$(LOCAL_MAKEFILE):$(LOCAL_MODULE): LOCAL_MODULE_FILENAME should not include file extensions)\
1000    )\
1001  )
1002
1003# -----------------------------------------------------------------------------
1004# Function  : handle-module-filename
1005# Arguments : 1: default file prefix
1006#             2: file suffix
1007# Returns   : None
1008# Usage     : $(call handle-module-filename,<prefix>,<suffix>)
1009# Rationale : To be used to check and or set the module's filename through
1010#             the LOCAL_MODULE_FILENAME variable.
1011# -----------------------------------------------------------------------------
1012handle-module-filename = $(eval $(call ev-handle-module-filename,$1,$2))
1013
1014#
1015# Check that LOCAL_MODULE_FILENAME is properly defined
1016# - with one single item
1017# - without a library file extension
1018# - with no directory separators
1019#
1020define ev-check-module-filename
1021ifneq (1,$$(words $$(LOCAL_MODULE_FILENAME)))
1022    $$(call __ndk_info,$$(LOCAL_MAKEFILE):$$(LOCAL_MODULE): LOCAL_MODULE_FILENAME must not contain any space)
1023    $$(call __ndk_error,Aborting)
1024endif
1025ifneq (,$$(filter %.a %.so,$$(LOCAL_MODULE_FILENAME)))
1026    $$(call __ndk_info,$$(LOCAL_MAKEFILE):$$(LOCAL_MODULE): LOCAL_MODULE_FILENAME must not contain a file extension)
1027    $$(call __ndk_error,Aborting)
1028endif
1029ifneq (1,$$(words $$(subst /, ,$$(LOCAL_MODULE_FILENAME))))
1030    $$(call __ndk_info,$$(LOCAL_MAKEFILE):$$(LOCAL_MODULE): LOCAL_MODULE_FILENAME must not contain directory separators)
1031    $$(call __ndk_error,Aborting)
1032endif
1033endef
1034
1035#
1036# Check the definition of LOCAL_MODULE_FILENAME. If none exists,
1037# infer it from the LOCAL_MODULE name.
1038#
1039# $1: default file prefix
1040# $2: default file suffix
1041#
1042define ev-handle-module-filename
1043LOCAL_MODULE_FILENAME := $$(strip $$(LOCAL_MODULE_FILENAME))
1044ifndef LOCAL_MODULE_FILENAME
1045    LOCAL_MODULE_FILENAME := $1$$(LOCAL_MODULE)
1046endif
1047$$(eval $$(call ev-check-module-filename))
1048LOCAL_MODULE_FILENAME := $$(LOCAL_MODULE_FILENAME)$2
1049endef
1050
1051handle-prebuilt-module-filename = $(eval $(call ev-handle-prebuilt-module-filename,$1))
1052
1053#
1054# Check the definition of LOCAL_MODULE_FILENAME for a _prebuilt_ module.
1055# If none exists, infer it from $(LOCAL_SRC_FILES)
1056#
1057# $1: default file suffix
1058#
1059define ev-handle-prebuilt-module-filename
1060LOCAL_MODULE_FILENAME := $$(strip $$(LOCAL_MODULE_FILENAME))
1061ifndef LOCAL_MODULE_FILENAME
1062    LOCAL_MODULE_FILENAME := $$(notdir $(LOCAL_SRC_FILES))
1063    LOCAL_MODULE_FILENAME := $$(LOCAL_MODULE_FILENAME:%.a=%)
1064    LOCAL_MODULE_FILENAME := $$(LOCAL_MODULE_FILENAME:%.so=%)
1065endif
1066LOCAL_MODULE_FILENAME := $$(LOCAL_MODULE_FILENAME)$1
1067$$(eval $$(call ev-check-module-filename))
1068endef
1069
1070
1071# -----------------------------------------------------------------------------
1072# Function  : handle-module-built
1073# Returns   : None
1074# Usage     : $(call handle-module-built)
1075# Rationale : To be used to automatically compute the location of the generated
1076#             binary file, and the directory where to place its object files.
1077# -----------------------------------------------------------------------------
1078handle-module-built = \
1079    $(eval LOCAL_BUILT_MODULE := $(TARGET_OUT)/$(LOCAL_MODULE_FILENAME))\
1080    $(eval LOCAL_OBJS_DIR     := $(TARGET_OBJS)/$(LOCAL_MODULE))
1081
1082# -----------------------------------------------------------------------------
1083# Strip any 'lib' prefix in front of a given string.
1084#
1085# Function : strip-lib-prefix
1086# Arguments: 1: module name
1087# Returns  : module name, without any 'lib' prefix if any
1088# Usage    : $(call strip-lib-prefix,$(LOCAL_MODULE))
1089# -----------------------------------------------------------------------------
1090strip-lib-prefix = $(1:lib%=%)
1091
1092# -----------------------------------------------------------------------------
1093# This is used to strip any lib prefix from LOCAL_MODULE, then check that
1094# the corresponding module name is not already defined.
1095#
1096# Function : check-user-LOCAL_MODULE
1097# Arguments: 1: path of Android.mk where this LOCAL_MODULE is defined
1098# Returns  : None
1099# Usage    : $(call check-LOCAL_MODULE,$(LOCAL_MAKEFILE))
1100# -----------------------------------------------------------------------------
1101check-LOCAL_MODULE = \
1102  $(eval LOCAL_MODULE := $$(call strip-lib-prefix,$$(LOCAL_MODULE)))
1103
1104# -----------------------------------------------------------------------------
1105# Macro    : my-dir
1106# Returns  : the directory of the current Makefile
1107# Usage    : $(my-dir)
1108# -----------------------------------------------------------------------------
1109my-dir = $(call parent-dir,$(lastword $(MAKEFILE_LIST)))
1110
1111# -----------------------------------------------------------------------------
1112# Function : all-makefiles-under
1113# Arguments: 1: directory path
1114# Returns  : a list of all makefiles immediately below some directory
1115# Usage    : $(call all-makefiles-under, <some path>)
1116# -----------------------------------------------------------------------------
1117all-makefiles-under = $(wildcard $1/*/Android.mk)
1118
1119# -----------------------------------------------------------------------------
1120# Macro    : all-subdir-makefiles
1121# Returns  : list of all makefiles in subdirectories of the current Makefile's
1122#            location
1123# Usage    : $(all-subdir-makefiles)
1124# -----------------------------------------------------------------------------
1125all-subdir-makefiles = $(call all-makefiles-under,$(call my-dir))
1126
1127# =============================================================================
1128#
1129# Source file tagging support.
1130#
1131# Each source file listed in LOCAL_SRC_FILES can have any number of
1132# 'tags' associated to it. A tag name must not contain space, and its
1133# usage can vary.
1134#
1135# For example, the 'debug' tag is used to sources that must be built
1136# in debug mode, the 'arm' tag is used for sources that must be built
1137# using the 32-bit instruction set on ARM platforms, and 'neon' is used
1138# for sources that must be built with ARM Advanced SIMD (a.k.a. NEON)
1139# support.
1140#
1141# More tags might be introduced in the future.
1142#
1143#  LOCAL_SRC_TAGS contains the list of all tags used (initially empty)
1144#  LOCAL_SRC_FILES contains the list of all source files.
1145#  LOCAL_SRC_TAG.<tagname> contains the set of source file names tagged
1146#      with <tagname>
1147#  LOCAL_SRC_FILES_TAGS.<filename> contains the set of tags for a given
1148#      source file name
1149#
1150# Tags are processed by a toolchain-specific function (e.g. TARGET-compute-cflags)
1151# which will call various functions to compute source-file specific settings.
1152# These are currently stored as:
1153#
1154#  LOCAL_SRC_FILES_TARGET_CFLAGS.<filename> contains the list of
1155#      target-specific C compiler flags used to compile a given
1156#      source file. This is set by the function TARGET-set-cflags
1157#      defined in the toolchain's setup.mk script.
1158#
1159#  LOCAL_SRC_FILES_TEXT.<filename> contains the 'text' that will be
1160#      displayed along the label of the build output line. For example
1161#      'thumb' or 'arm  ' with ARM-based toolchains.
1162#
1163# =============================================================================
1164
1165# -----------------------------------------------------------------------------
1166# Macro    : clear-all-src-tags
1167# Returns  : remove all source file tags and associated data.
1168# Usage    : $(clear-all-src-tags)
1169# -----------------------------------------------------------------------------
1170clear-all-src-tags = \
1171$(foreach __tag,$(LOCAL_SRC_TAGS), \
1172    $(eval LOCAL_SRC_TAG.$(__tag) := $(empty)) \
1173) \
1174$(foreach __src,$(LOCAL_SRC_FILES), \
1175    $(eval LOCAL_SRC_FILES_TAGS.$(__src) := $(empty)) \
1176    $(eval LOCAL_SRC_FILES_TARGET_CFLAGS.$(__src) := $(empty)) \
1177    $(eval LOCAL_SRC_FILES_TEXT.$(__src) := $(empty)) \
1178) \
1179$(eval LOCAL_SRC_TAGS := $(empty_set))
1180
1181# -----------------------------------------------------------------------------
1182# Macro    : tag-src-files
1183# Arguments: 1: list of source files to tag
1184#            2: tag name (must not contain space)
1185# Usage    : $(call tag-src-files,<list-of-source-files>,<tagname>)
1186# Rationale: Add a tag to a list of source files
1187# -----------------------------------------------------------------------------
1188tag-src-files = \
1189$(eval LOCAL_SRC_TAGS := $(call set_insert,$2,$(LOCAL_SRC_TAGS))) \
1190$(eval LOCAL_SRC_TAG.$2 := $(call set_union,$1,$(LOCAL_SRC_TAG.$2))) \
1191$(foreach __src,$1, \
1192    $(eval LOCAL_SRC_FILES_TAGS.$(__src) += $2) \
1193)
1194
1195# -----------------------------------------------------------------------------
1196# Macro    : get-src-files-with-tag
1197# Arguments: 1: tag name
1198# Usage    : $(call get-src-files-with-tag,<tagname>)
1199# Return   : The list of source file names that have been tagged with <tagname>
1200# -----------------------------------------------------------------------------
1201get-src-files-with-tag = $(LOCAL_SRC_TAG.$1)
1202
1203# -----------------------------------------------------------------------------
1204# Macro    : get-src-files-without-tag
1205# Arguments: 1: tag name
1206# Usage    : $(call get-src-files-without-tag,<tagname>)
1207# Return   : The list of source file names that have NOT been tagged with <tagname>
1208# -----------------------------------------------------------------------------
1209get-src-files-without-tag = $(filter-out $(LOCAL_SRC_TAG.$1),$(LOCAL_SRC_FILES))
1210
1211# -----------------------------------------------------------------------------
1212# Macro    : set-src-files-target-cflags
1213# Arguments: 1: list of source files
1214#            2: list of compiler flags
1215# Usage    : $(call set-src-files-target-cflags,<sources>,<flags>)
1216# Rationale: Set or replace the set of compiler flags that will be applied
1217#            when building a given set of source files. This function should
1218#            normally be called from the toolchain-specific function that
1219#            computes all compiler flags for all source files.
1220# -----------------------------------------------------------------------------
1221set-src-files-target-cflags = $(foreach __src,$1,$(eval LOCAL_SRC_FILES_TARGET_CFLAGS.$(__src) := $2))
1222
1223# -----------------------------------------------------------------------------
1224# Macro    : add-src-files-target-cflags
1225# Arguments: 1: list of source files
1226#            2: list of compiler flags
1227# Usage    : $(call add-src-files-target-cflags,<sources>,<flags>)
1228# Rationale: A variant of set-src-files-target-cflags that can be used
1229#            to append, instead of replace, compiler flags for specific
1230#            source files.
1231# -----------------------------------------------------------------------------
1232add-src-files-target-cflags = $(foreach __src,$1,$(eval LOCAL_SRC_FILES_TARGET_CFLAGS.$(__src) += $2))
1233
1234# -----------------------------------------------------------------------------
1235# Macro    : get-src-file-target-cflags
1236# Arguments: 1: single source file name
1237# Usage    : $(call get-src-file-target-cflags,<source>)
1238# Rationale: Return the set of target-specific compiler flags that must be
1239#            applied to a given source file. These must be set prior to this
1240#            call using set-src-files-target-cflags or add-src-files-target-cflags
1241# -----------------------------------------------------------------------------
1242get-src-file-target-cflags = $(LOCAL_SRC_FILES_TARGET_CFLAGS.$1)
1243
1244# -----------------------------------------------------------------------------
1245# Macro    : set-src-files-text
1246# Arguments: 1: list of source files
1247#            2: text
1248# Usage    : $(call set-src-files-text,<sources>,<text>)
1249# Rationale: Set or replace the 'text' associated to a set of source files.
1250#            The text is a very short string that complements the build
1251#            label. For example, it will be either 'thumb' or 'arm  ' for
1252#            ARM-based toolchains. This function must be called by the
1253#            toolchain-specific functions that processes all source files.
1254# -----------------------------------------------------------------------------
1255set-src-files-text = $(foreach __src,$1,$(eval LOCAL_SRC_FILES_TEXT.$(__src) := $2))
1256
1257# -----------------------------------------------------------------------------
1258# Macro    : get-src-file-text
1259# Arguments: 1: single source file
1260# Usage    : $(call get-src-file-text,<source>)
1261# Rationale: Return the 'text' associated to a given source file when
1262#            set-src-files-text was called.
1263# -----------------------------------------------------------------------------
1264get-src-file-text = $(LOCAL_SRC_FILES_TEXT.$1)
1265
1266# This should only be called for debugging the source files tagging system
1267dump-src-file-tags = \
1268$(info LOCAL_SRC_TAGS := $(LOCAL_SRC_TAGS)) \
1269$(info LOCAL_SRC_FILES = $(LOCAL_SRC_FILES)) \
1270$(foreach __tag,$(LOCAL_SRC_TAGS),$(info LOCAL_SRC_TAG.$(__tag) = $(LOCAL_SRC_TAG.$(__tag)))) \
1271$(foreach __src,$(LOCAL_SRC_FILES),$(info LOCAL_SRC_FILES_TAGS.$(__src) = $(LOCAL_SRC_FILES_TAGS.$(__src)))) \
1272$(info WITH arm = $(call get-src-files-with-tag,arm)) \
1273$(info WITHOUT arm = $(call get-src-files-without-tag,arm)) \
1274$(foreach __src,$(LOCAL_SRC_FILES),$(info LOCAL_SRC_FILES_TARGET_CFLAGS.$(__src) = $(LOCAL_SRC_FILES_TARGET_CFLAGS.$(__src)))) \
1275$(foreach __src,$(LOCAL_SRC_FILES),$(info LOCAL_SRC_FILES_TEXT.$(__src) = $(LOCAL_SRC_FILES_TEXT.$(__src)))) \
1276
1277
1278# =============================================================================
1279#
1280# Application.mk support
1281#
1282# =============================================================================
1283
1284# the list of variables that *must* be defined in Application.mk files
1285NDK_APP_VARS_REQUIRED :=
1286
1287# the list of variables that *may* be defined in Application.mk files
1288NDK_APP_VARS_OPTIONAL := APP_OPTIM APP_CPPFLAGS APP_CFLAGS APP_CXXFLAGS \
1289                         APP_PLATFORM APP_BUILD_SCRIPT APP_ABI APP_MODULES \
1290                         APP_PROJECT_PATH APP_STL APP_SHORT_COMMANDS
1291
1292# the list of all variables that may appear in an Application.mk file
1293# or defined by the build scripts.
1294NDK_APP_VARS := $(NDK_APP_VARS_REQUIRED) \
1295                $(NDK_APP_VARS_OPTIONAL) \
1296                APP_DEBUG \
1297                APP_DEBUGGABLE \
1298                APP_MANIFEST
1299
1300# =============================================================================
1301#
1302# Android.mk support
1303#
1304# =============================================================================
1305
1306# =============================================================================
1307#
1308# Build commands support
1309#
1310# =============================================================================
1311
1312get-object-name = $(strip \
1313    $(subst ../,__/,\
1314        $(eval __obj := $1)\
1315        $(foreach __ext,.c .s .S $(LOCAL_CPP_EXTENSION),\
1316            $(eval __obj := $(__obj:%$(__ext)=%.o))\
1317        )\
1318        $(__obj)\
1319    ))
1320
1321# -----------------------------------------------------------------------------
1322# Macro    : hide
1323# Returns  : nothing
1324# Usage    : $(hide)<make commands>
1325# Rationale: To be used as a prefix for Make build commands to hide them
1326#            by default during the build. To show them, set V=1 in your
1327#            environment or command-line.
1328#
1329#            For example:
1330#
1331#                foo.o: foo.c
1332#                -->|$(hide) <build-commands>
1333#
1334#            Where '-->|' stands for a single tab character.
1335#
1336# -----------------------------------------------------------------------------
1337ifeq ($(V),1)
1338hide = $(empty)
1339else
1340hide = @
1341endif
1342
1343# cmd-convert-deps
1344#
1345# On Cygwin, we need to convert the .d dependency file generated by
1346# the gcc toolchain by transforming any Windows paths inside it into
1347# Cygwin paths that GNU Make can understand (i.e. C:/Foo => /cygdrive/c/Foo)
1348#
1349# To do that, we will force the compiler to write the dependency file to
1350# <foo>.d.org, which will will later convert through a clever sed script
1351# that is auto-generated by our build system.
1352#
1353# The script is invoked with:
1354#
1355#    $(NDK_DEPENDENCIES_CONVERTER) foo.d
1356#
1357# It will look if foo.d.org exists, and if so, process it
1358# to generate foo.d, then remove the original foo.d.org.
1359#
1360# On other systems, we simply tell the compiler to write to the .d file directly.
1361#
1362# NOTE: In certain cases, no dependency file will be generated by the
1363#       compiler (e.g. when compiling an assembly file as foo.s)
1364#
1365# convert-deps is used to compute the name of the compiler-generated dependency file
1366# cmd-convert-deps is a command used to convert it to a Cygwin-specific path
1367#
1368ifeq ($(HOST_OS),cygwin)
1369convert-deps = $1.org
1370cmd-convert-deps = && $(NDK_DEPENDENCIES_CONVERTER) $1
1371else
1372convert-deps = $1
1373cmd-convert-deps =
1374endif
1375
1376# This assumes that many variables have been pre-defined:
1377# _SRC: source file
1378# _OBJ: destination file
1379# _CC: 'compiler' command
1380# _FLAGS: 'compiler' flags
1381# _TEXT: Display text (e.g. "Compile++ thumb", must be EXACTLY 15 chars long)
1382#
1383define ev-build-file
1384$$(_OBJ): PRIVATE_SRC      := $$(_SRC)
1385$$(_OBJ): PRIVATE_OBJ      := $$(_OBJ)
1386$$(_OBJ): PRIVATE_DEPS     := $$(call host-path,$$(_OBJ).d)
1387$$(_OBJ): PRIVATE_MODULE   := $$(LOCAL_MODULE)
1388$$(_OBJ): PRIVATE_TEXT     := "$$(_TEXT)"
1389$$(_OBJ): PRIVATE_CC       := $$(_CC)
1390$$(_OBJ): PRIVATE_CFLAGS   := $$(_FLAGS)
1391
1392ifeq ($$(LOCAL_SHORT_COMMANDS),true)
1393_OPTIONS_LISTFILE := $$(_OBJ).cflags
1394$$(_OBJ): $$(call generate-list-file,$$(_FLAGS),$$(_OPTIONS_LISTFILE))
1395$$(_OBJ): PRIVATE_CFLAGS := @$$(call host-path,$$(_OPTIONS_LISTFILE))
1396$$(_OBJ): $$(_OPTIONS_LISTFILE)
1397endif
1398
1399$$(call generate-file-dir,$$(_OBJ))
1400
1401$$(_OBJ): $$(_SRC) $$(LOCAL_MAKEFILE) $$(NDK_APP_APPLICATION_MK) $$(NDK_DEPENDENCIES_CONVERTER)
1402	@$$(HOST_ECHO) "$$(PRIVATE_TEXT)  : $$(PRIVATE_MODULE) <= $$(notdir $$(PRIVATE_SRC))"
1403	$$(hide) $$(PRIVATE_CC) -MMD -MP -MF $$(call convert-deps,$$(PRIVATE_DEPS)) $$(PRIVATE_CFLAGS) $$(call host-path,$$(PRIVATE_SRC)) -o $$(call host-path,$$(PRIVATE_OBJ)) \
1404	$$(call cmd-convert-deps,$$(PRIVATE_DEPS))
1405endef
1406
1407# This assumes the same things than ev-build-file, but will handle
1408# the definition of LOCAL_FILTER_ASM as well.
1409define ev-build-source-file
1410LOCAL_DEPENDENCY_DIRS += $$(dir $$(_OBJ))
1411ifndef LOCAL_FILTER_ASM
1412  # Trivial case: Directly generate an object file
1413  $$(eval $$(call ev-build-file))
1414else
1415  # This is where things get hairy, we first transform
1416  # the source into an assembler file, send it to the
1417  # filter, then generate a final object file from it.
1418  #
1419
1420  # First, remember the original settings and compute
1421  # the location of our temporary files.
1422  #
1423  _ORG_SRC := $$(_SRC)
1424  _ORG_OBJ := $$(_OBJ)
1425  _ORG_FLAGS := $$(_FLAGS)
1426  _ORG_TEXT  := $$(_TEXT)
1427
1428  _OBJ_ASM_ORIGINAL := $$(patsubst %.o,%.s,$$(_ORG_OBJ))
1429  _OBJ_ASM_FILTERED := $$(patsubst %.o,%.filtered.s,$$(_ORG_OBJ))
1430
1431  # If the source file is a plain assembler file, we're going to
1432  # use it directly in our filter.
1433  ifneq (,$$(filter %.s,$$(_SRC)))
1434    _OBJ_ASM_ORIGINAL := $$(_SRC)
1435  endif
1436
1437  #$$(info SRC=$$(_SRC) OBJ=$$(_OBJ) OBJ_ORIGINAL=$$(_OBJ_ASM_ORIGINAL) OBJ_FILTERED=$$(_OBJ_ASM_FILTERED))
1438
1439  # We need to transform the source into an assembly file, instead of
1440  # an object. The proper way to do that depends on the file extension.
1441  #
1442  # For C and C++ source files, simply replace the -c by an -S in the
1443  # compilation command (this forces the compiler to generate an
1444  # assembly file).
1445  #
1446  # For assembler templates (which end in .S), replace the -c with -E
1447  # to send it to the preprocessor instead.
1448  #
1449  # Don't do anything for plain assembly files (which end in .s)
1450  #
1451  ifeq (,$$(filter %.s,$$(_SRC)))
1452    _OBJ   := $$(_OBJ_ASM_ORIGINAL)
1453    ifneq (,$$(filter %.S,$$(_SRC)))
1454      _FLAGS := $$(patsubst -c,-E,$$(_ORG_FLAGS))
1455    else
1456      _FLAGS := $$(patsubst -c,-S,$$(_ORG_FLAGS))
1457    endif
1458    $$(eval $$(call ev-build-file))
1459  endif
1460
1461  # Next, process the assembly file with the filter
1462  $$(_OBJ_ASM_FILTERED): PRIVATE_SRC    := $$(_OBJ_ASM_ORIGINAL)
1463  $$(_OBJ_ASM_FILTERED): PRIVATE_DST    := $$(_OBJ_ASM_FILTERED)
1464  $$(_OBJ_ASM_FILTERED): PRIVATE_FILTER := $$(LOCAL_FILTER_ASM)
1465  $$(_OBJ_ASM_FILTERED): PRIVATE_MODULE := $$(LOCAL_MODULE)
1466  $$(_OBJ_ASM_FILTERED): $$(_OBJ_ASM_ORIGINAL)
1467	@$$(HOST_ECHO) "AsmFilter      : $$(PRIVATE_MODULE) <= $$(notdir $$(PRIVATE_SRC))"
1468	$$(hide) $$(PRIVATE_FILTER) $$(PRIVATE_SRC) $$(PRIVATE_DST)
1469
1470  # Then, generate the final object, we need to keep assembler-specific
1471  # flags which look like -Wa,<option>:
1472  _SRC   := $$(_OBJ_ASM_FILTERED)
1473  _OBJ   := $$(_ORG_OBJ)
1474  _FLAGS := $$(filter -Wa%,$$(_ORG_FLAGS)) -c
1475  _TEXT  := "Assembly     "
1476  $$(eval $$(call ev-build-file))
1477endif
1478endef
1479
1480# -----------------------------------------------------------------------------
1481# Template  : ev-compile-c-source
1482# Arguments : 1: single C source file name (relative to LOCAL_PATH)
1483#             2: target object file (without path)
1484# Returns   : None
1485# Usage     : $(eval $(call ev-compile-c-source,<srcfile>,<objfile>)
1486# Rationale : Internal template evaluated by compile-c-source and
1487#             compile-s-source
1488# -----------------------------------------------------------------------------
1489define  ev-compile-c-source
1490_SRC:=$$(LOCAL_PATH)/$(1)
1491_OBJ:=$$(LOCAL_OBJS_DIR)/$(2)
1492
1493_FLAGS := $$($$(my)CFLAGS) \
1494          $$(call get-src-file-target-cflags,$(1)) \
1495          $$(call host-c-includes,$$(LOCAL_C_INCLUDES) $$(LOCAL_PATH)) \
1496          $$(LOCAL_CFLAGS) \
1497          $$(NDK_APP_CFLAGS) \
1498          $$(call host-c-includes,$$($(my)C_INCLUDES)) \
1499          -c \
1500
1501_TEXT := "Compile $$(call get-src-file-text,$1)"
1502_CC   := $$(NDK_CCACHE) $$(TARGET_CC)
1503
1504$$(eval $$(call ev-build-source-file))
1505endef
1506
1507# -----------------------------------------------------------------------------
1508# Function  : compile-c-source
1509# Arguments : 1: single C source file name (relative to LOCAL_PATH)
1510#             2: object file
1511# Returns   : None
1512# Usage     : $(call compile-c-source,<srcfile>,<objfile>)
1513# Rationale : Setup everything required to build a single C source file
1514# -----------------------------------------------------------------------------
1515compile-c-source = $(eval $(call ev-compile-c-source,$1,$2))
1516
1517# -----------------------------------------------------------------------------
1518# Function  : compile-s-source
1519# Arguments : 1: single Assembly source file name (relative to LOCAL_PATH)
1520#             2: object file
1521# Returns   : None
1522# Usage     : $(call compile-s-source,<srcfile>,<objfile>)
1523# Rationale : Setup everything required to build a single Assembly source file
1524# -----------------------------------------------------------------------------
1525compile-s-source = $(eval $(call ev-compile-c-source,$1,$2))
1526
1527
1528# -----------------------------------------------------------------------------
1529# Template  : ev-compile-cpp-source
1530# Arguments : 1: single C++ source file name (relative to LOCAL_PATH)
1531#             2: target object file (without path)
1532# Returns   : None
1533# Usage     : $(eval $(call ev-compile-cpp-source,<srcfile>,<objfile>)
1534# Rationale : Internal template evaluated by compile-cpp-source
1535# -----------------------------------------------------------------------------
1536
1537define  ev-compile-cpp-source
1538_SRC:=$$(LOCAL_PATH)/$(1)
1539_OBJ:=$$(LOCAL_OBJS_DIR)/$(2)
1540_FLAGS := $$($$(my)CXXFLAGS) \
1541          $$(call get-src-file-target-cflags,$(1)) \
1542          $$(call host-c-includes, $$(LOCAL_C_INCLUDES) $$(LOCAL_PATH)) \
1543          $$(LOCAL_CFLAGS) \
1544          $$(LOCAL_CPPFLAGS) \
1545          $$(LOCAL_CXXFLAGS) \
1546          $$(NDK_APP_CFLAGS) \
1547          $$(NDK_APP_CPPFLAGS) \
1548          $$(NDK_APP_CXXFLAGS) \
1549          $$(call host-c-includes,$$($(my)C_INCLUDES)) \
1550          -c \
1551
1552_CC   := $$(NDK_CCACHE) $$($$(my)CXX)
1553_TEXT := "Compile++ $$(call get-src-file-text,$1)"
1554
1555$$(eval $$(call ev-build-source-file))
1556endef
1557
1558# -----------------------------------------------------------------------------
1559# Function  : compile-cpp-source
1560# Arguments : 1: single C++ source file name (relative to LOCAL_PATH)
1561#           : 2: object file name
1562# Returns   : None
1563# Usage     : $(call compile-c-source,<srcfile>)
1564# Rationale : Setup everything required to build a single C++ source file
1565# -----------------------------------------------------------------------------
1566compile-cpp-source = $(eval $(call ev-compile-cpp-source,$1,$2))
1567
1568#
1569#  Module imports
1570#
1571
1572# Initialize import list
1573import-init = $(eval __ndk_import_dirs :=)
1574
1575# Add an optional single directory to the list of import paths
1576#
1577import-add-path-optional = \
1578  $(if $(strip $(wildcard $1)),\
1579    $(call ndk_log,Adding import directory: $1)\
1580    $(eval __ndk_import_dirs += $1)\
1581  )\
1582
1583# Add a directory to the list of import paths
1584# This will warn if the directory does not exist
1585#
1586import-add-path = \
1587  $(if $(strip $(wildcard $1)),\
1588    $(call ndk_log,Adding import directory: $1)\
1589    $(eval __ndk_import_dirs += $1)\
1590  ,\
1591    $(call __ndk_info,WARNING: Ignoring unknown import directory: $1)\
1592  )\
1593
1594import-find-module = $(strip \
1595      $(eval __imported_module :=)\
1596      $(foreach __import_dir,$(__ndk_import_dirs),\
1597        $(if $(__imported_module),,\
1598          $(call ndk_log,  Probing $(__import_dir)/$1/Android.mk)\
1599          $(if $(strip $(wildcard $(__import_dir)/$1/Android.mk)),\
1600            $(eval __imported_module := $(__import_dir)/$1)\
1601          )\
1602        )\
1603      )\
1604      $(__imported_module)\
1605    )
1606
1607# described in docs/IMPORT-MODULE.TXT
1608# $1: tag name for the lookup
1609#
1610# Small technical note on __ndk_import_depth: we use this variable to
1611# record the depth of recursive import-module calls. The variable is
1612# initially empty, and we append a "x" to it each time import-module is
1613# called. I.e. for three recursive calls to import-module, we would get
1614# the values:
1615#
1616#   first call:   x
1617#   second call:  xx
1618#   third call:   xxx
1619#
1620# This is used in module-add to add the top-level modules (i.e. those
1621# that are not added with import-module) to __ndk_top_modules, corresponding
1622# to the default list of wanted modules (see setup-toolchain.mk).
1623#
1624import-module = \
1625    $(eval __import_tag := $(strip $1))\
1626    $(if $(call seq,$(words $(__import_tag)),1),,\
1627      $(call __ndk_info,$(call local-makefile): Cannot import module with spaces in tag: '$(__import_tag)')\
1628    )\
1629    $(if $(call set_is_member,$(__ndk_import_list),$(__import_tag)),\
1630      $(call ndk_log,Skipping duplicate import for module with tag '$(__import_tag)')\
1631    ,\
1632      $(call ndk_log,Looking for imported module with tag '$(__import_tag)')\
1633      $(eval __imported_path := $(call import-find-module,$(__import_tag)))\
1634      $(if $(__imported_path),\
1635        $(call ndk_log,    Found in $(__imported_path))\
1636        $(eval __ndk_import_depth := $(__ndk_import_depth)x) \
1637        $(eval __ndk_import_list := $(call set_insert,$(__ndk_import_list),$(__import_tag)))\
1638        $(eval include $(__imported_path)/Android.mk)\
1639        $(eval __ndk_import_depth := $(__ndk_import_depth:%x=%))\
1640      ,\
1641        $(call __ndk_info,$(call local-makefile): Cannot find module with tag '$(__import_tag)' in import path)\
1642        $(call __ndk_info,Are you sure your NDK_MODULE_PATH variable is properly defined ?)\
1643        $(call __ndk_info,The following directories were searched:)\
1644        $(for __import_dir,$(__ndk_import_dirs),\
1645          $(call __ndk_info,    $(__import_dir))\
1646        )\
1647        $(call __ndk_error,Aborting.)\
1648      )\
1649   )
1650
1651# Only used for debugging
1652#
1653import-debug = \
1654    $(info IMPORT DIRECTORIES:)\
1655    $(foreach __dir,$(__ndk_import_dirs),\
1656      $(info -- $(__dir))\
1657    )\
1658
1659#
1660#  Module classes
1661#
1662NDK_MODULE_CLASSES :=
1663
1664# Register a new module class
1665# $1: class name (e.g. STATIC_LIBRARY)
1666# $2: optional file prefix (e.g. 'lib')
1667# $3: optional file suffix (e.g. '.so')
1668#
1669module-class-register = \
1670    $(eval NDK_MODULE_CLASSES += $1) \
1671    $(eval NDK_MODULE_CLASS.$1.FILE_PREFIX := $2) \
1672    $(eval NDK_MODULE_CLASS.$1.FILE_SUFFIX := $3) \
1673    $(eval NDK_MODULE_CLASS.$1.INSTALLABLE := $(false)) \
1674
1675# Same a module-class-register, for installable modules
1676#
1677# An installable module is one that will be copied to $PROJECT/libs/<abi>/
1678# during the NDK build.
1679#
1680# $1: class name
1681# $2: optional file prefix
1682# $3: optional file suffix
1683#
1684module-class-register-installable = \
1685    $(call module-class-register,$1,$2,$3) \
1686    $(eval NDK_MODULE_CLASS.$1.INSTALLABLE := $(true))
1687
1688module-class-set-prebuilt = \
1689    $(eval NDK_MODULE_CLASS.$1.PREBUILT := $(true))
1690
1691# Returns $(true) if $1 is a valid/registered LOCAL_MODULE_CLASS value
1692#
1693module-class-check = $(call set_is_member,$(NDK_MODULE_CLASSES),$1)
1694
1695# Returns $(true) if $1 corresponds to an installable module class
1696#
1697module-class-is-installable = $(if $(NDK_MODULE_CLASS.$1.INSTALLABLE),$(true),$(false))
1698
1699# Returns $(true) if $1 corresponds to an installable module class
1700#
1701module-class-is-prebuilt = $(if $(NDK_MODULE_CLASS.$1.PREBUILT),$(true),$(false))
1702
1703#
1704# Register valid module classes
1705#
1706
1707# static libraries:
1708# <foo> -> lib<foo>.a by default
1709$(call module-class-register,STATIC_LIBRARY,lib,.a)
1710
1711# shared libraries:
1712# <foo> -> lib<foo>.so
1713# a shared library is installable.
1714$(call module-class-register-installable,SHARED_LIBRARY,lib,.so)
1715
1716# executable
1717# <foo> -> <foo>
1718# an executable is installable.
1719$(call module-class-register-installable,EXECUTABLE,,)
1720
1721# prebuilt shared library
1722# <foo> -> <foo>  (we assume it is already well-named)
1723# it is installable
1724$(call module-class-register-installable,PREBUILT_SHARED_LIBRARY,,)
1725$(call module-class-set-prebuilt,PREBUILT_SHARED_LIBRARY)
1726
1727# prebuilt static library
1728# <foo> -> <foo> (we assume it is already well-named)
1729$(call module-class-register,PREBUILT_STATIC_LIBRARY,,)
1730$(call module-class-set-prebuilt,PREBUILT_STATIC_LIBRARY)
1731
1732#
1733# C++ STL support
1734#
1735
1736# The list of registered STL implementations we support
1737NDK_STL_LIST :=
1738
1739# Used internally to register a given STL implementation, see below.
1740#
1741# $1: STL name as it appears in APP_STL (e.g. system)
1742# $2: STL module name (e.g. cxx-stl/system)
1743# $3: list of static libraries all modules will depend on
1744# $4: list of shared libraries all modules will depend on
1745#
1746ndk-stl-register = \
1747    $(eval __ndk_stl := $(strip $1)) \
1748    $(eval NDK_STL_LIST += $(__ndk_stl)) \
1749    $(eval NDK_STL.$(__ndk_stl).IMPORT_MODULE := $(strip $2)) \
1750    $(eval NDK_STL.$(__ndk_stl).STATIC_LIBS := $(strip $3)) \
1751    $(eval NDK_STL.$(__ndk_stl).SHARED_LIBS := $(strip $4))
1752
1753# Called to check that the value of APP_STL is a valid one.
1754# $1: STL name as it apperas in APP_STL (e.g. 'system')
1755#
1756ndk-stl-check = \
1757    $(if $(call set_is_member,$(NDK_STL_LIST),$1),,\
1758        $(call __ndk_info,Invalid APP_STL value: $1)\
1759        $(call __ndk_info,Please use one of the following instead: $(NDK_STL_LIST))\
1760        $(call __ndk_error,Aborting))
1761
1762# Called before the top-level Android.mk is parsed to
1763# select the STL implementation.
1764# $1: STL name as it appears in APP_STL (e.g. system)
1765#
1766ndk-stl-select = \
1767    $(call import-module,$(NDK_STL.$1.IMPORT_MODULE))
1768
1769# Called after all Android.mk files are parsed to add
1770# proper STL dependencies to every C++ module.
1771# $1: STL name as it appears in APP_STL (e.g. system)
1772#
1773ndk-stl-add-dependencies = \
1774    $(call modules-add-c++-dependencies,\
1775        $(NDK_STL.$1.STATIC_LIBS),\
1776        $(NDK_STL.$1.SHARED_LIBS))
1777
1778#
1779#
1780
1781# Register the 'system' STL implementation
1782#
1783$(call ndk-stl-register,\
1784    system,\
1785    cxx-stl/system,\
1786    libstdc++,\
1787    )
1788
1789# Register the 'stlport_static' STL implementation
1790#
1791$(call ndk-stl-register,\
1792    stlport_static,\
1793    cxx-stl/stlport,\
1794    stlport_static,\
1795    )
1796
1797# Register the 'stlport_shared' STL implementation
1798#
1799$(call ndk-stl-register,\
1800    stlport_shared,\
1801    cxx-stl/stlport,\
1802    ,\
1803    stlport_shared\
1804    )
1805
1806# Register the 'gnustl_static' STL implementation
1807#
1808$(call ndk-stl-register,\
1809    gnustl_static,\
1810    cxx-stl/gnu-libstdc++,\
1811    gnustl_static,\
1812    \
1813    )
1814
1815$(call ndk-stl-register,\
1816    gnustl_shared,\
1817    cxx-stl/gnu-libstdc++,\
1818    ,\
1819    gnustl_shared\
1820    )
1821
1822# Register the static version of the GAbi++ C++ runtime
1823#
1824$(call ndk-stl-register,\
1825    gabi++_static,\
1826    cxx-stl/gabi++,\
1827    gabi++_static,\
1828    )
1829
1830# Register the shared version of the GAbi++ C++ runtime
1831#
1832$(call ndk-stl-register,\
1833    gabi++_shared,\
1834    cxx-stl/gabi++,\
1835    gabi++_shared,\
1836    )
1837
1838# The 'none' APP_STL value corresponds to no C++ support at
1839# all. Used by some of the STLport and GAbi++ test projects.
1840#
1841$(call ndk-stl-register,\
1842    none,\
1843    cxx-stl/system,\
1844    )
1845