gcbenison
gcbenison

Reputation: 11963

Creating files by means of pattern rules

Given this makefile:

foo_*.txt: foo_%.txt:
        echo "Foo number $*" > $@

I was hoping to be able to run, say, "make foo_22.txt" to create a file called "foo_22.txt". Evidently, that is not the case: the result is the error "No rule to make target `foo_22.txt'." If the file foo_22.txt does exist, I can get close to the desired behavior by running "make -B foo_22.txt". How can I get to the desired behavior - namely, being able to run "make foo_22.txt" when the file "foo_22.txt" does not exist, resulting in creation of the file with the expected contents?

Upvotes: 0

Views: 21

Answers (1)

Beta
Beta

Reputation: 99094

foo_%.txt:
    echo "Foo number $*" > $@

Upvotes: 1

Related Questions