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

pkgname=tar
pkgver=1.35
pkgrel=3
pkgdesc="Utility used to store, backup, and transport files"
arch=('i686' 'x86_64')
url="https://www.gnu.org/software/tar/tar.html"
msys2_references=(
  "anitya: 4939"
  "cpe: cpe:/a:gnu:tar"
)
license=('GPL3')
groups=('compression')
depends=('libiconv' 'libintl' 'sh')
makedepends=('libiconv-devel' 'gettext-devel' 'autotools' 'gcc')
options=('!emptydirs')
source=(https://ftpmirror.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.xz{,.sig}
        tar-1.33-textmount.patch
        tar-LDADD.patch::https://git.savannah.gnu.org/cgit/tar.git/patch/?id=8632df398b2f548465ebe68b8f494c0d6f8d913d
        tar-LDADD-tests.patch::https://git.savannah.gnu.org/cgit/tar.git/patch/?id=71530f72d21d9af00b5688948111666f62f5ec4b
        paxutils-Prevent-file-name-escape.patch)
sha256sums=('4d62ff37342ec7aed748535323930c7cf94acf71c3591882b26a7ea50f3edc16'
            'SKIP'
            'eb43f400cdf1317aac2937cce8eb4f47c7da3b41a6d5b10369cf9cbf9f33e244'
            '95a8cec49a3a2909cabf4ef6f5daaebb45befa4a4ccb4367028a257bc5c6506a'
            '994ba0c59db44e993081ac3e35741025814b25b3b3b92c2a32d931780f4b605d'
            '1078b211e1dc12fa253beb6368c9a7dffe97c7e3a05755c8c8e67607a50fc511')
validpgpkeys=('325F650C4C2B6AD58807327A3602B07F55D0C732') # Sergey Poznyakoff

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

  patch -p2 -i ${srcdir}/tar-1.33-textmount.patch
  patch -p1 -i ${srcdir}/tar-LDADD.patch
  patch -p1 -i ${srcdir}/tar-LDADD-tests.patch

  # Backport from paxutils which is vendored:
  # https://cgit.git.savannah.gnu.org/cgit/paxutils.git/commit/?id=063408cc6f32fff79b4f436a62236b84ca442d2e
  patch -bp1 -i ${srcdir}/paxutils-Prevent-file-name-escape.patch

  autoreconf -fi
}

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

  export gl_cv_have_weak=no
  local -a extra_config
  # 32-bit cygwin only has 32-bit time_t
  # https://github.com/msys2/MSYS2-packages/issues/4078
  if [[ "$CARCH" == "i686" ]]; then
    extra_config+=("--disable-year2038")
  fi
  ./configure \
    --build=${CHOST} \
    --prefix=/usr \
    --sbindir=/usr/bin \
    --libexecdir=/usr/lib/tar \
    --enable-backup-scripts \
    "${extra_config[@]}"
  make
}

check() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make check || true
}

package() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make DESTDIR=${pkgdir} install
}
