Your first rule:
default: *.s
echo $(basename $<)
works as you expect because *
is a wildcard character in GNU Make.
On the other hand, your second rule:
default: %.s
echo $(basename $<)
has %.s
as a prerequisite. Since there is no file named %.s
Make needs an additional rule to generate this missing file %.s
. That is what the error message is about:
make: *** No rule to make target '%.s', needed by 'default'. Stop.
You may think that %
is a wildcard character. Actually, it behaves as such in pattern rules. However, your second rule isn't a pattern rule. The following is an excerpt from the documentation:
A pattern rule looks like an ordinary rule, except that its target contains the character ‘%’ (exactly one of them).
Your second rule's target – i.e., default
– does not contain the character %
. Therefore, it can't be qualified as a pattern rule, so the %
in the prerequisite, %.s
, is literally the %
character.