Makefile subdirectory help - controlling where objects are placed
<p>I have a quick question about a makefile I have.  I have done some searching, but everyone's makefiles are <em>so</em> different that it's hard to follow along unless you really know the make system well, which I really don't.</p>

<p>So, it is enforced upon me that my makefile be called like:</p>

<pre><code>make -f /path/to/src/Makefile "SRCPATH=/path/to/src"
</code></pre>

<p>This is so (ideally) all the objects from different makefiles end up in the same place, as this is run from a directory like <code>/some/path/Objects_C</code></p>

<p>My directory structure looks like this:</p>

<pre><code>src/
  Makefile
  src1.cpp
  src2.cpp
  src3.cpp

src/src_subdir
  subsrc1.cpp
  subsrc2.cpp
  subsrc3.cpp
</code></pre>

<p>I cannot have two makefiles due to the dependencies, and in context, it makes much more sense not to.</p>

<p>Anyway, my makefile is rather simple, it looks like:</p>

<pre><code>SRCPATH ?= .

INCLUDES = -I$.......(all my include paths)

vpath % $(SRCPATH)

CPPFLAGS = -g $(INCLUDES)

    OBJS = src1.o \
       src2.o \
       src3.o \
       $(SRCPATH)/src_subdir/subsrc1.o \
       $(SRCPATH)/src_subdir/subsrc2.o \
       $(SRCPATH)/src_subdir/subsrc3.o

.PHONY : clean all

# ====================================================

libname.a : $(OBJS)
ld -r $(OBJS) -o $@

# ====================================================
</code></pre>

<p>Now, I get <strong>half</strong> of what I want...top level <code>src1.o</code>, <code>src2.o</code>, and <code>src3.o</code> appear where I want (where make was run from, the Objects_C directory), but the <code>subsrc.o</code> files are located in <code>/path/to/src/src_subdir</code>.  Am I missing something simple, or am I totally spun around?</p>

<p>I really appreciate any help! Every time I feel like I can do the basics with make, it makes me feel like a beginner again.</p>