]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
build: Always define ENABLE_* macros
authorLucas De Marchi <lucas.de.marchi@gmail.com>
Wed, 4 Dec 2024 07:04:09 +0000 (01:04 -0600)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 6 Dec 2024 21:06:42 +0000 (13:06 -0800)
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 <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/262
configure.ac
libkmod/libkmod-internal-file.h
libkmod/libkmod-signature.c
meson.build
shared/util.c
testsuite/test-modinfo.c
testsuite/test-util.c

index c605c112dd3387f664b67405490d68e8bbf8154e..368a59ce1004b5cfef4fde640dbe74872172fe28 100644 (file)
@@ -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])
@@ -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])
@@ -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])
@@ -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])
index d633822f4f2a4cc6f935812233a604535eb51ec1..a50d06e85402d2dfeaaa51c1768ba07d24e0b3c0 100644 (file)
@@ -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)
@@ -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)
@@ -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)
index 8cb596d611171349e92d44124b6083992aec36f2..4f5023edb993023e55116f7ee6987630bd96140e 100644 (file)
@@ -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
@@ -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;
index 3631dd2af6e575fdf772e710843974d01f8d7d4a..a5e84797e0b56c9463af22d3550a9c1ff977d82e 100644 (file)
@@ -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() ? '+' : '-')]
 
 #-------------------------------------------------------------------------------
@@ -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))
index 9a54c07efc93c30c761597e04a2626fdb4322079..4e3e7b5d3bc4e19de958636cf4eae070e770e31d 100644 (file)
@@ -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
        {},
index a8e8e552333363afa7c7f332cdbed5e2566da85a..22b6ea12243a84aff1576de98b9e829c85dc8a3a 100644 (file)
@@ -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")
index 84a04ad95344085ed97624c03ab2626769201b2e..d7bceead63434bfacd7254b15ff0843a2ebd13ef 100644 (file)
@@ -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 },