PKGBUILD 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. # Maintainer: David P. <megver83@parabola.nu>
  2. # Contributor: André Silva <emulatorman@hyperbola.info>
  3. # Contributor: Márcio Silva <coadde@hyperbola.info>
  4. # Based on linux-hardened package
  5. _replacesarchkernel=('linux%') # '%' gets replaced with kernel suffix
  6. _replacesoldkernels=() # '%' gets replaced with kernel suffix
  7. _replacesoldmodules=() # '%' gets replaced with kernel suffix
  8. pkgbase=linux-libre-hardened
  9. pkgver=5.12.19.hardened1
  10. pkgrel=1
  11. pkgdesc='Security-Hardened Linux-libre'
  12. url='https://linux-libre.fsfla.org/'
  13. arch=(x86_64)
  14. license=(GPL2)
  15. makedepends=(
  16. bc kmod libelf pahole cpio perl tar xz
  17. xmlto python-sphinx python-sphinx_rtd_theme graphviz imagemagick
  18. )
  19. options=('!strip')
  20. _srcname=linux-5.12
  21. _srctag=${pkgver%.*}-${pkgver##*.}
  22. source=(
  23. "https://linux-libre.fsfla.org/pub/linux-libre/releases/${_srcname##*-}-gnu/linux-libre-${_srcname##*-}-gnu.tar.xz"{,.sign}
  24. "https://linux-libre.fsfla.org/pub/linux-libre/releases/${pkgver%.*}-gnu/patch-${_srcname##*-}-gnu-${pkgver%.*}-gnu.xz"{,.sign}
  25. "https://github.com/anthraxx/linux-hardened/releases/download/${_srctag}/linux-hardened-${_srctag}.patch"{,.sig}
  26. "https://repo.parabola.nu/other/linux-libre/logos/logo_linux_"{clut224.ppm,vga16.ppm,mono.pbm}{,.sig}
  27. config # the main kernel config file
  28. # maintain the TTY over USB disconnects
  29. # http://www.coreboot.org/EHCI_Gadget_Debug
  30. 0001-usb-serial-gadget-no-TTY-hangup-on-USB-disconnect-WI.patch
  31. # fix Atmel maXTouch touchscreen support
  32. # https://labs.parabola.nu/issues/877
  33. # http://www.fsfla.org/pipermail/linux-libre/2015-November/003202.html
  34. 0002-fix-Atmel-maXTouch-touchscreen-support.patch
  35. # Arch Linux patches
  36. )
  37. validpgpkeys=(
  38. '474402C8C582DAFBE389C427BCB7CF877E7D47A7' # Alexandre Oliva
  39. '65EEFE022108E2B708CBFCF7F9E712E59AF5F22A' # Daniel Micay
  40. '6DB9C4B4F0D8C0DC432CF6E4227CA7C556B2BA78' # David P.
  41. 'E240B57E2C4630BA768E2F26FC1B547C8D8172C8' # Levente Polyak
  42. )
  43. sha512sums=('07730c51e4030dc9c1d01367098eabafd5665c40a69f8b102b2fa0aaae4f2124c32f60560b30a55fab18a76eb782650fac04a4aa2aaa558e96bfd13faaea328c'
  44. 'SKIP'
  45. '9857f7c8e88f9a59faaea695245d668d7c73347bcf43feb60d61fa94dfc9c7bfdfcbca6a6afa32839991924644bd990a7fff2b60b68d4f14da74b343ede5ff15'
  46. 'SKIP'
  47. 'e5e427702841d941c605a9fe27ba051c7e947dc7c2ab5906cd19a40b9fe99863e41b9e860e8f00fad2f11922403d9ee042a94b9e7fefc85e89f333192b2bda85'
  48. 'SKIP'
  49. '13cb5bc42542e7b8bb104d5f68253f6609e463b6799800418af33eb0272cc269aaa36163c3e6f0aacbdaaa1d05e2827a4a7c4a08a029238439ed08b89c564bb3'
  50. 'SKIP'
  51. '7a3716bfe3b9f546da309c7492f3e08f8f506813afeb1c737a474c83313d5c313cf4582b65215c2cfce3b74d9d1021c96e8badafe8f6e5b01fe28d2b5c61ae78'
  52. 'SKIP'
  53. '267295aa0cea65684968420c68b32f1a66a22d018b9d2b2c1ef14267bcf4cb68aaf7099d073cbfefe6c25c8608bdcbbd45f7ac8893fdcecbf1e621abdfe9ecc1'
  54. 'SKIP'
  55. '17e5fead55a8bbffaaa4a37ed09bd38309b2dbcbebbd44fdd2f382732da8a0e41dded9ab78fbcb154788e8e0f7ddd5bf02a5f3dede630731bdd6e72773effcc7'
  56. '02af4dd2a007e41db0c63822c8ab3b80b5d25646af1906dc85d0ad9bb8bbf5236f8e381d7f91cf99ed4b0978c50aee37cb9567cdeef65b7ec3d91b882852b1af'
  57. 'b8fe56e14006ab866970ddbd501c054ae37186ddc065bb869cf7d18db8c0d455118d5bda3255fb66a0dde38b544655cfe9040ffe46e41d19830b47959b2fb168')
  58. _replacesarchkernel=("${_replacesarchkernel[@]/\%/${pkgbase#linux-libre}}")
  59. _replacesoldkernels=("${_replacesoldkernels[@]/\%/${pkgbase#linux-libre}}")
  60. _replacesoldmodules=("${_replacesoldmodules[@]/\%/${pkgbase#linux-libre}}")
  61. export KBUILD_BUILD_HOST=parabola
  62. export KBUILD_BUILD_USER=$pkgbase
  63. export KBUILD_BUILD_TIMESTAMP="$(date -Ru${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})"
  64. prepare() {
  65. cd $_srcname
  66. if [ "${_srcname##*-}" != "${pkgver%.*}" ]; then
  67. echo "Applying upstream patch..."
  68. patch -Np1 < "../patch-${_srcname##*-}-gnu-${pkgver%.*}-gnu"
  69. fi
  70. echo "Adding freedo as boot logo..."
  71. install -m644 -t drivers/video/logo \
  72. ../logo_linux_{clut224.ppm,vga16.ppm,mono.pbm}
  73. echo "Setting version..."
  74. sed -e "/^-EXTRAVERSION =/s/=/= -gnu/" \
  75. -e "/^+EXTRAVERSION =/s/= /= -gnu/" \
  76. -i "../linux-hardened-$_srctag.patch"
  77. scripts/setlocalversion --save-scmversion
  78. echo "-$pkgrel" > localversion.10-pkgrel
  79. echo "${pkgbase#linux-libre}" > localversion.20-pkgname
  80. local src
  81. for src in "${source[@]}"; do
  82. src="${src%%::*}"
  83. src="${src##*/}"
  84. [[ $src = *.patch ]] || continue
  85. echo "Applying patch $src..."
  86. patch -Np1 < "../$src"
  87. done
  88. echo "Setting config..."
  89. cp ../config .config
  90. make olddefconfig
  91. make -s kernelrelease > version
  92. echo "Prepared $pkgbase version $(<version)"
  93. }
  94. build() {
  95. cd $_srcname
  96. make all
  97. make htmldocs
  98. }
  99. _package() {
  100. pkgdesc="The $pkgdesc kernel and modules"
  101. depends=(coreutils kmod initramfs)
  102. optdepends=('crda: to set the correct wireless channels of your country'
  103. 'linux-libre-firmware: firmware images needed for some devices'
  104. 'usbctl: deny_new_usb control')
  105. provides=(VIRTUALBOX-GUEST-MODULES WIREGUARD-MODULE)
  106. provides+=("${_replacesarchkernel[@]/%/=${pkgver%.*}}" "LINUX-ABI_VERSION=${pkgver%.*}")
  107. conflicts=("${_replacesarchkernel[@]}" "${_replacesoldkernels[@]}" "${_replacesoldmodules[@]}")
  108. replaces=("${_replacesarchkernel[@]}" "${_replacesoldkernels[@]}" "${_replacesoldmodules[@]}")
  109. cd $_srcname
  110. local kernver="$(<version)"
  111. local modulesdir="$pkgdir/usr/lib/modules/$kernver"
  112. echo "Installing boot image..."
  113. # systemd expects to find the kernel here to allow hibernation
  114. # https://github.com/systemd/systemd/commit/edda44605f06a41fb86b7ab8128dcf99161d2344
  115. install -Dm644 "$(make -s image_name)" "$modulesdir/vmlinuz"
  116. # Used by mkinitcpio to name the kernel
  117. echo "$pkgbase" | install -Dm644 /dev/stdin "$modulesdir/pkgbase"
  118. echo "Installing modules..."
  119. make INSTALL_MOD_PATH="$pkgdir/usr" INSTALL_MOD_STRIP=1 modules_install
  120. # remove build and source links
  121. rm "$modulesdir"/{source,build}
  122. }
  123. _package-headers() {
  124. pkgdesc="Headers and scripts for building modules for the $pkgdesc kernel"
  125. provides=("${_replacesarchkernel[@]/%/-headers=${pkgver%.*}}")
  126. conflicts=("${_replacesarchkernel[@]/%/-headers}" "${_replacesoldkernels[@]/%/-headers}")
  127. replaces=("${_replacesarchkernel[@]/%/-headers}" "${_replacesoldkernels[@]/%/-headers}")
  128. cd $_srcname
  129. local builddir="$pkgdir/usr/lib/modules/$(<version)/build"
  130. echo "Installing build files..."
  131. install -Dt "$builddir" -m644 .config Makefile Module.symvers System.map \
  132. localversion.* version 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. # add objtool for external module building and enabled VALIDATION_STACK option
  137. install -Dt "$builddir/tools/objtool" tools/objtool/objtool
  138. # add xfs and shmem for aufs building
  139. mkdir -p "$builddir"/{fs/xfs,mm}
  140. echo "Installing headers..."
  141. cp -t "$builddir" -a include
  142. cp -t "$builddir/arch/x86" -a arch/x86/include
  143. install -Dt "$builddir/arch/x86/kernel" -m644 arch/x86/kernel/asm-offsets.s
  144. install -Dt "$builddir/drivers/md" -m644 drivers/md/*.h
  145. install -Dt "$builddir/net/mac80211" -m644 net/mac80211/*.h
  146. # https://bugs.archlinux.org/task/13146
  147. install -Dt "$builddir/drivers/media/i2c" -m644 drivers/media/i2c/msp3400-driver.h
  148. # https://bugs.archlinux.org/task/20402
  149. install -Dt "$builddir/drivers/media/usb/dvb-usb" -m644 drivers/media/usb/dvb-usb/*.h
  150. install -Dt "$builddir/drivers/media/dvb-frontends" -m644 drivers/media/dvb-frontends/*.h
  151. install -Dt "$builddir/drivers/media/tuners" -m644 drivers/media/tuners/*.h
  152. # https://bugs.archlinux.org/task/71392
  153. install -Dt "$builddir/drivers/iio/common/hid-sensors" -m644 drivers/iio/common/hid-sensors/*.h
  154. echo "Installing KConfig files..."
  155. find . -name 'Kconfig*' -exec install -Dm644 {} "$builddir/{}" \;
  156. echo "Removing unneeded architectures..."
  157. local arch
  158. for arch in "$builddir"/arch/*/; do
  159. [[ $arch = */x86/ ]] && continue
  160. echo "Removing $(basename "$arch")"
  161. rm -r "$arch"
  162. done
  163. echo "Removing documentation..."
  164. rm -r "$builddir/Documentation"
  165. echo "Removing broken symlinks..."
  166. find -L "$builddir" -type l -printf 'Removing %P\n' -delete
  167. echo "Removing loose objects..."
  168. find "$builddir" -type f -name '*.o' -printf 'Removing %P\n' -delete
  169. echo "Stripping build tools..."
  170. local file
  171. while read -rd '' file; do
  172. case "$(file -bi "$file")" in
  173. application/x-sharedlib\;*) # Libraries (.so)
  174. strip -v $STRIP_SHARED "$file" ;;
  175. application/x-archive\;*) # Libraries (.a)
  176. strip -v $STRIP_STATIC "$file" ;;
  177. application/x-executable\;*) # Binaries
  178. strip -v $STRIP_BINARIES "$file" ;;
  179. application/x-pie-executable\;*) # Relocatable binaries
  180. strip -v $STRIP_SHARED "$file" ;;
  181. esac
  182. done < <(find "$builddir" -type f -perm -u+x ! -name vmlinux -print0)
  183. echo "Stripping vmlinux..."
  184. strip -v $STRIP_STATIC "$builddir/vmlinux"
  185. echo "Adding symlink..."
  186. mkdir -p "$pkgdir/usr/src"
  187. ln -sr "$builddir" "$pkgdir/usr/src/$pkgbase"
  188. }
  189. _package-docs() {
  190. pkgdesc="Documentation for the $pkgdesc kernel"
  191. provides=("${_replacesarchkernel[@]/%/-docs=${pkgver%.*}}")
  192. conflicts=("${_replacesarchkernel[@]/%/-docs}" "${_replacesoldkernels[@]/%/-docs}")
  193. replaces=("${_replacesarchkernel[@]/%/-docs}" "${_replacesoldkernels[@]/%/-docs}")
  194. cd $_srcname
  195. local builddir="$pkgdir/usr/lib/modules/$(<version)/build"
  196. echo "Installing documentation..."
  197. local src dst
  198. while read -rd '' src; do
  199. dst="${src#Documentation/}"
  200. dst="$builddir/Documentation/${dst#output/}"
  201. install -Dm644 "$src" "$dst"
  202. done < <(find Documentation -name '.*' -prune -o ! -type d -print0)
  203. echo "Adding symlink..."
  204. mkdir -p "$pkgdir/usr/share/doc"
  205. ln -sr "$builddir/Documentation" "$pkgdir/usr/share/doc/$pkgbase"
  206. }
  207. pkgname=("$pkgbase" "$pkgbase-headers" "$pkgbase-docs")
  208. for _p in "${pkgname[@]}"; do
  209. eval "package_$_p() {
  210. $(declare -f "_package${_p#$pkgbase}")
  211. _package${_p#$pkgbase}
  212. }"
  213. done
  214. # vim:set ts=8 sts=2 sw=2 et: