|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 |
|
| 3 | +import errno |
| 4 | +import subprocess |
| 5 | + |
3 | 6 | from distutils.core import setup, Extension |
4 | 7 |
|
| 8 | +libudev_so = "libudev.so.1" |
| 9 | + |
| 10 | +# Because libsuinput can be linked against both libudev.so.0 and |
| 11 | +# libudev.so.1, we try to use ldconfig to find out which one is |
| 12 | +# available. Preferably libudev.so.1. |
| 13 | +try: |
| 14 | + ldconfig_output = subprocess.check_output(["ldconfig", "-p"]) |
| 15 | + for line in ldconfig_output.splitlines(): |
| 16 | + |
| 17 | + try: |
| 18 | + lib = line.split()[0] |
| 19 | + except IndexError: |
| 20 | + # An unexpected line, but let's proceed. |
| 21 | + continue |
| 22 | + |
| 23 | + if lib == "libudev.so.0": |
| 24 | + libudev_so = lib |
| 25 | + # We are quite happy, but let's look if there's something |
| 26 | + # better. |
| 27 | + |
| 28 | + if lib == "libudev.so.1": |
| 29 | + libudev_so = lib |
| 30 | + break # We are really happy, no reason to look further. |
| 31 | +except: |
| 32 | + # We don't care if something goes wrong while we scan through all |
| 33 | + # the available libraries. The whole scan operation is just |
| 34 | + # best-effort, we can always fall back to the default, hard-coded, |
| 35 | + # library. |
| 36 | + pass |
| 37 | + |
5 | 38 | setup(name='python-uinput', |
6 | 39 | version='0.11.1', |
7 | 40 | description='Pythonic API to Linux uinput kernel module.', |
|
36 | 69 | programmatically. |
37 | 70 | """, |
38 | 71 | ext_modules=[Extension('_libsuinput', ['libsuinput/src/suinput.c'], |
39 | | - libraries=[":libudev.so.1"])] |
| 72 | + libraries=[":%s" % libudev_so])] |
40 | 73 | ) |
0 commit comments