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

pkgname=subversion
pkgver=1.14.2
pkgrel=11
pkgdesc="A Modern Concurrent Version Control System"
arch=('i686' 'x86_64')
url="https://subversion.apache.org/"
msys2_references=(
  "anitya: 4905"
  "cpe: cpe:/a:apache:subversion"
  "cpe: cpe:/a:subversion:subversion"
)
license=('spdx:Apache-2.0')
groups=('VCS')
depends=('apr' 'apr-util' 'file' 'gcc-libs' 'libbz2' 'libexpat' 'libiconv' 'libintl'
         'liblz4' 'liblzma' 'libopenssl' 'libsasl' 'libserf' 'libsqlite' 'libutil-linux'
         'libxcrypt' 'libzstd' 'zlib')
makedepends=('gcc' 'autotools' 'perl' 'python' 'python-py3c' 'python-setuptools' 'ruby' 'swig'
             'gmp-devel' 'liblz4-devel' 'libsasl-devel' 'libserf-devel' 'libsqlite-devel')
optdepends=('bash-completion: for svn bash completion'
            'python: for some hook scripts'
            'ruby: for some hook scripts')
provides=('svn')
options=('!libtool' '!emptydirs')
noextract=("subversion-${pkgver}.tar.bz2")
source=(https://archive.apache.org/dist/subversion/subversion-${pkgver}.tar.bz2{,.asc}
        svnclean
        01-make-build-directories.patch
        02-fix-linking.patch
        03-fix-linking-perl.patch
        04-fix-switch-tests.patch
        05-retry-loop.patch
        06-svnadmin-binary-mode.patch
        07-fix-path-tests.patch
        08-ruby-test-fix.patch
        09-wincrypt.patch
        10-perl-vendors.patch
        11-XFAIL-case-sensitive-move-tests.patch
        12-fix-svnlook-test.patch
        13-dso_open.patch
        14-fix_svnauthz_tests.patch
        15-XFAIL_case_sensitive_tree_conflict.patch
        16-fix-swig3.patch
        17-fix-test-link.patch
        18-fix-serf-config.patch
        19-remove-contrib-from-configure.patch
        20-fix-build-with-python-3.12.patch
        subversion-1.9.1-msys2.patch
        remove-checking-symlink.patch
        90-use-copy-instead-symlink.patch)
sha256sums=('c9130e8d0b75728a66f0e7038fc77052e671830d785b5616aad53b4810d3cc28'
            'SKIP'
            'b09dd041aba0078c8d50df130ef2f96c3ef8486279a620532fef4fe48ef9961e'
            '66d8028dbee086502e453d7435aa15f7e141dbc8808e650e883e1d90a0a022b1'
            '6dc4dda8291087abb94ac0e256833b2ecae452a597fc9222e7443ea0e5694ff7'
            '96a786a619cc7d45d2c3dcc6851579f7e3cb65fb8d254bb817227439465041a0'
            'ea93b62a7f71437c7066aa489044fc311457ea330b9735347a4609858e12c2ad'
            '2504c157f51cfb6453205da3ef2705ad6f36b63169fde3efaf438b7dc4ecc306'
            '1ee9719475a89e3447fade44e704a32e63c8a2916b38b68984f1cb6a4dae158a'
            '6445d7f0758e3ddbd91e35612c545c1f4f5cecbd1c8e134b6b8ea66e8a39e6f0'
            'edad1ae1db35522af533efa8346885a16e9bbdf43ad8196827e8411ca84d7825'
            'a93ad1ccbcc2e68ef3a50fed9b529107aa434acb6618ddb28f4fde934bfcb3b8'
            '5ef14d187071c60de834d87dbea18d3fd022fd11a648dc5315bc7b9fa7067141'
            'eca0edb5d2afbbe8a7d556d8afb79000e653f1e4662b62157368d00f58dd9fff'
            '4069a84189db7ed0d08c5fda927308d494ac9377e111d70debdbb6ad889af70b'
            '21038203297180e74bd75878aae6ce5c1c299ca56d71075bb7029e4dbf083fa2'
            'cad2c464dc3ae6753b1ce2f330d984c97679a52ac1baa411981cfa8c7ebcf312'
            '7f9e60b99a2ec8424f702b5dc07e5b1d37c8eb7d8bd134cc79a7024cb35292d6'
            '8682d9f7da2ba8607ed15daf3beec92e5dacda3a6e4c07baaef8991264eb44cd'
            '78053226695b702fbc8a5fed3587a5f641313a266d9b0a91d457ca70584edf2c'
            'f61c9b3333d90790a4c6763d81ee05ee5a2029e562c900e92f7526393460181c'
            'a1072514d1be6e2026ae1e2fa24d3bfd97dfbda13b4bd4d89aae0e871b2aae32'
            'e2063e5d6636576e3c4b578435587cf650aa643446f9280b827b2bbd9f11b3e7'
            '9d718bc1a8eb51b6b95513830574d4bf57875db720f03c7c376a977beebae82c'
            'd821304ee957ef4adbb0a8dec9cea3fe62ad7163aef132317d28f70ea25162ca'
            'fc545e375d8af4ef6d8afad453453480664b6a2ff74915f94b8a7da7de14155b')
