root/trunk/libffado/admin/pkgconfig.py

Revision 1896, 3.4 kB (checked in by arnonym, 14 years ago)

Replace os.popen2 by subprocess. Removes two ugly warnings.

Line 
1 #!/usr/bin/python
2 #
3 # Copyright (C) 2007-2008 Arnold Krille
4 #
5 # This file is part of FFADO
6 # FFADO = Free Firewire (pro-)audio drivers for linux
7 #
8 # FFADO is based upon FreeBoB.
9 #
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.
14 #
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.
19 #
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/>.
22 #
23
24 #
25 # Taken from http://www.scons.org/wiki/UsingPkgConfig
26 # and heavily modified
27 #
28
29 import subprocess
30
31 #
32 # Checks for pkg-config
33 #
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]
37         context.Result( ret )
38         return ret
39
40 #
41 # Checks for the given package with an optional version-requirement
42 #
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 +,-,.
45 # and upper-casing.
46 #
47 def CheckForPKG( context, name, version="" ):
48         name2 = name.replace("+","").replace(".","").replace("-","")
49
50         if version == "":
51                 context.Message( "Checking for %s... \t" % name )
52                 ret = context.TryAction( "pkg-config --exists '%s'" % name )[0]
53         else:
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]
56
57         if ret:
58                 context.env['%s_FLAGS' % name2.upper()] = context.env.ParseFlags("!pkg-config --cflags --libs %s" % name)
59
60         context.Result( ret )
61         return ret
62
63 #
64 # Checks for the existance of the package and returns the packages flags.
65 #
66 # This should allow caching of the flags so that pkg-config is called only once.
67 #
68 def GetPKGFlags( context, name, version="" ):
69         import os
70
71         if version == "":
72                 context.Message( "Checking for %s... \t" % name )
73                 ret = context.TryAction( "pkg-config --exists '%s'" % name )[0]
74         else:
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]
77
78         if not ret:
79                 context.Result( ret )
80                 return ret
81
82         out = subprocess.Popen(['pkg-config', '--cflags', '--libs', name], stdout=subprocess.PIPE)
83         ret = out.stdout.read()
84
85         context.Result( True )
86         return ret
87
88 #
89 # Checks for the existance of the package and returns the value of the specified variable.
90 #
91 def GetPKGVariable( context, name, variable ):
92         import os
93
94         context.Message( "Checking for variable %s in package %s... \t" % (variable,name) )
95
96         ret = context.TryAction( "pkg-config --exists '%s'" % name )[0]
97         if not ret:
98                 context.Result( ret )
99                 return ret
100
101         out = subprocess.Popen(['pkg-config', '--variable=%s' % variable, name], stdout=subprocess.PIPE)
102         ret = out.stdout.read()
103
104         context.Result( True )
105         return ret
106
107 def generate( env, **kw ):
108         env['PKGCONFIG_TESTS' ] = { 'CheckForPKGConfig' : CheckForPKGConfig, 'CheckForPKG' : CheckForPKG, 'GetPKGFlags' : GetPKGFlags, 'GetPKGVariable' : GetPKGVariable }
109
110 def exists( env ):
111         return 1
112
113
Note: See TracBrowser for help on using the browser.