From: Andre Noll Date: Sat, 16 Jul 2016 20:24:12 +0000 (+0200) Subject: build: Let .d files depend only on .c. X-Git-Tag: v0.6.0~2^2~10 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=9059ae879362cbab03c5c0892143799ca881e47b;p=paraslash.git build: Let .d files depend only on .c. Currently we let each .d file depend on the same set of files as the .o file by having two targets specified as arguments to -MT options in the cc command that creates the .d file: one for the .d file and one for the .o file. This approach runs into problems if header files are removed and the now stale .d file depends on a file which no longer exists. It is enough to let the .d file depend only on the corresponding .c file. In case an included file changes or is removed, the .c file changes as well, so we already know we must build the object file and can update the .d file at the same time, without running cc twice. The -MMD option which is added to the usual cc command instructs the compiler to create both the .d and the .o file in one go. When creating the .o and .d files simultaneously, we don't need a sed command to prepend the directory containing the .lsg.h headers as these files are prerequisites of the object file being created, so they are known to exist when the cc command is executed. --- diff --git a/Makefile.real b/Makefile.real index cb3bcaa3..3192bf1e 100644 --- a/Makefile.real +++ b/Makefile.real @@ -248,14 +248,15 @@ $(object_dir)/compress_filter.o: CFLAGS += -O3 $(object_dir)/%.o: %.c | $(object_dir) @[ -z "$(Q)" ] || echo 'CC $<' - $(Q) $(CC) -c -o $@ $(CPPFLAGS) $(STRICT_CFLAGS) $< + $(Q) $(CC) -c -o $@ -MMD -MF $(dep_dir)/$(*F).d -MT $@ $(CPPFLAGS) \ + $(STRICT_CFLAGS) $< # The compiler outputs dependencies either as foo.h or as some_directory/foo.h, # depending on whether the latter file exists. Since make needs the directory # part we prefix the dependency as appropriate. $(dep_dir)/%.d: %.c | $(dep_dir) @[ -z "$(Q)" ] || echo 'DEP $<' - $(Q) $(CC) $(CPPFLAGS) -MM -MG -MT $@ -MT $(object_dir)/$(*F).o $< \ + $(Q) $(CC) $(CPPFLAGS) -MM -MG -MT $(object_dir)/$(*F).o $< \ | sed -e "s@ \([a-zA-Z0-9_]\{1,\}.lsg.h\)@ $(lls_suite_dir)/\1@g" > $@ para_recv para_afh para_play para_server: LDFLAGS += $(id3tag_ldflags)