]> git.karo-electronics.de Git - karo-tx-linux.git/blob - scripts/package/builddeb
kbuild, deb-pkg: Fix build with paranoid umask
[karo-tx-linux.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         cp debian/copyright "$pdir/usr/share/doc/$pname/"
19         cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian"
20         gzip -9 "$pdir/usr/share/doc/$pname/changelog.Debian"
21         sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \
22                 | xargs -r0 md5sum > DEBIAN/md5sums"
23
24         # Fix ownership and permissions
25         chown -R root:root "$pdir"
26         chmod -R go-w "$pdir"
27
28         # Create the package
29         dpkg-gencontrol -isp -p$pname -P"$pdir"
30         dpkg --build "$pdir" ..
31 }
32
33 # Some variables and settings used throughout the script
34 version=$KERNELRELEASE
35 revision=$(cat .version)
36 if [ -n "$KDEB_PKGVERSION" ]; then
37         packageversion=$KDEB_PKGVERSION
38 else
39         packageversion=$version-$revision
40 fi
41 tmpdir="$objtree/debian/tmp"
42 fwdir="$objtree/debian/fwtmp"
43 packagename=linux-image-$version
44 fwpackagename=linux-firmware-image
45
46 if [ "$ARCH" = "um" ] ; then
47         packagename=user-mode-linux-$version
48 fi
49
50 # Setup the directory structure
51 rm -rf "$tmpdir" "$fwdir"
52 mkdir -m 755 -p "$tmpdir/DEBIAN"
53 mkdir -p  "$tmpdir/lib" "$tmpdir/boot" "$tmpdir/usr/share/doc/$packagename"
54 mkdir -m 755 -p "$fwdir/DEBIAN"
55 mkdir -p "$fwdir/lib" "$fwdir/usr/share/doc/$fwpackagename"
56 if [ "$ARCH" = "um" ] ; then
57         mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin"
58 fi
59
60 # Build and install the kernel
61 if [ "$ARCH" = "um" ] ; then
62         $MAKE linux
63         cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
64         cp .config "$tmpdir/usr/share/doc/$packagename/config"
65         gzip "$tmpdir/usr/share/doc/$packagename/config"
66         cp $KBUILD_IMAGE "$tmpdir/usr/bin/linux-$version"
67 else 
68         cp System.map "$tmpdir/boot/System.map-$version"
69         cp .config "$tmpdir/boot/config-$version"
70         # Not all arches include the boot path in KBUILD_IMAGE
71         if [ -e $KBUILD_IMAGE ]; then
72                 cp $KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
73         else
74                 cp arch/$ARCH/boot/$KBUILD_IMAGE "$tmpdir/boot/vmlinuz-$version"
75         fi
76 fi
77
78 if grep -q '^CONFIG_MODULES=y' .config ; then
79         INSTALL_MOD_PATH="$tmpdir" make KBUILD_SRC= modules_install
80         if [ "$ARCH" = "um" ] ; then
81                 mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
82                 rmdir "$tmpdir/lib/modules/$version"
83         fi
84 fi
85
86 # Install the maintainer scripts
87 # Note: hook scripts under /etc/kernel are also executed by official Debian
88 # kernel packages, as well as kernel packages built using make-kpkg
89 debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
90 for script in postinst postrm preinst prerm ; do
91         mkdir -p "$tmpdir$debhookdir/$script.d"
92         cat <<EOF > "$tmpdir/DEBIAN/$script"
93 #!/bin/sh
94
95 set -e
96
97 # Pass maintainer script parameters to hook scripts
98 export DEB_MAINT_PARAMS="\$*"
99
100 test -d $debhookdir/$script.d && run-parts --arg="$version" $debhookdir/$script.d
101 exit 0
102 EOF
103         chmod 755 "$tmpdir/DEBIAN/$script"
104 done
105
106 # Try to determine maintainer and email values
107 if [ -n "$DEBEMAIL" ]; then
108        email=$DEBEMAIL
109 elif [ -n "$EMAIL" ]; then
110        email=$EMAIL
111 else
112        email=$(id -nu)@$(hostname -f)
113 fi
114 if [ -n "$DEBFULLNAME" ]; then
115        name=$DEBFULLNAME
116 elif [ -n "$NAME" ]; then
117        name=$NAME
118 else
119        name="Anonymous"
120 fi
121 maintainer="$name <$email>"
122
123 # Generate a simple changelog template
124 cat <<EOF > debian/changelog
125 linux-upstream ($packageversion) unstable; urgency=low
126
127   * Custom built Linux kernel.
128
129  -- $maintainer  $(date -R)
130 EOF
131
132 # Generate copyright file
133 cat <<EOF > debian/copyright
134 This is a packacked upstream version of the Linux kernel.
135
136 The sources may be found at most Linux ftp sites, including:
137 ftp://ftp.kernel.org/pub/linux/kernel
138
139 Copyright: 1991 - 2009 Linus Torvalds and others.
140
141 The git repository for mainline kernel development is at:
142 git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
143
144     This program is free software; you can redistribute it and/or modify
145     it under the terms of the GNU General Public License as published by
146     the Free Software Foundation; version 2 dated June, 1991.
147
148 On Debian GNU/Linux systems, the complete text of the GNU General Public
149 License version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
150 EOF
151
152 # Generate a control file
153 cat <<EOF > debian/control
154 Source: linux-upstream
155 Section: kernel
156 Priority: optional
157 Maintainer: $maintainer
158 Standards-Version: 3.8.4
159 Homepage: http://www.kernel.org/
160 EOF
161
162 if [ "$ARCH" = "um" ]; then
163         cat <<EOF >> debian/control
164
165 Package: $packagename
166 Provides: linux-image, linux-image-2.6, linux-modules-$version
167 Architecture: any
168 Description: User Mode Linux kernel, version $version
169  User-mode Linux is a port of the Linux kernel to its own system call
170  interface.  It provides a kind of virtual machine, which runs Linux
171  as a user process under another Linux kernel.  This is useful for
172  kernel development, sandboxes, jails, experimentation, and
173  many other things.
174  .
175  This package contains the Linux kernel, modules and corresponding other
176  files, version: $version.
177 EOF
178
179 else
180         cat <<EOF >> debian/control
181
182 Package: $packagename
183 Provides: linux-image, linux-image-2.6, linux-modules-$version
184 Suggests: $fwpackagename
185 Architecture: any
186 Description: Linux kernel, version $version
187  This package contains the Linux kernel, modules and corresponding other
188  files, version: $version.
189 EOF
190
191 fi
192
193 # Do we have firmware? Move it out of the way and build it into a package.
194 if [ -e "$tmpdir/lib/firmware" ]; then
195         mv "$tmpdir/lib/firmware" "$fwdir/lib/"
196
197         cat <<EOF >> debian/control
198
199 Package: $fwpackagename
200 Architecture: all
201 Description: Linux kernel firmware, version $version
202  This package contains firmware from the Linux kernel, version $version.
203 EOF
204
205         create_package "$fwpackagename" "$fwdir"
206 fi
207
208 create_package "$packagename" "$tmpdir"
209
210 exit 0