NDK系統參數詳解:android
LOCAL_PATH := $(call my-dir)c++
指定LOCAL_PATH變量,用於查找源文件,上面的語句的意思是將LOCAL_PATH變量定義成當前文件所在目錄路徑, my-dir是編譯系統提供的宏函數,被用來獲取當前的目錄。函數
$(call import-add-path,$(LOCAL_PATH)/../../../../)code
import-add-path用來添加路徑到 NDK_MODULE_PATH 環境變量中。xml
include $(CLEAR_VARS)io
CLEAR_VARS由編譯系統提供,指定讓GNU MAKEFILE爲你清除除LOCAL_PATH之外的全部LOCAL_XXX變量,如LOCAL_MODULE,LOCAL_SRC_FILES,LOCAL_SHARED_LIBRARIES等. 一個Android.mk中能夠定義多個編譯模塊,每一個編譯模塊都是以include $(CLEAR_VARS)開始,以include $(BUILD_XXX)結束。編譯
LOCAL_MODULE := cocos2dcpp_sharedimport
每個android.mk文件中都必須定義一個模塊標示 LOCAL_MODULE , 這個名字必須是惟一的而且不包含任何的空格,編譯系統將自動的修改生成文件的前綴和後綴,如一個模塊爲foo共享庫將被改成libfoo.so,若是你的模塊名爲libfoo,編譯系統生成的文件爲 libfoo.so, 而不會去再增長前綴,當你使用的時候,android平臺會自動識別變量
LOCAL_MODULE_FILENAME := libcocos2dcppmodule
LOCAL_MODULE_FILENAME指定模塊文件名
LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp
LOCAL_SRC_FILES指定本模塊的c/c++源文件(.c .cpp .cc),各文件之間以空格分隔,\爲續行符。
LOCAL_CPP_EXTENSION := .cc .cpp
默認的c++文件擴展名是.cpp, LOCAL_CPP_EXTENSION能夠用來指定不一樣類型的擴展名,不要忘了前面的點
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../Classes
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../Classes/Game
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../Classes/Lobby
LOCAL_C_INCLUDES參數指定本模塊包含的頭文件路徑,多個路徑之間以空格分隔
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
LOCAL_WHOLE_STATIC_LIBRARIES參數用來指定本模塊依賴的全部靜態庫模塊(鏈接靜態鏈接庫的時候不會移除"daed code",何謂dead code呢,就是調用者模塊永遠都不會用到的代碼段和變量)
LOCAL_STATIC_LIBRARIES += cocos2dx_static
LOCAL_STATIC_LIBRARIES += cocosdenshion_static
LOCAL_ STATIC_LIBRARIES參數用來指定本模塊依賴的全部靜態庫模塊(鏈接靜態鏈接庫的時候會移除"daed code",何謂dead code呢,就是調用者模塊永遠都不會用到的代碼段和變量)
include $(BUILD_STATIC_LIBRARY) 表示編譯成靜態庫。
include $(BUILD_SHARED_LIBRARY) 表示編譯成動態庫(即共享庫)。
include $(BUILD_EXECUTABLE) 表示編譯成可執行程序。
include $(PREBUILT_STATIC_LIBRARY) 表示定義一個預編譯好的靜態庫模塊。
include $(PREBUILT_SHARED_LIBRARY) 表示定義一個預編譯好的動態庫模塊。
$(call import-module,cocos2dx)導入外部模塊(此處表示導入cocos2dx模塊,cocos2dx爲模塊名LOCAL_MODULE,注意該命令搜索外部模塊的路徑在NDK_MODULE_PATH中指定或經過$(call import-add-path,$(LOCAL_PATH)/../../)命令導入)。
編寫預編譯靜態庫Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libxml2_static
LOCAL_SRC_FILES := $(LOCAL_PATH)/lib/android/libxml2.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)
編寫預編譯動態庫Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libYvImSdk
LOCAL_SRC_FILES := $(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/libYvImSdk.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)
自動蒐集欲編譯的源文件
define walk
$(wildcard $(1)) $(foreach e, $(wildcard $(1)/*), $(call walk, $(e)))
endef
ALLFILES := $(call walk, $(LOCAL_PATH)/../../Classes)
FILE_LIST := hellocpp/main.cpp
FILE_LIST += $(filter %.cpp, $(ALLFILES))
FILE_LIST += $(filter %.c, $(ALLFILES))
FILE_LIST += $(filter %.cc, $(ALLFILES))
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)