How to create a list of non-transitive dependencies (GCC)

Is there a way to generate dependencies of the C (++) source file, similar to using the -MM GCC option, which includes only the direct dependencies of the specified file, that is, only the files directly included in this source file?

More context on why I am looking for this functionality - maybe I have a completely different solution: I have a general make file with automatic detection of dependencies that satisfy my needs but are slow. The basic structure is as follows:

  • Complete main.cpp dependencies are retrieved using gcc -MM
  • All * .h dependencies for which there is an associated * .cpp change to * .o dependencies
  • changed dependencies are included in the makefile
  • All * .o targets are built, dependencies are retrieved using gcc -MM and enabled
  • All * .o goals are related to creating an executable file

So far, this makefile has worked fine, but as mentioned earlier, it is slow. I analyzed its execution path for one project and included all the created dependencies manually in order to try to optimize its speed. The result was the removal of all transitive dependencies, the makefile retained its functionality, but became much faster (also reflected in the number of lines of the debug output of make -d).

+3
source share
1 answer

, , , . .h, .cpp , , *.o . classic -MM cpp, . automake , , : -).

, -H gcc . stderr, . . ,

cpp -I $< >/dev/null | sed -n -e 's/^\. //p'

. Caveat: , , . , , 1 1.h .cpp.

0

Source: https://habr.com/ru/post/1796617/


All Articles