Chapter 5. Adding an external dependency

Suppose you change your Makefile. For example you add -O2 to the CFLAGS variable, because finally it's release time. Of course all object files have to be regenerated. The classical way to do that is

make clean
make

But isn't it easier to let all .o files depend on the Makefile itself? So that once you touch the makefile, all objects are immediatly out of date and thus regenerated. That's what the --extraremakedep= option is for.

Example 5-1. Adding an extra dependency to all targets

.depend:
	fastdep --extraremakedep=Makefile \
			  --remakedeptarget=.depend $(SOURCES) > .depend

-include .depend

Here is a possible result

file1.o: file1.cc \
	header1.h \
	header2.h \
	header3.h
file2.o: file2.cc \
	header1.h \
	header3.h \
	header4.h \
.depend: \
	file1.cc \
	header1.h \
	header2.h \
	header3.h \
	file2.cc \
	header4.h \
	Makefile