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

pkgname=mc
pkgver=4.8.27
pkgrel=1
pkgdesc="Midnight Commander is a text based filemanager/shell that emulates Norton Commander"
arch=('i686' 'x86_64')
url="https://www.midnight-commander.org/"
license=('GPL')
depends=('glib2'
         'libssh2')
makedepends=('glib2-devel' 'libssh2-devel' 'ncurses-devel')
optdepends=('gawk: hp48+ extfs'
            #'aspell: spelling corrections'
            'cvs: CVS support'
            'perl: needed by several extfs scripts'
            #'unace: uace extfs'
            #'unarj: uarj extfs'
            'unrar: urar extfs'
            'zip: uzip extfs'
            'p7zip: support for 7zip archives')
options=('!emptydirs' '!makeflags')
backup=('etc/mc/edit.indent.rc'
        'etc/mc/filehighlight.ini'
        'etc/mc/mcedit.menu'
        'etc/mc/mc.ext'
        'etc/mc/mc.keymap'
        'etc/mc/mc.menu'
        'etc/mc/sfs.ini')
source=(${pkgname}-${pkgver}.tar.gz::"https://github.com/MidnightCommander/${pkgname}/archive/${pkgver}.tar.gz"
        4.7.5.2-ncursesw-term.h.patch
        mc-4.8.19-msys2.patch
        0003-vfs-win32-absolute-paths.patch)
sha256sums=('3bab1460d187e1f09409be4bb8550ea7dab125fb9b50036a8dbd2b16e8b1985b'
            '49e9a7d918088c8760b0090e99cd6257fa56efa3a4d3e6c9166270cda9c2e8e3'
            '513a015f237a6907bbbf92bcc13351d831740163a0b8a508a99ba647dea64981'
            'dad59dada28d12d262389b23b7972703cb75da48e95f90102a9c30fc2174521a')
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
  
  cd "${srcdir}/${pkgname}-${pkgver}"
  cp -f doc/{INSTALL,NEWS,README} .
  
  ./autogen.sh
  
  patch -Np2 -i "${srcdir}/4.7.5.2-ncursesw-term.h.patch"
  patch -Np1 -i "${srcdir}/mc-4.8.19-msys2.patch"
  patch -Np0 -i "${srcdir}/0003-vfs-win32-absolute-paths.patch"

  autoreconf -fi

}

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

  ./configure --build=${CHOST} \
    --prefix=/usr \
    --sysconfdir=/etc \
    --without-libintl-prefix \
    --without-libiconv-prefix \
    --with-screen=ncursesw \
    --enable-charset \
    --libexecdir=/usr/lib

  make
}

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

  make DESTDIR="${pkgdir}" install

  # Fix FS#15177
  sed 's|op_has_zipinfo = 0|op_has_zipinfo = 1|' \
    -i "${pkgdir}/usr/lib/mc/extfs.d/uzip"

  sed 's#/usr/bin/env python#/usr/bin/python#' \
    -i "${pkgdir}/usr/lib/mc/extfs.d/s3+"
}
