用自己修改过的 framework/base/media/libstagefright/Android.mk做例子,讲得不对的大家扔鸡蛋吧:
LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS)
第二行,是用于清除之前其他mk文件定义的全局变量。例如LOCAL_SRC_FILE,就每个模块都会定义一个,这样定义这些变量之前,先清掉。但是这个函数不会清LOCAL_PATH。
LOCAL_SRC_FILES:= \ AMRExtractor.cpp \ AMRWriter.cpp \ SubtitlePlayer.cpp \ ... vome/voCMediaDecoder.cpp
LOCAL_C_INCLUDES:= frameworks/base/media/libstagefright/include/include\ frameworks/base/media/libstagefright/include\ frameworks/base/media/libstagefright/include/real\ $(JNI_H_INCLUDE) \ $(TOP)/frameworks/base/include/media/stagefright/openmax \ $(TOP)/external/tremolo \ $(TOP)/frameworks/base/media/libstagefright/rtsp
TARGET_ROOT_OUT:表示根文件系统。
TARGET_OUT:表示system文件系统。
TARGET_OUT_DATA:表示data文件系统。
用法如:
CAL_MODULE_PATH:=$(TARGET_ROOT_OUT)
LOCAL_MODULE_PATH和LOCAL_UNSTRIPPED_PATH来指定最后的目标安装路径。
LOCAL_SHARED_LIBRARIES := \ libbinder \ libmedia \ libutils \ libiconv \ libcutils \ libui \ libsonivox \ libvorbisidec \ libsurfaceflinger_client \ libcamera_client
LOCAL_STATIC_LIBRARIES := \ libstagefright_rtsp \ libstagefright_id3 \ libstagefright_g711dec
LOCAL_SHARED_LIBRARIES += \ libstagefright_amrnb_common \ libstagefright_enc_common \ libstagefright_avc_common \ libstagefright_foundation \ libstagefright_color_conversion
ifeq ($(TARGET_OS)-$(TARGET_SIMULATOR),linux-true) LOCAL_LDLIBS += -lpthread -ldl LOCAL_SHARED_LIBRARIES += libdvm LOCAL_CPPFLAGS += -DANDROID_SIMULATOR endif ifneq ($(TARGET_SIMULATOR),true) LOCAL_SHARED_LIBRARIES += libdl endif ifeq ($(TARGET_OS)-$(TARGET_SIMULATOR),linux-true) LOCAL_LDLIBS += -lpthread endif根据平台添加库和编译参数
LOCAL_CFLAGS += -Wno-multichar对multichar不报warning,编译参数
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/common -lstagefright_ccmp3dec -lstagefright_cookdec -lstagefright_ac3dec -lstagefright_flacdec -lstagefright_wmadec \ -lstagefright_wma3dec -lstagefright_dtsdec -lstagefright_apedec -lstagefright_faad2dec -lstagefright_matroska -lstagefright_mpet2ts_cc \ -lstagefright_real -lstagefright_mov -lstagefright_asf -lstagefright_mpg -lstagefright_ape -lstagefright_flac -lstagefright_flv -lstagefright_avi \ -lstagefright_adpcmdec -lstagefright_sub_txtdec -lstagefright_sub_extra
LOCAL_MODULE:= libstagefrightLOCAL_MODULE变量必须定义,以标识你在Android.mk文件中描述的每个模块。名称必须是唯一的,而且不包含任何空格。注意编译系统会自动产生合适的后缀。在这里,将会编译生成libstagefright.so(因为后面写好了编译的是动态库)
include $(BUILD_SHARED_LIBRARY)表示编译一个动态库,生成的文件放在out/target/product/generic/obj/SHARED_LIBRARY,目标文件夹为:XXX_shared_intermediates
其他:
include $(BUILD_STATIC_LIBRARY) 表示编译一个静态库,生成的文件放在out/target/product/generic/obj/STATIC_LIBRARY,目标文件夹为:XXX_static_intermediates
include $(BUILD_EXECUTABLE) 表示编译一个可执行文件,生成的文件放在 out/target/product/generic/obj/EXECUTABLE下,目标文件夹为:XXX_intermediates
include $(call all-makefiles-under,$(LOCAL_PATH))向子目录深入,编译子目录的所有东西,有另外一种写法,是include $(call all-subdir-makefiles),暂时没试出什么区别
另外,附上常用模板:
1,编译应用程序的模板:
#Test Exe
LOCAL_PATH := $(call my-dir)
#include $(CLEAR_VARS)
LOCAL_SRC_FILES:= main.c
LOCAL_MODULE:= test_exe
#LOCAL_C_INCLUDES :=
#LOCAL_STATIC_LIBRARIES :=
#LOCAL_SHARED_LIBRARIES :=
include $(BUILD_EXECUTABLE)
2,编译静态库的模板:
#Test Static Lib
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= /
helloworld.c
LOCAL_MODULE:= libtest_static
#LOCAL_C_INCLUDES :=
#LOCAL_STATIC_LIBRARIES :=
#LOCAL_SHARED_LIBRARIES :=
include $(BUILD_STATIC_LIBRARY)
3,编译动态库的模板:
#Test Shared Lib
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= /
helloworld.c
LOCAL_MODULE:= libtest_shared
TARGET_PRELINK_MODULES := false
#LOCAL_C_INCLUDES :=
#LOCAL_STATIC_LIBRARIES :=
#LOCAL_SHARED_LIBRARIES :=
include $(BUILD_SHARED_LIBRARY)
以上部分来自http://blog.csdn.net/zhandoushi1982/article/details/5316669