Android.mk 遍历

2016-12-29  本文已影响0人  juket

android.mk

在mac和windows下多目录 文件/目录遍历

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d)
$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/external)
$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/cocos)
$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/cocos/audio/include)
###############################################################################
#mac环境 注释掉下面这行
IS_WINDOWS := true

LOCAL_MODULE := MyGame_shared

LOCAL_MODULE_FILENAME := libcocos2dcpp
###############################################################################
# 配置源文件目录和源文件后缀名
MY_FILES_PATH  :=  $(LOCAL_PATH) \
                   $(LOCAL_PATH)/../../../Classes
MY_FILES_SUFFIX := %.cpp %.c

# 遍历目录及子目录的函数
define walk
    $(wildcard $(1)) $(foreach e, $(wildcard $(1)/*), $(call walk, $(e)))
endef

# 去除字串的重复单词
define uniq =
  $(eval seen :=)
  $(foreach _,$1,$(if $(filter $_,${seen}),,$(eval seen += $_)))
  ${seen}
endef

# 遍历Jni和Classes目录
ALLFILES := $(foreach src_path,$(MY_FILES_PATH), $(call walk,$(src_path),*.*) )
#$(warning ALLFILES $(ALLFILES))
# 从所有文件中提取出所有.c和.cpp文件
FILE_LIST  := $(filter $(MY_FILES_SUFFIX),$(ALLFILES))
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
$(warning LOCAL_SRC_FILES= $(LOCAL_SRC_FILES))
###############################################################################
ifdef IS_WINDOWS
    # windows递归遍历获取所有目录
    MY_ALL_DIRS := $(dir $(foreach src_path,$(MY_FILES_PATH), $(call walk,$(src_path),*/) ) )
    MY_ALL_DIRS := $(call uniq,$(MY_ALL_DIRS))
    LOCAL_C_INCLUDES := $(MY_ALL_DIRS)
else
    # mac获取所有目录
    FILE_INCLUDES := $(shell find $(LOCAL_PATH)/../../../Classes -type d)
    LOCAL_C_INCLUDES := $(FILE_INCLUDES)
endif
$(warning LOCAL_C_INCLUDES= $(LOCAL_C_INCLUDES))
###############################################################################
上一篇下一篇

猜你喜欢

热点阅读