# Maintainer:  Bartłomiej Piotrowski <bpiotrowski@archlinux.org>
# Contributor: Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
# Contributor: Kovivchak Evgen <oneonfire@gmail.com>

# ALARM: Hayden Seay <me@diatr.us>
#  - build with 16 KiB page sizes on arm.

pkgname=jemalloc
epoch=1
pkgver=5.3.0
pkgrel=3
pkgdesc='General-purpose scalable concurrent malloc implementation'
arch=('x86_64')
license=('BSD')
url='http://www.canonware.com/jemalloc/'
depends=('glibc')
makedepends=('clang')
options=('!lto')
provides=('libjemalloc.so')
optdepends=('perl: for jeprof')
source=("https://github.com/jemalloc/jemalloc/releases/download/${pkgver}/${pkgname}-${pkgver}.tar.bz2")
sha256sums=('2db82d1e7119df3e71b7640219b6dfe84789bc0537983c3b7ac4f7189aecfeaa')

build() {
  cd $pkgname-$pkgver

  # FS#71745: GCC-built jemalloc causes telegram-desktop to crash a lot. The reason is still not clear.
  export CC=clang
  export CXX=clang++

  [[ $CARCH == "aarch64" ]] && CONFIG="--with-lg-page=14"
  ./configure \
    --enable-prof \
    --enable-autogen \
    --prefix=/usr $CONFIG
  make
}

package() {
  cd $pkgname-$pkgver

  make DESTDIR="$pkgdir" install

  install -Dm644 COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING"
  chmod 644 "$pkgdir/usr/lib/libjemalloc_pic.a"
}