# Maintainer: Anatol Pomozov
# Maintainer: Carl Smedstad <carsme@archlinux.org>
# Contributor: Jan de Groot <jgc@archlinux.org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Pierre Schmitz <pierre@archlinux.de>

pkgname=apr
pkgver=1.7.6
pkgrel=1
pkgdesc="The Apache Portable Runtime"
arch=(x86_64 aarch64)
url="https://apr.apache.org/"
license=(Apache-2.0)
depends=(
  glibc
  util-linux-libs
)
makedepends=(python)
source=(
  "https://archive.apache.org/dist/apr/apr-$pkgver.tar.bz2"{,.asc}
  "fix_apr-config.patch"
  "fix-apr.pc.patch"
  "ship_find_apr.m4.patch"
  "omit_extra_libs.patch"
  "dont_override_external_buildflags"
)
sha256sums=('49030d92d2575da735791b496dc322f3ce5cff9494779ba8cc28c7f46c5deb32'
            'SKIP'
            '572efb102d02bb3e85ff08eca6b2ea8ff7936ce5228da7a45c1e639faca36a5c'
            '12595d331b48be9e44bd843635eb4f0f500bd213e197a551a9d383a28a24641f'
            '315932ef6536fc0644c1efe770ceb3bb675c3c7103a7cbb2f02efd8be03eb752'
            '3d491d3af8fb5a75db4e085a17e5d8dcbe058bd256ef893ee779dc97fc9f8ad6'
            '5ac0bdc532479f6082d29115ac9d3ca24524fd8b97a556568755b88e5a68e3df')
validpgpkeys=(
  '5B5181C2C0AB13E59DA3F7A3EC582EB639FF092C' # Jeff Trawick
  'B1B96F45DFBDCCF974019235193F180AB55D9977' # Nick Kew <niq@apache.org>
  '65B2D44FE74BD5E3DE3AC3F082781DE46D5954FA' # "Eric Covener <covener@apache.org>"
  '120A8667241AEDD4A78B46104C042818311A3DE5' # Ruediger Pluem <rpluem@apache.org>
  'CBA1525BAA7A47BE28FF23DDD3B13FCA2CE60BED' # Graham Leggett <minfrin@redwax.eu>
)

prepare() {
  cd $pkgname-$pkgver
  patch -Np1 -i ../fix_apr-config.patch
  patch -Np1 -i ../ship_find_apr.m4.patch
  patch -Np1 -i ../fix-apr.pc.patch
  patch -Np1 -i ../omit_extra_libs.patch
  patch -Np1 -i ../dont_override_external_buildflags
  # Make reproducible by removing hostname.
  sed -i '/Libtool was configured on host/d' configure build/libtool.m4
}

build() {
  cd $pkgname-$pkgver
  ./configure \
    --prefix=/usr \
    --includedir=/usr/include/apr-1 \
    --with-installbuilddir=/usr/share/apr-1/build \
    --enable-nonportable-atomics \
    --with-devrandom=/dev/urandom \
    --disable-static
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

check() {
  cd $pkgname-$pkgver
  make -j1 check
}

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