Makefiles -- .c and .h
Len Reed
lbr at holos0.uucp
Sat Nov 17 03:46:14 AEST 1990
In article <9011151442.AA02010 at decpa.pa.dec.com> ellis at ultra.dec.com (David Ellis 15-Nov-1990 0915) writes:
=Consider a Makefile for an executable built from a large number of .o files,
=each separately compiled from a .c file.
=
=If we use a single .c.o rule for compiling all the source files, then it
=seems that a change in a .h file that is #include'd in a .c file will
=not be picked up by Make to automatically force recompilation of the .c file.
=
=One workaround is to replace the single .c.o rule with a collection of rules,
=one for each .o file, listing the dependencies on the .h files #include'd in
=the corresponding .c file. But this is a lot of writing, and if we change
=the "#include" lines in any .c file, we have to update the Makefile with the
=corresponding change.
=
=Is there a simpler way?
You don't want a separate rule for each C file, just a separate dependency
line. Like this:
MOST = this.h that.h more.h another.h etc.h
one.o : $(MOST) header_a.h header_b.h
two.o : $(MOST) header_c.h
three.o : $(MOST)
.c.o :
$(CC) $(CFLAGS) $<
The MOST macro is used to group headers that most C files include. You only
have one rule. Note that x.o depends implicitly upon x.c for all x. In
this example the rule is superfluous, since it's just the default.
Now, what about those dependency lines? There are dependency
checkers out there, and for complicated projects using one is far better
than trying to maintain these by hand.
--
Len Reed
Holos Software, Inc.
Voice: (404) 496-1358
UUCP: ...!gatech!holos0!lbr
More information about the Comp.unix.programmer
mailing list