Autotools: how to cleanup files created by "./configure" in lighttpd project?
Asked Answered
B

2

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?

Butter answered 29/5, 2010 at 18:17 Comment(2)
Did you consider using the tools from your source control software for getting a clean state of your sources?Rape
Well, currently my (virtual) test machine (by the way, Ubuntu 10.04) doesn't use source control.Butter
R
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.

Rape answered 30/5, 2010 at 0:34 Comment(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?Butter
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!Butter
@Andi: using a build directory is very similar to cmake: mkdir build && cd build && $CONF_PATH/.configure && makeRape
@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.Butter
@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/.Rape
@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.Butter
B
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!

Bluhm answered 3/4, 2016 at 13:46 Comment(2)
You can use git clean to remove ignored files: git clean -X.Kostroma
git clean -dnx to dry-run preview what untracked files would be removed. Then git clean -dfX to force the removalDeena

© 2022 - 2024 — McMap. All rights reserved.