Android.mk遍历子目录所有文件

plain]  view plain copy
  1. define all-cpp-files-under  
  2. $(patsubst ./%,%, \  
  3.   $(shell cd $(LOCAL_PATH) ; \  
  4.           find $(1) -name "*.cpp" -and -not -name ".*" -and -not -name "CCEditBoxImplWindow.cpp") \  
  5.  )  
  6. endef  
  7.   
  8. define all-subdir-cpp-files  
  9. $(call all-cpp-files-under,.)  
  10. endef  
  11.   
  12. LOCAL_SRC_FILES := $(call all-subdir-cpp-files)  

使用这个方法可以遍历子目录所有.cpp文件,替换find的参数可以实现遍历和过滤任意文件。

Android.mk编写变得非常简洁和方便,无需再维护文件列表了。

另附一个更加简单的宏,可以实现遍历一个目录下的所有文件(但是不会递归调用)

[plain]  view plain copy
  1. LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/../*.c)  

通过wildcard可以进行文件遍历,如果是单目录结构,通过这个同样可以达到非常简洁的效果。如果是c++代码的话(*.cpp文件),需要使用下面的方式,否则可能找不到文件:

[plain]  view plain copy
  1. FILE_LIST := $(wildcard $(LOCAL_PATH)/../*.cpp)  
  2. LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)  


加强版本(遍历所有文件,但是忽略某一个目录的文件)

[plain]  view plain copy
  1. define all-cpp-files-under  
  2. $(patsubst ./%,%, \  
  3.   $(shell cd $(LOCAL_PATH) ; \  
  4.           find $(1) -name LogicLayer -prune -o -name "*.cpp" -and -not -name ".*") \  
  5.  )  
  6. endef  
通过-prune可以指定忽略 "LogicLayer"这个目录
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值