Search code examples
gitdependenciesmakefileautomake

"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.


Solution

  • 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.