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)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值