make
not a utility that goes and reads inside your C file and determines which header it includes. It works based on modified temporary files. Therefore, regardless of whether the target depends on the header or any other file, you need to explicitly specify make
dependencies.
gcc
can help you make your work easier by creating a dependency list for you
main.c
#include<stdio.h> #include"my_header.h" int main () { return 0; }
And then,
gcc -M main.c
Now, with the -M
preprocessor flag, it will automatically generate a list of dependencies, for example
main.o: main.c /usr/include/stdio.h /usr/include/features.h \ /usr/include/bits/predefs.h /usr/include/sys/cdefs.h \ /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \ /usr/include/gnu/stubs-64.h \ /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/include/stddef.h \ /usr/include/bits/types.h /usr/include/bits/typesizes.h \ /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/include/stdarg.h \ /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ my_header.h
gcc
found out that everything included inside stdio.h
too!
source share