mkdebian 5.1 KB

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