diff mbox series

[1/9] UBUNTU: [Packaging] generate nvidia version mappings at clean time

Message ID 20210122162312.459010-3-apw@canonical.com
State New
Headers show
Series LP: #1912803 -- autogenerate Nvidia rules/control | expand

Commit Message

Andy Whitcroft Jan. 22, 2021, 4:23 p.m. UTC
Generate the rules and control fragments from debian/rules.config at
clean time so we do not have to maintain this package directly.

Signed-off-by: Andy Whitcroft <apw@canonical.com>
---
 debian/control.d/meta-nvidia | 148 -----------------------
 debian/control.d/nvidia      | 227 -----------------------------------
 debian/package.config        |   2 +
 debian/rules                 | 194 +-----------------------------
 debian/rules.in              | 139 +++++++++++++++++++++
 debian/scripts/gen-rules     |  85 +++++++++++++
 debian/source/options        |   3 +
 7 files changed, 233 insertions(+), 565 deletions(-)
 delete mode 100644 debian/control.d/meta-nvidia
 delete mode 100644 debian/control.d/nvidia
 create mode 100644 debian/package.config
 create mode 100755 debian/rules.in
 create mode 100755 debian/scripts/gen-rules
diff mbox series

Patch

diff --git a/debian/control.d/meta-nvidia b/debian/control.d/meta-nvidia
deleted file mode 100644
index 77a9ad7..0000000
--- a/debian/control.d/meta-nvidia
+++ /dev/null
@@ -1,148 +0,0 @@ 
-Package: linux-modules-nvidia-390-generic${variant:suffix}
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Provides: ${dkms:nvidia-390-modules}
-Depends:
- ${misc:Depends},
- linux-modules-nvidia-390-@ABI@-generic (= ${binary:Version}),
- ${nvk:nvidia-390}
-Description: Extra drivers for nvidia-390 for generic${variant:suffix}
- Install extra signed nvidia-390 modules compatible with
- generic${variant:suffix}
-
-Package: linux-modules-nvidia-450-generic${variant:suffix}
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Provides: ${dkms:nvidia-450-modules}, nvidia-prebuilt-kernel
-Depends:
- ${misc:Depends},
- linux-modules-nvidia-450-@ABI@-generic (= ${binary:Version}),
- ${nvk:nvidia-450}
-Description: Extra drivers for nvidia-450 for generic${variant:suffix}
- Install extra signed nvidia-450 modules compatible with
- generic${variant:suffix}
-
-Package: linux-modules-nvidia-455-generic${variant:suffix}
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Provides: ${dkms:nvidia-455-modules}, nvidia-prebuilt-kernel
-Depends:
- ${misc:Depends},
- linux-modules-nvidia-455-@ABI@-generic (= ${binary:Version}),
- ${nvk:nvidia-455}
-Description: Extra drivers for nvidia-455 for generic${variant:suffix}
- Install extra signed nvidia-455 modules compatible with
- generic${variant:suffix}
-
-Package: linux-modules-nvidia-418-server-generic${variant:suffix}
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Provides: ${dkms:nvidia-418-server-modules}, nvidia-prebuilt-kernel
-Depends:
- ${misc:Depends},
- linux-modules-nvidia-418-server-@ABI@-generic (= ${binary:Version}),
- ${nvk:nvidia-418-server}
-Description: Extra drivers for nvidia-418-server for generic${variant:suffix}
- Install extra signed nvidia-418-server modules compatible with
- generic${variant:suffix}
-
-Package: linux-modules-nvidia-440-server-generic${variant:suffix}
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Provides: ${dkms:nvidia-440-server-modules}, nvidia-prebuilt-kernel
-Depends:
- ${misc:Depends},
- linux-modules-nvidia-440-server-@ABI@-generic (= ${binary:Version}),
- ${nvk:nvidia-440-server}
-Description: Extra drivers for nvidia-440-server for generic${variant:suffix}
- Install extra signed nvidia-440-server modules compatible with
- generic${variant:suffix}
-
-Package: linux-modules-nvidia-450-server-generic${variant:suffix}
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Provides: ${dkms:nvidia-450-server-modules}, nvidia-prebuilt-kernel
-Depends:
- ${misc:Depends},
- linux-modules-nvidia-450-server-@ABI@-generic (= ${binary:Version}),
- ${nvk:nvidia-450-server}
-Description: Extra drivers for nvidia-450-server for generic${variant:suffix}
- Install extra signed nvidia-450-server modules compatible with
- generic${variant:suffix}
-
-Package: linux-modules-nvidia-390-lowlatency${variant:suffix}
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Provides: ${dkms:nvidia-390-modules}
-Depends:
- ${misc:Depends},
- linux-modules-nvidia-390-@ABI@-lowlatency (= ${binary:Version}),
- ${nvk:nvidia-390}
-Description: Extra drivers for nvidia-390 for lowlatency${variant:suffix}
- Install extra signed nvidia-390 modules compatible with
- lowlatency${variant:suffix}
-
-Package: linux-modules-nvidia-450-lowlatency${variant:suffix}
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Provides: ${dkms:nvidia-450-modules}, nvidia-prebuilt-kernel
-Depends:
- ${misc:Depends},
- linux-modules-nvidia-450-@ABI@-lowlatency (= ${binary:Version}),
- ${nvk:nvidia-450}
-Description: Extra drivers for nvidia-450 for lowlatency${variant:suffix}
- Install extra signed nvidia-450 modules compatible with
- lowlatency${variant:suffix}
-
-Package: linux-modules-nvidia-455-lowlatency${variant:suffix}
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Provides: ${dkms:nvidia-455-modules}, nvidia-prebuilt-kernel
-Depends:
- ${misc:Depends},
- linux-modules-nvidia-455-@ABI@-lowlatency (= ${binary:Version}),
- ${nvk:nvidia-455}
-Description: Extra drivers for nvidia-455 for lowlatency${variant:suffix}
- Install extra signed nvidia-455 modules compatible with
- lowlatency${variant:suffix}
-
-Package: linux-modules-nvidia-418-server-lowlatency${variant:suffix}
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Provides: ${dkms:nvidia-418-server-modules}, nvidia-prebuilt-kernel
-Depends: ${misc:Depends},
- linux-modules-nvidia-418-server-@ABI@-lowlatency (= ${binary:Version}),
- ${nvk:nvidia-418-server}
-Description: Extra drivers for nvidia-418-server for the lowlatency flavour
- Install extra signed nvidia-418-server modules compatible with the lowlatency flavour.
-
-Package: linux-modules-nvidia-440-server-lowlatency${variant:suffix}
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Provides: ${dkms:nvidia-440-server-modules}, nvidia-prebuilt-kernel
-Depends: ${misc:Depends},
- linux-modules-nvidia-440-server-@ABI@-lowlatency (= ${binary:Version}),
- ${nvk:nvidia-440-server}
-Description: Extra drivers for nvidia-440-server for the lowlatency flavour
- Install extra signed nvidia-440-server modules compatible with the lowlatency flavour.
-
-Package: linux-modules-nvidia-450-server-lowlatency${variant:suffix}
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Provides: ${dkms:nvidia-450-server-modules}, nvidia-prebuilt-kernel
-Depends: ${misc:Depends}, linux-modules-nvidia-450-server-@ABI@-lowlatency (= ${binary:Version}),
- ${nvk:nvidia-450-server}
-Description: Extra drivers for nvidia-450-server for the lowlatency flavour
- Install extra signed nvidia-450-server modules compatible with the lowlatency flavour.
diff --git a/debian/control.d/nvidia b/debian/control.d/nvidia
deleted file mode 100644
index 53fc1b5..0000000
--- a/debian/control.d/nvidia
+++ /dev/null
@@ -1,227 +0,0 @@ 
-Package: linux-modules-nvidia-390-@ABI@-generic
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Priority: optional
-Built-Using: ${linux:BuiltUsing}
-Depends:
- ${misc:Depends},
- ${shlibs:Depends},
- binutils,
- linux-image-@ABI@-generic | linux-image-unsigned-@ABI@-generic,
-Description: Linux kernel nvidia modules for version @ABI@
- This package contains the Linux kernel nvidia modules for version @ABI@.
- .
- You likely do not want to install this package directly. Instead, install the
- one of the linux-modules-nvidia-390-generic* meta-packages,
- which will ensure that upgrades work correctly, and that supporting packages are
- also installed.
-
-Package: linux-modules-nvidia-450-@ABI@-generic
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Priority: optional
-Built-Using: ${linux:BuiltUsing}
-Depends:
- ${misc:Depends},
- ${shlibs:Depends},
- binutils,
- linux-image-@ABI@-generic | linux-image-unsigned-@ABI@-generic,
-Description: Linux kernel nvidia modules for version @ABI@
- This package contains the Linux kernel nvidia modules for version @ABI@.
- .
- You likely do not want to install this package directly. Instead, install the
- one of the linux-modules-nvidia-450-generic* meta-packages,
- which will ensure that upgrades work correctly, and that supporting packages are
- also installed.
-
-Package: linux-modules-nvidia-455-@ABI@-generic
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Priority: optional
-Built-Using: ${linux:BuiltUsing}
-Depends:
- ${misc:Depends},
- ${shlibs:Depends},
- binutils,
- linux-image-@ABI@-generic | linux-image-unsigned-@ABI@-generic,
-Description: Linux kernel nvidia modules for version @ABI@
- This package contains the Linux kernel nvidia modules for version @ABI@.
- .
- You likely do not want to install this package directly. Instead, install the
- one of the linux-modules-nvidia-455-generic* meta-packages,
- which will ensure that upgrades work correctly, and that supporting packages are
- also installed.
-
-Package: linux-modules-nvidia-418-server-@ABI@-generic
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Priority: optional
-Built-Using: ${linux:BuiltUsing}
-Depends:
- ${misc:Depends},
- ${shlibs:Depends},
- binutils,
- linux-image-@ABI@-generic | linux-image-unsigned-@ABI@-generic,
-Description: Linux kernel nvidia modules for version @ABI@
- This package contains the Linux kernel nvidia modules for version @ABI@.
- .
- You likely do not want to install this package directly. Instead, install the
- one of the linux-modules-nvidia-418-server-generic* meta-packages,
- which will ensure that upgrades work correctly, and that supporting packages are
- also installed.
-
-Package: linux-modules-nvidia-440-server-@ABI@-generic
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Priority: optional
-Built-Using: ${linux:BuiltUsing}
-Depends:
- ${misc:Depends},
- ${shlibs:Depends},
- binutils,
- linux-image-@ABI@-generic | linux-image-unsigned-@ABI@-generic,
-Description: Linux kernel nvidia modules for version @ABI@
- This package contains the Linux kernel nvidia modules for version @ABI@.
- .
- You likely do not want to install this package directly. Instead, install the
- one of the linux-modules-nvidia-440-server-generic* meta-packages,
- which will ensure that upgrades work correctly, and that supporting packages are
- also installed.
-
-Package: linux-modules-nvidia-450-server-@ABI@-generic
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Priority: optional
-Built-Using: ${linux:BuiltUsing}
-Depends:
- ${misc:Depends},
- ${shlibs:Depends},
- binutils,
- linux-image-@ABI@-generic | linux-image-unsigned-@ABI@-generic,
-Description: Linux kernel nvidia modules for version @ABI@
- This package contains the Linux kernel nvidia modules for version @ABI@.
- .
- You likely do not want to install this package directly. Instead, install the
- one of the linux-modules-nvidia-450-server-generic* meta-packages,
- which will ensure that upgrades work correctly, and that supporting packages are
- also installed.
-
-Package: linux-modules-nvidia-390-@ABI@-lowlatency
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Priority: optional
-Built-Using: ${linux:BuiltUsing}
-Depends:
- ${misc:Depends},
- ${shlibs:Depends},
- binutils,
- linux-image-@ABI@-lowlatency | linux-image-unsigned-@ABI@-lowlatency,
-Description: Linux kernel nvidia modules for version @ABI@
- This package contains the Linux kernel nvidia modules for version @ABI@.
- .
- You likely do not want to install this package directly. Instead, install the
- one of the linux-modules-nvidia-390-lowlatency* meta-packages,
- which will ensure that upgrades work correctly, and that supporting packages are
- also installed.
-
-Package: linux-modules-nvidia-450-@ABI@-lowlatency
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Priority: optional
-Built-Using: ${linux:BuiltUsing}
-Depends:
- ${misc:Depends},
- ${shlibs:Depends},
- binutils,
- linux-image-@ABI@-lowlatency | linux-image-unsigned-@ABI@-lowlatency,
-Description: Linux kernel nvidia modules for version @ABI@
- This package contains the Linux kernel nvidia modules for version @ABI@.
- .
- You likely do not want to install this package directly. Instead, install the
- one of the linux-modules-nvidia-450-lowlatency* meta-packages,
- which will ensure that upgrades work correctly, and that supporting packages are
- also installed.
-
-Package: linux-modules-nvidia-455-@ABI@-lowlatency
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Priority: optional
-Built-Using: ${linux:BuiltUsing}
-Depends:
- ${misc:Depends},
- ${shlibs:Depends},
- binutils,
- linux-image-@ABI@-lowlatency | linux-image-unsigned-@ABI@-lowlatency,
-Description: Linux kernel nvidia modules for version @ABI@
- This package contains the Linux kernel nvidia modules for version @ABI@.
- .
- You likely do not want to install this package directly. Instead, install the
- one of the linux-modules-nvidia-455-lowlatency* meta-packages,
- which will ensure that upgrades work correctly, and that supporting packages are
- also installed.
-
-Package: linux-modules-nvidia-418-server-@ABI@-lowlatency
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Priority: optional
-Built-Using: ${linux:BuiltUsing}
-Depends:
- ${misc:Depends},
- ${shlibs:Depends},
- binutils,
- linux-image-@ABI@-lowlatency | linux-image-unsigned-@ABI@-lowlatency,
-Description: Linux kernel nvidia modules for version @ABI@
- This package contains the Linux kernel nvidia modules for version @ABI@.
- .
- You likely do not want to install this package directly. Instead, install the
- one of the linux-modules-nvidia-418-server-lowlatency* meta-packages,
- which will ensure that upgrades work correctly, and that supporting packages are
- also installed.
-
-Package: linux-modules-nvidia-440-server-@ABI@-lowlatency
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Priority: optional
-Built-Using: ${linux:BuiltUsing}
-Depends:
- ${misc:Depends},
- ${shlibs:Depends},
- binutils,
- linux-image-@ABI@-lowlatency | linux-image-unsigned-@ABI@-lowlatency,
-Description: Linux kernel nvidia modules for version @ABI@
- This package contains the Linux kernel nvidia modules for version @ABI@.
- .
- You likely do not want to install this package directly. Instead, install the
- one of the linux-modules-nvidia-440-server-lowlatency* meta-packages,
- which will ensure that upgrades work correctly, and that supporting packages are
- also installed.
-
-Package: linux-modules-nvidia-450-server-@ABI@-lowlatency
-Build-Profiles: <!stage1>
-Architecture: amd64
-Section: kernel
-Priority: optional
-Built-Using: ${linux:BuiltUsing}
-Depends:
- ${misc:Depends},
- ${shlibs:Depends},
- binutils,
- linux-image-@ABI@-lowlatency | linux-image-unsigned-@ABI@-lowlatency,
-Description: Linux kernel nvidia modules for version @ABI@
- This package contains the Linux kernel nvidia modules for version @ABI@.
- .
- You likely do not want to install this package directly. Instead, install the
- one of the linux-modules-nvidia-450-server-lowlatency* meta-packages,
- which will ensure that upgrades work correctly, and that supporting packages are
- also installed.
diff --git a/debian/package.config b/debian/package.config
new file mode 100644
index 0000000..2b69799
--- /dev/null
+++ b/debian/package.config
@@ -0,0 +1,2 @@ 
+build generic amd64
+build lowlatency amd64
diff --git a/debian/rules b/debian/rules
index 1d799fe..7c00598 100755
--- a/debian/rules
+++ b/debian/rules
@@ -1,194 +1,8 @@ 
 #! /usr/bin/make -f
 
