summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons/Util.py
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2002-11-12 13:43:54 (GMT)
committerSteven Knight <knight@baldmt.com>2002-11-12 13:43:54 (GMT)
commit889f0c7238da15a89be500e40ce9f73102e31b8c (patch)
tree92ed84c42045815814f2cb39fc39e7c5984c5bb7 /src/engine/SCons/Util.py
parent1cfff0b089cc56024ed5ea71c33ad843373bb9fc (diff)
downloadSCons-889f0c7238da15a89be500e40ce9f73102e31b8c.zip
SCons-889f0c7238da15a89be500e40ce9f73102e31b8c.tar.gz
SCons-889f0c7238da15a89be500e40ce9f73102e31b8c.tar.bz2
Add the ParseConfig() method. (Steve Leblanc)
Diffstat (limited to 'src/engine/SCons/Util.py')
-rw-r--r--src/engine/SCons/Util.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py
index 3a39c4e..5c2fd26 100644
--- a/src/engine/SCons/Util.py
+++ b/src/engine/SCons/Util.py
@@ -523,3 +523,50 @@ else:
if stat.S_IMODE(st[stat.ST_MODE]) & 0111:
return f
return None
+
+def ParseConfig(env, command, function=None):
+ """Use the specified function to parse the output of the command in order
+ to modify the specified environment. The 'command' can be a string or a
+ list of strings representing a command and it's arguments. 'Function' is
+ an optional argument that takes the environment and the output of the
+ command. If no function is specified, the output will be treated as the
+ output of a typical 'X-config' command (i.e. gtk-config) and used to set
+ the CPPPATH, LIBPATH, LIBS, and CCFLAGS variables.
+ """
+ # the default parse function
+ def parse_conf(env, output):
+ env_dict = env.Dictionary()
+ static_libs = []
+
+ # setup all the dictionary options
+ if not env_dict.has_key('CPPPATH'):
+ env_dict['CPPPATH'] = []
+ if not env_dict.has_key('LIBPATH'):
+ env_dict['LIBPATH'] = []
+ if not env_dict.has_key('LIBS'):
+ env_dict['LIBS'] = []
+ if not env_dict.has_key('CCFLAGS') or env_dict['CCFLAGS'] == "":
+ env_dict['CCFLAGS'] = []
+
+ params = string.split(output)
+ for arg in params:
+ switch = arg[0:1]
+ opt = arg[1:2]
+ if switch == '-':
+ if opt == 'L':
+ env_dict['LIBPATH'].append(arg[2:])
+ elif opt == 'l':
+ env_dict['LIBS'].append(arg[2:])
+ elif opt == 'I':
+ env_dict['CPPPATH'].append(arg[2:])
+ else:
+ env_dict['CCFLAGS'].append(arg)
+ else:
+ static_libs.append(arg)
+ return static_libs
+
+ if function is None:
+ function = parse_conf
+ if type(command) is type([]):
+ command = string.join(command)
+ return function(env, os.popen(command).read())