# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit cmake xdg udev

DESCRIPTION="Advanced Digital DJ tool based on Qt"
HOMEPAGE="https://mixxx.org/"
if [[ ${PV} == *9999 ]] ; then
	inherit git-r3
	if [[ ${PV} == ?.?.9999 ]] ; then
		EGIT_BRANCH=${PV%.9999}
	fi
	EGIT_REPO_URI="https://github.com/mixxxdj/${PN}.git"
else
	SRC_URI="https://github.com/mixxxdj/${PN}/archive/release-${PV}.tar.gz -> ${P}.tar.gz"
	S="${WORKDIR}/${PN}-release-${PV}"
	KEYWORDS="~amd64 ~x86"
fi

LICENSE="GPL-2"
SLOT="0"
IUSE="aac doc ffmpeg hid keyfinder lv2 mp3 mp4 opus qt5 qtkeychain shout wavpack"

RDEPEND="
	dev-db/sqlite
	dev-libs/glib:2
	dev-libs/protobuf:=
	media-libs/chromaprint
	media-libs/flac:=
	media-libs/libebur128
	media-libs/libid3tag:=
	media-libs/libogg
	media-libs/libsndfile
	>=media-libs/libsoundtouch-2.1.2
	media-libs/libvorbis
	media-libs/portaudio
	media-libs/portmidi
	media-libs/rubberband
	<media-libs/taglib-2.0.0
	media-libs/vamp-plugin-sdk
	sci-libs/fftw:3.0=
	sys-power/upower
	virtual/glu
	virtual/libusb:1
	virtual/opengl
	virtual/udev
	x11-libs/libX11
	>=x11-libs/libxkbcommon-0.5.0
	aac? (
		media-libs/faad2
		media-libs/libmp4v2
	)
	ffmpeg? ( media-video/ffmpeg:= )
	hid? ( dev-libs/hidapi )
	keyfinder? ( >=media-libs/libkeyfinder-2.2.4 )
	lv2? ( media-libs/lilv )
	mp3? ( media-libs/libmad )
	mp4? ( media-libs/libmp4v2:= )
	opus? (	media-libs/opusfile )
	qt5? (
		dev-qt/qtconcurrent:5
		dev-qt/qtcore:5
		dev-qt/qtdbus:5
		dev-qt/qtgui:5
		dev-qt/qtnetwork:5
		dev-qt/qtopengl:5
		dev-qt/qtsql:5
		dev-qt/qtsvg:5
		dev-qt/qtwidgets:5
		dev-qt/qtx11extras:5
		dev-qt/qtxml:5
		qtkeychain? ( dev-libs/qtkeychain:=[qt5(+)] )
	)
	!qt5? (
		dev-qt/qt5compat:6
		dev-qt/qtbase:6[concurrent,dbus,gui,network,opengl,sql,sqlite,widgets,xml]
		dev-qt/qtdeclarative:6
		dev-qt/qtshadertools:6
		dev-qt/qtsvg:6
		qtkeychain? ( dev-libs/qtkeychain:=[qt6] )
	)
	shout? ( >=media-libs/libshout-2.4.5 )
	wavpack? ( media-sound/wavpack )
"
DEPEND="${RDEPEND}
	dev-cpp/ms-gsl
"
BDEPEND="
	qt5? (
		dev-qt/qttest:5
		dev-qt/qtxmlpatterns:5
	)
	dev-cpp/benchmark
	dev-cpp/gtest
	virtual/pkgconfig
"

PATCHES=(
	"${FILESDIR}"/${PN}-9999-docs.patch
)

src_configure() {
	local mycmakeargs=(
		-DFAAD="$(usex aac ON OFF)"
		-DFFMPEG="$(usex ffmpeg ON OFF)"
		-DHID="$(usex hid ON OFF)"
		-DLILV="$(usex lv2 ON OFF)"
		-DMAD="$(usex mp3 ON OFF)"
		-DOPTIMIZE="OFF"
		-DCCACHE_SUPPORT="OFF"
		-DOPUS="$(usex opus ON OFF)"
		-DBROADCAST="$(usex shout ON OFF)"
		-DVINYLCONTROL="ON"
		-DINSTALL_USER_UDEV_RULES="OFF"
		-DWAVPACK="$(usex wavpack ON OFF)"
		-DQT6="$(usex qt5 OFF ON)"
		-DQTKEYCHAIN="$(usex qtkeychain ON OFF)"
		-DKEYFINDER="$(usex keyfinder ON OFF)"
		-DDOWNLOAD_MANUAL="OFF"
		-DBUILD_SHARED_LIBS="OFF"
		-DENGINEPRIME="OFF"
	)

	cmake_src_configure
}

src_install() {
	cmake_src_install
	insinto /usr/share/mixxx/
	doins -r res/qml
	udev_newrules "${S}"/res/linux/mixxx-usb-uaccess.rules 69-mixxx-usb-uaccess.rules

	if use doc ; then
		dodoc README res/Mixxx-Keyboard-Shortcuts.pdf
	fi
}

pkg_postinst() {
	xdg_pkg_postinst
	udev_reload
}

pkg_postrm() {
	xdg_pkg_postrm
	udev_reload
}