# Maintainer: Maxime Gauduin <alucryd@archlinux.org>
# Contributor: kozec <kozec@kozec.com>
# Contributor: Limao Luo <luolimao+AUR@gmail.com>

pkgname=aegisub
pkgver=3.2.2
pkgrel=46
pkgdesc='A general-purpose subtitle editor with ASS/SSA support'
arch=(x86_64)
url=http://www.aegisub.org
license=(
  GPL
  BSD
)
depends=(
  alsa-lib
  boost-libs
  fftw
  fontconfig
  hunspell
  icu
  libass.so
  libffms2.so
  libgl
  libpulse
  wxgtk3
  zlib
)
makedepends=(
  boost
  git
  intltool
  mesa
)
source=(
  git+https://github.com/Aegisub/Aegisub.git?signed#tag=v${pkgver}
  boost-1.68.patch
  icu59.patch
  make-4.3.patch
  fix-ffms2-compat.patch
  fix-ffms2-compat-2.patch
  fix-ffms2-compat-3.patch
)
validpgpkeys=(6DD9508BCB1CE31AF295FF9B6A889F50A8B00C08) # Thomas Goyne <plorkyeran@aegisub.org>
sha256sums=('SKIP'
            'aa1689a2204f6a617000f3380b8dea9c3dca4f500d0643e05172750c49cc5a21'
            '29d8cc91e73602d5e3c8517c977dcc77cb84af7d42787f510d487d0a6abf7fa6'
            '1e350a04c152075b369176f8e0b7f691a792de0d5091568e2388e6bd677180e1'
            '1361e782a19d1e6cdd0dabe0a5e7dedd3d750ea5c18884eee807c70637811fad'
            'c5753b989896d1f29722fbf748a2177ffd2d73538020bedaadbf3bca73a3c6d7'
            '301ee822a01bad9004c8cab4e96d8bf3fe378a31956c0bd784e0bc245de57c5c')

prepare() {
  cd Aegisub

  patch -Np1 -i ../boost-1.68.patch
  sed 's|gil/gil_all.hpp|gil.hpp|g' -i src/*.cpp # boost 1.69
  sed 's/$(LIBS_BOOST) $(LIBS_ICU)/$(LIBS_BOOST) $(LIBS_ICU) -pthread/' -i tools/Makefile # missing link flag
  sed 's/^Exec=/Exec=env GDK_BACKEND=x11 /' -i packages/desktop/aegisub.desktop.template.in # fix running under wayland
  sed  -i 's/-Wno-c++11-narrowing/-Wno-narrowing/' configure.ac
  patch -Np1 -i ../icu59.patch
  patch -Np1 -i ../make-4.3.patch
  patch -p1 -i ../fix-ffms2-compat.patch
  patch -p1 -i ../fix-ffms2-compat-2.patch
  patch -p1 -i ../fix-ffms2-compat-3.patch

  # Not sure when this broke and resulted in:
  # > configure.ac: error: required file 'config.rpath' not found
  cp /usr/share/gettext/config.rpath .

  ./autogen.sh
}

build() {
  cd Aegisub

  # http://site.icu-project.org/download/61#TOC-Migration-Issues
  CPPFLAGS+=' -DU_USING_ICU_NAMESPACE=1'

  ./configure \
    --prefix=/usr \
    --with-wx-config=/usr/bin/wx-config-gtk3 \
    --without-{portaudio,openal,oss} \
    --disable-update-checker
  make
}

package() {
  cd Aegisub

  make DESTDIR="${pkgdir}" install

  install -dm 755 "${pkgdir}"/usr/share/licenses/aegisub
  install -m 644 LICENCE "${pkgdir}"/usr/share/licenses/aegisub/LICENSE
}

# vim: ts=2 sw=2 et:
