37

I'm trying out lighttpd for an embedded Linux project. I got the latest source package and started writing a master Makefile encapsulating all configure, compile, install (for testing) etc stuff.

And vice-versa, I want to cleanup every step. After the cleanup there should be no generated files anymore. This is important for repetitive testing.

I wonder if there is a way to do a complete cleanup of what ./configure generated? I'm not familiar with autotools in details.

Any hints?

fduff
  • 3,671
  • 2
  • 30
  • 39
Andi
  • 888
  • 2
  • 10
  • 24

2 Answers2

41

I personally would really use the features of a source control software (you should use one) for this. This would cleanup make independent of your build process. See e.g. svn-cleanup or git clean.

Nevertheless, automake allows some tweaking when to remove which files. This has (intentionally?) built-in limitations on what files generated by autotools can be remove this way though. Have a look at the definitions for MOSTLYCLEANFILES, CLEANFILES, DISTCLEANFILES, and MAINTAINERCLEANFILES and adjust your Makefile.am's. With them you can remove a lot of stuff with

make mostlyclean
make clean
make distclean
make maintainer-clean

You won't be able to remove e.g. Makefile or .deps/ this way.

As for the reliability of make clean it should "work 100%" if you stick to cleanly specifying your files and stay away from manual intervention. Otherwise extend the cleanup rules.

Benjamin Bannier
  • 55,163
  • 11
  • 60
  • 80
  • Thanks Honk, I will have a look to the suggested parts of the documentation. If make clean works 99% and a few well-known files can be removed manually, this will be ok. Another question arises: is it possible to redirect all generated output to a specified build-directory (like CMake)? This would be helpful for cleanup, and for building for different platforms I guess? – Andi May 30 '10 at 07:50
  • Ok, it looks like that a command like "make mostlyclean clean distclean maintainer-clean" will do the job! One funny effect is that in the lighttpd package 2 source files are modified by the build processs: src/configparser.c and src/mod_ssi_exprparser.c. But only the relatve include pathes. Maybe this files are re-generated by the build process. Thank you, Honk! – Andi May 30 '10 at 15:54
  • 2
    @Andi: using a build directory is very similar to cmake: `mkdir build && cd build && $CONF_PATH/.configure && make` – Benjamin Bannier May 30 '10 at 18:18
  • @Honk: will try this. In the meantime I had a similar idea: create builddir, copy the whole source tree into it and do everything as usual. This doesn't change the modified source files in the original tree. And parallel builds for different platforms doesn't affect each other. – Andi May 30 '10 at 19:31
  • @Andi: Maybe I don't understand your point. In that example I gave `build/` doesn't have to be in the source directory. Also, files in the source directory won't be modified by this. Whatever `Makefile` is created from you `./configure` call has all the information on platform, compiler, ... and will be saved in `build/`. – Benjamin Bannier May 30 '10 at 21:31
  • @Honk: you are right, using build/ works file! I wasn't sure about the changed source files mentioned above, but this files are created inside the build/ directory. Great! with this solution I can realize the clean all by removing the build/ directory. – Andi May 31 '10 at 12:20
4

In addition to Benjamin Bannier's answer, the generated files names may be listed in .gitignore file so that they are ignored, not tracked with git and don't irritate and bother when run git status. You can't remove these files with git clean. In this case I personally use rm -rf * ; git checkout . command.

But don't use that if you have other ignored files which you don't want to be removed!

Community
  • 1
  • 1
konstunn
  • 355
  • 4
  • 17