diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2015-09-04 09:50:51 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2015-09-04 09:50:51 +0200 |
commit | ddca9bbe3a6fa3ac0d045f13bb425fe2bd401be4 (patch) | |
tree | 56def503dd72b7c1fbda24084ac6b751b6ad1c9b | |
parent | d03d276625a746b9b1c2a75f8488ab300730a7a9 (diff) | |
download | python-systemd-ddca9bbe3a6fa3ac0d045f13bb425fe2bd401be4.tar.gz |
build-sys: use pkg-config to build with old systemd
This should allow the build to just work on old Ubuntu
and similar.
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | setup.py | 35 |
2 files changed, 33 insertions, 10 deletions
@@ -37,6 +37,14 @@ On Fedora 21+ with Python 3: dnf install git python3-pip gcc python3-devel systemd-devel pip3 install git+https://github.com/systemd/python-systemd.git#egg=systemd +On Debian or Ubuntu with Python 2: + + apt-get install libsystemd-{journal,daemon,login,id128}-dev gcc python-dev + +On Debian or Ubuntu with Python 3: + + apt-get install libsystemd-{journal,daemon,login,id128}-dev gcc python3-dev + Usage ===== @@ -1,35 +1,50 @@ from distutils.core import setup, Extension +import subprocess + +def pkgconfig(package, **kw): + flag_map = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries'} + output = subprocess.check_output(['pkg-config', '--libs', '--cflags', package], + universal_newlines=True) + for token in output.split(): + kw.setdefault(flag_map.get(token[:2]), []).append(token[2:]) + return kw + +def lib(name, fallback): + try: + return pkgconfig(name) + except subprocess.CalledProcessError: + return pkgconfig(fallback) version = '230' defines = [('PACKAGE_VERSION', '"{}"'.format(version))] _journal = Extension('systemd/_journal', define_macros = defines, - libraries = ['systemd'], sources = ['systemd/_journal.c', - 'systemd/pyutil.c']) + 'systemd/pyutil.c'], + **lib('libsystemd', 'libsystemd-journal')) _reader = Extension('systemd/_reader', define_macros = defines, - libraries = ['systemd'], sources = ['systemd/_reader.c', 'systemd/pyutil.c', - 'systemd/strv.c']) + 'systemd/strv.c'], + **lib('libsystemd', 'libsystemd-journal')) _daemon = Extension('systemd/_daemon', define_macros = defines, - libraries = ['systemd'], sources = ['systemd/_daemon.c', - 'systemd/pyutil.c']) + 'systemd/pyutil.c'], + **lib('libsystemd', 'libsystemd-daemon')) id128 = Extension('systemd/id128', define_macros = defines, - libraries = ['systemd'], sources = ['systemd/id128.c', - 'systemd/pyutil.c']) + 'systemd/pyutil.c'], + **lib('libsystemd', 'libsystemd-id128')) login = Extension('systemd/login', define_macros = defines, - libraries = ['systemd'], sources = ['systemd/login.c', 'systemd/pyutil.c', - 'systemd/strv.c']) + 'systemd/strv.c'], + **lib('libsystemd', 'libsystemd-login')) setup (name = 'python-systemd', version = version, description = 'Native interface to the facilities of systemd', |