Of course, the proper way to write a Makefile is to actually document which targets depend on which sources. In the trivial case, the proposed solution will make foo
depend on itself, but of course, make
is smart enough to drop a circular dependency. But if you add a temporary file to your directory, it will "magically" become part of the dependency chain. Better to create an explicit list of dependencies once and for all, perhaps via a script.
GNU make knows how to run gcc
to produce an executable out of a set of .c
and .h
files, so maybe all you really need amounts to
foo: $(wildcard *.h) $(wildcard *.c)