diff mbox series

[REVIEW,4/6,linux-restricted-modules] UBUNTU: [Packaging] Support variant substitutions in control files

Message ID 20191203222657.1152249-22-seth.forshee@canonical.com
State New
Headers show
Series None | expand

Commit Message

Seth Forshee Dec. 3, 2019, 10:26 p.m. UTC
Support substitution patterns for variant information in control
files. Also update debian/control.d/meta-nvidia to use these
variablesso to produce meta packages for all variants.

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
---
 debian/control.d/meta-nvidia |  8 +++----
 debian/rules                 | 42 ++++++++++++++++++++++++++----------
 2 files changed, 35 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/debian/control.d/meta-nvidia b/debian/control.d/meta-nvidia
index d090f08fcebf..2a10a70cc7ba 100644
--- a/debian/control.d/meta-nvidia
+++ b/debian/control.d/meta-nvidia
@@ -1,4 +1,4 @@ 
-Package: linux-modules-nvidia-390-generic
+Package: linux-modules-nvidia-390-generic${variant:suffix}
 Build-Profiles: <!stage1>
 Architecture: amd64
 Section: kernel
@@ -6,7 +6,7 @@  Depends: ${misc:Depends}, linux-modules-nvidia-390-ABI-generic (= ${binary:Versi
 Description: Extra drivers for nvidia-390 for the generic flavour
  Install extra signed nvidia-390 modules compatible with the generic flavour.
 
-Package: linux-modules-nvidia-390-lowlatency
+Package: linux-modules-nvidia-390-lowlatency${variant:suffix}
 Build-Profiles: <!stage1>
 Architecture: amd64
 Section: kernel
@@ -14,7 +14,7 @@  Depends: ${misc:Depends}, linux-modules-nvidia-390-ABI-lowlatency (= ${binary:Ve
 Description: Extra drivers for nvidia-390 for the lowlatency flavour
  Install extra signed nvidia-390 modules compatible with the lowlatency flavour.
 
-Package: linux-modules-nvidia-440-generic
+Package: linux-modules-nvidia-440-generic${variant:suffix}
 Build-Profiles: <!stage1>
 Architecture: amd64
 Section: kernel
@@ -22,7 +22,7 @@  Depends: ${misc:Depends}, linux-modules-nvidia-440-ABI-generic (= ${binary:Versi
 Description: Extra drivers for nvidia-440 for the generic flavour
  Install extra signed nvidia-440 modules compatible with the generic flavour.
 
-Package: linux-modules-nvidia-440-lowlatency
+Package: linux-modules-nvidia-440-lowlatency${variant:suffix}
 Build-Profiles: <!stage1>
 Architecture: amd64
 Section: kernel
diff --git a/debian/rules b/debian/rules
index 1e611e68ece8..913148e835fd 100755
--- a/debian/rules
+++ b/debian/rules
@@ -14,29 +14,49 @@  src_abi = $(shell echo "$(src_fullversion)" | sed -ne 's/\([0-9]*\.[0-9]*\.[0-9]
 src_version = $(shell echo $(src_fullversion) | sed -e 's/+[0-9][0-9]*//')
 series = $(shell dpkg-parsechangelog | sed -ne 's/^Distribution: *//p' | sed -e 's/-\(security\|updates\|proposed\)$$//')
 
+VARIANT_PROVIDES=$(shell echo "$(src_package)" | sed -e 's/linux-restricted-modules-//')
+
 dkms_nvidia_390_version=$(shell gawk '/^nvidia-graphics-drivers-390/ { print $$2; }' debian/dkms-versions)
 dkms_nvidia_440_version=$(shell gawk '/^nvidia-graphics-drivers-440/ { print $$2; }' debian/dkms-versions)
 
+# Get variants, assumng 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 += $(filter-out $(primary_control_files),$(shell LC_ALL=C ls -d debian/control.d/*))
+control_files += $(shell LC_ALL=C ls -d debian/control.d/*)
 
 test:
 	echo "$(src_fullversion) $(src_version)"
 
+define variant_payload
+variant="$$(echo '$(variant)' | sed -e 's/--//')"; \
+sed -e "s/\$${variant:suffix}/$$variant/g" -e "s/\$${variant:provides\(\|-image\|-headers\)}/$${variant_provides:+linux\1-$$variant_provides}/" <$$i; \
+variant_provides=''; \
+echo "";
+endef
+
 # 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: $(control_files)
 	rm -f debian/control.tmp
-	for i in $^; do \
-		sed							\
-			-e 's/LRM_SOURCE/$(src_package)/g'		\
-			-e "s/ABI/$(src_abi)/g"				\
-			-e "s/VERSION/$(src_version)/g"			\
-			-e "s/@SERIES@/$(series)/g"			\
-			$$i >>debian/control.tmp;			\
-		echo "" >>debian/control.tmp;				\
-	done
-	rm -f $@
+	for i in $^; do 							\
+		if grep -q "{variant:" $$i; then				\
+			variant_provides="$(VARIANT_PROVIDES)";			\
+			$(foreach variant,$(variants),$(variant_payload))	\
+		else								\
+			cat $$i;						\
+			echo "";						\
+		fi;								\
+	done | sed								\
+			-e 's/LRM_SOURCE/$(src_package)/g'			\
+			-e "s/ABI/$(src_abi)/g"					\
+			-e "s/VERSION/$(src_version)/g"				\
+			-e "s/@SERIES@/$(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				\