I\'m using GCC to generate a dependency file, but my build rules put the output into a subdirectory. Is there a way to tell GCC to put my subdirectory prefix in the dependency f
You may like this briefer version of Don McCaughey's answer:
SRCS = \
main.c \
foo.c \
stuff/bar.c
DEPS = $(SRCS:.c=.d)
Add -include $(DEPS)
note the -
prefix, which silences errors if the .d
files don't yet exist.
There's no need for a separate pattern rule to generate the dependency files. Simply add -MD
or -MMD
to your normal compilation line, and the .d
files get generated at the same time your source files are compiled. For example:
%.o: %.c
gcc $(INCLUDE) -MMD -c $< -o $@
# -MD can be used to generate a dependency output file as a side-effect of the compilation process.