petersohn
petersohn

Reputation: 11730

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

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.

Upvotes: 6

Views: 5639

Answers (3)

lmat - Reinstate Monica
lmat - Reinstate Monica

Reputation: 7768

If you're willing to run git clean -xf, you should be willing to run git clean -xfd.

From git help clean:

-d Remove untracted directories in addition to untracted files.

Upvotes: 0

ldav1s
ldav1s

Reputation: 16315

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.

Upvotes: 14

Chris Dodd
Chris Dodd

Reputation: 126328

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.

Upvotes: 1

Related Questions