Closed trygvis closed 6 years ago
Interesting idea. But may be difficult to fully implement. It will be pretty easy to track all the included or imported files. But some dependencies may be used by calling scripts and pp does not parse the scripts it run. pp can also generate files (e.g. with a script) and include them later. Or include the result of a script.
Here is what pp could do:
Other dependencies will be explicitly given by the user.
pp doesn't know the name of the output, it can not exactly generate Makefile syntax. It may only generate the list of dependencies.
I don't know if it's better to generate the output or not with -M. There may be side effects that should not be made twice. One solution would be to use -M to generate the dependencies in a file and the output to stdout at once (dependencies can not be added if no already known dependency is modified).
In a Makefile you would to a non-required include with -include foo.d
, then have a dependency on foo.d
that would be generated on the first run by a dependency on foo.c
from foo.d
.
I think it would make sense for pp to track recursively all files consumed, shells scripts would be nice to track, but I could live without it and specify them by hand in my build system. I also think it makes sense to not execute the build, but just analyze dependencies and output those. That would match how -M is done with GCC.
I have implemented the -M option. It tracks files that are imported, included, referenced by the mdate and csv macros. Scripts are not taken into account.
I propose to close this issue. Tracking dependencies in external script seems to be very ambiguous (what's the difference between dependancies and standard external tools, what if some "dependencies" need compilation from other sources, ...). So -M only tracks files that are imported, included and referenced in some macros (currently mdate and csv).
GCC has a -M option that changes the output to be a Makefile snippet that lists all file dependencies of the source files instead of compiling it. This is useful for generating Makefiles and integration with other tools.