3 # Copyright (C) 2007-2008 Arnold Krille
5 # This file is part of FFADO
6 # FFADO = Free Firewire (pro-)audio drivers for linux
8 # FFADO is based upon FreeBoB.
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 2 of the License, or
13 # (at your option) version 3 of the License.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 # Taken from http://www.scons.org/wiki/UsingPkgConfig
26 # and heavily modified
32 # Checks for pkg-config
34 def CheckForPKGConfig( context
, version
='0.0.0' ):
35 context
.Message( "Checking for pkg-config (at least version %s)... " % version
)
36 ret
= context
.TryAction( "pkg-config --atleast-pkgconfig-version=%s" %version
)[0]
41 # Checks for the given package with an optional version-requirement
43 # The flags (which can be imported into the environment by env.MergeFlags(...)
44 # are exported as env['NAME_FLAGS'] where name is built by removing all +,-,.
47 def CheckForPKG( context
, name
, version
="" ):
48 name2
= name
.replace("+","").replace(".","").replace("-","")
51 context
.Message( "Checking for %s... \t" % name
)
52 ret
= context
.TryAction( "pkg-config --exists '%s'" % name
)[0]
54 context
.Message( "Checking for %s (%s or higher)... \t" % (name
,version
) )
55 ret
= context
.TryAction( "pkg-config --atleast-version=%s '%s'" % (version
,name
) )[0]
58 context
.env
['%s_FLAGS' % name2
.upper()] = context
.env
.ParseFlags("!pkg-config --cflags --libs %s" % name
)
64 # Checks for the existance of the package and returns the packages flags.
66 # This should allow caching of the flags so that pkg-config is called only once.
68 def GetPKGFlags( context
, name
, version
="" ):
72 context
.Message( "Checking for %s... \t" % name
)
73 ret
= context
.TryAction( "pkg-config --exists '%s'" % name
)[0]
75 context
.Message( "Checking for %s (%s or higher)... \t" % (name
,version
) )
76 ret
= context
.TryAction( "pkg-config --atleast-version=%s '%s'" % (version
,name
) )[0]
82 out
= subprocess
.Popen(['pkg-config', '--cflags', '--libs', name
], stdout
=subprocess
.PIPE
)
83 ret
= out
.stdout
.read()
85 context
.Result( True )
89 # Checks for the existance of the package and returns the value of the specified variable.
91 def GetPKGVariable( context
, name
, variable
):
94 context
.Message( "Checking for variable %s in package %s... \t" % (variable
,name
) )
96 ret
= context
.TryAction( "pkg-config --exists '%s'" % name
)[0]
101 out
= subprocess
.Popen(['pkg-config', '--variable=%s' % variable
, name
], stdout
=subprocess
.PIPE
)
102 ret
= out
.stdout
.read()
104 context
.Result( True )
107 def generate( env
, **kw
):
108 env
['PKGCONFIG_TESTS' ] = { 'CheckForPKGConfig' : CheckForPKGConfig
, 'CheckForPKG' : CheckForPKG
, 'GetPKGFlags' : GetPKGFlags
, 'GetPKGVariable' : GetPKGVariable
}