PKGBUILD 7.1 KB

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