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        x86_64
    256             For x86-64
    257 
    258        mips
    259             For mips32 (r1)
    260 
    261 >    NOTE: Up to Android NDK 1.6_r1, this variable was simply defined
    262 >          as '`arm`'. However, the value has been redefined to better
    263 >          match what is used internally by the Android platform.
    264 
    265 >    For more details about architecture ABIs and corresponding
    266 >    compatibility issues, please read [CPU ARCH ABIS](CPU-ARCH-ABIS.html)
    267 
    268 >    Other target ABIs will be introduced in future releases of the NDK
    269 >    and will have a different name. Note that all ARM-based ABIs will
    270 >    have 'TARGET_ARCH' defined to '`arm`', but may have different
    271 >    'TARGET_ARCH_ABI'
    272 
    273 - - - - - - - - - - -
    274 TARGET_ABI
    275 >    The concatenation of target platform and ABI, it really is defined
    276 >    as `$(TARGET_PLATFORM)-$(TARGET_ARCH_ABI)` and is useful when you want
    277 >    to test against a specific target system image for a real device.
    278 
    279 >    By default, this will be '`android-3-armeabi`'
    280 
    281 >    (Up to Android NDK 1.6_r1, this used to be '`android-3-arm`' by default)
    282 
    283 NDK-provided function macros:
    284 -----------------------------
    285 
    286 The following are GNU Make 'function' macros, and must be evaluated
    287 by using '$(call <function>)'. They return textual information.
    288 
    289 - - - -
    290 my-dir
    291 >    Returns the path of the last included Makefile, which typically is
    292 >    the current `Android.mk`'s directory. This is useful to define
    293 >    LOCAL_PATH at the start of your `Android.mk` as with:
    294 
    295               LOCAL_PATH := $(call my-dir)
    296 
    297 >    IMPORTANT NOTE: Due to the way GNU Make works, this really returns
    298 >    the path of the *last* *included* *Makefile* during the parsing of
    299 >    build scripts. Do not call `my-dir` after including another file.
    300 
    301 >    For example, consider the following example:
    302 
    303               LOCAL_PATH := $(call my-dir)
    304 
    305               ... declare one module
    306 
    307               include $(LOCAL_PATH)/foo/`Android.mk`
    308 
    309               LOCAL_PATH := $(call my-dir)
    310 
    311               ... declare another module
    312 
    313 >    The problem here is that the second call to `my-dir` will define
    314 >    LOCAL_PATH to `$PATH/foo` instead of `$PATH`, due to the include that
    315 >    was performed before that.
    316 
    317 >    For this reason, it's better to put additional includes after
    318 >    everything else in an `Android.mk`, as in:
    319 
    320               LOCAL_PATH := $(call my-dir)
    321 
    322               ... declare one module
    323 
    324               LOCAL_PATH := $(call my-dir)
    325 
    326               ... declare another module
    327 
    328               # extra includes at the end of the `Android.mk`
    329               include $(LOCAL_PATH)/foo/`Android.mk`
    330 
    331 >    If this is not convenient, save the value of the first `my-dir` call
    332 >    into another variable, for example:
    333 
    334               MY_LOCAL_PATH := $(call my-dir)
    335 
    336               LOCAL_PATH := $(MY_LOCAL_PATH)
    337 
    338               ... declare one module
    339 
    340               include $(LOCAL_PATH)/foo/`Android.mk`
    341 
    342               LOCAL_PATH := $(MY_LOCAL_PATH)
    343 
    344               ... declare another module
    345 
    346 
    347 - - - -
    348 all-subdir-makefiles
    349 >    Returns a list of `Android.mk` located in all sub-directories of
    350 >    the current 'my-dir' path. For example, consider the following
    351 >    hierarchy:
    352 
    353               sources/foo/Android.mk
    354               sources/foo/lib1/Android.mk
    355               sources/foo/lib2/Android.mk
    356 
    357 >    If sources/foo/`Android.mk` contains the single line:
    358 
    359               include $(call all-subdir-makefiles)
    360 
    361 >    Then it will include automatically sources/foo/lib1/`Android.mk` and
    362 >    sources/foo/lib2/`Android.mk`
    363 
    364 >    This function can be used to provide deep-nested source directory
    365 >    hierarchies to the build system. Note that by default, the NDK
    366 >    will only look for files in sources/*/`Android.mk`
    367 
    368 - - - -
    369 this-makefile
    370 >    Returns the path of the current Makefile (i.e. where the function
    371 >    is called).
    372 
    373 - - - -
    374 parent-makefile
    375 >    Returns the path of the parent Makefile in the inclusion tree,
    376 >    i.e. the path of the Makefile that included the current one.
    377 
    378 - - - -
    379 grand-parent-makefile
    380 >    Guess what...
    381 
    382 - - - -
    383 import-module
    384 >    A function that allows you to find and include the `Android.mk`
    385 >    of another module by name. A typical example is:
    386 
    387             $(call import-module,<name>)
    388 
    389 >    And this will look for the module tagged <name> in the list of
    390 >    directories referenced by your NDK_MODULE_PATH environment
    391 >    variable, and include its `Android.mk` automatically for you.
    392 >
    393 >    Read [IMPORT-MODULE](IMPORT-MODULE.html) for more details.
    394 - - - -
    395 
    396 
    397 Module-description variables:
    398 -----------------------------
    399 
    400 The following variables are used to describe your module to the build
    401 system. You should define some of them between an '`include $(CLEAR_VARS)`'
    402 and an '`include $(BUILD_XXXXX)`'. As written previously, $(CLEAR_VARS) is
    403 a script that will undefine/clear all of these variables, unless explicitly
    404 noted in their description.
    405 
    406 - - - -
    407 LOCAL_PATH
    408 >    This variable is used to give the path of the current file.
    409 >    You MUST define it at the start of your `Android.mk`, which can
    410 >    be done with:
    411 
    412             LOCAL_PATH := $(call my-dir)
    413 
    414 >    This variable is *not* cleared by $(CLEAR_VARS) so only one
    415 >    definition per `Android.mk` is needed (in case you define several
    416 >    modules in a single file).
    417 
    418 - - - -
    419 LOCAL_MODULE
    420 >    This is the name of your module. It must be unique among all
    421 >    module names, and shall not contain any space. You MUST define
    422 >    it before including any $(BUILD_XXXX) script.
    423 >
    424 >    By default, the module name determines the name of generated files,
    425 >    e.g. lib<foo>.so for a shared library module named <foo>. However
    426 >    you should only refer to other modules with their 'normal'
    427 >    name (e.g. <foo>) in your NDK build files (either `Android.mk`
    428 >    or Application.mk)
    429 >
    430 >    You can override this default with LOCAL_MODULE_FILENAME (see below)
    431 
    432 - - - -
    433 LOCAL_MODULE_FILENAME
    434 >    This variable is optional, and allows you to redefine the name of
    435 >    generated files. By default, module <foo> will always generate a
    436 >    static library named lib<foo>.a or a shared library named lib<foo>.so,
    437 >    which are standard Unix conventions.
    438 >
    439 >    You can override this by defining LOCAL_MODULE_FILENAME, For example:
    440 
    441               LOCAL_MODULE := foo-version-1
    442               LOCAL_MODULE_FILENAME := libfoo
    443 
    444 >    *NOTE(: You should not put a path or file extension in your
    445 >    LOCAL_MODULE_FILENAME, these will be handled automatically by the
    446 >    build system.
    447 
    448 - - - -
    449 LOCAL_SRC_FILES
    450 >    This is a list of source files that will be built for your module.
    451 >    Only list the files that will be passed to a compiler, since the
    452 >    build system automatically computes dependencies for you.
    453 >
    454 >    Note that source files names are relative to LOCAL_PATH and
    455 >    you can use path components, e.g.:
    456 
    457             LOCAL_SRC_FILES := foo.c \
    458                                toto/bar.c
    459 
    460 >    Absolute file paths are also supported:
    461 
    462             LOCAL_SRC_FILES := /home/user/mysources/foo.c
    463 
    464 >    or on Windows:
    465 
    466             LOCAL_SRC_FILES := c:/Users/user/sources/foo.c
    467 
    468 >    Avoiding absolute file paths is recommended, this makes your
    469 >    `Android.mk` easy to reuse on a different machine / system.
    470 >
    471 >    NOTE: Always use Unix-style forward slashes (/) in build files.
    472 >          Windows-style back-slashes will not be handled properly.
    473 
    474 - - - -
    475 LOCAL_CPP_EXTENSION
    476 >    This is an optional variable that can be defined to indicate
    477 >    the file extension(s) of C++ source files. They must begin with a dot.
    478 >    The default is '.cpp' but you can change it. For example:
    479 
    480               LOCAL_CPP_EXTENSION := .cxx
    481 
    482 >    Since NDK r7, you can list several extensions in this variable, as in:
    483 
    484               LOCAL_CPP_EXTENSION := .cxx .cpp .cc
    485 
    486 - - - -
    487 LOCAL_CPP_FEATURES
    488 >    This is an optional variable that can be defined to indicate
    489 >    that your code relies on specific C++ features. To indicate that
    490 >    your code uses RTTI (RunTime Type Information), use the following:
    491 
    492               LOCAL_CPP_FEATURES := rtti
    493 
    494 >    To indicate that your code uses C++ exceptions, use:
    495 
    496               LOCAL_CPP_FEATURES := exceptions
    497 
    498 >    You can also use both of them with (order is not important):
    499 
    500               LOCAL_CPP_FEATURES := rtti features
    501 
    502 >    The effect of this variable is to enable the right compiler/linker
    503 >    flags when building your modules from sources. For prebuilt binaries,
    504 >    this also helps declare which features the binary relies on to ensure
    505 >    the final link works correctly.
    506 >
    507 >    It is recommended to use this variable instead of enabling `-frtti` and
    508 >    `-fexceptions` directly in your LOCAL_CPPFLAGS definition.
    509 
    510 - - - -
    511 LOCAL_C_INCLUDES
    512 >    An optional list of paths, relative to the NDK *root* directory,
    513 >    which will be appended to the include search path when compiling
    514 >    all sources (C, C++ and Assembly). For example:
    515 
    516               LOCAL_C_INCLUDES := sources/foo
    517 
    518 >    Or even:
    519 
    520               LOCAL_C_INCLUDES := $(LOCAL_PATH)/../foo
    521 
    522 >    These are placed before any corresponding inclusion flag in
    523 >    LOCAL_CFLAGS / LOCAL_CPPFLAGS
    524 >
    525 >    The LOCAL_C_INCLUDES path are also used automatically when
    526 >    launching native debugging with ndk-gdb.
    527 
    528 
    529 - - - -
    530 LOCAL_CFLAGS
    531 >    An optional set of compiler flags that will be passed when building
    532 >    C *and* C++ source files.
    533 >
    534 >    This can be useful to specify additional macro definitions or
    535 >    compile options.
    536 >
    537 >    **IMPORTANT**: Try not to change the optimization/debugging level in
    538 >               your `Android.mk`, this can be handled automatically for
    539 >               you by specifying the appropriate information in
    540 >               your Application.mk, and will let the NDK generate
    541 >               useful data files used during debugging.
    542 >
    543 >    NOTE: In android-ndk-1.5_r1, the corresponding flags only applied
    544 >          to C source files, not C++ ones. This has been corrected to
    545 >          match the full Android build system behaviour. (You can use
    546 >          LOCAL_CPPFLAGS to specify flags for C++ sources only now).
    547 >
    548 >    It is possible to specify additional include paths with
    549 >    LOCAL_CFLAGS += -I<path>, however, it is better to use LOCAL_C_INCLUDES
    550 >    for this, since the paths will then also be used during native
    551 >    debugging with ndk-gdb.
    552 
    553 
    554 - - - -
    555 LOCAL_CXXFLAGS
    556 >    An alias for LOCAL_CPPFLAGS. Note that use of this flag is obsolete
    557 >    as it may disappear in future releases of the NDK.
    558 
    559 - - - -
    560 LOCAL_CPPFLAGS
    561 >    An optional set of compiler flags that will be passed when building
    562 >    C++ source files *only*. They will appear after the LOCAL_CFLAGS
    563 >    on the compiler's command-line.
    564 >
    565 >    NOTE: In android-ndk-1.5_r1, the corresponding flags applied to
    566 >          both C and C++ sources. This has been corrected to match the
    567 >          full Android build system. (You can use LOCAL_CFLAGS to specify
    568 >          flags for both C and C++ sources now).
    569 
    570 - - - -
    571 LOCAL_STATIC_LIBRARIES
    572 >    The list of static libraries modules that the current module depends
    573 >    on.
    574 >
    575 >    If the current module is a shared library or an executable, this will
    576 >    force these libraries to be linked into the resulting binary.
    577 >
    578 >    If the current module is a static library, this simply tells that
    579 >    another other module that depends on the current one will also
    580 >    depend on the listed libraries.
    581 
    582 - - - -
    583 LOCAL_SHARED_LIBRARIES
    584 >    The list of shared libraries *modules* this module depends on at runtime.
    585 >    This is necessary at link time and to embed the corresponding information
    586 >    in the generated file.
    587 >
    588 
    589 - - - -
    590 LOCAL_WHOLE_STATIC_LIBRARIES
    591 >    A variant of LOCAL_STATIC_LIBRARIES used to express that the corresponding
    592 >    library module should be used as "whole archives" to the linker. See the
    593 >    GNU linker's documentation for the `--whole-archive` flag.
    594 >
    595 >    This is generally useful when there are circular dependencies between
    596 >    several static libraries. Note that when used to build a shared library,
    597 >    this will force all object files from your whole static libraries to be
    598 >    added to the final binary. This is not true when generating executables
    599 >    though.
    600 
    601 - - - -
    602 LOCAL_LDLIBS
    603 >    The list of additional linker flags to be used when building your
    604 >    shared library or executable. This is useful to pass the name of
    605 >    specific system libraries with the '`-l`' prefix. For example, the
    606 >    following will tell the linker to generate a module that links to
    607 >    `/system/lib/libz.so` at load time:
    608 
    609             LOCAL_LDLIBS := -lz
    610 
    611 >    See [STABLE-APIS](STABLE-APIS.html) for the list of exposed system libraries you
    612 >    can linked against with this NDK release.
    613 >
    614 >    NOTE: This is ignored for static libraries, and ndk-build will print
    615 >          a warning if you define it in such a module.
    616 
    617 - - - -
    618 LOCAL_LDFLAGS
    619 >    The list of other linker flags to be used when building your shared
    620 >    library or executable. For example, the following will use the `ld.bfd`
    621 >    linker on ARM/X86 GCC 4.6+ where `ld.gold` is the default
    622 
    623             LOCAL_LDFLAGS += -fuse-ld=bfd
    624 
    625 >    NOTE: This is ignored for static libraries, and ndk-build will print
    626 >          a warning if you define it in such a module.
    627 
    628 - - - -
    629 LOCAL_ALLOW_UNDEFINED_SYMBOLS
    630 >    By default, any undefined reference encountered when trying to build
    631 >    a shared library will result in an "undefined symbol" error. This is a
    632 >    great help to catch bugs in your source code.
    633 >
    634 >    However, if for some reason you need to disable this check, set this
    635 >    variable to '`true`'. Note that the corresponding shared library may fail
    636 >    to load at runtime.
    637 >
    638 >    *NOTE*: This is ignored for static libraries, and ndk-build will print
    639 >          a warning if you define it in such a module.
    640 
    641 - - - -
    642 LOCAL_ARM_MODE
    643 >    By default, ARM target binaries will be generated in 'thumb' mode, where
    644 >    each instruction are 16-bit wide. You can define this variable to '`arm`'
    645 >    if you want to force the generation of the module's object files in
    646 >    'arm' (32-bit instructions) mode. E.g.:
    647 
    648             LOCAL_ARM_MODE := arm
    649 
    650 >    Note that you can also instruct the build system to only build specific
    651 >    sources in ARM mode by appending an '`.arm`' suffix to its source file
    652 >    name. For example, with:
    653 
    654             LOCAL_SRC_FILES := foo.c bar.c.arm
    655 
    656 >    Tells the build system to always compile '`bar.c`' in ARM mode, and to
    657 >    build `foo.c` according to the value of LOCAL_ARM_MODE.
    658 >
    659 >    NOTE: Setting APP_OPTIM to '`debug`' in your `Application.mk` will also force
    660 >          the generation of ARM binaries as well. This is due to bugs in the
    661 >          toolchain debugger that don't deal too well with thumb code.
    662 
    663 - - - -
    664 LOCAL_ARM_NEON
    665 >    Defining this variable to '`true`' allows the use of ARM Advanced SIMD
    666 >    (a.k.a. NEON) GCC intrinsics in your C and C++ sources, as well as
    667 >    NEON instructions in Assembly files.
    668 >
    669 >    You should only define it when targeting the '`armeabi-v7a`' ABI that
    670 >    corresponds to the ARMv7 instruction set. Note that not all ARMv7
    671 >    based CPUs support the NEON instruction set extensions and that you
    672 >    should perform runtime detection to be able to use this code at runtime
    673 >    safely. To learn more about this, please read the documentation at
    674 >    [CPU-ARM-NEON](CPU-ARM-NEON.html) and [CPU-FEATURES](CPU-FEATURES.html).
    675 >
    676 >    Alternatively, you can also specify that only specific source files
    677 >    may be compiled with NEON support by using the '`.neon`' suffix, as
    678 >    in:
    679 
    680             LOCAL_SRC_FILES = foo.c.neon bar.c zoo.c.arm.neon
    681 
    682 >    In this example, '`foo.c`' will be compiled in thumb+neon mode,
    683 >    '`bar.c`' will be compiled in 'thumb' mode, and '`zoo.c`' will be
    684 >    compiled in 'arm+neon' mode.
    685 >
    686 >    Note that the '`.neon`' suffix must appear after the '`.arm`' suffix
    687 >    if you use both (i.e. `foo.c.arm.neon` works, but not `foo.c.neon.arm` !)
    688 
    689 - - - -
    690 LOCAL_DISABLE_NO_EXECUTE
    691 >    Android NDK r4 added support for the "NX bit" security feature.
    692 >    It is enabled by default, but you can disable it if you *really*
    693 >    need to by setting this variable to 'true'.
    694 >
    695 >    NOTE: This feature does not modify the ABI and is only enabled on
    696 >          kernels targeting ARMv6+ CPU devices. Machine code generated
    697 >          with this feature enabled will run unmodified on devices
    698 >          running earlier CPU architectures.
    699 >
    700 >    For more information, see:
    701 >
    702 >    * [Wikipedia: NX bit](http://en.wikipedia.org/wiki/NX_bit)
    703 >    * [The GNU stack kickstart](http://www.gentoo.org/proj/en/hardened/gnu-stack.xml)
    704 
    705 - - - -
    706 LOCAL_DISABLE_RELRO
    707 >    By default, NDK compiled code is built with read-only relocations
    708 >    and GOT protection.  This instructs the runtime linker to mark
    709 >    certain regions of memory as being read-only after relocation,
    710 >    making certain security exploits (such as GOT overwrites) harder
    711 >    to perform.
    712 >
    713 >    It is enabled by default, but you can disable it if you *really*
    714 >    need to by setting this variable to '`true`'.
    715 >
    716 >    NOTE: These protections are only effective on newer Android devices
    717 >          ("Jelly Bean" and beyond). The code will still run on older
    718 >          versions (albeit without memory protections).
    719 >
    720 >    For more information, see:
    721 >
    722 >    * [RELRO: RELocation Read-Only](http://isisblogs.poly.edu/2011/06/01/relro-relocation-read-only/)
    723 >    * [Security enhancements in RedHat Enterprise Linux (section 6)](http://www.akkadia.org/drepper/nonselsec.pdf)
    724 
    725 - - - -
    726 LOCAL_DISABLE_FORMAT_STRING_CHECKS
    727 >    By default, NDK compiled code is compiled with format string
    728 >    protection. This forces a compiler error if a non-constant format
    729 >    string is used in a printf style function.
    730 >
    731 >    It is enabled by default, but you can disable it if you *really*
    732 >    need to by setting this variable to '`true`'.
    733 
    734 - - - -
    735 LOCAL_EXPORT_CFLAGS
    736 >    Define this variable to record a set of C/C++ compiler flags that will
    737 >    be added to the LOCAL_CFLAGS definition of any other module that uses
    738 >    this one with LOCAL_STATIC_LIBRARIES or LOCAL_SHARED_LIBRARIES.
    739 >
    740 >    For example, consider the module '`foo`' with the following definition:
    741 
    742               include $(CLEAR_VARS)
    743               LOCAL_MODULE := foo
    744               LOCAL_SRC_FILES := foo/foo.c
    745               LOCAL_EXPORT_CFLAGS := -DFOO=1
    746               include $(BUILD_STATIC_LIBRARY)
    747 
    748 >    And another module, named '`bar`' that depends on it as:
    749 
    750               include $(CLEAR_VARS)
    751               LOCAL_MODULE := bar
    752               LOCAL_SRC_FILES := bar.c
    753               LOCAL_CFLAGS := -DBAR=2
    754               LOCAL_STATIC_LIBRARIES := foo
    755               include $(BUILD_SHARED_LIBRARY)
    756 
    757 >    Then, the flags '`-DFOO=1` `-DBAR=2`' will be passed to the compiler when
    758 >    building `bar.c`.
    759 >
    760 >    Exported flags are prepended to your module's LOCAL_CFLAGS so you can
    761 >    easily override them. They are also transitive: if '`zoo`' depends on
    762 >    '`bar`' which depends on '`foo`', then '`zoo`' will also inherit all flags
    763 >    exported by '`foo`'.
    764 >
    765 >    Finally, exported flags are *not* used when building the module that
    766 >    exports them. In the above example, `-DFOO=1` would not be passed to the
    767 >    compiler when building `foo/foo.c`.
    768 
    769 - - - -
    770 LOCAL_EXPORT_CPPFLAGS
    771 >    Same as LOCAL_EXPORT_CFLAGS, but for C++ flags only.
    772 
    773 - - - -
    774 LOCAL_EXPORT_C_INCLUDES
    775 >    Same as LOCAL_EXPORT_CFLAGS, but for C include paths.
    776 >    This can be useful if 'bar.c' wants to include headers
    777 >    that are provided by module 'foo'.
    778 
    779 - - - -
    780 LOCAL_EXPORT_LDFLAGS
    781 >    Same as LOCAL_EXPORT_CFLAGS, but for linker flags.
    782 
    783 - - - -
    784 LOCAL_EXPORT_LDLIBS
    785 >    Same as LOCAL_EXPORT_CFLAGS, but for passing the name of specific
    786 >    system libraries with the '`-l`' prefix. Note that the
    787 >    imported linker flags will be appended to your module's LOCAL_LDLIBS
    788 >    though, due to the way Unix linkers work.
    789 >
    790 >    This is typically useful when module '`foo`' is a static library and has
    791 >    code that depends on a system library. LOCAL_EXPORT_LDLIBS can then be
    792 >    used to export the dependency. For example:
    793 
    794               include $(CLEAR_VARS)
    795               LOCAL_MODULE := foo
    796               LOCAL_SRC_FILES := foo/foo.c
    797               LOCAL_EXPORT_LDLIBS := -llog
    798               include $(BUILD_STATIC_LIBRARY)
    799 
    800               include $(CLEAR_VARS)
    801               LOCAL_MODULE := bar
    802               LOCAL_SRC_FILES := bar.c
    803               LOCAL_STATIC_LIBRARIES := foo
    804               include $(BUILD_SHARED_LIBRARY)
    805 
    806 >    There, `libbar.so` will be built with a `-llog` at the end of the linker
    807 >    command to indicate that it depends on the system logging library,
    808 >    because it depends on '`foo`'.
    809 
    810 - - - -
    811 LOCAL_SHORT_COMMANDS
    812 >    Set this variable to '`true`' when your module has a very high number of
    813 >    sources and/or dependent static or shared libraries. This forces the
    814 >    build system to use an intermediate list file, and use it with the
    815 >    library archiver or static linker with the `@$(listfile)` syntax.
    816 
    817 >    This can be useful on Windows, where the command-line only accepts
    818 >    a maximum of 8191 characters, which can be too small for complex
    819 >    projects.
    820 
    821 >    This also impacts the compilation of individual source files, placing
    822 >    nearly all compiler flags inside list files too.
    823 
    824 >    Note that any other value than '`true`' will revert to the default
    825 >    behaviour. You can also define APP_SHORT_COMMANDS in your
    826 >    Application.mk to force this behaviour for all modules in your
    827 >    project.
    828 
    829 >    *NOTE*: We do not recommend enabling this feature by default, since it
    830 >          makes the build slower.
    831 
    832 - - - -
    833 LOCAL_THIN_ARCHIVE
    834 >    Set this variable to '`true`' when building static libraries. This will
    835 >    generate a 'thin archive', i.e. a library file (e.g. `libfoo.a`) which
    836 >    doesn't contain object files, but simply file paths to the actual
    837 >    objects that it should normally contain.
    838 
    839 >    This is useful to reduce the size of your build output. The drawback
    840 >    is that such libraries _cannot_ be moved to a different location
    841 >    (all paths inside them are relative).
    842 
    843 >    Valid values are '`true`', '`false`' or empty. A default value can be
    844 >    set in your Application.mk through APP_THIN_ARCHIVE.
    845 
    846 >    *NOTE*: This is ignored for non-static library modules, or prebuilt
    847 >    static library ones.
    848 
    849 - - - -
    850 LOCAL_FILTER_ASM
    851 >    Define this variable to a shell command that will be used to filter
    852 >    the assembly files from, or generated from, your LOCAL_SRC_FILES.
    853 >
    854 >    When it is defined, the following happens:
    855 >
    856 >      - Any C or C++ source file is generated into a temporary assembly
    857 >        file (instead of being compiled into an object file).
    858 >
    859 >      - Any temporary assembly file, and any assembly file listed in
    860 >        LOCAL_SRC_FILES is sent through the LOCAL_FILTER_ASM command
    861 >        to generate _another_ temporary assembly file.
    862 >
    863 >      - These filtered assembly files are compiled into object file.
    864 >
    865 >    In other words, If you have:
    866 
    867               LOCAL_SRC_FILES  := foo.c bar.S
    868               LOCAL_FILTER_ASM := myasmfilter
    869 
    870             foo.c --1--> $OBJS_DIR/foo.S.original --2--> $OBJS_DIR/foo.S --3--> $OBJS_DIR/foo.o
    871             bar.S                                 --2--> $OBJS_DIR/bar.S --3--> $OBJS_DIR/bar.o
    872 
    873 >    Were "1" corresponds to the compiler, "2" to the filter, and "3" to the
    874 >    assembler. The filter must be a standalone shell command that takes the
    875 >    name of the input file as its first argument, and the name of the output
    876 >    file as the second one, as in:
    877 
    878               myasmfilter $OBJS_DIR/foo.S.original $OBJS_DIR/foo.S
    879               myasmfilter bar.S $OBJS_DIR/bar.S
    880