The GNU Makefile Standards specify a number of different clean rules. See Standard Targets for Users in The GNU Coding Standards.
Generally the files that can be cleaned are determined automatically by
Automake. Of course, Automake also recognizes some variables that can
be defined to specify additional files to clean. These variables are
When cleaning involves more than deleting some hard-coded list of
files, it is also possible to supplement the cleaning rules with your
own commands. Simply define a rule for any of the
maintainer-clean-local targets (see Extending). A common
case is deleting a directory, for instance, a directory created by the
clean-local: -rm -rf testSubDir
make allows only one set of rules for a given target,
a more extensible way of writing this is to use a separate target
listed as a dependency:
clean-local: clean-local-check .PHONY: clean-local-check clean-local-check: -rm -rf testSubDir
We recommend that you follow the following set of heuristics in your Makefile.am to decide which files should be removed by which rule:
makebuilt it, and it is commonly something that one would want to rebuild (for instance, a .o file), then
mostlycleanshould delete it.
makebuilt it, then
cleanshould delete it.
configurebuilt it, then
distcleanshould delete it.
maintainer-cleanshould delete it. However
maintainer-cleanshould not delete anything that needs to exist in order to run ‘./configure && make’.