Search notes:

gcc -MM

Show dependencies of compilation units, excluding system header files. The printed output of dependencies is suitable to be copy-pasted into a Makefile.
In order to include system header files, use gcc -M.

Demonstration - Source files

The output of gcc -MM is demonstrated with the following three trivial compilation units and corresponding header files:
main.c:
#include "hello-world.h"

int main() {

  hello_world();

}
Github repository about-gcc, path: /options/MM/main.c
hello-world.c:
#include "hello-world.h"

void hello_world() {
  print_line("Hello world");
}
Github repository about-gcc, path: /options/MM/hello-world.c
hello-world.h:
#ifndef HELLO_WORLD
#define HELLO_WORLD

#include "print-line.h"

void hello_world();

#endif
Github repository about-gcc, path: /options/MM/hello-world.h
print-line.c:
#include "print-line.h"

void print_line(const char* line) {
  printf("%s\n", line);
}
Github repository about-gcc, path: /options/MM/print-line.c
print-line.h:
#ifndef PRINT_LINE_H
#define PRINT_LINE_H

#include <stdio.h>

void print_line(const char* line);

#endif
Github repository about-gcc, path: /options/MM/print-line.h

Demonstration - output

gcc -MM main.c prints
main.o: main.c hello-world.h print-line.h
gcc -MM hello-world.c prints
hello-world.o: hello-world.c hello-world.h print-line.h
gcc -MM print-line.c prints
print-line.o: print-line.c print-line.h

See also

GCC options

Index