How to collect all the dependencies on a large Makefile project?

In a large C project, I have a top Makefile and many sub-Make files in different subdirectories. I need to collect all compilation dependencies. To do this, I add -MMD to CFLAGS and get a bunch of .d dependency files .

These .d files are scattered in subdirectories. In addition, dependencies are sometimes recorded as absolute paths, sometimes as paths related to the compilation directory, and sometimes containing symbolic links. I wrote a script that finds all the .d files, traverses their directories and solves all the found paths. It works, but with tens of thousands of dependency files, this collection of dependencies lasts around the same time as compilation! (which is too long to wait :))

Is there a faster way to get all the dependencies in one file? These are ANSI C, GCC and Linux, if that matters. Thanks in advance.

+4
source share
2 answers

-MMD -MM, .

gcc -MM ... file.c >>$(top)/all.d

- ,

gcc -MM ... file.c | sh filter.sh >file.d

.

include (defs.h) , gcc , -I, .

gcc -MM -I$(top)/path/to ... $(top)/path/to/file.c >>$(top)/all.d

gcc -MM -I$(top)/path/to ... $(top)/path/to/file.c | sh filter.sh >file.d

file.o: file.c defs.h

gcc

file.o: /absolute/path/to/file.c /absolute/path/to/defs.h

.

+1

.

, . , .

Makefile ++ .

0

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


All Articles