From 6c6d8451d9f10a495b11f1ed186ee290c2d03104 Mon Sep 17 00:00:00 2001
From: Arnaud Ferraris <aferraris@debian.org>
Date: Sun, 9 Feb 2025 01:43:24 +0100
Subject: [PATCH] Add meson.build

This can ease installation, while providing enough flexibility to cover
both installation use-cases:
* systemd installs, using the service file and specific udev rules
* generics installs, using the basic udev rules only
---
 meson.build | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
 create mode 100644 meson.build

diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..4252ece
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,58 @@
+project(
+    'bootmac', 'c',
+    version: '0.6.0',
+    license : 'GPL-3.0-or-later',
+)
+
+prefix = get_option('prefix')
+bindir = prefix / get_option('bindir')
+libdir = prefix / get_option('libdir')
+
+pkg = import('pkgconfig')
+
+systemd = dependency('systemd', required : false)
+
+# udev is only used to get the rules location, we can have a fallback
+udev = dependency('udev', required : false)
+if udev.found()
+    udev_rules_dir = udev.get_variable(pkgconfig : 'udevdir') / 'rules.d'
+else
+    udev_rules_dir = libdir / 'udev' / 'rules.d'
+endif
+
+# By default, install the udev rules that execute bootmac directly
+bt_udev_rules = 'bootmac-bluetooth.rules'
+wifi_udev_rules = 'bootmac-wifi.rules'
+
+if systemd.found()
+    # On systemd-based system, install a specific udev rule for bluetooth, using
+    # unit activation and a template service we can instantiate for either
+    # bluetooth or wifi
+    systemd_system_unit_dir = systemd.get_variable(
+        pkgconfig : 'systemdsystemunitdir',
+        pkgconfig_define: ['prefix', prefix]
+    )
+
+    install_data(
+        'systemd/bootmac@.service',
+        install_dir: systemd_system_unit_dir
+    )
+
+    bt_udev_rules = 'systemd/bootmac-bluetooth.rules'
+endif
+
+install_data(
+    bt_udev_rules,
+    wifi_udev_rules,
+    install_dir: udev_rules_dir,
+    rename: [
+        '90-bootmac-bluetooth.rules',
+        '90-bootmac-wifi.rules'
+    ],
+)
+
+install_data(
+    'bootmac',
+    install_dir: bindir,
+    install_mode: 'rwxr-xr-x'
+)
-- 
GitLab