PKGBUILD 7.2 KB

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