当前位置:网站首页>mk file introduction

mk file introduction

2022-08-11 06:35:00 The rest of my life love static

Introduction to Android.mk:

The Android.mk file is used to tell the NDK Build system about the Source.Android.mk will be part of the GNU Makefile and will be parsed by the Build System one or more times.
So, try to declare as few variables in Android.mk as possible, and don't assume anything won't be defined during parsing.

Android.mk file syntax allows us to package Source into a "modules", modules can be:

  • Static library (.a file)
  • Dynamic library (.so file)

Only dynamic libraries can be installed/copied into application packages (APK), static libraries can be linked into dynamic libraries.
You can define one or more modules in an Android.mk. You can also add the same source to multiple modules.
Build System handles a lot of details for us and doesn't need us to care anymore.For example: you don't need to list header files and external dependencies in Android.mk.
NDK Build System provides this information for us automatically.This also means that when users upgrade the NDK, you can benefit from the new toolchain/platform without having to modify Android.mk.

Android.mk syntax

LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := VideoJniLOCAL_CFLAGS := -DWEBRTC_POSIX -DFIXED_POINT -DUSE_KISS_FFT -DEXPORT="" -UHAVE_CONFIG_HLOCAL_CPPFLAGS :=-std=c++11LOCAL_LDLIBS :=-llog -lcLOCAL_C_INCLUDES := \$(LOCAL_PATH)/webrtc \$(LOCAL_PATH)/speex/includeLOCAL_SRC_FILES := \com_example_videoclient_VideoJni.cpp \$(AUDIO_SRC_PATH)/Host.cpp \speex/libspeex/bits.c \include $(BUILD_SHARED_LIBRARY)

1, LOCAL_PATH

LOCAL_PATH := $(call my-dir)

Each Android.mk file must start with the definition LOCAL_PATHwhich is used to find source files in the development tree; macros my-dirstrong> is provided by Build System and returns the directory path containing Android.mk.

2, CLEAR_VARS

include $(CLEAR_VARS)
The

CLEAR_VARS variable is provided by the Build System and points to a specific GNU Makefile, which is responsible for cleaning up many LOCAL_xxx.For example: LOCAL_MODULE, LOCAL_SRC_FILES, LOCAL_STATIC_LIBRARIES, etc.But if LOCAL_PATH is not cleaned up, this cleaning action is necessary, because all compilation control files are parsed and executed by the same GNU Make, and their variables are global, so they can avoid mutual influence after cleaning.

3, LOCAL_MODULE

LOCAL_MODULE := VideoJni
The

LOCAL_MODULE module must be defined to represent every module in Android.mk.First names must be unique and contain no spaces.
The Build System will automatically add the appropriate prefix and suffix.For example, VideoJni, to generate a dynamic library, generate libVideoJni.so.But please note: If the module name is set as: libxxx, libxxx.so will be generated without prefix.
insert image description here

4, LOCAL_CFLAGS

LOCAL_CFLAGS := -DWEBRTC_POSIX -DFIXED_POINT -DUSE_KISS_FFT -DEXPORT="" -UHAVE_CONFIG_H

Additional compilation parameters provided to the C/C++ compiler, such as specifying all warnings as error, specifying optimization levels, such as: LOCAL_CFLAGS := -Werror

5, LOCAL_CPPFLAGS

LOCAL_CPPFLAGS :=-std=c++11

Define extra flags for C++ files

6, LOCAL_LDLIBS

LOCAL_LDLIBS :=-llog -lc

Specify the link library that the program depends on, -llog links the Android NDK log library -lc links the C language library

7. LOCAL_C_INCLUDES

LOCAL_C_INCLUDES := \$(LOCAL_PATH)/webrtc \$(LOCAL_PATH)/speex/include

8, LOCAL_SRC_FILES

Header file path required for C/C++

LOCAL_SRC_FILES := \com_example_videoclient_VideoJni.cpp \$(AUDIO_SRC_PATH)/Host.cpp \speex/libspeex/bits.c \

All source files

contained in the current module

9, BUILD_SHARED_LIBRARY

include $(BUILD_SHARED_LIBRARY)

BUILD_SHARED_LIBRARY is a Build System-provided variable that points to a GNU Makefile Script.It is responsible for collecting all LOCAL_XXX information since the last call to include $(CLEAR_VARS) and deciding what to compile.

  • BUILD_STATIC_LIBRARY: Compile as a static library
  • BUILD_SHARED_LIBRARY: Compile as dynamic library
  • BUILD_EXECUTABLE: Compile to Native C executable program
原网站

版权声明
本文为[The rest of my life love static]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/223/202208110515270190.html