1

In my makefile:

default: *.s
   echo $(basename $<)

Does echo the basename, but

default: %.s
   echo $(basename $<)

outputs:

make: *** No rule to make target '%.s', needed by 'default'.  Stop.

I have smf.s file in directory, where the makefile is. So why do not makefile use it as Prerequisite? (only shell-like * does, but % does not), why?

JFMR
  • 23,265
  • 4
  • 52
  • 76
Herdsman
  • 799
  • 1
  • 7
  • 24

1 Answers1

0

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.

JFMR
  • 23,265
  • 4
  • 52
  • 76