Advertisement
Guest User

Untitled

a guest
Feb 1st, 2019
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.09 KB | None | 0 0
  1. # Maintainer: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
  2. # Maintainer: Tobias Powalowski <tpowa@archlinux.org>
  3. # Maintainer: Thomas Baechler <thomas@archlinux.org>
  4.  
  5. #pkgbase=linux # Build stock -ARCH kernel
  6. pkgbase=linux-custom # Build kernel with a different name
  7. _srcver=4.20.5-arch1
  8. pkgver=${_srcver//-/.}
  9. pkgrel=1
  10. arch=(x86_64)
  11. url="https://git.archlinux.org/linux.git/log/?h=v$_srcver"
  12. license=(GPL2)
  13. makedepends=(xmlto kmod inetutils bc libelf git python-sphinx graphviz)
  14. options=('!strip')
  15. _srcname=archlinux-linux
  16. source=(
  17. "$_srcname::git+https://git.archlinux.org/linux.git?signed#tag=v$_srcver"
  18. config # the main kernel config file
  19. 60-linux.hook # pacman hook for depmod
  20. 90-linux.hook # pacman hook for initramfs regeneration
  21. linux.preset # standard config files for mkinitcpio ramdisk
  22. )
  23. validpgpkeys=(
  24. 'ABAF11C65A2970B130ABE3C479BE3E4300411886' # Linus Torvalds
  25. '647F28654894E3BD457199BE38DBBDC86092693E' # Greg Kroah-Hartman
  26. '8218F88849AAC522E94CF470A5E9288C4FA415FA' # Jan Alexander Steffens (heftig)
  27. )
  28. sha256sums=('SKIP'
  29. 'f863b3e9640161f61e859f22f2d1258c940101de8f007a207c1ede2f71d36206'
  30. 'ae2e95db94ef7176207c690224169594d49445e04249d2499e9d2fbc117a0b21'
  31. 'c043f3033bb781e2688794a59f6d1f7ed49ef9b13eb77ff9a425df33a244a636'
  32. 'ad6344badc91ad0630caacde83f7f9b97276f80d26a20619a87952be65492c65')
  33.  
  34. _kernelname=${pkgbase#linux}
  35. : ${_kernelname:=-ARCH}
  36.  
  37. prepare() {
  38. cd $_srcname
  39.  
  40. msg2 "Setting version..."
  41. scripts/setlocalversion --save-scmversion
  42. echo "-$pkgrel" > localversion.10-pkgrel
  43. echo "$_kernelname" > localversion.20-pkgname
  44.  
  45. local src
  46. for src in "${source[@]}"; do
  47. src="${src%%::*}"
  48. src="${src##*/}"
  49. [[ $src = *.patch ]] || continue
  50. msg2 "Applying patch $src..."
  51. patch -Np1 < "../$src"
  52. done
  53.  
  54. msg2 "Setting config..."
  55. cp ../config .config
  56. make olddefconfig
  57. make menuconfig
  58. vim .config
  59. make -s kernelrelease > ../version
  60. msg2 "Prepared %s version %s" "$pkgbase" "$(<../version)"
  61. }
  62.  
  63. build() {
  64. cd $_srcname
  65. make bzImage modules htmldocs
  66. }
  67.  
  68. _package() {
  69. pkgdesc="The ${pkgbase/linux/Linux} kernel and modules"
  70. [[ $pkgbase = linux ]] && groups=(base)
  71. depends=(coreutils linux-firmware kmod mkinitcpio)
  72. optdepends=('crda: to set the correct wireless channels of your country')
  73. backup=("etc/mkinitcpio.d/$pkgbase.preset")
  74. install=linux.install
  75.  
  76. local kernver="$(<version)"
  77. local modulesdir="$pkgdir/usr/lib/modules/$kernver"
  78.  
  79. cd $_srcname
  80.  
  81. msg2 "Installing boot image..."
  82. # systemd expects to find the kernel here to allow hibernation
  83. # https://github.com/systemd/systemd/commit/edda44605f06a41fb86b7ab8128dcf99161d2344
  84. install -Dm644 "$(make -s image_name)" "$modulesdir/vmlinuz"
  85. install -Dm644 "$modulesdir/vmlinuz" "$pkgdir/boot/vmlinuz-$pkgbase"
  86.  
  87. msg2 "Installing modules..."
  88. make INSTALL_MOD_PATH="$pkgdir/usr" modules_install
  89.  
  90. # a place for external modules,
  91. # with version file for building modules and running depmod from hook
  92. local extramodules="extramodules$_kernelname"
  93. local extradir="$pkgdir/usr/lib/modules/$extramodules"
  94. install -Dt "$extradir" -m644 ../version
  95. ln -sr "$extradir" "$modulesdir/extramodules"
  96.  
  97. # remove build and source links
  98. rm "$modulesdir"/{source,build}
  99.  
  100. msg2 "Installing hooks..."
  101. # sed expression for following substitutions
  102. local subst="
  103. s|%PKGBASE%|$pkgbase|g
  104. s|%KERNVER%|$kernver|g
  105. s|%EXTRAMODULES%|$extramodules|g
  106. "
  107.  
  108. # hack to allow specifying an initially nonexisting install file
  109. sed "$subst" "$startdir/$install" > "$startdir/$install.pkg"
  110. true && install=$install.pkg
  111.  
  112. # fill in mkinitcpio preset and pacman hooks
  113. sed "$subst" ../linux.preset | install -Dm644 /dev/stdin \
  114. "$pkgdir/etc/mkinitcpio.d/$pkgbase.preset"
  115. sed "$subst" ../60-linux.hook | install -Dm644 /dev/stdin \
  116. "$pkgdir/usr/share/libalpm/hooks/60-$pkgbase.hook"
  117. sed "$subst" ../90-linux.hook | install -Dm644 /dev/stdin \
  118. "$pkgdir/usr/share/libalpm/hooks/90-$pkgbase.hook"
  119.  
  120. msg2 "Fixing permissions..."
  121. chmod -Rc u=rwX,go=rX "$pkgdir"
  122. }
  123.  
  124. _package-headers() {
  125. pkgdesc="Header files and scripts for building modules for ${pkgbase/linux/Linux} kernel"
  126.  
  127. local builddir="$pkgdir/usr/lib/modules/$(<version)/build"
  128.  
  129. cd $_srcname
  130.  
  131. msg2 "Installing build files..."
  132. install -Dt "$builddir" -m644 Makefile .config Module.symvers System.map vmlinux
  133. install -Dt "$builddir/kernel" -m644 kernel/Makefile
  134. install -Dt "$builddir/arch/x86" -m644 arch/x86/Makefile
  135. cp -t "$builddir" -a scripts
  136.  
  137. # add objtool for external module building and enabled VALIDATION_STACK option
  138. install -Dt "$builddir/tools/objtool" tools/objtool/objtool
  139.  
  140. # add xfs and shmem for aufs building
  141. mkdir -p "$builddir"/{fs/xfs,mm}
  142.  
  143. # ???
  144. mkdir "$builddir/.tmp_versions"
  145.  
  146. msg2 "Installing headers..."
  147. cp -t "$builddir" -a include
  148. cp -t "$builddir/arch/x86" -a arch/x86/include
  149. install -Dt "$builddir/arch/x86/kernel" -m644 arch/x86/kernel/asm-offsets.s
  150.  
  151. install -Dt "$builddir/drivers/md" -m644 drivers/md/*.h
  152. install -Dt "$builddir/net/mac80211" -m644 net/mac80211/*.h
  153.  
  154. # http://bugs.archlinux.org/task/13146
  155. install -Dt "$builddir/drivers/media/i2c" -m644 drivers/media/i2c/msp3400-driver.h
  156.  
  157. # http://bugs.archlinux.org/task/20402
  158. install -Dt "$builddir/drivers/media/usb/dvb-usb" -m644 drivers/media/usb/dvb-usb/*.h
  159. install -Dt "$builddir/drivers/media/dvb-frontends" -m644 drivers/media/dvb-frontends/*.h
  160. install -Dt "$builddir/drivers/media/tuners" -m644 drivers/media/tuners/*.h
  161.  
  162. msg2 "Installing KConfig files..."
  163. find . -name 'Kconfig*' -exec install -Dm644 {} "$builddir/{}" \;
  164.  
  165. msg2 "Removing unneeded architectures..."
  166. local arch
  167. for arch in "$builddir"/arch/*/; do
  168. [[ $arch = */x86/ ]] && continue
  169. echo "Removing $(basename "$arch")"
  170. rm -r "$arch"
  171. done
  172.  
  173. msg2 "Removing documentation..."
  174. rm -r "$builddir/Documentation"
  175.  
  176. msg2 "Removing broken symlinks..."
  177. find -L "$builddir" -type l -printf 'Removing %P\n' -delete
  178.  
  179. msg2 "Removing loose objects..."
  180. find "$builddir" -type f -name '*.o' -printf 'Removing %P\n' -delete
  181.  
  182. msg2 "Stripping build tools..."
  183. local file
  184. while read -rd '' file; do
  185. case "$(file -bi "$file")" in
  186. application/x-sharedlib\;*) # Libraries (.so)
  187. strip -v $STRIP_SHARED "$file" ;;
  188. application/x-archive\;*) # Libraries (.a)
  189. strip -v $STRIP_STATIC "$file" ;;
  190. application/x-executable\;*) # Binaries
  191. strip -v $STRIP_BINARIES "$file" ;;
  192. application/x-pie-executable\;*) # Relocatable binaries
  193. strip -v $STRIP_SHARED "$file" ;;
  194. esac
  195. done < <(find "$builddir" -type f -perm -u+x ! -name vmlinux -print0)
  196.  
  197. msg2 "Adding symlink..."
  198. mkdir -p "$pkgdir/usr/src"
  199. ln -sr "$builddir" "$pkgdir/usr/src/$pkgbase-$pkgver"
  200.  
  201. msg2 "Fixing permissions..."
  202. chmod -Rc u=rwX,go=rX "$pkgdir"
  203. }
  204.  
  205. _package-docs() {
  206. pkgdesc="Kernel hackers manual - HTML documentation that comes with the ${pkgbase/linux/Linux} kernel"
  207.  
  208. local builddir="$pkgdir/usr/lib/modules/$(<version)/build"
  209.  
  210. cd $_srcname
  211.  
  212. msg2 "Installing documentation..."
  213. mkdir -p "$builddir"
  214. cp -t "$builddir" -a Documentation
  215.  
  216. msg2 "Removing doctrees..."
  217. rm -r "$builddir/Documentation/output/.doctrees"
  218.  
  219. msg2 "Moving HTML docs..."
  220. local src dst
  221. while read -rd '' src; do
  222. dst="$builddir/Documentation/${src#$builddir/Documentation/output/}"
  223. mkdir -p "${dst%/*}"
  224. mv "$src" "$dst"
  225. rmdir -p --ignore-fail-on-non-empty "${src%/*}"
  226. done < <(find "$builddir/Documentation/output" -type f -print0)
  227.  
  228. msg2 "Adding symlink..."
  229. mkdir -p "$pkgdir/usr/share/doc"
  230. ln -sr "$builddir/Documentation" "$pkgdir/usr/share/doc/$pkgbase"
  231.  
  232. msg2 "Fixing permissions..."
  233. chmod -Rc u=rwX,go=rX "$pkgdir"
  234. }
  235.  
  236. pkgname=("$pkgbase" "$pkgbase-headers" "$pkgbase-docs")
  237. for _p in "${pkgname[@]}"; do
  238. eval "package_$_p() {
  239. $(declare -f "_package${_p#$pkgbase}")
  240. _package${_p#$pkgbase}
  241. }"
  242. done
  243.  
  244. # vim:set ts=8 sts=2 sw=2 et:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement