Cocos2dx-Android 之Makefile通用高级写法
不废话,直接贴。节约时间。须要改进的地方请各位指出。共同学习。
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := cocos2dcpp_shared LOCAL_MODULE_FILENAME := libcocos2dcpp ############################################################################### ##########################手动遍历文件夹以及子文件夹############################## ##########################这是第一种非常麻烦的写法################################ #XLOCAL_C_INCLUDES := \ # $(LOCAL_PATH)/hellocpp \ # $(LOCAL_PATH)/../../Classes # #XLOCAL_CPPS := \ # $(wildcard $(LOCAL_PATH)/hellocpp/*.cpp) \ # $(wildcard $(LOCAL_PATH)/../../Classes/*.c) \ # $(wildcard $(LOCAL_PATH)/../../Classes/*.cpp) # #XLOCAL_SRC_FILES := $(XLOCAL_CPPS:$(LOCAL_PATH)/%=%) # #LOCAL_C_INCLUDES += $(XLOCAL_C_INCLUDES) #LOCAL_SRC_FILES := $(XLOCAL_SRC_FILES) ############################################################################### ############################################################################### ##########################自己主动遍历文件夹以及子文件夹############################## ##########################这是另外一种比較方便的写法############################## # 遍历文件夹及子文件夹的函数 #define walk # $(wildcard $(1)) $(foreach e, $(wildcard $(1)/*), $(call walk, $(e))) #endef # ## 遍历Classes文件夹 #ALLFILES = $(call walk, $(LOCAL_PATH)/../../Classes) # #FILE_LIST := hellocpp/main.cpp ## 从全部文件里提取出全部.cpp文件 #FILE_LIST += $(filter %.cpp, $(ALLFILES)) # #LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%) #LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \ # $(LOCAL_PATH)/../../Classes/LogClass ############################################################################### ############################################################################### ##########################自己主动遍历文件夹以及子文件夹(源文件和头文件)################ ##########################这是第三种之相对最方便的写法########################### # 配置自己的源文件文件夹和源文件后缀名 APP_FILES_PATH := $(LOCAL_PATH) \ $(LOCAL_PATH)/../../Classes APP_FILES_SUFFIX := %.cpp %.c # 递归遍历文件夹下的全部的文件 rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2)) # 获取对应的源文件 APP_ALL_FILES := $(foreach src_path,$(APP_FILES_PATH), $(call rwildcard,$(src_path),*.*) ) APP_ALL_FILES := $(APP_ALL_FILES:$(APP_CPP_PATH)/./%=$(APP_CPP_PATH)%) APP_SRC_LIST := $(filter $(APP_FILES_SUFFIX),$(APP_ALL_FILES)) APP_SRC_LIST := $(APP_SRC_LIST:$(LOCAL_PATH)/%=%) # 去除字串的反复单词 define uniq = $(eval seen :=) $(foreach _,$1,$(if $(filter $_,${seen}),,$(eval seen += $_))) ${seen} endef # 递归遍历获取全部文件夹 APP_ALL_DIRS := $(dir $(foreach src_path,$(APP_FILES_PATH), $(call rwildcard,$(src_path),*/) ) ) APP_ALL_DIRS := $(call uniq,$(APP_ALL_DIRS)) # 赋值给NDK编译系统 LOCAL_SRC_FILES := $(APP_SRC_LIST) LOCAL_C_INCLUDES := $(APP_ALL_DIRS) ############################################################################### LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static LOCAL_WHOLE_STATIC_LIBRARIES += cocosbuilder_static LOCAL_WHOLE_STATIC_LIBRARIES += spine_static LOCAL_WHOLE_STATIC_LIBRARIES += cocostudio_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos_network_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static include $(BUILD_SHARED_LIBRARY) $(call import-module,.) $(call import-module,audio/android) $(call import-module,Box2D) $(call import-module,editor-support/cocosbuilder) $(call import-module,editor-support/spine) $(call import-module,editor-support/cocostudio) $(call import-module,network) $(call import-module,extensions)