title: Where to add a CFLAG, such as -std=gnu99, into an autotools project
body: <p>I have a simple Autotools C project (not C++).</p>
  
  <p>CFLAGs (by inspection) seem to be <code>-g -O2</code>.</p>
  
  <p>I want all of the generated make files to also have <code>-std=gnu99</code> appended to the CFLAGs, because I use <code>for (int i = 0; i &lt; MAX; i++)</code> and similar.</p>
  
  <p>I can obviously hack the Makefile, but this gets overwritten on <code>./configure</code>.</p>
  
  <p>Where is the correct place to add (or change) CFLAGs which are required by the code (as opposed to those CFLAGs which the user might want to change)?</p>
  
  <p>(Note this is partial duplicate of <a href="https://stackoverflow.com/questions/11633763/where-to-add-a-cflag-such-as-std-gnu99-into-an-eclipse-cdt-autotools-project">Where to add a CFLAG, such as -std=gnu99, into an (Eclipse CDT) autotools project</a> as I was getting Eclipse-specific answers which I didn't want.)</p>
  
  <hr>
  
  <p>@DevSolar's answer has not helped yet.  A <code>configure.ac</code> file (below) generates the <code>configure</code> script (also below).</p>
  
  <p>configure.ac:</p>
  
  <pre><code>dnl Process this file with autoconf to produce a configure script.
  
  CFLAGS="$CFLAGS -std=gnu99"
  AC_PREREQ(2.59)
  AC_INIT(tuntest, 1.0)
  
  
  AC_CANONICAL_SYSTEM
  AM_INIT_AUTOMAKE()
  
  AC_PROG_CC
  
  AC_CONFIG_FILES(Makefile src/Makefile)
  AC_OUTPUT
  </code></pre>
  
  <p>$ grep CFLAGS configure</p>
  
  <pre><code>CFLAGS
  CFLAGS
  To assign environment variables (e.g., CC, CFLAGS...), specify them as
    CFLAGS      C compiler flags
  ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext &gt;&amp;5'
  ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS &gt;&amp;5'
  ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext &gt;&amp;5'
  ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS &gt;&amp;5'
  ac_test_CFLAGS=${CFLAGS+set}
  ac_save_CFLAGS=$CFLAGS
     CFLAGS="-g"
    CFLAGS=""
       CFLAGS="-g"
  if test "$ac_test_CFLAGS" = set; then
    CFLAGS=$ac_save_CFLAGS
      CFLAGS="-g -O2"
      CFLAGS="-g"
      CFLAGS="-O2"
      CFLAGS=
  ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext &gt;&amp;5'
  ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS &gt;&amp;5'
  </code></pre>