Makefile: Difference between revisions

Jump to navigation Jump to search
m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
m (Bot: Replace deprecated source tag with syntaxhighlight)
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
Line 190:
 
Now comes the dependency magic I talked about earlier. Note that this needs GCC 3.3 or newer.
<sourcesyntaxhighlight lang="make">
%.o: %.c Makefile
@$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
</syntaxhighlight>
</source>
Isn't it a beauty? ;-)
 
Line 204:
Of course we also need a rule for generating the test driver executables (and their dependency files):
 
<sourcesyntaxhighlight lang="make">
%_t: %.c Makefile pdclib.a
@$(CC) $(CFLAGS) -MMD -MP -DTEST $< pdclib.a -o $@
</syntaxhighlight>
</source>
 
Here you can see why test driver executables get a ''*_t'' suffix instead of a ''*.t'' extension: The ''-MMD'' option uses the basename (i.e., filename without extension) of the ''compiled'' file as basis for the dependency file. If we would compile the sources into ''abc.o'' and ''abc.t'', the dependency files would both be named ''abc.d'', overwriting each other.
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu