# Maintainer (arch): George Rawlinson <grawlinson@archlinux.org>
# Contributor: Alad Wenter <alad@archlinux.org>
# Contributor: schuay <jakob.gruber@gmail.com>
# Contributor: Daniel J Griffiths <ghost1227@archlinux.us>
# Contributor: André Silva <emulatorman@hyperbola.info>
# Contributor: Márcio Silva <coadde@hyperbola.info>
# Maintainer: Omar Vega Ramos <ovruni@gnu.org.pe>


# parabola changes and rationale:
#   - remove non-free archiver optdepends
#   - use versioned source-ball rather than VCS sources


pkgname=mc
pkgver=4.8.30
pkgrel=1
pkgrel+=.parabola1
pkgdesc='A file manager that emulates Norton Commander'
arch=('x86_64')
arch+=('armv7h' 'i686')
url='https://midnight-commander.org/'
license=('GPL')
depends=(
  'e2fsprogs'
  'glib2'
  'gpm'
  'libssh2'
  'slang'
  'which'
)
makedepends=(
  'aspell'
  'git'
  'libxt'
  'libx11'
  'unzip'
)
optdepends=(
  'aspell: spelling corrections'
  'cabextract: ucab extfs'
  'cdparanoia: audio extfs'
  'cdrkit: iso9660 extfs'
  'cvs: CVS support'
  'gawk: hp48+ extfs'
  'mtools: a+ extfs'
  'p7zip: support for 7zip archives'
  'perl: needed by several extfs scripts'
  'python: to access uc1541 or s3 storage'
  'python-boto: s3+ extfs'
  'python-pytz: s3+ extfs'
  # non-free deleted
  # non-free deleted
  # non-free deleted
  'unzip: open zip archives'
  'zip: uzip extfs'

)
optdepends+=(
  'samba: VFS support'
  'arj: uarj extfs'
)
backup=(
  'etc/mc/edit.indent.rc'
  'etc/mc/filehighlight.ini'
  'etc/mc/mc.ext'
  'etc/mc/mc.keymap'
  'etc/mc/mc.menu'
  'etc/mc/mcedit.menu'
  'etc/mc/sfs.ini'
)
options=('!emptydirs')
source=(
  http://ftp.midnight-commander.org/${pkgname}-${pkgver}.tar.xz
  'mc-python3.patch'
)
source+=('libre.patch')
sha256sums=('5ebc3cb2144b970c5149fda556c4ad50b78780494696cdf2d14a53204c95c7df'
            '78df8592c86445fa6249433e8587889e3923c0bb8b604cae32d5e739d2cc025c')
sha256sums+=('c5785a63c194363824e9218bfc1c068f4cc8fc41f7cbc934c0da9bdb495c5861')


prepare() {
  ln -fs ${pkgname}{-${pkgver},} # link source-ball root dir as VCS root dirname
  cd "$pkgname"

  # port to Python 3
  # ref: https://github.com/MidnightCommander/mc/pull/149
  patch -p1 -i "$srcdir/mc-python3.patch"

  #./autogen.sh # does not exist in the source-ball


  ## parabola changes ##

  rm -v src/vfs/extfs/helpers/{uace,urar}.in

  echo "applying libre.patch"
  patch -Np1 -i ../libre.patch

  # libre.patch requires autotools reconfigure
  rm -v configure Makefile.in
  autoreconf -ifv
}

build() {
  cd "$pkgname"

  ./configure \
    --prefix=/usr \
    --libexecdir=/usr/lib \
    --sysconfdir=/etc \
    --enable-aspell \
    --enable-vfs-smb \
    --with-screen=slang \
    --with-x

  make
}

package() {
  cd "$pkgname"

  make DESTDIR="$pkgdir" install

  # FS#50889: Replace mc.keymap symlink with target file to fix backup mechanism.
  rm "$pkgdir/etc/mc/mc.keymap"
  cp "$pkgdir"/etc/mc/mc{.default,}.keymap
}
