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

Trying to form my own answer based on some research. I think the approximate order of severity is; mostlyclean, clean, maintainer-clean, mrproper, distclean and finally clobber (which is combined distclean and uninstall).

make clean

make clean is the most basic level. It cleans up most generated files but not anything that records configuration. GNU Make Manual’s Goals page states:

Delete all files that are normally created by running make.

Further, the GNU Make Manual’s Standard Targets page stages:

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

make mostlyclean is the only gentler form of clean I have found, it behaves like clean but leaves behind files that would take a long time to compile and do not often need to be regenerated.

The GNU Make Manual’s Standard Targets page stages:

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.

make distclean

make distclean is the first step up from the basic make clean on many GNU Make systems. It seems to be pseudonymous or at least very similar to with make realclean and make clobber in many, but not all cases. It will delete everything that make clean does and remove the configuration.

In the Linux system this is one step beyond make mrpropper, see the section below for details.

I am not sure if the name implies that things are being made clean enough for distribution (the forming of a tar archive) or that the process is returning them to the state equal to what was distributed (just as things were immediately after unpacking a tar archive).

GNU Make Manual’s Goals page states:

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.

Further, the GNU Make Manual’s Standard Targets page stages:

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 uninstall will uninstall software installed via make install or one of the install-* variants. This is similar to part of the behaviour to make clobber on some systems but make uninstall should not touch the build area as make clobber will.

The GNU Make Manual’s Standard Targets page stages:

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 seems to be one step back from the more common make distclean. It deletes almost everything apart from the configuration. This makes it very similar to make clean.

The GNU Make Manual’s Standard Targets page stages:

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.

It is also highlighted that this is not a commonly used target as it is for a specific set of users:

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

make mrproper

make mrproper seems to be a Linux Kernel version of make distclean or make clobber. that stops short of removing backup and patch files. It does everything that the make clean target does and strips out configuration.

I believe the name comes from a cleaning product known in the USA as Mr. Clean and the UK as Flash (which is why I had not heard of the product as named). Linus Torvalds being Finnish-American was presumably familiar with the Mr. Propper brand name.

The Linux Kernel Makefile states:

# 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

make clobber gets a mention on the Wikipedia article for Clobbering too. That also states that it is more severe than make clean, possibly one that even uninstalls the software. It is possible a combination of make uninstall and make distclean.

There is no single source for make clean levels. As things have evolved over time terminology and behaviour is inconsistent. The above is the best I have managed to piece together so far.

Leave a Comment