PKGBUILD 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. # Maintainer (arch): Antonio Rojas <arojas@archlinux.org>
  2. # Contributor: Ray Rashif <schiv@archlinux.org>
  3. # Contributor: Tobias Powalowski <tpowa@archlinux.org>
  4. # Contributor: André Silva <emulatorman@hyperbola.info>
  5. # Contributor: Márcio Silva <coadde@hyperbola.info>
  6. # Maintainer: Omar Vega Ramos <ovruni@gnu.org.pe>
  7. # Contributor: grizzlyuser <grizzlyuser@protonmail.com>
  8. # Contributor: bill-auger <bill-auger@programmer.net>
  9. # parabola changes and rationale:
  10. # - remove support for non-free/patent-encumbered algorithms and graphics
  11. # (SIFT and SURF algorithms, "lena" images, CUDA)
  12. # - disable build of non-free intel 'ippicv/ippiw'
  13. # NOTE: This PKGBUILD is kept in-sync, as closely as possible,
  14. # with arch{,arm,32}, for the sake of documentation and cleaner diffs.
  15. # That also helps to identify which changes were made by Parabola vs upstream.
  16. # Therefore, this PKGBUILD may declare blacklisted dependencies, non-free sources,
  17. # or include code for anti-features; but those will be filtered-out subsequently.
  18. # Any code which implements an anti-feature should be commented-out;
  19. # and include an 'anti-feature' comment, for clarity.
  20. # Any blacklisted dependencies and non-free sources should be filtered,
  21. # and include a 'non-free' comment, for clarity.
  22. # Without those over-rides, the resulting program may not be FSDG-fit.
  23. # Do not circumvent those over-rides, if compiling for the Parabola repos.
  24. # per-arch mksource hack
  25. # because mksource() runs in the host environment; $CARCH will always be the host arch
  26. # this explicit _CARCH=/CARCH= switch allows per-arch pkgver and sources
  27. # NOTE: remember to delete the CARCH= line and reset it to _CARCH= before each build
  28. _CARCH=
  29. sed -i "s|^_CARCH=.*|CARCH=${CARCH}|" PKGBUILD &> /dev/null || :
  30. pkgbase=opencv
  31. pkgname=(opencv
  32. opencv-samples
  33. python-opencv
  34. opencv-cuda)
  35. pkgname=( ${pkgname[*]/opencv-cuda/} ) # non-free
  36. pkgver=4.9.0
  37. pkgrel=6
  38. _pkgver_i686=4.6.0
  39. _pkgrel_i686=6.0
  40. eval "[[ -v _pkgver_${CARCH} ]] && pkgver=\$_pkgver_${CARCH}" # our different arches do not
  41. eval "[[ -v _pkgrel_${CARCH} ]] && pkgrel=\$_pkgrel_${CARCH}" # always roll at the same speed
  42. pkgrel+=.parabola1
  43. pkgdesc='Open Source Computer Vision Library'
  44. pkgdesc="${pkgdesc/Open Source/}"
  45. arch=(x86_64)
  46. arch+=(armv7h i686)
  47. #license=(Apache-2.0) # TODO:
  48. license=(Apache)
  49. url='https://opencv.org/'
  50. depends=(abseil-cpp
  51. cblas
  52. ffmpeg
  53. freetype2
  54. gcc-libs
  55. glib2
  56. glibc
  57. gst-plugins-base
  58. gst-plugins-base-libs
  59. gstreamer
  60. harfbuzz
  61. lapack
  62. libdc1394
  63. libglvnd
  64. libjpeg-turbo
  65. libpng
  66. libtiff
  67. libwebp
  68. openexr
  69. openjpeg2
  70. verdict
  71. protobuf
  72. tbb
  73. zlib)
  74. makedepends=(ant
  75. cmake
  76. cudnn
  77. eigen
  78. fmt
  79. glew
  80. hdf5
  81. java-environment
  82. lapacke
  83. mesa
  84. nlohmann-json
  85. openmpi
  86. pugixml
  87. python-numpy
  88. python-setuptools
  89. qt6-5compat
  90. vtk)
  91. makedepends=( ${makedepends[*]/cudnn/} ) # non-free
  92. optdepends=('opencv-samples: samples'
  93. 'vtk: for the viz module'
  94. 'glew: for the viz module'
  95. 'qt6-base: for the HighGUI module'
  96. 'hdf5: for the HDF5 module'
  97. 'opencl-icd-loader: For coding with OpenCL'
  98. 'java-runtime: Java interface')
  99. source=(https://github.com/opencv/opencv/archive/$pkgver/$pkgname-$pkgver.tar.gz
  100. https://github.com/opencv/opencv_contrib/archive/$pkgver/opencv_contrib-$pkgver.tar.gz
  101. $pkgname-cccl-2.2.0.zip::https://github.com/NVIDIA/cccl/archive/refs/tags/v2.2.0.zip
  102. vtk9.patch
  103. fix-nppi-bufsize-type.patch)
  104. sha256sums=('ddf76f9dffd322c7c3cb1f721d0887f62d747b82059342213138dc190f28bc6c'
  105. '8952c45a73b75676c522dd574229f563e43c271ae1d5bbbd26f8e2b6bc1a4dae'
  106. 'f0899311b537614f3bb79fcb20e5fa09e72b857ba3e5ef5d13ef64c6710483e7'
  107. 'f35a2d4ea0d6212c7798659e59eda2cb0b5bc858360f7ce9c696c77d3029668e'
  108. '993032a43a62faecc56f3f7aeaed29e471605dabdf28579fbeb36d52ecaa4060')
  109. [[ "${CARCH}" == i686 ]] && sha256sums[0]='1ec1cba65f9f20fe5a41fda1586e01c70ea0c9a6d7b67c9e13edf0cfe2239277' # upstream source-ball
  110. [[ "${CARCH}" == i686 ]] && sha256sums[1]='1777d5fd2b59029cf537e5fd6f8aa68d707075822f90bde683fcde086f85f7a7' # contrib source-ball
  111. # parabola mksource over-rides
  112. mksource=( ${source[0]} ${source[1]} )
  113. mksha256sums=( ${sha256sums[0]} ${sha256sums[1]} )
  114. source=(https://repo.parabola.nu/other/${pkgname}-libre/${pkgname}-libre-${pkgver}.tar.gz{,.sig}
  115. ${source[*]:2})
  116. sha256sums=('5196d749c45b50b7de62fb2d078791524324df00e73ffd7876b198115dd62f53'
  117. SKIP
  118. ${sha256sums[*]:2})
  119. [[ "${CARCH}" == i686 ]] && sha256sums[0]='05817a0578786bb4cf1ddd8cf74c36961af54c3540e188b0da278b87af10e43c' # libre source-ball
  120. validpgpkeys=('3954A7AB837D0EA9CFA9798925DB7D9B5A8D4B40') # bill-auger
  121. mksource() {
  122. ## opencv ##
  123. cd "${srcdir}"/${pkgname}-${pkgver}
  124. # remove lena.png and lena.jpg images
  125. rm -v $(find . -iname '*lena*')
  126. # disable build of non-free modules
  127. # NOTE: this 'download_ippicv()' LOC should not be hit,
  128. # per the bogus define: 'IPPROOT' in build(), but delete it anyways
  129. rm -rf 3rdparty/ippicv/
  130. grep 'download_ippicv(ICV_PACKAGE_ROOT)' cmake/OpenCVFindIPP.cmake &> /dev/null &&
  131. sed -i 's|download_ippicv([^)]*)|return()|' cmake/OpenCVFindIPP.cmake &&
  132. ! grep 'download_ippicv(ICV_PACKAGE_ROOT)' cmake/OpenCVFindIPP.cmake &> /dev/null ||
  133. ! echo "download_ippicv (non-free) - mksource needs reworking" || exit 1
  134. ## opencv_contrib ##
  135. cd "${srcdir}"/opencv_contrib-${pkgver}
  136. # remove SIFT and SURF algorithms
  137. rm -rv modules/xfeatures2d
  138. # remove CUDA modules
  139. rm -rv modules/cuda*
  140. }
  141. prepare() {
  142. patch -d $pkgname-$pkgver -p1 < vtk9.patch # Don't require all vtk optdepends
  143. # fix type of several buffer size variables (NPP from CUDA 12.4 has breaking API change
  144. # as several function parameters were changed from `int*` to `size_t*`)
  145. # fix-nppi-bufsize-type.patch patches deleted non-free files
  146. ## arch-specific patching ##
  147. cd "${srcdir}"/${pkgname}-${pkgver}
  148. # error: ‘CODEC_ID_H263P’ was not declared in this scope; did you mean ‘AV_CODEC_ID_H263P’?
  149. [[ "$CARCH" != i686 ]] ||
  150. sed -i 's| CODEC_ID_| AV_CODEC_ID_|g' modules/videoio/src/ffmpeg_codecs.hpp
  151. # but alas, there is another problem with i686
  152. # /usr/include/qt6/QtCore/qfloat16.h:80:52: error: SSE register return with SSE2 disabled
  153. # /usr/include/qt6/QtCore/qfloat16.h:163:147: error: operation not permitted on type ‘_Float16’ without option ‘-msse2’
  154. }
  155. build() {
  156. # SSE{2,3} is not available for armv7h or i686 (ARM has 'NEON' instead)
  157. local parabola_options=''
  158. case "$CARCH" in
  159. armv7h|i686) parabola_options='-DCPU_BASELINE_DISABLE=SSE,SSE2' ;;
  160. x86_64 ) parabola_options='-DCPU_BASELINE_DISABLE=SSE3 -DCPU_BASELINE_REQUIRE=SSE2' ;;
  161. esac
  162. parabola_options+=' -DIPPROOT=/this-is-non-free' # disable build of non-free modules
  163. export JAVA_HOME="/usr/lib/jvm/default"
  164. # cmake's FindLAPACK doesn't add cblas to LAPACK_LIBRARIES, so we need to specify them manually
  165. _opts="-DWITH_OPENCL=ON \
  166. -DWITH_OPENGL=ON \
  167. -DOpenGL_GL_PREFERENCE=LEGACY \
  168. -DCMAKE_CXX_STANDARD=17 \
  169. -DWITH_TBB=ON \
  170. -DWITH_VULKAN=ON \
  171. -DWITH_QT=ON \
  172. -DBUILD_TESTS=OFF \
  173. -DBUILD_PERF_TESTS=OFF \
  174. -DBUILD_EXAMPLES=ON \
  175. -DBUILD_PROTOBUF=OFF \
  176. -DPROTOBUF_UPDATE_FILES=ON \
  177. -DINSTALL_C_EXAMPLES=ON \
  178. -DINSTALL_PYTHON_EXAMPLES=ON \
  179. -DCMAKE_INSTALL_PREFIX=/usr \
  180. -DCPU_BASELINE_DISABLE=SSE3 \
  181. -DCPU_BASELINE_REQUIRE=SSE2 \
  182. -DOPENCV_EXTRA_MODULES_PATH=$srcdir/opencv_contrib-$pkgver/modules \
  183. -DOPENCV_SKIP_PYTHON_LOADER=ON \
  184. -DLAPACK_LIBRARIES=/usr/lib/liblapack.so;/usr/lib/libblas.so;/usr/lib/libcblas.so \
  185. -DLAPACK_CBLAS_H=/usr/include/cblas.h \
  186. -DLAPACK_LAPACKE_H=/usr/include/lapacke.h \
  187. -DOPENCV_GENERATE_PKGCONFIG=ON \
  188. -DOPENCV_ENABLE_NONFREE=ON \
  189. -DOPENCV_JNI_INSTALL_PATH=lib \
  190. -DOPENCV_GENERATE_SETUPVARS=OFF \
  191. -DEIGEN_INCLUDE_PATH=/usr/include/eigen3 \
  192. -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON \
  193. -Dprotobuf_MODULE_COMPATIBLE=ON"
  194. _opts="${_opts/-DCPU_BASELINE_DISABLE=SSE3/}" # per-arch options
  195. _opts="${_opts/-DCPU_BASELINE_REQUIRE=SSE2/}" # per-arch options
  196. _opts="${_opts/-DOPENCV_ENABLE_NONFREE=ON/-DOPENCV_ENABLE_NONFREE=OFF}" # non-free
  197. _opts+=" ${parabola_options}" # non-free
  198. cmake -B build -S $pkgname-$pkgver $_opts \
  199. -DBUILD_WITH_DEBUG_INFO=ON
  200. cmake --build build
  201. # 'build-cuda' recipe deleted (non-free)
  202. }
  203. package_opencv() {
  204. DESTDIR="$pkgdir" cmake --install build
  205. # separate samples package
  206. mv "$pkgdir"/usr/share/opencv4/samples "$srcdir"
  207. # Add java symlinks expected by some binary blobs
  208. ln -sr "$pkgdir"/usr/share/java/{opencv4/opencv-${pkgver//./},opencv}.jar
  209. ln -sr "$pkgdir"/usr/lib/{libopencv_java${pkgver//./},libopencv_java}.so
  210. # Split Python bindings
  211. rm -r "$pkgdir"/usr/lib/python3*
  212. }
  213. package_opencv-samples() {
  214. pkgdesc+=' (samples)'
  215. depends=(opencv)
  216. unset optdepends
  217. mkdir -p "$pkgdir"/usr/share/opencv4
  218. mv samples "$pkgdir"/usr/share/opencv4
  219. }
  220. package_python-opencv() {
  221. pkgdesc='Python bindings for OpenCV'
  222. depends=(fmt
  223. glew
  224. hdf5
  225. jsoncpp
  226. opencv
  227. openmpi
  228. pugixml
  229. python-numpy
  230. qt6-base
  231. vtk)
  232. unset optdepends
  233. DESTDIR="$pkgdir" cmake --install build/modules/python3
  234. }
  235. # package_opencv-cuda() deleted (non-free)