mkdebian 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #!/bin/sh
  2. #
  3. # Copyright 2003 Wichert Akkerman <[email protected]>
  4. #
  5. # Simple script to generate a debian/ directory for a Linux kernel.
  6. set -e
  7. is_enabled() {
  8. grep -q "^$1=y" include/config/auto.conf
  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 CONFIG_64BIT 64) ;;
  30. s390*)
  31. debarch=s390x ;;
  32. ppc*)
  33. if is_enabled CONFIG_64BIT; then
  34. debarch=ppc64$(if_enabled_echo CONFIG_CPU_LITTLE_ENDIAN el)
  35. else
  36. debarch=powerpc$(if_enabled_echo CONFIG_SPE spe)
  37. fi
  38. ;;
  39. parisc*)
  40. debarch=hppa ;;
  41. mips*)
  42. if is_enabled CONFIG_CPU_LITTLE_ENDIAN; then
  43. debarch=mips$(if_enabled_echo CONFIG_64BIT 64)$(if_enabled_echo CONFIG_CPU_MIPSR6 r6)el
  44. elif is_enabled CONFIG_CPU_MIPSR6; then
  45. debarch=mips$(if_enabled_echo CONFIG_64BIT 64)r6
  46. else
  47. debarch=mips
  48. fi
  49. ;;
  50. aarch64|arm64)
  51. debarch=arm64 ;;
  52. arm*)
  53. if is_enabled CONFIG_AEABI; then
  54. debarch=arm$(if_enabled_echo CONFIG_VFP hf el)
  55. else
  56. debarch=arm
  57. fi
  58. ;;
  59. openrisc)
  60. debarch=or1k ;;
  61. sh)
  62. if is_enabled CONFIG_CPU_SH3; then
  63. debarch=sh3$(if_enabled_echo CONFIG_CPU_BIG_ENDIAN eb)
  64. elif is_enabled CONFIG_CPU_SH4; then
  65. debarch=sh4$(if_enabled_echo CONFIG_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. if [ "$ARCH" = "um" ] ; then
  92. packagename=user-mode-linux
  93. else
  94. packagename=linux-image
  95. fi
  96. debarch=
  97. set_debarch
  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/source/
  124. echo "1.0" > debian/source/format
  125. echo $debarch > debian/arch
  126. extra_build_depends=", $(if_enabled_echo CONFIG_UNWINDER_ORC libelf-dev:native)"
  127. extra_build_depends="$extra_build_depends, $(if_enabled_echo CONFIG_SYSTEM_TRUSTED_KEYRING libssl-dev:native)"
  128. # Generate a simple changelog template
  129. cat <<EOF > debian/changelog
  130. $sourcename ($packageversion) $distribution; urgency=low
  131. * Custom built Linux kernel.
  132. -- $maintainer $(date -R)
  133. EOF
  134. # Generate copyright file
  135. cat <<EOF > debian/copyright
  136. This is a packacked upstream version of the Linux kernel.
  137. The sources may be found at most Linux archive sites, including:
  138. https://www.kernel.org/pub/linux/kernel
  139. Copyright: 1991 - 2018 Linus Torvalds and others.
  140. The git repository for mainline kernel development is at:
  141. git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
  142. This program is free software; you can redistribute it and/or modify
  143. it under the terms of the GNU General Public License as published by
  144. the Free Software Foundation; version 2 dated June, 1991.
  145. On Debian GNU/Linux systems, the complete text of the GNU General Public
  146. License version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
  147. EOF
  148. # Generate a control file
  149. cat <<EOF > debian/control
  150. Source: $sourcename
  151. Section: kernel
  152. Priority: optional
  153. Maintainer: $maintainer
  154. Rules-Requires-Root: no
  155. Build-Depends: bc, rsync, kmod, cpio, bison, flex | flex:native $extra_build_depends
  156. Homepage: https://www.kernel.org/
  157. Package: $packagename-$version
  158. Architecture: $debarch
  159. Description: Linux kernel, version $version
  160. This package contains the Linux kernel, modules and corresponding other
  161. files, version: $version.
  162. Package: linux-libc-dev
  163. Section: devel
  164. Provides: linux-kernel-headers
  165. Architecture: $debarch
  166. Description: Linux support headers for userspace development
  167. This package provides userspaces headers from the Linux kernel. These headers
  168. are used by the installed headers for GNU glibc and other system libraries.
  169. Multi-Arch: same
  170. EOF
  171. if is_enabled CONFIG_MODULES; then
  172. cat <<EOF >> debian/control
  173. Package: linux-headers-$version
  174. Architecture: $debarch
  175. Description: Linux kernel headers for $version on $debarch
  176. This package provides kernel header files for $version on $debarch
  177. .
  178. This is useful for people who need to build external modules
  179. EOF
  180. fi
  181. if is_enabled CONFIG_DEBUG_INFO; then
  182. cat <<EOF >> debian/control
  183. Package: linux-image-$version-dbg
  184. Section: debug
  185. Architecture: $debarch
  186. Description: Linux kernel debugging symbols for $version
  187. This package will come in handy if you need to debug the kernel. It provides
  188. all the necessary debug symbols for the kernel and its modules.
  189. EOF
  190. fi
  191. cat <<EOF > debian/rules
  192. #!$(command -v $MAKE) -f
  193. srctree ?= .
  194. build-indep:
  195. build-arch:
  196. \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} \
  197. KBUILD_BUILD_VERSION=${revision} -f \$(srctree)/Makefile
  198. build: build-arch
  199. binary-indep:
  200. binary-arch: build-arch
  201. \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} \
  202. KBUILD_BUILD_VERSION=${revision} -f \$(srctree)/Makefile intdeb-pkg
  203. clean:
  204. rm -rf debian/files debian/linux-*
  205. \$(MAKE) clean
  206. binary: binary-arch
  207. EOF
  208. chmod +x debian/rules
  209. exit 0