Note that there are some explanatory texts on larger screens.

plurals
  1. POMakefile pattern rule either ignores phony rule or spontaneously deletes output file
    text
    copied!<p>I'm trying to write a makefile to produce several output files for each of several sources, using pattern rules.</p> <p>I have the following <code>Makefile</code> (GNU Make 3.8.1):</p> <pre><code>all : foo.all bar.all %.all : %.pdf %.svg @echo Made $* %.pdf : touch $@ %.svg : touch $@ .PHONY: foo.all bar.all </code></pre> <p>Since <code>*.all</code> do not represent real output files, I tried marking them as <a href="https://stackoverflow.com/questions/2145590/what-is-the-purpose-of-phony-in-a-makefile"><code>.PHONY</code></a>. However, running <code>make</code> then doesn't work:</p> <pre><code>$ ls Makefile $ make make: Nothing to be done for `all'. </code></pre> <p>According to <code>make -d</code>:</p> <pre><code> No implicit rule found for `all'. Considering target file `foo.all'. File `foo.all' does not exist. Finished prerequisites of target file `foo.all'. Must remake target `foo.all'. Successfully remade target file `foo.all'. Considering target file `bar.all'. File `bar.all' does not exist. Finished prerequisites of target file `bar.all'. Must remake target `bar.all'. Successfully remade target file `bar.all'. Finished prerequisites of target file `all'. Must remake target `all'. Successfully remade target file `all'. make: Nothing to be done for `all'. </code></pre> <p>which seems to be pretending to run the <code>%.all</code> rules, but skipping the bodies.</p> <p>But with the <code>.PHONY</code> line commented out, Make runs the targets, but then spontaneously decides to delete the output files:</p> <pre><code>$ make touch foo.pdf touch foo.svg Made foo touch bar.pdf touch bar.svg Made bar rm foo.pdf foo.svg bar.pdf bar.svg </code></pre> <p>According to <code>make -d</code>, it says:</p> <pre><code>Removing intermediate files... </code></pre> <h1>Minimal example</h1> <p>A minimal example giving anomalous behavior:</p> <pre><code>%.all: %.out @echo Made $* %.out: touch $@ </code></pre> <p>I expect running <code>make somefile.all</code> to cause it to create the file <code>somefile.out</code>, but it gets deleted:</p> <pre><code>$ make somefile.all touch somefile.out Made somefile rm somefile.out </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload