builddeb 8.8 KB

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