PKGBUILD 6.6 KB

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