Skip to contentSkip to conversation

Improve flexibility of deb-pkg target

PATCH NAK Frans Pop 2 participants 12 messages Apr 1, 2009 Kbuild

lore
Share & tools
lore

Frans Pop

author
#0 lore raw

cover Improve flexibility of deb-pkg target

Hi Sam,

This series of patches aims to make the deb-pkg target more flexible. I've been using these patches for the past year or so and they've greatly improved my workflow for kernel testing on 4 different architectures (2 cross-compiled).

The last 2 patches I've submitted before (in Feb. 2008) but were not applied as you had some questions. This new series has improved versions and I'll address your questions below.

[1/5] deb-pkg: minor general improvements in builddeb script [2/5] deb-pkg: fix 'file not found' error when building .deb package for arm

These first 2 patches are minor improvements and fixes.

[3/5] deb-pkg: pass Debian maintainer script parameters to packaging hook scripts

This allows to make hook scripts more specific differentiate their behavior for e.g. package installation, removal or upgrade. It's very much Debian specific.

[4/5] deb-pkg: allow to specify a custom revision for .deb packages

This has helped me to use a different versioning system for bisections than for "regular" builds. Note that this does not affect the kernel version (which is part of the package name), but only the version of the generated .deb package itself.

[5/5] deb-pkg: allow alternative hook scripts directory in .deb packages

This last patch comes in two variants (5a and 5b) because for my previous submission you asked:

Quoted 2 lines

Does this btw have to be an environment variable?
Why not make it a config option?

I personally prefer the first variant (env var) because I feel having a config option for this will mainly be confusing for people not using the deb-pkg target (probably the vast majority :-).
Either variant works for me, so I'm happy to let you choose.

For my previous version of patches 4 and 5 you also asked if the changes could be relevant for .rpm packages. AFAICT they are not:
- .rpm packages do not have a package version separate from the kernel version;
- .rpm packages do not have a hook scripts structure; it's a .deb-specific mechanism also used for kernel images built using other methods (official kernels, make-kpkg)
But I'm not an .rpm user, so I may be wrong.

After the changes have been accepted I plan to write a doc explaining how the deb-pkg target works. I'll submit that separately later.

A few of the patches have minor conflicts with the patch series Maximilian Attems submitted yesterday, but they should be easy to resolve. If you prefer I'll be happy to rebase mine on top of his series when it's clear what will get accepted.

Cheers,
FJP

Diffstat with the 5a patch:

 scripts/package/builddeb |   51 +++++++++++++++++++++++++++++----------------
 1 files changed, 33 insertions(+), 18 deletions(-)

With the 5b variant this becomes:

 init/Kconfig             |   12 +++++++++++
 scripts/package/Makefile |    2 +
 scripts/package/builddeb |   50 +++++++++++++++++++++++++++++----------------
 3 files changed, 46 insertions(+), 18 deletions(-)
author
#1 lore raw

PATCH 1/5 deb-pkg: minor general improvements in builddeb script

* minor coding style improvements
* typo fix in leading comment
* better changelog entry
* minor improvements in package descriptions

scripts/package/builddeb +4 -4
index 1264b8e..462ee45 100644
@@ -4,7 +4,7 @@
 # Copyright 2003 Wichert Akkerman <[email protected]>
 #
 # Simple script to generate a deb package for a Linux kernel. All the
-# complexity of what to do with a kernel after it is installer or removed
+# complexity of what to do with a kernel after it is installed or removed
 # is left to other scripts and packages: they can install scripts in the
 # /etc/kernel/{pre,post}{inst,rm}.d/ directories that will be called on
 # package install and removal.
@@ -13,13 +13,13 @@ set -e
 
 # Some variables and settings used throughout the script
 version=$KERNELRELEASE
-revision=`cat .version`
+revision=$(cat .version)
 tmpdir="$objtree/debian/tmp"
 fwdir="$objtree/debian/fwtmp"
 packagename=linux-$version
 fwpackagename=linux-firmware-image
 
-if [ "$ARCH" == "um" ] ; then
+if [ "$ARCH" = "um" ] ; then
 	packagename=user-mode-linux-$version
 fi
 
