44from __future__ import print_function
55
66from distutils .core import setup , Extension
7+ import sys
8+
79try :
810 import commands
911except ImportError :
1012 import subprocess as commands
11- import sys
13+ run = commands . getstatusoutput
1214
1315version = '0.12'
1416
@@ -28,60 +30,38 @@ def __init__(self, *args, **kwargs):
2830 # on Python 3, that's not needed or possible
2931 pass
3032 self ._pkg = pkg
31- self ._pkgconfig_result = None
32-
33- @property
34- def pkgconfig (self ):
35- if self ._pkgconfig_result is None :
36- self ._pkgconfig_result = self ._pkgconfig (self ._pkg )
37- return self ._pkgconfig_result
38-
39- def _pkgconfig (self , pkg ):
40- def _str2list (pkgstr , onlystr ):
41- res = []
42- for l in pkgstr .split (" " ):
43- if l .find (onlystr ) == 0 :
44- res .append (l .replace (onlystr , "" , 1 ))
45- return res
46-
47- (res , cflags ) = commands .getstatusoutput ('pkg-config --cflags-only-other %s' % pkg )
48- if res != 0 :
49- print ('Failed to query pkg-config --cflags-only-other %s' % pkg )
50- sys .exit (1 )
51-
52- (res , includes ) = commands .getstatusoutput ('pkg-config --cflags-only-I %s' % pkg )
53- if res != 0 :
54- print ('Failed to query pkg-config --cflags-only-I %s' % pkg )
55- sys .exit (1 )
56-
57- (res , libs ) = commands .getstatusoutput ('pkg-config --libs-only-l %s' % pkg )
58- if res != 0 :
59- print ('Failed to query pkg-config --libs-only-l %s' % pkg )
60- sys .exit (1 )
61-
62- (res , libdirs ) = commands .getstatusoutput ('pkg-config --libs-only-L %s' % pkg )
63- if res != 0 :
64- print ('Failed to query pkg-config --libs-only-L %s' % pkg )
65- sys .exit (1 )
6633
67- # Clean up the results and return what we've extracted from pkg-config
68- return {'cflags' : cflags ,
69- 'include' : _str2list (includes , '-I' ),
70- 'libs' : _str2list (libs , '-l' ),
71- 'libdirs' : _str2list (libdirs , '-L' )
72- }
34+ @classmethod
35+ def _str2list (cls , pkgstr , onlystr ):
36+ res = []
37+ for l in pkgstr .split (" " ):
38+ if l .find (onlystr ) == 0 :
39+ res .append (l .replace (onlystr , "" , 1 ))
40+ return res
7341
7442 @property
7543 def include_dirs (self ):
76- return self .pkgconfig ['include' ]
44+ res , includes = run ('pkg-config --cflags-only-I %s' % self ._pkg )
45+ if res != 0 :
46+ print ('Failed to query pkg-config --cflags-only-I %s' % self ._pkg )
47+ sys .exit (1 )
48+ return self ._str2list (includes , '-I' )
7749
7850 @property
7951 def library_dirs (self ):
80- return self .pkgconfig ['libdirs' ]
52+ res , libdirs = run ('pkg-config --libs-only-L %s' % self ._pkg )
53+ if res != 0 :
54+ print ('Failed to query pkg-config --libs-only-L %s' % self ._pkg )
55+ sys .exit (1 )
56+ return self ._str2list (libdirs , '-L' )
8157
8258 @property
8359 def libraries (self ):
84- return self .pkgconfig ['libs' ] + ['nl-route-3' ]
60+ res , libs = run ('pkg-config --libs-only-l %s' % self ._pkg )
61+ if res != 0 :
62+ print ('Failed to query pkg-config --libs-only-l %s' % self ._pkg )
63+ sys .exit (1 )
64+ return self ._str2list (libs , '-l' ) + ['nl-route-3' ]
8565
8666 @include_dirs .setter
8767 def include_dirs (self , value ):
0 commit comments