Greg Nisbet
Greg Nisbet

Reputation: 6994

GNU Make pattern rule depending on non-pattern file

In GNU Make, what exactly are the semantics of a pattern rule that depends on a non-pattern file?

I have the following snippet in a Makefile. When foo.a exists, GNU Make doesn't seem to create foo.b when make foo.b is called.

.SUFFIXES:

%.b: move_a_to_b.artifact

move_a_to_b.artifact:
        mv foo.a foo.b
        touch move_a_to_b.artifact

The following, however, works fine and moves the file from foo.a to foo.b.

.SUFFXIES:

%.b: %.a
        mv $< $@

As does this, with a pattern rule depending on a pattern rule

.SUFFIXES:

%.b: %.intermediate
        mv $< $@

%.intermediate: %.a
        mv $< $@

Upvotes: 2

Views: 138

Answers (1)

MadScientist
MadScientist

Reputation: 101081

It doesn't have anything to do with pattern rules depending on non-patterns. That's fine and it has the expected semantics: for any file ending in .b if it's out of date with respect to the file move_a_to_b.artifact then the recipe will be run.

Your issue is that you're not defining a pattern rule, you're deleting a pattern rule. A pattern rule must always have a recipe. A pattern rule without a recipe deletes the pattern rule. See Canceling Pattern Rules.

You have to add a recipe, then it will do something:

%.b : move_a_to_b.artifact
        @echo do something to create $@

Upvotes: 4

Related Questions