title: How to work around "scons: warning: Two different environments were specified for target"
body: <p>Suppose I have an <code>SConstruct</code> file that looks like this:</p>
  
  <pre><code>env = Environment()
  
  env.Program("a", ["a.c", "util.c"])
  env.Program("b", ["b.c", "util.c"])
  </code></pre>
  
  <p>This build works properly with no SCons warning messages. However, if I modify this to specify <em>different</em> libraries for each <code>Program</code> build (the actual libraries are not relevant):</p>
  
  <pre><code>env.Program("a", ["a.c", "util.c"], LIBS="m")
  env.Program("b", ["b.c", "util.c"], LIBS="c")
  </code></pre>
  
  <p>then I get the warning:</p>
  
  <pre>
  scons: warning: Two different environments were specified for target util.o,
          but they appear to have the same action: $CC -o $TARGET -c $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES
  </pre>
  
  <p>This appears to be caused by the <code>Program</code> builder automatically creating a new environment for building the <em>sources</em>, even though it is just the <code>LIBS</code> variable that is different (and so only the <em>link</em> step needs to have a different environment). I can work around this by doing something like:</p>
  
  <pre><code>util = env.Object("util.c")
  env.Program("a", ["a.c"] + util, LIBS="m")
  env.Program("b", ["b.c"] + util, LIBS="c")
  </code></pre>
  
  <p>This uses a single <code>Object</code> builder for building <code>util.c</code>, then using the precompiled object file in each <code>Program</code> build, thus avoiding the warning. However, this should not really be necessary. Is there a more elegant way to work around this problem? Or is this actually a bug in SCons that should be fixed?</p>
  
  <p>Context: I have nearly 2000 C source files compiled into about 20 libraries and 120 executables with lots of shared sources. I created the <code>SConstruct</code> file from the previous proprietary build system using a conversion script I wrote. There are about 450 "Two different environments" warning messages produced by SCons for a full build using my current <code>SConstruct</code>.</p>