# $Id: PKGBUILD 57440 2011-10-27 20:16:15Z lcarlier $
# Maintainer: Eduardo Martins Lopes "duca" <edumlopes@gmail.com>
# Maintainer: Abhishek Dasgupta <abhidg@gmail.com>
# Contributor: Ricardo <rikardo.horo@gmail.com>
# Contributor: Hector <hsearaDOTatDOTgmailDOTcom>

pkgname=gromacs4
_pkgname=gromacs
pkgver=4.5.5
pkgrel=1
pkgdesc='A versatile package to perform molecular dynamics. Old version'
url='http://www.gromacs.org/'
license=("GPL")
arch=('i686' 'x86_64')
depends=('fftw' 'lesstif' 'perl' 'libxml2' 'libsm' 'libx11')
makedepends=('cmake')
options=('!libtool')
source=(ftp://ftp.gromacs.org/pub/gromacs/${_pkgname}-${pkgver}.tar.gz)
md5sums=('6a87e7cdfb25d81afa9fea073eb28468')

build() {
  mkdir -p "${srcdir}/double"
  msg2 "Building the doulbe precision files"
  cd "${srcdir}/double"
  cmake -DCMAKE_PREFIX=/opt/gromacs_old/ -DCMAKE_INSTALL_PREFIX=/opt/gromacs_old/ -DGMX_THREADS=ON -DGMX_SHARED_LIBS=ON -DGMX_DOUBLE=ON -DGMX_X11=ON -DGMX_DEFAULT_SUFFIX=OFF -DGMX_LIBS_SUFFIX=_4.5 -DGMX_BINARY_SUFFIX=_4.5 ../${_pkgname}-${pkgver}/
  make -j5
}

package() {
  mkdir -p "${pkgdir}/etc/profile.d/"
  mkdir -p "${pkgdir}/usr/share/bash-completion/completions"
  # Cleaning up, kept the csh completion at default location
  msg2 "Making the double precision executables"
  cd "${srcdir}/double"
  make DESTDIR="${pkgdir}" install

  # installing completions in correct location and environment setup script
  install -D -m755 "${srcdir}/${_pkgname}-${pkgver}/scripts/completion.bash" "${pkgdir}/usr/share/bash-completion/completions/gromacs_old"
  mv "${pkgdir}/opt/gromacs_old/bin/GMXRC.bash" "${pkgdir}/etc/profile.d/GMXRC_OLD.bash"
  mv "${pkgdir}/opt/gromacs_old/bin/GMXRC.zsh" "${pkgdir}/etc/profile.d/GMXRC_OLD.zsh"
  mv "${pkgdir}/opt/gromacs_old/bin/GMXRC.csh" "${pkgdir}/etc/profile.d/GMXRC_OLD.csh"
  sed "s:/opt/gromacs_old/bin:/etc/profile.d:g" "${pkgdir}/opt/gromacs_old/bin/GMXRC" > "${pkgdir}/etc/profile.d/GMXRC"
  sed -e "s/GMXRC/GMXRC_OLD/g" "${pkgdir}/etc/profile.d/GMXRC" > "${pkgdir}/etc/profile.d/GMXRC_OLD"
  chmod 755 "${pkgdir}/etc/profile.d/GMXRC_OLD"
  rm -f "${pkgdir}/etc/profile.d/GMXRC"
  rm -f "${pkgdir}/opt/gromacs_old/bin/completion.*"
  rm -f "${pkgdir}/opt/gromacs_old/bin/GMXRC"
} 
