kheyse
kheyse

Reputation: 1919

Give a name to a rule in Makefile

Simply put I want to give a name to a rule in my Makefile:

A.ext : B.ext
    compute A.ext from B.ext

so that I get something like this:

.PHONY : my_rule
A.ext : my_rule
my_rule : B.ext
    compute A.ext from B.ext

But this is not yet equivalent to the first, since my_rule is always executed even if B.ext hasn't changed. How can I achieve equivalence?

This is the trimmed output of make -d:

Considering target file `A.ext'.
  Considering target file `my_rule'.
   File `my_rule' does not exist.
    Considering target file `B.ext'.
     Finished prerequisites of target file `B.ext'.
    No need to remake target `B.ext'.
   Finished prerequisites of target file `my_rule'.
  Must remake target `my_rule'.

(The reason I want this is that I have another rule C.ext :| my_rule.)

Upvotes: 0

Views: 238

Answers (1)

Beta
Beta

Reputation: 99124

.PHONY : my_rule
my_rule: A.ext
A.ext : B.ext
    compute A.ext from B.ext

Or better:

.PHONY : my_rule
my_rule: A.ext
A.ext : B.ext
    compute $@ from $<

Upvotes: 1

Related Questions