title: Automake and external conditional sources
body: <p>How to properly define external conditional sources in a <code>Makefile.am</code> file?</p>
  
  <p>As an example, in GNU MPFR, we currently have in <a href="https://gforge.inria.fr/scm/viewvc.php/mpfr/trunk/src/Makefile.am?revision=13228&amp;view=markup#l95" rel="nofollow noreferrer"><code>src/Makefile.am</code></a>:</p>
  
  <pre><code>if MINI_GMP
  nodist_include_HEADERS += $(mini_gmp_path)/mini-gmp.h
  noinst_LTLIBRARIES = libminigmp.la
  nodist_libminigmp_la_SOURCES = $(mini_gmp_path)/mini-gmp.h $(mini_gmp_path)/mini-gmp.c
  libmpfr_la_LIBADD += libminigmp.la
  endif
  </code></pre>
  
  <p>where <code>MINI_GMP</code> is true when <code>mini_gmp_path</code> is defined. The goal is to optionally build MPFR against a libminigmp library (mini-gmp), which is itself built with the autotools machinery (same compiler, same options, etc. as MPFR).</p>
  
  <p>Everything seems to work well, except when one does not want to build against mini-gmp. In this case, the generated <code>configure</code> script fails with:</p>
  
  <pre><code>configure: creating ./config.status
  config.status: creating Makefile
  config.status: creating mpfr.pc
  config.status: creating doc/Makefile
  config.status: creating src/Makefile
  config.status: creating tests/Makefile
  config.status: creating tune/Makefile
  config.status: creating src/mparam.h
  config.status: creating tools/bench/Makefile
  config.status: executing depfiles commands
  config.status: error: in `/home/vlefevre/software/mpfr':
  config.status: error: Something went wrong bootstrapping makefile fragments
      for automatic dependency tracking.  Try re-running configure with the
      '--disable-dependency-tracking' option to at least be able to build
      the package (albeit without support for automatic dependency tracking).
  See `config.log' for more details
  </code></pre>
  
  <p>and in the <code>config.log</code> file:</p>
  
  <pre><code>config.status:19572: executing depfiles commands
  config.status:19647: cd src       &amp;&amp; sed -e '/# am--include-marker/d' Makefile         | make -f - am--depfiles
  /bin/mkdir: cannot create directory '/.deps': Permission denied
  make: *** [/tmp/GmlvxQJQ:720: /.deps/mini-gmp.Plo] Error 1
  </code></pre>
  
  <p>The reason is that the generated <code>src/Makefile</code> file contains things like <code>$(mini_gmp_path)/$(DEPDIR)/mini-gmp.Plo</code> while <code>mini_gmp_path</code> is not defined. But since one does not want to build against mini-gmp, such information about <code>mini-gmp.Plo</code> is incorrect, i.e. mini-gmp files should completely be ignored for automatic dependency tracking when <code>MINI_GMP</code> is false.</p>
  
  <p>As a workaround, we currently define <code>mini_gmp_path</code> to <code>.</code> in <code>configure.ac</code> when one does not build against mini-gmp, so that the <code>$(mini_gmp_path)/$(DEPDIR)</code> directory exists, avoiding a <code>configure</code> failure. But this is not a clean solution, which might interfere with <code>mini-gmp.{c,h}</code> files that could be added in the MPFR source tree. The solution should just get rid of <code>mini-gmp.Plo</code> entirely.</p>