是否可以从父目录执行make clean,而该父目录也递归地清理所有子目录,而不必在每个子目录中都包含makefile?
Is it possible to perform a make clean from the parent directory which also recursively cleans all sub-directories without having to include a makefile in each sub-directory?
例如,当前在我的Makefile中,我有类似的内容:
For example, currently in my Makefile, I have something like:
SUBDIRS = src, src1 .PHONY: clean subdirs $(SUBDIRS) clean: $(SUBDIRS) rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c $(SUBDIRS): $(MAKE) -C $(SUBDIRS) clean但是,这要求我在src和src1中都具有一个Makefile.否则,我会得到错误
However, this requires me to have a Makefile in both src and src1. Otherwise, I would get the error
No rule to make target clean由于我只想在每个子目录中运行命令"rm -rf * .o 〜core .depend. .cmd * .ko * .mod.c",因此似乎多余必须在每个子目录中包含一个Makefile,并使用完全相同的行进行清理.没有办法简单地在每个子目录中运行相同的clean命令吗?
Since I only want to run the command "rm -rf *.o ~ core .depend ..cmd *.ko *.mod.c" in each subdirectory anyways, it seems redundant to have to include a Makefile in every subdirectory with the exact same line for clean. Is there no way to simply have the same clean command run in each of the subdirectories?
推荐答案我同意您可以让rm命令对子目录进行操作.但是类似以下的内容仅允许使用单个makefile进行递归生成:
I agree that you could just have the rm command operate on subdirs. But something like the following allows recursive make using only a single makefile:
SUBDIRS = . src src1 SUBDIRSCLEAN=$(addsuffix clean,$(SUBDIRS)) clean: $(SUBDIRSCLEAN) clean_curdir: rm -rfv *.o *~ core .depend .*.cmd *.ko *.mod.c %clean: % $(MAKE) -C $< -f $(PWD)/Makefile clean_curdir更多推荐
使用Makefile清理子目录
发布评论