diff mbox series

[5/7,RFC,LRM,Unstable] debian: generalize template generation for multiple modules

Message ID 20220414212123.3616050-6-vicamo.yang@canonical.com
State New
Headers show
Series Build presigned iwlwifi dkms modules | expand

Commit Message

You-Sheng Yang April 14, 2022, 9:21 p.m. UTC
From: "You-Sheng Yang (vicamo)" <vicamo.yang@canonical.com>

BugLink: https://bugs.launchpad.net/bugs/1962515

Signed-off-by: You-Sheng Yang (vicamo) <vicamo.yang@canonical.com>
---
 debian/rules.in                     |   3 +-
 debian/scripts/gen-rules.lrg        |  22 +++---
 debian/scripts/gen-rules.lrm        | 103 ++++++++++++++++------------
 debian/scripts/gen-rules.lrs        |  37 +++++++---
 debian/templates/nvidia.postinst.in |  14 ++--
 debian/templates/nvidia.prerm.in    |   4 +-
 6 files changed, 111 insertions(+), 72 deletions(-)
diff mbox series

Patch

diff --git a/debian/rules.in b/debian/rules.in
index 2301329..f438500 100755
--- a/debian/rules.in
+++ b/debian/rules.in
@@ -103,7 +103,8 @@  define install_control =
 		sed -e 's/@abiname@/$(src_abi)/g'				\
 		    -e 's/@localversion@/-$(2)/g'				\
 		    -e 's/@image-stem@/$(instfile)/g'				\
-		    -e 's/@nvidia-ver@/$(4)/g'					\
+		    -e 's/@module@/$(3)/g'					\
+		    -e 's/@suffix-short@/$(4)/g'				\
 			<"$$template" >"$$script";				\
 	done
 endef
diff --git a/debian/scripts/gen-rules.lrg b/debian/scripts/gen-rules.lrg
index 0c19b8f..fd16fa5 100755
--- a/debian/scripts/gen-rules.lrg
+++ b/debian/scripts/gen-rules.lrg
@@ -122,14 +122,20 @@  do
 		fi
 
 		targets=$(echo "$pkg_archs" | sed -e 's/\</targets-/g')
-		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')
+		case "$package" in
+		nvidia-*)
+			module=nvidia
+			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')
+			;;
+		*) continue ;;
+		esac
 
 		echo "II: build $package for $flavour $pkg_archs"
 
 		cat - >>"debian/control.interlock-up" <<EOL
- linux-objects-nvidia-${suffix_minus}-${src_abi}-${flavour} (>= ${src_lrm_version}) [${pkg_archs}],
+ linux-objects-${module}-${suffix_minus}-${src_abi}-${flavour} (>= ${src_lrm_version}) [${pkg_archs}],
 EOL
 
 		# debian/rules.gen
@@ -138,14 +144,14 @@  EOL
 
 # $package $version $suffix_minus $suffix_under $suffix_short
 $targets::
-	install -d \$(custom_dir)/${src_abi}-${flavour}/signatures/nvidia-${suffix_short}
-	cp -rp /lib/modules/${src_abi}-${flavour}/kernel/nvidia-${suffix_short}/bits \$(custom_dir)/${src_abi}-${flavour}/signatures/nvidia-${suffix_short}
+	install -d \$(custom_dir)/${src_abi}-${flavour}/signatures/${module}-${suffix_short}
+	cp -rp /lib/modules/${src_abi}-${flavour}/kernel/${module}-${suffix_short}/bits \$(custom_dir)/${src_abi}-${flavour}/signatures/${module}-${suffix_short}
 	(													\
-		cd \$(custom_dir)/${src_abi}-${flavour}/signatures/nvidia-${suffix_short}/bits || exit 1;	\
+		cd \$(custom_dir)/${src_abi}-${flavour}/signatures/${module}-${suffix_short}/bits || exit 1;	\
 		sh BUILD unsigned || exit 1;									\
 		mv *.ko ..;											\
 	)
-	rm -rf \$(custom_dir)/${src_abi}-${flavour}/signatures/nvidia-${suffix_short}/bits
+	rm -rf \$(custom_dir)/${src_abi}-${flavour}/signatures/${module}-${suffix_short}/bits
 EOL
 
 	done <"debian/dkms-versions"
