Skip to content

Commit

Permalink
build: Always define ENABLE_* macros
Browse files Browse the repository at this point in the history
Define either to 0 or 1 so codebase is forced to used `#if ENABLE_*` or
similar. It's confusing to have some leaving undefined and others
defining as 0 or 1.

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 9a3930e commit 01d9c6a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 20 deletions.
12 changes: 8 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ AC_ARG_WITH([zstd],
[], [with_zstd=no])
AS_IF([test "x$with_zstd" != "xno"], [
PKG_CHECK_MODULES([libzstd], [libzstd >= 1.4.4], [LIBS="$LIBS $libzstd_LIBS"])
AC_DEFINE([ENABLE_ZSTD], [1], [Enable Zstandard for modules.])
AC_DEFINE([ENABLE_ZSTD], [1], [Zstandard for modules.])
module_compressions="zstd $module_compressions"
], [
AC_DEFINE([ENABLE_ZSTD], [0], [Zstandard for modules.])
AC_MSG_NOTICE([Zstandard support not requested])
])
CC_FEATURE_APPEND([with_features], [with_zstd], [ZSTD])
Expand All @@ -124,9 +125,10 @@ AC_ARG_WITH([xz],
[], [with_xz=no])
AS_IF([test "x$with_xz" != "xno"], [
PKG_CHECK_MODULES([liblzma], [liblzma >= 4.99], [LIBS="$LIBS $liblzma_LIBS"])
AC_DEFINE([ENABLE_XZ], [1], [Enable Xz for modules.])
AC_DEFINE([ENABLE_XZ], [1], [xz for modules.])
module_compressions="xz $module_compressions"
], [
AC_DEFINE([ENABLE_XZ], [0], [xz for modules.])
AC_MSG_NOTICE([Xz support not requested])
])
CC_FEATURE_APPEND([with_features], [with_xz], [XZ])
Expand All @@ -137,9 +139,10 @@ AC_ARG_WITH([zlib],
[], [with_zlib=no])
AS_IF([test "x$with_zlib" != "xno"], [
PKG_CHECK_MODULES([zlib], [zlib], [LIBS="$LIBS $zlib_LIBS"])
AC_DEFINE([ENABLE_ZLIB], [1], [Enable zlib for modules.])
AC_DEFINE([ENABLE_ZLIB], [1], [zlib for modules.])
module_compressions="gzip $module_compressions"
], [
AC_DEFINE([ENABLE_ZLIB], [0], [zlib for modules.])
AC_MSG_NOTICE([zlib support not requested])
])
CC_FEATURE_APPEND([with_features], [with_zlib], [ZLIB])
Expand All @@ -150,9 +153,10 @@ AC_ARG_WITH([openssl],
[], [with_openssl=no])
AS_IF([test "x$with_openssl" != "xno"], [
PKG_CHECK_MODULES([libcrypto], [libcrypto >= 1.1.0], [LIBS="$LIBS $libcrypto_LIBS"])
AC_DEFINE([ENABLE_OPENSSL], [1], [Enable openssl for modinfo.])
AC_DEFINE([ENABLE_OPENSSL], [1], [openssl for modinfo.])
module_signatures="PKCS7 $module_signatures"
], [
AC_DEFINE([ENABLE_OPENSSL], [0], [openssl for modinfo.])
AC_MSG_NOTICE([openssl support not requested])
])
CC_FEATURE_APPEND([with_features], [with_openssl], [LIBCRYPTO])
Expand Down
6 changes: 3 additions & 3 deletions libkmod/libkmod-internal-file.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct kmod_file {
struct kmod_elf *elf;
};

#ifdef ENABLE_XZ
#if ENABLE_XZ
int kmod_file_load_xz(struct kmod_file *file);
#else
static inline int kmod_file_load_xz(struct kmod_file *file)
Expand All @@ -29,7 +29,7 @@ static inline int kmod_file_load_xz(struct kmod_file *file)
}
#endif