@@ -27,12 +27,12 @@ fi
 rm -rf "$tmpdir" "$fwdir"
 mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot"
 mkdir -p "$fwdir/DEBIAN" "$fwdir/lib"
-if [ "$ARCH" == "um" ] ; then
+if [ "$ARCH" = "um" ] ; then
 	

mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/share/doc/$packagename" "$tmpdir/usr/bin"
fi

# Build and install the kernel
-if [ "$ARCH" == "um" ] ; then
+if [ "$ARCH" = "um" ] ; then
$MAKE linux
cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map" cp .config "$tmpdir/usr/share/doc/$packagename/config"
@@ -46,7 +46,7 @@ fi

if grep -q '^CONFIG_MODULES=y' .config ; then
INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
- if [ "$ARCH" == "um" ] ; then
+ if [ "$ARCH" = "um" ] ; then
mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/" rmdir "$tmpdir/lib/modules/$version"
fi
@@ -71,13 +71,13 @@ name="Kernel Compiler <$(id -nu)@$(hostname -f)>"
cat <<EOF > debian/changelog
linux ($version-$revision) unstable; urgency=low

- * A standard release
+ * Custom built Linux kernel.

-- $name $(date -R)
EOF

# Generate a control file
-if [ "$ARCH" == "um" ]; then
+if [ "$ARCH" = "um" ]; then

cat <<EOF > debian/control
Source: linux
@@ -97,7 +97,7 @@ Description: User Mode Linux kernel, version $version
many other things.
.
This package contains the Linux kernel, modules and corresponding other
- files version $version
+ files. Version: $version.
EOF

else
@@ -114,7 +114,7 @@ Suggests: $fwpackagename
Architecture: any
Description: Linux kernel, version $version
This package contains the Linux kernel, modules and corresponding other
- files version $version
+ files. Version: $version.
EOF
fi

@@ -143,4 +143,3 @@ dpkg-gencontrol -isp -p$packagename
dpkg --build "$tmpdir" ..

exit 0
-

#2 lore raw

Re: [PATCH 1/5] deb-pkg: minor general improvements in builddeb script

Quoted 6 lines · Frans Pop

* minor coding style improvements
* typo fix in leading comment
* better changelog entry
* minor improvements in package descriptions

ack,
beside the changelog entry, have more work done in that region ;)

Quoted 98 lines
scripts/package/builddeb +4 -4
index 1264b8e..462ee45 100644
@@ -4,7 +4,7 @@
 # Copyright 2003 Wichert Akkerman <[email protected]>
 #
 # Simple script to generate a deb package for a Linux kernel. All the
-# complexity of what to do with a kernel after it is installer or removed
+# complexity of what to do with a kernel after it is installed or removed
 # is left to other scripts and packages: they can install scripts in the
 # /etc/kernel/{pre,post}{inst,rm}.d/ directories that will be called on
 # package install and removal.
@@ -13,13 +13,13 @@ set -e
 
 # Some variables and settings used throughout the script
 version=$KERNELRELEASE
-revision=`cat .version`
+revision=$(cat .version)
 tmpdir="$objtree/debian/tmp"
 fwdir="$objtree/debian/fwtmp"
 packagename=linux-$version
 fwpackagename=linux-firmware-image
 
-if [ "$ARCH" == "um" ] ; then
+if [ "$ARCH" = "um" ] ; then
 	packagename=user-mode-linux-$version
 fi
 
@@ -27,12 +27,12 @@ fi
 rm -rf "$tmpdir" "$fwdir"
 mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot"
 mkdir -p "$fwdir/DEBIAN" "$fwdir/lib"
-if [ "$ARCH" == "um" ] ; then
+if [ "$ARCH" = "um" ] ; then
 

mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/share/doc/$packagename" "$tmpdir/usr/bin"
fi

# Build and install the kernel

scripts/package/builddeb +6 -8
-if [ "$ARCH" == "um" ] ; then
+if [ "$ARCH" = "um" ] ; then
 	$MAKE linux
 	cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
 	cp .config "$tmpdir/usr/share/doc/$packagename/config"
@@ -46,7 +46,7 @@ fi
 
 if grep -q '^CONFIG_MODULES=y' .config ; then
 	INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
