# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: André Klitzing <aklitzing@gmail.com>
pkgname=pngquant
pkgver=3.0.3
pkgrel=0
_libimagequant=4.2.2
pkgdesc="Lossy PNG compressor"
url="https://pngquant.org/"
arch="all"
license="GPL-3.0-or-later"
makedepends="
	cargo
	cargo-auditable
	lcms2-dev
	libpng-dev
	"
subpackages="$pkgname-doc"
source="https://github.com/kornelski/pngquant/archive/$pkgver/pngquant-$pkgver.tar.gz
	libimagequant-$_libimagequant.tar.gz::https://github.com/ImageOptim/libimagequant/archive/refs/tags/$_libimagequant.tar.gz
	Cargo.lock
	"
options="!check" # seems to not have any runnable anymore

prepare() {
	default_prepare
	rmdir lib
	ln -sfv "$srcdir"/libimagequant-$_libimagequant lib
	ln -sfv "$srcdir"/Cargo.lock Cargo.lock
	cargo fetch --target="$CTARGET" --locked
}

build() {
	# 20% faster than =s/=2
	export CARGO_PROFILE_RELEASE_OPT_LEVEL=3
	cargo auditable build --release --frozen
}

check() {
	cargo test --frozen
}

package() {
	install -Dm755 target/release/pngquant -t "$pkgdir"/usr/bin/
	install -Dm644 pngquant.1 -t "$pkgdir"/usr/share/man/man1/
}

sha512sums="
8d4b290e4b9fbd5061c28d9521f514c36e091d26d27b72b27d06349b8948582baddb4e81a0be653eca9ebbacb1b8722db4cd5d35ed0d19f96f610b0de4ccb0bc  pngquant-3.0.3.tar.gz
31bd79024abc1fd884461f8f422d6eac1f5786ce347ac3c517e9cb66f289ad1ace0e3a25c55c7b7384badb2545174871464d60f1238ed2deb1f521d5f3ede96b  libimagequant-4.2.2.tar.gz
03ae19c2caaad5815ef1b0c4a1cf534b661fa1006eaaf8002807f763c0f53f678e18326e43249058ac0136e7fbf79a24440a333fbb2fe6833b5371883367a14b  Cargo.lock
"
