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