-	if [ "$ARCH" == "um" ] ; then
+	if [ "$ARCH" = "um" ] ; then
 		mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
 		rmdir "$tmpdir/lib/modules/$version"
 	fi
@@ -71,13 +71,13 @@ name="Kernel Compiler <$(id -nu)@$(hostname -f)>"
 cat <<EOF > debian/changelog
 linux ($version-$revision) unstable; urgency=low
 
-  * A standard release
+  * Custom built Linux kernel.
 
  -- $name  $(date -R)
 EOF
 
 # Generate a control file
-if [ "$ARCH" == "um" ]; then
+if [ "$ARCH" = "um" ]; then
 
 cat <<EOF > debian/control
 Source: linux
@@ -97,7 +97,7 @@ Description: User Mode Linux kernel, version $version
  many other things.
  .
  This package contains the Linux kernel, modules and corresponding other
- files version $version
+ files. Version: $version.
 EOF
 
 else
@@ -114,7 +114,7 @@ Suggests: $fwpackagename
 Architecture: any
 Description: Linux kernel, version $version
  This package contains the Linux kernel, modules and corresponding other
- files version $version
+ files. Version: $version.
 EOF
 fi
 
@@ -143,4 +143,3 @@ dpkg-gencontrol -isp -p$packagename
 dpkg --build "$tmpdir" ..
 
 exit 0
-
--

To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
maks
author
#3 lore raw

PATCH 2/5 deb-pkg: fix 'file not found' error when building .deb package for arm

In reply to Frans Pop

Not all architectures prepend the $(boot) path in $(KBUILD_IMAGE). Allow for that fact in the builddeb script. Example is arm.

scripts/package/builddeb +4 -1
index 462ee45..5b1517d 100644
@@ -41,7 +41,10 @@ if [ "$ARCH" = "um" ] ; then
 else 
 	cp System.map "$tmpdir/boot/System.map-$version"
 	cp .config "$tmpdir/boot/config-$version"
-	cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
+	# Not all arches include the boot path in KBUILD_IMAGE
+	if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then
+		cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
+	fi
 fi
 
 if grep -q '^CONFIG_MODULES=y' .config ; then
author
#4 lore raw

PATCH 3/5 deb-pkg: pass Debian maintainer script parameters to packaging hook scripts

In reply to Frans Pop

The Debian packaging scripts created by the deb-pkg target do not pass on the standard Debian maintainer script parameters to hook scripts, which means that those scripts cannot tell whether they are being called during e.g. install vs. upgrade, or removal vs. purge of the package.

As there are several variantions in how hook scripts are called from kernel packages, we pass the parameters in the environment variable DEB_MAINT_PARAMS rather than as extra arguments.

Bump version of builddep script to 1.3.

scripts/package/builddeb +6 -2
index 5b1517d..c9a4dcd 100644
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# builddeb 1.2
+# builddeb 1.3
 # Copyright 2003 Wichert Akkerman <[email protected]>
 #
 # Simple script to generate a deb package for a Linux kernel. All the
@@ -63,7 +63,11 @@ for script in postinst postrm preinst prerm ; do
 
 set -e
 
-test -d /etc/kernel/$script.d && run-parts --arg="$version" /etc/kernel/$script.d
+# Pass maintainer script parameters to hook scripts
+export DEB_MAINT_PARAMS="\$@"
+
+test -d $debhookdir/$script.d && \\
+	run-parts --arg="$version" /etc/kernel/$script.d
 exit 0
 EOF
 	chmod 755 "$tmpdir/DEBIAN/$script"
#5 lore raw

Re: [PATCH 3/5] deb-pkg: pass Debian maintainer script parameters to packaging hook scripts

Quoted 5 lines · Frans Pop

The Debian packaging scripts created by the deb-pkg target do not pass on the standard Debian maintainer script parameters to hook scripts, which means that those scripts cannot tell whether they are being called during e.g. install vs. upgrade, or removal vs. purge of the package.

Quoted 7 lines

As there are several variantions in how hook scripts are called from kernel packages, we pass the parameters in the environment variable DEB_MAINT_PARAMS rather than as extra arguments.

Bump version of builddep script to 1.3.

ack for the env variable.

