diff mbox series

[1/9] UBUNTU: [Packaging] parameterise package generator based on package

Message ID 20210308150004.1746089-2-apw@canonical.com
State New
Headers show
Series LP#1918134 -- LRMv4 switch to signing with Ubuntu Kernel Modules signing key | expand

Commit Message

Andy Whitcroft March 8, 2021, 2:59 p.m. UTC
Move debian/scripts/gen-rules to a package specific name and add a simple
name based switch table to call it.  No changes are made to gen-rules.lrm.

BugLink: https://bugs.launchpad.net/bugs/1918134
Signed-off-by: Andy Whitcroft <apw@canonical.com>
---
 debian/scripts/gen-rules     | 175 +----------------------------------
 debian/scripts/gen-rules.lrm | 173 ++++++++++++++++++++++++++++++++++
 2 files changed, 178 insertions(+), 170 deletions(-)
 create mode 100755 debian/scripts/gen-rules.lrm
diff mbox series

Patch

diff --git a/debian/scripts/gen-rules b/debian/scripts/gen-rules
index 19830c0..ff91f48 100755
--- a/debian/scripts/gen-rules
+++ b/debian/scripts/gen-rules
@@ -1,173 +1,8 @@ 
 #!/bin/bash
 
-mkdir -p "debian/control.d"
-cat "debian/rules.in" >"debian/rules.gen"
-: >"debian/control.gen"
-: >"debian/control.d/meta-nvidia"
-: >"debian/control.d/nvidia"
-: >"debian/control.d/migrate-nvidia"
-: >"debian/control.d/transitionals-local"
+src_package=$(LC_ALL=C dpkg-parsechangelog -SSource)
+case "$src_package" in
+linux-restricted-modules*)	pkg='lrm' ;;
+esac
 