# https://subversion.apache.org/download.cgi#recommended-release
validpgpkeys=('EC25FCC105618D04ADB43429C4416167349A3BCB')

apply_patch_with_msg() {
  for _fname in "$@"
  do
    msg2 "Applying ${_fname}"
    patch -Nbp1 -i "${srcdir}"/${_fname}
  done
}

prepare() {
  echo "Extracting ${pkgname}-${pkgver}.tar.bz2..."
  tar -xjf ${pkgname}-${pkgver}.tar.bz2 -C ${srcdir} || true

  cd "${srcdir}"/${pkgname}-${pkgver}

  apply_patch_with_msg \
    01-make-build-directories.patch \
    02-fix-linking.patch \
    03-fix-linking-perl.patch \
    04-fix-switch-tests.patch \
    05-retry-loop.patch \
    06-svnadmin-binary-mode.patch \
    07-fix-path-tests.patch \
    08-ruby-test-fix.patch \
    09-wincrypt.patch \
    10-perl-vendors.patch \
    11-XFAIL-case-sensitive-move-tests.patch \
    12-fix-svnlook-test.patch \
    13-dso_open.patch \
    14-fix_svnauthz_tests.patch \
    15-XFAIL_case_sensitive_tree_conflict.patch \
    16-fix-swig3.patch \
    17-fix-test-link.patch \
    18-fix-serf-config.patch \
    19-remove-contrib-from-configure.patch \
    20-fix-build-with-python-3.12.patch \
    subversion-1.9.1-msys2.patch \
    remove-checking-symlink.patch \
    90-use-copy-instead-symlink.patch

  PYTHON=/usr/bin/python ./autogen.sh
}

build() {
  export lt_cv_deplibs_check_method='pass_all'
  cd ${pkgname}-${pkgver}
  export PYTHON=/usr/bin/python

  CFLAGS+=" -Wno-int-conversion -Wno-incompatible-pointer-types"

  ./configure --prefix=/usr \
      --build=${CHOST} \
      --with-apr=/usr \
      --with-apr-util=/usr \
      --with-zlib=/usr \
      --with-serf=/usr \
      --with-sqlite=/usr \
      --without-apxs \
      --without-gnome-keyring \
      --with-utf8proc=internal \
      --enable-shared --disable-static \
      --with-ruby-sitedir=/usr/lib/ruby/vendor_ruby \
      --disable-mod-activation \
      --enable-disallowing-of-undefined-references \
      --enable-local-library-preloading

  make clean-swig
  make autogen-swig
  make all

  plain "Compiling swig bindings: ruby"
  make swig-rb

  plain "Compiling swig bindings: perl"
  make swig-pl

  plain "Compiling swig bindings: python"
  PYTHON_SITELIB=$(/usr/bin/python -c 'from distutils.sysconfig import * ; print(get_python_lib(0,0));')
  make swig-py swig_pydir=${PYTHON_SITELIB}/libsvn swig_pydir_extra=${PYTHON_SITELIB}/svn
}

#check() {
#   cd ${pkgname}-${pkgver}
#   export LANG=C LC_ALL=C
#   make check check-swig-pl check-swig-py check-swig-rb CLEANUP=yes # check-javahl
#}

package() {
  cd ${pkgname}-${pkgver}

  PYTHON_SITELIB=$(/usr/bin/python -c 'from distutils.sysconfig import * ; print(get_python_lib(0,0));')
  make -j1 DESTDIR="${pkgdir}" INSTALLDIRS=vendor \
    swig_pydir=${PYTHON_SITELIB}/libsvn \
    swig_pydir_extra=${PYTHON_SITELIB}/svn \
    install install-tools install-swig-py install-swig-pl install-swig-rb

  install -dm755 "${pkgdir}"/usr/share/subversion
  cp -a tools/hook-scripts "${pkgdir}"/usr/share/subversion/
  rm "${pkgdir}"/usr/share/subversion/hook-scripts/*.in

  ## svnclean
  install -Dm 755 ${srcdir}/svnclean "${pkgdir}"/usr/bin/svnclean

  install -Dm 644 tools/client-side/bash_completion \
     "${pkgdir}"/usr/share/bash-completion/completions/subversion
  for i in svn svnadmin svndumpfilter svnlook svnsync svnversion; do
      ln -sf subversion "${pkgdir}"/usr/share/bash-completion/completions/${i}
  done

  # Remove illegal files
  find ${pkgdir}/usr -type f -name "*::*" | xargs rm -f

  # fix permissons
  find ${pkgdir}/usr -type f \( -name *.dll -o -name *.exe \) | xargs chmod 0755
}
