# Maintainer: Green0Photon <green0photon AT gmail DOT com>

pkgname=task
pkgver=2.6.2
pkgrel=2
pkgdesc="A command-line todo list manager"
arch=('i686' 'x86_64')
url="https://taskwarrior.org/"
msys2_repository_url="https://github.com/GothenburgBitFactory/taskwarrior"
msys2_references=(
  "anitya: 5841"
)
license=("MIT")
depends=("gcc-libs"
         "libgnutls"
         "libutil-linux"
         "libhogweed" # for some reason, didn't install with libgnutls
)
makedepends=("cmake"
             "libgnutls-devel"
             "libutil-linux-devel"
             'gcc'
)
# AUR packages had an odd colon notation
# The comments were within the quotes so pacman knew about it
optdepends=("bash-completion" # for bash completion
            "python" # for python export addon
            "ruby" # for ruby export addon
            "perl" # for perl export addon
            "perl-JSON" # for perl export addon
            "rsync" # synchronisation via rsync
            "curl" # synchronisation via http(s)/ftp
            "openssh" # synchronisation via ssh
)
checkdepends=("python" # for tests
              "bash" # for tests
)

# This has symlink problems with files missing
#source=("https://taskwarrior.org/download/${pkgname}-${pkgver}.tar.gz")
#sha256sums=("d87bcee58106eb8a79b850e9abc153d98b79e00d50eade0d63917154984f2a15")

source=("https://github.com/GothenburgBitFactory/taskwarrior/releases/download/v${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha256sums=('b1d3a7f000cd0fd60640670064e0e001613c9e1cb2242b9b3a9066c78862cfec')
noextract=(${pkgname}-${pkgver}.tar.gz)

prepare() {
  [[ -d ${srcdir}/${pkgname}-${pkgver} ]] && rm -rf ${srcdir}/${pkgname}-${pkgver}
  tar -xzf ${srcdir}/${pkgname}-${pkgver}.tar.gz -C $srcdir || true
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  CXXFLAGS+=" -D_GNU_SOURCE" \
  cmake -DCMAKE_BUILD_TYPE=release -DCMAKE_INSTALL_PREFIX=/usr .
  make
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make DESTDIR="${pkgdir}" install

  # Note that we rename the bash completion script for bash-completion > 1.99, until upstream does so.
  install -Dm644 "$pkgdir/usr/share/doc/task/scripts/bash/task.sh" "$pkgdir/usr/share/bash-completion/completions/task"
  install -Dm644 "$pkgdir/usr/share/doc/task/scripts/fish/task.fish" "$pkgdir/usr/share/fish/completions/task.fish"

  install -Dm644 "$pkgdir/usr/share/doc/task/scripts/vim/ftdetect/task.vim" "$pkgdir/usr/share/vim/vimfiles/ftdetect/task.vim"
  install -Dm644 "$pkgdir/usr/share/doc/task/scripts/vim/syntax/taskdata.vim" "$pkgdir/usr/share/vim/vimfiles/syntax/taskdata.vim"
  install -Dm644 "$pkgdir/usr/share/doc/task/scripts/vim/syntax/taskedit.vim" "$pkgdir/usr/share/vim/vimfiles/syntax/taskedit.vim"
  install -Dm644 "$pkgdir/usr/share/doc/task/scripts/vim/syntax/taskrc.vim" "$pkgdir/usr/share/vim/vimfiles/syntax/taskrc.vim"

  install -Dm644 "$srcdir/$pkgname-$pkgver/LICENSE" "$pkgdir/usr/share/licenses/task/LICENSE"
}
