title: How to add and implement configure flags in Autotools?
body: <p>A portion of our research group's program has auxiliary functionality provided by <a href="http://code.google.com/p/google-ctemplate/" rel="noreferrer">ctemplate</a> library. On our dated cluster, we can not build the software due to compilation , so I would like to separate this functionality and control whether it is included or not via a <code>configure</code> flag, such as <code>--disable-ctemplate</code>.</p>
  
  <p>The software, written in C++, uses the Autotools build system&mdash;neither of which I have much experience with. My understanding is that to accomplish this task, I need to do the following:</p>
  
  <ol>
  <li><p>Add a new flag to the configure script by creating a new <code>AC_ARG_ENABLE</code> entry in <code>configure.ac</code>.</p></li>
  <li><p>Add some <code>#ifdef</code> (or possibly <code>#ifndef</code>) statements around the code that uses the <code>ctemplate</code> library, and around any code that calls that code.</p></li>
  </ol>
  
  <p>I think the first step would look something like this:</p>
  
  <pre><code>AC_ARG_ENABLE(ctemplate,
  [  --disable-ctemplate    Disable HTML output],
  [case "${enableval}" in
    yes) ctemplate=false ;;
    no)  ctemplate=true ;;
    *) AC_MSG_ERROR(bad value ${enableval} for --disable-ctemplate) ;;
  esac],[ctemplate=true])
  AM_CONDITIONAL(NOCTEMPLATE, test x$ctemplate = xfalse)
  </code></pre>
  
  <p>though I don't know if the logic is correct, since I've adapted this example from examples that used <code>--enable-FLAG</code> instead of <code>--disable-FLAG</code>.</p>
  
  <p>For the second step, I'll wrap sections in preprocessor flags such as</p>
  
  <pre><code>#ifndef NOCTEMPLATE
  void Class::MethodUsingCtemplate(...)
  {
      ...
  }
  #endif
  </code></pre>
  
  <p>Would this correctly "wire up" everything if I did <code>configure --disable-ctemplate</code>?</p>
  
  <p>Also, will this ensure that the program does not go into the <code>ctemplate</code> library for compilation? If not, then all of this is for nothing; it's imperative that I can prevent compilation of the <code>ctemplate</code> library and dependent components.</p>
  
  <p>I'll re-iterate that I'm unfamiliar with both C++ and Autotools; I have taken a very naive first approach at solving this problem. If you have experience in this area, I would really appreciate your corrections and any explanations you could offer.</p>