#ifdef ENABLE_ZLIB
#if ENABLE_ZLIB
int kmod_file_load_zlib(struct kmod_file *file);
#else
static inline int kmod_file_load_zlib(struct kmod_file *file)
Expand All @@ -38,7 +38,7 @@ static inline int kmod_file_load_zlib(struct kmod_file *file)
}
#endif

#ifdef ENABLE_ZSTD
#if ENABLE_ZSTD
int kmod_file_load_zstd(struct kmod_file *file);
#else
static inline int kmod_file_load_zstd(struct kmod_file *file)
Expand Down
4 changes: 2 additions & 2 deletions libkmod/libkmod-signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <endian.h>
#include <inttypes.h>
#ifdef ENABLE_OPENSSL
#if ENABLE_OPENSSL
#include <openssl/pkcs7.h>
#include <openssl/ssl.h>
#endif
Expand Down Expand Up @@ -109,7 +109,7 @@ static bool fill_default(const char *mem, off_t size,
return true;
}

#ifdef ENABLE_OPENSSL
#if ENABLE_OPENSSL

struct pkcs7_private {
PKCS7 *pkcs7;
Expand Down
8 changes: 4 additions & 4 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -289,23 +289,23 @@ endif

zstd = dependency('libzstd', version : '>= 1.4.4', required : get_option('zstd'))
if zstd.found()
cdata.set('ENABLE_ZSTD', true)
module_compressions += 'zstd '
endif
cdata.set10('ENABLE_ZSTD', zstd.found())
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
cdata.set10('ENABLE_XZ', xz.found())
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
cdata.set10('ENABLE_ZLIB', zlib.found())
features += ['@0@ZLIB'.format(zlib.found() ? '+' : '-')]

#-------------------------------------------------------------------------------
Expand All @@ -314,11 +314,11 @@ 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
cdata.set10('ENABLE_OPENSSL', crypto.found())
features += ['@0@LIBCRYPTO'.format(crypto.found() ? '+' : '-')]

cdata.set_quoted('KMOD_FEATURES', ' '.join(features))
Expand Down
6 changes: 3 additions & 3 deletions shared/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ static const struct kmod_ext {
size_t len;
} kmod_exts[] = {
{ KMOD_EXTENSION_UNCOMPRESSED, sizeof(KMOD_EXTENSION_UNCOMPRESSED) - 1 },
#ifdef ENABLE_ZLIB
#if ENABLE_ZLIB
{ ".ko.gz", sizeof(".ko.gz") - 1 },
#endif
#ifdef ENABLE_XZ
#if ENABLE_XZ
{ ".ko.xz", sizeof(".ko.xz") - 1 },
#endif
#ifdef ENABLE_ZSTD
#if ENABLE_ZSTD
{ ".ko.zst", sizeof(".ko.zst") - 1 },
#endif
{},
Expand Down
2 changes: 1 addition & 1 deletion testsuite/test-modinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static const char *progname = TOOLS_DIR "/modinfo";
#define DEFINE_MODINFO_GENERIC_TEST(_field) \
DEFINE_MODINFO_TEST(_field, , "/mod-simple.ko")

#ifdef ENABLE_OPENSSL
#if ENABLE_OPENSSL
#define DEFINE_MODINFO_SIGN_TEST(_field) \
DEFINE_MODINFO_TEST(_field, -openssl, "/mod-simple-sha1.ko", \
"/mod-simple-sha256.ko", "/mod-simple-pkcs7.ko")
Expand Down
6 changes: 3 additions & 3 deletions testsuite/test-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ static int test_path_ends_with_kmod_ext(const struct test *t)
bool res;
} teststr[] = {
{ "/bla.ko", true },
#ifdef ENABLE_ZLIB
#if ENABLE_ZLIB
{ "/bla.ko.gz", true },
#endif
#ifdef ENABLE_XZ
#if ENABLE_XZ
{ "/bla.ko.xz", true },
#endif
#ifdef ENABLE_ZSTD
#if ENABLE_ZSTD
{ "/bla.ko.zst", true },
#endif
{ "/bla.ko.x", false },
Expand Down

0 comments on commit 01d9c6a

Please sign in to comment.