0

I have a makefile, called "Makefile", and some target in it like:

file.o: file.c Makefile
      gcc <some flags & options> file.c

What exactly does file.o: file.c Makefile do?

Mike Dannyboy
  • 462
  • 1
  • 4
  • 13

1 Answers1

2

That line describes the dependencies for file.o.

If any file listed after the : (file.c and Makefile in this case) has been modified later than file.o, then file.o is rebuilt according to the command in the following line.

dbush
  • 205,898
  • 23
  • 218
  • 273
  • 1
    I'm kinda curious about this one as I've never seen `Makefile` as a dependency. Is that just listing the makefile itself as a dependent of `file.o` so that if it is modified at all since the last make command it will remake `file.o`? – Taelsin Feb 19 '16 at 19:18
  • @Taelsin That is correct. From what I've seen it's not that common, although it makes sense that a change to the makefile can potentially affect all the files it is instructed to build. – dbush Feb 19 '16 at 19:20
  • Thank you very much for answer, and thank you @Taelsin for further clarification. – Mike Dannyboy Feb 19 '16 at 19:45