# Copyright 2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit toolchain-funcs multilib

DESCRIPTION="Common image-processing filters for vapoursynth"
HOMEPAGE="https://github.com/chikuzen/GenericFilters"

if [[ ${PV} == *9999* ]]; then
	inherit git-r3
	EGIT_REPO_URI="https://github.com/myrsloik/GenericFilters.git"
else
	inherit vcs-snapshot
	SRC_URI="https://github.com/myrsloik/GenericFilters/archive/r${PV}.tar.gz -> ${PN}-${PV}.tar.gz"
fi

LICENSE="LGPL-2.1"
SLOT="0"
KEYWORDS=""
IUSE="-noasm debug"

RDEPEND+="
	media-libs/vapoursynth
"
DEPEND="${RDEPEND}
"

S="${WORKDIR}/${P}/src"

src_prepare() {
	sed -i 's/"$CC" "$LD" "$STRIP"/"$CC" "$LD"/' configure || die
	sed -i 's/STRIP="${CROSS}${STRIP}"/STRIP=""/' configure || die
	if use debug ; then
		myconf="${myconf} --enable-debug"
	fi
	if use noasm ; then
		myconf="${myconf} --disable-simd"
	fi
	sed -i -e "s:CC=\"gcc\":CC=\"$(tc-getCC)\":" configure || die
	sed -i -e "s:LD=\"gcc\":LD=\"$(tc-getCC)\":" configure || die
	chmod +x configure || die
	default
}

src_configure() {
	./configure ${myconf} --extra-cflags="${CFLAGS}" --extra-ldflags="${LDFLAGS}" || die
}

src_install() {
	exeinto /usr/$(get_libdir)/vapoursynth/
	doexe libgenericfilters.so
	dodoc ../readme.rst
}