builddeb 7.8 KB

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