kbuild, deb-pkg: improve changelog entry and package descriptions
[pandora-kernel.git] / scripts / package / builddeb
1 #!/bin/sh
2 #
3 # builddeb 1.3
4 # Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
5 #
6 # Simple script to generate a deb package for a Linux kernel. All the
7 # complexity of what to do with a kernel after it is installed or removed
8 # is left to other scripts and packages: they can install scripts in the
9 # /etc/kernel/{pre,post}{inst,rm}.d/ directories (or an alternative location
10 # specified in KDEB_HOOKDIR) that will be called on package install and
11 # removal.
12
13 set -e
14
15 create_package() {
16         local pname="$1" pdir="$2"
17
18         # Fix ownership and permissions
19         chown -R root:root "$pdir"
20         chmod -R go-w "$pdir"
21
22         # Create the package
23         dpkg-gencontrol -isp -p$pname -P"$pdir"
24         dpkg --build "$pdir" ..
25 }
26
27 # Some variables and settings used throughout the script
28 version=$KERNELRELEASE
29 revision=$(cat .version)
30 if [ -n "$KDEB_PKGVERSION" ]; then
31         packageversion=$KDEB_PKGVERSION
32 else
33         packageversion=$version-$revision
34 fi
35 tmpdir="$objtree/debian/tmp"
36 fwdir="$objtree/debian/fwtmp"
37 packagename=linux-$version
38 fwpackagename=linux-firmware-image
39
40 if [ "$ARCH" = "um" ] ; then
41         packagename=user-mode-linux-$version
42 fi
43
44 # Setup the directory structure
45 rm -rf "$tmpdir" "$fwdir"
46 mkdir -p "$tmpdir/DEBIAN" "$tmpdir/lib" "$tmpdir/boot"
47 mkdir -p "$fwdir/DEBIAN" "$fwdir/lib"
48 if [ "$ARCH" = "um" ] ; then
49         mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/share/doc/$packagename" "$tmpdir/usr/bin"
50 fi
51
52 # Build and install the kernel
53 if [ "$ARCH" = "um" ] ; then
54         $MAKE linux
55         cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
56         cp .config "$tmpdir/usr/share/doc/$packagename/config"
57         gzip "$tmpdir/usr/share/doc/$packagename/config"
58         cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version"
59 else 
60         cp System.map "$tmpdir/boot/System.map-$version"
61         cp .config "$tmpdir/boot/config-$version"
62         # Not all arches include the boot path in KBUILD_IMAGE
63         if ! cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"; then
64                 cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
65         fi
66 fi
67
68 if grep -q '^CONFIG_MODULES=y' .config ; then
69         INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
70         if [ "$ARCH" = "um" ] ; then
71                 mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
72                 rmdir "$tmpdir/lib/modules/$version"
73         fi
74 fi
75
76 # Install the maintainer scripts
77 # Note: hook scripts under /etc/kernel are also executed by official Debian
78 # kernel packages, as well as kernel packages built using make-kpkg
79 debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
80 for script in postinst postrm preinst prerm ; do
81         mkdir -p "$tmpdir$debhookdir/$script.d"
82         cat <<EOF > "$tmpdir/DEBIAN/$script"
83 #!/bin/sh
84
85 set -e
86
87 # Pass maintainer script parameters to hook scripts
88 export DEB_MAINT_PARAMS="\$@"
89
90 test -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d
91 exit 0
92 EOF
93         chmod 755 "$tmpdir/DEBIAN/$script"
94 done
95
96 name="Kernel Compiler <$(id -nu)@$(hostname -f)>"
97 # Generate a simple changelog template
98 cat <<EOF > debian/changelog
99 linux ($packageversion) unstable; urgency=low
100
101   * Custom built Linux kernel.
102
103  -- $name  $(date -R)
104 EOF
105
106 # Generate a control file
107 cat <<EOF > debian/control
108 Source: linux
109 Section: base
110 Priority: optional
111 Maintainer: $name
112 Standards-Version: 3.6.1
113 EOF
114
115 if [ "$ARCH" = "um" ]; then
116         cat <<EOF >> debian/control
117
118 Package: $packagename
119 Provides: kernel-image-$version, linux-image-$version
120 Architecture: any
121 Description: User Mode Linux kernel, version $version
122  User-mode Linux is a port of the Linux kernel to its own system call
123  interface.  It provides a kind of virtual machine, which runs Linux
124  as a user process under another Linux kernel.  This is useful for
125  kernel development, sandboxes, jails, experimentation, and
126  many other things.
127  .
128  This package contains the Linux kernel, modules and corresponding other
129  files, version: $version.
130 EOF
131
132 else
133         cat <<EOF >> debian/control
134
135 Package: $packagename
136 Provides: kernel-image-$version, linux-image-$version
137 Suggests: $fwpackagename
138 Architecture: any
139 Description: Linux kernel, version $version
140  This package contains the Linux kernel, modules and corresponding other
141  files, version: $version.
142 EOF
143
144 fi
145
146 # Do we have firmware? Move it out of the way and build it into a package.
147 if [ -e "$tmpdir/lib/firmware" ]; then
148         mv "$tmpdir/lib/firmware" "$fwdir/lib/"
149
150         cat <<EOF >> debian/control
151
152 Package: $fwpackagename
153 Architecture: all
154 Description: Linux kernel firmware, version $version
155  This package contains firmware from the Linux kernel, version $version.
156 EOF
157
158         create_package "$fwpackagename" "$fwdir"
159 fi
160
161 create_package "$packagename" "$tmpdir"
162
163 exit 0