Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"make clean" doesn't clean dependencies with Automake?

I have a C++ project which uses Autoconf and Automake. I decided that there are too many source files in my src directory, and moved some files to a subdirectory. Then, I modified the Makefile.am and changed these files from source.cpp to subdir/source.cpp. I knew this approach should work, as I did this before for some new files (but then I didn't rename anything). Now I ran the following, as usual:

autoreconf
./configure
make clean
make

I got an error message of something like this:

No rule to make target "source.cpp" needed for "source.o"

I didn't understand what went wrong. I checked my Makefile, but it seemed to be right. So I cloned my git repository to a new place, and tried a make there, and it worked. No problem, thought I, and did a git clean -xf on my original directory. After this, compilation still didn't work. Now I did a diff on the two directory stuctures (after another git clean -xf, and found that there remained a .deps directory. After deleting that, it compiled.

The moral of the story is the following:

  • make clean doesn't delete dependencies.
  • git clean -xf doesn't delete dependencies (probably because of the hidden directory).

Is there any way to make make clean (or possibly git clean) remove this directory automatically? Sure I can do it manually, but it is very annoying that there are dependency files left after a clean.

like image 884
petersohn Avatar asked Jul 07 '12 20:07

petersohn


People also ask

Is make Clean necessary?

Why Is the Command Necessary? The make clean command allows you to get rid of objects and executable files. The compiler, at times, will compile or link files incorrectly, which may cause issues. The only way to have a new start is by removing all the objects and the executable files.

What does make clean all do?

It allows you to type 'make clean' at the command line to get rid of your object and executable files. Sometimes the compiler will link or compile files incorrectly and the only way to get a fresh start is to remove all the object and executable files.

How automake works?

Automake works by reading a Makefile.am and generating a Makefile.in . Certain variables and targets defined in the Makefile.am instruct Automake to generate more specialized code; for instance, a bin_PROGRAMS variable definition will cause targets for compiling and linking programs to be generated.

What is an automake file?

Automake is a tool for automatically generating Makefile.in s from files called Makefile.am . Each Makefile.am is basically a series of make variable definitions1, with rules being thrown in occasionally. The generated Makefile.in s are compliant with the GNU Makefile standards.


2 Answers

Is there any way to make make clean (or possibly git clean) remove this directory automatically?

Use make distclean instead of make clean which will remove .deps.

like image 106
ldav1s Avatar answered Nov 10 '22 01:11

ldav1s


make clean just does whatever the clean target in your makefile is. If you want to remove the .deps directory, add

clean::
        rm -rf .deps

to the Makefile.

If you want git clean to do this for you, just add the -d flag: git clean -fxd will also clean out untracked subdirectories.

like image 39
Chris Dodd Avatar answered Nov 10 '22 01:11

Chris Dodd