Explanation of Android. mk file of Android ndk

Source: Internet
Author: User

Local_path: =$ (call my-DIR) </P> <p> include $ (clear_vars) </P> <p> local_module: = Tun </P> <p> local_src_files: = tunemu. c tun. c </P> <p> local_cflags: =/<br/>-I/home/xuxin/mylib/android-platform_external_libpcap/JNI </P> <p> local_ldlibs: =-L $ (sysroot) /usr/lib-llog-lpcap-L/home/xuxin/mylib/android-platform_external_libpcap/libs/armeabi </P> <p> include $ (build_shared_library) <br/>

1 local_path must be located at the beginning of the android. mk file. It is used to locate the source file,$ (Call my-DIR) is used to return the path of the current directory.

 

Include $ (clear_vars) is used to clear the values of some variables, except for local_path.

 

Local_module is used to specify the name of the module to be compiled. In this example, the module name is hello-JNI.

 

Local_src_files is used to specify the files to be compiled.Source codeFile. Here only compile hell0-jin.c

 

Include $ (build_shared_library) is used to indicate that the current module is compiled as a shared library, prefixed with Lib, and suffixed with. So.

Another build_static_library is used to indicate that the current module is compiled as a static library with the prefix. A and suffix..

 

This is the simplest structure of Android. mk. There may be another point to introduce:

 

2. Define multiple Android. mk files.

Sometimes there are many modules to be compiled. We may place the corresponding modules in the corresponding directory so that we can define the corresponding android. MK file (similar to the preceding method). Finally, put an android file in the root directory. MK file with the following content:

Include $ (call all-subdir-makefiles)

You only need this line. Its function is to include the Android. mk file in all subdirectories.

 

3. You can also include multiple modules in an android. mk file.

The intuitive idea is to copy and modify the content of the first Android. mk file. I did the same in the first place, but then I encountered a problem. I couldn't find the source code in the second module. Finally, I read the document and found that there was an example explanation in it:

Local_path: = $ (call my-DIR)

 

Important Note: Due to the way GNU make works, this really returns
The path of the * Last ** encoded ** makefile * during the parsing
Build scripts. Do not call my-Dir after including another file.

 

Call my-Dir returns the directory involved in the last include when parsing the build script based on the GNU make method.

 

Therefore, in most cases, you only need to call $ (call my-DIR) once in Android. mk, if all the source files are in a directory.

 

If necessary, save the value when calling my-Dir for the first time, for example:

My_local_path: = $ (call my-DIR)

Local_path: = $ (my_local_path)

 

Then, in another module, continue with the following definition:

Local_path: = $ (my_local_path)

 

4. Sometimes we need to introduce third-party library files and configure

Local_cflags: =/
-I/home/xuxin/mylib/android-platform_external_libpcap/JNI

Local_ldlibs: =-L $ (sysroot)/usr/lib-llog-lpcap-L/home/xuxin/mylib/android-platform_external_libpcap/libs/armeabi

The two variables local_cflags: = mainly reference the external C header file.-I is the storage path of the header file. If the header file is in the same directory as our own source file, no configuration is required;

Local_ldlibs: = refers to the external library file, and-L specifies the storage path of the Lib File

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.