|
20 | 20 | from __future__ import annotations |
21 | 21 |
|
22 | 22 | from os import environ |
23 | | -from subprocess import DEVNULL, PIPE, CalledProcessError |
| 23 | +from subprocess import DEVNULL, PIPE |
24 | 24 | from subprocess import run as subprocess_run |
25 | 25 | from typing import List, Optional, Tuple |
26 | 26 |
|
|
30 | 30 | c_macros: List[Tuple[str, Optional[str]]] = [] |
31 | 31 |
|
32 | 32 |
|
33 | | -def get_libsystemd_version() -> Tuple[int, int, int]: |
| 33 | +def get_libsystemd_version() -> int: |
34 | 34 | process = subprocess_run( |
35 | | - args=('ldconfig', '-f', '/dev/null', '-C', '/dev/null', |
36 | | - '-v', '-N', '-X'), |
| 35 | + args=('pkg-config', '--modversion', 'libsystemd'), |
37 | 36 | stderr=DEVNULL, |
38 | 37 | stdout=PIPE, |
| 38 | + check=True, |
39 | 39 | ) |
40 | 40 |
|
41 | | - try: |
42 | | - process.check_returncode() |
43 | | - except CalledProcessError: |
44 | | - return 0, 0, 0 |
45 | | - |
46 | 41 | result_str = process.stdout.decode('utf-8') |
47 | 42 |
|
48 | | - for line in result_str.splitlines(): |
49 | | - if 'libsystemd.so' in line: |
50 | | - version_str = line.split('libsystemd.so')[-1] |
51 | | - semver_strs = version_str.split('.') |
52 | | - return ( |
53 | | - int(semver_strs[1]), |
54 | | - int(semver_strs[2]), |
55 | | - int(semver_strs[3]), |
56 | | - ) |
57 | | - |
58 | | - return 0, 0, 0 |
| 43 | + return int(result_str) |
59 | 44 |
|
60 | 45 |
|
61 | 46 | if not environ.get('PYTHON_SDBUS_USE_IGNORE_SYSTEMD_VERSION'): |
62 | | - LIBSYSTEMD_MAJOR, LIBSYSTEMD_MINOR, LIBSYTEMD_PATCH \ |
63 | | - = get_libsystemd_version() |
| 47 | + systemd_version = get_libsystemd_version() |
64 | 48 |
|
65 | | - if LIBSYSTEMD_MAJOR <= 0 and LIBSYSTEMD_MINOR < 29: |
| 49 | + if systemd_version < 246: |
66 | 50 | c_macros.append(('LIBSYSTEMD_NO_VALIDATION_FUNCS', None)) |
67 | 51 |
|
68 | | - if LIBSYSTEMD_MAJOR <= 0 and LIBSYSTEMD_MINOR < 31: |
| 52 | + if systemd_version < 248: |
69 | 53 | c_macros.append(('LIBSYSTEMD_NO_OPEN_USER_MACHINE', None)) |
70 | 54 |
|
71 | | -link_arguments: List[str] = ['-lsystemd'] |
| 55 | + |
| 56 | +def get_link_arguments() -> List[str]: |
| 57 | + process = subprocess_run( |
| 58 | + args=('pkg-config', '--libs-only-l', 'libsystemd'), |
| 59 | + stderr=DEVNULL, |
| 60 | + stdout=PIPE, |
| 61 | + check=True, |
| 62 | + ) |
| 63 | + |
| 64 | + result_str = process.stdout.decode('utf-8') |
| 65 | + |
| 66 | + return result_str.rstrip(' \n').split(' ') |
| 67 | + |
| 68 | + |
| 69 | +link_arguments: List[str] = get_link_arguments() |
72 | 70 |
|
73 | 71 | if environ.get('PYTHON_SDBUS_USE_STATIC_LINK'): |
74 | 72 | # Link statically against libsystemd and libcap |
75 | | - link_arguments = ['-Wl,-Bstatic', '-lsystemd', '-lcap', |
| 73 | + link_arguments = ['-Wl,-Bstatic', *link_arguments, '-lcap', |
76 | 74 | '-Wl,-Bdynamic', '-lrt', '-lpthread'] |
77 | 75 |
|
78 | 76 | link_arguments.append('-flto') |
|
0 commit comments