mkdebian 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #!/bin/sh
  2. #
  3. # Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
  4. #
  5. # Simple script to generate a debian/ directory for a Linux kernel.
  6. set -e
  7. is_enabled() {
  8. grep -q "^CONFIG_$1=y" $KCONFIG_CONFIG
  9. }
  10. if_enabled_echo() {
  11. if is_enabled "$1"; then
  12. echo -n "$2"
  13. elif [ $# -ge 3 ]; then
  14. echo -n "$3"
  15. fi
  16. }
  17. set_debarch() {
  18. if [ -n "$KBUILD_DEBARCH" ] ; then
  19. debarch="$KBUILD_DEBARCH"
  20. return
  21. fi
  22. # Attempt to find the correct Debian architecture
  23. case "$UTS_MACHINE" in
  24. i386|ia64|alpha|m68k|riscv*)
  25. debarch="$UTS_MACHINE" ;;
  26. x86_64)
  27. debarch=amd64 ;;
  28. sparc*)
  29. debarch=sparc$(if_enabled_echo 64BIT 64) ;;
  30. s390*)
  31. debarch=s390x ;;
  32. ppc*)
  33. if is_enabled 64BIT; then
  34. debarch=ppc64$(if_enabled_echo CPU_LITTLE_ENDIAN el)
  35. else
  36. debarch=powerpc$(if_enabled_echo SPE spe)
  37. fi
  38. ;;
  39. parisc*)
  40. debarch=hppa ;;
  41. mips*)
  42. if is_enabled CPU_LITTLE_ENDIAN; then
  43. debarch=mips$(if_enabled_echo 64BIT 64)$(if_enabled_echo CPU_MIPSR6 r6)el
  44. elif is_enabled CPU_MIPSR6; then
  45. debarch=mips$(if_enabled_echo 64BIT 64)r6
  46. else
  47. debarch=mips
  48. fi
  49. ;;
  50. aarch64|arm64)
  51. debarch=arm64 ;;
  52. arm*)
  53. if is_enabled AEABI; then
  54. debarch=arm$(if_enabled_echo VFP hf el)
  55. else
  56. debarch=arm
  57. fi
  58. ;;
  59. openrisc)
  60. debarch=or1k ;;
  61. sh)
  62. if is_enabled CPU_SH3; then
  63. debarch=sh3$(if_enabled_echo CPU_BIG_ENDIAN eb)
  64. elif is_enabled CPU_SH4; then
  65. debarch=sh4$(if_enabled_echo CPU_BIG_ENDIAN eb)
  66. fi
  67. ;;
  68. esac
  69. if [ -z "$debarch" ]; then
  70. debarch=$(dpkg-architecture -qDEB_HOST_ARCH)
  71. echo "" >&2
  72. echo "** ** ** WARNING ** ** **" >&2
  73. echo "" >&2
  74. echo "Your architecture doesn't have its equivalent" >&2
  75. echo "Debian userspace architecture defined!" >&2
  76. echo "Falling back to the current host architecture ($debarch)." >&2
  77. echo "Please add support for $UTS_MACHINE to ${0} ..." >&2
  78. echo "" >&2
  79. fi
  80. }
  81. # Some variables and settings used throughout the script
  82. version=$KERNELRELEASE
  83. if [ -n "$KDEB_PKGVERSION" ]; then
  84. packageversion=$KDEB_PKGVERSION
  85. revision=${packageversion##*-}
  86. else
  87. revision=$(cat .version 2>/dev/null||echo 1)
  88. packageversion=$version-$revision
  89. fi
  90. sourcename=$KDEB_SOURCENAME
  91. packagename=linux-image-$version
  92. kernel_headers_packagename=linux-headers-$version
  93. dbg_packagename=$packagename-dbg
  94. debarch=
  95. set_debarch
  96. if [ "$ARCH" = "um" ] ; then
  97. packagename=user-mode-linux-$version
  98. fi
  99. email=${DEBEMAIL-$EMAIL}
  100. # use email string directly if it contains <email>
  101. if echo $email | grep -q '<.*>'; then
  102. maintainer=$email
  103. else
  104. # or construct the maintainer string
  105. user=${KBUILD_BUILD_USER-$(id -nu)}
  106. name=${DEBFULLNAME-$user}
  107. if [ -z "$email" ]; then
  108. buildhost=${KBUILD_BUILD_HOST-$(hostname -f 2>/dev/null || hostname)}
  109. email="$user@$buildhost"
  110. fi
  111. maintainer="$name <$email>"
  112. fi
  113. # Try to determine distribution
  114. if [ -n "$KDEB_CHANGELOG_DIST" ]; then
  115. distribution=$KDEB_CHANGELOG_DIST
  116. # In some cases lsb_release returns the codename as n/a, which breaks dpkg-parsechangelog
  117. elif distribution=$(lsb_release -cs 2>/dev/null) && [ -n "$distribution" ] && [ "$distribution" != "n/a" ]; then
  118. : # nothing to do in this case
  119. else
  120. distribution="unstable"
  121. echo >&2 "Using default distribution of 'unstable' in the changelog"
  122. echo >&2 "Install lsb-release or set \$KDEB_CHANGELOG_DIST explicitly"
  123. fi
  124. mkdir -p debian/
  125. echo $debarch > debian/arch
  126. # Generate a simple changelog template
  127. cat <<EOF > debian/changelog
  128. $sourcename ($packageversion) $distribution; urgency=low
  129. * Custom built Linux kernel.
  130. -- $maintainer $(date -R)
  131. EOF
  132. # Generate copyright file
  133. cat <<EOF > debian/copyright
  134. This is a packacked upstream version of the Linux kernel.
  135. The sources may be found at most Linux archive sites, including:
  136. https://www.kernel.org/pub/linux/kernel
  137. Copyright: 1991 - 2018 Linus Torvalds and others.
  138. The git repository for mainline kernel development is at:
  139. git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
  140. This program is free software; you can redistribute it and/or modify
  141. it under the terms of the GNU General Public License as published by
  142. the Free Software Foundation; version 2 dated June, 1991.
  143. On Debian GNU/Linux systems, the complete text of the GNU General Public
  144. License version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
  145. EOF
  146. # Generate a control file
  147. cat <<EOF > debian/control
  148. Source: $sourcename
  149. Section: kernel
  150. Priority: optional
  151. Maintainer: $maintainer
  152. Build-Depends: bc, kmod, cpio
  153. Homepage: http://www.kernel.org/
  154. Package: $packagename
  155. Architecture: $debarch
  156. Description: Linux kernel, version $version
  157. This package contains the Linux kernel, modules and corresponding other
  158. files, version: $version.
  159. Package: $kernel_headers_packagename
  160. Architecture: $debarch
  161. Description: Linux kernel headers for $version on $debarch
  162. This package provides kernel header files for $version on $debarch
  163. .
  164. This is useful for people who need to build external modules
  165. Package: linux-libc-dev
  166. Section: devel
  167. Provides: linux-kernel-headers
  168. Architecture: $debarch
  169. Description: Linux support headers for userspace development
  170. This package provides userspaces headers from the Linux kernel. These headers
  171. are used by the installed headers for GNU glibc and other system libraries.
  172. Package: $dbg_packagename
  173. Section: debug
  174. Architecture: $debarch
  175. Description: Linux kernel debugging symbols for $version
  176. This package will come in handy if you need to debug the kernel. It provides
  177. all the necessary debug symbols for the kernel and its modules.
  178. EOF
  179. cat <<EOF > debian/rules
  180. #!$(command -v $MAKE) -f
  181. build:
  182. \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} \
  183. KBUILD_BUILD_VERSION=${revision} KBUILD_SRC=
  184. binary-arch:
  185. \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} \
  186. KBUILD_BUILD_VERSION=${revision} KBUILD_SRC= intdeb-pkg
  187. clean:
  188. rm -rf debian/*tmp debian/files
  189. \$(MAKE) clean
  190. binary: binary-arch
  191. EOF
  192. exit 0