Android.mk detailed explanation

Add local programs or libraries to Android. These programs have nothing to do with their paths, but only with their Android.mk.
Android.mk is slightly different from ordinary makefiles. Android.mk has a unified writing method and mainly contains some common macros of the system: For
options in Android.mk, refer to the following file paths:
build/core/config.mk
Default values ​​of each option Defined in the following files:
build/core/base_config.mk
In one android.mk can also generate multiple executable programs, dynamic libraries, static libraries.

1. Compile the program:

1.1 Executable program template:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_PATH)
LOCAL_SRC_FILES := \
                    main.c
LOCAL_MODULE := test_exe
#LOCAL_C_INCLUDES := 
#LOCAL_STATIC_LIBRARIES := 
#LOCAL_SHARED_LIBRARISE := 
include $(BUILD_STATIC_LIBRAR)

LOCAL_PATH:= $(call my-dir)

This line of code is at the beginning of Android.mk and is used to give the path of the current file:
LOCAL_PATH:
used to find source files in the development tree;
macro function 'my-dir':
provided by the build system to return the current path ( That is, the directory containing the Android.mk file)
---
LOCAL_C_INCLUDES:
Indicates the path to include the required header files to be added
---
LOCAL_MODULE:
Indicates the final final name of the module
---
LOCAL_STATIC_LIBRARIES: Adds
the required static library for the
connection- --
LOCAL_SHARED_LIBRARISE:
Add the required dynamic library
and finally use include $(BUILD_EXECUTABLE) to indicate that it is compiled as an executable program; the final generated static library is libtest_static.a;

1.2 Compile a static library

The template for compiling a static library in Android.mk looks like this:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_PATH)
LOCAL_SRC_FILES := \
                    main.c
LOCAL_MODULE := libtest_static
#LOCAL_C_INCLUDES := 
#LOCAL_STATIC_LIBRARIES := 
#LOCAL_SHARED_LIBRARISE := 
include $(BUILD_STATIC_LIBRARY)

1.3 Compile a dynamic library

The template for compiling a dynamic library in Android.mk looks like this:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_PATH)
LOCAL_SRC_FILES := \
                    helloworld.c
LOCAL_MODULE := libtest_shared
TARGET_PRELINK_MODULE := false
#LOCAL_C_INCLUDES := 
#LOCAL_STATIC_LIBRARIES := 
#LOCAL_SHARED_LIBRARISE := 
include $(BUILD_SHARED_LIBRARY)

Similarly, the name of the final generated dynamic library is libtest_shared.so;

1.4 Compilation results

The compilation results generated by executable programs, static libraries, and dynamic libraries are respectively in the following directories:
out/target/product/xxxx/obj/EXECUTABLE
out/target/product/xxxx/obj/STATIC_LIBRARY
out/target/product/xxxx/obj/ SHARED_LIBRARY

The target folders for each module are:

  • Executable: {XXX}_intermediates
  • Static library: {XXX}_static_intermediates
  • Dynamic library: {XXX}_shared__intermediates

During the compilation process, you can compile the content of the target machine or the content of the host computer. The macros used in executable files, dynamic libraries, and static libraries are as follows:

include $(BUILD_EXECUTABLE)
include $(BUILD_STATIC_LIBRARY)
include $(BUILD_SHARED_LIBRARY)

Compile the content of the host, the executable file, dynamic library, static library use macros are as follows:

include $(BUILD_HOST_EXECUTABLE)
include $(BUILD_HOST_STATIC_LIBRARY)
include $(BUILD_HOST_SHARED_LIBRARY)

In android.mk, the final target installation path can be specified using the following two macros:

LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)  
LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED)

Different filesystems use the following macros to make selections:

2. Installer:

In addition to compiling various content, sometimes it is necessary to copy some files to the target file system, such as configuration scripts, resource files, preset programs and libraries, etc., and sometimes it is necessary to create directories in the target file system;
in Android.mk, do Examples of directory creation and installation are as follows:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_PATH)
xxx(正常makefile语法)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324802407&siteId=291194637
Recommended