title: scons: How to deal with dynamic targets?
body: <p>I'm trying to automate my work of converting <code>PDF</code> to <code>png</code> file with <code>scons</code>. The tool used for my conversion is <code>convert</code> from <code>ImageMagick</code>.</p>
  
  <p>Here's the raw command line:</p>
  
  <ol>
  <li><code>convert input.pdf temp/temp.png</code></li>
  <li><code>convert temp/*.png -append output.png</code></li>
  </ol>
  
  <p>The first command will generate one PNG file for each page in PDF file, so the <em>target</em> of the first command is a dynamic file list.</p>
  
  <p>Here's the <code>SConstruct</code> file I'm working on:</p>
  
  <pre><code>convert = Builder(action=[
      Delete("${TARGET.dir}"),
      Mkdir("${TARGET.dir}"),
      "convert $SOURCE $TARGET"])
  combine = Builder(action="convert $SOURCE -append $TARGET")
  
  env = Environment(BUILDERS={"Convert": convert, "Combine": combine})
  
  pdf = env.PDF("input.tex")
  pngs = env.Convert("temp/temp.png", pdf) # I don't know how to specify target in this line
  png = env.Combine('output.png', pngs)
  Default(png)
  </code></pre>
  
  <p>The code <code>pngs = env.Convert("temp/temp.png", pdf)</code> actually is wrong since the target is multiple files that I don't know how many before <code>env.Convert</code> is executed, so the final <code>output.png</code> only contains the first page of the PDF file.</p>
  
  <p>Any hint is appreciated.</p>
  
  <p>UPDATE:</p>
  
  <p>I just found that I can use command <code>convert input.pdf -append output.png</code> to avoid the two-step conversion.</p>
  
  <p>Still I'm curious how to handle the scenario when the intermediate temporary file list is unknown beforehand and requires a dynamic target list.</p>