]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
UBUNTU: [Packaging] support standalone dkms module builds
authorYou-Sheng Yang (vicamo) <vicamo.yang@canonical.com>
Wed, 25 May 2022 11:23:00 +0000 (13:23 +0200)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Tue, 31 May 2022 16:30:49 +0000 (18:30 +0200)
BugLink: https://bugs.launchpad.net/bugs/1969434
Signed-off-by: You-Sheng Yang (vicamo) <vicamo.yang@canonical.com>
Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
debian/control.d/flavour-module.stub [new file with mode: 0644]
debian/rules
debian/rules.d/0-common-vars.mk
debian/rules.d/2-binary-arch.mk
debian/scripts/control-create

diff --git a/debian/control.d/flavour-module.stub b/debian/control.d/flavour-module.stub
new file mode 100644 (file)
index 0000000..2810f83
--- /dev/null
@@ -0,0 +1,19 @@
+
+Package: linux-modules-MODULE-PKGVER-ABINUM-FLAVOUR
+Build-Profiles: <!stage1>
+Architecture: ARCH
+Section: kernel
+Priority: optional
+Depends:
+ ${misc:Depends},
+ linux-image-PKGVER-ABINUM-FLAVOUR | linux-image-unsigned-PKGVER-ABINUM-FLAVOUR,
+Built-Using: ${linux:BuiltUsing}
+Description: Linux kernel MODULE modules for version PKGVER-ABINUM
+ This package provides the Linux kernel MODULE modules for version
+ PKGVER-ABINUM.
+ .
+ You likely do not want to install this package directly. Instead, install the
+ one of the linux-modules-MODULE-FLAVOUR* meta-packages,
+ which will ensure that upgrades work correctly, and that supporting packages are
+ also installed.
+
index eca69cdc98a3e97801f6d97d42a8bf3203f035e7..540e7a3cfccf59dcb7fc31d31005e917d92748a2 100755 (executable)
@@ -40,6 +40,11 @@ do_tools_host?=false
 do_tools_perf_jvmti?=false
 do_enforce_all?=false
 
+# Default settings for DKMS modules.
+$(foreach _m,$(all_dkms_modules), \
+  $(eval do_$(_m) ?= $(if $(filter $(_m),$(filter-out $(dkms_exclude),$(dkms_include) $(subst any,$(_m),$(subst $(arch),$(_m),$(dkms_$(_m)_archs))))),true,false)) \
+)
+
 # Don't build tools in a cross compile environment.
 ifneq ($(DEB_HOST_ARCH),$(DEB_BUILD_ARCH))
        do_tools=false
@@ -74,8 +79,7 @@ endif
 #  - disable dkms builds as the versions used may have been deleted
 ifneq ($(filter autopkgtest,$(DEB_BUILD_PROFILES)),)
        flavours := $(firstword $(flavours))
-       do_zfs=false
-       do_v4l2loopback=false
+       $(foreach _m,$(all_dkms_modules),$(eval do_$(_m) = false))
 endif
 
 # Being used to build a mainline build -- turn off things which do not work.
@@ -97,13 +101,11 @@ ifneq ($(do_tools),true)
        do_tools_host=
 endif
 
-ifeq ($(do_zfs),false)
-       do_zfs_disable:=$(shell for m in $$(cat $(DROOT)/zfs-modules.ignore); do grep -qxF $$m $(prev_abidir)/../modules.ignore 2>/dev/null || echo $$m >> $(prev_abidir)/../modules.ignore; done)
-endif
-
-ifeq ($(do_v4l2loopback),false)
-       do_v4l2loopback_disable:=$(shell for m in $$(cat $(DROOT)/v4l2loopback-modules.ignore); do grep -qxF $$m $(prev_abidir)/../modules.ignore 2>/dev/null || echo $$m >> $(prev_abidir)/../modules.ignore; done)
-endif
+$(foreach _m,$(all_built-in_dkms_modules), \
+  $(if $(filter true,$(do_$(_m))),, \
+    $(eval do_$(_m)_disable := $$(shell for m in $$$$(cat $(DROOT)/$(_m)-modules.ignore); do grep -qxF $$$$m $(prev_abidir)/../modules.ignore 2>/dev/null || echo $$$$m >> $(prev_abidir)/../modules.ignore; done)) \
+  ) \
+)
 
 ifeq ($(do_dkms_wireguard),false)
        do_wireguard_disable:=$(shell for m in $$(cat $(DROOT)/wireguard-modules.ignore); do grep -qxF $$m $(prev_abidir)/../modules.ignore 2>/dev/null || echo $$m >> $(prev_abidir)/../modules.ignore; done)
