SUMMARY="Convert, edit, or compose bitmap images"
DESCRIPTION="ImageMagick® is a software suite to create, edit, compose, or \
convert bitmap images. It can read and write images in a variety of formats \
(over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PNG, Postscript, \
SVG, and TIFF. Use ImageMagick to resize, flip, mirror, rotate, distort, shear \
and transform images, adjust image colors, apply various special effects, or \
draw text, lines, polygons, ellipses and Bézier curves."
HOMEPAGE="https://www.imagemagick.org/
	https://github.com/ImageMagick/ImageMagick/"
COPYRIGHT="1999-2020 ImageMagick Studio LLC"
LICENSE="IMAGEMAGICK"
REVISION="1"
imageMagickVersion="${portVersion%.*}-${portVersion##*.}"
SOURCE_URI="https://www.imagemagick.org/download/releases/ImageMagick-$imageMagickVersion.tar.xz
	https://mirror.sobukus.de/files/src/imagemagick/ImageMagick-$imageMagickVersion.tar.xz
	https://github.com/ImageMagick/ImageMagick/archive/$imageMagickVersion.tar.gz"
CHECKSUM_SHA256="f7abbc65cce01caa314ef4cc9acf8adfa7b633689901a52f29d681230a997c59"
SOURCE_DIR="ImageMagick-$imageMagickVersion"
PATCHES="imagemagick-$portVersion.patchset"

ARCHITECTURES="all !x86_gcc2 ?x86"
SECONDARY_ARCHITECTURES="x86"

GLOBAL_WRITABLE_FILES="
	settings/ImageMagick-7/colors.xml keep-old
	settings/ImageMagick-7/delegates.xml keep-old
	settings/ImageMagick-7/log.xml keep-old
	settings/ImageMagick-7/mime.xml keep-old
	settings/ImageMagick-7/policy.xml keep-old
	settings/ImageMagick-7/quantization-table.xml keep-old
	settings/ImageMagick-7/thresholds.xml keep-old
	settings/ImageMagick-7/type-dejavu.xml keep-old
	settings/ImageMagick-7/type-ghostscript.xml keep-old
	settings/ImageMagick-7/type-windows.xml keep-old
	settings/ImageMagick-7/type-apple.xml keep-old
	settings/ImageMagick-7/type.xml keep-old
	settings/ImageMagick-7/type-urw-base35.xml keep-old
	"

libMagickVersion="4.0.0"
libMagickCoreVersion="7.0.0"
libMagickWandVersion="7.0.0"
libMagickVersionCompat="$libMagickVersion compat >= ${libMagickVersion%%.*}"
libMagickCoreVersionCompat="$libMagickCoreVersion compat >= ${libMagickCoreVersion%%.*}"
libMagickWandVersionCompat="$libMagickWandVersion compat >= ${libMagickWandVersion%%.*}"

PROVIDES="
	imagemagick7$secondaryArchSuffix = $portVersion
	cmd:animate$secondaryArchSuffix
	cmd:compare$secondaryArchSuffix
	cmd:composite$secondaryArchSuffix
	cmd:conjure$secondaryArchSuffix
	cmd:convert$secondaryArchSuffix
	cmd:display$secondaryArchSuffix
	cmd:identify$secondaryArchSuffix
	cmd:import$secondaryArchSuffix
	cmd:magick$secondaryArchSuffix
	cmd:magick_script$secondaryArchSuffix
	cmd:mogrify$secondaryArchSuffix
	cmd:montage$secondaryArchSuffix
	cmd:stream$secondaryArchSuffix
	lib:libMagick++_7.Q16HDRI$secondaryArchSuffix = $libMagickVersionCompat
	lib:libMagickCore_7.Q16HDRI$secondaryArchSuffix = $libMagickCoreVersionCompat
	lib:libMagickWand_7.Q16HDRI$secondaryArchSuffix = $libMagickWandVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libltdl$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libtiff$secondaryArchSuffix
	lib:libwebp$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"
if [ "$effectiveTargetArchitecture" != x86_gcc2 ]; then
	REQUIRES="$REQUIRES
		lib:libgomp$secondaryArchSuffix
		"
fi

PROVIDES_devel="
	imagemagick7${secondaryArchSuffix}_devel = $portVersion
	cmd:Magick++_config$secondaryArchSuffix
	cmd:Magick_config$secondaryArchSuffix
	cmd:MagickCore_config$secondaryArchSuffix
	cmd:MagickWand_config$secondaryArchSuffix
	cmd:Wand_config$secondaryArchSuffix
	devel:libMagick++_7.Q16HDRI$secondaryArchSuffix = $libMagickVersionCompat
	devel:libMagickCore_7.Q16HDRI$secondaryArchSuffix = $libMagickCoreVersionCompat
	devel:libMagickWand_7.Q16HDRI$secondaryArchSuffix = $libMagickWandVersionCompat
	"
REQUIRES_devel="
	imagemagick7$secondaryArchSuffix == $portVersion base
	"


BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libbz2$secondaryArchSuffix
#	devel:libdjvulibre$secondaryArchSuffix
#	devel:libfftw3$secondaryArchSuffix
#	devel:libfontconfig$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
#	devel:libilmimf$secondaryArchSuffix #openexr
#	devel:libjbig2dec$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
#	devel:liblcms2$secondaryArchSuffix
	devel:libltdl$secondaryArchSuffix
#	devel:liblzma$secondaryArchSuffix
#	devel:libopenjp2$secondaryArchSuffix
#	devel:libpango_1.0$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libtiff$secondaryArchSuffix
	devel:libwebp$secondaryArchSuffix
	devel:libxml2$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoreconf
	cmd:awk
	cmd:gcc$secondaryArchSuffix
	cmd:git
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:perl
	cmd:pkg_config$secondaryArchSuffix
	cmd:sed
	"

defineDebugInfoPackage imagemagick7$secondaryArchSuffix \
	$binDir/animate \
	$binDir/compare \
	$binDir/composite \
	$binDir/conjure \
	$binDir/convert \
	$binDir/display \
	$binDir/identify \
	$binDir/import \
	$binDir/magick \
	$binDir/magick-script \
	$binDir/mogrify \
	$binDir/montage \
	$binDir/stream \
	$libDir/libMagick++-7.Q16HDRI.so.$libMagickVersion \
	$libDir/libMagickCore-7.Q16HDRI.so.$libMagickCoreVersion \
	$libDir/libMagickWand-7.Q16HDRI.so.$libMagickWandVersion

BUILD()
{
	export LDFLAGS="-lnetwork"
	autoreconf -vfi
	runConfigure ./configure \
		--enable-shared \
		--without-modules
	make $jobArgs
}

INSTALL()
{
	make install

	# remove libtool files
	rm -f $libDir/libMagick*.la

	prepareInstalledDevelLibs libMagick++-7.Q16HDRI \
		libMagickCore-7.Q16HDRI \
		libMagickWand-7.Q16HDRI
	fixPkgconfig

	packageEntries devel \
		$developDir \
		$binDir/*-config \
		$manDir/man1/*-config.1 \
		$dataDir/doc/ImageMagick-7/www/api
}

TEST()
{
	make check
}
