mkdebian 5.1 KB

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