1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
#!/usr/bin/python
#
# Copyright (C) 2007-2008 Arnold Krille
#
# This file is part of FFADO
# FFADO = Free FireWire (pro-)audio drivers for Linux
#
# FFADO is based upon FreeBoB.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# Taken from http://www.scons.org/wiki/UsingPkgConfig
# and heavily modified
#
import subprocess
#
# Checks for pkg-config
#
def CheckForPKGConfig( context, version='0.0.0' ):
context.Message( "Checking for pkg-config (at least version %s)... " % version )
ret = context.TryAction( "pkg-config --atleast-pkgconfig-version=%s" %version )[0]
context.Result( ret )
return ret
#
# Checks for the given package with an optional version-requirement
#
# The flags (which can be imported into the environment by env.MergeFlags(...)
# are exported as env['NAME_FLAGS'] where name is built by removing all +,-,.
# and upper-casing.
#
def CheckForPKG( context, name, version="" ):
name2 = name.replace("+","").replace(".","").replace("-","")
if version == "":
context.Message( "Checking for %s... \t" % name )
ret = context.TryAction( "pkg-config --exists '%s'" % name )[0]
else:
context.Message( "Checking for %s (%s or higher)... \t" % (name,version) )
ret = context.TryAction( "pkg-config --atleast-version=%s '%s'" % (version,name) )[0]
if ret:
context.env['%s_FLAGS' % name2.upper()] = context.env.ParseFlags("!pkg-config --cflags --libs %s" % name)
context.Result( ret )
return ret
#
# Checks for the existance of the package and returns the packages flags.
#
# This should allow caching of the flags so that pkg-config is called only once.
#
def GetPKGFlags( context, name, version="" ):
import os
if version == "":
context.Message( "Checking for %s... \t" % name )
ret = context.TryAction( "pkg-config --exists '%s'" % name )[0]
else:
context.Message( "Checking for %s (%s or higher)... \t" % (name,version) )
ret = context.TryAction( "pkg-config --atleast-version=%s '%s'" % (version,name) )[0]
if not ret:
context.Result( ret )
return ret
out = subprocess.Popen(['pkg-config', '--cflags', '--libs', name], stdout=subprocess.PIPE)
ret = out.stdout.read()
context.Result( True )
return ret
#
# Checks for the existance of the package and returns the value of the specified variable.
#
def GetPKGVariable( context, name, variable ):
import os
context.Message( "Checking for variable %s in package %s... \t" % (variable,name) )
ret = context.TryAction( "pkg-config --exists '%s'" % name )[0]
if not ret:
context.Result( ret )
return ret
out = subprocess.Popen(['pkg-config', '--variable=%s' % variable, name], stdout=subprocess.PIPE)
ret = out.stdout.read()
context.Result( True )
return ret
def generate( env, **kw ):
env['PKGCONFIG_TESTS' ] = { 'CheckForPKGConfig' : CheckForPKGConfig, 'CheckForPKG' : CheckForPKG, 'GetPKGFlags' : GetPKGFlags, 'GetPKGVariable' : GetPKGVariable }
def exists( env ):
return 1
|