# Template file for 'Aegisub'
pkgname=Aegisub
version=3.2.2
revision=12
build_style=gnu-configure
configure_args="--disable-update-checker --with-alsa --with-ffms2
 --with-wx-config=wx-config-gtk3 $(vopt_with fftw fftw3) $(vopt_with openal)
 $(vopt_with portaudio)"
hostmakedepends="automake gettext-devel intltool libtool LuaJIT pkg-config"
makedepends="alsa-lib-devel boost-devel libcurl-devel fontconfig-devel
 freetype-devel hunspell-devel icu-devel libass-devel libffms2-devel LuaJIT-devel
 MesaLib-devel wxWidgets-gtk3-devel $(vopt_if fftw fftw-devel)
 $(vopt_if openal libopenal-devel) $(vopt_if portaudio portaudio-devel)"
short_desc="Tool for creating and modifying subtitles"
maintainer="Enno Boland <gottox@voidlinux.org>"
license="BSD-3-Clause, MIT"
homepage="http://www.aegisub.org"
distfiles="https://github.com/Aegisub/Aegisub/archive/v${version}.tar.gz"
checksum=62757dd491455268a240f983b59734a801cc2e899039a7493deeaf5e24a61dcd

build_options="fftw openal portaudio"
build_options_default="fftw"

desc_option_fftw="Enable support for rendering of audio waveforms/spectrum"
desc_option_openal="Enable support for openal"

LDFLAGS+=" -pthread"

if [ "$XBPS_TARGET_NO_ATOMIC8" ]; then
	makedepends+="libatomic-devel"
	configure_args+=" --with-libatomic"
fi

if [ "$CROSS_BUILD" ]; then
	# When cross building the detection of iconv const parameters is wrong
	configure_args+=" agi_cv_with_iconv_const=no"
	# and cross is broken because of boost::icu_regex_trais anyway ...
	broken="/usr/aarch64-linux-gnu/usr/include/boost/regex/v4/perl_matcher_common.hpp:512: undefined reference to 'boost ::icu_regex_traits::isctype(int, unsigned long) const'"
fi

case "$XBPS_TARGET_MACHINE" in
	*musl) broken="segfaults on startup";;
esac

post_extract() {
	# Fix shebang to use system luajit instead of vendored minilua
	sed -e \
		"s:../vendor/luajit/src/host/minilua:/usr/bin/luajit:" \
		-i tools/respack.lua
}

pre_configure() {
	# Aegisub fails to start on Wayland, so we have to force GDK to start it
	# with the x11 backend
	sed "s/Exec=@AEGISUB_COMMAND@ %f/Exec=env GDK_BACKEND=x11 @AEGISUB_COMMAND@ %f/" -i \
		packages/desktop/aegisub.desktop.template.in

	autoreconf -fi
}

post_install() {
	vlicense LICENCE
}