Quoted 13 lines
scripts/package/builddeb +1 -1
index 5b1517d..c9a4dcd 100644
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# builddeb 1.2
+# builddeb 1.3
 # Copyright 2003 Wichert Akkerman <[email protected]>
 #
 # Simple script to generate a deb package for a Linux kernel. All the

scripts/package/builddeb for script in postinst postrm preinst prerm ; do · line 70

Quoted 9 lines
scripts/package/builddeb +5 -1
@@ -63,7 +63,11 @@ for script in postinst postrm preinst prerm ; do
 
 set -e
 
-test -d /etc/kernel/$script.d && run-parts --arg="$version" /etc/kernel/$script.d
+# Pass maintainer script parameters to hook scripts
+export DEB_MAINT_PARAMS="\$@"
+
+test -d $debhookdir/$script.d && \\
+	run-parts --arg="$version" /etc/kernel/$script.d

gratious formating change, please if this needs to be broken in 2 lines, break before && so that logic is more evident.

Quoted 8 lines
scripts/package/builddeb +0 -1
 exit 0
 EOF
 	chmod 755 "$tmpdir/DEBIAN/$script"
--

To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
maks
author
#7 lore raw

PATCH 1/1 deb-pkg: allow alternative hook scripts directory in .deb packages

In reply to Frans Pop

Hook scripts in the default directory /etc/kernel are also executed by official Debian kernel packages as well as kernel packages created using make-kpkg. Allow to specify an alternative hook scripts directory by exporting the environment variable KDEB_HOOKDIR.

scripts/package/builddeb +8 -4
index 1b8820f..dada305 100644
@@ -6,8 +6,9 @@
 # Simple script to generate a deb package for a Linux kernel. All the
 # complexity of what to do with a kernel after it is installed or removed
 # is left to other scripts and packages: they can install scripts in the
-# /etc/kernel/{pre,post}{inst,rm}.d/ directories that will be called on
-# package install and removal.
+# /etc/kernel/{pre,post}{inst,rm}.d/ directories (or an alternative location
+# specified in KDEB_HOOKDIR) that will be called on package install and
+# removal.
 
 set -e
 
@@ -61,8 +62,11 @@ if grep -q '^CONFIG_MODULES=y' .config ; then
 fi
 
 # Install the maintainer scripts
+# Note: hook scripts under /etc/kernel are also executed by official Debian
+# kernel packages, as well as kernel packages built using make-kpkg
+debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
 for script in postinst postrm preinst prerm ; do
-	mkdir -p "$tmpdir/etc/kernel/$script.d"
+	mkdir -p "$tmpdir$debhookdir/$script.d"
 	cat <<EOF > "$tmpdir/DEBIAN/$script"
 #!/bin/sh
 
@@ -72,7 +76,7 @@ set -e
 export DEB_MAINT_PARAMS="\$@"
 
 test -d $debhookdir/$script.d && \\
-	run-parts --arg="$version" /etc/kernel/$script.d
+	run-parts --arg="$version" $debhookdir/$script.d
 exit 0
 EOF
 	chmod 755 "$tmpdir/DEBIAN/$script"
#8 lore raw

Re: [PATCH 5a/5] deb-pkg: allow alternative hook scripts directory in .deb packages

Quoted 4 lines · Frans Pop

Hook scripts in the default directory /etc/kernel are also executed by official Debian kernel packages as well as kernel packages created using make-kpkg. Allow to specify an alternative hook scripts directory by exporting the environment variable KDEB_HOOKDIR.

under discusisson, no ack yet.

author
#9 lore raw

PATCH 1/1 deb-pkg: allow alternative hook scripts directory in .deb packages

In reply to Frans Pop

Hook scripts in the default directory /etc/kernel are also executed by official Debian kernel packages as well as kernel packages created using make-kpkg. Allow to specify the base hook scripts directory in the kernel configuration (DEB_HOOKDIRS_PATH).

init/Kconfig +12 -0
index 6a5c5fe..3121b01 100644
@@ -101,6 +101,18 @@ config LOCALVERSION_AUTO
 
 	  which is done within the script "scripts/setlocalversion".)
 
