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

pkgname=cvs
pkgver=1.11.23
pkgrel=5
pkgdesc="Concurrent Versions System - a source control system"
arch=('i686' 'x86_64')
license=('GPL')
url="http://cvs.nongnu.org/"
msys2_references=(
  "cpe: cpe:/a:cvs:cvs"
)
depends=('heimdal' 'zlib' 'libxcrypt' 'libopenssl')
makedepends=('groff' 'heimdal-devel' 'zlib-devel' 'gcc' 'libxcrypt-devel' 'openssl-devel' 'autotools')
options=('staticlibs')
source=(https://ftp.gnu.org/non-gnu/cvs/source/stable/${pkgver}/${pkgname}-${pkgver}.tar.bz2
    cvs-1.11.1p1-bs.patch
    cvs-1.11.19-abortabort.patch
    cvs-1.11.19-comp.patch
    cvs-1.11.19-extzlib.patch
    cvs-1.11.19-logmsg.patch
    cvs-1.11.19-netbsd-tag.patch
    cvs-1.11.19-tagname.patch
    cvs-1.11.19-tmp.patch
    cvs-1.11.21-diff-kk.patch
    cvs-1.11.21-diff.patch
    cvs-1.11.21-proxy.patch
    cvs-1.11.21-sort.patch
    cvs-1.11.22-cvspass.patch
    cvs-1.11.22-ipv6-proxy.patch
    cvs-1.11.22-stdinargs.patch
    cvs-1.11.23-Back-port-KeywordExpand-configuration-keyword.patch
    cvs-1.11.23-cve-2010-3846.patch
    cvs-1.11.23-Fix-proxy-response-parser.patch
    cvs-1.11.23-getline64.patch
    cvs-1.11.23-make_make_check_sanity_testing_verbose.patch
    cvs-1.11.23-Pass-server-IP-address-instead-of-hostname-to-GSSAPI.patch
    cvs-1.11.23-remove_undefined_date_from_cvs_1_header.patch
    cvs-1.11.23-sanity.patch
    cvs-1.11.23-doc-Add-mandatory-argument-to-sp.patch
    )
sha256sums=('400f51b59d85116e79b844f2d5dbbad4759442a789b401a94aa5052c3d7a4aa9'
            'cc273d17a8484a350e76f77cdf000090b12acdd9d40149609bb92eb64651cd18'
            'a63bd4d696d4785f3b16146c9a8e57b7f0b2fcb648b9b3b43b138857e28e23f4'
            '973d2c6682e2e4b9b9a80c0aec7dd436a180adbc06c6ed6914c349627cfb9a6e'
            '0587ac3753d1257fa6d22557fa077178ee1ec004178c0a0348720e8171b1e942'
            'f97ea853f2c7cc6cc0364e1d0ca148be6229c43327417c32a4b253d74bf9fd76'
            'f8e544879d3ca5589c09f56678cd0a5166b727f65ebb4daceaeb70bd700f5f6b'
            '0cf5fa737444344f76c7b361a60e6736ccff7887b5157fb1b2ddd6bd133cc4e5'
            '1ff4ae9d167f5449fbd1c8ae3b489da73b2806df3b3d8795711deffba7856953'
            'd924459e46ea4fb438d0f71b0d87bd528b132bc53224dbfb588b090633f2fea9'
            '70af9380ea697a9ffcca8b33bd3d591ee53e23da250462dd690fca357600fab6'
            '6b73dcc541a9c9358c7436687b1f763c8e84edf2b9cf12eba666a382855a08ba'
            '775feb4094f638bf30a47be5b6e098266879ba6592d15d3694fff9365fb65b2d'
            '2901fd2fd70896fc63b9eb64dc66402b274ed9d2640615fa5c67970816be08ff'
            'ea1ea171a38088e93c0a83e3bfa87ab2d2bd52c888f97613c6e7df597dcdd0d1'
            '5ed4c490d6073b900e9ef5a31de7f4eb916ba50d9404118294d849c2f148f91f'
            'f36491c72ad354cdbcc38aff67352aeae8aaccdbbdc8473381d200b5f6c8a578'
            'c6506d0a5efc7b0cab6415f26e070ec214fb9781fac8d295506f4d0825431a8f'
            'fbd0e7ec4be5547a9443df82f5f00e85f088cfd8cd179bb2d0e23d91a18e0563'
            '9126d7992ace943980ad8a10d5a09aeb6f1eeeb9b921fc796fe31de7b1c220cf'
            '9eeb10fcee6a131210c16978f2eb91fad3e7a8df7fc579bda0ea3a4108c78e1d'
            '78e425726b51c3c18be06b6de0e44de85476a790d5779776569d5415e7602862'
            '887d09d266a796582b046ef36c80792a1b244aea714cd9280f6928cef7dc6698'
            'f661dbd97518b12d63b1cec2f3e6f1ab8219aeddfd1e96e7e505f38ffb04a4b2'
            '30f68fc13474db4468d22fbdbe771b5f107217cdd2513c058e07de8fe7300d01')

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}

  patch -p1 -i ${srcdir}/cvs-1.11.22-cvspass.patch
  patch -p1 -i ${srcdir}/cvs-1.11.19-extzlib.patch
  patch -p1 -i ${srcdir}/cvs-1.11.19-netbsd-tag.patch
  patch -p1 -i ${srcdir}/cvs-1.11.19-abortabort.patch
  patch -p1 -i ${srcdir}/cvs-1.11.1p1-bs.patch
  patch -p1 -i ${srcdir}/cvs-1.11.21-proxy.patch
  patch -p1 -i ${srcdir}/cvs-1.11.19-logmsg.patch
  patch -p1 -i ${srcdir}/cvs-1.11.19-tagname.patch
  patch -p1 -i ${srcdir}/cvs-1.11.19-comp.patch
  patch -p1 -i ${srcdir}/cvs-1.11.19-tmp.patch
  patch -p1 -i ${srcdir}/cvs-1.11.21-diff.patch
  patch -p1 -i ${srcdir}/cvs-1.11.21-diff-kk.patch
  patch -p1 -i ${srcdir}/cvs-1.11.21-sort.patch
  patch -p1 -i ${srcdir}/cvs-1.11.22-ipv6-proxy.patch
  patch -p1 -i ${srcdir}/cvs-1.11.23-getline64.patch
  patch -p1 -i ${srcdir}/cvs-1.11.22-stdinargs.patch
  patch -p1 -i ${srcdir}/cvs-1.11.23-cve-2010-3846.patch
  patch -p1 -i ${srcdir}/cvs-1.11.23-remove_undefined_date_from_cvs_1_header.patch
  patch -p1 -i ${srcdir}/cvs-1.11.23-sanity.patch
  patch -p1 -i ${srcdir}/cvs-1.11.23-make_make_check_sanity_testing_verbose.patch
  patch -p1 -i ${srcdir}/cvs-1.11.23-Back-port-KeywordExpand-configuration-keyword.patch
  patch -p1 -i ${srcdir}/cvs-1.11.23-Pass-server-IP-address-instead-of-hostname-to-GSSAPI.patch
  patch -p1 -i ${srcdir}/cvs-1.11.23-Fix-proxy-response-parser.patch
  patch -p1 -i ${srcdir}/cvs-1.11.23-doc-Add-mandatory-argument-to-sp.patch
  autoreconf -vfi

  #patch -Np1 < ../cvs-1.11.19-extzlib.patch
  #patch -Np1 < ../cvs-1.11.23-getline64.patch
  # CVE-2010-3864, https://www.redhat.com/security/data/cve/CVE-2010-3846.html
  #patch -Np1 < ../cvs-1.11.23-cve-2010-3846.patch

  sed -i -e 's/AM_CONFIG_HEADER/AC_CONFIG_HEADERS/' configure.in
  find . -name Makefile.am | xargs sed -i -e 's/^INCLUDES/AM_CPPFLAGS/'
  AUTOMAKE='automake --add-missing' autoreconf
}

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

  ./configure --prefix=/usr
  make
}

package() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make DESTDIR=${pkgdir} install
  rm "${pkgdir}"/usr/share/info/dir
}
