Skip to content

Commit ddca9bb

Browse files
committed
build-sys: use pkg-config to build with old systemd
This should allow the build to just work on old Ubuntu and similar.
1 parent d03d276 commit ddca9bb

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ On Fedora 21+ with Python 3:
3737
dnf install git python3-pip gcc python3-devel systemd-devel
3838
pip3 install git+https://github.com/systemd/python-systemd.git#egg=systemd
3939

40+
On Debian or Ubuntu with Python 2:
41+
42+
apt-get install libsystemd-{journal,daemon,login,id128}-dev gcc python-dev
43+
44+
On Debian or Ubuntu with Python 3:
45+
46+
apt-get install libsystemd-{journal,daemon,login,id128}-dev gcc python3-dev
47+
4048
Usage
4149
=====
4250

setup.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,50 @@
11
from distutils.core import setup, Extension
2+
import subprocess
3+
4+
def pkgconfig(package, **kw):
5+
flag_map = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries'}
6+
output = subprocess.check_output(['pkg-config', '--libs', '--cflags', package],
7+
universal_newlines=True)
8+
for token in output.split():
9+
kw.setdefault(flag_map.get(token[:2]), []).append(token[2:])
10+
return kw
11+
12+
def lib(name, fallback):
13+
try:
14+
return pkgconfig(name)
15+
except subprocess.CalledProcessError:
16+
return pkgconfig(fallback)
217

318
version = '230'
419
defines = [('PACKAGE_VERSION', '"{}"'.format(version))]
520

621
_journal = Extension('systemd/_journal',
722
define_macros = defines,
8-
libraries = ['systemd'],
923
sources = ['systemd/_journal.c',
10-
'systemd/pyutil.c'])
24+
'systemd/pyutil.c'],
25+
**lib('libsystemd', 'libsystemd-journal'))
1126
_reader = Extension('systemd/_reader',
1227
define_macros = defines,
13-
libraries = ['systemd'],
1428
sources = ['systemd/_reader.c',
1529
'systemd/pyutil.c',
16-
'systemd/strv.c'])
30+
'systemd/strv.c'],
31+
**lib('libsystemd', 'libsystemd-journal'))
1732
_daemon = Extension('systemd/_daemon',
1833
define_macros = defines,
19-
libraries = ['systemd'],
2034
sources = ['systemd/_daemon.c',
21-
'systemd/pyutil.c'])
35+
'systemd/pyutil.c'],
36+
**lib('libsystemd', 'libsystemd-daemon'))
2237
id128 = Extension('systemd/id128',
2338
define_macros = defines,
24-
libraries = ['systemd'],
2539
sources = ['systemd/id128.c',
26-
'systemd/pyutil.c'])
40+
'systemd/pyutil.c'],
41+
**lib('libsystemd', 'libsystemd-id128'))
2742
login = Extension('systemd/login',
2843
define_macros = defines,
29-
libraries = ['systemd'],
3044
sources = ['systemd/login.c',
3145
'systemd/pyutil.c',
32-
'systemd/strv.c'])
46+
'systemd/strv.c'],
47+
**lib('libsystemd', 'libsystemd-login'))
3348
setup (name = 'python-systemd',
3449
version = version,
3550
description = 'Native interface to the facilities of systemd',

0 commit comments

Comments
 (0)