Makefiles: clean a target, make this more user friendly

Would like to get your feeling and positions on the following proposal for a feature request.

Use case:

  • say a repository considered as 1 project
  • many libraries
  • many programs (as a result of combining functionality out of many of those libraries)

From the top of the buil directory for example we can build many of the targets (executables, libraries) and their dependencies. Say we have somewhere library/target “Foo”.
The we can do:

  • make Foo
  • make Foo/fast
  • make clean
    ==>the later cleans the entire project
    Now what if I would want to clean only library/target Foo.
    One way I know on how to do that is cd-ing into the directory in the build tree corresponding to that library, and there I can issues “make clean” which is then restricted to just cleaning the library Foo (it just clean the local library), one can also do at that location “make clean/fast”. I have no idea what the difference is.

Now cd-ing to this location is not that user friendly, but one important thing is, that it is indeed possible to clean just the library.

I would like/propose that we could do the following at the top level of the build directory:

  • make Foo/clean

So kind of mimicking the fast ‘thing’.

So 2 axes to this proposal:

  • ability to clean the library/target from the top
  • syntax proposal “/clean”

What do you think ?

IIRC the Makefile generator’s make clean implementation already hands off most of the work to target-specific scripts. It likely wouldn’t be too hard to expose those on a per-target basis through <target-name>/clean.

Exposing it in the Ninja generator as an alias for ninja -t clean -r target_compile_rule -r target_link_rule would be nice to have as well while we’re at it.

1 Like

You’ll need to add one for each configuration in the multi-config Ninja generator, for example ninja foo/clean:Debug.

1 Like

issue created for this :