GNU Make 语法笔记

#ndk make 笔记记录

ndk-build:The shell script is the starting point of Android NDK build system.

ndk-gfb: The shell script is GNU origin native components.

ndk-stack: The shell script can be helpful in analysis bug.

build: The package includes all Android NDK module.

platforms: The package includes different API head files and lib files.

samples: The directory includes some examples.

sources: The directory includes some share module.

toolchains: The directory includes different ABI cross compiler.

--------------------------------------------------------------A GNU Makefile fragment
#Android.mk

LOCAL_PATH := $(call my-dir)

It is used to specify variables. And this line must be first line.

my-dir is a macro function. means current directory.

include $(CLEAR_VARS)

This line can clear all variables except LOCAL_PATH.

LOCAL_MODULE := hello-jin

Current module is named as “hello-jin”

LOCAL_SRC_FIELS := hello-jni.c

define the source files. separation by space.

include $(BUILD_SHARED_LIBRARY)
#build the shared lib which will generate a so file.


#build several share libs

LOCAL_PATH := $(call my-dir)

#module 1

include $(CLEAR_VARS)

LOCAL_MODULE := module1
LOCAL_SRC_FILES := module1.c
include $(BUILD_SHARED_LIBRARY)

#module 2

include $(CLEAR_VAR)

LOCAL_MODULE := module2
LOCAL_SRC_FILES := module2.c

include $(BUILD_SHARED_LIBRARY)

build static lib

LOCAL_PATH := $(call my-dir)

The third-part lib

include $(CLEAR_VARS)

LOCAL_MODULE := avilib
LOCAL_SRC_FILES := avilib.c platform_posix.c

include $(BUILD_STATIC_LIBRARY)

The origin module

include $(CLEAR_VARS)

LOCAL_MODULE := module
LOCAL_SRC_FILES := module.c

LOCAL_STATIC_LIBRARIES := avilib

include $(BUILD_SHARED_LIBRARY)

dynamic link share lib

LOCAL_PATH := $(call my-dir)

The third-part lib

include $(CLEAR_VAR)
LOCAL_MODULE := avilib
LOCAL_SRC_FILES := avilib.c platform_posix.c

include $(BUILD_SHARED_LIBRARY)

The origin module 2

include $(CLEAR_VARS)

LOCAL_MODULE := module2
LOCAL_SRC_FILES := module2.c

LOCAL_SHARD_LIBRARIES := avilib

include &(BUILD_SHARD_LIBRARY)

The origin module 1

include $(CLEAR_VARS)

LOCAL_MODULE := module1
LOCAL_SRC_FILES := module1.c

LOCAL_SHARED_LIBRARIES := avilib

include &(BUILD_SHARD_LIBRARY)


several NDK projects share the lib module

  1. firstly, moving the share source file out of ndk project.
  2. build itself mk file.

#android.mk

LOCAL_PATH :+= $(call my-dir)

The third-part lib

include $(CLEAR_VARS)

LOCAL_MODULE := avilib
LOCAL_SRC_FILES := avilib.c platform_posix.c

include $(BUILD SHARD LIBRARY)


use the outer shared lib

The origin share lib

include $(CLEAR_VARS)

LOCAL_MODULE := module
LOCAL_SRC_FILES := module.c
LOCAL_SHARED_LIBRARIES := avilib //!!!

include $(BUILD_SHARED_LIBRARY) //!!!

$(call import-module,transcode/avilib) // default only search ndk path.默认情况下,只搜索ndk/sources目录, 可以配置 NDK_MODULE_PATH环境变量


Prebuilt Lib

LOCAL_PATH := $(call my-dir)

The third prebuild AVI lib

LOCAL_MODULE := avilib
LOCAL_SRC_FILES := libavilib.so //这是实际 so 相对于LOCAL_PATH的位置 该目录下有mk文件 包含LOCAL_PATH CLEAR LOCAL_SHARED_LIBRARIES := avilib

include $(PREBUILD_SHARED_LIBRARY)


build exe file

include $(CLEAR_VARS)
LOCAL_MODULE := module
LOCAL_SRC_FILES := module.c

LOCAL_STATIC_LIBHRARIES := avilib

include $(BUILD_EXECUTABLE)


other system variable

TARGET_ARCH //example : arm
TARGET_PLATFORM // example : android-3
TARGET_ARCH_ABI // CPU archtecture and ABI name
TARGET_ABI // aim platform and ABI

LOCAL_MODULE_FILENAME : //optional override the module name

LOCAL_CPP_EXTENSION : //amending C++ source file default

LOCAL_CPP_FEATURES //optional indicate C++ feature

LOCAL_C_INCLUDES //optional NDK installation path

LOCAL_CFLAGS // optional complie FLAGS

LOCAL_CPP_FLAGS // optional complie CPP FLAGS

LOCAL_WHOLE_STATIC_LIBRARIES // LOCAL_STATIC_LIBRARIES `s varant for indicating all should be included static lib.

LOCAL_LDLIBS // link flag optional list.

LOCAL_ALLOW_UNDEFINED_SYMBOLS // optional , it fobiddens check undefine symbol

LOCAL_ARM_MODE // optional ARM machine specific variable for indicating arm binary style.

LOCAL_ARM_NEON //optional ARM machine specific varibal for indicating source file should use ARM high single command that muti data stream inline function.

LOCAL_DISABLE_NO_EXECUTE //optional forbidden NX Bit safity feature. NX Bit means Never Execute


你可能感兴趣的:(笔记)