builddeb 6.8 KB

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