]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
meson: add support for the tools
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)
Nothing too spectacular, apart from a few meson quirks:
 - one can use both_libraries() alas, "install: true" will also install
   the static library, which we do not want
 - need to workaround kmod.pc empty variables, introduced in 1.4.0
 - wrapper script is needed for the symlink creation - see wrapper
   script for details
 - resulting binary exports optarg/optind/stderr/stdout and more

v2:
 - add kmod bash-completion hunk

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
meson.build
meson_options.txt
scripts/kmod-symlink.sh [new file with mode: 0755]

index 1c294ca43ef820a945e1d7453c637be369ddf3cc..969a9ff6e7dd17aea3b097c7023380eff3857bb8 100644 (file)
@@ -18,7 +18,8 @@ export GCC_COLORS
 # meson bits
 EXTRA_DIST += \
        meson.build \
-       meson_options.txt
+       meson_options.txt \
+       scripts/kmod-symlink.sh
 
 AM_CPPFLAGS = \
        -include $(top_builddir)/config.h \
index e20e66dbc4c34302e6244da67231d898506bd96c..65f4511e6ee748e1c3ef7fbcd27eaf2b7725400b 100644 (file)
@@ -153,6 +153,9 @@ add_project_link_arguments(
 # Options
 ################################################################################
 
+module_compressions = ''
+module_signatures = ''
+
 features = []
 
 #-------------------------------------------------------------------------------
@@ -177,6 +180,22 @@ if moduledir == ''
 endif
 cdata.set_quoted('MODULE_DIRECTORY', moduledir)
 
+bashcompletiondir = get_option('bashcompletiondir')
+if bashcompletiondir == ''
+  bashcompletion = dependency('bash-completion', required : false)
+  if bashcompletion.found()
+    bashcompletiondir = bashcompletion.get_variable(pkgconfig : 'completionsdir')
+  else
+    bashcompletiondir = join_paths(get_option('prefix'), get_option('datadir'),
+                                   'bash-completion/completions')
+  endif
+endif
+
+install_data(
+  files('shell-completion/bash/kmod'),
+  install_dir : bashcompletiondir,
+)
+
 #-------------------------------------------------------------------------------
 # Compression support
 #-------------------------------------------------------------------------------
@@ -184,18 +203,21 @@ cdata.set_quoted('MODULE_DIRECTORY', moduledir)
 zstd = dependency('libzstd', version : '>= 1.4.4', required : get_option('zstd'))
 if zstd.found()
   cdata.set('ENABLE_ZSTD', true)
+  module_compressions += 'zstd '
 endif
 features += ['@0@ZSTD'.format(zstd.found() ? '+' : '-')]
 
 xz = dependency('liblzma', version : '>= 4.99', required : get_option('xz'))
 if xz.found()
   cdata.set('ENABLE_XZ', true)
+  module_compressions += 'xz '
 endif
 features += ['@0@XZ'.format(xz.found() ? '+' : '-')]
 
 zlib = dependency('zlib', required : get_option('zlib'))
 if zlib.found()
   cdata.set('ENABLE_ZLIB', true)
+  module_compressions += 'zlib '
 endif
 features += ['@0@ZLIB'.format(zlib.found() ? '+' : '-')]
 
@@ -206,6 +228,9 @@ features += ['@0@ZLIB'.format(zlib.found() ? '+' : '-')]
 crypto = dependency('libcrypto', version : '>= 1.1.0', required : get_option('openssl'))
 if crypto.found()
   cdata.set('ENABLE_OPENSSL', true)
+  module_signatures = 'PKCS7 legacy'
+else
+  module_signatures = 'legacy'
 endif
 features += ['@0@LIBCRYPTO'.format(crypto.found() ? '+' : '-')]
 
@@ -301,6 +326,73 @@ pkg.generate(
   requires_private : libkmod_deps,
 )
 
+libkmod_internal = static_library(
+  'kmod-internal',
+  objects : libkmod.extract_all_objects(recursive : true),
+  dependencies : libkmod_deps,
+  install : false,
+)
+
+kmod_sources = files(
+  'tools/depmod.c',
+  'tools/insmod.c',
+  'tools/kmod.c',
+  'tools/kmod.h',
+  'tools/log.c',
+  'tools/log.h',
+  'tools/lsmod.c',
+  'tools/modinfo.c',
+  'tools/modprobe.c',
+  'tools/rmmod.c',
+  'tools/static-nodes.c',
+)
+
+kmod = executable(
+  'kmod',
+  kmod_sources,
+  link_with : [libshared, libkmod_internal],
+  gnu_symbol_visibility : 'hidden',
+  build_by_default : get_option('tools'),
+  install : get_option('tools'),
+)
+
+_kmod_variables = [
+  'sysconfdir=' + sysconfdir,
+  'distconfdir=' + distconfdir,
+  'module_directory=' + moduledir,
+  'module_signatures=' + module_signatures,
+]
+
+# XXX: Support for empty variables was added in meson v1.4.0.
+# pkgconf behaves identically on missing and empty variable.
+if module_compressions != ''
+  _kmod_variables += ['module_compressions=' + module_compressions]
+endif
+
+pkg.generate(
+  name : 'kmod',
+  description : 'Tools to deal with kernel modules',
+  install_dir : join_paths(get_option('datadir'), 'pkgconfig'),
+  variables : _kmod_variables,
+)
+
+_tools = [
+  'depmod',
+  'insmod',
+  'lsmod',
+  'modinfo',
+  'modprobe',
+  'rmmod',
+]
+
+kmod_symlink = find_program('scripts/kmod-symlink.sh')
+foreach tool : _tools
+  if get_option('tools')
+    symlink = join_paths(get_option('bindir'), tool)
+    meson.add_install_script(kmod_symlink, symlink)
+  endif
+endforeach
+
 summary({
   'moduledir'   : moduledir,
   'prefix'      : get_option('prefix'),
@@ -312,6 +404,7 @@ summary({
 }, section : 'Directories')
 
 summary({
+  'tools'       : get_option('tools'),
   'logging'     : get_option('logging'),
   'debug'       : get_option('debug-messages'),
 }, section : 'Options')
index e618abc3b47b32691b0897663de1e5e28cadf683..0153d0b48599b4f477ab7d344dc4991f7064aa11 100644 (file)
@@ -12,6 +12,12 @@ option(
   description : 'Directory to look for kernel modules. Default: /lib/modules',
 )
 
+option(
+  'bashcompletiondir',
+  type : 'string',
+  description : 'Bash completions directory.',
+)
+
 # Compression options
 option(
   'zstd',
@@ -42,6 +48,13 @@ option(
   description : 'Openssl support, PKCS7 signatures. Default: disabled',
 )
 
+option(
+  'tools',
+  type : 'boolean',
+  value : true,
+  description : 'Build the tools - kmod, depmod, lsmod ... Default: true',
+)
+
 option(
   'logging',
   type : 'boolean',
diff --git a/scripts/kmod-symlink.sh b/scripts/kmod-symlink.sh
new file mode 100755 (executable)
index 0000000..1f97bc5
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+set -euo pipefail
+
+# Dummy wrapper script, since that's the meson way. Aka, there is no access to
+# DESTDIR from within meson nor any other way to check/fetch it.
+#
+# For context read through https://github.com/mesonbuild/meson/issues/9
+
+ln -sf kmod "$MESON_INSTALL_DESTDIR_PREFIX/$1"