title: how to place .o files into a separate directory, with Makefile rule
body: <p>I have the following <code>Makefile</code> rules:</p>
  
  <pre><code>DIR = src
  SOURCES = $(shell find $(DIR) -name "*.cpp")
  OBJS := $(SOURCES:.cpp=.o)
  </code></pre>
  
  <p>With this definition all my <code>.o</code> files are located in the same directories (and sub-directories) as their <code>.cpp</code> counterparts. Such allocation principle turns the project directory into a mess very soon (with 50+ files). I would like to make a new specific folder for <code>.o</code> files and place them there. I need to write a make-rule that will convert every <code>.o</code> file name like the following:</p>
  
  <pre><code>foo/bar/test.o —&gt; objects/foo-bar-test.o
  </code></pre>
  
  <p>How can I create such a rule in <code>Makefile</code>? Thanks in advance!</p>