38

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?

2
  • 1
    Did you consider using the tools from your source control software for getting a clean state of your sources? May 29, 2010 at 18:24
  • Well, currently my (virtual) test machine (by the way, Ubuntu 10.04) doesn't use source control.
    – Andi
    May 29, 2010 at 20:32

2 Answers 2

42

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.

6
  • 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, 2010 at 7: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, 2010 at 15:54
  • 2
    @Andi: using a build directory is very similar to cmake: mkdir build && cd build && $CONF_PATH/.configure && make May 30, 2010 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, 2010 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/. May 30, 2010 at 21:31
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!

2
  • 10
    You can use git clean to remove ignored files: git clean -X. Jan 13, 2017 at 19:20
  • 6
    git clean -dnx to dry-run preview what untracked files would be removed. Then git clean -dfX to force the removal
    – Josh Peak
    Jan 26, 2019 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.