root/trunk/libffado/admin/pkgconfig.py

Revision 640, 2.0 kB (checked in by arnonym, 17 years ago)

Make the pkgconfig.py a real scons-tool.

Line 
1 #!/usr/bin/python
2
3 #
4 # Taken from http://www.scons.org/wiki/UsingPkgConfig
5 # and heavily modified
6 #
7
8 #
9 # Checks for pkg-config
10 #
11 def CheckForPKGConfig( context, version='0.0.0' ):
12         context.Message( "Checking for pkg-config (at least version %s)... " % version )
13         ret = context.TryAction( "pkg-config --atleast-pkgconfig-version=%s" %version )[0]
14         context.Result( ret )
15         return ret
16
17 #
18 # Checks for the given package with an optional version-requirement
19 #
20 # The flags (which can be imported into the environment by env.MergeFlags(...)
21 # are exported as env['NAME_FLAGS'] where name is built by removing all +,-,.
22 # and upper-casing.
23 #
24 def CheckForPKG( context, name, version="" ):
25         name2 = name.replace("+","").replace(".","").replace("-","")
26
27         if version == "":
28                 context.Message( "Checking for %s... \t" % name )
29                 ret = context.TryAction( "pkg-config --exists '%s'" % name )[0]
30         else:
31                 context.Message( "Checking for %s (%s or higher)... \t" % (name,version) )
32                 ret = context.TryAction( "pkg-config --atleast-version=%s '%s'" % (version,name) )[0]
33
34         if ret:
35                 context.env['%s_FLAGS' % name2.upper()] = context.env.ParseFlags("!pkg-config --cflags --libs %s" % name)
36
37         context.Result( ret )
38         return ret
39
40 #
41 # Checks for the existance of the package and returns the packages flags.
42 #
43 # This should allow caching of the flags so that pkg-config is called only once.
44 #
45 def GetPKGFlags( context, name, version="" ):
46         import os
47
48         if version == "":
49                 context.Message( "Checking for %s... \t" % name )
50                 ret = context.TryAction( "pkg-config --exists '%s'" % name )[0]
51         else:
52                 context.Message( "Checking for %s (%s or higher)... \t" % (name,version) )
53                 ret = context.TryAction( "pkg-config --atleast-version=%s '%s'" % (version,name) )[0]
54
55         if not ret:
56                 context.Result( ret )
57                 return ret
58
59         out = os.popen2( "pkg-config --cflags --libs %s" % name )[1]
60         ret = out.read()
61
62         context.Result( True )
63         return ret
64
65 def generate( env, **kw ):
66         env['PKGCONFIG_TESTS' ] = { 'CheckForPKGConfig' : CheckForPKGConfig, 'CheckForPKG' : CheckForPKG, 'GetPKGFlags' : GetPKGFlags }
67
68 def exists( env ):
69         return 1
70
71
Note: See TracBrowser for help on using the browser.