make clean、make clobber、make distclean、make mrproper 和 make realclean 之间有什么区别?

What are the differences between make clean, make clobber, make distclean, make mrproper and make realclean?

我并不总是编写 make 文件,但当我编写文件时,我喜欢尝试将它们写好。试图使界面与其他开发人员可能期望的一致总是很困难。我正在寻找的是所有常见的 make something cleaner (GNU) make 目标的摘要。

常见的清理 make 目标是什么?

每个目标通常在什么时候使用?

每个目标与其他目标相比如何?


我以前使用过 make cleanmake clobbermake mrproper 的系统。那些变得越来越极端; make clean 只整理临时文件,make clobber 摆脱大部分配置,make mrproper 几乎回到刚签出的状态。这是事情的正常顺序吗? make mrproper 是否应该始终删除生成的二进制文件和共享库以进行部署?

四处阅读表明 make distclean 已将事情整理到准备好制作分发包的程度。我想这会留下一些自动生成的版本标记文件、文件清单和共享库,但可能会删除您不想存档的临时文件?

当我在 GNU Make Goals manual page 上看到

make realclean 时,它对我来说是全新的。由于它与 distcleanclobber 一起列出,我猜它具有类似的效果。我从来没有遇到过它,因为它是一件历史文物,或者只是对我必须从事的一组项目非常特定?


抱歉,有点乱。我发现了各种将一个目标与另一个目标进行比较的问题和答案,但 none 似乎给出了一个很好的概述。

尝试根据一些研究形成我自己的答案。我认为严重程度的大致顺序是; mostlycleancleanmaintainer-cleanmrproperdistclean 最后是 clobber(合并了 distcleanuninstall).

清理

make clean是最基本的水平。它会清除大多数生成的文件,但不会清除任何记录配置的文件。 GNU Make Manual's Goals page 状态:

Delete all files that are normally created by running make.

此外,GNU Make Manual's Standard Targets page 个阶段:

Delete all files in the current directory that are normally created by building the program. Also delete files in other directories if they are created by this makefile. However, don’t delete the files that record the configuration. Also preserve files that could be made by building, but normally aren’t because the distribution comes with them. There is no need to delete parent directories that were created with ‘mkdir -p’, since they could have existed anyway.

Delete .dvi files here if they are not part of the distribution.

使大部分清洁

make mostlyclean 是我发现的唯一更温和的 clean 形式,它的行为类似于 clean,但会留下需要很长时间编译且不需要经常重新生成的文件。

GNU Make Manual's Standard Targets page 个阶段:

Like ‘clean’, but may refrain from deleting a few files that people normally don’t want to recompile. For example, the ‘mostlyclean’ target for GCC does not delete libgcc.a, because recompiling it is rarely necessary and takes a lot of time.

进行 distclean

make distclean 是许多 GNU Make 系统上基本 make clean 的第一步。在许多情况下,它似乎是假名或至少与 make realcleanmake clobber 非常相似,但并非所有情况。它将删除 make clean 所做的一切并删除配置。

在 Linux 系统中,这是超越 make mrpropper 的一步,详情请参阅下面的部分。

我不确定这个名字是否意味着事情正在变得足够干净以供分发(形成 tar 存档)或者该过程正在将它们返回到与分发的状态相同的状态(就像解压 tar 存档后的情况一样)。

GNU Make Manual's Goals page 状态:

Any of these targets might be defined to delete more files than ‘clean’ does. For example, this would delete configuration files or links that you would normally create as preparation for compilation, even if the makefile itself cannot create these files.

此外,GNU Make Manual's Standard Targets page 个阶段:

Delete all files in the current directory (or created by this makefile) that are created by configuring or building the program. If you have unpacked the source and built the program without creating any other files, ‘make distclean’ should leave only the files that were in the distribution. However, there is no need to delete parent directories that were created with ‘mkdir -p’, since they could have existed anyway.

卸载

make uninstall 将卸载通过 make installinstall-* 变体之一安装的软件。这类似于某些系统上 make clobber 的部分行为,但 make uninstall 不应像 make clobber 那样接触构建区域。

GNU Make Manual's Standard Targets page 个阶段:

Delete all the installed files—the copies that the ‘install’ and ‘install-*’ targets create.

This rule should not modify the directories where compilation is done, only the directories where files are installed.

make maintainer-clean

make maintainer-clean 似乎比更常见的 make distclean 倒退了一步。它删除了除了配置之外的几乎所有内容。这使得它与 make clean 非常相似。

GNU Make Manual's Standard Targets page 个阶段:

Delete almost everything that can be reconstructed with this Makefile. This typically includes everything deleted by distclean, plus more: C source files produced by Bison, tags tables, Info files, and so on.

还需要强调的是,这不是常用的 target,因为它适用于一组特定的用户:

The ‘maintainer-clean’ target is intended to be used by a maintainer of the package, not by ordinary users.

使mrproper

make mrproper 似乎是 make distcleanmake clobber 的 Linux 内核版本。 没有删除备份和补丁文件。它完成了 make clean target 所做的一切,并删除了配置。

我相信这个名字来自一种清洁产品,在美国被称为 Mr. Clean,在英国被称为 Flash(这就是为什么我没有听说过该产品的命名)。 Linus Torvalds 是芬兰裔美国人,大概对 Mr. Propper 这个品牌很熟悉。

Linux Kernel Makefile 状态:

# Cleaning is done on three levels.
# make clean     Delete most generated files
#                Leave enough to build external modules
# make mrproper  Delete the current configuration, and all generated files
# make distclean Remove editor backup files, patch leftover files and the like

破坏

make clobber 也在 Wikipedia article for Clobbering 上被提及。这也表明它比 make clean 更严重,甚至可能卸载软件。 make uninstallmake distclean 的组合是可能的。


make clean 关卡没有单一来源。随着时间的推移,事物不断发展,术语和行为是不一致的。以上是迄今为止我设法拼凑的最好的。