Why both `make clean` and `make mrproper` are used?

25,876

Solution 1

Cleaning is done on three levels, as described in a comment in the 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

According to the Makefile, the mrproper target depends on the clean target (see line 1421). Additionally, the distclean target depends on mrproper.

Executing make mrproper will therefore be enough as it would also remove the same things as what the clean target would do (and more).

The mrproper target was added in 1993 (Linux 0.97.7) and has always depended on the clean target. This means that it was never necessary to use both targets as in make clean && make mrproper.

Historic reference: https://archive.org/details/git-history-of-linux

Solution 2

clean is a prerequisite for mrproper target in Makefile, so executing make clean separately is redundant.

Solution 3

In that particular instruction (make clean && make mrproper) yes, it's pointless (it's like saying remove all squares, then remove all squares and all triangles)...but make clean is normally much more useful than make mrproper (because the last thing you want, with the vast majority of kernel builds, is to trash your .config)... so perhaps someone wrote the instruction that way purely as a helpful reminder of the difference (i.e. to remind you that the second part was going to trash your .config, so back it up now, if you're used to running make clean and then being able to build as usual).

Share:
25,876

Related videos on Youtube

sitilge
Author by

sitilge

Updated on September 18, 2022

Comments

  • sitilge
    sitilge over 1 year

    It is written in the linux kernel Makefile that

    clean - Remove most generated files but keep the config and
            enough build support to build external modules
    mrproper - Remove all generated files + config + various backup files
    

    And it is stated on the arch docs that

    To finalise the preparation, ensure that the kernel tree is absolutely clean;

    $ make clean && make mrproper

    So if make mrproper does a more thorough remove, why is the make clean used?

  • sitilge
    sitilge over 6 years
    @derobert wow, great. So make clean is redundant, right?
  • derobert
    derobert over 6 years
    @sitilge yes, it's redundant, as make will run it anyway when you run make mrproper.