From: Jose Ignacio Tornos Martinez Date: Mon, 8 Jul 2024 11:41:24 +0000 (+0200) Subject: feat(dracut-install): configure if weak dep is still not supported in kmod X-Git-Tag: 103~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77c3efa67e1ad724a441eb3341b3fc8a3d9684b6;p=thirdparty%2Fdracut-ng.git feat(dracut-install): configure if weak dep is still not supported in kmod 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 --- diff --git a/configure b/configure index 9a313db61..a7b5ff680 100755 --- a/configure +++ b/configure @@ -144,6 +144,27 @@ if test "$enable_dracut_cpio" = "yes"; then fi fi +cat << EOF > weakdep_test.c +#include +#include + +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 diff --git a/src/install/dracut-install.c b/src/install/dracut-install.c index 860cce109..2cf3e08d6 100644 --- a/src/install/dracut-install.c +++ b/src/install/dracut-install.c @@ -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; }