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.
I came to the industry at the end of that times when the computer program executes as it was written. I saw a quite big machines, occupied more than 100 square meters for its central processor, but I started my professional activity as a programmer on IBM PC clones. There were different CPU architectures (68k, PowerPC, 386/486, SPARC...) when I began, but Intel defeated them all with Pentium CPU (marketing) family.
I saw the knowledge and technology fragmentation. I saw many technologies started, developed and retired. However, I have not seen many things yet.
I have some experience, but my experience is not perfectly comprehensive. I still have many things to learn and I still cannot make a poker face when I find out some aspects about how the things were designed and works. My experience does not make me an absolute expert in some areas, because these areas are changing. I know some things, but I also understand that some things I know could be useless for nowadays.