]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Makefile: Fix compilation after header removal, try #2.
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 14 Mar 2022 21:28:27 +0000 (22:28 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 3 Oct 2022 20:42:13 +0000 (22:42 +0200)
This is a revised version of 3bc858ee0d9b, which got reverted in
f0b8296a0635 because of a flaw related to how CPPFLAGS was handled.

When switching from an older git version which still contains some
header file to a newer version where it got removed, a .d file remains
in build/deps which lists the no longer existing header file as a
prerequisite. This causes the build to fail because the prerequisite
cannot be created. The problem can be worked around by removing the
stale .d file, for example by running make clean, but this is no real
fix, and is inefficient.

The root of the matter is that .d files depend on their .c counterpart,
but this dependency is not stated anywhere in the Makefile. Thus, we
need a rule for the .d target with the same prerequisites and the same
recipe as the object file target. GNU make supports multiple targets,
but the feature does not seem to work as advertised, regardless of
whether rules with independent targets or rules with grouped targets
(using the &: separator) are employed. Thus we bite the bullet and
use two separate rules.

Another issue is that the CC command refers to CFLAGS and CPPFLAGS,
which get modified according to the target. We currently do this
modification only for object files but not for the dependency files,
so this needs to be fixed as well. We make use of make's "call"
function feature to avoid having to duplicate the file names and
patterns.

Makefile.real

index 4dac79f9941f5cee0c2848b53e0312b1233a385d..9c426673233f927d7d324c3cf76b970a0e2c23b2 100644 (file)
@@ -195,73 +195,46 @@ $(man_dir)/para_%.1: $(lls_suite_dir)/%.lsg.man \
 
 $(object_dir)/%.o: %.c | $(object_dir)
 
-$(object_dir)/opus%.o: CPPFLAGS += $(opus_cppflags)
-$(object_dir)/gui.o $(object_dir)/gui%.o \
-: CPPFLAGS += $(curses_cppflags)
-$(object_dir)/spx%.o: CPPFLAGS += $(speex_cppflags)
-$(object_dir)/flac%.o: CPPFLAGS += $(flac_cppflags)
-
-$(object_dir)/mp3_afh.o: CPPFLAGS += $(id3tag_cppflags)
-$(object_dir)/openssl.o: CPPFLAGS += $(openssl_cppflags)
-$(object_dir)/gcrypt.o: CPPFLAGS += $(gcrypt_cppflags)
-$(object_dir)/ao_write.o: CPPFLAGS += $(ao_cppflags)
-$(object_dir)/alsa%.o: CPPFLAGS += $(alsa_cppflags)
-
-$(object_dir)/interactive.o \
-: CPPFLAGS += $(readline_cppflags)
-
-$(object_dir)/resample_filter.o \
-: CPPFLAGS += $(samplerate_cppflags)
-
-$(object_dir)/oss_write.o \
-: CPPFLAGS += $(oss_cppflags)
-
-$(object_dir)/ao_write.o \
-: CPPFLAGS += $(ao_cppflags) $(pthread_cppflags)
-
-$(object_dir)/mp3dec_filter.o \
-: CPPFLAGS += $(mad_cppflags)
-
-$(object_dir)/aacdec_filter.o \
-$(object_dir)/aac_afh.o \
-: CPPFLAGS += $(faad_cppflags)
-
-$(object_dir)/ogg_afh.o \
-$(object_dir)/oggdec_filter.o \
-: CPPFLAGS += $(vorbis_cppflags)
-
-$(object_dir)/spx_common.o \
-$(object_dir)/spxdec_filter.o \
-$(object_dir)/spx_afh.o \
-$(object_dir)/oggdec_filter.o \
-$(object_dir)/ogg_afh.o \
-$(object_dir)/ogg_afh_common.o \
-$(object_dir)/opus%.o \
-: CPPFLAGS += $(ogg_cppflags)
-
-$(object_dir)/afs.o \
-$(object_dir)/aft.o \
-$(object_dir)/attribute.o \
-$(object_dir)/blob.o  \
-$(object_dir)/mood.o \
-$(object_dir)/playlist.o \
-$(object_dir)/score.o \
-$(object_dir)/server.o \
-$(object_dir)/vss.o \
-$(object_dir)/command.o \
-$(object_dir)/http_send.o \
-$(object_dir)/dccp_send.o \
-$(object_dir)/udp_send.o \
-$(object_dir)/send_common.o \
-$(object_dir)/mm.o \
-: CPPFLAGS += $(osl_cppflags)
-
-$(object_dir)/compress_filter.o: CFLAGS += -O3
-
-$(object_dir)/%.o: %.c | $(object_dir) $(dep_dir) $(lsg_h) $(yy_h)
+OD = $(addsuffix .d, $(addprefix $(dep_dir)/, $(1))) \
+       $(addsuffix .o, $(addprefix $(object_dir)/, $(1)))
+
+$(call OD, opus%): CPPFLAGS += $(opus_cppflags)
+$(call OD, gui gui%): CPPFLAGS += $(curses_cppflags)
+$(call OD, spx%): CPPFLAGS += $(speex_cppflags)
+$(call OD, flac%): CPPFLAGS += $(flac_cppflags)
+$(call OD, mp3_afh): CPPFLAGS += $(id3tag_cppflags)
+$(call OD, openssl): CPPFLAGS += $(openssl_cppflags)
+$(call OD, gcrypt): CPPFLAGS += $(gcrypt_cppflags)
+$(call OD, ao_write): CPPFLAGS += $(ao_cppflags)
+$(call OD, alsa%): CPPFLAGS += $(alsa_cppflags)
+$(call OD, interactive): CPPFLAGS += $(readline_cppflags)
+$(call OD, resample_filter): CPPFLAGS += $(samplerate_cppflags)
+$(call OD, oss_write): CPPFLAGS += $(oss_cppflags)
+$(call OD, ao_write): CPPFLAGS += $(ao_cppflags) $(pthread_cppflags)
+$(call OD, mp3dec_filter): CPPFLAGS += $(mad_cppflags)
+$(call OD, aacdec_filter aac_afh): CPPFLAGS += $(faad_cppflags)
+$(call OD, ogg_afh oggdec_filter): CPPFLAGS += $(vorbis_cppflags)
+$(call OD, spx_common spxdec_filter spx_afh oggdec_filter ogg_afh \
+       ogg_afh_common opus%): CPPFLAGS += $(ogg_cppflags)
+$(call OD, afs aft attribute blob mood playlist score server vss command \
+       http_send dccp_send udp_send send_common mm.o): \
+       CPPFLAGS += $(osl_cppflags)
+
+$(call OD, compress_filter): CFLAGS += -O3
+
+define CC_CMD
        $(call SAY, CC $<)
-       $(CC) -c -o $@ -MMD -MF $(dep_dir)/$(*F).d -MT $@ $(CPPFLAGS) \
-               $(STRICT_CFLAGS) $(CFLAGS) $<
+       $(CC) -c -o $(object_dir)/$(*F).o -MMD -MF \
+               $(dep_dir)/$(*F).d -MT $(object_dir)/$(*F).o \
+               $(CPPFLAGS) $(STRICT_CFLAGS) $(CFLAGS) $<
+endef
+CC_PREREQUISITES := %.c | $(object_dir) $(dep_dir) $(lsg_h) $(yy_h)
+# These two have the same prerequisites and the same recipe. There should be a
+# better way to write this.
+$(object_dir)/%.o: $(CC_PREREQUISITES)
+       $(CC_CMD)
+$(dep_dir)/%.d: $(CC_PREREQUISITES)
+       $(CC_CMD)
 
 para_recv para_afh para_play para_server: LDFLAGS += $(id3tag_ldflags)
 para_write para_play para_audiod \