# Maintainer: Developer <dev@opalos.org>
# Maintainer: Developer <dev@opalos.org>

pkgname=mc
pkgver=%version%
pkgrel=%release%
pkgdesc='A file manager that emulates Norton Commander'
arch=('x86_64')
url='https://midnight-commander.org/'
license=('GPL-3.0-or-later')
depends=(
  'e2fsprogs'
  'glib2'
  'glibc'
  'gpm'
  'libssh2'
  'sh'
  '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'
  'unace: uace extfs'
  'unarj: uarj extfs'
  'unrar: urar extfs'
  'unzip: open zip archives'
  'zip: uzip 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=("git+https://github.com/MidnightCommander/mc#tag=$pkgver")
sha256sums=('70a9fa0da9da13b82e6a612f132626bba4d685078a74884d8d0f2b6abdf317e1')

prepare() {
  cd "$pkgname"

  ./autogen.sh
}

build() {
  cd "$pkgname"

  ./configure \
    --prefix=/usr \
    --libexecdir=/usr/lib \
    --sysconfdir=/etc \
    --enable-aspell \
    --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
  # remove s3 support until it no longer depends on deprecated python-boto:
  # https://midnight-commander.org/ticket/3904
  rm -v "$pkgdir/usr/lib/mc/extfs.d/s3+"
}
