]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
meson: Allow to set dlopen option for compression libraries
authorLucas De Marchi <lucas.de.marchi@gmail.com>
Wed, 4 Dec 2024 07:19:32 +0000 (01:19 -0600)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 6 Dec 2024 21:15:20 +0000 (13:15 -0800)
Add a dlopen option that allows toggling what libraries libkmod should
attempt to dlopen. If -Ddlopen=foo is passed, it means that library is
required to build, regardless of -Dfoo=*. However that library will
only be linked in if it's not set as dlopen.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
[ with disagreement on the need to toggle each one individually,
  it'd be better to be all-or-nothing dlopen'ed ]
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/262
configure.ac
libkmod/libkmod-file-xz.c
libkmod/libkmod-file-zlib.c
libkmod/libkmod-file-zstd.c
meson.build
meson_options.txt

index 368a59ce1004b5cfef4fde640dbe74872172fe28..7e35f1be0f8a94d00ddfaba67d50af66acad03a9 100644 (file)
@@ -119,6 +119,7 @@ AS_IF([test "x$with_zstd" != "xno"], [
 ])
 CC_FEATURE_APPEND([with_features], [with_zstd], [ZSTD])
 AM_CONDITIONAL([ENABLE_ZSTD], [test "x$with_zstd" != "xno"])
+AC_DEFINE([ENABLE_ZSTD_DLOPEN], [0], [dlopen zstd])
 
 AC_ARG_WITH([xz],
        AS_HELP_STRING([--with-xz], [handle Xz-compressed modules @<:@default=disabled@:>@]),
@@ -133,6 +134,7 @@ AS_IF([test "x$with_xz" != "xno"], [
 ])
 CC_FEATURE_APPEND([with_features], [with_xz], [XZ])
 AM_CONDITIONAL([ENABLE_XZ], [test "x$with_xz" != "xno"])
+AC_DEFINE([ENABLE_XZ_DLOPEN], [0], [dlopen xz])
 
 AC_ARG_WITH([zlib],
        AS_HELP_STRING([--with-zlib], [handle gzipped modules @<:@default=disabled@:>@]),
@@ -147,6 +149,7 @@ AS_IF([test "x$with_zlib" != "xno"], [
 ])
 CC_FEATURE_APPEND([with_features], [with_zlib], [ZLIB])
 AM_CONDITIONAL([ENABLE_ZLIB], [test "x$with_zlib" != "xno"])
+AC_DEFINE([ENABLE_ZLIB_DLOPEN], [0], [dlopen zlib])
 
 AC_ARG_WITH([openssl],
        AS_HELP_STRING([--with-openssl], [handle PKCS7 signatures @<:@default=disabled@:>@]),
index 3f44b43dbcd509a31de0c7ac886ef87c9ae4adcf..f769f835e8e65aad9bbc7f6ff668bb8955c99644 100644 (file)
@@ -3,8 +3,7 @@
  * Copyright © 2024 Intel Corporation
  */
 
-/* TODO: replace with build system define once supported */
-#define DLSYM_LOCALLY_ENABLED 0
+#define DLSYM_LOCALLY_ENABLED ENABLE_XZ_DLOPEN
 
 #include <errno.h>
 #include <lzma.h>
index fd382939aaea6c3f74299fd6644e8a2eefeadf21..f8ead1b91ccb94d6a788077f4e8039e2ba9499cd 100644 (file)
@@ -3,8 +3,7 @@
  * Copyright © 2024 Intel Corporation
  */
 
-/* TODO: replace with build system define once supported */
-#define DLSYM_LOCALLY_ENABLED 0
+#define DLSYM_LOCALLY_ENABLED ENABLE_ZLIB_DLOPEN
 
 #include <errno.h>
 #include <stdio.h>
index 5bccf761c24523d740b386577fdb977886838f4a..a2eece7d50d1ef756f58a7c1191851f70eaed9e1 100644 (file)
@@ -3,8 +3,7 @@
  * Copyright © 2024 Intel Corporation
  */
 
-/* TODO: replace with build system define once supported */
-#define DLSYM_LOCALLY_ENABLED 0
+#define DLSYM_LOCALLY_ENABLED ENABLE_ZSTD_DLOPEN
 
 #include <errno.h>
 #include <stdio.h>
index 25029d6c93f032527e322064a5c6338782941c09..64288dd94deba84519c334cb377a56fb0c7a7556 100644 (file)
@@ -176,6 +176,9 @@ module_signatures = ''
 features = []
 dep_map = {}
 
+# keep in sync with meson_options.txt
+dlopen_all = get_option('dlopen').contains('all')
+
 #-------------------------------------------------------------------------------
 # Directories
 #-------------------------------------------------------------------------------
@@ -299,10 +302,19 @@ foreach tuple : _compression
   pkg_dep = tuple[1]
   pkg_dep_version = tuple[2]
 
+  dlopen = dlopen_all or get_option('dlopen').contains(opt)
+  if not dlopen_all and dlopen and get_option(opt).disabled()
+    error('Incompatiable options: dlopen=@0@ for disabled @0@'.format(opt))
+  endif
+
   dep = dependency(pkg_dep, version : pkg_dep_version, required : get_option(opt))
   have = dep.found()
+  if have and dlopen
+    dep = dep.partial_dependency(compile_args : true, includes : true)
+  endif
 
   cdata.set10('ENABLE_' + opt.to_upper(), have)
+  cdata.set10('ENABLE_' + opt.to_upper() + '_DLOPEN', have and dlopen)
 
   if have
     module_compressions += '@0@ '.format(opt)
@@ -567,6 +579,7 @@ summary({
   'build-tests'     : get_option('build-tests'),
   'manpages'        : get_option('manpages'),
   'docs'            : get_option('docs'),
+  'dlopen'          : get_option('dlopen'),
 }, section : 'Options')
 
 summary({
index 0522d95c9f7918d2d410beee06a9c11971c7033c..3d41fae2ec3afcae6e424cf0b3150f61a394fdfd 100644 (file)
@@ -67,6 +67,14 @@ option(
   description : 'Build the tools - kmod, depmod, lsmod ... Default: true',
 )
 
+option(
+  'dlopen',
+  type : 'array',
+  choices : ['zstd', 'xz', 'zlib', 'all'],
+  value : [],
+  description : 'Libraries to dlopen rather than linking. Use \'all\' to . Default: none',
+)
+
 option(
   'logging',
   type : 'boolean',