-##export DH_VERBOSE := 1
-
-arch = $(shell dpkg-architecture -qDEB_HOST_ARCH)
-
-# Work out the source package name and version. The version
-# is identical to this package less any rebuild suffix (+lrmN).
-src_package := $(shell LC_ALL=C dpkg-parsechangelog -SSource)
-src_fullversion = $(shell LC_ALL=C dpkg-parsechangelog -SVersion)
-src_abi = $(shell echo "$(src_fullversion)" | sed -ne 's/\([0-9]*\.[0-9]*\.[0-9]*\-[0-9]*\)\..*/\1/p')
-src_version = $(shell echo $(src_fullversion) | sed -e 's/+[0-9][0-9]*//')
-src_series = $(shell dpkg-parsechangelog -SDistribution | sed -e 's/-\(security\|updates\|proposed\)$$//')
-src_kernel = $(shell echo "$(src_package)" | sed -e 's/restricted-modules-//')
-
-dkms_nvidia_390_version=$(shell gawk '/^nvidia-graphics-drivers-390 / { print $$2; }' debian/dkms-versions)
-dkms_nvidia_450_version=$(shell gawk '/^nvidia-graphics-drivers-450 / { print $$2; }' debian/dkms-versions)
-dkms_nvidia_455_version=$(shell gawk '/^nvidia-graphics-drivers-455 / { print $$2; }' debian/dkms-versions)
-dkms_nvidia_418_server_version=$(shell gawk '/^nvidia-graphics-drivers-418-server / { print $$2; }' debian/dkms-versions)
-dkms_nvidia_440_server_version=$(shell gawk '/^nvidia-graphics-drivers-440-server / { print $$2; }' debian/dkms-versions)
-dkms_nvidia_450_server_version=$(shell gawk '/^nvidia-graphics-drivers-450-server / { print $$2; }' debian/dkms-versions)
-
-nvidia_390_upstream_version=$(shell echo "$(dkms_nvidia_390_version)" | cut -d '-' -f 1)
-nvidia_450_upstream_version=$(shell echo "$(dkms_nvidia_450_version)" | cut -d '-' -f 1)
-nvidia_455_upstream_version=$(shell echo "$(dkms_nvidia_455_version)" | cut -d '-' -f 1)
-nvidia_418_server_upstream_version=$(shell echo "$(dkms_nvidia_418_server_version)" | cut -d '-' -f 1)
-nvidia_440_server_upstream_version=$(shell echo "$(dkms_nvidia_440_server_version)" | cut -d '-' -f 1)
-nvidia_450_server_upstream_version=$(shell echo "$(dkms_nvidia_450_server_version)" | cut -d '-' -f 1)
-
-# Get variants, assuming primary if debian/variants is not present
-variants = --
-ifneq (,$(wildcard debian/variants))
-	variants := $(shell cat debian/variants)
-endif
-
-control_files := debian/control.common
-# control files only wanted for the primary variant
-primary_control_files := $(shell LC_ALL=C ls -d debian/control.d/transitionals-* 2>/dev/null)
-ifneq ($(filter --, $(variants)),)
-	control_files += $(primary_control_files)
-endif
-control_files += $(filter-out $(primary_control_files),$(shell LC_ALL=C ls -d debian/control.d/*))
-
-test:
-	echo "$(src_fullversion) $(src_version)"
-
-# We build our control file.  This has to be done before dh runs otherwise
-# we have no binary files and we will not run the appropriate targets.
-pre-clean: tp_key=test:provides\(-full\|-image\|-headers\|-modules-extra\)
-pre-clean: $(control_files)
-	rm -f debian/control.tmp
-	for i in $^; do 								\
-		if grep -q "{variant:" $$i; then					\
-			variant_first='yes';						\
-                        for variant in $(variants); do					\
-				variant="$$(echo "$$variant" | sed -e 's/--//')";	\
-				sed							\
-					-e "s/\$${variant:suffix}/$$variant/g"		\
-					-e "s/\(\$${$(tp_key)[^}]*}\)/$${variant_first:+\1}/g" \
-					<$$i;						\
-				echo "";						\
-				variant_first='';					\
-			done;								\
-		else									\
-			cat $$i;							\
-			echo "";							\
-		fi;									\
-	done | sed									\
-		-e "s/\(\$${$(tp_key)\([^}]*\)}\)/kernel-testing--$(src_kernel)-\1-\2,/g" \
-		-e "s/@SRCPKGNAME@/$(src_package)/g"					\
-		-e "s/@ABI@/$(src_abi)/g"						\
-		-e "s/@VERSION@/$(src_version)/g"					\
-		-e "s/@SERIES@/$(src_series)/g"						\
-	    >debian/control.tmp
-	rm -f debian/control
-	mv debian/control.tmp debian/control
-	rm -rf ./$(src_version) UNSIGNED SIGNED
-	rm -f 	debian/linux-modules-*.install						\
-		debian/linux-modules-*.preinst 						\
-		debian/linux-modules-*.prerm 						\
-		debian/linux-modules-*.postinst 					\
-		debian/linux-modules-*.postrm
-	rm -rf $(dkms_dir)
-
-.PHONY: pre-clean
-
-debian/scripts/fix-filenames: debian/scripts/fix-filenames.c
-	$(CC) -o $@ $^
-
-clean:: pre-clean
+clean:
+	./debian/scripts/gen-rules
+	$(MAKE) -f debian/rules.gen clean
 
 %:
-	dh $@
-
-# Ensure the directory prefix is exactly 100 characters long so pathnames are the
-# exact same length in any binary files produced by the builds.  These will be
-# commonised later.
-dkms_20d=....................
-dkms_100d=$(dkms_20d)$(dkms_20d)$(dkms_20d)$(dkms_20d)$(dkms_20d)
-dkms_100c=$(shell echo '$(dkms_100d)' | sed -e 's/\./_/g')
-#dkms_dir=$(shell echo '$(CURDIR)/$(dkms_100c)' | \
-#	sed -e 's/\($(dkms_100d)\).*/\1/' -e 's/^\(.*\)....$$/\1dkms/')
-define dkms_dir_prefix =
-$(strip $(shell echo '$(1)/$(dkms_100c)' | \
-	sed -e 's/\($(dkms_100d)\).*/\1/' -e 's/^\(.*\)....$$/\1dkms/'))
-endef
-dkms_dir=$(call dkms_dir_prefix,$(CURDIR))
-
-define build_dkms =
-	$(SHELL) debian/scripts/dkms-build $(dkms_dir) $(1) --lrm $(2) $(3) $(4) $(5) $(6)
-endef
-
-ifeq ($(arch),ppc64el)
-instfile=vmlinux
-else
-instfile=vmlinuz
-endif
-
-define install_control =
-	for which in $(5);							\
-	do									\
-		template="debian/templates/$(3).$$which.in";			\
-		script="debian/$(1).$$which";					\
-		sed -e 's/@abiname@/$(src_abi)/g'				\
-		    -e 's/@localversion@/-$(2)/g'				\
-		    -e 's/@image-stem@/$(instfile)/g'				\
-		    -e 's/@nvidia-ver@/$(4)/g'					\
-			<"$$template" >"$$script";				\
-	done
-endef
-
-signatures=$(wildcard /usr/lib/linux/$(src_abi)-*)
-flavours=$(patsubst /usr/lib/linux/$(src_abi)-%,nvidia-%,$(signatures))
-
-nvidia-%:
-	rm -rf $(dkms_dir)/build $(dkms_dir)/source
-	mkdir -p $(dkms_dir)/build $(dkms_dir)/source
-	install -d debian/linux-modules-nvidia-390-$(src_abi)-$*
-	install -d debian/linux-modules-nvidia-390-$(src_abi)-$*/usr/lib/linux/triggers
-	$(call build_dkms, $(src_abi)-$*, linux-modules-nvidia-390-$(src_abi)-$*, $(CURDIR)/debian/linux-modules-nvidia-390-$(src_abi)-$*/lib/modules/$(src_abi)-$*/kernel, "", nvidia-390, pool/restricted/n/nvidia-graphics-drivers-390/nvidia-kernel-source-390_$(dkms_nvidia_390_version)_$(arch).deb pool/restricted/n/nvidia-graphics-drivers-390/nvidia-dkms-390_$(dkms_nvidia_390_version)_$(arch).deb)
-	$(call install_control,linux-modules-nvidia-390-$(src_abi)-$*,$*,nvidia,390,postinst postrm prerm config templates)
-
-	install -d debian/linux-modules-nvidia-450-$(src_abi)-$*
-	install -d debian/linux-modules-nvidia-450-$(src_abi)-$*/usr/lib/linux/triggers
-	$(call build_dkms, $(src_abi)-$*, linux-modules-nvidia-450-$(src_abi)-$*, $(CURDIR)/debian/linux-modules-nvidia-450-$(src_abi)-$*/lib/modules/$(src_abi)-$*/kernel, "", nvidia-450, pool/restricted/n/nvidia-graphics-drivers-450/nvidia-kernel-source-450_$(dkms_nvidia_450_version)_$(arch).deb pool/restricted/n/nvidia-graphics-drivers-450/nvidia-dkms-450_$(dkms_nvidia_450_version)_$(arch).deb)
-	$(call install_control,linux-modules-nvidia-450-$(src_abi)-$*,$*,nvidia,450,postinst postrm prerm config templates)
-
-	install -d debian/linux-modules-nvidia-455-$(src_abi)-$*
-	install -d debian/linux-modules-nvidia-455-$(src_abi)-$*/usr/lib/linux/triggers
-	$(call build_dkms, $(src_abi)-$*, linux-modules-nvidia-455-$(src_abi)-$*, $(CURDIR)/debian/linux-modules-nvidia-455-$(src_abi)-$*/lib/modules/$(src_abi)-$*/kernel, "", nvidia-455, pool/restricted/n/nvidia-graphics-drivers-455/nvidia-kernel-source-455_$(dkms_nvidia_455_version)_$(arch).deb pool/restricted/n/nvidia-graphics-drivers-455/nvidia-dkms-455_$(dkms_nvidia_455_version)_$(arch).deb)
-	$(call install_control,linux-modules-nvidia-455-$(src_abi)-$*,$*,nvidia,455,postinst postrm prerm config templates)
-
-	install -d debian/linux-modules-nvidia-418-server-$(src_abi)-$*
-	install -d debian/linux-modules-nvidia-418-server-$(src_abi)-$*/usr/lib/linux/triggers
-	$(call build_dkms, $(src_abi)-$*, linux-modules-nvidia-418-server-$(src_abi)-$*, $(CURDIR)/debian/linux-modules-nvidia-418-server-$(src_abi)-$*/lib/modules/$(src_abi)-$*/kernel, "", nvidia-418srv, pool/restricted/n/nvidia-graphics-drivers-418-server/nvidia-kernel-source-418-server_$(dkms_nvidia_418_server_version)_$(arch).deb pool/restricted/n/nvidia-graphics-drivers-418-server/nvidia-dkms-418-server_$(dkms_nvidia_418_server_version)_$(arch).deb)
-	$(call install_control,linux-modules-nvidia-418-server-$(src_abi)-$*,$*,nvidia,418srv,postinst postrm prerm config templates)
-
-	install -d debian/linux-modules-nvidia-440-server-$(src_abi)-$*
-	install -d debian/linux-modules-nvidia-440-server-$(src_abi)-$*/usr/lib/linux/triggers
-	$(call build_dkms, $(src_abi)-$*, linux-modules-nvidia-440-server-$(src_abi)-$*, $(CURDIR)/debian/linux-modules-nvidia-440-server-$(src_abi)-$*/lib/modules/$(src_abi)-$*/kernel, "", nvidia-440srv, pool/restricted/n/nvidia-graphics-drivers-440-server/nvidia-kernel-source-440-server_$(dkms_nvidia_440_server_version)_$(arch).deb pool/restricted/n/nvidia-graphics-drivers-440-server/nvidia-dkms-440-server_$(dkms_nvidia_440_server_version)_$(arch).deb)
-	$(call install_control,linux-modules-nvidia-440-server-$(src_abi)-$*,$*,nvidia,440srv,postinst postrm prerm config templates)
-
-	install -d debian/linux-modules-nvidia-450-server-$(src_abi)-$*
-	install -d debian/linux-modules-nvidia-450-server-$(src_abi)-$*/usr/lib/linux/triggers
-	$(call build_dkms, $(src_abi)-$*, linux-modules-nvidia-450-server-$(src_abi)-$*, $(CURDIR)/debian/linux-modules-nvidia-450-server-$(src_abi)-$*/lib/modules/$(src_abi)-$*/kernel, "", nvidia-450srv, pool/restricted/n/nvidia-graphics-drivers-450-server/nvidia-kernel-source-450-server_$(dkms_nvidia_450_server_version)_$(arch).deb pool/restricted/n/nvidia-graphics-drivers-450-server/nvidia-dkms-450-server_$(dkms_nvidia_450_server_version)_$(arch).deb)
-	$(call install_control,linux-modules-nvidia-450-server-$(src_abi)-$*,$*,nvidia,450srv,postinst postrm prerm config templates)
-
-prepare-dkms:
-	mkdir -p $(dkms_dir)
-	ln -s /usr/src $(dkms_dir)/headers
-
-override_dh_prep: debian/scripts/fix-filenames
-	dh_prep
-
-override_dh_auto_install: prepare-dkms $(flavours)
-	dh_install
-
-gencontrol_flags :=
-gencontrol_flags += -Vdkms:nvidia-390-modules="nvidia-dkms-390 (= $(dkms_nvidia_390_version))"
-gencontrol_flags += -Vdkms:nvidia-450-modules="nvidia-dkms-450 (= $(dkms_nvidia_450_version))"
-gencontrol_flags += -Vdkms:nvidia-455-modules="nvidia-dkms-455 (= $(dkms_nvidia_455_version))"
-gencontrol_flags += -Vdkms:nvidia-418-server-modules="nvidia-dkms-418-server (= $(dkms_nvidia_418_server_version))"
-gencontrol_flags += -Vdkms:nvidia-440-server-modules="nvidia-dkms-440-server (= $(dkms_nvidia_440_server_version))"
-gencontrol_flags += -Vdkms:nvidia-450-server-modules="nvidia-dkms-450-server (= $(dkms_nvidia_450_server_version))"
-
-gencontrol_flags += -Vnvk:nvidia-390="nvidia-kernel-common-390 (<= $(nvidia_390_upstream_version)-1), nvidia-kernel-common-390 (>= $(nvidia_390_upstream_version))"
-gencontrol_flags += -Vnvk:nvidia-450="nvidia-kernel-common-450 (<= $(nvidia_450_upstream_version)-1), nvidia-kernel-common-450 (>= $(nvidia_450_upstream_version))"
-gencontrol_flags += -Vnvk:nvidia-455="nvidia-kernel-common-455 (<= $(nvidia_455_upstream_version)-1), nvidia-kernel-common-455 (>= $(nvidia_455_upstream_version))"
-gencontrol_flags += -Vnvk:nvidia-418-server="nvidia-kernel-common-418-server (<= $(nvidia_418_server_upstream_version)-1), nvidia-kernel-common-418-server (>= $(nvidia_418_server_upstream_version))"
-gencontrol_flags += -Vnvk:nvidia-440-server="nvidia-kernel-common-440-server (<= $(nvidia_440_server_upstream_version)-1), nvidia-kernel-common-440-server (>= $(nvidia_440_server_upstream_version))"
-gencontrol_flags += -Vnvk:nvidia-450-server="nvidia-kernel-common-450-server (<= $(nvidia_450_server_upstream_version)-1), nvidia-kernel-common-450-server (>= $(nvidia_450_server_upstream_version))"
-
-override_dh_gencontrol:
-	dh_gencontrol -- $(gencontrol_flags)
+	$(MAKE) -f debian/rules.gen $@
diff --git a/debian/rules.in b/debian/rules.in
new file mode 100755
index 0000000..31b7aeb
--- /dev/null
+++ b/debian/rules.in
@@ -0,0 +1,139 @@ 
+#! /usr/bin/make -f
+
+##export DH_VERBOSE := 1
+
+arch = $(shell dpkg-architecture -qDEB_HOST_ARCH)
+
+# Work out the source package name and version. The version
+# is identical to this package less any rebuild suffix (+lrmN).
+src_package := $(shell LC_ALL=C dpkg-parsechangelog -SSource)
+src_fullversion = $(shell LC_ALL=C dpkg-parsechangelog -SVersion)
+src_abi = $(shell echo "$(src_fullversion)" | sed -ne 's/\([0-9]*\.[0-9]*\.[0-9]*\-[0-9]*\)\..*/\1/p')
+src_version = $(shell echo $(src_fullversion) | sed -e 's/+[0-9][0-9]*//')
+src_series = $(shell dpkg-parsechangelog -SDistribution | sed -e 's/-\(security\|updates\|proposed\)$$//')
+src_kernel = $(shell echo "$(src_package)" | sed -e 's/restricted-modules-//')
+
+# Get variants, assuming primary if debian/variants is not present
+variants = --
+ifneq (,$(wildcard debian/variants))
+	variants := $(shell cat debian/variants)
+endif
+
+control_files := debian/control.common
+# control files only wanted for the primary variant
+primary_control_files := $(shell LC_ALL=C ls -d debian/control.d/transitionals-* 2>/dev/null)
+ifneq ($(filter --, $(variants)),)
+	control_files += $(primary_control_files)
+endif
+control_files += $(filter-out $(primary_control_files),$(shell LC_ALL=C ls -d debian/control.d/*))
+
+test::
+	echo "$(src_fullversion) $(src_version)"
+
+# We build our control file.  This has to be done before dh runs otherwise
+# we have no binary files and we will not run the appropriate targets.
+pre-clean: tp_key=test:provides\(-full\|-image\|-headers\|-modules-extra\)
+pre-clean: $(control_files)
+	rm -f debian/control.tmp
+	for i in $^; do 								\
+		if grep -q "{variant:" $$i; then					\
+			variant_first='yes';						\
+                        for variant in $(variants); do					\
+				variant="$$(echo "$$variant" | sed -e 's/--//')";	\
+				sed							\
+					-e "s/\$${variant:suffix}/$$variant/g"		\
+					-e "s/\(\$${$(tp_key)[^}]*}\)/$${variant_first:+\1}/g" \
+					<$$i;						\
+				echo "";						\
+				variant_first='';					\
+			done;								\
+		else									\
+			cat $$i;							\
+			echo "";							\
+		fi;									\
+	done | sed									\
+		-e "/@BUILD-INTERLOCK@/{"						\
+		-e " r debian/control.gen"						\
+		-e " d"									\
+		-e " }"									\
+	     | sed									\
+		-e "s/\(\$${$(tp_key)\([^}]*\)}\)/kernel-testing--$(src_kernel)-\1-\2,/g" \
+		-e "s/@SRCPKGNAME@/$(src_package)/g"					\
+		-e "s/@ABI@/$(src_abi)/g"						\
+		-e "s/@VERSION@/$(src_version)/g"					\
+		-e "s/@SERIES@/$(src_series)/g"						\
+	    >debian/control.tmp
+	rm -f debian/control
+	mv debian/control.tmp debian/control
+	rm -rf ./$(src_version) UNSIGNED SIGNED
+	rm -f 	debian/linux-modules-*.install						\
+		debian/linux-modules-*.preinst 						\
+		debian/linux-modules-*.prerm 						\
+		debian/linux-modules-*.postinst 					\
+		debian/linux-modules-*.postrm
+	rm -rf $(dkms_dir)
+
+.PHONY: pre-clean
+
+debian/scripts/fix-filenames: debian/scripts/fix-filenames.c
+	$(CC) -o $@ $^
+
+clean:: pre-clean
+
+%:
+	dh $@
+
+# Ensure the directory prefix is exactly 100 characters long so pathnames are the
+# exact same length in any binary files produced by the builds.  These will be
+# commonised later.
+dkms_20d=....................
+dkms_100d=$(dkms_20d)$(dkms_20d)$(dkms_20d)$(dkms_20d)$(dkms_20d)
+dkms_100c=$(shell echo '$(dkms_100d)' | sed -e 's/\./_/g')
+#dkms_dir=$(shell echo '$(CURDIR)/$(dkms_100c)' | \
+#	sed -e 's/\($(dkms_100d)\).*/\1/' -e 's/^\(.*\)....$$/\1dkms/')
+define dkms_dir_prefix =
+$(strip $(shell echo '$(1)/$(dkms_100c)' | \
+	sed -e 's/\($(dkms_100d)\).*/\1/' -e 's/^\(.*\)....$$/\1dkms/'))
+endef
+dkms_dir=$(call dkms_dir_prefix,$(CURDIR))
+
+define build_dkms =
+	$(SHELL) debian/scripts/dkms-build $(dkms_dir) $(1) --lrm $(2) $(3) $(4) $(5) $(6)
+endef
+
+ifeq ($(arch),ppc64el)
+instfile=vmlinux
+else
+instfile=vmlinuz
+endif
+
+define install_control =
+	for which in $(5);							\
+	do									\
+		template="debian/templates/$(3).$$which.in";			\
+		script="debian/$(1).$$which";					\
+		sed -e 's/@abiname@/$(src_abi)/g'				\
+		    -e 's/@localversion@/-$(2)/g'				\
+		    -e 's/@image-stem@/$(instfile)/g'				\
+		    -e 's/@nvidia-ver@/$(4)/g'					\
+			<"$$template" >"$$script";				\
+	done
+endef
+
+signatures=$(wildcard /usr/lib/linux/$(src_abi)-*)
+
+prepare-dkms:
+	mkdir -p $(dkms_dir)
+	ln -s /usr/src $(dkms_dir)/headers
+
+override_dh_prep: debian/scripts/fix-filenames
+	dh_prep
+
+override_dh_auto_install: prepare-dkms nvidia-$(arch)
+	dh_install
+
+override_dh_gencontrol:
+	dh_gencontrol -- $(gencontrol_flags)
+
+gencontrol_flags :=
+
diff --git a/debian/scripts/gen-rules b/debian/scripts/gen-rules
new file mode 100755
index 0000000..1a3fe02
--- /dev/null
+++ b/debian/scripts/gen-rules
@@ -0,0 +1,85 @@ 
+#!/bin/bash
+
+cat "debian/rules.in" >"debian/rules.gen"
+: >"debian/control.d/meta-nvidia"
+: >"debian/control.d/nvidia"
+
+while read command flavour archs
+do
+	case "$command" in
+	build)		;;
+	*)		continue ;;
+	esac
+
+	targets=$(echo "$archs" | sed -e 's/\</nvidia-/g')
+
+	while read package version
+	do
+		case "$package" in
+		nvidia-graphics-drivers-*)	;;
+		*) continue ;;
+		esac
+
+		suffix_minus=$(echo "$package" | sed -e 's/nvidia-graphics-drivers-//')
+		suffix_under=$(echo "$suffix_minus" | sed -e 's/-/_/g')
+		suffix_short=$(echo "$suffix_minus" | sed -e 's/-server/srv/g')
+
+		# debian/rules.gen
+		{
+			echo ""
+			#echo "# $package $version $suffix_minus $suffix_under"
+			echo "dkms_nvidia_${suffix_under}_version=\$(shell gawk '/^${package} / { print \$\$2; }' debian/dkms-versions)"
+			echo "nvidia_${suffix_under}_upstream_version=\$(shell echo \"\$(dkms_nvidia_${suffix_under}_version)\" | cut -d '-' -f 1)"
+			echo "gencontrol_flags += -Vdkms:nvidia-${suffix_minus}-modules=\"nvidia-dkms-${suffix_minus} (= \$(dkms_nvidia_${suffix_under}_version))\""
+			echo "gencontrol_flags += -Vnvk:nvidia-${suffix_minus}=\"nvidia-kernel-common-${suffix_minus} (<= \$(nvidia_${suffix_under}_upstream_version)-1), nvidia-kernel-common-${suffix_minus} (>= \$(nvidia_${suffix_under}_upstream_version))\""
+			echo "test::"
+			echo "	@echo $package $version $suffix_minus $suffix_under $suffix_short $targets"
+			echo "$targets::"
+			echo "	rm -rf \$(dkms_dir)/build \$(dkms_dir)/source"
+			echo "	mkdir -p \$(dkms_dir)/build \$(dkms_dir)/source"
+			echo "	install -d debian/linux-modules-nvidia-${suffix_minus}-\$(src_abi)-${flavour}"
+			echo "	install -d debian/linux-modules-nvidia-${suffix_minus}-\$(src_abi)-${flavour}/usr/lib/linux/triggers"
+			echo "	\$(call build_dkms, \$(src_abi)-${flavour}, linux-modules-nvidia-${suffix_minus}-\$(src_abi)-${flavour}, \$(CURDIR)/debian/linux-modules-nvidia-${suffix_minus}-\$(src_abi)-${flavour}/lib/modules/\$(src_abi)-${flavour}/kernel, \"\", nvidia-${suffix_short}, pool/restricted/n/nvidia-graphics-drivers-${suffix_minus}/nvidia-kernel-source-${suffix_minus}_\$(dkms_nvidia_${suffix_under}_version)_\$(arch).deb pool/restricted/n/nvidia-graphics-drivers-${suffix_minus}/nvidia-dkms-${suffix_minus}_\$(dkms_nvidia_${suffix_under}_version)_\$(arch).deb)"
+			echo "	\$(call install_control,linux-modules-nvidia-${suffix_minus}-\$(src_abi)-${flavour},${flavour},nvidia,${suffix_short},postinst postrm prerm config templates)"
+		} >>"debian/rules.gen"
+
+		# debian/control.d/meta-nvidia
+		cat - >>"debian/control.d/meta-nvidia" <<EOL
+Package: linux-modules-nvidia-${suffix_minus}-${flavour}\${variant:suffix}
+Build-Profiles: <!stage1>
+Architecture: ${archs}
+Section: kernel
+Provides: \${dkms:nvidia-${suffix_minus}-modules}, nvidia-prebuilt-kernel
+Depends:
+ \${misc:Depends},
+ linux-modules-nvidia-${suffix_minus}-@ABI@-${flavour} (= \${binary:Version}),
+ \${nvk:nvidia-${suffix_minus}}
+Description: Extra drivers for nvidia-${suffix_minus} for the ${flavour}\${variant:suffix} flavour
+ Install extra signed nvidia-${suffix_minus} modules compatible with the ${flavour}\${variant:suffix} flavour.
+
+EOL
+
+		# debian/control.d/nvidia
+		cat - >>"debian/control.d/nvidia" <<EOL
+Package: linux-modules-nvidia-${suffix_minus}-@ABI@-${flavour}
+Build-Profiles: <!stage1>
+Architecture: ${archs}
+Section: kernel
+Priority: optional
+Built-Using: \${linux:BuiltUsing}
+Depends:
+ \${misc:Depends},
+ \${shlibs:Depends},
+ binutils,
+ linux-image-@ABI@-${flavour} | linux-image-unsigned-@ABI@-${flavour},
+Description: Linux kernel nvidia modules for version @ABI@
+ This package contains the Linux kernel nvidia modules for version @ABI@.
+ .
+ You likely do not want to install this package directly. Instead, install the
+ one of the linux-modules-nvidia-${suffix_minus}-${flavour}* meta-packages,
+ which will ensure that upgrades work correctly, and that supporting packages are
+ also installed.
+
+EOL
+	done <"debian/dkms-versions"
+done <"debian/package.config"
diff --git a/debian/source/options b/debian/source/options
index 8e1f8cf..693e1f7 100644
--- a/debian/source/options
+++ b/debian/source/options
@@ -1,3 +1,6 @@ 
 # force "dpkg-source -I -i" behavior
 diff-ignore
 tar-ignore
+tar-ignore debian/control.d
+tar-ignore debian/rules.gen
+tar-ignore debian/control.gen