Introduction
This text is written for those developers, who can write or update Makefile for GNU Make by bare hands. Ok. Ok! You can use the vi or ed editors to make your changes in terminal, but you should be able to know how to read and understand makefiles without direct internet connection. :-)
Background
From time to time in my work, I need to support some not so small software parts, even if they are written by someone else. Everybody is lazy even if they don't agree with this. So am I. And I'm trying to avoid the situation when source file a.cpp includes header file a.hpp, which also includes file utils.hpp, which in turn includes b.hpp, which in addition includes utils.hpp and so on and so forth. But it happens again and again. And if you don't manage this at the beginning of the project, you will have a makefile with object file after the build removal, because you are not strong enough to provide dependencies with such accuracy.
N.B. Netbeans IDE and Eclipse IDE are great toolsets for rapid application development, but makefiles generate by these toolsets not suitable for all cases.
Using the Code
So I've got a Python script which can generate dependency section for makefile.
Minimal command line of this script should look like this:
python cpp_depends.py -I . *.cpp
If you want to know more about available script options, just run it with -h
argument, or take a look inside.
Remember wildcards in Windows works slightly differently than in Linux.
Points of Interest
This is not the first Python script I wrote, but it helped me to understand how to deal with string
s in Python.
History
Current revision was tested against Python 3.4 (Windows) and Python 2.7 (Linux).
The latest revision of the Python script was compressed and attached to this tip.