diff options
author | marha <marha@users.sourceforge.net> | 2011-07-04 14:21:49 +0200 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2011-07-04 14:21:49 +0200 |
commit | 5c671fd7f8198bed2fc32b33b81d1081f1486ed9 (patch) | |
tree | 96fc6a6d761473737def7c35256fed9bbe52753e /mesalib/scons/custom.py | |
parent | d9f970a847e1af706f07560ef163b229bb592307 (diff) | |
download | vcxsrv-5c671fd7f8198bed2fc32b33b81d1081f1486ed9.tar.gz vcxsrv-5c671fd7f8198bed2fc32b33b81d1081f1486ed9.tar.bz2 vcxsrv-5c671fd7f8198bed2fc32b33b81d1081f1486ed9.zip |
xserver mesa git update 4 July 2011
Diffstat (limited to 'mesalib/scons/custom.py')
-rw-r--r-- | mesalib/scons/custom.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/mesalib/scons/custom.py b/mesalib/scons/custom.py index 029f99b99..df7ac93bb 100644 --- a/mesalib/scons/custom.py +++ b/mesalib/scons/custom.py @@ -33,6 +33,8 @@ Custom builders and methods. import os import os.path import re +import sys +import subprocess import SCons.Action import SCons.Builder @@ -154,6 +156,79 @@ def createCodeGenerateMethod(env): env.AddMethod(code_generate, 'CodeGenerate') +def _pkg_check_modules(env, name, modules): + '''Simple wrapper for pkg-config.''' + + env['HAVE_' + name] = False + + # For backwards compatability + env[name.lower()] = False + + if env['platform'] == 'windows': + return + + if not env.Detect('pkg-config'): + return + + if subprocess.call(["pkg-config", "--exists", ' '.join(modules)]) != 0: + return + + # Other flags may affect the compilation of unrelated targets, so store + # them with a prefix, (e.g., XXX_CFLAGS, XXX_LIBS, etc) + try: + flags = env.ParseFlags('!pkg-config --cflags --libs ' + ' '.join(modules)) + except OSError: + return + prefix = name + '_' + for flag_name, flag_value in flags.iteritems(): + assert '_' not in flag_name + env[prefix + flag_name] = flag_value + + env['HAVE_' + name] = True + +def pkg_check_modules(env, name, modules): + + sys.stdout.write('Checking for %s...' % name) + _pkg_check_modules(env, name, modules) + result = env['HAVE_' + name] + sys.stdout.write(' %s\n' % ['no', 'yes'][int(bool(result))]) + + # XXX: For backwards compatability + env[name.lower()] = result + + +def pkg_use_modules(env, names): + '''Search for all environment flags that match NAME_FOO and append them to + the FOO environment variable.''' + + names = env.Flatten(names) + + for name in names: + prefix = name + '_' + + if not 'HAVE_' + name in env: + print 'Attempt to use unknown module %s' % name + env.Exit(1) + + if not env['HAVE_' + name]: + print 'Attempt to use unavailable module %s' % name + env.Exit(1) + + flags = {} + for flag_name, flag_value in env.Dictionary().iteritems(): + if flag_name.startswith(prefix): + flag_name = flag_name[len(prefix):] + if '_' not in flag_name: + flags[flag_name] = flag_value + if flags: + env.MergeFlags(flags) + + +def createPkgConfigMethods(env): + env.AddMethod(pkg_check_modules, 'PkgCheckModules') + env.AddMethod(pkg_use_modules, 'PkgUseModules') + + def generate(env): """Common environment generation code""" @@ -164,6 +239,7 @@ def generate(env): # Custom builders and methods createConvenienceLibBuilder(env) createCodeGenerateMethod(env) + createPkgConfigMethods(env) # for debugging #print env.Dump() |