mkdebian 6.6 KB

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