PKGBUILD 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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.13006.g2a0c9af33128
  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 ${_builddir}/include/config/kernel.release)
  65. cd $_builddir
  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")
  123. #pkgname=("$pkgbase" "$pkgbase-headers")
  124. #for _p in "${pkgname[@]}"; do
  125. # eval "package_$_p() {
  126. # $(declare -f "_package${_p#$pkgbase}")
  127. # _package${_p#$pkgbase}
  128. # }"
  129. #done
  130. package() {
  131. mkdir -p ${pkgdir}
  132. prepare
  133. boot_dir="${pkgdir}/boot"
  134. dtb_dir="${boot_dir}/dtbs"
  135. usr_dir="${pkgdir}/usr"
  136. usr_lib_dir="${usr_dir}/lib"
  137. version=$(cat ${_builddir}/include/config/kernel.release)
  138. modules_dir="${usr_lib_dir}/modules/${version}"
  139. firmware_dir="${usr_lib_dir}/firmware"
  140. preset_dir=${pkgdir}/etc/mkinitcpio.d
  141. cd $_builddir
  142. INSTALL_MOD_PATH=${usr_dir} INSTALL_MOD_STRIP=1 ${_make_cmd} modules_install
  143. if [ -n "${_pi_ver}" ]; then
  144. INSTALL_DTBS_PATH=${dtb_dir} ${_make_cmd} dtbs_install
  145. fi
  146. mkdir -p ${boot_dir} ${modules_dir}
  147. touch ${modules_dir}/.force-existence
  148. if [ "${_pi_ver}" = "3" ] || [ "${_pi_ver}" = "4" ]; then
  149. cp arch/arm64/boot/Image ${boot_dir}/Image
  150. cp arch/arm64/boot/Image.gz ${boot_dir}/Image.gz
  151. elif [ "${_pi_ver}" = "2" ]; then
  152. cp arch/arm/boot/zImage ${boot_dir}/vmlinuz-${postfix}
  153. else
  154. cp arch/x86/boot/bzImage ${boot_dir}/vmlinuz-${postfix}
  155. fi
  156. mkdir -p ${preset_dir}
  157. cp ${startdir}/spudd.preset ${preset_dir}/${postfix}.preset
  158. sed -i "s/spudd/${postfix}/g" ${preset_dir}/${postfix}.preset
  159. rm -Rf ${startdir}/firmware
  160. if [[ -d ${firmware_dir} ]]; then
  161. mv ${firmware_dir} ${startdir}
  162. fi
  163. }
  164. if [ -n "${_pi_ver}" ]; then
  165. case ${_pi_ver} in
  166. 2)
  167. echo "Compiling for the RPi 2 aarch32"
  168. _config_file="${startdir}/rpi2"
  169. _xcompile_args="ARCH=arm CROSS_COMPILE=/opt/armv7-rpi2-linux-gnueabihf/bin/armv7-rpi2-linux-gnueabihf-"
  170. ;;
  171. 3)
  172. #symbols omitted by default wtf!
  173. #DTC_FLAGS=\"-@ -H epapr\"
  174. echo "Compiling for the RPi 3 aarch64"
  175. _config_file="${startdir}/rpi3"
  176. _xcompile_args="ARCH=arm64 CROSS_COMPILE=/opt/x-tools/aarch64-rpi3-linux-gnu/bin/aarch64-rpi3-linux-gnu-"
  177. ;;
  178. 4)
  179. #symbols omitted by default wtf!
  180. #DTC_FLAGS=\"-@ -H epapr\"
  181. echo "Compiling for the RPi 4 aarch64"
  182. _config_preset="bcm2711_defconfig"
  183. _xcompile_args="ARCH=arm64 CROSS_COMPILE=${HOME}/x-tools/aarch64-spudd-linux-gnu/bin/aarch64-spudd-linux-gnu-"
  184. ;;
  185. *)
  186. echo "Only supports the rpi 4 at this point in time"
  187. exit 1
  188. ;;
  189. esac
  190. else
  191. echo "Compiling for desktop"
  192. # wasted a lot of time manually tracking this shit down before finding this doc, like a muppet
  193. # Documentation/kbuild/llvm.rst
  194. _xcompile_args="LLVM=1 LLVM_IAS=1"
  195. #_xcompile_args=""
  196. _config_preset="spudd_desktop_defconfig"
  197. #_config_file="${_kernel_src_dir}/configs/desktop"
  198. fi
  199. _builddir=${BUILDDIR}/${pkgbase}
  200. _make_cmd="eval time make O=${_builddir} V=0 ${_xcompile_args}"