diff --git a/debian/scripts/gen-rules.lrm b/debian/scripts/gen-rules.lrm
index a24629a..fd4a1d2 100755
--- a/debian/scripts/gen-rules.lrm
+++ b/debian/scripts/gen-rules.lrm
@@ -32,9 +32,11 @@  src_sigs_version=${src_version}
 
 mkdir -p "debian/control.d"
 : >"debian/control.interlock-up"
-: >"debian/control.d/meta-nvidia"
-: >"debian/control.d/nvidia"
-: >"debian/control.d/migrate-nvidia"
+for module in nvidia; do
+	: >"debian/control.d/meta-${module}"
+	: >"debian/control.d/${module}"
+	: >"debian/control.d/migrate-${module}"
+done
 : >"debian/control.d/transitionals-local"
 : >"debian/control.d/signatures"
 
@@ -130,9 +132,15 @@  EOL
 		fi
 
 		targets=$(echo "$pkg_archs" | sed -e 's/\</targets-/g')
-		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')
+		case "$package" in
+		nvidia-*)
+			module=nvidia
+			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')
+			;;
+		*) continue ;;
+		esac
 
 		echo "II: build $package for $flavour $pkg_archs"
 
@@ -140,42 +148,42 @@  EOL
 		cat - >>"debian/rules.gen" <<EOL
 
 # $package $version $suffix_minus $suffix_under
-dkms_nvidia_${suffix_under}_version=\$(shell gawk '/^${package} / { print \$\$2; }' debian/dkms-versions)
-nvidia_${suffix_under}_upstream_version=\$(shell echo "\$(dkms_nvidia_${suffix_under}_version)" | cut -d '-' -f 1)
-gencontrol_flags += -Vdkms:nvidia-${suffix_minus}-modules="nvidia-dkms-${suffix_minus} (= \$(dkms_nvidia_${suffix_under}_version))"
-gencontrol_flags += -Vadditional-deps:nvidia-${suffix_minus}="nvidia-kernel-common-${suffix_minus} (<= \$(nvidia_${suffix_under}_upstream_version)-1), nvidia-kernel-common-${suffix_minus} (>= \$(nvidia_${suffix_under}_upstream_version))"
+dkms_${module}_${suffix_under}_version=\$(shell gawk '/^${package} / { print \$\$2; }' debian/dkms-versions)
+${module}_${suffix_under}_upstream_version=\$(shell echo "\$(dkms_${module}_${suffix_under}_version)" | cut -d '-' -f 1)
+gencontrol_flags += -Vdkms:${module}-${suffix_minus}-modules="${module}-dkms-${suffix_minus} (= \$(dkms_${module}_${suffix_under}_version))"
+gencontrol_flags += -Vadditional-deps:${module}-${suffix_minus}="nvidia-kernel-common-${suffix_minus} (<= \$(${module}_${suffix_under}_upstream_version)-1), nvidia-kernel-common-${suffix_minus} (>= \$(${module}_${suffix_under}_upstream_version))"
 test::
 	@echo $package $version $suffix_minus $suffix_under $suffix_short $targets
 $targets::
 	rm -rf \$(dkms_dir)/build \$(dkms_dir)/source
 	mkdir -p \$(dkms_dir)/build \$(dkms_dir)/source
-	install -d debian/linux-modules-nvidia-${suffix_minus}-\$(src_abi)-${flavour}
-	install -d debian/linux-modules-nvidia-${suffix_minus}-\$(src_abi)-${flavour}/usr/lib/linux/triggers
-	\$(call install_control,linux-modules-nvidia-${suffix_minus}-\$(src_abi)-${flavour},${flavour},nvidia,${suffix_short},postinst postrm prerm config templates)
-	install -d debian/linux-objects-nvidia-${suffix_minus}-\$(src_abi)-${flavour}
-	\$(call build_dkms, \$(src_abi)-${flavour}, linux-objects-nvidia-${suffix_minus}-\$(src_abi)-${flavour}, \$(CURDIR)/debian/linux-objects-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)
+	install -d debian/linux-modules-${module}-${suffix_minus}-\$(src_abi)-${flavour}
+	install -d debian/linux-modules-${module}-${suffix_minus}-\$(src_abi)-${flavour}/usr/lib/linux/triggers
+	\$(call install_control,linux-modules-${module}-${suffix_minus}-\$(src_abi)-${flavour},${flavour},${module},${suffix_short},postinst postrm prerm config templates)
+	install -d debian/linux-objects-${module}-${suffix_minus}-\$(src_abi)-${flavour}
+	\$(call build_dkms, \$(src_abi)-${flavour}, linux-objects-${module}-${suffix_minus}-\$(src_abi)-${flavour}, \$(CURDIR)/debian/linux-objects-${module}-${suffix_minus}-\$(src_abi)-${flavour}/lib/modules/\$(src_abi)-${flavour}/kernel, "", ${module}-${suffix_short}, pool/restricted/n/nvidia-graphics-drivers-${suffix_minus}/nvidia-kernel-source-${suffix_minus}_\$(dkms_${module}_${suffix_under}_version)_\$(arch).deb pool/restricted/n/nvidia-graphics-drivers-${suffix_minus}/nvidia-dkms-${suffix_minus}_\$(dkms_${module}_${suffix_under}_version)_\$(arch).deb)
 EOL
 
