title: How to enable flags with automake specific to GCC
body: <p>I'm new to automake, but found my way through the docs and have everything building as I like.  However, I currently have CFLAGS="-Wall -Werror" turned on.  While this is great for gcc, I'm assuming that someone is going to build my code with a non-gcc compiler.  What's the correct way to detect whether GCC is being used and to only set those flags for GCC?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>The solution looks like this:</p>
  
  <ol>
  <li>Download <a href="http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html" rel="nofollow">http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html</a> and place the macro in your project's ./m4/ directory.</li>
  <li><p>Add the following lines to your configure.ac:</p>
  
  <pre><code>AX_CHECK_COMPILE_FLAG([-Wall], [CFLAGS="$CFLAGS -Wall"], [], [])
  AX_CHECK_COMPILE_FLAG([-Werror], [CFLAGS="$CFLAGS -Werror"], [], [])
  </code></pre></li>
  </ol>
  
  <p><strong>Edit 2</strong></p>
  
  <p>This macro might also be more useful than -Wall since it does the same for multiple compilers: <a href="http://www.gnu.org/software/autoconf-archive/ax_cflags_warn_all.html" rel="nofollow">http://www.gnu.org/software/autoconf-archive/ax_cflags_warn_all.html</a></p>