display | more...
The traditional makefile target for cleaning up various files, particularly object files from the build. Normally you want to keep them around; the whole point of make is that it only rebuilds the object files that need to be rebuilt. But sometimes you want to get rid of all the by-products, so you add a clean target to your makefile. A simple clean target could look something like this:
        /bin/rm -f $(OBJS)
# The previous line MUST start with a TAB!
Here it's assumed variable(OBJS) holds the names of all the object files in the project.

Two common uses for make clean:

  1. A build is just "make clean; make all".
  2. Since make only looks at modification times of files, if you want to change the compilation flags you have to force all targets to be rebuilt; "make clean; make CFLAGS=-g" is a good way to do this.

Log in or register to write something here or to contact authors.