# Template file for 'ImageMagick'
pkgname=ImageMagick
_majorver=7.0.10
_patchver=60
version="${_majorver}.${_patchver}"
revision=1
wrksrc="${pkgname}-${_majorver}-${_patchver}"
build_style=gnu-configure
configure_args="--without-autotrace --with-wmf=yes
 --without-dps --without-fpx --without-gvc --without-jbig --with-gslib=yes
 --without-lqr --without-openexr --with-gs-font-dir=/usr/share/fonts/Type1
 --with-magick-plus-plus --with-modules --enable-shared --with-rsvg
 --with-dejavu-font-dir=/usr/share/fonts/TTF --enable-opencl --disable-static"
hostmakedepends="automake libtool pkg-config autoconf automake"
makedepends="djvulibre-devel fftw-devel ghostscript-devel glib-devel lcms2-devel
 libXt-devel libgomp-devel libltdl-devel librsvg-devel libwebp-devel libwmf-devel
 ocl-icd-devel pango-devel"
short_desc="Package for display and interactive manipulation of images"
maintainer="Johannes <johannes.brechtmann@gmail.com>"
license="ImageMagick"
homepage="https://www.imagemagick.org/"
changelog="https://imagemagick.org/script/changelog.php"
distfiles="https://github.com/ImageMagick/ImageMagick/archive/${_majorver}-${_patchver}.tar.gz"
checksum=044fc1b27bd9aab515d4c512a33cf3a39313af2baef4aebf5c5c3044b7366ee4

subpackages="libmagick libmagick-devel"

keep_libtool_archives=yes
conf_files="/etc/ImageMagick-${_majorver%%.*}/*.xml"

if [ -z "$CROSS_BUILD" ]; then
	# XXX native perl uses XBPS_TARGET_CFLAGS (-mtune=generic)
	configure_args+=" --with-perl --with-perl-options=INSTALLDIRS=vendor"
	hostmakedepends+=" perl"
	subpackages+=" libmagick-perl"
fi

pre_configure() {
	autoreconf -if
}

do_check() {
	# Disable failing checks
	sed -i '/validate-formats/d' Makefile

	make check
}

post_install() {
	if [ "$CROSS_BUILD" ]; then
		vsed -i -e "s,$XBPS_WRAPPERDIR/$XBPS_CROSS_TRIPLET-,,g" \
			$DESTDIR/usr/bin/*-config
	fi
	vlicense LICENSE
	vlicense NOTICE
}

libmagick_package() {
	short_desc="ImageMagick low-level image manipulation libraries"
	pkg_install() {
		vmove "usr/lib/libMagick*.so.*"
		vmove "usr/lib/ImageMagick*"
		vmove "usr/share/ImageMagick*"
	}
}

libmagick-devel_package() {
	depends="
		fftw-devel fontconfig-devel lcms2-devel libXt-devel
		libgomp-devel libltdl-devel
		libmagick>=${version}_${revision}"
	short_desc="ImageMagick low-level image manipulation development files"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/pkgconfig
		vmove usr/share/doc
		vmove "usr/bin/*-config"
		vmove "usr/lib/*.so"
		vmove "usr/lib/*.la"
		vmove "usr/share/man/man1/*-config.1"
	}
}

libmagick-perl_package() {
	short_desc="ImageMagick perl library bindings"
	pkg_install() {
		vmove usr/lib/perl5
		vmove usr/share/man/man3
	}
}