-		# debian/control.d/meta-nvidia
-		cat - >>"debian/control.d/meta-nvidia" <<EOL
+		# debian/control.d/meta-${module}
+		cat - >>"debian/control.d/meta-${module}" <<EOL
 
-Package: linux-modules-nvidia-${suffix_minus}-${flavour}\${variant:suffix}
+Package: linux-modules-${module}-${suffix_minus}-${flavour}\${variant:suffix}
 Build-Profiles: <!stage1>
 Architecture: ${pkg_archs}
 Section: kernel
-Provides: \${dkms:nvidia-${suffix_minus}-modules}, nvidia-prebuilt-kernel
+Provides: \${dkms:${module}-${suffix_minus}-modules}, ${module}-prebuilt-kernel
 Depends:
  \${misc:Depends},
- linux-modules-nvidia-${suffix_minus}-${src_abi}-${flavour} (= \${binary:Version}),
- \${additional-deps: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.
+ linux-modules-${module}-${suffix_minus}-${src_abi}-${flavour} (= \${binary:Version}),
+ \${additional-deps:${module}-${suffix_minus}},
+Description: Extra drivers for ${module}-${suffix_minus} for the ${flavour}\${variant:suffix} flavour
+ Install extra signed ${module}-${suffix_minus} modules compatible with the ${flavour}\${variant:suffix} flavour.
 EOL
 
-		# debian/control.d/nvidia
-		cat - >>"debian/control.d/nvidia" <<EOL
+		# debian/control.d/${module}
+		cat - >>"debian/control.d/${module}" <<EOL
 
-Package: linux-objects-nvidia-${suffix_minus}-${src_abi}-${flavour}
+Package: linux-objects-${module}-${suffix_minus}-${src_abi}-${flavour}
 Build-Profiles: <!stage1>
 Architecture: ${pkg_archs}
 Section: kernel
@@ -185,15 +193,15 @@  Depends:
  \${misc:Depends},
  \${shlibs:Depends},
  binutils,
-Description: Linux kernel nvidia modules for version ${src_abi} (objects)
- This package contains the Linux kernel nvidia modules for version ${src_abi}.
+Description: Linux kernel ${module} modules for version ${src_abi} (objects)
+ This package contains the Linux kernel ${module} modules for version ${src_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,
+ one of the linux-modules-${module}-${suffix_minus}-${flavour}* meta-packages,
  which will ensure that upgrades work correctly, and that supporting packages are
  also installed.
 
-Package: linux-modules-nvidia-${suffix_minus}-${src_abi}-${flavour}
+Package: linux-modules-${module}-${suffix_minus}-${src_abi}-${flavour}
 Build-Profiles: <!stage1>
 Architecture: ${pkg_archs}
 Section: kernel
@@ -203,40 +211,45 @@  Depends:
  \${misc:Depends},
  \${shlibs:Depends},
  linux-image-${src_abi}-${flavour} | linux-image-unsigned-${src_abi}-${flavour},
- linux-signatures-nvidia-${src_abi}-${flavour} (= ${src_sigs_version}),
- linux-objects-nvidia-${suffix_minus}-${src_abi}-${flavour} (= \${binary:Version}),
- \${additional-deps:nvidia-${suffix_minus}},
-Description: Linux kernel nvidia modules for version ${src_abi}
- This package pulls together the Linux kernel nvidia modules for
+ linux-signatures-${module}-${src_abi}-${flavour} (= ${src_sigs_version}),
+ linux-objects-${module}-${suffix_minus}-${src_abi}-${flavour} (= \${binary:Version}),
+ \${additional-deps:${module}-${suffix_minus}},
+Description: Linux kernel ${module} modules for version ${src_abi}
+ This package pulls together the Linux kernel ${module} modules for
  version ${src_abi} with the appropriate signatures.
  .
  You likely do not want to install this package directly. Instead, install the
- one of the linux-modules-nvidia-${suffix_minus}-${flavour}* meta-packages,
+ one of the linux-modules-${module}-${suffix_minus}-${flavour}* meta-packages,
  which will ensure that upgrades work correctly, and that supporting packages are
  also installed.
 EOL
-		# debian/control.d/migrate-nvidia
+		# debian/control.d/migrate-${module}
 		for cmd in $extra
 		do
 			case "$cmd" in
 			transition=*)
 				from="${cmd#transition=}"
-				from_minus=$(echo "$from" | sed -e 's/nvidia-graphics-drivers-//')
+				case "$package" in
+				nvidia-*)
+					from_minus=$(echo "$from" | sed -e 's/nvidia-graphics-drivers-//')
+					;;
+				*)
+					echo "EE: unsupported transition for $package" 1>&2
+					exit 1
+					;;
+				esac
 				echo "II: general transition $from -> $package ($from_minus -> $suffix_minus) $pkg_archs"
