diff options
Diffstat (limited to 'src/engine/SCons/Util.py')
-rw-r--r-- | src/engine/SCons/Util.py | 47 |
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()) |