title: How to use gzip correctly in a makefile?
body: <p>I'm a <code>make</code> newbie, so feel free to correct my syntax for this question.</p>
  
  <p>I want to create a makefile that downloads a bunch of compressed files, uncompresses them and does something with them. Here's my toy example:</p>
  
  <pre><code>my_dir/*.txt.gz:
      echo "# obtaining data"
      mkdir -p my_dir
      echo 1 &gt; my_dir/file1.txt
      gzip my_dir/file1.txt
      echo 2 &gt; my_dir/file2.txt
      gzip my_dir/file2.txt
  
  my_dir/*.txt: my_dir/*.txt.gz
      echo "# unzipping data"
      parallel gzip -d ::: my_dir/*.txt.gz
  
  final.txt: my_dir/*.txt
      echo "# doing something with data"
      cat my_dir/*.txt &gt; $@
  
  clean_my_dir:
      rm -rf my_dir
      rm -f final.txt
  </code></pre>
  
  <p>When I run <code>make final.txt</code> I get what I expect (<code>final.txt</code> contains <code>1\n2</code>), but if I run <code>make final.txt</code> again (without running <code>make clean_my_dir</code>) I get an error:</p>
  
  <pre><code>make final.txt
  echo "# obtaining data"
  # obtaining data
  mkdir -p my_dir
  echo 1 &gt; my_dir/file1.txt
  gzip my_dir/file1.txt
  echo 2 &gt; my_dir/file2.txt
  gzip my_dir/file2.txt
  echo "# unzipping data"
  # unzipping data
  parallel gzip -d ::: my_dir/*.txt.gz
  echo "# unzipping data"
  # unzipping data
  parallel gzip -d ::: my_dir/*.txt.gz
  gzip: can't stat: my_dir/*.txt.gz (my_dir/*.txt.gz.gz): No such file or directory
  make: *** [my_dir/file2.txt] Error 1
  </code></pre>
  
  <p>I'm sure I'm making a mistake in the way I set up the targets and the prerequisites: I want <code>final.txt</code> to contain the contents of <code>file1.txt</code> and <code>file2.txt</code>, but these files are initially zipped. How do I tell <code>make</code> to call <code>gzip</code> when there are compressed files and to not do anything when the uncompressed files are available?</p>