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

标签 makefile compilation gnu-make packaging code-cleanup

我并不总是编写 make 文件,但当我这样做时,我喜欢尝试并写好它们。试图使界面与其他开发人员的期望一致始终是一项艰巨的任务。我正在寻找的是所有常见的 make some clean (GNU) make 目标的摘要。

常见的清理目标有哪些?

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

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

<小时/>

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

阅读周围的内容后发现,make distclean 可以将事情整理到准备制作分发包的程度。我想这会留下一些自动生成的版本标记文件、文件 list 和共享库,但可能会删除您不希望存档的临时文件?

当我在GNU Make Goals manual page上发现

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

<小时/>

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

最佳答案

尝试根据一些研究形成我自己的答案。我认为严重程度的大致顺序是: 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.

使大部分干净

makemostclean 是我发现的唯一更温和的 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 Maintenanceer-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.

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

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 目标执行的所有操作并删除配置。

我相信这个名字来自于美国的一种清洁产品 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 clobberWikipedia article for Clobbering 上得到提及也。这也表明它比 make clean 更严重,甚至可能会卸载软件。可以将 make uninstallmake distclean 组合起来。

<小时/>

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

关于makefile - make clean、make clobber、make distclean、make mrproper 和 make realclean 之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51837675/

相关文章:

ubuntu - 编译器错误 :/usr/bin/ld: cannot find -lbluetooth

c++ - makefile中汇编文件的生成

收集2 : ld terminated with signal 11 [Segmentation fault] in qemu arm ubuntu disk image based compile

linux - "make install"- 更改所有构建的输出目标

c - 如果从 shell 脚本调用,则使文件环境变量不生效

java - AndroidManifest 虽然存在,但丢失了

linux - 在 Linux/Ubuntu 上安装 boost

c++ - 如何使用 Make 以相同的方式编译多种文件类型

linux - 按顺序用命令运行makefile

parallel-processing - 如何强制某组目标始终按顺序运行?