builddeb 6.8 KB

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