title: Makefile for pandoc with references file
body: <p>I'm trying to write a Makefile for pandoc. I want to be able to type <code>make filename.ext</code> and the Makefile will automatically compile from <code>filename.txt</code> to <code>filename.ext</code>. The filename could be anything named .txt. This part is easy. e.g. I have a set of rules like:</p>
  
  <pre><code>%.pdf: %.txt
      pandoc -s --smart -f markdown -o $@ $&lt;
  
  %.html: %.txt
      pandoc -s --smart --bibliography $(bib) -f markdown -t html --standalone -o $@ $&lt;
  
  %.docx: %.txt
      pandoc -s --smart --bibliography references.bib -f markdown -t docx -o $@ $&lt;
  
  %.tex: %.txt
      pandoc -s --smart --bibliography references.bib -o $@ $&lt;
  </code></pre>
  
  <p>However, I also want to add citations from the same file called <code>filename.bib</code>. So, if I type <code>make fudge.pdf</code>, pandoc will convert fudge.txt to fudge.pdf while incorporating bibtex citations from fudge.bib. How do I do this? The command line is something like</p>
  
  <pre><code>pandoc -s --smart --bibliography filename.bib -f markdown -o $@ $&lt;
  </code></pre>
  
  <p>... but I can't figure out how to get fudge.bib from fudge.txt without doing something like this: </p>
  
  <pre><code>pandoc -s --smart --bibliography $(subst .txt,.bib,$&lt;) -f markdown -o $@ $&lt;
  </code></pre>
  
  <p>This will work, but a) I want to do some preprocessing on the file *.bib first (namely generating it and adding missing references) and b) need that macro on every line. Is there anything more elegant?</p>