# Template file for 'opencv'
pkgname=opencv
version=4.6.0
revision=3
create_wrksrc=yes
build_wrksrc=${pkgname}-${version}
build_style=cmake
configure_args="-DENABLE_PRECOMPILED_HEADERS=OFF -DWITH_OPENMP=ON
 -DWITH_OPENCL=ON -DENABLE_CXX11=ON -DOPENCV_SKIP_PYTHON_LOADER=ON
 -DOPENCV_PYTHON3_INSTALL_PATH=/${py3_sitelib}
 -DOPENCV_GENERATE_PKGCONFIG=YES -DWITH_EIGEN=ON
 -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${version}/modules
 -DBUILD_opencv_wechat_qrcode=OFF -DBUILD_opencv_rgbd=OFF
 -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF"
hostmakedepends="pkg-config eigen python3-numpy"
makedepends="ffmpeg-devel libpng-devel libjpeg-turbo-devel tiff-devel
 jasper-devel ocl-icd-devel libgomp-devel libopenexr-devel gtk+3-devel
 libgphoto2-devel gst-plugins-base1-devel openblas-devel
 python3-numpy python3-devel"
short_desc="Computer vision and machine learning software library"
maintainer="Orphaned <orphan@voidlinux.org>"
license="BSD-3-Clause"
homepage="https://opencv.org"
changelog="https://github.com/opencv/opencv/wiki/ChangeLog"
distfiles="https://github.com/opencv/opencv/archive/${version}.tar.gz
 https://github.com/opencv/opencv_contrib/archive/${version}.tar.gz>contrib.tar.gz"
checksum="1ec1cba65f9f20fe5a41fda1586e01c70ea0c9a6d7b67c9e13edf0cfe2239277
 1777d5fd2b59029cf537e5fd6f8aa68d707075822f90bde683fcde086f85f7a7"
patch_args="-Np1 -d ${build_wrksrc}"
# tests hang indenfinitely, even with test data included
make_check=no

if [ "$XBPS_TARGET_NO_ATOMIC8" ]; then
	makedepends+=" libatomic-devel"
fi

if [ "$CROSS_BUILD" ]; then
	# Tell opencv where to find python and numpy
	configure_args+=" -DPYTHON3_INCLUDE_PATH=${XBPS_CROSS_BASE}/${py3_inc}
	 -DPYTHON3_NUMPY_INCLUDE_DIRS=${XBPS_CROSS_BASE}/${py3_sitelib}/numpy/core/include"
fi

case "$XBPS_TARGET_MACHINE" in
	ppc64*) ;;
	ppc*) broken="grfmt_jpeg2000.cpp:380:48: error: lvalue required as unary '&' operand";;
esac

post_install() {
	vlicense LICENSE
}

libopencv_package() {
	short_desc+=" - library files"
	pkg_install() {
		vmove usr/lib/*.so.*
	}
}

libopencv-devel_package() {
	short_desc+=" - development files"
	depends="libopencv>=${version}_${revision}"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/cmake
		vmove usr/lib/pkgconfig
		vmove usr/lib/*.so
		vmove usr/share/opencv4
	}
}

libopencv-python3_package() {
	short_desc+=" - Python3 bindings"
	depends="python3-numpy"
	pkg_install() {
		vmove ${py3_sitelib}
	}
}

opencv4_package() {
	depends="${sourcepkg}>=${version}_${revision}"
	short_desc+=" (transitional dummy package)"
	build_style=meta
}

libopencv4_package() {
	depends="lib${sourcepkg}>=${version}_${revision}"
	short_desc+=" - library files (transitional dummy package)"
	build_style=meta
}

libopencv4-devel_package() {
	depends="lib${sourcepkg}-devel>=${version}_${revision}"
	short_desc+=" - development files (transitional dummy package)"
	build_style=meta
}

libopencv4-python3_package() {
	depends="lib${sourcepkg}-python3>=${version}_${revision}"
	short_desc+=" - Python3 bindings (transitional dummy package)"
	build_style=meta
}
