From 516d184b5db8ebdd8b184ef871050c3ab3f03fdf Mon Sep 17 00:00:00 2001
From: Andrew Chadwick <andrewc-git@piffle.org>
Date: Sun, 21 Apr 2013 22:51:05 +0100
Subject: [PATCH] SConstruct: support standard build environ vars

Support the standard build environment vars CC, CXX, CFLAGS, CXXFLAGS,
CPPFLAGS, and LDFLAGS everywhere.

Partially addresses https://gna.org/bugs/?20754
---
 SConstruct |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/SConstruct b/SConstruct
index 0b55da1..ef39b9e 100644
--- a/SConstruct
+++ b/SConstruct
@@ -1,6 +1,7 @@
 import os, sys
 from os.path import join, basename
 from SCons.Script.SConscript import SConsEnvironment
+import SCons.Util
 
 EnsureSConsVersion(1, 0)
 
@@ -45,6 +46,24 @@ print('using %r (use scons python_config=xxx to change)' % env['python_config'])
 if sys.platform == "win32":
     # remove this mingw if trying VisualStudio
     env = Environment(tools=tools + ['mingw'], ENV=os.environ, options=opts)
+
+# Respect some standard build environment stuff
+if os.environ.has_key('CC'):
+   env['CC'] = os.environ['CC']
+if os.environ.has_key('CFLAGS'):
+   env['CCFLAGS'] += SCons.Util.CLVar(os.environ['CFLAGS'])
+if os.environ.has_key('CXX'):
+   env['CXX'] = os.environ['CXX']
+if os.environ.has_key('CXXFLAGS'):
+   env['CXXFLAGS'] += SCons.Util.CLVar(os.environ['CXXFLAGS'])
+if os.environ.has_key('CPPFLAGS'):
+   env['CCFLAGS'] += SCons.Util.CLVar(os.environ['CPPFLAGS'])
+   env['CXXFLAGS'] += SCons.Util.CLVar(os.environ['CPPFLAGS'])
+if os.environ.has_key('LDFLAGS'):
+   env['LINKFLAGS'] += SCons.Util.CLVar(os.environ['LDFLAGS'])
+if "$CCFLAGS" in env['CXXCOM']:
+   env['CXXCOM'] = env['CXXCOM'].replace("$CCFLAGS","")
+
 opts.Update(env)
 
 env.Append(CXXFLAGS=' -Wall -Wno-sign-compare -Wno-write-strings')
-- 
1.7.10.4

