Makefile语法规则:
target:depend on
commands
Android.m语法规则:
作用:
- A static library. 静态库 ar -cr ---->libtest.a
- A shared library. 动态库 gcc -shared -fPIC test.c -o libtest.so -I指定头文件路径 -L指定库的路径 -l引用库
- A standalone executable.可执行文件
规则:
LOCAL_PATH := $(call my-dir) //获取当前路径的
126 define my-dir
127 $(strip \
128 $(eval LOCAL_MODULE_MAKEFILE := $$(lastword $$(MAKEFILE_LIST))) \
129 $(if $(filter $(BUILD_SYSTEM)/% $(OUT_DIR)/%,$(LOCAL_MODULE_MAKEFILE)), \
130 $(error my-dir must be called before including any other makefile.) \
131 , \
132 $(patsubst %/,%,$(dir $(LOCAL_MODULE_MAKEFILE))) \
133 ) \
134 )
135 endef
include $(CLEAR_VARS) //清除环境变量
69 CLEAR_VARS:= $(BUILD_SYSTEM)/clear_vars.mk
LOCAL_MODULE:=
LOCAL_MODULE_PATH:=
LOCAL_MODULE_RELATIVE_PATH :=
LOCAL_MODULE_STEM:=
LOCAL_DONT_CHECK_MODULE:=
LOCAL_MODULE := hello-jni 指定模块名字
LOCAL_SRC_FILES := hello-jni.c 指定源文件
include $(BUILD_SHARED_LIBRARY) 指定动态库
include $(BUILD_STATIC_LIBRARY) 指定静态库
include $(BUILD_EXECUTABLE) 指定可执行程序
编译方法:
source build/envsetup.sh
mm: Builds all of the modules in the current directory, but not their dependencies.
mmm: Builds all of the modules in the supplied directories, but not their dependencies.
单文件编译:
1 LOCAL_PATH:=$(call my-dir)
2 include $(CLEAR_VARS)
3 LOCAL_MODULE:=test
4 LOCAL_MODULE_PATH:=$(LOCAL_PATH)/bin
5 LOCAL_SRC_FILES:= test.c
6 include $(BUILD_EXECUTABLE)
多文件编译:
1 LOCAL_PATH:=$(call my-dir)
2 include $(CLEAR_VARS)
3 LOCAL_MODULE:=test
4 LOCAL_MODULE_PATH:=$(LOCAL_PATH)/bin
5 LOCAL_SRC_FILES:= $(call all-c-files-under,src)
6 include $(BUILD_EXECUTABLE)
库文件的编译:
1 LOCAL_PATH:=$(call my-dir)
8 include $(CLEAR_VARS)
9 LOCAL_MODULE:=libadd
10 LOCAL_SRC_FILES:= src/add.c
11 LOCAL_MODULE_PATH:=$(LOCAL_PATH)/lib
12 include $(BUILD_SHARED_LIBRARY)
14 include $(CLEAR_VARS)
15 LOCAL_MODULE:=libadd
16 LOCAL_SRC_FILES:= src/add.c
18 include $(BUILD_STATIC_LIBRARY)
指定系统动态库:
LOCAL_SHARED_LIBRARIES:= 动态库
LOCAL_STATIC_LIBRARIES:= 动态库
14 include $(CLEAR_VARS)
15 LOCAL_MODULE:=test
16 LOCAL_SRC_FILES:= src/test.c
17 LOCAL_MODULE_PATH:=$(LOCAL_PATH)/bin
18 LOCAL_SHARED_LIBRARIES:= liblog
19 include $(BUILD_EXECUTABLE)
生成一个apk文件:
17 LOCAL_PATH := $(call my-dir)
18 include $(CLEAR_VARS)
24 LOCAL_SRC_FILES := $(call all-java-files-under, src)
28 LOCAL_PACKAGE_NAME := Calculator
LOCAL_DEX_PREOPT := false
32 include $(BUILD_PACKAGE)