0

It is advised to use -MM option to manage indirect dependencies in headers. Why we don't use touch command. Am I missing anything here, or just it's because it's a hack and we want to keep the real last modification of timestamp (look like intrusive method).

Example: - stack.h, stack.c, array.h, array.c array depend on stack

array.o: array.c

array.c: array.h

stack.o: stack.c

stack.c: stack.h

stack.h: array.h
    touch stack.h

Another thing: files need to be entirely reparsed each time with -MM option, right ? And not with this touch method and be an advantage if I don't miss anything, no ?

rafoo
  • 1,506
  • 10
  • 17
  • 2
    Yes, `touch` is a horrible hack that I (for one) would never use, but afaik it'd work, if you don't care about preserving modtimes. (It's a hack because it subverts the philosophy of `make`: header files *don't* depend on each other in the way that object files depend on source files.) – Steve Summit Oct 21 '19 at 23:00

1 Answers1

1

You can use touch. But it's painful for anything but relatively trivial environments, because you have to ensure that your header file include dependencies are accurately reflected in the makefile otherwise you can get build failures or worse, mysterious crashes.

Regarding files need to be entirely reparsed each time, you should look into the modern auto-dependency generation methods. These do the dependency generation as a side-effect of the compilation, so it doesn't cost anything extra.

MadScientist
  • 92,819
  • 9
  • 109
  • 136