PKGBUILD 7.0 KB

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