make clean

make clean

by Pejvak Javaheri -
Number of replies: 1

Hi,

I have seen some Makefiles that the clean rule also takes care of everything that is autogenerated including the executable (and I suppose any test outputs?). I noticed not only on the slides but also in assignment 3, the clean rule only removes *.o.

I was wondering if there is a rationale behind this or whether it's simply a matter of style. (Personally, since `git reset --hard` doesn't remove the newly created untracked files, I find it more convenient to have `make` clean everything. Is that okay?)

In reply to Pejvak Javaheri

Re: make clean

by Ramses van Zon -
It's a bit a matter of style and what you want "make clean" to mean. In the slides and example, it means 'get ready for a complete, clean rebuild'. Removing the object files is necessary and sufficient for that (provided every cpp file is first compiled to an object file, which is good practice). If you want it to mean 'clean up the directory', then you can also delete the target executables, and that is fine too. Some Makefiles have a "distclean" or "realclean" target to mean cleaning up all produced artifacts.