找回密码
 注册
搜索
热搜: 超星 读书 找书
查看: 4639|回复: 0

[【推荐】] 制作一个遍历当前子目录的Makefile

[复制链接]
发表于 2009-8-6 14:50:50 | 显示全部楼层 |阅读模式
要对子目录执行make,需要在当前目录制作一个Makefile,遍历所有子目录的Makefile,并运行相应的make target. 以下是我用来编译内核模块的一个Makefile

#

# Reference http://www.gnu.org/software/make/manual/make.html

#

# 需要排除的目录

exclude_dirs := include bin

# 取得当年子目录深度为1的所有目录名称

dirs := $(shell find . -maxdepth 1 -type d)

dirs := $(basename $(patsubst ./%,%,$(dirs)))

dirs := $(filter-out $(exclude_dirs),$(dirs))

# 避免clean子目录操作同名,加上_clean_前缀

SUBDIRS := $(dirs)

clean_dirs := $(addprefix _clean_,$(SUBDIRS) )

#

.PHONY: subdirs $(SUBDIRS) clean

# 执行默认make target

$(SUBDIRS):  

$(MAKE) -C $@

subdirs: $(SUBDIRS)

# 执行clean

$(clean_dirs):  

$(MAKE) -C $(patsubst _clean_%,%,$@) clean

clean: $(clean_dirs)  

@find . \\   

\\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \\

-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \\

-o -name '*.symtypes' \\) \\

-type f -print | xargs rm -f
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|网上读书园地

GMT+8, 2024-5-19 00:07 , Processed in 0.267419 second(s), 5 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表