FreeBSD and NetBSD ship an m4 version which does not understand
the --debug=i option which we use to generate the .m4d dependency
files. This results in empty dependency files on those systems.
This was broken since m4 dependencies were introduced two years ago
in commit
e249d105 (Generate ggo dependencies automatically). The
bug went unnoticed for so long because the problematic m4 command
is the first command of a pipeline (hence the exit code is lost),
and because the command redirects stderr, so the error message is
not printed to the terminal.
This commit fixes the bug by using the (portable) -s option of
m4 rather than --debug. The -s option outputs line synchronization
directives which include the file name, so it is equally well suited
for generating the dependency files.
$(m4depdir)/%.m4d: $(m4_ggo_dir)/%.m4 | $(m4depdir)
@[ -z "$(Q)" ] || echo 'M4D $<'
- $(Q) m4 -I $(m4_ggo_dir) --debug=i $< 3>&1 1>/dev/null 2>&3 \
- | awk '{if ($$0 ~ "^m4debug: input read from ") \
- print "$(ggo_dir)/$(*F).ggo: " $$NF}' > $@
+ $(Q) m4 -I $(m4_ggo_dir) -s $< \
+ | awk '{if ($$1 ~ /#line/) {gsub(/"/, "", $$3); if ($$3 != "$<") \
+ print "$(ggo_dir)/$(*F).ggo: " $$3}}' | sort | uniq > $@
$(ggo_dir)/%.ggo: $(m4_ggo_dir)/%.m4 $(m4_ggo_dir)/header.m4 | $(ggo_dir)
@[ -z "$(Q)" ] || echo 'M4 $<'