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