# Template file for 'gmic'
pkgname=gmic
version=2.9.9
revision=1
_zart_hash=939cf381c5871e506aabd066037acf2b55143c1d
build_wrksrc="src"
build_style=gnu-makefile
build_helper=qmake
hostmakedepends="pkg-config gimp qt5-host-tools qt5-qmake"
makedepends="fftw-devel ilmbase-devel libopenexr-devel MesaLib-devel libopencv-devel
 libgomp-devel lcms2-devel libpng-devel libjpeg-turbo-devel tiff-devel libcurl-devel
 gtk+-devel gimp-devel qt5-devel"
short_desc="GREYC's Magic for Image Computing (image processing framework)"
maintainer="Jakub Skrzypnik <jot.skrzyp@gmail.com>"
license="CECILL-2.1"
homepage="http://gmic.eu/"
distfiles="http://gmic.eu/files/source/gmic_${version}.tar.gz
 https://github.com/c-koi/zart/archive/${_zart_hash}.tar.gz"
checksum="9f053338752ec96a6b619718037767682c5fd58e2471c08f3740fdb070605bc0
 eec47cc9b572cb3e3c26b424381948e12161e129f3d0d3ceca87ff4a8f99fe5d"
disable_parallel_build="yes"

post_extract() {
	mv ../zart-${_zart_hash} zart
}

post_patch() {
	vsed -i Makefile -e "s,-I[\$](USR),-I$XBPS_CROSS_BASE/usr,g"
	vsed -i Makefile -e "s/-Ofast/-O2/g"
	# uses gimptool-2.0 to determine PLUGINDIR which fails in cross builds
	vsed -i Makefile -e "s,^PLUGINDIR = .*,PLUGINDIR = /usr/lib/gimp/2\.0/plug-ins,g"
	vsed -i ../gmic-qt/gmic_qt.pro -e "s/-Ofast/-O2/g"
	# Not supported on ppc but we already compile for baselines
	case "$XBPS_TARGET_MACHINE" in
		ppc*) vsed -i Makefile -e 's;-mtune=generic;;' ;;
	esac
}

do_build() {
	make CC="$CC" CXX="$CXX" LD="$LD" AR="$AR" RANLIB="$RANLIB" \
		CPP="$CPP" AS="$AS" OBJCOPY="$OBJCOPY" OBJDUMP="$OBJDUMP" \
		CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" LDFLAGS="$LDFLAGS" \
		cli lib libc

	for _target in gimp gmic_qt zart; do
		make $_target
	done
}

post_install() {
	vlicense ../COPYING
}

gmic-gimp_package() {
	short_desc+=" - GIMP plugin"
	depends="gimp ${sourcepkg}>=${version}_${revision}"
	pkg_install() {
		vmove usr/lib/gimp
	}
}

gmic-zart_package() {
	short_desc+=" - ZArt tool"
	depends="${sourcepkg}>=${version}_${revision}"
	pkg_install() {
		vmove usr/bin/zart
		vmove usr/share/applications/zart.desktop
		vmove usr/share/icons/hicolor/48x48/apps/zart.png
		vmove usr/share/icons/hicolor/scalable/apps/zart.svg
	}
}

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