mkdebian 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 -eu
  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 [ "${KBUILD_DEBARCH:+set}" ]; then
  19. debarch="$KBUILD_DEBARCH"
  20. return
  21. fi
  22. # Attempt to find the correct Debian architecture
  23. case "$UTS_MACHINE" in
  24. i386|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. # Create debian/source/ if it is a source package build
  82. gen_source ()
  83. {
  84. mkdir -p debian/source
  85. echo "3.0 (quilt)" > debian/source/format
  86. {
  87. echo "diff-ignore"
  88. echo "extend-diff-ignore = .*"
  89. } > debian/source/local-options
  90. # Add .config as a patch
  91. mkdir -p debian/patches
  92. {
  93. echo "Subject: Add .config"
  94. echo "Author: ${maintainer}"
  95. echo
  96. echo "--- /dev/null"
  97. echo "+++ linux/.config"
  98. diff -u /dev/null "${KCONFIG_CONFIG}" | tail -n +3
  99. } > debian/patches/config.patch
  100. echo config.patch > debian/patches/series
  101. "${srctree}/scripts/package/gen-diff-patch" debian/patches/diff.patch
  102. if [ -s debian/patches/diff.patch ]; then
  103. sed -i "
  104. 1iSubject: Add local diff
  105. 1iAuthor: ${maintainer}
  106. 1i
  107. " debian/patches/diff.patch
  108. echo diff.patch >> debian/patches/series
  109. else
  110. rm -f debian/patches/diff.patch
  111. fi
  112. }
  113. rm -rf debian
  114. mkdir debian
  115. user=${KBUILD_BUILD_USER:-$(id -nu)}
  116. name=${DEBFULLNAME:-${user}}
  117. if [ "${DEBEMAIL:+set}" ]; then
  118. email=${DEBEMAIL}
  119. else
  120. buildhost=${KBUILD_BUILD_HOST:-$(hostname -f 2>/dev/null || hostname)}
  121. email="${user}@${buildhost}"
  122. fi
  123. maintainer="${name} <${email}>"
  124. while [ $# -gt 0 ]; do
  125. case "$1" in
  126. --need-source)
  127. gen_source
  128. shift
  129. ;;
  130. *)
  131. break
  132. ;;
  133. esac
  134. done
  135. # Some variables and settings used throughout the script
  136. version=$KERNELRELEASE
  137. if [ "${KDEB_PKGVERSION:+set}" ]; then
  138. packageversion=$KDEB_PKGVERSION
  139. else
  140. packageversion=$(${srctree}/scripts/setlocalversion --no-local ${srctree})-$($srctree/scripts/build-version)
  141. fi
  142. sourcename=${KDEB_SOURCENAME:-linux-upstream}
  143. if [ "$ARCH" = "um" ] ; then
  144. packagename=user-mode-linux
  145. else
  146. packagename=linux-image
  147. fi
  148. debarch=
  149. set_debarch
  150. # Try to determine distribution
  151. if [ "${KDEB_CHANGELOG_DIST:+set}" ]; then
  152. distribution=$KDEB_CHANGELOG_DIST
  153. # In some cases lsb_release returns the codename as n/a, which breaks dpkg-parsechangelog
  154. elif distribution=$(lsb_release -cs 2>/dev/null) && [ -n "$distribution" ] && [ "$distribution" != "n/a" ]; then
  155. : # nothing to do in this case
  156. else
  157. distribution="unstable"
  158. echo >&2 "Using default distribution of 'unstable' in the changelog"
  159. echo >&2 "Install lsb-release or set \$KDEB_CHANGELOG_DIST explicitly"
  160. fi
  161. echo $debarch > debian/arch
  162. host_gnu=$(dpkg-architecture -a "${debarch}" -q DEB_HOST_GNU_TYPE | sed 's/_/-/g')
  163. # Generate a simple changelog template
  164. cat <<EOF > debian/changelog
  165. $sourcename ($packageversion) $distribution; urgency=low
  166. * Custom built Linux kernel.
  167. -- $maintainer $(date -R)
  168. EOF
  169. # Generate a control file
  170. cat <<EOF > debian/control
  171. Source: $sourcename
  172. Section: kernel
  173. Priority: optional
  174. Maintainer: $maintainer
  175. Rules-Requires-Root: no
  176. Build-Depends: debhelper-compat (= 12)
  177. Build-Depends-Arch: bc, bison, cpio, flex,
  178. gcc-${host_gnu} <!pkg.${sourcename}.nokernelheaders>,
  179. kmod, libelf-dev:native,
  180. libssl-dev:native, libssl-dev <!pkg.${sourcename}.nokernelheaders>,
  181. rsync
  182. Homepage: https://www.kernel.org/
  183. Package: $packagename-$version
  184. Architecture: $debarch
  185. Description: Linux kernel, version $version
  186. This package contains the Linux kernel, modules and corresponding other
  187. files, version: $version.
  188. EOF
  189. if [ "${SRCARCH}" != um ]; then
  190. cat <<EOF >> debian/control
  191. Package: linux-libc-dev
  192. Section: devel
  193. Provides: linux-kernel-headers
  194. Architecture: $debarch
  195. Description: Linux support headers for userspace development
  196. This package provides userspaces headers from the Linux kernel. These headers
  197. are used by the installed headers for GNU glibc and other system libraries.
  198. Multi-Arch: same
  199. EOF
  200. if is_enabled CONFIG_MODULES; then
  201. cat <<EOF >> debian/control
  202. Package: linux-headers-$version
  203. Architecture: $debarch
  204. Build-Profiles: <!pkg.${sourcename}.nokernelheaders>
  205. Description: Linux kernel headers for $version on $debarch
  206. This package provides kernel header files for $version on $debarch
  207. .
  208. This is useful for people who need to build external modules
  209. EOF
  210. fi
  211. fi
  212. if is_enabled CONFIG_DEBUG_INFO; then
  213. cat <<EOF >> debian/control
  214. Package: linux-image-$version-dbg
  215. Section: debug
  216. Architecture: $debarch
  217. Build-Profiles: <!pkg.${sourcename}.nokerneldbg>
  218. Description: Linux kernel debugging symbols for $version
  219. This package will come in handy if you need to debug the kernel. It provides
  220. all the necessary debug symbols for the kernel and its modules.
  221. EOF
  222. fi
  223. cat <<EOF > debian/rules.vars
  224. ARCH := ${ARCH}
  225. KERNELRELEASE := ${KERNELRELEASE}
  226. EOF
  227. cp "${srctree}/scripts/package/debian/copyright" debian/
  228. cp "${srctree}/scripts/package/debian/rules" debian/
  229. exit 0