Home | History | Annotate | Download | only in text
      1 `Android.mk` file syntax specification
      2 
      3 Introduction:
      4 -------------
      5 
      6 This document describes the syntax of `Android.mk` build file
      7 written to describe your C and C++ source files to the Android
      8 NDK. To understand what follows, it is assumed that you have
      9 read the [OVERVIEW](OVERVIEW.html) file that explains their role and
     10 usage.
     11 
     12 Overview:
     13 ---------
     14 
     15 An `Android.mk` file is written to describe your sources to the
     16 build system. More specifically:
     17 
     18 - The file is really a tiny GNU Makefile fragment that will be
     19   parsed one or more times by the build system. As such, you
     20   should try to minimize the variables you declare there and
     21   do not assume that anything is not defined during parsing.
     22 
     23 - The file syntax is designed to allow you to group your
     24   sources into 'modules'. A module is one of the following:
     25 
     26     - A static library.
     27     - A shared library.
     28     - A standalone executable.
     29 
     30   Only shared libraries will be installed/copied to your
     31   application package. Static libraries can be used to generate
     32   shared libraries though.
     33 
     34   You can define one or more modules in each `Android.mk` file,
     35   and you can use the same source file in several modules.
     36 
     37 - The build system handles many details for you. For example, you
     38   don't need to list header files or explicit dependencies between
     39   generated files in your `Android.mk`. The NDK build system will
     40   compute these automatically for you.
     41 
     42   This also means that, when updating to newer releases of the NDK,
     43   you should be able to benefit from new toolchain/platform support
     44   without having to touch your `Android.mk` files.
     45 
     46 Note that the syntax is *very* close to the one used in `Android.mk` files
     47 distributed with the full open-source Android platform sources. While
     48 the build system implementation that uses them is different, this is
     49 an intentional design decision made to allow reuse of 'external' libraries'
     50 source code easier for application developers.
     51 
     52 Simple example:
     53 ---------------
     54 
     55 Before describing the syntax in details, let's consider the simple
     56 "hello JNI" example, i.e. the files under:
     57 
     58 > `samples/hello-jni`
     59 
     60 Here, we can see:
     61 
     62   - The `src` directory containing the Java sources for the
     63     sample Android project.
     64 
     65   - The `jni` directory containing the native source for
     66     the sample, i.e. `jni/hello-jni.c`
     67 
     68     This source file implements a simple shared library that
     69     implements a native method that returns a string to the
     70     VM application.
     71 
     72   - The `jni/Android.mk` file that describes the shared library
     73     to the NDK build system. Its content is:
     74 
     75 #
     76 
     77         ---------- cut here ------------------
     78         LOCAL_PATH := $(call my-dir)
     79 
     80         include $(CLEAR_VARS)
     81 
     82         LOCAL_MODULE    := hello-jni
     83         LOCAL_SRC_FILES := hello-jni.c
     84 
     85         include $(BUILD_SHARED_LIBRARY)
     86         ---------- cut here ------------------
     87 
     88 Now, let's explain these lines:
     89 
     90         LOCAL_PATH := $(call my-dir)
     91 
     92 
     93 An `Android.mk` file must begin with the definition of the LOCAL_PATH variable.
     94 It is used to locate source files in the development tree. In this example,
     95 the macro function 'my-dir', provided by the build system, is used to return
     96 the path of the current directory (i.e. the directory containing the
     97 `Android.mk` file itself).
     98 
     99         include $(CLEAR_VARS)
    100 
    101 The CLEAR_VARS variable is provided by the build system and points to a
    102 special GNU Makefile that will clear many LOCAL_XXX variables for you
    103 (e.g. LOCAL_MODULE, LOCAL_SRC_FILES, LOCAL_STATIC_LIBRARIES, etc...),
    104 with the exception of LOCAL_PATH. This is needed because all build
    105 control files are parsed in a single GNU Make execution context where
    106 all variables are global.
    107 
    108         LOCAL_MODULE := hello-jni
    109 
    110 The LOCAL_MODULE variable must be defined to identify each module you
    111 describe in your `Android.mk`. The name must be *unique* and not contain
    112 any spaces. Note that the build system will automatically add proper
    113 prefix and suffix to the corresponding generated file. In other words,
    114 a shared library module named 'foo' will generate 'libfoo.so'.
    115 
    116 IMPORTANT NOTE:
    117 If you name your module 'libfoo', the build system will not
    118 add another 'lib' prefix and will generate libfoo.so as well.
    119 This is to support `Android.mk` files that originate from the
    120 Android platform sources, would you need to use these.
    121 
    122         LOCAL_SRC_FILES := hello-jni.c
    123 
    124 The LOCAL_SRC_FILES variables must contain a list of C and/or C++ source
    125 files that will be built and assembled into a module. Note that you should
    126 not list header and included files here, because the build system will
    127 compute dependencies automatically for you; just list the source files
    128 that will be passed directly to a compiler, and you should be good.
    129 
    130 Note that the default extension for C++ source files is '.cpp'. It is
    131 however possible to specify a different one by defining the variable
    132 LOCAL_CPP_EXTENSION. Don't forget the initial dot (i.e. '.cxx' will
    133 work, but not 'cxx').
    134 
    135         include $(BUILD_SHARED_LIBRARY)
    136 
    137 The BUILD_SHARED_LIBRARY is a variable provided by the build system that
    138 points to a GNU Makefile script that is in charge of collecting all the
    139 information you defined in LOCAL_XXX variables since the latest
    140 'include $(CLEAR_VARS)' and determine what to build, and how to do it
    141 exactly. There is also BUILD_STATIC_LIBRARY to generate a static library.
    142 
    143 There are more complex examples in the samples directories, with commented
    144 `Android.mk` files that you can look at.
    145 
    146 Reference:
    147 ----------
    148 
    149 This is the list of variables you should either rely on or define in
    150 an `Android.mk`. You can define other variables for your own usage, but
    151 the NDK build system reserves the following variable names:
    152 
    153 - Names that begin with LOCAL_  (e.g. LOCAL_MODULE)
    154 - Names that begin with PRIVATE_, NDK_ or APP_  (used internally)
    155 - Lower-case names (used internally, e.g. `my-dir`)
    156 
    157 If you need to define your own convenience variables in an `Android.mk`
    158 file, we recommend using the MY_ prefix, for a trivial example:
    159 
    160         ---------- cut here ------------------
    161         MY_SOURCES := foo.c
    162         ifneq ($(MY_CONFIG_BAR),)
    163           MY_SOURCES += bar.c
    164         endif
    165 
    166         LOCAL_SRC_FILES += $(MY_SOURCES)
    167         ---------- cut here ------------------
    168 
    169 So, here we go:
    170 
    171 
    172 NDK-provided variables:
    173 -----------------------
    174 
    175 These GNU Make variables are defined by the build system before
    176 your `Android.mk` file is parsed. Note that under certain circumstances
    177 the NDK might parse your `Android.mk` several times, each with different
    178 definition for some of these variables.
    179 
    180 - - - - - - - - - - -
    181 CLEAR_VARS
    182 > Points to a build script that undefines nearly all LOCAL_XXX variables
    183 > listed in the "Module-description" section below. You must include
    184 > the script before starting a new module, e.g.:
    185 
    186             include $(CLEAR_VARS)
    187 
    188 - - - - - - - - - - -
    189 BUILD_SHARED_LIBRARY
    190 > Points to a build script that collects all the information about the
    191 > module you provided in LOCAL_XXX variables and determines how to build
    192 > a target shared library from the sources you listed. Note that you
    193 > must have LOCAL_MODULE and LOCAL_SRC_FILES defined, at a minimum before
    194 > including this file. Example usage:
    195 
    196             include $(BUILD_SHARED_LIBRARY)
    197 
    198 > note that this will generate a file named `lib$(LOCAL_MODULE).so`.
    199 
    200 - - - - - - - - - - -
    201 BUILD_STATIC_LIBRARY
    202 >    A variant of BUILD_SHARED_LIBRARY that is used to build a target static
    203 >    library instead. Static libraries are not copied into your
    204 >    project/packages but can be used to build shared libraries (see
    205 >    LOCAL_STATIC_LIBRARIES and LOCAL_WHOLE_STATIC_LIBRARIES described below).
    206 >    Example usage:
    207 
    208             include $(BUILD_STATIC_LIBRARY)
    209 
    210 > Note that this will generate a file named `lib$(LOCAL_MODULE).a`.
    211 
    212 - - - - - - - - - - -
    213 PREBUILT_SHARED_LIBRARY
    214 >    Points to a build script used to specify a prebuilt shared library.
    215 >    Unlike BUILD_SHARED_LIBRARY and BUILD_STATIC_LIBRARY, the value
    216 >    of LOCAL_SRC_FILES must be a single path to a prebuilt shared
    217 >    library (e.g. `foo/libfoo.so`), instead of a source file.
    218 
    219 >    You can reference the prebuilt library in another module using
    220 >    the LOCAL_PREBUILTS variable (see [PREBUILTS](PREBUILTS.html) for more
    221 >    information).
    222 
    223 - - - - - - - - - - -
    224 PREBUILT_STATIC_LIBRARY
    225 >    This is the same as PREBUILT_SHARED_LIBRARY, but for a static library
    226 >    file instead. See [PREBUILTS](PREBUILTS.html) for more.
    227 
    228 - - - - - - - - - - -
    229 TARGET_ARCH
    230 >    Name of the target CPU architecture as it is specified by the
    231 >    full Android open-source build. This is 'arm' for any ARM-compatible
    232 >    build, independent of the CPU architecture revision.
    233 
    234 - - - - - - - - - - -
    235 TARGET_PLATFORM
    236 >    Name of the target Android platform when this `Android.mk` is parsed.
    237 >    For example, 'android-3' correspond to Android 1.5 system images. For
    238 >    a complete list of platform names and corresponding Android system
    239 >    images, read [STABLE APIS](STABLE-APIS.html).
    240 
    241 - - - - - - - - - - -
    242 TARGET_ARCH_ABI
    243 >    Name of the target CPU+ABI when this `Android.mk` is parsed.
    244 >    Four values are supported at the moment:
    245 
    246        armeabi
    247             For ARMv5TE
    248 
    249        armeabi-v7a
    250             For ARMv7
    251 
    252        x86
    253             For i686
    254 
    255        mips
    256             For mips32 (r1)
    257 
    258 >    NOTE: Up to Android NDK 1.6_r1, this variable was simply defined
    259 >          as '`arm`'. However, the value has been redefined to better
    260 >          match what is used internally by the Android platform.
    261 
    262 >    For more details about architecture ABIs and corresponding
    263 >    compatibility issues, please read [CPU ARCH ABIS](CPU-ARCH-ABIS.html)
    264 
    265 >    Other target ABIs will be introduced in future releases of the NDK
    266 >    and will have a different name. Note that all ARM-based ABIs will
    267 >    have 'TARGET_ARCH' defined to '`arm`', but may have different
    268 >    'TARGET_ARCH_ABI'
    269 
    270 - - - - - - - - - - -
    271 TARGET_ABI
    272 >    The concatenation of target platform and ABI, it really is defined
    273 >    as `$(TARGET_PLATFORM)-$(TARGET_ARCH_ABI)` and is useful when you want
    274 >    to test against a specific target system image for a real device.
    275 
    276 >    By default, this will be '`android-3-armeabi`'
    277 
    278 >    (Up to Android NDK 1.6_r1, this used to be '`android-3-arm`' by default)
    279 
    280 NDK-provided function macros:
    281 -----------------------------
    282 
    283 The following are GNU Make 'function' macros, and must be evaluated
    284 by using '$(call <function>)'. They return textual information.
    285 
    286 - - - -
    287 my-dir
    288 >    Returns the path of the last included Makefile, which typically is
    289 >    the current `Android.mk`'s directory. This is useful to define
    290 >    LOCAL_PATH at the start of your `Android.mk` as with:
    291 
    292               LOCAL_PATH := $(call my-dir)
    293 
    294 >    IMPORTANT NOTE: Due to the way GNU Make works, this really returns
    295 >    the path of the *last* *included* *Makefile* during the parsing of
    296 >    build scripts. Do not call `my-dir` after including another file.
    297 
    298 >    For example, consider the following example:
    299 
    300               LOCAL_PATH := $(call my-dir)
    301 
    302               ... declare one module
    303 
    304               include $(LOCAL_PATH)/foo/`Android.mk`
    305 
    306               LOCAL_PATH := $(call my-dir)
    307 
    308               ... declare another module
    309 
    310 >    The problem here is that the second call to `my-dir` will define
    311 >    LOCAL_PATH to `$PATH/foo` instead of `$PATH`, due to the include that
    312 >    was performed before that.
    313 
    314 >    For this reason, it's better to put additional includes after
    315 >    everything else in an `Android.mk`, as in:
    316 
    317               LOCAL_PATH := $(call my-dir)
    318 
    319               ... declare one module
    320 
    321               LOCAL_PATH := $(call my-dir)
    322 
    323               ... declare another module
    324 
    325               # extra includes at the end of the `Android.mk`
    326               include $(LOCAL_PATH)/foo/`Android.mk`
    327 
    328 >    If this is not convenient, save the value of the first `my-dir` call
    329 >    into another variable, for example:
    330 
    331               MY_LOCAL_PATH := $(call my-dir)
    332 
    333               LOCAL_PATH := $(MY_LOCAL_PATH)
    334 
    335               ... declare one module
    336 
    337               include $(LOCAL_PATH)/foo/`Android.mk`
    338 
    339               LOCAL_PATH := $(MY_LOCAL_PATH)
    340 
    341               ... declare another module
    342 
    343 
    344 - - - -
    345 all-subdir-makefiles
    346 >    Returns a list of `Android.mk` located in all sub-directories of
    347 >    the current 'my-dir' path. For example, consider the following
    348 >    hierarchy:
    349 
    350               sources/foo/Android.mk
    351               sources/foo/lib1/Android.mk
    352               sources/foo/lib2/Android.mk
    353 
    354 >    If sources/foo/`Android.mk` contains the single line:
    355 
    356               include $(call all-subdir-makefiles)
    357 
    358 >    Then it will include automatically sources/foo/lib1/`Android.mk` and
    359 >    sources/foo/lib2/`Android.mk`
    360 
    361 >    This function can be used to provide deep-nested source directory
    362 >    hierarchies to the build system. Note that by default, the NDK
    363 >    will only look for files in sources/*/`Android.mk`
    364 
    365 - - - -
    366 this-makefile
    367 >    Returns the path of the current Makefile (i.e. where the function
    368 >    is called).
    369 
    370 - - - -
    371 parent-makefile
    372 >    Returns the path of the parent Makefile in the inclusion tree,
    373 >    i.e. the path of the Makefile that included the current one.
    374 
    375 - - - -
    376 grand-parent-makefile
    377 >    Guess what...
    378 
    379 - - - -
    380 import-module
    381 >    A function that allows you to find and include the `Android.mk`
    382 >    of another module by name. A typical example is:
    383 
    384             $(call import-module,<name>)
    385 
    386 >    And this will look for the module tagged <name> in the list of
    387 >    directories referenced by your NDK_MODULE_PATH environment
    388 >    variable, and include its `Android.mk` automatically for you.
    389 >
    390 >    Read [IMPORT-MODULE](IMPORT-MODULE.html) for more details.
    391 - - - -
    392 
    393 
    394 Module-description variables:
    395 -----------------------------
    396 
    397 The following variables are used to describe your module to the build
    398 system. You should define some of them between an '`include $(CLEAR_VARS)`'
    399 and an '`include $(BUILD_XXXXX)`'. As written previously, $(CLEAR_VARS) is
    400 a script that will undefine/clear all of these variables, unless explicitly
    401 noted in their description.
    402 
    403 - - - -
    404 LOCAL_PATH
    405 >    This variable is used to give the path of the current file.
    406 >    You MUST define it at the start of your `Android.mk`, which can
    407 >    be done with:
    408 
    409             LOCAL_PATH := $(call my-dir)
    410 
    411 >    This variable is *not* cleared by $(CLEAR_VARS) so only one
    412 >    definition per `Android.mk` is needed (in case you define several
    413 >    modules in a single file).
    414 
    415 - - - -
    416 LOCAL_MODULE
    417 >    This is the name of your module. It must be unique among all
    418 >    module names, and shall not contain any space. You MUST define
    419 >    it before including any $(BUILD_XXXX) script.
    420 >
    421 >    By default, the module name determines the name of generated files,
    422 >    e.g. lib<foo>.so for a shared library module named <foo>. However
    423 >    you should only refer to other modules with their 'normal'
    424 >    name (e.g. <foo>) in your NDK build files (either `Android.mk`
    425 >    or Application.mk)
    426 >
    427 >    You can override this default with LOCAL_MODULE_FILENAME (see below)
    428 
    429 - - - -
    430 LOCAL_MODULE_FILENAME
    431 >    This variable is optional, and allows you to redefine the name of
    432 >    generated files. By default, module <foo> will always generate a
    433 >    static library named lib<foo>.a or a shared library named lib<foo>.so,
    434 >    which are standard Unix conventions.
    435 >
    436 >    You can override this by defining LOCAL_MODULE_FILENAME, For example:
    437 
    438               LOCAL_MODULE := foo-version-1
    439               LOCAL_MODULE_FILENAME := libfoo
    440 
    441 >    *NOTE(: You should not put a path or file extension in your
    442 >    LOCAL_MODULE_FILENAME, these will be handled automatically by the
    443 >    build system.
    444 
    445 - - - -
    446 LOCAL_SRC_FILES
    447 >    This is a list of source files that will be built for your module.
    448 >    Only list the files that will be passed to a compiler, since the
    449 >    build system automatically computes dependencies for you.
    450 >
    451 >    Note that source files names are relative to LOCAL_PATH and
    452 >    you can use path components, e.g.:
    453 
    454             LOCAL_SRC_FILES := foo.c \
    455                                toto/bar.c
    456 
    457 >    Absolute file paths are also supported:
    458 
    459             LOCAL_SRC_FILES := /home/user/mysources/foo.c
    460 
    461 >    or on Windows:
    462 
    463             LOCAL_SRC_FILES := c:/Users/user/sources/foo.c
    464 
    465 >    Avoiding absolute file paths is recommended, this makes your
    466 >    `Android.mk` easy to reuse on a different machine / system.
    467 >
    468 >    NOTE: Always use Unix-style forward slashes (/) in build files.
    469 >          Windows-style back-slashes will not be handled properly.
    470 
    471 - - - -
    472 LOCAL_CPP_EXTENSION
    473 >    This is an optional variable that can be defined to indicate
    474 >    the file extension(s) of C++ source files. They must begin with a dot.
    475 >    The default is '.cpp' but you can change it. For example:
    476 
    477               LOCAL_CPP_EXTENSION := .cxx
    478 
    479 >    Since NDK r7, you can list several extensions in this variable, as in:
    480 
    481               LOCAL_CPP_EXTENSION := .cxx .cpp .cc
    482 
    483 - - - -
    484 LOCAL_CPP_FEATURES
    485 >    This is an optional variable that can be defined to indicate
    486 >    that your code relies on specific C++ features. To indicate that
    487 >    your code uses RTTI (RunTime Type Information), use the following:
    488 
    489               LOCAL_CPP_FEATURES := rtti
    490 
    491 >    To indicate that your code uses C++ exceptions, use:
    492 
    493               LOCAL_CPP_FEATURES := exceptions
    494 
    495 >    You can also use both of them with (order is not important):
    496 
    497               LOCAL_CPP_FEATURES := rtti features
    498 
    499 >    The effect of this variable is to enable the right compiler/linker
    500 >    flags when building your modules from sources. For prebuilt binaries,
    501 >    this also helps declare which features the binary relies on to ensure
    502 >    the final link works correctly.
    503 >
    504 >    It is recommended to use this variable instead of enabling `-frtti` and
    505 >    `-fexceptions` directly in your LOCAL_CPPFLAGS definition.
    506 
    507 - - - -
    508 LOCAL_C_INCLUDES
    509 >    An optional list of paths, relative to the NDK *root* directory,
    510 >    which will be appended to the include search path when compiling
    511 >    all sources (C, C++ and Assembly). For example:
    512 
    513               LOCAL_C_INCLUDES := sources/foo
    514 
    515 >    Or even:
    516 
    517               LOCAL_C_INCLUDES := $(LOCAL_PATH)/../foo
    518 
    519 >    These are placed before any corresponding inclusion flag in
    520 >    LOCAL_CFLAGS / LOCAL_CPPFLAGS
    521 >
    522 >    The LOCAL_C_INCLUDES path are also used automatically when
    523 >    launching native debugging with ndk-gdb.
    524 
    525 
    526 - - - -
    527 LOCAL_CFLAGS
    528 >    An optional set of compiler flags that will be passed when building
    529 >    C *and* C++ source files.
    530 >
    531 >    This can be useful to specify additional macro definitions or
    532 >    compile options.
    533 >
    534 >    **IMPORTANT**: Try not to change the optimization/debugging level in
    535 >               your `Android.mk`, this can be handled automatically for
    536 >               you by specifying the appropriate information in
    537 >               your Application.mk, and will let the NDK generate
    538 >               useful data files used during debugging.
    539 >
    540 >    NOTE: In android-ndk-1.5_r1, the corresponding flags only applied
    541 >          to C source files, not C++ ones. This has been corrected to
    542 >          match the full Android build system behaviour. (You can use
    543 >          LOCAL_CPPFLAGS to specify flags for C++ sources only now).
    544 >
    545 >    It is possible to specify additional include paths with
    546 >    LOCAL_CFLAGS += -I<path>, however, it is better to use LOCAL_C_INCLUDES
    547 >    for this, since the paths will then also be used during native
    548 >    debugging with ndk-gdb.
    549 
    550 
    551 - - - -
    552 LOCAL_CXXFLAGS
    553 >    An alias for LOCAL_CPPFLAGS. Note that use of this flag is obsolete
    554 >    as it may disappear in future releases of the NDK.
    555 
    556 - - - -
    557 LOCAL_CPPFLAGS
    558 >    An optional set of compiler flags that will be passed when building
    559 >    C++ source files *only*. They will appear after the LOCAL_CFLAGS
    560 >    on the compiler's command-line.
    561 >
    562 >    NOTE: In android-ndk-1.5_r1, the corresponding flags applied to
    563 >          both C and C++ sources. This has been corrected to match the
    564 >          full Android build system. (You can use LOCAL_CFLAGS to specify
    565 >          flags for both C and C++ sources now).
    566 
    567 - - - -
    568 LOCAL_STATIC_LIBRARIES
    569 >    The list of static libraries modules that the current module depends
    570 >    on.
    571 >
    572 >    If the current module is a shared library or an executable, this will
    573 >    force these libraries to be linked into the resulting binary.
    574 >
    575 >    If the current module is a static library, this simply tells that
    576 >    another other module that depends on the current one will also
    577 >    depend on the listed libraries.
    578 
    579 - - - -
    580 LOCAL_SHARED_LIBRARIES
    581 >    The list of shared libraries *modules* this module depends on at runtime.
    582 >    This is necessary at link time and to embed the corresponding information
    583 >    in the generated file.
    584 >
    585 
    586 - - - -
    587 LOCAL_WHOLE_STATIC_LIBRARIES
    588 >    A variant of LOCAL_STATIC_LIBRARIES used to express that the corresponding
    589 >    library module should be used as "whole archives" to the linker. See the
    590 >    GNU linker's documentation for the `--whole-archive` flag.
    591 >
    592 >    This is generally useful when there are circular dependencies between
    593 >    several static libraries. Note that when used to build a shared library,
    594 >    this will force all object files from your whole static libraries to be
    595 >    added to the final binary. This is not true when generating executables
    596 >    though.
    597 
    598 - - - -
    599 LOCAL_LDLIBS
    600 >    The list of additional linker flags to be used when building your
    601 >    shared library or executable. This is useful to pass the name of
    602 >    specific system libraries with the '`-l`' prefix. For example, the
    603 >    following will tell the linker to generate a module that links to
    604 >    `/system/lib/libz.so` at load time:
    605 
    606             LOCAL_LDLIBS := -lz
    607 
    608 >    See [STABLE-APIS](STABLE-APIS.html) for the list of exposed system libraries you
    609 >    can linked against with this NDK release.
    610 >
    611 >    NOTE: This is ignored for static libraries, and ndk-build will print
    612 >          a warning if you define it in such a module.
    613 
    614 - - - -
    615 LOCAL_LDFLAGS
    616 >    The list of other linker flags to be used when building your shared
    617 >    library or executable. For example, the following will use the `ld.bfd`
    618 >    linker on ARM/X86 GCC 4.6+ where `ld.gold` is the default
    619 
    620             LOCAL_LDFLAGS += -fuse-ld=bfd
    621 
    622 >    NOTE: This is ignored for static libraries, and ndk-build will print
    623 >          a warning if you define it in such a module.
    624 
    625 - - - -
    626 LOCAL_ALLOW_UNDEFINED_SYMBOLS
    627 >    By default, any undefined reference encountered when trying to build
    628 >    a shared library will result in an "undefined symbol" error. This is a
    629 >    great help to catch bugs in your source code.
    630 >
    631 >    However, if for some reason you need to disable this check, set this
    632 >    variable to '`true`'. Note that the corresponding shared library may fail
    633 >    to load at runtime.
    634 >
    635 >    *NOTE*: This is ignored for static libraries, and ndk-build will print
    636 >          a warning if you define it in such a module.
    637 
    638 - - - -
    639 LOCAL_ARM_MODE
    640 >    By default, ARM target binaries will be generated in 'thumb' mode, where
    641 >    each instruction are 16-bit wide. You can define this variable to '`arm`'
    642 >    if you want to force the generation of the module's object files in
    643 >    'arm' (32-bit instructions) mode. E.g.:
    644 
    645             LOCAL_ARM_MODE := arm
    646 
    647 >    Note that you can also instruct the build system to only build specific
    648 >    sources in ARM mode by appending an '`.arm`' suffix to its source file
    649 >    name. For example, with:
    650 
    651             LOCAL_SRC_FILES := foo.c bar.c.arm
    652 
    653 >    Tells the build system to always compile '`bar.c`' in ARM mode, and to
    654 >    build `foo.c` according to the value of LOCAL_ARM_MODE.
    655 >
    656 >    NOTE: Setting APP_OPTIM to '`debug`' in your `Application.mk` will also force
    657 >          the generation of ARM binaries as well. This is due to bugs in the
    658 >          toolchain debugger that don't deal too well with thumb code.
    659 
    660 - - - -
    661 LOCAL_ARM_NEON
    662 >    Defining this variable to '`true`' allows the use of ARM Advanced SIMD
    663 >    (a.k.a. NEON) GCC intrinsics in your C and C++ sources, as well as
    664 >    NEON instructions in Assembly files.
    665 >
    666 >    You should only define it when targeting the '`armeabi-v7a`' ABI that
    667 >    corresponds to the ARMv7 instruction set. Note that not all ARMv7
    668 >    based CPUs support the NEON instruction set extensions and that you
    669 >    should perform runtime detection to be able to use this code at runtime
    670 >    safely. To learn more about this, please read the documentation at
    671 >    [CPU-ARM-NEON](CPU-ARM-NEON.html) and [CPU-FEATURES](CPU-FEATURES.html).
    672 >
    673 >    Alternatively, you can also specify that only specific source files
    674 >    may be compiled with NEON support by using the '`.neon`' suffix, as
    675 >    in:
    676 
    677             LOCAL_SRC_FILES = foo.c.neon bar.c zoo.c.arm.neon
    678 
    679 >    In this example, '`foo.c`' will be compiled in thumb+neon mode,
    680 >    '`bar.c`' will be compiled in 'thumb' mode, and '`zoo.c`' will be
    681 >    compiled in 'arm+neon' mode.
    682 >
    683 >    Note that the '`.neon`' suffix must appear after the '`.arm`' suffix
    684 >    if you use both (i.e. `foo.c.arm.neon` works, but not `foo.c.neon.arm` !)
    685 
    686 - - - -
    687 LOCAL_DISABLE_NO_EXECUTE
    688 >    Android NDK r4 added support for the "NX bit" security feature.
    689 >    It is enabled by default, but you can disable it if you *really*
    690 >    need to by setting this variable to 'true'.
    691 >
    692 >    NOTE: This feature does not modify the ABI and is only enabled on
    693 >          kernels targeting ARMv6+ CPU devices. Machine code generated
    694 >          with this feature enabled will run unmodified on devices
    695 >          running earlier CPU architectures.
    696 >
    697 >    For more information, see:
    698 >
    699 >    * [Wikipedia: NX bit](http://en.wikipedia.org/wiki/NX_bit)
    700 >    * [The GNU stack kickstart](http://www.gentoo.org/proj/en/hardened/gnu-stack.xml)
    701 
    702 - - - -
    703 LOCAL_DISABLE_RELRO
    704 >    By default, NDK compiled code is built with read-only relocations
    705 >    and GOT protection.  This instructs the runtime linker to mark
    706 >    certain regions of memory as being read-only after relocation,
    707 >    making certain security exploits (such as GOT overwrites) harder
    708 >    to perform.
    709 >
    710 >    It is enabled by default, but you can disable it if you *really*
    711 >    need to by setting this variable to '`true`'.
    712 >
    713 >    NOTE: These protections are only effective on newer Android devices
    714 >          ("Jelly Bean" and beyond). The code will still run on older
    715 >          versions (albeit without memory protections).
    716 >
    717 >    For more information, see:
    718 >
    719 >    * [RELRO: RELocation Read-Only](http://isisblogs.poly.edu/2011/06/01/relro-relocation-read-only/)
    720 >    * [Security enhancements in RedHat Enterprise Linux (section 6)](http://www.akkadia.org/drepper/nonselsec.pdf)
    721 
    722 - - - -
    723 LOCAL_DISABLE_FORMAT_STRING_CHECKS
    724 >    By default, NDK compiled code is compiled with format string
    725 >    protection. This forces a compiler error if a non-constant format
    726 >    string is used in a printf style function.
    727 >
    728 >    It is enabled by default, but you can disable it if you *really*
    729 >    need to by setting this variable to '`true`'.
    730 
    731 - - - -
    732 LOCAL_EXPORT_CFLAGS
    733 >    Define this variable to record a set of C/C++ compiler flags that will
    734 >    be added to the LOCAL_CFLAGS definition of any other module that uses
    735 >    this one with LOCAL_STATIC_LIBRARIES or LOCAL_SHARED_LIBRARIES.
    736 >
    737 >    For example, consider the module '`foo`' with the following definition:
    738 
    739               include $(CLEAR_VARS)
    740               LOCAL_MODULE := foo
    741               LOCAL_SRC_FILES := foo/foo.c
    742               LOCAL_EXPORT_CFLAGS := -DFOO=1
    743               include $(BUILD_STATIC_LIBRARY)
    744 
    745 >    And another module, named '`bar`' that depends on it as:
    746 
    747               include $(CLEAR_VARS)
    748               LOCAL_MODULE := bar
    749               LOCAL_SRC_FILES := bar.c
    750               LOCAL_CFLAGS := -DBAR=2
    751               LOCAL_STATIC_LIBRARIES := foo
    752               include $(BUILD_SHARED_LIBRARY)
    753 
    754 >    Then, the flags '`-DFOO=1` `-DBAR=2`' will be passed to the compiler when
    755 >    building `bar.c`.
    756 >
    757 >    Exported flags are prepended to your module's LOCAL_CFLAGS so you can
    758 >    easily override them. They are also transitive: if '`zoo`' depends on
    759 >    '`bar`' which depends on '`foo`', then '`zoo`' will also inherit all flags
    760 >    exported by '`foo`'.
    761 >
    762 >    Finally, exported flags are *not* used when building the module that
    763 >    exports them. In the above example, `-DFOO=1` would not be passed to the
    764 >    compiler when building `foo/foo.c`.
    765 
    766 - - - -
    767 LOCAL_EXPORT_CPPFLAGS
    768 >    Same as LOCAL_EXPORT_CFLAGS, but for C++ flags only.
    769 
    770 - - - -
    771 LOCAL_EXPORT_C_INCLUDES
    772 >    Same as LOCAL_EXPORT_CFLAGS, but for C include paths.
    773 >    This can be useful if 'bar.c' wants to include headers
    774 >    that are provided by module 'foo'.
    775 
    776 - - - -
    777 LOCAL_EXPORT_LDLIBS
    778 >    Same as LOCAL_EXPORT_CFLAGS, but for linker flags. Note that the
    779 >    imported linker flags will be appended to your module's LOCAL_LDLIBS
    780 >    though, due to the way Unix linkers work.
    781 >
    782 >    This is typically useful when module '`foo`' is a static library and has
    783 >    code that depends on a system library. LOCAL_EXPORT_LDLIBS can then be
    784 >    used to export the dependency. For example:
    785 
    786               include $(CLEAR_VARS)
    787               LOCAL_MODULE := foo
    788               LOCAL_SRC_FILES := foo/foo.c
    789               LOCAL_EXPORT_LDLIBS := -llog
    790               include $(BUILD_STATIC_LIBRARY)
    791 
    792               include $(CLEAR_VARS)
    793               LOCAL_MODULE := bar
    794               LOCAL_SRC_FILES := bar.c
    795               LOCAL_STATIC_LIBRARIES := foo
    796               include $(BUILD_SHARED_LIBRARY)
    797 
    798 >    There, `libbar.so` will be built with a `-llog` at the end of the linker
    799 >    command to indicate that it depends on the system logging library,
    800 >    because it depends on '`foo`'.
    801 
    802 - - - -
    803 LOCAL_SHORT_COMMANDS
    804 >    Set this variable to '`true`' when your module has a very high number of
    805 >    sources and/or dependent static or shared libraries. This forces the
    806 >    build system to use an intermediate list file, and use it with the
    807 >    library archiver or static linker with the `@$(listfile)` syntax.
    808 
    809 >    This can be useful on Windows, where the command-line only accepts
    810 >    a maximum of 8191 characters, which can be too small for complex
    811 >    projects.
    812 
    813 >    This also impacts the compilation of individual source files, placing
    814 >    nearly all compiler flags inside list files too.
    815 
    816 >    Note that any other value than '`true`' will revert to the default
    817 >    behaviour. You can also define APP_SHORT_COMMANDS in your
    818 >    Application.mk to force this behaviour for all modules in your
    819 >    project.
    820 
    821 >    *NOTE*: We do not recommend enabling this feature by default, since it
    822 >          makes the build slower.
    823 
    824 - - - -
    825 LOCAL_THIN_ARCHIVE
    826 >    Set this variable to '`true`' when building static libraries. This will
    827 >    generate a 'thin archive', i.e. a library file (e.g. `libfoo.a`) which
    828 >    doesn't contain object files, but simply file paths to the actual
    829 >    objects that it should normally contain.
    830 
    831 >    This is useful to reduce the size of your build output. The drawback
    832 >    is that such libraries _cannot_ be moved to a different location
    833 >    (all paths inside them are relative).
    834 
    835 >    Valid values are '`true`', '`false`' or empty. A default value can be
    836 >    set in your Application.mk through APP_THIN_ARCHIVE.
    837 
    838 >    *NOTE*: This is ignored for non-static library modules, or prebuilt
    839 >    static library ones.
    840 
    841 - - - -
    842 LOCAL_FILTER_ASM
    843 >    Define this variable to a shell command that will be used to filter
    844 >    the assembly files from, or generated from, your LOCAL_SRC_FILES.
    845 >
    846 >    When it is defined, the following happens:
    847 >
    848 >      - Any C or C++ source file is generated into a temporary assembly
    849 >        file (instead of being compiled into an object file).
    850 >
    851 >      - Any temporary assembly file, and any assembly file listed in
    852 >        LOCAL_SRC_FILES is sent through the LOCAL_FILTER_ASM command
    853 >        to generate _another_ temporary assembly file.
    854 >
    855 >      - These filtered assembly files are compiled into object file.
    856 >
    857 >    In other words, If you have:
    858 
    859               LOCAL_SRC_FILES  := foo.c bar.S
    860               LOCAL_FILTER_ASM := myasmfilter
    861 
    862             foo.c --1--> $OBJS_DIR/foo.S.original --2--> $OBJS_DIR/foo.S --3--> $OBJS_DIR/foo.o
    863             bar.S                                 --2--> $OBJS_DIR/bar.S --3--> $OBJS_DIR/bar.o
    864 
    865 >    Were "1" corresponds to the compiler, "2" to the filter, and "3" to the
    866 >    assembler. The filter must be a standalone shell command that takes the
    867 >    name of the input file as its first argument, and the name of the output
    868 >    file as the second one, as in:
    869 
    870               myasmfilter $OBJS_DIR/foo.S.original $OBJS_DIR/foo.S
    871               myasmfilter bar.S $OBJS_DIR/bar.S
    872