I have couple of cpp and hpp files in directory ./src. I compile all cpp files in one binary file, say ./bin/run. I want to re-compile only if I need i.e it or one of its header was changed.
I, probably, can create Makefile where file will be recompiled if and only if it was changed, but it’s quite uncomfortable because big part of my code is in the headers. (It’s not going to be changed, because the product is header itself and cpp files are tests).
I want to store temporary .o files in ./build
I know about g++ -MM function but I’m not sure how to use it.
I’ll glad to see solutions that use not necessary make but any other system possible if they are easy enough.
UPD
I’ll try to clarify, what’s the problem is:
New cpp’s maybe created, includes may be added or gone, etc. I don’t want to edit my makefile each time.
You mention
g++ -MM, which can do what you’re trying to do:Basically this defines a rule that creates
.dfiles from.cxxfiles. The.dfiles are, in turn, required by theincludestatement, which requires one for each.ofile inALLOBJ.The last line in the dependency rule is the ‘sed magic’ that makes the dependency files regenerate themselves. If you think regular expressions are hacks at best, and evil more often than not, you can use the
-MTflag.