Skip to content

Commit

Permalink
meson: Allow to set dlopen option for compression libraries
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Emil Velikov <[email protected]>
Link: #262
  • Loading branch information
lucasdemarchi committed Dec 6, 2024
1 parent 8d39823 commit c22cce1
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
3 changes: 3 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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@:>@]),
Expand All @@ -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@:>@]),
Expand All @@ -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@:>@]),
Expand Down
3 changes: 1 addition & 2 deletions libkmod/libkmod-file-xz.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 1 addition & 2 deletions libkmod/libkmod-file-zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 1 addition & 2 deletions libkmod/libkmod-file-zstd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
13 changes: 13 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ module_signatures = ''
features = []
dep_map = {}

# keep in sync with meson_options.txt
dlopen_all = get_option('dlopen').contains('all')

#-------------------------------------------------------------------------------
# Directories
#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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({
Expand Down
8 changes: 8 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit c22cce1

Please sign in to comment.