PKGBUILD 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. # Maintainer: Donald Carr <sirspudd at gmail dot com>
  2. #set -x
  3. options=('!strip')
  4. # The firmware the kernel produces blows: don't falsify this lightly
  5. # "linux-firmware=20170309.695f2d6-1"
  6. pkgrel=1
  7. pkgver=5.11.10679.g381aff47f157
  8. pkgdesc="Kernel build from head"
  9. arch=("x86_64" "aarch64" "armv7h")
  10. license=("GPL2.1")
  11. log_path="${PWD}/$(date +"%Y-%m-%d-%H%M").log"
  12. _kernel_src_dir=/opt/src/OSS/linux
  13. pkgbase() {
  14. oldpath=${PWD}
  15. cd $_kernel_src_dir
  16. postfix="spudd-$(git rev-parse --abbrev-ref HEAD)"
  17. if [[ -f testing ]]; then
  18. postfix=${postfix}-testing
  19. fi
  20. pkgbase=linux-${postfix}
  21. cd ${oldpath}
  22. }
  23. pkgbase
  24. if [ -z "${LOCAL_PI_VER}" ]; then
  25. install=spudd.install
  26. fi
  27. prepare() {
  28. cp ${startdir}/_spudd.install ${startdir}/spudd.install
  29. sed -i "s/spudd/${postfix}/g" ${startdir}/spudd.install
  30. }
  31. pkgver() {
  32. cd $_kernel_src_dir
  33. git describe --tags | sed -e "s/^v//" | tr '-' '.'
  34. }
  35. build() {
  36. cd $_kernel_src_dir && git clean -xdf
  37. if [[ -n ${_config_preset} ]]; then
  38. echo ${_make_cmd} ${_config_preset}
  39. ${_make_cmd} ${_config_preset}
  40. elif [[ -n ${_config_file} ]]; then
  41. cp ${_config_file} ${_kernel_src_dir}/.config
  42. else
  43. echo "Kernel not configured; bailing"
  44. exit 1
  45. fi
  46. ${_make_cmd} all 2>&1 | tee ${log_path}
  47. if [ -n "${LOCAL_PI_VER}" ]; then
  48. ${_make_cmd} dtbs 2>&1 | tee -a ${log_path}
  49. fi
  50. }
  51. _package-headers() {
  52. pkgdesc="Headers and scripts for building modules for the $pkgdesc kernel"
  53. cd $_kernel_src_dir
  54. local builddir="$pkgdir/usr/lib/modules/$(<version)/build"
  55. echo "Installing build files..."
  56. install -Dt "$builddir" -m644 .config Makefile Module.symvers System.map \
  57. vmlinux
  58. install -Dt "$builddir/kernel" -m644 kernel/Makefile
  59. install -Dt "$builddir/arch/x86" -m644 arch/x86/Makefile
  60. cp -t "$builddir" -a scripts
  61. # add objtool for external module building and enabled VALIDATION_STACK option
  62. install -Dt "$builddir/tools/objtool" tools/objtool/objtool
  63. # add xfs and shmem for aufs building
  64. mkdir -p "$builddir"/{fs/xfs,mm}
  65. echo "Installing headers..."
  66. cp -t "$builddir" -a include
  67. cp -t "$builddir/arch/x86" -a arch/x86/include
  68. install -Dt "$builddir/arch/x86/kernel" -m644 arch/x86/kernel/asm-offsets.s
  69. install -Dt "$builddir/drivers/md" -m644 drivers/md/*.h
  70. install -Dt "$builddir/net/mac80211" -m644 net/mac80211/*.h
  71. # http://bugs.archlinux.org/task/13146
  72. install -Dt "$builddir/drivers/media/i2c" -m644 drivers/media/i2c/msp3400-driver.h
  73. # http://bugs.archlinux.org/task/20402
  74. install -Dt "$builddir/drivers/media/usb/dvb-usb" -m644 drivers/media/usb/dvb-usb/*.h
  75. install -Dt "$builddir/drivers/media/dvb-frontends" -m644 drivers/media/dvb-frontends/*.h
  76. install -Dt "$builddir/drivers/media/tuners" -m644 drivers/media/tuners/*.h
  77. echo "Installing KConfig files..."
  78. find . -name 'Kconfig*' -exec install -Dm644 {} "$builddir/{}" \;
  79. echo "Removing unneeded architectures..."
  80. local arch
  81. for arch in "$builddir"/arch/*/; do
  82. [[ $arch = */x86/ ]] && continue
  83. echo "Removing $(basename "$arch")"
  84. rm -r "$arch"
  85. done
  86. echo "Removing documentation..."
  87. rm -r "$builddir/Documentation"
  88. echo "Removing broken symlinks..."
  89. find -L "$builddir" -type l -printf 'Removing %P\n' -delete
  90. echo "Removing loose objects..."
  91. find "$builddir" -type f -name '*.o' -printf 'Removing %P\n' -delete
  92. echo "Stripping build tools..."
  93. local file
  94. while read -rd '' file; do
  95. case "$(file -bi "$file")" in
  96. application/x-sharedlib\;*) # Libraries (.so)
  97. strip -v $STRIP_SHARED "$file" ;;
  98. application/x-archive\;*) # Libraries (.a)
  99. strip -v $STRIP_STATIC "$file" ;;
  100. application/x-executable\;*) # Binaries
  101. strip -v $STRIP_BINARIES "$file" ;;
  102. application/x-pie-executable\;*) # Relocatable binaries
  103. strip -v $STRIP_SHARED "$file" ;;
  104. esac
  105. done < <(find "$builddir" -type f -perm -u+x ! -name vmlinux -print0)
  106. echo "Adding symlink..."
  107. mkdir -p "$pkgdir/usr/src"
  108. ln -sr "$builddir" "$pkgdir/usr/src/$pkgbase"
  109. }
  110. pkgname=("$pkgbase" "$pkgbase-headers")
  111. for _p in "${pkgname[@]}"; do
  112. eval "package_$_p() {
  113. $(declare -f "_package${_p#$pkgbase}")
  114. _package${_p#$pkgbase}
  115. }"
  116. done
  117. _package() {
  118. prepare
  119. boot_dir="${pkgdir}/boot"
  120. dtb_dir="${boot_dir}/dtbs"
  121. usr_dir="${pkgdir}/usr"
  122. firmware_dir="${usr_dir}/lib/firmware"
  123. preset_dir=${pkgdir}/etc/mkinitcpio.d
  124. cd $_kernel_src_dir
  125. INSTALL_MOD_PATH=${usr_dir} INSTALL_MOD_STRIP=1 ${_make_cmd} modules_install
  126. if [ -n "${LOCAL_PI_VER}" ]; then
  127. INSTALL_DTBS_PATH=${dtb_dir} ${_make_cmd} dtbs_install
  128. fi
  129. mkdir -p ${boot_dir}
  130. if [ "${LOCAL_PI_VER}" = "3" ] || [ "${LOCAL_PI_VER}" = "4" ]; then
  131. cp arch/arm64/boot/Image ${boot_dir}/Image
  132. cp arch/arm64/boot/Image.gz ${boot_dir}/Image.gz
  133. elif [ "${LOCAL_PI_VER}" = "2" ]; then
  134. cp arch/arm/boot/zImage ${boot_dir}/vmlinuz-${postfix}
  135. else
  136. cp arch/x86/boot/bzImage ${boot_dir}/vmlinuz-${postfix}
  137. fi
  138. mkdir -p ${preset_dir}
  139. cp ${startdir}/spudd.preset ${preset_dir}/${postfix}.preset
  140. sed -i "s/spudd/${postfix}/g" ${preset_dir}/${postfix}.preset
  141. rm -Rf ${startdir}/firmware
  142. if [[ -d ${firmware_dir} ]]; then
  143. mv ${firmware_dir} ${startdir}
  144. fi
  145. }
  146. if [ -n "${LOCAL_PI_VER}" ]; then
  147. case ${LOCAL_PI_VER} in
  148. 2)
  149. echo "Compiling for the RPi 2 aarch32"
  150. _config_file="${startdir}/rpi2"
  151. _xcompile_args="ARCH=arm CROSS_COMPILE=/opt/armv7-rpi2-linux-gnueabihf/bin/armv7-rpi2-linux-gnueabihf-"
  152. ;;
  153. 3)
  154. #symbols omitted by default wtf!
  155. #DTC_FLAGS=\"-@ -H epapr\"
  156. echo "Compiling for the RPi 3 aarch64"
  157. _config_file="${startdir}/rpi3"
  158. _xcompile_args="ARCH=arm64 CROSS_COMPILE=/opt/x-tools/aarch64-rpi3-linux-gnu/bin/aarch64-rpi3-linux-gnu-"
  159. ;;
  160. 4)
  161. #symbols omitted by default wtf!
  162. #DTC_FLAGS=\"-@ -H epapr\"
  163. echo "Compiling for the RPi 4 aarch64"
  164. _config_preset="bcm2711_defconfig"
  165. _xcompile_args="ARCH=arm64 CROSS_COMPILE=${HOME}/x-tools/aarch64-spudd-linux-gnu/bin/aarch64-spudd-linux-gnu-"
  166. ;;
  167. *)
  168. echo "Only supports the rpi 4 at this point in time"
  169. exit 1
  170. ;;
  171. esac
  172. else
  173. echo "Compiling for desktop"
  174. # wasted a lot of time manually tracking this shit down before finding this doc, like a muppet
  175. # Documentation/kbuild/llvm.rst
  176. _xcompile_args="LLVM=1 LLVM_IAS=1"
  177. #_xcompile_args=""
  178. _config_file="${startdir}/desktop"
  179. #_config_file="${_kernel_src_dir}/configs/desktop"
  180. fi
  181. _make_cmd="eval time make V=0 ${_xcompile_args}"