# $Id: PKGBUILD 3023 2008-06-18 02:32:22Z eric $
# Maintainer: dorphell <dorphell@archlinux.org>
# Committer: Judd Vinet <jvinet@zeroflux.org>
# Contributor: Lucien Immink <l.immink@student.fnt.hvu.nl>
pkgname=mc
pkgver=4.6.1
pkgrel=5
pkgdesc="A filemanager/shell that emulates Norton Commander"
arch=('i686' 'x86_64')
url="http://www.ibiblio.org/mc/"
license=('GPL')
depends=('e2fsprogs' 'glib2' 'pcre' 'gpm>=1.20.4' 'slang')
makedepends=('libxt' 'libx11')
conflicts=('mc-utf8')
replaces=('mc-utf8')
options=('!emptydirs' '!makeflags')
source=(http://www.ibiblio.org/pub/Linux/utils/file/managers/mc/${pkgname}-${pkgver}.tar.gz \
        ftp://ftp.archlinux.org/other/mc/mc-4.6.1-utf8-r2.patch.bz2 \
        mc-4.6.1-bash-all.patch mc-4.6.1-find.patch mc-4.6.1-invalid-mtime.patch \
        mc-4.6.1-largefile.patch mc-4.6.1-nonblock.patch)
md5sums=('18b20db6e40480a53bac2870c56fc3c4' 'f90bffe7f51883e818143dc2077eb98f'\
         'd0c5d1f7258daf2a86b41b185524dced' '3c950491cdf44091df216cfa709d133a'\
         '81930cce827fe93639dcd6bff630a1a4' '80b45ecf38d9b5df6d368c83d14fd89d'\
         '00e89cfc43fe6026b61f52b218a65907')

build() {
  cd ${srcdir}/${pkgname}-${pkgver}
  patch -p1 < ../mc-4.6.1-find.patch || return 1
  patch -p1 < ../mc-4.6.1-largefile.patch || return 1
  patch -p1 < ../mc-4.6.1-invalid-mtime.patch || return 1
  patch -p1 < ../mc-4.6.1-utf8-r2.patch || return 1
  patch -p1 < ../mc-4.6.1-nonblock.patch || return 1
  patch -p1 < ../mc-4.6.1-bash-all.patch || return 1

# Prevent lazy bindings in cons.saver binary.
#  - not using bindnow-flags() because cons.saver is only built on GNU/Linux
  sed -i -e "s:^\(cons_saver_LDADD = .*\):\1 -Wl,-z,now:" src/Makefile.in

  ./configure --prefix=/usr --mandir=/usr/share/man \
    --without-gnome --without-debug --with-screen=slang --without-included-gettext \
    -enable-largefile --with-subshell --with-edit --with-vfs --with-samba --with-mmap \
    --with-x --with-gpm-mouse --enable-charset
  make || return 1
  make DESTDIR=${pkgdir} install

  iconv -f koi8-r -t utf8 ${pkgdir}/usr/share/mc/mc.hint.ru > ${pkgdir}/usr/share/mc/mc.hint.ru.tmp || return 1
  mv ${pkgdir}/usr/share/mc/mc.hint.ru.tmp ${pkgdir}/usr/share/mc/mc.hint.ru

  iconv -f koi8-r -t utf8 ${pkgdir}/usr/share/mc/mc.hlp.ru > ${pkgdir}/usr/share/mc/mc.hlp.ru.tmp || return 1
  mv ${pkgdir}/usr/share/mc/mc.hlp.ru.tmp ${pkgdir}/usr/share/mc/mc.hlp.ru

  # convert man pages to utf8
  cd ${pkgdir}/usr/share/man/ru
  find -type f | xargs -i123 -- sh -c "mv 123 123.old && iconv -f koi8-r -t utf8 123.old >123 && rm 123.old" || return 1
}