# Template file for 'dlib'
pkgname=dlib
version=20.0
revision=2
build_style=cmake
# arm6/7 need helper
build_helper=python3
configure_args="-DBUILD_SHARED_LIBS=ON"
hostmakedepends="pkg-config python3-devel python3-setuptools python3-distutils-extra
 python3-packaging-bootstrap"
makedepends="libjpeg-turbo-devel libpng-devel zlib-devel ffmpeg6-devel cblas-devel
 $(vopt_if openblas openblas-devel) $(vopt_if x11 libX11-devel) python3-pybind11 python3"
short_desc="Modern C++ toolkit containing machine learning algorithms and tools"
maintainer="Felix Hanley <felix@userspace.com.au>"
license="BSL-1.0"
homepage="http://dlib.net"
distfiles="https://github.com/davisking/dlib/archive/v${version}.tar.gz"
checksum=705749801c7896f5c19c253b6be639f4cef2c1831a9606955f01b600b3d86d80

build_options="openblas x11"
desc_option_x11="Enable X11 for GUI components"
build_options_default="openblas x11"

case "$XBPS_TARGET_MACHINE" in
	arm*)
		configure_args+=" -DPYBIND11_FINDPYTHON=ON"
		cmake_args+=" -DPYBIND11_USE_CROSSCOMPILING=ON"
		;;
esac

post_extract() {
	# don't prefer bundled libs
	rm -rf ./dlib/external
}

post_build() {
	case "$XBPS_TARGET_MACHINE" in
	arm*)
		inc="include($(pwd)/$(find -name 'cross_*cmake'))"
		sed -i "1i$inc" tools/python/CMakeLists.txt
		;;
	esac
	python3 setup.py build --set DPYBIND11_FINDPYTHON=ON --set PYBIND11_USE_CROSSCOMPILING=ON \
 --no DLIB_USE_CUDA ${make_build_args}
}

post_install() {
	python setup.py install --skip-build --prefix=/usr --root="${DESTDIR}" --optimize=1 --compiler-flags
}

python3-dlib_package() {
	depends="${sourcepkg}>=${version}_${revision}"
	short_desc+=" - python3"
	pkg_install() {
		vmove "usr/lib/python*"
	}
}

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