makefile do same job in a lot of folders
<p>I try to build a static website via <code>make</code>.</p>

<p>I would like to compress all images inside sub-directories of <code>src</code> folder, leaving <code>src</code> untouched, then output compressed images to <code>build</code> folder via <code>make</code>.</p>

<pre><code>src
  + img/
      + thumb/
           + a.jpg
           + x.png
      + big/
           + p.jpg
           + q.jpg
      + ...
build
  + img/
      + thumb/
           + a.jpg
           + x.png
      + big/
           + p.jpg
           + q.jpg
      + ...
</code></pre>

<p>I don't want to write some like this:</p>

<pre><code>build/img/thumb/%: src/img/thumb/%
    mkdir....
    compress $&lt;
build/img/big/%: src/img/big/%
    mkdir....
    compress $&lt;
...
</code></pre>

<p>since all images inside <code>src</code> do same jobs, is there any possible to write more concise code?</p>

<p>something like this:</p>

<pre><code>build/%: src/%
    mkdir....
    compress $&lt;
</code></pre>

<hr>

<h3>update 1</h3>

<pre><code>build/img/%: src/img/%
    mkdir....
    compress $&lt;
</code></pre>

<p>this snippet show error:</p>

<pre><code>make: *** No targets.  Stop.
</code></pre>

<h3>update 2</h3>

<p>after some google, I add <code>all: build/img/*/*.jpg</code>:</p>

<pre><code>all: build/img/*/*.jpg

# this line only specified how to create your targets, but not which.
build/img/%: src/img/%
    jpegoptim --strip-all $&lt;
</code></pre>

<p>this version only dealt one file (first file?)...</p>

<p>ref: <a href="http://makepp.sourceforge.net/1.19/makepp_tutorial.html#Using%20Wildcards" rel="nofollow">wildcard</a></p>

<hr>

<h3>update 3</h3>

<p>I find <code>make</code> would stuck the filename with space...</p>

<p>my version:</p>

<pre><code>$ make -v
GNU Make 4.1
Built for x86_64-pc-msys
</code></pre>