6

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.

petersohn
  • 11,292
  • 13
  • 61
  • 98
  • 1
    Running `autoreconf` after editing `Makefile.am`, or removing `AM_MAINTAINER_MODE` from `configure.ac`, might solve your problem. – ptomato Jul 08 '12 at 13:33

3 Answers3

14

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.

ldav1s
  • 15,885
  • 2
  • 53
  • 56
1

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.

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226
  • 1
    The git clean -d solution worked. The one with the Makefile doesn't seem so straightforward to me though. Since I use Automake, I don't think I can just simply redefine rules. Maybe there is a way, but since the dependency files were created by the automatically generated Makefile, I think there should be a way to remove them without hacking. – petersohn Jul 08 '12 at 06:02
0

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.

lmat - Reinstate Monica
  • 7,289
  • 6
  • 48
  • 62