]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
feat(dracut-install): configure if weak dep is still not supported in kmod
authorJose Ignacio Tornos Martinez <jtornosm@redhat.com>
Mon, 8 Jul 2024 11:41:24 +0000 (13:41 +0200)
committerLaszlo Gombos <laszlo.gombos@gmail.com>
Mon, 8 Jul 2024 12:02:06 +0000 (08:02 -0400)
The weak dependency feature is new and better be backward compatible.
So check in configure stage if the kmod used includes the weak dependency
feature so as not to include it here and avoid compilation errors.

Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
configure
src/install/dracut-install.c

index 9a313db61d53552a8dae506aab7c4440e5064844..a7b5ff6805634ae8ecf1aa4319e6002659cc054c 100755 (executable)
--- a/configure
+++ b/configure
@@ -144,6 +144,27 @@ if test "$enable_dracut_cpio" = "yes"; then
     fi
 fi
 
+cat << EOF > weakdep_test.c
+#include <stddef.h>
+#include <libkmod.h>
+
+int main(void) {
+  struct kmod_module *mod = NULL;
+  struct kmod_list *modweak = NULL;
+
+  return kmod_module_get_weakdeps(mod, &modweak);
+}
+EOF
+
+# shellcheck disable=SC2086,SC2046
+${CC} $CFLAGS $LDFLAGS weakdep_test.c $(${PKG_CONFIG} --libs libkmod) > /dev/null 2>&1
+ret=$?
+rm -f weakdep_test.c a.out
+
+if test $ret -eq 0; then
+    KMOD_CFLAGS_EXTRA+=" -DCONFIG_WEAKDEP"
+fi
+
 cat > Makefile.inc.$$ << EOF
 prefix ?= ${prefix}
 libdir ?= ${libdir:-${prefix}/lib}
@@ -154,7 +175,7 @@ mandir ?= ${mandir:-${prefix}/share/man}
 enable_documentation ?= ${enable_documentation:-yes}
 enable_dracut_cpio ?= ${enable_dracut_cpio}
 bindir ?= ${bindir:-${prefix}/bin}
-KMOD_CFLAGS ?= $(${PKG_CONFIG} --cflags " libkmod >= 23 ")
+KMOD_CFLAGS ?= $(${PKG_CONFIG} --cflags " libkmod >= 23 ") ${KMOD_CFLAGS_EXTRA}
 KMOD_LIBS ?= $(${PKG_CONFIG} --libs " libkmod >= 23 ")
 FTS_LIBS ?= ${FTS_LIBS}
 EOF
index 860cce109e5d71affabf85b8487a3550d9fd2acb..2cf3e08d64290d1ee6b4c1993472ac897f1ab6d9 100644 (file)
@@ -1693,7 +1693,9 @@ static int install_dependent_module(struct kmod_ctx *ctx, struct kmod_module *mo
                 _cleanup_kmod_module_unref_list_ struct kmod_list *modlist = NULL;
                 _cleanup_kmod_module_unref_list_ struct kmod_list *modpre = NULL;
                 _cleanup_kmod_module_unref_list_ struct kmod_list *modpost = NULL;
+#ifdef CONFIG_WEAKDEP
                 _cleanup_kmod_module_unref_list_ struct kmod_list *modweak = NULL;
+#endif
                 log_debug("dracut_install '%s' '%s' OK", path, &path[kerneldirlen]);
                 install_firmware(mod);
                 modlist = kmod_module_get_dependencies(mod);
@@ -1707,11 +1709,13 @@ static int install_dependent_module(struct kmod_ctx *ctx, struct kmod_module *mo
                                 *err = *err ? : r;
                         }
                 }
+#ifdef CONFIG_WEAKDEP
                 if (*err == 0) {
                         *err = kmod_module_get_weakdeps(mod, &modweak);
                         if (*err == 0)
                                 *err = install_dependent_modules(ctx, modweak, NULL);
                 }
+#endif
         } else {
                 log_error("dracut_install '%s' '%s' ERROR", path, &path[kerneldirlen]);
         }
@@ -1770,7 +1774,9 @@ static int install_module(struct kmod_ctx *ctx, struct kmod_module *mod)
         _cleanup_kmod_module_unref_list_ struct kmod_list *modlist = NULL;
         _cleanup_kmod_module_unref_list_ struct kmod_list *modpre = NULL;
         _cleanup_kmod_module_unref_list_ struct kmod_list *modpost = NULL;
+#ifdef CONFIG_WEAKDEP
         _cleanup_kmod_module_unref_list_ struct kmod_list *modweak = NULL;
+#endif
         const char *path = NULL;
         const char *name = NULL;
 
@@ -1828,11 +1834,13 @@ static int install_module(struct kmod_ctx *ctx, struct kmod_module *mod)
                         ret = ret ? : r;
                 }
         }
+#ifdef CONFIG_WEAKDEP
         if (ret == 0) {
                 ret = kmod_module_get_weakdeps(mod, &modweak);
                 if (ret == 0)
                         ret = install_dependent_modules(ctx, modweak, NULL);
         }
+#endif
 
         return ret;
 }