@@ -112,10 +114,6 @@ endif
 # Either tools package needs the common source preparation
 do_any_tools=$(sort $(filter-out false,$(do_linux_tools) $(do_cloud_tools)))
 
-# Versions of dkms packages.
-dkms_zfs_linux_version=$(shell gawk '/^zfs-linux / { print $$2; }' debian/dkms-versions)
-dkms_v4l2loopback_version=$(shell gawk '/^v4l2loopback / { print $$2; }' debian/dkms-versions)
-
 # NVIDIA DKMS package gross series split into desktop and server.
 nvidia_desktop_series=$(shell sed -n -e 's/^nvidia-graphics-drivers-\([0-9][0-9]*\) .*/\1/p' debian/dkms-versions)
 nvidia_server_series=$(shell sed -n -e 's/^nvidia-graphics-drivers-\([0-9][0-9]*-server\) .*/\1/p' debian/dkms-versions)
@@ -182,6 +180,7 @@ endif
 $(DEBIAN)/control.stub:                                \
                $(DROOT)/scripts/control-create         \
                $(control_files)                        \
+               $(DROOT)/control.d/flavour-module.stub  \
                $(DEBIAN)/changelog                     \
                $(wildcard $(DEBIAN)/control.d/* $(DEBIAN)/sub-flavours/*.vars)
        for i in $(control_files); do                                           \
index 78f8a0f16e3af40cc582e91c458eb69cec02c7e2..2f27d1710ea5e0b158bae3c2a2155b9a09a9a1af 100644 (file)
@@ -285,3 +285,50 @@ custom_override = \
 
 # selftests that Ubuntu cares about
 ubuntu_selftests = breakpoints cpu-hotplug efivarfs memfd memory-hotplug mount net ptrace seccomp timers powerpc user ftrace
+
+# DKMS
+all_dkms_modules =
+
+subst_paired = $(subst $(firstword $(subst =, ,$(1))),$(lastword $(subst =, ,$(1))),$(2))
+recursive_call = $(if $(2),$(call recursive_call,$(1),$(wordlist 2,$(words $(2)),$(2)),$(call $(1),$(firstword $(2)),$(3))),$(3))
+
+$(foreach _line,$(shell gawk '{ OFS = "!"; $$1 = $$1; print }' $(DROOT)/dkms-versions), \
+  $(eval _params = $(subst !, ,$(_line))) \
+  $(eval _deb_pkgname = $(firstword $(_params))) \
+  $(eval _deb_version = $(word 2,$(_params))) \
+  $(if $(filter modulename=%,$(_params)), \
+    $(eval _m = $(word 2,$(subst =, ,$(filter modulename=%,$(_params))))) \
+    , \
+    $(info modulename for $(_deb_pkgname) not specified in dkms-versions. Assume $(_deb_pkgname).) \
+    $(eval _m = $(_deb_pkgname)) \
+  ) \
+  $(eval all_dkms_modules += $(_m)) \
+  $(eval dkms_$(_m)_version = $(_deb_version)) \
+  $(foreach _p,$(patsubst debpath=%,%,$(filter debpath=%,$(_params))), \
+    $(eval dkms_$(_m)_debpath += $(strip \
+      $(call recursive_call,subst_paired, \
+        %module%=$(_m) \
+        %package%=$(_deb_pkgname) \
+        %version%=$(lastword $(subst :, ,$(_deb_version))) \
+        , \
+        $(_p) \
+      ) \
+    )) \
+  ) \
+  $(if $(dkms_$(_m)_debpath),,$(error debpath for $(_deb_pkgname) not specified.)) \
+  $(if $(filter arch=%,$(_params)), \
+    $(eval dkms_$(_m)_archs = $(patsubst arch=%,%,$(filter arch=%,$(_params)))) \
+    , \
+    $(eval dkms_$(_m)_archs = any) \
+  ) \
+  $(eval dkms_$(_m)_rprovides = $(patsubst rprovides=%,%,$(filter rprovides=%,$(_params)))) \
+  $(eval dkms_$(_m)_type = $(word 1,$(patsubst type=%,%,$(filter type=%,$(_params))) built-in)) \
+  $(eval all_$(dkms_$(_m)_type)_dkms_modules += $(_m)) \
+  $(if $(filter standalone,$(dkms_$(_m)_type)), \
+    $(eval dkms_$(_m)_pkg_name = linux-modules-$(_m)-$(abi_release)) \
+    $(eval dkms_$(_m)_subdir = ubuntu) \
+    , \
+    $(eval dkms_$(_m)_pkg_name = $(mods_pkg_name)) \
+    $(eval dkms_$(_m)_subdir = kernel) \
+  ) \
+)
index c4906036ceb85526b465644256b4bcb351deb3c5..24a395d310f46610215ed0d13250dcf755a5ee02 100644 (file)
@@ -117,8 +117,10 @@ $(stampdir)/stamp-install-%: MODSECKEY=$(builddir)/build-$*/certs/signing_key.pe
 $(stampdir)/stamp-install-%: MODPUBKEY=$(builddir)/build-$*/certs/signing_key.x509
 $(stampdir)/stamp-install-%: build_dir=$(builddir)/build-$*
 $(stampdir)/stamp-install-%: dkms_dir=$(call dkms_dir_prefix,$(builddir)/build-$*)
-$(stampdir)/stamp-install-%: enable_zfs = $(call custom_override,do_zfs,$*)
-$(stampdir)/stamp-install-%: enable_v4l2loopback = $(call custom_override,do_v4l2loopback,$*)
+$(foreach _m,$(all_dkms_modules), \
+  $(eval $$(stampdir)/stamp-install-%: enable_$(_m) = $$(filter true,$$(call custom_override,do_$(_m),$$*))) \
+  $(eval $$(stampdir)/stamp-install-%: dkms_$(_m)_pkgdir = $$(CURDIR)/debian/$(dkms_$(_m)_pkg_name)-$$*) \
+)
 $(stampdir)/stamp-install-%: dbgpkgdir_dkms = $(if $(filter true,$(skipdbg)),"",$(dbgpkgdir)/usr/lib/debug/lib/modules/$(abi_release)-$*/kernel)
 $(stampdir)/stamp-install-%: $(stampdir)/stamp-build-% $(stampdir)/stamp-install-headers
        @echo Debug: $@ kernel_file $(kernel_file) kernfile $(kernfile) install_file $(install_file) instfile $(instfile)
@@ -126,6 +128,9 @@ $(stampdir)/stamp-install-%: $(stampdir)/stamp-build-% $(stampdir)/stamp-install
        dh_prep -p$(bin_pkg_name)-$*
        dh_prep -p$(mods_pkg_name)-$*
        dh_prep -p$(hdrs_pkg_name)-$*
+       $(foreach _m,$(all_standalone_dkms_modules), \
+         $(if $(enable_$(_m)),dh_prep -p$(dkms_$(_m)_pkg_name)-$*;)\
+       )
 ifneq ($(skipdbg),true)
        dh_prep -p$(bin_pkg_name)-$*-dbgsym
 endif
@@ -263,6 +268,12 @@ ifeq ($(do_extras_package),true)
                $(call install_control,$(mods_extra_pkg_name)-$*,extra,postinst postrm); \
        fi
 endif
+       $(foreach _m,$(all_standalone_dkms_modules), \
+         $(if $(enable_$(_m)), \
+           install -d $(dkms_$(_m)_pkgdir)/usr/lib/linux/triggers; \
+           $(call install_control,$(dkms_$(_m)_pkg_name)-$*,extra,postinst postrm); \
+         ) \
+       )
 
        # Install the full changelog.
 ifeq ($(do_doc_package),true)
@@ -412,8 +423,11 @@ endif
        install -d $(dkms_dir) $(dkms_dir)/headers $(dkms_dir)/build $(dkms_dir)/source
        cp -rp "$(hdrdir)" "$(indep_hdrdir)" "$(dkms_dir)/headers"
 
-       $(if $(filter true,$(enable_zfs)),$(call build_dkms, $(mods_pkg_name)-$*, $(pkgdir)/lib/modules/$(abi_release)-$*/kernel, $(dbgpkgdir_dkms), zfs, pool/universe/z/zfs-linux/zfs-dkms_$(dkms_zfs_linux_version)_all.deb))
-       $(if $(filter true,$(enable_v4l2loopback)),$(call build_dkms, $(mods_pkg_name)-$*, $(pkgdir)/lib/modules/$(abi_release)-$*/kernel, $(dbgpkgdir_dkms), v4l2loopback, pool/universe/v/v4l2loopback/v4l2loopback-dkms_$(dkms_v4l2loopback_version)_all.deb))
+       $(foreach _m,$(all_dkms_modules), \
+         $(if $(enable_$(_m)), \
+           $(call build_dkms,$(dkms_$(_m)_pkg_name)-$*,$(dkms_$(_m)_pkgdir)/lib/modules/$(abi_release)-$*/$(dkms_$(_m)_subdir),$(dbgpkgdir_dkms),$(_m),$(dkms_$(_m)_debpath)); \
+         ) \
+       )
 
 
 ifneq ($(skipdbg),true)
@@ -563,7 +577,7 @@ define dh_all
        dh_shlibdeps -p$(1) $(shlibdeps_opts)
        dh_installdeb -p$(1)
        dh_installdebconf -p$(1)
-       $(lockme) dh_gencontrol -p$(1) -- -Vlinux:rprovides='$(rprovides)'
+       $(lockme) dh_gencontrol -p$(1) -- -Vlinux:rprovides='$(rprovides)' $(2)
        dh_md5sums -p$(1)
        dh_builddeb -p$(1)
 endef
@@ -572,7 +586,7 @@ define newline
 
 endef
 define dh_all_inline
-        $(subst ${newline},; \${newline},$(call dh_all,$(1)))
+        $(subst ${newline},; \${newline},$(call dh_all,$(1),$(2)))
 endef
 
 binary-arch-headers: install-arch-headers
@@ -597,8 +611,10 @@ binary-%: dbgpkg = $(bin_pkg_name)-$*-dbgsym
 binary-%: dbgpkgdir = $(CURDIR)/debian/$(bin_pkg_name)-$*-dbgsym
 binary-%: pkgtools = $(tools_flavour_pkg_name)-$*
 binary-%: pkgcloud = $(cloud_flavour_pkg_name)-$*
-binary-%: rprovides = $(if $(filter true,$(call custom_override,do_zfs,$*)),spl-modules$(comma) spl-dkms$(comma) zfs-modules$(comma) zfs-dkms$(comma)) \
-               $(if $(filter true,$(call custom_override,do_v4l2loopback,$*)),v4l2loopback-modules$(comma) v4l2loopback-dkms$(comma))
+$(foreach _m,$(all_dkms_modules), \
+  $(eval binary-%: enable_$(_m) = $$(filter true,$$(call custom_override,do_$(_m),$$*))) \
+)
+binary-%: rprovides = $(foreach _m,$(all_built-in_dkms_modules),$(if $(enable_$(_m)),$(foreach _r,$(dkms_$(_m)_rprovides),$(_r)$(comma) )))
 binary-%: target_flavour = $*
 binary-%: checks-%
        @echo Debug: $@
@@ -623,6 +639,10 @@ ifeq ($(do_extras_package),true)
   endif
 endif
 
+       $(foreach _m,$(all_standalone_dkms_modules), \
+         $(if $(enable_$(_m)),$(call dh_all,$(dkms_$(_m)_pkg_name)-$*);)\
+       )
+
        $(call dh_all,$(pkgbldinfo))
        $(call dh_all,$(pkghdr))
 
index 2ab9e497515fe1d458effc26eaa0f2e8a2a593f5..5d0e3e46556c6c32df20d1b54a60bf4c049fcbeb 100755 (executable)
@@ -38,3 +38,30 @@ cat $stub | grep -v '^#' | sed \
        -e "s#=SIGN-ME-PKG=#$sign_me_pkg#g"     \
        -e "s#=SIGN-ME-TXT=#$sign_me_txt#g"     \
        -e "s#=SIGN-PEER-PKG=#$sign_peer_pkg#g"
+
+while read package version extras
+do
+       module="$package"
+       module_type=
+
+       # Module arch parameters are skipped here, so a package section will
+       # be generated for each flavour, and its Architecture will be set to
+       # all architectures with that flavour. Even that is being generated,
+       # it doesn't follow all of them will be built. That's to work-around
+       # dkms_exclude/dkms_include that manipulates supported architectures
+       # in $(DEBIAN)/rules.d/$(arch).mk.
+       for param in $extras; do
+               case "$param" in
+               modulename=*) module="${param#modulename=}" ;;
+               type=*) module_type="${param#type=}" ;;
+               *) continue ;;
+               esac
+       done
+
+       [ "$module_type" = "standalone" ] || continue
+
+       cat debian/control.d/flavour-module.stub | grep -v '^#' | sed   \
+               -e "s#ARCH#$arch#g"             \
+               -e "s#MODULE#$module#g"         \
+               -e "s#FLAVOUR#$flavour#g"
+done <"debian/dkms-versions"