# Template file for 'gifski'
pkgname=gifski
version=1.34.0
revision=2
build_helper="qemu"
build_style=cargo
configure_args="$(vopt_if ffmpeg --features=video)"
hostmakedepends="pkg-config $(vopt_if ffmpeg clang21-devel)"
makedepends="$(vopt_if ffmpeg ffmpeg6-devel)"
short_desc="Highest-quality GIF encoder based on pngquant"
maintainer="Orphaned <orphan@voidlinux.org>"
license="AGPL-3.0-only"
homepage="https://gif.ski"
changelog="https://github.com/ImageOptim/gifski/releases"
distfiles="https://github.com/ImageOptim/gifski/archive/refs/tags/${version}.tar.gz"
checksum=c9711473615cb20d7754e8296621cdd95cc068cb04b640f391cd71f8787b692c

build_options="ffmpeg"
build_options_default="ffmpeg"

# we are patching ffmpeg-sys-next to make cross compilation work,
_clear_vendor_checksums() {
	sed -i 's/\("files":{\)[^}]*/\1/' vendor/$1/.cargo-checksum.json
}
post_extract() {
	mkdir -p .cargo
	cargo vendor --locked --versioned-dirs >.cargo/config.toml
	_clear_vendor_checksums ffmpeg-sys-next-6.1.0
}

_setup_env() {
	export CFLAGS_${RUST_TARGET//-/_}="${CFLAGS}" \
		HOST_CFLAGS="-fstack-clash-protection ${CFLAGS_host}" \
		CFLAGS_${RUST_BUILD//-/_}="${HOST_CFLAGS}" \
	# unset CFLAGS to work around cc-rs adding CFLAGS to host and target CFLAGS_*.
	# https://github.com/rust-lang/cc-rs/issues/1469
	unset CFLAGS
}

pre_build() {
	_setup_env
}

pre_check() {
	_setup_env
}

pre_install() {
	_setup_env
	vlicense LICENSE
}
