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