Make comes from a time when version control was fairly immature. I understand the need for a streamlined way to clean the workspace back then.

Nowadays any decent version control tool can clean the unversioned files in the workspace. Files which don't need cleaning (cache, downloads, etc.) can be excluded. It is also fast and easy to clone the entire workspace again if required.

I can think of reasons why not to write a clean target: it increases the size of the codebase, it might contain bugs, etc. I would like to know if there are any good reasons to write one nowadays?

  • 2
    A clean also removes temporary (e.g. .o) files which the VC would just leave on its place (given they are in the ignore list). – qwerty_so Nov 21 '16 at 10:05
  • 2
    I'm not sure it's useful to write a makefile at all, nowadays. There are a lot of tools that exist that will generate appropriate makefiles for you, so unless your project is highly unusual I'd suggest using one of those instead. – Jules Nov 21 '16 at 11:32
  • @ThomasKilian, I suppose it depends on the VC, but git handles this for instance (git clean -x). – marcv81 Nov 22 '16 at 7:53

There's certainly some overlap between git clean and make clean. However, they are usually not equivalent. Possible scenarios:

  • The source code is distributed in a tarball, not as a git repo. End users compile the software themselves. Here, there's no version control that could clean the results of a botched build.

  • Invoking the Makefile is only one step in a larger build process. E.g. we might have to create the Makefile first via ./configure or cmake. Those can take some time to run, so we might not want to reconfigure for a clean build. A version-control based clean does not have the required level of granularity.

  • I build and test before I commit. If I were to use a version-control based cleaning mechanism, I might remove my uncommitted work. In contrast, make clean is expected to only delete files that were generated by the build process.

  • With recursive Makefiles, I am able to restrict the clean build to the module I am working on. I don't have to clean the whole project if I don't want to.

I've come to appreciate different levels of clean builds when I did some build engineering for niche hardware that made builds rather slow. The less I could delete and still get a successful build the better. There's a very noticeable difference between waiting half a day or waiting five minutes for my results, especially when there's a deadline looming.

| improve this answer | |
  • Very good points. Especially as my use case is similar to yours (hardware), which I suppose I should have stated in the question. – marcv81 Nov 22 '16 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.