mkdebian 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. else
  86. revision=$(cat .version 2>/dev/null||echo 1)
  87. packageversion=$version-$revision
  88. fi
  89. sourcename=$KDEB_SOURCENAME
  90. packagename=linux-image-$version
  91. kernel_headers_packagename=linux-headers-$version
  92. dbg_packagename=$packagename-dbg
  93. debarch=
  94. set_debarch
  95. if [ "$ARCH" = "um" ] ; then
  96. packagename=user-mode-linux-$version
  97. fi
  98. email=${DEBEMAIL-$EMAIL}
  99. # use email string directly if it contains <email>
  100. if echo $email | grep -q '<.*>'; then
  101. maintainer=$email
  102. else
  103. # or construct the maintainer string
  104. user=${KBUILD_BUILD_USER-$(id -nu)}
  105. name=${DEBFULLNAME-$user}
  106. if [ -z "$email" ]; then
  107. buildhost=${KBUILD_BUILD_HOST-$(hostname -f 2>/dev/null || hostname)}
  108. email="$user@$buildhost"
  109. fi
  110. maintainer="$name <$email>"
  111. fi
  112. # Try to determine distribution
  113. if [ -n "$KDEB_CHANGELOG_DIST" ]; then
  114. distribution=$KDEB_CHANGELOG_DIST
  115. # In some cases lsb_release returns the codename as n/a, which breaks dpkg-parsechangelog
  116. elif distribution=$(lsb_release -cs 2>/dev/null) && [ -n "$distribution" ] && [ "$distribution" != "n/a" ]; then
  117. : # nothing to do in this case
  118. else
  119. distribution="unstable"
  120. echo >&2 "Using default distribution of 'unstable' in the changelog"
  121. echo >&2 "Install lsb-release or set \$KDEB_CHANGELOG_DIST explicitly"
  122. fi
  123. mkdir -p debian/
  124. echo $debarch > debian/arch
  125. # Generate a simple changelog template
  126. cat <<EOF > debian/changelog
  127. $sourcename ($packageversion) $distribution; urgency=low
  128. * Custom built Linux kernel.
  129. -- $maintainer $(date -R)
  130. EOF
  131. # Generate copyright file
  132. cat <<EOF > debian/copyright
  133. This is a packacked upstream version of the Linux kernel.
  134. The sources may be found at most Linux archive sites, including:
  135. https://www.kernel.org/pub/linux/kernel
  136. Copyright: 1991 - 2018 Linus Torvalds and others.
  137. The git repository for mainline kernel development is at:
  138. git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
  139. This program is free software; you can redistribute it and/or modify
  140. it under the terms of the GNU General Public License as published by
  141. the Free Software Foundation; version 2 dated June, 1991.
  142. On Debian GNU/Linux systems, the complete text of the GNU General Public
  143. License version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
  144. EOF
  145. # Generate a control file
  146. cat <<EOF > debian/control
  147. Source: $sourcename
  148. Section: kernel
  149. Priority: optional
  150. Maintainer: $maintainer
  151. Build-Depends: bc, kmod, cpio
  152. Homepage: http://www.kernel.org/
  153. Package: $packagename
  154. Architecture: $debarch
  155. Description: Linux kernel, version $version
  156. This package contains the Linux kernel, modules and corresponding other
  157. files, version: $version.
  158. Package: $kernel_headers_packagename
  159. Architecture: $debarch
  160. Description: Linux kernel headers for $version on $debarch
  161. This package provides kernel header files for $version on $debarch
  162. .
  163. This is useful for people who need to build external modules
  164. Package: linux-libc-dev
  165. Section: devel
  166. Provides: linux-kernel-headers
  167. Architecture: $debarch
  168. Description: Linux support headers for userspace development
  169. This package provides userspaces headers from the Linux kernel. These headers
  170. are used by the installed headers for GNU glibc and other system libraries.
  171. Package: $dbg_packagename
  172. Section: debug
  173. Architecture: $debarch
  174. Description: Linux kernel debugging symbols for $version
  175. This package will come in handy if you need to debug the kernel. It provides
  176. all the necessary debug symbols for the kernel and its modules.
  177. EOF
  178. cat <<EOF > debian/rules
  179. #!$(command -v $MAKE) -f
  180. build:
  181. \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} KBUILD_SRC=
  182. binary-arch:
  183. \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} KBUILD_SRC= intdeb-pkg
  184. clean:
  185. rm -rf debian/*tmp debian/files
  186. \$(MAKE) clean
  187. binary: binary-arch
  188. EOF
  189. exit 0