From f4b936008505ef24efe3481845f6586709d7d425 Mon Sep 17 00:00:00 2001 From: Herman Semenoff Date: Thu, 30 Apr 2026 02:31:39 +0300 Subject: [PATCH] linux: fix building on Alpine Linux and many other distros --- meson.build | 32 ++++++++++++++++++++++++-------- meson_options.txt | 5 +++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/meson.build b/meson.build index 2c7018f..2e4b87e 100644 --- a/meson.build +++ b/meson.build @@ -92,16 +92,27 @@ if os_backend == 'linux' cdata.set10('HAVE_IDEVICE', true) endif + init_system = get_option('init_system') + udev_required = init_system == 'systemd' + udevrulesdir = get_option('udevrulesdir') if udevrulesdir == 'auto' - udev_dep = dependency('udev', required: true) - udevrulesdir = udev_dep.get_variable(pkgconfig: 'udev_dir') / 'rules.d' + udev_dep = dependency('udev', required: udev_required) + if udev_dep.found() + udevrulesdir = udev_dep.get_variable(pkgconfig: 'udev_dir') / 'rules.d' + else + udevrulesdir = '/lib/udev/rules.d' + endif endif udevhwdbdir = get_option('udevhwdbdir') if udevhwdbdir == 'auto' - udev_dep = dependency('udev', required: true) - udevhwdbdir = udev_dep.get_variable(pkgconfig: 'udev_dir') / 'hwdb.d' + udev_dep = dependency('udev', required: udev_required) + if udev_dep.found() + udevhwdbdir = udev_dep.get_variable(pkgconfig: 'udev_dir') / 'hwdb.d' + else + udevhwdbdir = '/lib/udev/hwdb.d' + endif endif endif @@ -116,10 +127,15 @@ if statedir == '' endif dbusdir = get_option('datadir') / 'dbus-1' -systemdsystemunitdir = get_option('systemdsystemunitdir') -if systemdsystemunitdir == '' - systemd_dep = dependency('systemd') - systemdsystemunitdir = systemd_dep.get_variable(pkgconfig: 'systemdsystemunitdir') +init_system = get_option('init_system') +if init_system == 'systemd' + systemdsystemunitdir = get_option('systemdsystemunitdir') + if systemdsystemunitdir == '' + systemd_dep = dependency('systemd') + systemdsystemunitdir = systemd_dep.get_variable(pkgconfig: 'systemdsystemunitdir') + endif +else + systemdsystemunitdir = '' endif datadir = get_option('datadir') diff --git a/meson_options.txt b/meson_options.txt index 7220d2f..304b60b 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -48,3 +48,8 @@ option('installed_tests', type : 'boolean', value : true, description : 'Install integration tests') +option('init_system', + type: 'combo', + choices: ['systemd', 'other'], + value: 'systemd', + description: 'Select init system')