Stem variable "$*" expands to nonempty string in non-pattern rules

Pip Cet <[email protected]>
Newsgroups gmane.comp.gnu.make.bugs
Message-ID <[email protected]>
This Makefile:

-------------------------
%.o: %.c
        gcc -c $< -o $@

foo.o: foo.c
        echo "stem is $*"
-------------------------

results in "make foo.o" producing the output "stem is foo". The same is
true if I omit the first two lines, but not if I run "make -r foo.o"
with just the second rule.

This seems like a bug to me: the correct output is "stem is ".

Note that GCC relies on this behavior:

https://forge.sourceware.org/gcc/gcc/src/commit/c8545a3143330983e51d913f0a01187258b14510/libgcc/static-object.mk#L30

points to this code:

----------------------------
$(base)$(objext): $o $(base).vis
	$(gcc_compile) -c $(as_flags-$<) -include $*.vis $<
----------------------------

This means GCC cannot currently be built with "make -r" on some
machines. It doesn't actually use the built-in rules, it only relies on
them to determine what the stem would be according to the rule if it
were to be used.

This seems like a GCC bug to me.

My apologies if this has been reported before; a brief search didn't
produce any relevant results, the make documentation doesn't mention
this behavior, and the make source code looks like this was originally
an accident.

If this isn't a bug, or a bug we cannot fix at this point because too
much code out there might rely on it, maybe the documentation could
mention it.

Pip
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.