]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
meson: allow building the manpages
authorEmil Velikov <emil.l.velikov@gmail.com>
Mon, 2 Sep 2024 17:58:35 +0000 (18:58 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 3 Sep 2024 01:13:54 +0000 (20:13 -0500)
Not as brief as the pipeline and pattern matching that (auto)make can
do, although it's fully functional ;-)

v2:
 - move man/meson.build
 - move script under scripts/

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/86
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Makefile.am
man/meson.build [new file with mode: 0644]
meson.build
meson_options.txt
scripts/build-scdoc.sh [new file with mode: 0644]

index 74b1130391719aa5e191e55a31aa6e746b3590ed..1a518585841e8dc6dc8e4c5272ccb4b46442efe0 100644 (file)
@@ -17,9 +17,11 @@ export GCC_COLORS
 
 # meson bits
 EXTRA_DIST += \
+       man/meson.build \
        meson.build \
        meson_options.txt \
        testsuite/meson.build \
+       scripts/build-scdoc.sh \
        scripts/kmod-symlink.sh
 
 AM_CPPFLAGS = \
diff --git a/man/meson.build b/man/meson.build
new file mode 100644 (file)
index 0000000..f2c2c8d
--- /dev/null
@@ -0,0 +1,56 @@
+scdoc = find_program('scdoc')
+
+_man_pages = [
+  ['5', 'depmod.d'],
+  ['5', 'modprobe.d'],
+  ['5', 'modules.dep'],
+  ['8', 'depmod'],
+  ['8', 'insmod'],
+  ['8', 'kmod'],
+  ['8', 'lsmod'],
+  ['8', 'modinfo'],
+  ['8', 'modprobe'],
+  ['8', 'rmmod'],
+]
+foreach tuple : _man_pages
+  section = tuple[0]
+  man = tuple[1]
+
+  custom_target(
+    'man_@0@_@1@'.format(section, man),
+    command : [
+      build_scdoc,
+      scdoc,
+      '@INPUT@',
+      's|@SYSCONFDIR@|@0@|g;'.format(sysconfdir) +
+      's|@DISTCONFDIR@|@0@|g;'.format(distconfdir) +
+      's|@MODULE_DIRECTORY@|@0@|g;'.format(moduledir),
+    ],
+    input : '@0@.@1@.scd'.format(man, section),
+    output : '@0@.@1@'.format(man, section),
+    capture : true,
+    build_by_default : get_option('manpages'),
+    install : true,
+    install_dir : join_paths(get_option('mandir'), 'man@0@'.format(section))
+  )
+endforeach
+
+_man_aliases = [
+  ['5', 'modules.dep.bin', 'modules.dep.5'],
+]
+
+foreach tuple : _man_aliases
+  section = tuple[0]
+  man = tuple[1]
+  dest = tuple[2]
+
+  custom_target(
+    'man_@0@_@1@'.format(section, man),
+    command : ['echo', '.so @0@'.format(dest)],
+    output : '@0@.@1@'.format(man, section),
+    capture : true,
+    build_by_default : get_option('manpages'),
+    install : true,
+    install_dir : join_paths(get_option('mandir'), 'man@0@'.format(section))
+  )
+endforeach
index 63002dc752c932544feb82caf83a044b6b50162d..3aee0eb40958a7e5e4f401969340018b123e2618 100644 (file)
@@ -407,6 +407,15 @@ if get_option('build-tests')
   subdir('testsuite')
 endif
 
+# ------------------------------------------------------------------
+# documentation
+# ------------------------------------------------------------------
+
+if get_option('manpages')
+  build_scdoc = find_program('scripts/build-scdoc.sh')
+  subdir('man')
+endif
+
 summary({
   'moduledir'   : moduledir,
   'prefix'      : get_option('prefix'),
@@ -422,6 +431,7 @@ summary({
   'logging'     : get_option('logging'),
   'debug'       : get_option('debug-messages'),
   'build-tests' : get_option('build-tests'),
+  'man'         : get_option('manpages'),
 }, section : 'Options')
 
 summary({
index f8607ece2a807318db6480ce73838476da3b50f6..7de6258eb9ac920ce81277a6a77e1582c9d366ed 100644 (file)
@@ -78,3 +78,10 @@ option(
   value : false,
   description : 'Always build the test suite. Default: false',
 )
+
+option(
+  'manpages',
+  type : 'boolean',
+  value : true,
+  description : 'Build the manpages. Default: true',
+)
diff --git a/scripts/build-scdoc.sh b/scripts/build-scdoc.sh
new file mode 100644 (file)
index 0000000..66aa673
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+set -euo pipefail
+
+SCDOC=$1
+INPUT=$2
+SED_PATTERN=$3
+
+cat $INPUT | sed -e $SED_PATTERN | $SCDOC