klipper-9999.ebuild 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. # Copyright 1999-2024 Gentoo Authors
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=8
  4. PYTHON_COMPAT=( python3_{10..12} )
  5. inherit python-single-r1 systemd
  6. DESCRIPTION="Klipper is a 3d-Printer firmware"
  7. HOMEPAGE="https://www.klipper3d.org/"
  8. if [[ ${PV} = *9999 ]]; then
  9. inherit git-r3
  10. EGIT_REPO_URI="https://github.com/Klipper3d/${PN}"
  11. EGIT_BRANCH="master"
  12. KEYWORDS=""
  13. else
  14. COMMIT="6ce6fbbce07605010c0d4fa8eaa0ebcde01e53db"
  15. SRC_URI="https://github.com/Klipper3d/${PN}/archive/${COMMIT}.tar.gz -> ${P}.tar.gz
  16. dict? ( https://github.com/Klipper3d/klipper/files/7491378/klipper-dict-20211106.tar.gz )"
  17. KEYWORDS="~amd64 ~x86 ~arm ~arm64"
  18. S="${WORKDIR}/${PN}-${COMMIT}"
  19. fi
  20. LICENSE="GPL-3"
  21. SLOT="0"
  22. IUSE="dict doc +examples firmware systemd"
  23. DEPEND="
  24. acct-group/klipper
  25. acct-user/klipper
  26. "
  27. RDEPEND="
  28. ${DEPEND}
  29. ${PYTHON_DEPS}
  30. virtual/libusb:1
  31. firmware? (
  32. sys-libs/ncurses:0=
  33. cross-arm-none-eabi/binutils
  34. cross-arm-none-eabi/gcc
  35. cross-arm-none-eabi/newlib
  36. )
  37. $(python_gen_cond_dep '
  38. dev-python/numpy
  39. >=dev-python/jinja2-2.10.1[${PYTHON_USEDEP}]
  40. >=dev-python/pyserial-3.4[${PYTHON_USEDEP}]
  41. >=dev-python/markupsafe-1.1.1[${PYTHON_USEDEP}]
  42. dev-python/virtualenv[${PYTHON_USEDEP}]
  43. ')
  44. "
  45. RESTRICT="mirror"
  46. DOCS=( COPYING )
  47. PATCHES=(
  48. ${FILESDIR}/ecf4266cc71f52045460c4021fdd7b971f119562.patch
  49. ${FILESDIR}/klipper-fix-arm-firmware-build.patch
  50. )
  51. # set_config <file> <option name> <yes value> <no value> test
  52. # a value of "#" will just comment out the option
  53. set_config() {
  54. local file="${ED}/$1" var=$2 val com
  55. eval "${@:5}" && val=$3 || val=$4
  56. [[ ${val} == "#" ]] && com="#" && val='\2'
  57. sed -i -r -e "/^#?${var}=/{s:=([\"'])?([^ ]*)\1?:=\1${val}\1:;s:^#?:${com}:}" "${file}"
  58. }
  59. set_config_yes_no() {
  60. set_config "$1" "$2" YES NO "${@:3}"
  61. }
  62. pkg_pretend() {
  63. if use firmware; then
  64. if ! has_version -b cross-arm-none-eabi/newlib; then
  65. ewarn
  66. ewarn " create a cross-compiler to build a firmware for your printer board, for example:"
  67. ewarn " crossdev -t arm-none-eabi --lenv 'USE=nano' --without-headers"
  68. ewarn
  69. die
  70. fi
  71. fi
  72. }
  73. src_compile() {
  74. sed -i -r -e "s/(\!\/usr\/bin\/env )python2/\1${EPYTHON}/" klippy/klippy.py || die
  75. ${EPYTHON} -m compileall klippy
  76. ${EPYTHON} klippy/chelper/__init__.py
  77. }
  78. src_install() {
  79. if use doc; then
  80. dodoc -r ${DOCS[@]} docs/*.md docs/img docs/prints
  81. fi
  82. if use examples; then
  83. insinto "/usr/share/${PN}/examples"
  84. doins -r config/*
  85. fi
  86. # currently only these are python3 compatible or have missing dependencies
  87. local python_scripts=( \
  88. buildcommands.py \
  89. canbus_query.py \
  90. checkstack.py \
  91. dump_mcu.py \
  92. graph_accelerometer.py \
  93. flash_usb.py \
  94. check_whitespace.py \
  95. calibrate_shaper.py \
  96. graph_temp_sensor.py \
  97. logextract.py \
  98. make_version.py \
  99. stepstats.py \
  100. update_chitu.py \
  101. update_mks_robin.py \
  102. whconsole.py \
  103. )
  104. # UPSTREAM-ISSUE https://github.com/KevinOConnor/klipper/issues/3689
  105. for f in ${python_scripts[@]}; do
  106. sed -i -r -e "s/(\!\/usr\/bin\/env )python.*$/\1${EPYTHON}/" "scripts/${f}" || die
  107. done
  108. sed -i -e '1i #!/usr/bin/env python' scripts/test_klippy.py || die
  109. python_fix_shebang scripts/*.py
  110. insinto "/usr/$(get_libdir)/${PN}"
  111. insopts -m0755
  112. doins -r klippy lib scripts
  113. if use firmware; then
  114. doins -r src Makefile
  115. fi
  116. dodir /usr/libexec/${PN}
  117. dosym "/usr/$(get_libdir)/${PN}/klippy" "/usr/libexec/${PN}/klippy"
  118. #${EPYTHON} scripts/make_version.py GENTOOLINUX > "/usr/$(get_libdir)/${PN}/klippy/.version"
  119. if use systemd; then
  120. systemd_newunit "${FILESDIR}/${PN}.service" "${PN}.service"
  121. else
  122. newinitd "${FILESDIR}/${PN}.initd" "${PN}"
  123. fi
  124. dodir /etc/${PN}
  125. keepdir /etc/${PN}
  126. dodir /var/spool/${PN}/virtual_sdcard
  127. keepdir /var/spool/${PN}/virtual_sdcard
  128. fperms 0755 /var/spool/${PN}/virtual_sdcard
  129. fowners -R ${PN}:${PN} /usr/$(get_libdir)/${PN} /var/spool/${PN} /etc/${PN}
  130. use systemd || set_config /etc/rc.conf rc_env_allow "KLIPPER_CONFIG KLIPPER_LOG KLIPPER_SOCKET"
  131. doenvd "${FILESDIR}/99klipper"
  132. }
  133. pkg_postinst() {
  134. if use firmware; then
  135. elog
  136. elog " Use following command to configure your printer board firmware:"
  137. elog " cd /usr/$(get_libdir)/klipper"
  138. elog " make ARCH=\${ARCH} CROSS_PREFIX=\${ARCH}-none-eabi- menuconfig"
  139. elog
  140. elog " Build the firmware with: "
  141. elog " make ARCH=\${ARCH} CROSS_PREFIX=\${ARCH}-none-eabi- -j\$(nproc)"
  142. elog
  143. elog " Use official klipper documentation to flash firmware."
  144. fi
  145. elog
  146. elog " Provide a valid printer.cfg in /etc/klipper, which should be writeable by the user 'klipper'"
  147. elog
  148. elog " Run the klipper service with:"
  149. elog " rc-service klipper start"
  150. elog " or with systemd service"
  151. elog " systemctl enable klipper.service"
  152. elog
  153. elog " To use the virtual_sdcard feature of klipper the path"
  154. elog " /var/spool/klipper/virtual_sdcard/ should be used in printer.cfg."
  155. elog
  156. }