使用Makefile清理子目录

编程入门 行业动态 更新时间:2024-10-14 08:29:04
本文介绍了使用Makefile清理子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否可以从父目录执行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清理子目录

本文发布于:2023-11-01 13:22:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549435.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子目录   Makefile

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!