-dkms_build_new=$(grep -c 'shift 7' debian/scripts/dkms-build)
-if [ "$dkms_build_new" -eq 0 ]; then
-	sed -i -e '/debian\/scripts\/dkms-build/s/ $(4)//' debian/rules.gen
-fi
-
-nvidia_desktop=
-nvidia_server=
-nvidia_ignore=
-while read command arg
-do
-	case "$command" in
-	option)		;;
-	suppress)		nvidia_ignore="$nvidia_ignore $arg"; continue ;;
-	*)		continue ;;
-	esac
-
-	case "$arg" in
-	desktop)	nvidia_desktop=y ;;
-	server)		nvidia_server=y ;;
-	esac
-done <"debian/package.config"
-
-while read command flavour archs
-do
-	case "$command" in
-	build)		;;
-	*)		continue ;;
-	esac
-
-	targets=$(echo "$archs" | sed -e 's/\</nvidia-/g')
-
-	cat - >>"debian/control.gen" <<EOL
- linux-headers-@ABI@-${flavour} (>= @VERSION@) [${archs}],
- linux-buildinfo-@ABI@-${flavour} (>= @VERSION@) [${archs}],
-EOL
-
-	while read package version extra
-	do
-		case "$package" in
-		nvidia-graphics-drivers-*-server)
-			[ -z "$nvidia_server" ] && continue
-			;;
-		nvidia-graphics-drivers-*)
-			[ -z "$nvidia_desktop" ] && continue
-			;;
-		*) continue ;;
-		esac
-		case " $nvidia_ignore " in
-		*\ $package\ *)		continue ;;
-		esac
-
-		case " $extra " in
-		*\ signonly\ *)		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')
-
-		echo "II: build $package for $flavour $archs"
-
-		# 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
-		# debian/control.d/migrate-nvidia
-		for cmd in $extra
-		do
-			case "$cmd" in
-			transition=*)
-				from="${cmd#transition=}"
-				from_minus=$(echo "$from" | sed -e 's/nvidia-graphics-drivers-//')
-				echo "II: general transition $from -> $package ($from_minus -> $suffix_minus)"
-				cat - >>"debian/control.d/migrate-nvidia" <<EOL
-Package: linux-modules-nvidia-${from_minus}-${flavour}\${variant:suffix}
-Architecture: ${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)
- 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"
-
-while read command from to archs
-do
-	case "$command" in
-	transitional)	;;
-	*)		continue ;;
-	esac
-
-	# debian/control.d/transitionals-local
-	echo "II: manual transition linux-modules-nvidia-$from -> linux-modules-nvidia-$to"
-	cat - >>"debian/control.d/transitionals-local" <<EOL
-Package: linux-modules-nvidia-${from}
-Architecture: ${archs}
-Section: oldlibs
-Depends: linux-modules-nvidia-${to}
-Description: Extra drivers for nvidia-${from} (dummy transitional package)
- Transitional package for upgrades of ${from} to ${to}.
-
-EOL
-done <"debian/package.config"
+exec "$0.$pkg" "$@"
diff --git a/debian/scripts/gen-rules.lrm b/debian/scripts/gen-rules.lrm
new file mode 100755
index 0000000..19830c0
--- /dev/null
+++ b/debian/scripts/gen-rules.lrm
@@ -0,0 +1,173 @@ 
+#!/bin/bash
+
+mkdir -p "debian/control.d"
+cat "debian/rules.in" >"debian/rules.gen"
+: >"debian/control.gen"
+: >"debian/control.d/meta-nvidia"
+: >"debian/control.d/nvidia"
+: >"debian/control.d/migrate-nvidia"
+: >"debian/control.d/transitionals-local"
+
+dkms_build_new=$(grep -c 'shift 7' debian/scripts/dkms-build)
+if [ "$dkms_build_new" -eq 0 ]; then
+	sed -i -e '/debian\/scripts\/dkms-build/s/ $(4)//' debian/rules.gen
+fi
+
+nvidia_desktop=
+nvidia_server=
+nvidia_ignore=
+while read command arg
+do
+	case "$command" in
+	option)		;;
+	suppress)		nvidia_ignore="$nvidia_ignore $arg"; continue ;;
+	*)		continue ;;
+	esac
+
+	case "$arg" in
+	desktop)	nvidia_desktop=y ;;
+	server)		nvidia_server=y ;;
+	esac
+done <"debian/package.config"
+
+while read command flavour archs
+do
+	case "$command" in
+	build)		;;
+	*)		continue ;;
+	esac
+
+	targets=$(echo "$archs" | sed -e 's/\</nvidia-/g')
+
+	cat - >>"debian/control.gen" <<EOL
+ linux-headers-@ABI@-${flavour} (>= @VERSION@) [${archs}],
+ linux-buildinfo-@ABI@-${flavour} (>= @VERSION@) [${archs}],
+EOL
+
+	while read package version extra
+	do
+		case "$package" in
+		nvidia-graphics-drivers-*-server)
+			[ -z "$nvidia_server" ] && continue
+			;;
+		nvidia-graphics-drivers-*)
+			[ -z "$nvidia_desktop" ] && continue
+			;;
+		*) continue ;;
+		esac
+		case " $nvidia_ignore " in
+		*\ $package\ *)		continue ;;
+		esac
+
+		case " $extra " in
+		*\ signonly\ *)		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')
+
+		echo "II: build $package for $flavour $archs"
+
+		# 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
+		# debian/control.d/migrate-nvidia
+		for cmd in $extra
+		do
+			case "$cmd" in
+			transition=*)
+				from="${cmd#transition=}"
+				from_minus=$(echo "$from" | sed -e 's/nvidia-graphics-drivers-//')
+				echo "II: general transition $from -> $package ($from_minus -> $suffix_minus)"
+				cat - >>"debian/control.d/migrate-nvidia" <<EOL
+Package: linux-modules-nvidia-${from_minus}-${flavour}\${variant:suffix}
+Architecture: ${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)
+ 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"
+
+while read command from to archs
+do
+	case "$command" in
+	transitional)	;;
+	*)		continue ;;
+	esac
+
+	# debian/control.d/transitionals-local
+	echo "II: manual transition linux-modules-nvidia-$from -> linux-modules-nvidia-$to"
+	cat - >>"debian/control.d/transitionals-local" <<EOL
+Package: linux-modules-nvidia-${from}
+Architecture: ${archs}
+Section: oldlibs
+Depends: linux-modules-nvidia-${to}
+Description: Extra drivers for nvidia-${from} (dummy transitional package)
+ Transitional package for upgrades of ${from} to ${to}.
+
+EOL
+done <"debian/package.config"