# Template file for 'deadbeef'
pkgname=deadbeef
version=1.9.6
revision=1
build_style=gnu-configure
configure_args="--disable-oss --disable-lfm --disable-gtk2 --disable-libretro"
hostmakedepends="automake libtool gettext gettext-devel intltool pkg-config
 yasm clang glib-devel"
makedepends="
 alsa-lib-devel dbus-devel faad2-devel ffmpeg6-devel gtk+3-devel
 jansson-devel libcddb-devel libcdio-devel libcurl-devel libflac-devel
 libmad-devel libsamplerate-devel libsndfile-devel libvorbis-devel
 libzip-devel mpg123-devel opusfile-devel pulseaudio-devel
 wavpack-devel pipewire-devel libdispatch-devel"
depends="desktop-file-utils hicolor-icon-theme"
short_desc="Ultimate Music Player for GNU/Linux"
maintainer="Orphaned <orphan@voidlinux.org>"
license="Zlib, GPL-2.0-or-later, LGPL-2.1-or-later"
_libretro_commit=b4d3db19566398603069d02eeacb3b06987a1b74
_output_pw_commit=0b099d13ab0e89d9934aabdeb2872f0f66ea6960
_mp4p_commit=156195ccb635f016dc34b89425bfbecf046c90d4
homepage="https://deadbeef.sourceforge.io"
changelog="https://deadbeef.sourceforge.io/news0.html"
distfiles="https://github.com/DeaDBeeF-Player/deadbeef/archive/${version}.tar.gz>${pkgname}-${version}.tar.gz
 https://github.com/DeaDBeeF-Player/ddb_dsp_libretro/archive/${_libretro_commit}.tar.gz>libretro-${_libretro_commit}.tar.gz
 https://github.com/DeaDBeeF-Player/ddb_output_pw/archive/${_output_pw_commit}.tar.gz>output_pw-${_output_pw_commit}.tar.gz
 https://github.com/DeaDBeeF-Player/mp4p/archive/${_mp4p_commit}.tar.gz>mp4p-${_mp4p_commit}.tar.gz"
checksum="53ed535335e637437adf77eb4bcadb781eddbf5539f74373d5a863389df5e2d0
 444d4d89edbd51b9d2305c83a49e18949e0f21a42eec2a95ce03efd752a81049
 59115ddcd0378aa2f5914138c5c256198d66339bfbb3d65389b9bf4fa327f9ee
 3b5bdbcb2808d12b9f5af630a91e77be1036aeb487d5fa0a323ce8080918439b"
skip_extraction="libretro-${_libretro_commit}.tar.gz
 output_pw-${_output_pw_commit}.tar.gz
 mp4p-${_mp4p_commit}.tar.gz"

# The soundtouchup plugin was made default in 1.8.4 and fails to build on i686.
# Fixing that might be a good maintainer task.
# ffap also does not build on arm, it is only x86/64 assembly.
case "$XBPS_TARGET_MACHINE" in
	i686*|arm*|aarch*) configure_args+=" --disable-soundtouch --disable-ffap" ;;
esac

if [ "$XBPS_TARGET_LIBC" = "musl" ]; then
	makedepends+=" musl-legacy-compat"
fi

post_extract() {
	rm -rf external/ddb_dsp_libretro
	rm -rf external/ddb_output_pw
	rm -rf external/mp4p
	vsrcextract -C external/ddb_dsp_libretro libretro-${_libretro_commit}.tar.gz
	vsrcextract -C external/ddb_output_pw output_pw-${_output_pw_commit}.tar.gz
	vsrcextract -C external/mp4p mp4p-${_mp4p_commit}.tar.gz
}

# host = what we are on now (e.g. x86_64-unknown-linux-gnu)
# build = what tool to build with (e.g. aarch64-linux-gnu)
# target = what this should run on and what repo it's in (same as build for cross)
do_configure() {
	export CC=clang
	export CXX=clang++
	if [ "$CROSS_BUILD" ] ; then
		export CFLAGS="${CFLAGS/$XBPS_CROSS_CFLAGS/}"
		export CXXFLAGS="${CXXFLAGS/$XBPS_CROSS_CFLAGS/}"
		case "$XBPS_TARGET_MACHINE" in
			arm*|aarch*) # option not on arm
			 export CFLAGS="${CFLAGS/-fstack-clash-protection/}"
			 export CXXFLAGS="${CXXFLAGS/-fstack-clash-protection/}"
			 ;;
		esac
		CFLAGS+=" --target=${XBPS_CROSS_TRIPLET}"
		CXXFLAGS+=" --target=${XBPS_CROSS_TRIPLET}"
		configure_args="${configure_args/--host=${XBPS_CROSS_TRIPLET}/--host=${XBPS_TRIPLET}}"
		configure_args="${configure_args/--build=${XBPS_TRIPLET}/--build=${XBPS_CROSS_TRIPLET}}"
		configure_args+=" --target=${XBPS_CROSS_TRIPLET}"
	fi
	CFLAGS+=" -Wno-error"
	CXXFLAGS+=" -Wno-error"
	./autogen.sh
	case "$XBPS_TARGET_MACHINE" in
		x86_64*|i686*) ;; # only x86/64 should have sse2
		*) sed -e "s|-msse2|JUNK|" -i configure ;;
	esac # HACK: this was auto-determined before? or was super broken
	CC=clang CXX=clang++ ./configure ${configure_args}
}

post_install() {
	vlicense COPYING
}

deadbeef-devel_package() {
	short_desc+=" - development files"
	depends="${sourcepkg}>=${version}_${revision}"
	pkg_install() {
		vmove usr/include
	}
}
