In the following (cut down) make file, the dependencies are at the bottom. This is part of an actual make file that i am writing. In the real case there is a header file dependent on another header.
I haven’t been able to find the answer elsewhere so… would i need to include a line at the bottom under dependencies to the effect of “swap.h: other.h”?
SRC = swap.c other.c etc
OBJ = swap.o other.o etc
EXE = swap
$(EXE): $(OBJ)
$(CC) $(CFLAGS) -o $(EXE) $(OBJ) -lm
## Dependencies
swap.o: swap.h other.h
other.o: other.h
Thanks!
Since there nothing to do for
swap.hifother.hchanges even if the first#includes the seconds, the short answer is no.… But, if some C source includes
swap.hand swap.h includesother.h, a change in other.h will affect /the object needed to be generated from the said C source.Typically, however, you don’t want to maintain your header dependency manually. It is laborious and error prone.
There are several ways for generating these dependencies automatically.
I can recommend the Advanced Auto-Dependency Generation paper. This method is not perfect, but it is as good as you can get with Makefiles.