Android.mk 语法说明,(陆续添加)

别人翻译的NDK doc  http://www.cnblogs.com/qq78292959/archive/2011/11/02/2232962.html 感觉是非人工翻译的,但是可以看看。

关于prebuilt library 的文章http://www.cnblogs.com/liulipeng/archive/2013/03/29/2988543.html 写得很好


LOCAL_MODULE    := xxx

这样会指定生成对应的.so库,并自动命名为libxxx.so


LOCAL_SRC_FILES := xxx.c

生成module使用到的源文件,用空格做分割如LOCAL_SRC_FILES := aaa/xxx.c aaa/xxc.c

则使用了Android.mk文件同目录下的aaa目录下的xxx.c文件和aaa目录下的xxc.c文件


LOCAL_LDLIBS += -llog

The list of additional linker flags to be used when building your shared library or executable. (不知道linker flags 是神马意思,大概就是告诉编译器联接的时候除了自动连接外还要额外连接的东西吧)

需要调用系统提供的库的时候使用,如上,-l带表link的意思,表示连接liblog.so库,使用时,还需要在LOCAL_SRC_FILES 的文件内正确的引入头文件如log的头文件#include <android/log.h>,系统提供的api头文件在 $NDK/platforms/android-/arch-arm/usr/include 下。连接多个库如LOCAL_LDLIBS := -llog -lz,用空格隔开

直接连接 .a的静态库,如LOCAL_LDLIBS += x264/libx264.a


LOCAL_CFLAGS += xxx

An optional set of compiler flags that will be passed when building C and C++ source files.

不太懂有什么作用


LOCAL_STATIC_LIBRARIES :=  xxx aaa

The list of static libraries modules that the current module depends on.

If the current module is a shared library or an executable, this will force these libraries to be linked into the resulting binary.

If the current module is a static library, this simply tells that another other module that depends on the current one will also depend on the listed libraries.


LOCAL_C_INCLUDES

  An optional list of paths, relative to the NDK root directory, which will be appended to the include search path when compiling all sources (C, C++ and Assembly). For example:
    LOCAL_C_INCLUDES := sources/foo 

  Or even:
          LOCAL_C_INCLUDES := $(LOCAL_PATH)/../foo
    These are placed before any corresponding inclusion flag in LOCAL_CFLAGS / LOCAL_CPPFLAGS
    The LOCAL_C_INCLUDES path are also used automatically when launching native debugging with ndk-gdb.

就是说LOCAL_C_INCLUDES到编译一个东西时,找头文件时,会在LOCAL_C_INCLUDES里面找?


LOCAL_EXPORT_C_INCLUDES 

The LOCAL_EXPORT_C_INCLUDES definition here ensures that any module that depends on the prebuilt one will have its LOCAL_C_INCLUDES automatically prepended with the path to the prebuilt's include directory, and will thus be able to find headers inside that.

用在构建PREBUILT modle时,当依赖于对应的PREBUILT model的模块的LOCAL_C_INCLUDES 会自动包含LOCAL_EXPORT_C_INCLUDES 内的内容(特别是头文件),这样,依赖于这一个prebuilt model的model就可以找到并使用这个prebuilt model 的头文件。


include $(BUILD_SHARED_LIBRARY)

执行生成BUILD_SHARED_LIBRARY,在这之前,必须要定义LOCAL_MODULE 和LOCAL_SRC_FILES,编译脚本将会自动根据LOCAL_XXX等变量去生成对应的共享库,名字为,lib$(LOCAL_MODULE).so


include $(PREBUILT_STATIC_LIBRARY)

Points to a build script used to specify a prebuilt shared library. Unlike BUILD_SHARED_LIBRARY and BUILD_STATIC_LIBRARY, the value of LOCAL_SRC_FILES must be a single path to a prebuilt shared library (e.g. foo/libfoo.so), instead of a source file.不翻译了,很好理解


$(call import-module,<name>)

导入module,用于代码重用,会导入NDK_MODULE_PATH目录下的Android.mk文件(或者NDK_MODULE_PATH的子目录下),NDK_MODULE_PATH目录下的内容就相当于一个公共代码库,在项目中,只要在项目的jni目录下的Android.mk文件内使用$(call import-module,<name>),那么就相当于将NDK_MODULE_PATH/<name>,目录下的所有内容都导入到jni目录下一起使用了(有点不太确切),总之,用起来很像SDK中的LIbraryProject。$NDK/sources目录默认属于NDK_MODULE_PATH,如$(call import-module,ffmpeg-2.0.2-s/android/arm),则导入了$NDK/sources/ffmpeg-2.0.2-s/android/arm,下的内容。





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值