+config DEB_HOOKDIRS_PATH
+	string "location of hook script directories for Debian packages"
+	default "/etc/kernel"
+	help
+	  Path to {pre,post}{inst,rm}.d/ directories containing hook scripts
+	  that are called during installation/removal of a Debian kernel
+          package built using the 'deb-pkg' target.
+
+	  As official Debian kernel packages also execute scripts under
+	  /etc/kernel, it may be desirable to specify an alternative location
+	  for custom built kernels.
+
 config SWAP
 	bool "Support for paging of anonymous memory (swap)"
 	depends on MMU && BLOCK
scripts/package/Makefile +2 -0
index fa4a0a1..5c72945 100644
@@ -68,6 +68,8 @@ clean-files += $(objtree)/binkernel.spec
 
 # Deb target
 # ---------------------------------------------------------------------------
+export DEB_HOOKDIRS_PATH = $(CONFIG_DEB_HOOKDIRS_PATH)
+
 deb-pkg: FORCE
 	$(MAKE) KBUILD_SRC=
 	$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb
scripts/package/builddeb +7 -4
index 1b8820f..d51a18f 100644
@@ -6,8 +6,8 @@
 # Simple script to generate a deb package for a Linux kernel. All the
 # complexity of what to do with a kernel after it is installed or removed
 # is left to other scripts and packages: they can install scripts in the
-# /etc/kernel/{pre,post}{inst,rm}.d/ directories that will be called on
-# package install and removal.
+# {pre,post}{inst,rm}.d/ directories under CONFIG_DEB_HOOKDIRS_PATH (by
+# default /etc/kernel) that will be called on package install and removal.
 
 set -e
 
@@ -61,8 +61,11 @@ if grep -q '^CONFIG_MODULES=y' .config ; then
 fi
 
 # Install the maintainer scripts
+# Note: hook scripts under /etc/kernel are also executed by official Debian
+# kernel packages, as well as kernel packages built using make-kpkg
+debhookdir=${DEB_HOOKDIRS_PATH:-/etc/kernel}
 for script in postinst postrm preinst prerm ; do
-	mkdir -p "$tmpdir/etc/kernel/$script.d"
+	mkdir -p "$tmpdir$debhookdir/$script.d"
 	cat <<EOF > "$tmpdir/DEBIAN/$script"
 #!/bin/sh
 
@@ -72,7 +75,7 @@ set -e
 export DEB_MAINT_PARAMS="\$@"
 
 test -d $debhookdir/$script.d && \\
-	run-parts --arg="$version" /etc/kernel/$script.d
+	run-parts --arg="$version" $debhookdir/$script.d
 exit 0
 EOF
 	chmod 755 "$tmpdir/DEBIAN/$script"
#10 lore raw

Re: [PATCH 5b/5] deb-pkg: allow alternative hook scripts directory in .deb packages

Quoted 4 lines · Frans Pop

Hook scripts in the default directory /etc/kernel are also executed by official Debian kernel packages as well as kernel packages created using make-kpkg. Allow to specify the base hook scripts directory in the kernel configuration (DEB_HOOKDIRS_PATH).

this seems overkill defer to discussions.

#11 lore raw
In reply to Frans Pop
Quoted 22 lines · Frans Pop

Hi Sam,

This series of patches aims to make the deb-pkg target more flexible. I've been using these patches for the past year or so and they've greatly improved my workflow for kernel testing on 4 different architectures (2 cross-compiled).

The last 2 patches I've submitted before (in Feb. 2008) but were not applied as you had some questions. This new series has improved versions and I'll address your questions below.

[1/5] deb-pkg: minor general improvements in builddeb script [2/5] deb-pkg: fix 'file not found' error when building .deb package for arm

These first 2 patches are minor improvements and fixes.

[3/5] deb-pkg: pass Debian maintainer script parameters to packaging hook scripts

This allows to make hook scripts more specific differentiate their behavior for e.g. package installation, removal or upgrade. It's very much Debian specific.

Quoted 8 lines

[4/5] deb-pkg: allow to specify a custom revision for .deb packages

This has helped me to use a different versioning system for bisections than for "regular" builds. Note that this does not affect the kernel version (which is part of the package name), but only the version of the generated .deb package itself.

[5/5] deb-pkg: allow alternative hook scripts directory in .deb packages

argh none of those apply on top of those that i just sent in, will nevertheless review them.