-				cat - >>"debian/control.d/migrate-nvidia" <<EOL
+				cat - >>"debian/control.d/migrate-${module}" <<EOL
 
-Package: linux-modules-nvidia-${from_minus}-${flavour}\${variant:suffix}
+Package: linux-modules-${module}-${from_minus}-${flavour}\${variant:suffix}
 Architecture: ${pkg_archs}
 Section: oldlibs
-Depends: linux-modules-nvidia-${suffix_minus}-${flavour}\${variant:suffix}
-Description: Extra drivers for nvidia-${from_minus} for the ${flavour} flavour (dummy transitional package)
+Depends: linux-modules-${module}-${suffix_minus}-${flavour}\${variant:suffix}
+Description: Extra drivers for ${module}-${from_minus} for the ${flavour} flavour (dummy transitional package)
  Transitional package for upgrades of -${from_minus} to -${suffix_minus}.
 EOL
 				;;
 			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')
 		done
 	done <"debian/dkms-versions"
 done <"debian/package.config"
diff --git a/debian/scripts/gen-rules.lrs b/debian/scripts/gen-rules.lrs
index 657a745..51e1655 100755
--- a/debian/scripts/gen-rules.lrs
+++ b/debian/scripts/gen-rules.lrs
@@ -71,33 +71,52 @@  do
 	validate_unique "archs" "$archs"
 	targets=$(echo "$archs" | sed -e 's/\</targets-/g')
 
-	echo "II: build linux-signatures-nvidia-${src_abi}-${flavour} for ${archs}"
+	modules=
+	while read package version extra
+	do
+		case "$package" in
+		nvidia-*)
+			module=nvidia
+			;;
+		*) continue ;;
+		esac
+
+		# skip processed modules
+		case " ${modules} " in
+		*" ${module} "*) continue ;;
+		*)
+			modules="${modules} ${module}"
+			;;
+		esac
+
+		echo "II: build linux-signatures-${module}-${src_abi}-${flavour} for ${archs}"
 
-	cat - >>"debian/rules.gen" <<EOL
+		cat - >>"debian/rules.gen" <<EOL
 
 $targets::
