summaryrefslogtreecommitdiffstats
path: root/setup.py
blob: 57a58e54f3ec43b39c32f06656e32a050d0b0c44 (plain)
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
#!/usr/bin/python2

from distutils.core import setup, Extension
import commands
import sys

version = '0.10'

def pkgconfig(pkg):
    def _str2list(pkgstr, onlystr):
        res = []
        for l in pkgstr.split(" "):
            if l.find(onlystr) == 0:
                res.append(l.replace(onlystr, "", 1))
        return res

    (res, cflags) = commands.getstatusoutput('pkg-config --cflags-only-other %s' % pkg)
    if res != 0:
        print 'Failed to query pkg-config --cflags-only-other %s' % pkg
        sys.exit(1)

    (res, includes) = commands.getstatusoutput('pkg-config --cflags-only-I %s' % pkg)
    if res != 0:
        print 'Failed to query pkg-config --cflags-only-I %s' % pkg
        sys.exit(1)

    (res, libs) = commands.getstatusoutput('pkg-config --libs-only-l %s' % pkg)
    if res != 0:
        print 'Failed to query pkg-config --libs-only-l %s' % pkg
        sys.exit(1)

    (res, libdirs) = commands.getstatusoutput('pkg-config --libs-only-L %s' % pkg)
    if res != 0:
        print 'Failed to query pkg-config --libs-only-L %s' % pkg
        sys.exit(1)


    # Clean up the results and return what we've extracted from pkg-config
    return {'cflags': cflags,
            'include': _str2list(includes, '-I'),
            'libs': _str2list(libs, '-l'),
            'libdirs': _str2list(libdirs, '-L')
            }


libnl = pkgconfig('libnl-3.0')
libnl['libs'].append('nl-route-3')

# don't reformat this line, Makefile parses it
setup(name='ethtool',
      version=version,
      description='Python module to interface with ethtool',
      author='Harald Hoyer, Arnaldo Carvalho de Melo, David Sommerseth',
      author_email='davids@redhat.com',
      url='http://fedoraproject.org/wiki/python-ethtool',
      ext_modules=[
        Extension(
            'ethtool',
            sources = [
                'python-ethtool/ethtool.c',
                'python-ethtool/etherinfo.c',
                'python-ethtool/etherinfo_obj.c',
                'python-ethtool/netlink.c',
                'python-ethtool/netlink-address.c'],
            include_dirs = libnl['include'],
            library_dirs = libnl['libdirs'],
            libraries = libnl['libs'],
            define_macros = [('VERSION', '"%s"' % version)]
            )
        ]
)