# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=tmux
_base_ver=3.5
_bugfix=.a
pkgver=${_base_ver}${_bugfix}
pkgrel=2
pkgdesc='A terminal multiplexer'
url='https://tmux.github.io/'
msys2_repository_url="https://github.com/tmux/tmux"
msys2_references=(
  "anitya: 4980"
  "cpe: cpe:/a:nicholas_marriott:tmux"
  "cpe: cpe:/a:tmux_project:tmux"
)
arch=('i686' 'x86_64')
license=('BSD')
conflict=('tmux-git')
replaces=('tmux-git')
depends=('ncurses' 'libevent')
makedepends=('ncurses-devel' 'libevent-devel' 'autotools' 'gcc')
source=(${pkgname}-${pkgver}.tar.gz::https://github.com/tmux/tmux/archive/${_base_ver}${_bugfix/./}.tar.gz
        'no-check-dirs-permission.patch'
        'inherit-msystem-var.patch')

sha256sums=('49e68b41dec0bf408990160ee12fa29b06dee8f74c1f0b4b71c9d2a1477dd910'
            '31f3c9f1b98a97788edca46fb7a0ba2b5328758f014d445096561c8466540c5d'
            'aeaea034eeefe9598a56ebfabdf21cb991b2ac39d62dca9f857d24e5bc375366')

prepare() {
  cd "${srcdir}/${pkgname}-${_base_ver}${_bugfix/./}"
  patch -p0 -i "${srcdir}"/no-check-dirs-permission.patch
  patch -p0 -i "${srcdir}"/inherit-msystem-var.patch

  #msg2 "Running autogen.sh"
  ./autogen.sh
}

build() {
  cd "${srcdir}/${pkgname}-${_base_ver}${_bugfix/./}"

  ./configure \
    --build=${CHOST} \
    --enable-sixel \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    CPPFLAGS="${CPPFLAGS} -I/usr/include/ncursesw -U_XOPEN_SOURCE"
  make
}

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

  install -d "${pkgdir}"/usr/share/licenses/tmux
  install -m 644 COPYING "${pkgdir}"/usr/share/licenses/tmux

  #install -d "${pkgdir}"/usr/share/tmux
  #install -m 644 examples/* "${pkgdir}"/usr/share/tmux
  #install -d "${pkgdir}"/usr/share/vim/vimfiles/syntax
  #install -m 644 examples/tmux.vim "${pkgdir}"/usr/share/vim/vimfiles/syntax

  #install -d "${pkgdir}"/usr/share/bash-completion/completions/tmux
  #mv "${pkgdir}"/usr/share/tmux/bash_completion_tmux.sh "${pkgdir}"/usr/share/bash-completion/completions/tmux
}