-	for stream in "${src_genr_version}/${src_abi}-${flavour}/signatures"/*;		\
+	for stream in "${src_genr_version}/${src_abi}-${flavour}/signatures"/${module}-*;		\
 	do										\
-		nvidia=\$\$(basename "\$\$stream");						\
-		echo "\$\$stream/* /lib/modules/${src_abi}-${flavour}/kernel/\$\$nvidia/bits" >>debian/linux-signatures-nvidia-${src_abi}-${flavour}.install;	\
+		pkg=\$\$(basename "\$\$stream");						\
+		echo "\$\$stream/* /lib/modules/${src_abi}-${flavour}/kernel/\$\$pkg/bits" >>debian/linux-signatures-${module}-${src_abi}-${flavour}.install;	\
 	done
 EOL
 
-	cat - >>"debian/control.signatures" <<EOL
+		cat - >>"debian/control.signatures" <<EOL
 
-Package: linux-signatures-nvidia-${src_abi}-${flavour}
+Package: linux-signatures-${module}-${src_abi}-${flavour}
 Build-Profiles: <!stage1>
 Architecture: ${archs}
 Section: kernel
 Priority: optional
 Depends: linux-image-${src_abi}-${flavour} | linux-image-unsigned-${src_abi}-${flavour},
 Built-Using: \${linux:BuiltUsing}
-Description: Linux kernel signatures for nvidia modules for version ${src_abi}-${flavour}
- This package contains the Linux kernel signatures nvidia modules for
+Description: Linux kernel signatures for ${module} modules for version ${src_abi}-${flavour}
+ This package contains the Linux kernel signatures ${module} modules for
  version ${src_abi}-${flavour}.
  .
  You likely do not want to install this package directly.
 EOL
+	done <"debian/dkms-versions"
 done <"debian/package.config"
 
 cat "debian/control.common" "debian/control.signatures" | sed \
diff --git a/debian/templates/nvidia.postinst.in b/debian/templates/nvidia.postinst.in
index 663631f..d367ee4 100755
--- a/debian/templates/nvidia.postinst.in
+++ b/debian/templates/nvidia.postinst.in
@@ -4,7 +4,7 @@  set -e
 version=@abiname@@localversion@
 image_path=/boot/@image-stem@-$version
 
-bits=/lib/modules/$version/kernel/nvidia-@nvidia-ver@/bits
+bits=/lib/modules/$version/kernel/@module@-@suffix-short@/bits
 
 if [ "$1" != configure ]; then
     exit 0
@@ -22,12 +22,12 @@  if ! ubiquity_live; then
     . /usr/share/debconf/confmodule
 fi
 
-conf=/etc/default/linux-modules-nvidia
+conf=/etc/default/linux-modules-@module@
 latelink=''
 [ -f "$conf" ] && . "$conf"
 case "$latelink" in
 true|false|'')  ;;
-*)              echo "linux-modules-nvidia: latelink specifier invalid, ignored" 1>&2
+*)              echo "linux-modules-@module@: latelink specifier invalid, ignored" 1>&2
 		latelink=''
 		;;
 esac
@@ -45,8 +45,8 @@  if [ "$RET" != "$latelink" ]; then
 # If you change this file run one of the commands below to pull existing
 # installed packages into compliance:
 #
-# sudo dpkg-reconfigure linux-modules-nvidia-$(uname -r)
-# sudo dpkg-reconfigure $(dpkg -l 'linux-modules-nvidia-*' | awk '/^ii/ { print $2 }')
+# sudo dpkg-reconfigure linux-modules-@module@-$(uname -r)
+# sudo dpkg-reconfigure $(dpkg -l 'linux-modules-@module@-*' | awk '/^ii/ { print $2 }')
 
 latelink=$RET
 EOM
@@ -59,13 +59,13 @@  fi
 if [ "$RET" = 'true' ]; then
 	(
 		cd "$bits" || exit 1
-		echo "linux-image-nvidia-$version: constructing .ko files"
+		echo "linux-image-@module@-$version: constructing .ko files"
 		/bin/sh ./BUILD
 	)
 else
 	(
 		cd "$bits" || exit 1
-		echo "linux-image-nvidia-$version: removing .ko files"
+		echo "linux-image-@module@-$version: removing .ko files"
 		/bin/sh ./CLEAN
 	)
 fi
diff --git a/debian/templates/nvidia.prerm.in b/debian/templates/nvidia.prerm.in
index f8b8e3e..38cafaa 100755
--- a/debian/templates/nvidia.prerm.in
+++ b/debian/templates/nvidia.prerm.in
@@ -3,7 +3,7 @@  set -e
 
 version=@abiname@@localversion@
 
-bits=/lib/modules/$version/kernel/nvidia-@nvidia-ver@/bits
+bits=/lib/modules/$version/kernel/@module@-@suffix-short@/bits
 
 if [ "$1" != remove ]; then
     exit 0
@@ -12,7 +12,7 @@  fi
 # Clear out the build image before we lose the ability to do so.
 (
 	cd "$bits" || exit 1
-	echo "linux-image-nvidia-$version: removing .ko files"
+	echo "linux-image-@module@-$version: removing .ko files"
 	/bin/sh ./CLEAN
 )