title: autotools: compiling with code from another directory
body: <p>I have the following structure:</p>
  
  <pre><code>+Makefile.am
  +-common
  | +-common.c
  | +-common.h
  |
  +-module1
  | +module1.c
  | +Makefile.am
  |
  +-module2
  | +module2.c
  | +Makefile.am
  </code></pre>
  
  <p>where each moduleX is actually made of many C and header files, and therefore deserve their own subdirectory. </p>
  
  <p>I want to compile each moduleX with the common.c code. I mean compile, not just link with a library because each module actually defines some macro that influence the compilation of common.c.
  In other words the Makefile of each module looks like:</p>
  
  <pre><code>check_PROGRAMS = moduleX
  moduleX_CFLAGS = -I$(top_srcdir)/common -DCOMMON_OPTION_X
  moduleX_SOURCES = moduleX.c ../common/common.c
  </code></pre>
  
  <p>The reason why I am writting <code>../common/common.c</code> and not <code>$(top_srcdir)/common/common.c</code> is <a href="http://lists.gnu.org/archive/html/bug-automake/2004-01/msg00044.html" rel="nofollow noreferrer">this bug</a>, (also shown <a href="https://stackoverflow.com/questions/21609580/autotools-build-fails-due-to-subdir-objects-option-in-am-init-automake">here</a>). </p>
  
  <p>The top Makefile.am declares, of course, each module as subdir:</p>
  
  <pre><code>SUBDIRS = foo bar
  TESTS = foo/foo bar/bar
  </code></pre>
  
  <p>On the real project <code>./configure &amp;&amp; ./make distcheck</code> fails with a "XXX.Po file not found" when building for distcheck.</p>
  
  <p>I have tried to reproduce the problem in a much simpler scale (<a href="https://drive.google.com/file/d/0B7uJnHnw-ETNSGt3S0JDaHpFTEU/view?usp=sharing" rel="nofollow noreferrer">download this tar file</a>), and there, it fails on "common.h" not being found.</p>
  
  <p>I guess that in both cases, the problem is that I haven't succeeded to tell automake that the common part should be a part of each module (and therefore copied as well when building out of tree (VPATH))</p>
  
  <p>What is the proper way to achieve this?</p>
  
  <p>You are welcome to point out the modification needed to the tared example which you can untar with <code>tar -xvf</code> (see the README inside for build instructions)</p>
  
  <p>Thanks!</p>