PKGBUILD 6.7 KB

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